1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

OpenGL: Avoid enabling GL_TEXTURE_2D in core profile contexts

This commit is contained in:
reuk 2023-03-06 11:40:35 +00:00
parent 505285bb22
commit af2a4a7e2a
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
6 changed files with 54 additions and 32 deletions

View file

@ -841,6 +841,8 @@ public:
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture (GL_TEXTURE0);
if (! openGLContext.isCoreProfile())
glEnable (GL_TEXTURE_2D);
glViewport (0, 0,

View file

@ -240,22 +240,6 @@ private:
OpenGLTargetSaver& operator= (const OpenGLTargetSaver&);
};
static bool contextRequiresTexture2DEnableDisable()
{
#if JUCE_OPENGL_ES
return false;
#else
clearGLError();
GLint mask = 0;
glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &mask);
if (glGetError() == GL_INVALID_ENUM)
return true;
return (mask & (GLint) GL_CONTEXT_CORE_PROFILE_BIT) == 0;
#endif
}
} // namespace juce
//==============================================================================

View file

@ -537,7 +537,7 @@ public:
void drawComponentBuffer()
{
if (contextRequiresTexture2DEnableDisable())
if (! isCoreProfile())
glEnable (GL_TEXTURE_2D);
#if JUCE_WINDOWS
@ -644,6 +644,7 @@ public:
if (getOpenGLVersion() >= Version { 4, 3 } && glDebugMessageCallback != nullptr)
{
glEnable (GL_DEBUG_OUTPUT);
glEnable (GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback ([] (GLenum, GLenum type, GLuint, GLenum severity, GLsizei, const GLchar* message, const void*)
{
// This may reiterate issues that are also flagged by JUCE_CHECK_OPENGL_ERROR.
@ -674,6 +675,24 @@ public:
return InitResult::success;
}
bool isCoreProfile() const
{
#if JUCE_OPENGL_ES
return true;
#else
clearGLError();
GLint mask = 0;
glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &mask);
// The context isn't aware of the profile mask, so it pre-dates the core profile
if (glGetError() == GL_INVALID_ENUM)
return false;
// Also assumes a compatibility profile if the mask is completely empty for some reason
return (mask & (GLint) GL_CONTEXT_CORE_PROFILE_BIT) != 0;
#endif
}
/* Returns true if the context requires a non-zero vertex array object (VAO) to be bound.
If the context is a compatibility context, we can just pretend that VAOs don't exist,
@ -686,16 +705,7 @@ public:
#if JUCE_OPENGL_ES
return false;
#else
clearGLError();
GLint mask = 0;
glGetIntegerv (GL_CONTEXT_PROFILE_MASK, &mask);
// The context isn't aware of the profile mask, so it pre-dates the core profile
if (glGetError() == GL_INVALID_ENUM)
return false;
// Also assumes a compatibility profile if the mask is completely empty for some reason
return (mask & (GLint) GL_CONTEXT_CORE_PROFILE_BIT) != 0;
return isCoreProfile();
#endif
}
@ -1443,6 +1453,12 @@ void* OpenGLContext::getRawContext() const noexcept
return nativeContext != nullptr ? nativeContext->getRawContext() : nullptr;
}
bool OpenGLContext::isCoreProfile() const
{
auto* c = getCachedImage();
return c != nullptr && c->isCoreProfile();
}
OpenGLContext::CachedImage* OpenGLContext::getCachedImage() const noexcept
{
if (auto* comp = getTargetComponent())

View file

@ -133,7 +133,16 @@ public:
/** Returns true if non-power-of-two textures are supported in this context. */
bool isTextureNpotSupported() const;
/** OpenGL versions, used by setOpenGLVersionRequired(). */
/** OpenGL versions, used by setOpenGLVersionRequired().
The Core profile doesn't include some legacy functionality, including the
fixed-function pipeline.
The Compatibility profile is backwards-compatible, and includes functionality
deprecated in the Core profile. However, not all implementations provide
compatibility profiles targeting later versions of OpenGL. To run on the
broadest range of hardware, using the 3.2 Core profile is recommended.
*/
enum OpenGLVersion
{
defaultGLVersion = 0, ///< Whatever the device decides to give us, normally a compatibility profile
@ -285,6 +294,12 @@ public:
*/
void* getRawContext() const noexcept;
/** Returns true if this context is using the core profile.
@see OpenGLVersion
*/
bool isCoreProfile() const;
/** This structure holds a set of dynamically loaded GL functions for use on this context. */
OpenGLExtensionFunctions extensions;

View file

@ -216,7 +216,9 @@ bool OpenGLFrameBuffer::initialise (OpenGLFrameBuffer& other)
pimpl->bind();
#if ! JUCE_ANDROID
if (! pimpl->context.isCoreProfile())
glEnable (GL_TEXTURE_2D);
clearGLError();
#endif
glBindTexture (GL_TEXTURE_2D, p->textureID);

View file

@ -1086,7 +1086,7 @@ struct StateHelpers
GLuint currentTextureID[numTextures];
int texturesEnabled = 0, currentActiveTexture = -1;
const OpenGLContext& context;
const bool needsToEnableTexture = contextRequiresTexture2DEnableDisable();
const bool needsToEnableTexture = ! context.isCoreProfile();
ActiveTextures& operator= (const ActiveTextures&);
};
@ -1784,7 +1784,10 @@ struct NonShaderContext : public LowLevelGraphicsSoftwareRenderer
#if ! JUCE_ANDROID
target.context.extensions.glActiveTexture (GL_TEXTURE0);
if (! target.context.isCoreProfile())
glEnable (GL_TEXTURE_2D);
clearGLError();
#endif