From 0a78fa2a2b27ad5ebeec01474de24ba34c243b24 Mon Sep 17 00:00:00 2001 From: rogerman Date: Thu, 1 Aug 2024 00:11:05 -0700 Subject: [PATCH] OpenGL Renderer: Fix a few bugs here and there. - Fix a compiling bug for ES due to missing tokens. - Fix Fog and Edge Mark feature availability when running legacy OpenGL. (Regressions from commit 0c7cb99 and commit 8b5ac56.) - glDrawBuffer() now determines its own algorithm at runtime instead of at compile time. This change is being done to be consistent with all of the other Standard vs ES changes. --- desmume/src/OGLRender.cpp | 12 ++++--- desmume/src/OGLRender.h | 70 +++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 40ecfecb5..28eadf5f2 100644 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -2298,16 +2298,18 @@ OpenGLRenderer_1_2::OpenGLRenderer_1_2() _geometryAttachmentPolyID = GeometryAttachmentPolyIDStandard; _geometryAttachmentFogAttributes = GeometryAttachmentFogAttributesStandard; -#if MSB_FIRST +#if defined(GL_VERSION_1_2) + #if MSB_FIRST ref->textureSrcTypeCIColor = GL_UNSIGNED_SHORT_1_5_5_5_REV; ref->textureSrcTypeCIFog = GL_UNSIGNED_INT_8_8_8_8_REV; ref->textureSrcTypeEdgeColor = GL_UNSIGNED_INT_8_8_8_8; ref->textureSrcTypeToonTable = GL_UNSIGNED_SHORT_1_5_5_5_REV; -#else + #else ref->textureSrcTypeCIColor = GL_UNSIGNED_SHORT_1_5_5_5_REV; ref->textureSrcTypeCIFog = GL_UNSIGNED_INT_8_8_8_8_REV; ref->textureSrcTypeEdgeColor = GL_UNSIGNED_INT_8_8_8_8_REV; ref->textureSrcTypeToonTable = GL_UNSIGNED_SHORT_1_5_5_5_REV; + #endif #endif } @@ -2606,7 +2608,7 @@ Render3DError OpenGLRenderer_1_2::InitExtensions() // Set rendering support flags based on driver features. this->willFlipAndConvertFramebufferOnGPU = this->isShaderSupported && this->isVBOSupported; this->_deviceInfo.isEdgeMarkSupported = this->isShaderSupported && this->isVBOSupported && this->isFBOSupported; - this->_deviceInfo.isFogSupported = this->isShaderSupported && this->isVBOSupported; + this->_deviceInfo.isFogSupported = this->isShaderSupported && this->isVBOSupported && this->isFBOSupported; this->_deviceInfo.isTextureSmoothingSupported = this->isShaderSupported; this->_isDepthLEqualPolygonFacingSupported = this->isShaderSupported && this->isVBOSupported && this->isFBOSupported; @@ -3174,8 +3176,8 @@ Render3DError OpenGLRenderer_1_2::CreateGeometryPrograms() shaderFlags << "#define ENABLE_ALPHA_TEST " << ((programFlags.EnableAlphaTest) ? "true\n" : "false\n"); shaderFlags << "#define ENABLE_TEXTURE_SAMPLING " << ((programFlags.EnableTextureSampling) ? "true\n" : "false\n"); shaderFlags << "#define TOON_SHADING_MODE " << ((programFlags.ToonShadingMode) ? 1 : 0) << "\n"; - shaderFlags << "#define ENABLE_FOG " << ((programFlags.EnableFog && this->_deviceInfo.isFogSupported) ? 1 : 0) << "\n"; - shaderFlags << "#define ENABLE_EDGE_MARK " << ((programFlags.EnableEdgeMark && this->_deviceInfo.isEdgeMarkSupported) ? 1 : 0) << "\n"; + shaderFlags << "#define ENABLE_FOG " << ((programFlags.EnableFog && this->isVBOSupported && this->isFBOSupported) ? 1 : 0) << "\n"; // Do not rely on this->_deviceInfo.isFogSupported because it hasn't been set yet. + shaderFlags << "#define ENABLE_EDGE_MARK " << ((programFlags.EnableEdgeMark && this->isVBOSupported && this->isFBOSupported) ? 1 : 0) << "\n"; // Do not rely on this->_deviceInfo.isEdgeMarkSupported because it hasn't been set yet. shaderFlags << "#define DRAW_MODE_OPAQUE " << ((programFlags.OpaqueDrawMode && this->isVBOSupported && this->isFBOSupported) ? 1 : 0) << "\n"; shaderFlags << "\n"; shaderFlags << "#define ATTACHMENT_WORKING_BUFFER " << this->_geometryAttachmentWorkingBuffer[programFlags.DrawBuffersMode] << "\n"; diff --git a/desmume/src/OGLRender.h b/desmume/src/OGLRender.h index 049505af0..ffdd160bb 100644 --- a/desmume/src/OGLRender.h +++ b/desmume/src/OGLRender.h @@ -332,42 +332,7 @@ EXTERNOGLEXT(PFNGLDELETERENDERBUFFERSEXTPROC, glDeleteRenderbuffersEXT) // modification. In other words, these are one-to-one drop-in replacements. typedef GLclampf GLclampd; #define glClearDepth(depth) glClearDepthf(depth) - - #ifdef OPENGL_VARIANT_ES - #define glDrawBuffer glDrawBufferES - static inline void glDrawBufferES(GLenum theAttachment) - { - GLenum bufs[4] = { GL_NONE, GL_NONE, GL_NONE, GL_NONE }; - switch (theAttachment) - { - case GL_NONE: - glDrawBuffers(1, bufs); - return; - - case GL_COLOR_ATTACHMENT0: - case GL_COLOR_ATTACHMENT1: - case GL_COLOR_ATTACHMENT2: - case GL_COLOR_ATTACHMENT3: - { - const GLsizei i = theAttachment - GL_COLOR_ATTACHMENT0; - bufs[i] = theAttachment; - glDrawBuffers(i+1, bufs); - return; - } - default: - return; - } - } - #else - #define glDrawBuffer glDrawBufferDESMUME - static inline void glDrawBufferDESMUME(GLenum theAttachment) - { - GLenum bufs[] = { theAttachment }; - glDrawBuffers(1, bufs); - } - #endif - // 1D textures may not exist for a particular OpenGL variant, so they will be promoted to // 2D textures instead. Implementations need to modify their GLSL shaders accordingly to // treat any 1D textures as 2D textures instead. @@ -824,6 +789,41 @@ extern void (*OGLCreateRenderer_ES_3_0_Func)(OpenGLRenderer **rendererPtr); bool IsOpenGLDriverVersionSupported(unsigned int checkVersionMajor, unsigned int checkVersionMinor, unsigned int checkVersionRevision); +#define glDrawBuffer(theAttachment) glDrawBufferDESMUME((theAttachment), this->_variantID) +static inline void glDrawBufferDESMUME(GLenum theAttachment, const OpenGLVariantID variantID) +{ + GLenum bufs[4] = { GL_NONE, GL_NONE, GL_NONE, GL_NONE }; + + if (variantID & OpenGLVariantFamily_ES) + { + switch (theAttachment) + { + case GL_NONE: + glDrawBuffers(1, bufs); + return; + + case GL_COLOR_ATTACHMENT0: + case GL_COLOR_ATTACHMENT1: + case GL_COLOR_ATTACHMENT2: + case GL_COLOR_ATTACHMENT3: + { + const GLsizei i = theAttachment - GL_COLOR_ATTACHMENT0; + bufs[i] = theAttachment; + glDrawBuffers(i+1, bufs); + return; + } + + default: + return; + } + } + else + { + bufs[0] = theAttachment; + glDrawBuffers(1, bufs); + } +} + class OpenGLTexture : public Render3DTexture { protected: