diff --git a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp index 8bb89cd8..2fda76b6 100644 --- a/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp +++ b/src/Graphics/OpenGLContext/opengl_BufferManipulationObjectFactory.cpp @@ -404,7 +404,8 @@ struct FramebufferTextureFormatsGLES2 : public graphics::FramebufferTextureForma return _glinfo.isGLES2; } - FramebufferTextureFormatsGLES2() + FramebufferTextureFormatsGLES2(const GLInfo & _glinfo): + m_glinfo(_glinfo) { init(); } @@ -417,7 +418,7 @@ protected: monochromeType = GL_UNSIGNED_SHORT_5_6_5; monochromeFormatBytes = 2; - if (Utils::isExtensionSupported("GL_OES_depth_texture")) { + if (Utils::isExtensionSupported(m_glinfo, "GL_OES_depth_texture")) { depthInternalFormat = GL_DEPTH_COMPONENT; depthFormatBytes = 4; } else { @@ -428,7 +429,7 @@ protected: depthFormat = GL_DEPTH_COMPONENT; depthType = GL_UNSIGNED_INT; - if (Utils::isExtensionSupported("GL_OES_rgb8_rgba8")) { + if (Utils::isExtensionSupported(m_glinfo, "GL_OES_rgb8_rgba8")) { colorInternalFormat = GL_RGBA; colorFormat = GL_RGBA; colorType = GL_UNSIGNED_BYTE; @@ -441,6 +442,9 @@ protected: colorFormatBytes = 2; } } + +private: + const GLInfo & m_glinfo; }; struct FramebufferTextureFormatsGLES3 : public graphics::FramebufferTextureFormats @@ -602,7 +606,7 @@ graphics::FramebufferTextureFormats * BufferManipulationObjectFactory::getFrameb return new FramebufferTextureFormatsGLES3; if (FramebufferTextureFormatsGLES2::Check(m_glInfo)) - return new FramebufferTextureFormatsGLES2; + return new FramebufferTextureFormatsGLES2(m_glInfo); assert(false); return nullptr; diff --git a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp index 55a60186..125971b7 100644 --- a/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp +++ b/src/Graphics/OpenGLContext/opengl_ContextImpl.cpp @@ -406,12 +406,12 @@ bool ContextImpl::isSupported(graphics::SpecialFeatures _feature) const #endif if (m_glInfo.isGLESX) - return numBinaryFormats != 0 && Utils::isExtensionSupported("GL_OES_get_program_binary"); + return numBinaryFormats != 0 && Utils::isExtensionSupported(m_glInfo, "GL_OES_get_program_binary"); - return numBinaryFormats != 0 && Utils::isExtensionSupported("GL_ARB_get_program_binary"); + return numBinaryFormats != 0 && Utils::isExtensionSupported(m_glInfo, "GL_ARB_get_program_binary"); } case graphics::SpecialFeatures::DepthFramebufferTextures: - if (!m_glInfo.isGLES2 || Utils::isExtensionSupported("GL_OES_depth_texture")) + if (!m_glInfo.isGLES2 || Utils::isExtensionSupported(m_glInfo, "GL_OES_depth_texture")) return true; else return false; diff --git a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp index 20e016dc..1c3f5fba 100644 --- a/src/Graphics/OpenGLContext/opengl_GLInfo.cpp +++ b/src/Graphics/OpenGLContext/opengl_GLInfo.cpp @@ -12,8 +12,7 @@ void GLInfo::init() { if (isGLES2) { majorVersion = 2; minorVersion = 0; - } - else { + } else { glGetIntegerv(GL_MAJOR_VERSION, &majorVersion); glGetIntegerv(GL_MINOR_VERSION, &minorVersion); } @@ -35,18 +34,22 @@ void GLInfo::init() { imageTextures = (numericVersion >= 31) && (glBindImageTexture != nullptr); msaa = numericVersion >= 31; } else { - imageTextures = ((numericVersion >= 43) || (Utils::isExtensionSupported("GL_ARB_shader_image_load_store") && Utils::isExtensionSupported("GL_ARB_compute_shader"))) && (glBindImageTexture != nullptr); + imageTextures = ((numericVersion >= 43) || (Utils::isExtensionSupported(*this, "GL_ARB_shader_image_load_store") && + Utils::isExtensionSupported(*this, "GL_ARB_compute_shader"))) && (glBindImageTexture != nullptr); msaa = true; } - bufferStorage = (!isGLESX && (numericVersion >= 44)) || Utils::isExtensionSupported("GL_ARB_buffer_storage") || Utils::isExtensionSupported("GL_EXT_buffer_storage"); - texStorage = (isGLESX && (numericVersion >= 30)) || (!isGLESX && numericVersion >= 42) || Utils::isExtensionSupported("GL_ARB_texture_storage") || Utils::isExtensionSupported("GL_EXT_texture_storage"); + bufferStorage = (!isGLESX && (numericVersion >= 44)) || Utils::isExtensionSupported(*this, "GL_ARB_buffer_storage") || + Utils::isExtensionSupported(*this, "GL_EXT_buffer_storage"); + texStorage = (isGLESX && (numericVersion >= 30)) || (!isGLESX && numericVersion >= 42) || + Utils::isExtensionSupported(*this, "GL_ARB_texture_storage") || + Utils::isExtensionSupported(*this, "GL_EXT_texture_storage"); shaderStorage = false; if (config.generalEmulation.enableShadersStorage != 0) { const char * strGetProgramBinary = isGLESX ? "GL_OES_get_program_binary" : "GL_ARB_get_program_binary"; - if (Utils::isExtensionSupported(strGetProgramBinary)) { + if (Utils::isExtensionSupported(*this, strGetProgramBinary)) { GLint numBinaryFormats = 0; glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats); shaderStorage = numBinaryFormats > 0; diff --git a/src/Graphics/OpenGLContext/opengl_Utils.cpp b/src/Graphics/OpenGLContext/opengl_Utils.cpp index b2dba4d6..44f1e29f 100644 --- a/src/Graphics/OpenGLContext/opengl_Utils.cpp +++ b/src/Graphics/OpenGLContext/opengl_Utils.cpp @@ -7,21 +7,21 @@ using namespace opengl; -bool Utils::isExtensionSupported(const char *extension) -{ -#ifdef GL_NUM_EXTENSIONS - GLint count = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &count); - assert(count >= 0); - for (GLuint i = 0; i < (GLuint)count; ++i) { - const char* name = (const char*)glGetStringi(GL_EXTENSIONS, i); - if (name == nullptr) - continue; - if (strcmp(extension, name) == 0) - return true; +bool Utils::isExtensionSupported(const opengl::GLInfo & _glinfo, const char *extension) { + if (!_glinfo.isGLES2 && !_glinfo.majorVersion >= 3) { + GLint count = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &count); + assert(count >= 0); + for (GLuint i = 0; i < (GLuint)count; ++i) { + const char* name = (const char*)glGetStringi(GL_EXTENSIONS, i); + if (name == nullptr) + continue; + if (strcmp(extension, name) == 0) + return true; + } + return false; } - return false; -#else + GLubyte *where = (GLubyte *)strchr(extension, ' '); if (where || *extension == '\0') return false; @@ -35,15 +35,13 @@ bool Utils::isExtensionSupported(const char *extension) break; GLubyte *terminator = where + strlen(extension); - if (where == start || *(where - 1) == ' ') - if (*terminator == ' ' || *terminator == '\0') + if (where == start || *(where - 1) == ' ') if (*terminator == ' ' || *terminator == '\0') return true; start = terminator; } return false; -#endif // GL_NUM_EXTENSIONS } @@ -91,8 +89,7 @@ bool Utils::isGLError() errString = GLErrorString(errCode); if (errString != nullptr) { LOG(LOG_ERROR, "OpenGL Error: %s (%x)", errString, errCode); - } - else { + } else { LOG(LOG_ERROR, "OpenGL Error: %x", errCode); } diff --git a/src/Graphics/OpenGLContext/opengl_Utils.h b/src/Graphics/OpenGLContext/opengl_Utils.h index 966f9b90..c8566707 100644 --- a/src/Graphics/OpenGLContext/opengl_Utils.h +++ b/src/Graphics/OpenGLContext/opengl_Utils.h @@ -1,10 +1,12 @@ #pragma once +#include "opengl_GLInfo.h" + namespace opengl { struct Utils { - static bool isExtensionSupported(const char * extension); + static bool isExtensionSupported(const opengl::GLInfo & _glinfo, const char * extension); static bool isGLError(); static bool isFramebufferError(); };