Make opengl extension loading be core compliant. Avoid issuing glGetString before context creation on Windows.

This commit is contained in:
Shyotl
2019-03-25 19:21:45 -05:00
parent f3afe45e72
commit 7b5d7376c6
2 changed files with 55 additions and 17 deletions

View File

@@ -504,41 +504,78 @@ LLGLManager::LLGLManager() :
{ {
} }
std::set<std::string> sGLExtensions; std::set<std::string> sGLExtensions; // Not techincally safe to issue this before context is created.
void registerExtension(std::string ext) #if LL_WINDOWS
std::set<std::string> sWGLExtensions; // Fine (probably) without context.
#endif
void registerExtension(std::string ext, std::set<std::string>& extensions)
{ {
sGLExtensions.emplace(ext); extensions.emplace(ext);
LL_DEBUGS("GLExtensions") << ext << LL_ENDL; LL_INFOS("GLExtensions") << ext << LL_ENDL;
} }
void loadExtensionStrings() void loadExtensionStrings()
{ {
sGLExtensions.clear(); sGLExtensions.clear();
typedef boost::tokenizer<boost::char_separator<char> > tokenizer; U32 gl_version = atoi((const char*)glGetString(GL_VERSION));
boost::char_separator<char> sep(" "); if (gl_version >= 3)
std::string extensions((const char*)glGetString(GL_EXTENSIONS));
for (auto& extension : tokenizer(extensions, sep))
{ {
registerExtension(extension); #ifndef LL_DARWIN
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC)GLH_EXT_GET_PROC_ADDRESS("glGetStringi");
#endif
GLint count = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
for (GLint i = 0; i < count; ++i)
{
registerExtension((char const*)glGetStringi(GL_EXTENSIONS, i), sGLExtensions);
}
} }
else // Deprecated.
{
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(" ");
std::string extensions((const char*)glGetString(GL_EXTENSIONS));
for (auto& extension : tokenizer(extensions, sep))
{
registerExtension(extension, sGLExtensions);
}
}
}
#if LL_WINDOWS #if LL_WINDOWS
void loadWGLExtensionStrings()
{
sWGLExtensions.clear();
PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
if (wglGetExtensionsStringARB) if (wglGetExtensionsStringARB)
{ {
extensions = std::string(wglGetExtensionsStringARB(wglGetCurrentDC())); typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(" ");
std::string extensions = std::string(wglGetExtensionsStringARB(wglGetCurrentDC()));
for (auto& extension : tokenizer(extensions, sep)) for (auto& extension : tokenizer(extensions, sep))
{ {
registerExtension(extension); registerExtension(extension, sWGLExtensions);
} }
} }
#endif
} }
#endif
bool ExtensionExists(std::string ext) bool ExtensionExists(std::string ext)
{ {
if (sGLExtensions.empty()) auto* extensions = &sGLExtensions;
#if LL_WINDOWS
if (ext.rfind("WGL_", 0) == 0)
{
extensions = &sWGLExtensions;
if (extensions->empty())
loadWGLExtensionStrings();
}
else
#endif
if (extensions->empty())
loadExtensionStrings(); loadExtensionStrings();
return sGLExtensions.find(ext) != sGLExtensions.end(); bool found = extensions->find(ext) != extensions->end();
if (!found)
LL_INFOS("GLExtensions") << ext << " MISSING" << LL_ENDL;
return found;
} }
//--------------------------------------------------------------------- //---------------------------------------------------------------------
@@ -547,6 +584,7 @@ bool ExtensionExists(std::string ext)
void LLGLManager::initWGL() void LLGLManager::initWGL()
{ {
#if LL_WINDOWS && !LL_MESA_HEADLESS #if LL_WINDOWS && !LL_MESA_HEADLESS
loadWGLExtensionStrings();
if (ExtensionExists("WGL_ARB_pixel_format")) if (ExtensionExists("WGL_ARB_pixel_format"))
{ {
wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB"); wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)wglGetProcAddress("wglGetPixelFormatAttribivARB");

View File

@@ -474,7 +474,7 @@ void main()
#endif #endif
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
#if (HAS_SPECULAR_MAP == false) #if (HAS_SPECULAR_MAP == 0)
if(diffcol.a < .01) if(diffcol.a < .01)
{ {
discard; discard;