From 8c204efafb122eb13d9dad8a48504ed79a586ec0 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 5 Jan 2017 22:33:10 -0400 Subject: [PATCH] Minor pre-emptive fixes for GL3. --HG-- branch : minor --- src/modules/graphics/opengl/Graphics.cpp | 18 ++++++++++++++++-- src/modules/graphics/opengl/Graphics.h | 2 ++ src/modules/graphics/opengl/OpenGL.cpp | 24 ++++++++++++++++++++++-- src/modules/graphics/opengl/OpenGL.h | 7 +++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 45e61a8ac..f059950a7 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -56,6 +56,7 @@ namespace opengl Graphics::Graphics() : quadIndices(nullptr) , windowHasStencil(false) + , mainVAO(0) { gl = OpenGL(); @@ -224,9 +225,10 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b glEnable(GL_BLEND); // Auto-generated mipmaps should be the best quality possible - glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + if (!gl.isCoreProfile()) + glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); - if (!GLAD_ES_VERSION_2_0) + if (!GLAD_ES_VERSION_2_0 && !gl.isCoreProfile()) { // Make sure antialiasing works when set elsewhere glEnable(GL_MULTISAMPLE); @@ -235,6 +237,12 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b glEnable(GL_TEXTURE_2D); } + if (gl.isCoreProfile()) + { + glGenVertexArrays(1, &mainVAO); + glBindVertexArray(mainVAO); + } + gl.setTextureUnit(0); // Set pixel row alignment @@ -334,6 +342,12 @@ void Graphics::unSetMode() framebufferObjects.clear(); stencilBuffers.clear(); + if (mainVAO != 0) + { + glDeleteVertexArrays(1, &mainVAO); + mainVAO = 0; + } + gl.deInitContext(); created = false; diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index c05ce7151..08dfcfa38 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -157,6 +157,8 @@ private: bool windowHasStencil; + GLuint mainVAO; + }; // Graphics } // opengl diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index e8679179d..38f3c0b86 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -73,6 +73,8 @@ OpenGL::OpenGL() , maxRenderTargets(1) , maxRenderbufferSamples(0) , maxTextureUnits(1) + , maxPointSize(1) + , coreProfile(false) , vendor(VENDOR_UNKNOWN) , state() { @@ -90,6 +92,15 @@ bool OpenGL::initContext() if (!gladLoadGLLoader(LOVEGetProcAddress)) return false; + if (GLAD_VERSION_3_2) + { + GLint profileMask = 0; + glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profileMask); + coreProfile = (profileMask & GL_CONTEXT_CORE_PROFILE_BIT); + } + else + coreProfile = false; + initOpenGLFunctions(); initVendor(); @@ -100,7 +111,8 @@ bool OpenGL::initContext() if (getVendor() == VENDOR_AMD) { bugs.clearRequiresDriverTextureStateUpdate = true; - bugs.generateMipmapsRequiresTexture2DEnable = true; + if (!gl.isCoreProfile()) + bugs.generateMipmapsRequiresTexture2DEnable = true; } #endif @@ -306,7 +318,10 @@ void OpenGL::initMaxValues() glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); GLfloat limits[2]; - glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, limits); + if (GLAD_VERSION_3_0) + glGetFloatv(GL_POINT_SIZE_RANGE, limits); + else + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, limits); maxPointSize = limits[1]; } @@ -741,6 +756,11 @@ void OpenGL::updateTextureMemorySize(size_t oldsize, size_t newsize) stats.textureMemory = (size_t) std::max(memsize, (int64) 0); } +bool OpenGL::isCoreProfile() const +{ + return coreProfile; +} + OpenGL::Vendor OpenGL::getVendor() const { return vendor; diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index 47056cc3d..9ee4a303d 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -347,6 +347,11 @@ public: void updateTextureMemorySize(size_t oldsize, size_t newsize); + /** + * Gets whether the context is Core Profile OpenGL 3.2+. + **/ + bool isCoreProfile() const; + /** * Get the GPU vendor of this OpenGL context. **/ @@ -385,6 +390,8 @@ private: int maxTextureUnits; float maxPointSize; + bool coreProfile; + Vendor vendor; // Tracked OpenGL state.