diff options
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/renderer_base.h | 3 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 32 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 12 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/video_core/renderer_base.h b/src/video_core/renderer_base.h index d15db6c8c..28893b181 100644 --- a/src/video_core/renderer_base.h +++ b/src/video_core/renderer_base.h @@ -5,6 +5,7 @@ #pragma once #include <memory> +#include <boost/optional.hpp> #include "common/assert.h" #include "common/common_types.h" @@ -47,7 +48,7 @@ public: virtual ~RendererBase() {} /// Swap buffers (render frame) - virtual void SwapBuffers(const FramebufferInfo& framebuffer_info) = 0; + virtual void SwapBuffers(boost::optional<const FramebufferInfo&> framebuffer_info) = 0; /** * Set the emulator window to use for renderer diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index a5df91604..50396b5c1 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -4,8 +4,8 @@ #include <algorithm> #include <cstddef> -#include <cstring> #include <cstdlib> +#include <cstring> #include <memory> #include <glad/glad.h> #include "common/assert.h" @@ -98,20 +98,23 @@ RendererOpenGL::RendererOpenGL() = default; RendererOpenGL::~RendererOpenGL() = default; /// Swap buffers (render frame) -void RendererOpenGL::SwapBuffers(const FramebufferInfo& framebuffer_info) { +void RendererOpenGL::SwapBuffers(boost::optional<const FramebufferInfo&> framebuffer_info) { // Maintain the rasterizer's state as a priority OpenGLState prev_state = OpenGLState::GetCurState(); state.Apply(); - if (screen_info.texture.width != (GLsizei)framebuffer_info.width || - screen_info.texture.height != (GLsizei)framebuffer_info.height || - screen_info.texture.pixel_format != framebuffer_info.pixel_format) { - // Reallocate texture if the framebuffer size has changed. - // This is expected to not happen very often and hence should not be a - // performance problem. - ConfigureFramebufferTexture(screen_info.texture, framebuffer_info); + if (framebuffer_info != boost::none) { + // If framebuffer_info is provided, reload it from memory to a texture + if (screen_info.texture.width != (GLsizei)framebuffer_info->width || + screen_info.texture.height != (GLsizei)framebuffer_info->height || + screen_info.texture.pixel_format != framebuffer_info->pixel_format) { + // Reallocate texture if the framebuffer size has changed. + // This is expected to not happen very often and hence should not be a + // performance problem. + ConfigureFramebufferTexture(screen_info.texture, *framebuffer_info); + } + LoadFBToScreenInfo(*framebuffer_info, screen_info); } - LoadFBToScreenInfo(framebuffer_info, screen_info); DrawScreens(); @@ -290,16 +293,16 @@ void RendererOpenGL::LoadFBToScreenInfo(const FramebufferInfo& framebuffer_info, * Fills active OpenGL texture with the given RGB color. Since the color is solid, the texture can * be 1x1 but will stretch across whatever it's rendered on. */ -void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, +void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a, const TextureInfo& texture) { state.texture_units[0].texture_2d = texture.resource.handle; state.Apply(); glActiveTexture(GL_TEXTURE0); - u8 framebuffer_data[3] = {color_r, color_g, color_b}; + u8 framebuffer_data[4] = {color_a, color_b, color_g, color_r}; // Update existing texture - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, framebuffer_data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, framebuffer_data); state.texture_units[0].texture_2d = 0; state.Apply(); @@ -361,6 +364,9 @@ void RendererOpenGL::InitOpenGLObjects() { state.texture_units[0].texture_2d = 0; state.Apply(); + + // Clear screen to black + LoadColorToActiveGLTexture(0, 0, 0, 0, screen_info.texture); } void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture, diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index dc21d7a38..dd01e1b1a 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -37,7 +37,7 @@ public: ~RendererOpenGL() override; /// Swap buffers (render frame) - void SwapBuffers(const FramebufferInfo& framebuffer_info) override; + void SwapBuffers(boost::optional<const FramebufferInfo&> framebuffer_info) override; /** * Set the emulator window to use for renderer @@ -53,17 +53,15 @@ public: private: void InitOpenGLObjects(); - void ConfigureFramebufferTexture(TextureInfo& texture, - const FramebufferInfo& framebuffer_info); + void ConfigureFramebufferTexture(TextureInfo& texture, const FramebufferInfo& framebuffer_info); void DrawScreens(); void DrawSingleScreen(const ScreenInfo& screen_info, float x, float y, float w, float h); void UpdateFramerate(); // Loads framebuffer from emulated memory into the display information structure - void LoadFBToScreenInfo(const FramebufferInfo& framebuffer_info, - ScreenInfo& screen_info); - // Fills active OpenGL texture with the given RGB color. - void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, const TextureInfo& texture); + void LoadFBToScreenInfo(const FramebufferInfo& framebuffer_info, ScreenInfo& screen_info); + // Fills active OpenGL texture with the given RGBA color. + void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a, const TextureInfo& texture); EmuWindow* render_window; ///< Handle to render window |
