Skip to content

Commit

Permalink
OpenGL Renderer: Fix a few bugs here and there.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
rogerman committed Aug 1, 2024
1 parent 2f177d1 commit 0a78fa2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
12 changes: 7 additions & 5 deletions desmume/src/OGLRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
70 changes: 35 additions & 35 deletions desmume/src/OGLRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0a78fa2

Please sign in to comment.