Skip to content

Commit

Permalink
[GL] Enabled GL_EXT_framebuffer_object extension in GL 2.x backend.
Browse files Browse the repository at this point in the history
- Added GL_EXT_framebuffer_object as substitute for GL_ARB_framebuffer_object in GL.
- Removed HasNativeVAO(): VAOs are always required in GL 3+, but they are excluded for GL 2.x compatibility profile.
  • Loading branch information
LukasBanana committed Sep 22, 2024
1 parent d2338b2 commit c949aa4
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 271 deletions.
4 changes: 2 additions & 2 deletions sources/Renderer/OpenGL/Command/GLCommandExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static std::size_t ExecuteGLCommand(const GLOpcode opcode, const void* pc, GLSta
case GLOpcodeDrawArraysInstanced:
{
auto cmd = reinterpret_cast<const GLCmdDrawArraysInstanced*>(pc);
#if !LLGL_GL_ENABLE_OPENGL2X
#if LLGL_GLEXT_DRAW_INSTANCED
glDrawArraysInstanced(cmd->mode, cmd->first, cmd->count, cmd->instancecount);
#endif
return sizeof(*cmd);
Expand Down Expand Up @@ -370,7 +370,7 @@ static std::size_t ExecuteGLCommand(const GLOpcode opcode, const void* pc, GLSta
case GLOpcodeDrawElementsInstanced:
{
auto cmd = reinterpret_cast<const GLCmdDrawElementsInstanced*>(pc);
#if !LLGL_GL_ENABLE_OPENGL2X
#if LLGL_GLEXT_DRAW_INSTANCED
glDrawElementsInstanced(cmd->mode, cmd->count, cmd->type, cmd->indices, cmd->instancecount);
#endif
return sizeof(*cmd);
Expand Down
4 changes: 2 additions & 2 deletions sources/Renderer/OpenGL/Command/GLImmediateCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ void GLImmediateCommandBuffer::DrawIndexed(std::uint32_t numIndices, std::uint32

void GLImmediateCommandBuffer::DrawInstanced(std::uint32_t numVertices, std::uint32_t firstVertex, std::uint32_t numInstances)
{
#if !LLGL_GL_ENABLE_OPENGL2X
#if LLGL_GLEXT_DRAW_INSTANCED
LLGL_FLUSH_MEMORY_BARRIERS();
glDrawArraysInstanced(
GetDrawMode(),
Expand All @@ -661,7 +661,7 @@ void GLImmediateCommandBuffer::DrawInstanced(std::uint32_t numVertices, std::uin

void GLImmediateCommandBuffer::DrawIndexedInstanced(std::uint32_t numIndices, std::uint32_t numInstances, std::uint32_t firstIndex)
{
#if !LLGL_GL_ENABLE_OPENGL2X
#if LLGL_GLEXT_DRAW_INSTANCED
LLGL_FLUSH_MEMORY_BARRIERS();
glDrawElementsInstanced(
GetDrawMode(),
Expand Down
24 changes: 18 additions & 6 deletions sources/Renderer/OpenGL/Ext/GLExtensionRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,28 @@ namespace LLGL

static std::array<bool, static_cast<std::size_t>(GLExt::Count)> g_registeredExtensions { { false } };

void RegisterExtension(GLExt extension)
static void RegisterExtensionInternal(GLExt extension)
{
g_registeredExtensions[static_cast<std::size_t>(extension)] = true;
}

void RegisterExtension(GLExt extension)
{
#if LLGL_GL_ENABLE_OPENGL2X
switch (extension)
{
case GLExt::EXT_framebuffer_object:
RegisterExtensionInternal(GLExt::ARB_framebuffer_object); // Substitute EXT_framebuffer_object with ARB_framebuffer_object
break;
default:
RegisterExtensionInternal(extension);
break;
}
#else // LLGL_GL_ENABLE_OPENGL2X
RegisterExtensionInternal(extension);
#endif // /LLGL_GL_ENABLE_OPENGL2X
}

bool HasExtension(const GLExt extension)
{
return g_registeredExtensions[static_cast<std::size_t>(extension)];
Expand All @@ -30,11 +47,6 @@ bool HasNativeSamplers()
return HasExtension(GLExt::ARB_sampler_objects);
}

bool HasNativeVAO()
{
return HasExtension(GLExt::ARB_vertex_array_object);
}


} // /namespace LLGL

Expand Down
6 changes: 3 additions & 3 deletions sources/Renderer/OpenGL/Ext/GLExtensionRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ enum class GLExt
/* Intel sepcific extensions (INTEL) */
INTEL_conservative_rasterization, // no procedures

/* Substitute extensions for GL 2.x only - do *not* used in HasExtension() calls! */
EXT_framebuffer_object,

/* Enumeration entry counter */
Count,
};
Expand All @@ -130,9 +133,6 @@ bool HasExtension(const GLExt extension);
// Returns ture if GL_ARB_sampler_objects is supported. Shortcut for 'HasExtension(GLExt::ARB_sampler_objects)'.
bool HasNativeSamplers();

// Returns true if GL_ARB_vertex_array_object is supported. Shortcut for 'HasExtension(GLExt::ARB_vertex_array_object)'.
bool HasNativeVAO();


} // /namespace LLGL

Expand Down
2 changes: 1 addition & 1 deletion sources/Renderer/OpenGL/GLTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ GLenum ToTextureCubeMap(std::uint32_t arrayLayer)

GLenum ToColorAttachment(std::uint32_t attachmentIndex)
{
#if !LLGL_GL_ENABLE_OPENGL2X
#if LLGL_GLEXT_FRAMEBUFFER_OBJECT
if (attachmentIndex < LLGL_MAX_NUM_COLOR_ATTACHMENTS)
{
static const GLenum g_drawBuffers[] =
Expand Down
29 changes: 8 additions & 21 deletions sources/Renderer/OpenGL/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#else // LLGL_WEBGL

#if GL_ARB_framebuffer_object || GL_EXT_framebuffer_object || GL_ES_VERSION_2_0 || GL_ES_VERSION_3_0
# define LLGL_GLEXT_FRAMEBUFFER_OBJECT 1
#endif

#if !LLGL_GL_ENABLE_OPENGL2X

#if GL_ARB_vertex_array_object || GL_ES_VERSION_3_0
Expand All @@ -36,6 +40,10 @@
# define LLGL_GLEXT_SAMPLER_OBJECTS 1
#endif

#if GL_ARB_draw_instanced || GL_ES_VERSION_3_0
# define LLGL_GLEXT_DRAW_INSTANCED 1
#endif

#if GL_ARB_separate_shader_objects || GL_ES_VERSION_3_1
# define LLGL_GLEXT_SEPARATE_SHADER_OBJECTS 1
#elif GL_EXT_separate_shader_objects
Expand Down Expand Up @@ -195,27 +203,6 @@
# define LLGL_USE_NULL_FRAGMENT_SHADER 1
#endif

#if LLGL_GL_ENABLE_OPENGL2X
# define glGenFramebuffers glGenFramebuffersEXT
# define glDeleteFramebuffers glDeleteFramebuffersEXT
# define glBindFramebuffer glBindFramebufferEXT
# define glBindRenderbuffer glBindRenderbufferEXT
# define glBlitFramebuffer glBlitFramebufferEXT
# define glFramebufferTexture1D glFramebufferTexture1DEXT
# define glFramebufferTexture2D glFramebufferTexture2DEXT
# define glFramebufferTexture3D glFramebufferTexture3DEXT
# define glFramebufferRenderbuffer glFramebufferRenderbufferEXT
# define glCheckFramebufferStatus glCheckFramebufferStatusEXT
# define glGenRenderbuffers glGenRenderbuffersEXT
# define glDeleteRenderbuffers glDeleteRenderbuffersEXT
# define glRenderbufferStorage glRenderbufferStorageEXT
# define glRenderbufferStorageMultisample glRenderbufferStorageMultisampleEXT
# define glGetRenderbufferParameteriv glGetRenderbufferParameterivEXT
# define glGetFramebufferAttachmentParameteriv glGetFramebufferAttachmentParameterivEXT
# define glGenerateMipmap glGenerateMipmapEXT
#endif


#endif


Expand Down
Loading

0 comments on commit c949aa4

Please sign in to comment.