From 11642fd3a218185187bb356f2f446313694d4be4 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 28 Aug 2014 15:21:54 -0300 Subject: Rework OpenGL renderer. The OpenGL renderer has been revised, with the following changes: - Initialization and rendering have been refactored to reduce the number of redundant objects used. - Framebuffer rotation is now done directly, using texture mapping. - Vertex coordinates are now given in pixels, and the projection matrix isn't hardcoded anymore. --- src/video_core/renderer_opengl/renderer_opengl.h | 68 ++++++++---------------- 1 file changed, 22 insertions(+), 46 deletions(-) (limited to 'src/video_core/renderer_opengl/renderer_opengl.h') diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 3dcb331b..82ef4b14 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -7,12 +7,13 @@ #include "generated/gl_3_2_core.h" #include "common/common.h" -#include "common/emu_window.h" - +#include "core/hw/gpu.h" #include "video_core/renderer_base.h" #include +class EmuWindow; + class RendererOpenGL : public RendererBase { public: @@ -22,13 +23,6 @@ public: /// Swap buffers (render frame) void SwapBuffers(); - /** - * Renders external framebuffer (XFB) - * @param src_rect Source rectangle in XFB to copy - * @param dst_rect Destination rectangle in output framebuffer to copy to - */ - void RenderXFB(const Common::Rect& src_rect, const Common::Rect& dst_rect); - /** * Set the emulator window to use for renderer * @param window EmuWindow handle to emulator window to use for rendering @@ -42,32 +36,21 @@ public: void ShutDown(); private: + /// Structure used for storing information about the textures for each 3DS screen + struct TextureInfo { + GLuint handle; + GLsizei width; + GLsizei height; + }; + void InitOpenGLObjects(); void DrawScreens(); + void DrawSingleScreenRotated(const TextureInfo& texture, float x, float y, float w, float h); void UpdateFramerate(); - /// Structure used for storing information for rendering each 3DS screen - struct ScreenInfo { - // Properties - int width; - int height; - int stride; ///< Number of bytes between the coordinates (0,0) and (1,0) - - // OpenGL object IDs - GLuint texture_id; - GLuint vertex_buffer_id; - - // Temporary - u8* flipped_xfb_data; - }; - - /** - * Helper function to flip framebuffer from left-to-right to top-to-bottom - * @param raw_data Pointer to input raw framebuffer in V/RAM - * @param screen_info ScreenInfo structure with screen size and output buffer pointer - * @todo Early on hack... I'd like to find a more efficient way of doing this /bunnei - */ - void FlipFramebuffer(const u8* raw_data, ScreenInfo& screen_info); + // Loads framebuffer from emulated memory into the active OpenGL texture. + static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer, + const TextureInfo& texture); EmuWindow* render_window; ///< Handle to render window u32 last_mode; ///< Last render mode @@ -75,22 +58,15 @@ private: int resolution_width; ///< Current resolution width int resolution_height; ///< Current resolution height - // OpenGL global object IDs - GLuint vertex_array_id; + // OpenGL object IDs + GLuint vertex_array_handle; + GLuint vertex_buffer_handle; GLuint program_id; - GLuint sampler_id; + std::array textures; + // Shader uniform location indices + GLuint uniform_modelview_matrix; + GLuint uniform_color_texture; // Shader attribute input indices GLuint attrib_position; - GLuint attrib_texcoord; - - struct : std::array { - ScreenInfo& Top() { return (*this)[0]; } - ScreenInfo& Bottom() { return (*this)[1]; } - } screen_info; - - // "Flipped" framebuffers translate scanlines from native 3DS left-to-right to top-to-bottom - // as OpenGL expects them in a texture. There probably is a more efficient way of doing this: - u8 xfb_top_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopHeight * 4]; - u8 xfb_bottom_flipped[VideoCore::kScreenBottomWidth * VideoCore::kScreenBottomHeight * 4]; - + GLuint attrib_tex_coord; }; -- cgit v1.2.3