diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 3ec6f9908..5c609dce3 100755 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -1295,7 +1295,6 @@ OpenGLRenderer::OpenGLRenderer() _needsZeroDstAlphaPass = true; _currentPolyIndex = 0; _enableAlphaBlending = true; - _lastTextureDrawTarget = OGLTextureUnitID_GColor; _geometryProgramFlags.value = 0; _fogProgramKey.key = 0; _fogProgramMap.clear(); @@ -3509,7 +3508,7 @@ void OpenGLRenderer_1_2::DestroyFogPrograms() } } -Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) +Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString) { Render3DError error = OGLERROR_NOERR; OGLRenderRef &OGLRef = *this->ref; @@ -3528,7 +3527,7 @@ Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput6665Program(const size_ error = this->ShaderProgramCreate(OGLRef.vertexFramebufferOutput6665ShaderID, OGLRef.fragmentFramebufferRGBA6665OutputShaderID, - OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], + OGLRef.programFramebufferRGBA6665OutputID, vtxShaderCode.c_str(), fragShaderCString); if (error != OGLERROR_NOERR) @@ -3539,11 +3538,11 @@ Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput6665Program(const size_ return error; } - glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], OGLVertexAttributeID_Position, "inPosition"); - glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], OGLVertexAttributeID_TexCoord0, "inTexCoord0"); + glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID, OGLVertexAttributeID_Position, "inPosition"); + glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID, OGLVertexAttributeID_TexCoord0, "inTexCoord0"); - glLinkProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); - if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex])) + glLinkProgram(OGLRef.programFramebufferRGBA6665OutputID); + if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA6665OutputID)) { INFO("OpenGL: Failed to link the FRAMEBUFFER OUTPUT RGBA6665 shader program.\n"); glUseProgram(0); @@ -3551,17 +3550,19 @@ Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput6665Program(const size_ return OGLERROR_SHADER_CREATE_ERROR; } - glValidateProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); - glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); + glValidateProgram(OGLRef.programFramebufferRGBA6665OutputID); + glUseProgram(OGLRef.programFramebufferRGBA6665OutputID); - const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], "texInFragColor"); - if (outColorIndex == 0) + const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA6665OutputID, "texInFragColor"); + if (this->isFBOSupported) { - glUniform1i(uniformTexGColor, OGLTextureUnitID_FinalColor); + glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); } else { - glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); + // Reading back the output framebuffer without FBOs requires + // sampling from the working buffer. + glUniform1i(uniformTexGColor, OGLTextureUnitID_FinalColor); } return OGLERROR_NOERR; @@ -3576,20 +3577,12 @@ void OpenGLRenderer_1_2::DestroyFramebufferOutput6665Programs() return; } - if (OGLRef.programFramebufferRGBA6665OutputID[0] != 0) + if (OGLRef.programFramebufferRGBA6665OutputID != 0) { - glDetachShader(OGLRef.programFramebufferRGBA6665OutputID[0], OGLRef.vertexFramebufferOutput6665ShaderID); - glDetachShader(OGLRef.programFramebufferRGBA6665OutputID[0], OGLRef.fragmentFramebufferRGBA6665OutputShaderID); - glDeleteProgram(OGLRef.programFramebufferRGBA6665OutputID[0]); - OGLRef.programFramebufferRGBA6665OutputID[0] = 0; - } - - if (OGLRef.programFramebufferRGBA6665OutputID[1] != 0) - { - glDetachShader(OGLRef.programFramebufferRGBA6665OutputID[1], OGLRef.vertexFramebufferOutput6665ShaderID); - glDetachShader(OGLRef.programFramebufferRGBA6665OutputID[1], OGLRef.fragmentFramebufferRGBA6665OutputShaderID); - glDeleteProgram(OGLRef.programFramebufferRGBA6665OutputID[1]); - OGLRef.programFramebufferRGBA6665OutputID[1] = 0; + glDetachShader(OGLRef.programFramebufferRGBA6665OutputID, OGLRef.vertexFramebufferOutput6665ShaderID); + glDetachShader(OGLRef.programFramebufferRGBA6665OutputID, OGLRef.fragmentFramebufferRGBA6665OutputShaderID); + glDeleteProgram(OGLRef.programFramebufferRGBA6665OutputID); + OGLRef.programFramebufferRGBA6665OutputID = 0; } glDeleteShader(OGLRef.vertexFramebufferOutput6665ShaderID); @@ -3598,7 +3591,7 @@ void OpenGLRenderer_1_2::DestroyFramebufferOutput6665Programs() OGLRef.fragmentFramebufferRGBA6665OutputShaderID = 0; } -Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput8888Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) +Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput8888Program(const char *vtxShaderCString, const char *fragShaderCString) { Render3DError error = OGLERROR_NOERR; OGLRenderRef &OGLRef = *this->ref; @@ -3617,7 +3610,7 @@ Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput8888Program(const size_ error = this->ShaderProgramCreate(OGLRef.vertexFramebufferOutput8888ShaderID, OGLRef.fragmentFramebufferRGBA8888OutputShaderID, - OGLRef.programFramebufferRGBA8888OutputID[outColorIndex], + OGLRef.programFramebufferRGBA8888OutputID, vtxShaderCode.c_str(), fragShaderCString); if (error != OGLERROR_NOERR) @@ -3628,11 +3621,11 @@ Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput8888Program(const size_ return error; } - glBindAttribLocation(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex], OGLVertexAttributeID_Position, "inPosition"); - glBindAttribLocation(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex], OGLVertexAttributeID_TexCoord0, "inTexCoord0"); + glBindAttribLocation(OGLRef.programFramebufferRGBA8888OutputID, OGLVertexAttributeID_Position, "inPosition"); + glBindAttribLocation(OGLRef.programFramebufferRGBA8888OutputID, OGLVertexAttributeID_TexCoord0, "inTexCoord0"); - glLinkProgram(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex]); - if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex])) + glLinkProgram(OGLRef.programFramebufferRGBA8888OutputID); + if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA8888OutputID)) { INFO("OpenGL: Failed to link the FRAMEBUFFER OUTPUT RGBA8888 shader program.\n"); glUseProgram(0); @@ -3640,17 +3633,19 @@ Render3DError OpenGLRenderer_1_2::CreateFramebufferOutput8888Program(const size_ return OGLERROR_SHADER_CREATE_ERROR; } - glValidateProgram(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex]); - glUseProgram(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex]); + glValidateProgram(OGLRef.programFramebufferRGBA8888OutputID); + glUseProgram(OGLRef.programFramebufferRGBA8888OutputID); - const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA8888OutputID[outColorIndex], "texInFragColor"); - if (outColorIndex == 0) + const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA8888OutputID, "texInFragColor"); + if (this->isFBOSupported) { - glUniform1i(uniformTexGColor, OGLTextureUnitID_FinalColor); + glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); } else { - glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); + // Reading back the output framebuffer without FBOs requires + // sampling from the working buffer. + glUniform1i(uniformTexGColor, OGLTextureUnitID_FinalColor); } return OGLERROR_NOERR; @@ -3665,20 +3660,12 @@ void OpenGLRenderer_1_2::DestroyFramebufferOutput8888Programs() return; } - if (OGLRef.programFramebufferRGBA8888OutputID[0] != 0) + if (OGLRef.programFramebufferRGBA8888OutputID != 0) { - glDetachShader(OGLRef.programFramebufferRGBA8888OutputID[0], OGLRef.vertexFramebufferOutput8888ShaderID); - glDetachShader(OGLRef.programFramebufferRGBA8888OutputID[0], OGLRef.fragmentFramebufferRGBA8888OutputShaderID); - glDeleteProgram(OGLRef.programFramebufferRGBA8888OutputID[0]); - OGLRef.programFramebufferRGBA8888OutputID[0] = 0; - } - - if (OGLRef.programFramebufferRGBA8888OutputID[1] != 0) - { - glDetachShader(OGLRef.programFramebufferRGBA8888OutputID[1], OGLRef.vertexFramebufferOutput8888ShaderID); - glDetachShader(OGLRef.programFramebufferRGBA8888OutputID[1], OGLRef.fragmentFramebufferRGBA8888OutputShaderID); - glDeleteProgram(OGLRef.programFramebufferRGBA8888OutputID[1]); - OGLRef.programFramebufferRGBA8888OutputID[1] = 0; + glDetachShader(OGLRef.programFramebufferRGBA8888OutputID, OGLRef.vertexFramebufferOutput8888ShaderID); + glDetachShader(OGLRef.programFramebufferRGBA8888OutputID, OGLRef.fragmentFramebufferRGBA8888OutputShaderID); + glDeleteProgram(OGLRef.programFramebufferRGBA8888OutputID); + OGLRef.programFramebufferRGBA8888OutputID = 0; } glDeleteShader(OGLRef.vertexFramebufferOutput8888ShaderID); @@ -3739,25 +3726,13 @@ Render3DError OpenGLRenderer_1_2::InitPostprocessingPrograms(const char *edgeMar } } - error = this->CreateFramebufferOutput6665Program(0, framebufferOutputVtxShaderCString, framebufferOutputRGBA6665FragShaderCString); + error = this->CreateFramebufferOutput6665Program(framebufferOutputVtxShaderCString, framebufferOutputRGBA6665FragShaderCString); if (error != OGLERROR_NOERR) { return error; } - error = this->CreateFramebufferOutput6665Program(1, framebufferOutputVtxShaderCString, framebufferOutputRGBA6665FragShaderCString); - if (error != OGLERROR_NOERR) - { - return error; - } - - error = this->CreateFramebufferOutput8888Program(0, framebufferOutputVtxShaderCString, framebufferOutputRGBA8888FragShaderCString); - if (error != OGLERROR_NOERR) - { - return error; - } - - error = this->CreateFramebufferOutput8888Program(1, framebufferOutputVtxShaderCString, framebufferOutputRGBA8888FragShaderCString); + error = this->CreateFramebufferOutput8888Program(framebufferOutputVtxShaderCString, framebufferOutputRGBA8888FragShaderCString); if (error != OGLERROR_NOERR) { return error; @@ -4126,32 +4101,17 @@ Render3DError OpenGLRenderer_1_2::ReadBackPixels() // should be necessary at this point. if (this->willFlipAndConvertFramebufferOnGPU) { + const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID : OGLRef.programFramebufferRGBA8888OutputID; + glUseProgram(convertProgramID); + if (this->isFBOSupported) { - if (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor) - { - const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[1] : OGLRef.programFramebufferRGBA8888OutputID[1]; - glUseProgram(convertProgramID); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); - glReadBuffer(OGL_WORKING_ATTACHMENT_ID); - glDrawBuffer(OGL_WORKING_ATTACHMENT_ID); - this->_lastTextureDrawTarget = OGLTextureUnitID_FinalColor; - } - else - { - const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[0] : OGLRef.programFramebufferRGBA8888OutputID[0]; - glUseProgram(convertProgramID); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); - glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID); - glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID); - this->_lastTextureDrawTarget = OGLTextureUnitID_GColor; - } + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, OGLRef.fboRenderID); + glReadBuffer(OGL_WORKING_ATTACHMENT_ID); + glDrawBuffer(OGL_WORKING_ATTACHMENT_ID); } else { - const GLuint convertProgramID = (this->_outputFormat == NDSColorFormat_BGR666_Rev) ? OGLRef.programFramebufferRGBA6665OutputID[0] : OGLRef.programFramebufferRGBA8888OutputID[0]; - glUseProgram(convertProgramID); - glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FinalColor); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight); glActiveTexture(GL_TEXTURE0); @@ -4563,7 +4523,6 @@ Render3DError OpenGLRenderer_1_2::RenderGeometry() if (!this->_willUseMultisampleShaders) { this->_ResolveGeometry(); - this->_lastTextureDrawTarget = OGLTextureUnitID_GColor; } return OGLERROR_NOERR; @@ -4716,7 +4675,6 @@ Render3DError OpenGLRenderer_1_2::EndRender() if (this->_willUseMultisampleShaders) { this->_ResolveFinalFramebuffer(); - this->_lastTextureDrawTarget = OGLTextureUnitID_GColor; } this->ReadBackPixels(); @@ -5459,17 +5417,13 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h) if (OGLRef.readPixelsBestFormat == GL_BGRA) { - this->CreateFramebufferOutput6665Program(0, FramebufferOutputVtxShader_100, FramebufferOutputBGRA6665FragShader_100); - this->CreateFramebufferOutput6665Program(1, FramebufferOutputVtxShader_100, FramebufferOutputBGRA6665FragShader_100); - this->CreateFramebufferOutput8888Program(0, FramebufferOutputVtxShader_100, FramebufferOutputBGRA8888FragShader_100); - this->CreateFramebufferOutput8888Program(1, FramebufferOutputVtxShader_100, FramebufferOutputBGRA8888FragShader_100); + this->CreateFramebufferOutput6665Program(FramebufferOutputVtxShader_100, FramebufferOutputBGRA6665FragShader_100); + this->CreateFramebufferOutput8888Program(FramebufferOutputVtxShader_100, FramebufferOutputBGRA8888FragShader_100); } else { - this->CreateFramebufferOutput6665Program(0, FramebufferOutputVtxShader_100, FramebufferOutputRGBA6665FragShader_100); - this->CreateFramebufferOutput6665Program(1, FramebufferOutputVtxShader_100, FramebufferOutputRGBA6665FragShader_100); - this->CreateFramebufferOutput8888Program(0, FramebufferOutputVtxShader_100, FramebufferOutputRGBA8888FragShader_100); - this->CreateFramebufferOutput8888Program(1, FramebufferOutputVtxShader_100, FramebufferOutputRGBA8888FragShader_100); + this->CreateFramebufferOutput6665Program(FramebufferOutputVtxShader_100, FramebufferOutputRGBA6665FragShader_100); + this->CreateFramebufferOutput8888Program(FramebufferOutputVtxShader_100, FramebufferOutputRGBA8888FragShader_100); } } diff --git a/desmume/src/OGLRender.h b/desmume/src/OGLRender.h index 2ab880d14..c3f8ebc2e 100755 --- a/desmume/src/OGLRender.h +++ b/desmume/src/OGLRender.h @@ -673,8 +673,8 @@ struct OGLRenderRef GLuint fragmentFramebufferRGBA6665OutputShaderID; GLuint fragmentFramebufferRGBA8888OutputShaderID; GLuint programEdgeMarkID; - GLuint programFramebufferRGBA6665OutputID[2]; - GLuint programFramebufferRGBA8888OutputID[2]; + GLuint programFramebufferRGBA6665OutputID; + GLuint programFramebufferRGBA8888OutputID; GLint uniformStateEnableFogAlphaOnly; GLint uniformStateClearPolyID; @@ -891,7 +891,6 @@ protected: bool _needsZeroDstAlphaPass; size_t _currentPolyIndex; bool _enableAlphaBlending; - OGLTextureUnitID _lastTextureDrawTarget; OGLGeometryFlags _geometryProgramFlags; OGLFogProgramKey _fogProgramKey; std::map _fogProgramMap; @@ -946,9 +945,9 @@ protected: virtual Render3DError CreateFogProgram(const OGLFogProgramKey fogProgramKey, const bool isMultisample, const char *vtxShaderCString, const char *fragShaderCString) = 0; virtual void DestroyFogProgram(const OGLFogProgramKey fogProgramKey) = 0; virtual void DestroyFogPrograms() = 0; - virtual Render3DError CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) = 0; + virtual Render3DError CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString) = 0; virtual void DestroyFramebufferOutput6665Programs() = 0; - virtual Render3DError CreateFramebufferOutput8888Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) = 0; + virtual Render3DError CreateFramebufferOutput8888Program(const char *vtxShaderCString, const char *fragShaderCString) = 0; virtual void DestroyFramebufferOutput8888Programs() = 0; virtual Render3DError InitFinalRenderStates(const std::set *oglExtensionSet) = 0; @@ -1024,9 +1023,9 @@ protected: virtual Render3DError CreateFogProgram(const OGLFogProgramKey fogProgramKey, const bool isMultisample, const char *vtxShaderCString, const char *fragShaderCString); virtual void DestroyFogProgram(const OGLFogProgramKey fogProgramKey); virtual void DestroyFogPrograms(); - virtual Render3DError CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString); + virtual Render3DError CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString); virtual void DestroyFramebufferOutput6665Programs(); - virtual Render3DError CreateFramebufferOutput8888Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString); + virtual Render3DError CreateFramebufferOutput8888Program(const char *vtxShaderCString, const char *fragShaderCString); virtual void DestroyFramebufferOutput8888Programs(); virtual Render3DError InitFinalRenderStates(const std::set *oglExtensionSet); diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index 86ac25951..263efc655 100755 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -2201,7 +2201,7 @@ Render3DError OpenGLRenderer_3_2::CreateFogProgram(const OGLFogProgramKey fogPro return OGLERROR_NOERR; } -Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) +Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString) { Render3DError error = OGLERROR_NOERR; OGLRenderRef &OGLRef = *this->ref; @@ -2254,7 +2254,7 @@ Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput6665Program(const size_ error = this->ShaderProgramCreate(OGLRef.vertexFramebufferOutput6665ShaderID, OGLRef.fragmentFramebufferRGBA6665OutputShaderID, - OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], + OGLRef.programFramebufferRGBA6665OutputID, vtxShaderCode.c_str(), fragShaderCode.c_str()); if (error != OGLERROR_NOERR) @@ -2268,14 +2268,14 @@ Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput6665Program(const size_ #if defined(GL_VERSION_3_0) if (!this->_isShaderFixedLocationSupported) { - glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], OGLVertexAttributeID_Position, "inPosition"); - glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], OGLVertexAttributeID_TexCoord0, "inTexCoord0"); - glBindFragDataLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], 0, "outFragColor6665"); + glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID, OGLVertexAttributeID_Position, "inPosition"); + glBindAttribLocation(OGLRef.programFramebufferRGBA6665OutputID, OGLVertexAttributeID_TexCoord0, "inTexCoord0"); + glBindFragDataLocation(OGLRef.programFramebufferRGBA6665OutputID, 0, "outFragColor6665"); } #endif - glLinkProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); - if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex])) + glLinkProgram(OGLRef.programFramebufferRGBA6665OutputID); + if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA6665OutputID)) { INFO("OpenGL: Failed to link the FRAMEBUFFER OUTPUT RGBA6665 shader program.\n"); glUseProgram(0); @@ -2283,26 +2283,19 @@ Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput6665Program(const size_ return OGLERROR_SHADER_CREATE_ERROR; } - glValidateProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); - glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); + glValidateProgram(OGLRef.programFramebufferRGBA6665OutputID); + glUseProgram(OGLRef.programFramebufferRGBA6665OutputID); - const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], "texInFragColor"); - if (outColorIndex == 0) - { - glUniform1i(uniformTexGColor, OGLTextureUnitID_FinalColor); - } - else - { - glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); - } + const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA6665OutputID, "texInFragColor"); + glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); return OGLERROR_NOERR; } -Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput8888Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) +Render3DError OpenGLRenderer_3_2::CreateFramebufferOutput8888Program(const char *vtxShaderCString, const char *fragShaderCString) { OGLRenderRef &OGLRef = *this->ref; - OGLRef.programFramebufferRGBA8888OutputID[outColorIndex] = 0; + OGLRef.programFramebufferRGBA8888OutputID = 0; OGLRef.vertexFramebufferOutput8888ShaderID = 0; OGLRef.fragmentFramebufferRGBA8888OutputShaderID = 0; @@ -2507,24 +2500,10 @@ Render3DError OpenGLRenderer_3_2::ReadBackPixels() { // Both flips and converts the framebuffer on the GPU. No additional postprocessing // should be necessary at this point. - if (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor) - { - // Use the alternate program where the output color is not at index 0. - glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[1]); - glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); - glReadBuffer(OGL_WORKING_ATTACHMENT_ID); - glDrawBuffer(OGL_WORKING_ATTACHMENT_ID); - this->_lastTextureDrawTarget = OGLTextureUnitID_FinalColor; - } - else - { - // Use the program where the output color is from index 0. - glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[0]); - glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); - glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID); - glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID); - this->_lastTextureDrawTarget = OGLTextureUnitID_GColor; - } + glUseProgram(OGLRef.programFramebufferRGBA6665OutputID); + glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); + glReadBuffer(OGL_WORKING_ATTACHMENT_ID); + glDrawBuffer(OGL_WORKING_ATTACHMENT_ID); glViewport(0, 0, (GLsizei)this->_framebufferWidth, (GLsizei)this->_framebufferHeight); glDisable(GL_DEPTH_TEST); @@ -2540,25 +2519,10 @@ Render3DError OpenGLRenderer_3_2::ReadBackPixels() { // Just flips the framebuffer in Y to match the coordinates of OpenGL and the NDS hardware. glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); - if (this->_lastTextureDrawTarget == OGLTextureUnitID_GColor) - { - glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID); - glDrawBuffer(OGL_WORKING_ATTACHMENT_ID); - glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); - glReadBuffer(OGL_WORKING_ATTACHMENT_ID); - - this->_lastTextureDrawTarget = OGLTextureUnitID_FinalColor; - } - else - { - glBindFramebuffer(GL_FRAMEBUFFER, OGLRef.fboRenderID); - glReadBuffer(OGL_WORKING_ATTACHMENT_ID); - glDrawBuffer(OGL_COLOROUT_ATTACHMENT_ID); - glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); - glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID); - - this->_lastTextureDrawTarget = OGLTextureUnitID_GColor; - } + glReadBuffer(OGL_COLOROUT_ATTACHMENT_ID); + glDrawBuffer(OGL_WORKING_ATTACHMENT_ID); + glBlitFramebuffer(0, (GLint)this->_framebufferHeight, (GLint)this->_framebufferWidth, 0, 0, 0, (GLint)this->_framebufferWidth, (GLint)this->_framebufferHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glReadBuffer(OGL_WORKING_ATTACHMENT_ID); } // Read back the pixels in RGBA format, since an OpenGL 3.2 device should be able to read back this @@ -3273,8 +3237,7 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h) this->DestroyFogPrograms(); } - this->CreateFramebufferOutput6665Program(0, FramebufferOutputVtxShader_150, FramebufferOutput6665FragShader_150); - this->CreateFramebufferOutput6665Program(1, FramebufferOutputVtxShader_150, FramebufferOutput6665FragShader_150); + this->CreateFramebufferOutput6665Program(FramebufferOutputVtxShader_150, FramebufferOutput6665FragShader_150); // Call ResizeMultisampledFBOs() after _framebufferWidth and _framebufferHeight are set // since this method depends on them. diff --git a/desmume/src/OGLRender_3_2.h b/desmume/src/OGLRender_3_2.h index 478a77342..7d8ab2f7c 100644 --- a/desmume/src/OGLRender_3_2.h +++ b/desmume/src/OGLRender_3_2.h @@ -90,8 +90,8 @@ protected: virtual void DestroyMSGeometryZeroDstAlphaProgram(); virtual Render3DError CreateEdgeMarkProgram(const bool isMultisample, const char *vtxShaderCString, const char *fragShaderCString); virtual Render3DError CreateFogProgram(const OGLFogProgramKey fogProgramKey, const bool isMultisample, const char *vtxShaderCString, const char *fragShaderCString); - virtual Render3DError CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString); - virtual Render3DError CreateFramebufferOutput8888Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString); + virtual Render3DError CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString); + virtual Render3DError CreateFramebufferOutput8888Program(const char *vtxShaderCString, const char *fragShaderCString); virtual void GetExtensionSet(std::set *oglExtensionSet); virtual void _SetupGeometryShaders(const OGLGeometryFlags flags); diff --git a/desmume/src/OGLRender_ES3.cpp b/desmume/src/OGLRender_ES3.cpp index 8c1ff5f64..9161ff147 100644 --- a/desmume/src/OGLRender_ES3.cpp +++ b/desmume/src/OGLRender_ES3.cpp @@ -932,7 +932,7 @@ Render3DError OpenGLESRenderer_3_0::CreateFogProgram(const OGLFogProgramKey fogP return OGLERROR_NOERR; } -Render3DError OpenGLESRenderer_3_0::CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString) +Render3DError OpenGLESRenderer_3_0::CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString) { Render3DError error = OGLERROR_NOERR; OGLRenderRef &OGLRef = *this->ref; @@ -964,7 +964,7 @@ Render3DError OpenGLESRenderer_3_0::CreateFramebufferOutput6665Program(const siz error = this->ShaderProgramCreate(OGLRef.vertexFramebufferOutput6665ShaderID, OGLRef.fragmentFramebufferRGBA6665OutputShaderID, - OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], + OGLRef.programFramebufferRGBA6665OutputID, vtxShaderCode.c_str(), fragShaderCode.c_str()); if (error != OGLERROR_NOERR) @@ -975,8 +975,8 @@ Render3DError OpenGLESRenderer_3_0::CreateFramebufferOutput6665Program(const siz return error; } - glLinkProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); - if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex])) + glLinkProgram(OGLRef.programFramebufferRGBA6665OutputID); + if (!this->ValidateShaderProgramLink(OGLRef.programFramebufferRGBA6665OutputID)) { INFO("OpenGL ES: Failed to link the FRAMEBUFFER OUTPUT RGBA6665 shader program.\n"); glUseProgram(0); @@ -984,18 +984,11 @@ Render3DError OpenGLESRenderer_3_0::CreateFramebufferOutput6665Program(const siz return OGLERROR_SHADER_CREATE_ERROR; } - glValidateProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); - glUseProgram(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex]); + glValidateProgram(OGLRef.programFramebufferRGBA6665OutputID); + glUseProgram(OGLRef.programFramebufferRGBA6665OutputID); - const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA6665OutputID[outColorIndex], "texInFragColor"); - if (outColorIndex == 0) - { - glUniform1i(uniformTexGColor, OGLTextureUnitID_FinalColor); - } - else - { - glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); - } + const GLint uniformTexGColor = glGetUniformLocation(OGLRef.programFramebufferRGBA6665OutputID, "texInFragColor"); + glUniform1i(uniformTexGColor, OGLTextureUnitID_GColor); return OGLERROR_NOERR; } diff --git a/desmume/src/OGLRender_ES3.h b/desmume/src/OGLRender_ES3.h index eff863b32..72d5c47ab 100644 --- a/desmume/src/OGLRender_ES3.h +++ b/desmume/src/OGLRender_ES3.h @@ -48,7 +48,7 @@ protected: virtual Render3DError CreateGeometryZeroDstAlphaProgram(const char *vtxShaderCString, const char *fragShaderCString); virtual Render3DError CreateEdgeMarkProgram(const bool isMultisample, const char *vtxShaderCString, const char *fragShaderCString); virtual Render3DError CreateFogProgram(const OGLFogProgramKey fogProgramKey, const bool isMultisample, const char *vtxShaderCString, const char *fragShaderCString); - virtual Render3DError CreateFramebufferOutput6665Program(const size_t outColorIndex, const char *vtxShaderCString, const char *fragShaderCString); + virtual Render3DError CreateFramebufferOutput6665Program(const char *vtxShaderCString, const char *fragShaderCString); public: OpenGLESRenderer_3_0();