Move FB texture resizing to LoadFBToActiveGLTexture
This potentially saves a redundant glTexSubImage2D call, with a slight net reduction in lines of code.
This commit is contained in:
parent
81fa66e9a8
commit
d7630f97cc
2 changed files with 36 additions and 33 deletions
|
@ -59,8 +59,6 @@ void RendererOpenGL::SwapBuffers() {
|
||||||
render_window->MakeCurrent();
|
render_window->MakeCurrent();
|
||||||
|
|
||||||
for(int i : {0, 1}) {
|
for(int i : {0, 1}) {
|
||||||
const auto& framebuffer = GPU::g_regs.framebuffer_config[i];
|
|
||||||
|
|
||||||
u32 lcd_color_fill = 0;
|
u32 lcd_color_fill = 0;
|
||||||
// TODO: Get LCD Color Fill data from GPU (main: 0x202204, sub: 0x202A04)
|
// TODO: Get LCD Color Fill data from GPU (main: 0x202204, sub: 0x202A04)
|
||||||
|
|
||||||
|
@ -68,21 +66,19 @@ void RendererOpenGL::SwapBuffers() {
|
||||||
u8 r = (lcd_color_fill >> 0) & 0xFF;
|
u8 r = (lcd_color_fill >> 0) & 0xFF;
|
||||||
u8 g = (lcd_color_fill >> 8) & 0xFF;
|
u8 g = (lcd_color_fill >> 8) & 0xFF;
|
||||||
u8 b = (lcd_color_fill >> 16) & 0xFF;
|
u8 b = (lcd_color_fill >> 16) & 0xFF;
|
||||||
LoadColorToActiveGLTexture(r, g, b, &textures[i]);
|
LoadColorToActiveGLTexture(r, g, b, textures[i]);
|
||||||
|
|
||||||
|
// Resize the texture in case the framebuffer size has changed
|
||||||
|
textures[i].width = 1;
|
||||||
|
textures[i].height = 1;
|
||||||
} else {
|
} else {
|
||||||
if (textures[i].width != framebuffer.width || textures[i].height != framebuffer.height) {
|
const auto& framebuffer = GPU::g_regs.framebuffer_config[i];
|
||||||
// Reallocate texture if the framebuffer size has changed.
|
LoadFBToActiveGLTexture(framebuffer, textures[i]);
|
||||||
// This is expected to not happen very often and hence should not be a
|
|
||||||
// performance problem.
|
// Resize the texture in case the framebuffer size has changed
|
||||||
glBindTexture(GL_TEXTURE_2D, textures[i].handle);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, framebuffer.width, framebuffer.height, 0,
|
|
||||||
GL_BGR, GL_UNSIGNED_BYTE, nullptr);
|
|
||||||
textures[i].width = framebuffer.width;
|
textures[i].width = framebuffer.width;
|
||||||
textures[i].height = framebuffer.height;
|
textures[i].height = framebuffer.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadFBToActiveGLTexture(GPU::g_regs.framebuffer_config[i], textures[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawScreens();
|
DrawScreens();
|
||||||
|
@ -121,6 +117,13 @@ void RendererOpenGL::LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig&
|
||||||
glBindTexture(GL_TEXTURE_2D, texture.handle);
|
glBindTexture(GL_TEXTURE_2D, texture.handle);
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, (GLint)pixel_stride);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, (GLint)pixel_stride);
|
||||||
|
|
||||||
|
if (texture.width != framebuffer.width || texture.height != framebuffer.height) {
|
||||||
|
// Reallocate texture if the framebuffer size has changed.
|
||||||
|
// This is expected to not happen very often and hence should not be a
|
||||||
|
// performance problem.
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, framebuffer.width, framebuffer.height, 0,
|
||||||
|
GL_BGR, GL_UNSIGNED_BYTE, framebuffer_data);
|
||||||
|
} else {
|
||||||
// Update existing texture
|
// Update existing texture
|
||||||
// TODO: Test what happens on hardware when you change the framebuffer dimensions so that they
|
// TODO: Test what happens on hardware when you change the framebuffer dimensions so that they
|
||||||
// differ from the LCD resolution.
|
// differ from the LCD resolution.
|
||||||
|
@ -128,31 +131,30 @@ void RendererOpenGL::LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig&
|
||||||
// framebuffer sizes. We should make sure that this cannot happen.
|
// framebuffer sizes. We should make sure that this cannot happen.
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, framebuffer.width, framebuffer.height,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, framebuffer.width, framebuffer.height,
|
||||||
GL_BGR, GL_UNSIGNED_BYTE, framebuffer_data);
|
GL_BGR, GL_UNSIGNED_BYTE, framebuffer_data);
|
||||||
|
}
|
||||||
|
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates 1x1 framebuffer from color, loads into the active OpenGL texture.
|
* 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.
|
* Since the color is solid, the texture can be 1x1 but will stretch across whatever it's rendered on.
|
||||||
* This has the added benefit of being *really fast*.
|
* This has the added benefit of being *really fast*.
|
||||||
*/
|
*/
|
||||||
void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, TextureInfo* texture) {
|
void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b,
|
||||||
glBindTexture(GL_TEXTURE_2D, texture->handle);
|
const TextureInfo& texture) {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture.handle);
|
||||||
|
|
||||||
u8 framebuffer_data[3] = { color_r, color_g, color_b };
|
u8 framebuffer_data[3] = { color_r, color_g, color_b };
|
||||||
|
|
||||||
if (texture->width != 1 || texture->height != 1) {
|
if (texture.width != 1 || texture.height != 1) {
|
||||||
// Reallocate texture if the framebuffer size has changed.
|
// Reallocate texture if the framebuffer size has changed.
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
|
||||||
GL_RGB, GL_UNSIGNED_BYTE, framebuffer_data);
|
GL_RGB, GL_UNSIGNED_BYTE, framebuffer_data);
|
||||||
texture->width = 1;
|
|
||||||
texture->height = 1;
|
|
||||||
} else {
|
} else {
|
||||||
// Update existing texture
|
// Update existing texture
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height,
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture.width, texture.height,
|
||||||
GL_RGB, GL_UNSIGNED_BYTE, framebuffer_data);
|
GL_RGB, GL_UNSIGNED_BYTE, framebuffer_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,9 @@ private:
|
||||||
// Loads framebuffer from emulated memory into the active OpenGL texture.
|
// Loads framebuffer from emulated memory into the active OpenGL texture.
|
||||||
static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer,
|
static void LoadFBToActiveGLTexture(const GPU::Regs::FramebufferConfig& framebuffer,
|
||||||
const TextureInfo& texture);
|
const TextureInfo& texture);
|
||||||
// Creates 1x1 framebuffer from color, loads into the active OpenGL texture.
|
// Fills active OpenGL texture with the given RGB color.
|
||||||
static void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, TextureInfo* texture);
|
static void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b,
|
||||||
|
const TextureInfo& texture);
|
||||||
|
|
||||||
EmuWindow* render_window; ///< Handle to render window
|
EmuWindow* render_window; ///< Handle to render window
|
||||||
u32 last_mode; ///< Last render mode
|
u32 last_mode; ///< Last render mode
|
||||||
|
@ -64,7 +65,7 @@ private:
|
||||||
GLuint vertex_array_handle;
|
GLuint vertex_array_handle;
|
||||||
GLuint vertex_buffer_handle;
|
GLuint vertex_buffer_handle;
|
||||||
GLuint program_id;
|
GLuint program_id;
|
||||||
std::array<TextureInfo, 2> textures; // main, sub respectively
|
std::array<TextureInfo, 2> textures; // main and sub respectively
|
||||||
// Shader uniform location indices
|
// Shader uniform location indices
|
||||||
GLuint uniform_modelview_matrix;
|
GLuint uniform_modelview_matrix;
|
||||||
GLuint uniform_color_texture;
|
GLuint uniform_color_texture;
|
||||||
|
|
Loading…
Reference in a new issue