From b849c5b1c375b6239ac0ae9a974da2dde833d803 Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 18 Feb 2016 02:13:47 +0000 Subject: [PATCH] OpenGL Renderer: - Fix bug where if converting the framebuffer on GPU is not supported, but PBO is still supported, then the resulting framebuffer would be flipped with incorrect colors. (Regression from r5359.) - Read back the pixels in RGBA format instead of BGRA on OpenGL 3.2 devices, since such devices should natively support that type of pixel transfer. --- desmume/src/OGLRender.cpp | 2 +- desmume/src/OGLRender_3_2.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 8e31d0d8d..da8d56232 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -1115,7 +1115,7 @@ Render3DError OpenGLRenderer::FlushFramebuffer(const FragmentColor *__restrict s FragmentColor* OpenGLRenderer::GetFramebuffer() { - return (this->_mappedFramebuffer != NULL) ? this->_mappedFramebuffer : GPU->GetEngineMain()->Get3DFramebufferRGBA6665(); + return (this->willConvertFramebufferOnGPU) ? this->_mappedFramebuffer : GPU->GetEngineMain()->Get3DFramebufferRGBA6665(); } OpenGLRenderer_1_2::~OpenGLRenderer_1_2() diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index f908deb64..ae17079f2 100644 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -466,9 +466,7 @@ static const char *FramebufferOutputFragShader_150 = {"\ \n\ void main()\n\ {\n\ - // Note that we swap B and R since pixel readbacks are done in BGRA format for fastest\n\ - // performance. The final color is still in RGBA format.\n\ - vec4 colorRGBA6665 = texture(texInFragColor, texCoord).bgra;\n\ + vec4 colorRGBA6665 = texture(texInFragColor, texCoord);\n\ colorRGBA6665 = floor((colorRGBA6665 * 255.0) + 0.5);\n\ colorRGBA6665.rgb = floor(colorRGBA6665.rgb / 4.0);\n\ colorRGBA6665.a = floor(colorRGBA6665.a / 8.0);\n\ @@ -1281,7 +1279,7 @@ Render3DError OpenGLRenderer_3_2::ReadBackPixels() // Read back the pixels. glReadBuffer(GL_COLOR_ATTACHMENT2); - glReadPixels(0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0); + glReadPixels(0, 0, this->_framebufferWidth, this->_framebufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0); // Set the read and draw target buffers back to color attachment 0, which is always the default. glReadBuffer(GL_COLOR_ATTACHMENT0);