Skip to content

Commit

Permalink
[GLES] Fixed build issue in GLES backend.
Browse files Browse the repository at this point in the history
Provide implementation for GetSupportedOpenGLExtensions() and GetLoadedOpenGLExtensions() in GLESProfile/ source files.
  • Loading branch information
LukasBanana committed Jul 5, 2024
1 parent abb17bd commit 01beccf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 48 deletions.
39 changes: 0 additions & 39 deletions sources/Renderer/OpenGL/GLCoreProfile/GLCoreProfileCaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,45 +385,6 @@ void GLQueryRenderingCaps(RenderingCapabilities& caps)
GLGetTextureLimits(caps.features, caps.limits);
}

static void AppendCacheIDBytes(std::vector<char>& cacheID, const void* bytes, std::size_t count)
{
const std::size_t offset = cacheID.size();
cacheID.resize(offset + count);
::memcpy(&cacheID[offset], bytes, count);
}

template <typename T>
static void AppendCacheIDValue(std::vector<char>& cacheID, const T& val)
{
AppendCacheIDBytes(cacheID, &val, sizeof(val));
}

void GLQueryPipelineCacheID(std::vector<char>& cacheID)
{
#ifdef GL_ARB_get_program_binary
if (HasExtension(GLExt::ARB_get_program_binary))
{
GLint numBinaryFormats = 0;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats);
if (numBinaryFormats > 0)
{
/* Append number of binary formats */
AppendCacheIDValue(cacheID, numBinaryFormats);

/* Append binary format values themselves */
std::vector<GLint> formats;
formats.resize(numBinaryFormats);
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, formats.data());
AppendCacheIDBytes(cacheID, formats.data(), sizeof(GLint) * formats.size());

/* Append GL version string */
if (const GLubyte* versionStr = glGetString(GL_VERSION))
AppendCacheIDBytes(cacheID, versionStr, ::strlen(reinterpret_cast<const char*>(versionStr)));
}
}
#endif // /GL_ARB_get_program_binary
}


} // /namespace LLGL

Expand Down
47 changes: 38 additions & 9 deletions sources/Renderer/OpenGL/GLESProfile/GLESExtensionLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,26 @@ static GLESExtensionMap QuerySupportedOpenGLExtensions(bool coreProfile)
#endif // /LLGL_OS_IOS

// Global member to store if the extension have already been loaded
static bool g_OpenGLExtensionsLoaded = false;
static bool g_OpenGLESExtensionsLoaded = false;
static GLESExtensionMap g_OpenGLESExtensionsMap;
static std::set<const char*> g_supportedOpenGLESExtensions;
static std::set<const char*> g_loadedOpenGLESExtensions;

static void EnableGLESExtension(GLExt ext, const char* name)
{
RegisterExtension(ext);
g_supportedOpenGLESExtensions.insert(name); //TODO: find better way to determine supported GLES extensions
g_loadedOpenGLESExtensions.insert(name);
}

bool LoadSupportedOpenGLExtensions(bool isCoreProfile, bool abortOnFailure)
{
/* Only load GL extensions once */
if (g_OpenGLExtensionsLoaded)
if (g_OpenGLESExtensionsLoaded)
return true;

#define ENABLE_GLEXT(NAME) \
RegisterExtension(GLExt::NAME)
EnableGLESExtension(GLExt::NAME, "GL_" #NAME)

const int version = GLGetVersion();

Expand Down Expand Up @@ -198,13 +208,14 @@ bool LoadSupportedOpenGLExtensions(bool isCoreProfile, bool abortOnFailure)

#if 0 //TODO

GLESExtensionMap extensions = QuerySupportedOpenGLExtensions(isCoreProfile);
/* Query supported OpenGL extension names */
g_OpenGLESExtensionsMap = QuerySupportedOpenGLExtensions(isCoreProfile);

auto LoadExtension = [&extensions, abortOnFailure](const char* extName, const LoadGLExtensionProc& extLoadingProc, GLExt extensionID) -> void
auto LoadExtension = [abortOnFailure](const char* extName, const LoadGLExtensionProc& extLoadingProc, GLExt extensionID) -> void
{
/* Try to load OpenGL extension */
auto it = extensions.find(extName);
if (it != extensions.end())
auto it = g_OpenGLESExtensionsMap.find(extName);
if (it != g_OpenGLESExtensionsMap.end())
{
if (extLoadingProc(extName, abortOnFailure, /*usePlaceholder:*/ false))
{
Expand Down Expand Up @@ -236,14 +247,32 @@ bool LoadSupportedOpenGLExtensions(bool isCoreProfile, bool abortOnFailure)

#endif // /TODO

g_OpenGLExtensionsLoaded = true;
/* Cache supported and loaded extensions */
g_OpenGLESExtensionsLoaded = true;

for (const auto& it : g_OpenGLESExtensionsMap)
{
g_supportedOpenGLESExtensions.insert(it.first.c_str());
if (it.second)
g_loadedOpenGLESExtensions.insert(it.first.c_str());
}

return true;
}

bool AreOpenGLExtensionsLoaded()
{
return g_OpenGLExtensionsLoaded;
return g_OpenGLESExtensionsLoaded;
}

const std::set<const char*>& GetSupportedOpenGLExtensions()
{
return g_supportedOpenGLESExtensions;
}

const std::set<const char*>& GetLoadedOpenGLExtensions()
{
return g_loadedOpenGLESExtensions;
}


Expand Down
40 changes: 40 additions & 0 deletions sources/Renderer/OpenGL/GLRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,46 @@ static void GLQueryRendererInfo(RendererInfo& info)
GLQueryPipelineCacheID(info.pipelineCacheID);
}

static void AppendCacheIDBytes(std::vector<char>& cacheID, const void* bytes, std::size_t count)
{
const std::size_t offset = cacheID.size();
cacheID.resize(offset + count);
::memcpy(&cacheID[offset], bytes, count);
}

template <typename T>
static void AppendCacheIDValue(std::vector<char>& cacheID, const T& val)
{
AppendCacheIDBytes(cacheID, &val, sizeof(val));
}

// Must not be static to be available in GL module
void GLQueryPipelineCacheID(std::vector<char>& cacheID)
{
#ifdef GL_ARB_get_program_binary
if (HasExtension(GLExt::ARB_get_program_binary))
{
GLint numBinaryFormats = 0;
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats);
if (numBinaryFormats > 0)
{
/* Append number of binary formats */
AppendCacheIDValue(cacheID, numBinaryFormats);

/* Append binary format values themselves */
std::vector<GLint> formats;
formats.resize(numBinaryFormats);
glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, formats.data());
AppendCacheIDBytes(cacheID, formats.data(), sizeof(GLint) * formats.size());

/* Append GL version string */
if (const GLubyte* versionStr = glGetString(GL_VERSION))
AppendCacheIDBytes(cacheID, versionStr, ::strlen(reinterpret_cast<const char*>(versionStr)));
}
}
#endif // /GL_ARB_get_program_binary
}

bool GLRenderSystem::QueryRendererDetails(RendererInfo* outInfo, RenderingCapabilities* outCaps)
{
if (outInfo != nullptr || outCaps != nullptr)
Expand Down

0 comments on commit 01beccf

Please sign in to comment.