diff --git a/src/modules/graphics/opengl/wrap_Shader.cpp b/src/modules/graphics/opengl/wrap_Shader.cpp index 758fe0b81..5929af41c 100644 --- a/src/modules/graphics/opengl/wrap_Shader.cpp +++ b/src/modules/graphics/opengl/wrap_Shader.cpp @@ -87,7 +87,7 @@ int w_Shader_sendFloats(lua_State *L, int startidx, Shader *shader, const Shader float *values = _getNumbers(L, startidx, shader, components, count); - if (colors && love::graphics::isGammaCorrect()) + if (colors && graphics::isGammaCorrect()) { // alpha is always linear (when present). int gammacomponents = std::min(components, 3); @@ -95,7 +95,7 @@ int w_Shader_sendFloats(lua_State *L, int startidx, Shader *shader, const Shader for (int i = 0; i < count; i++) { for (int j = 0; j < gammacomponents; j++) - values[i * components + j] = love::math::gammaToLinear(values[i * components + j]); + values[i * components + j] = math::gammaToLinear(values[i * components + j]); } } diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index ae2fe3fc4..33f3a2556 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -62,6 +62,7 @@ Window::Window() , context(nullptr) , displayedWindowError(false) , hasSDL203orEarlier(false) + , contextAttribs() { if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError()); @@ -182,8 +183,14 @@ bool Window::checkGLVersion(const ContextAttribs &attribs, std::string &outversi return true; } -bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa) +std::vector Window::getContextAttribsList() const { + // If we already have a set of context attributes that we know work, just + // return that. love.graphics doesn't really support switching GL versions + // after the first initialization. + if (contextAttribs.versionMajor > 0) + return std::vector{contextAttribs}; + bool preferGLES = false; #ifdef LOVE_GRAPHICS_USE_OPENGLES @@ -235,23 +242,26 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla #ifdef LOVE_WINDOWS_UWP removeES3 = true; #endif - + if (removeES3) { - auto it = attribslist.begin(); - while (it != attribslist.end()) + std::remove_if(attribslist.begin(), attribslist.end(), [](ContextAttribs a) { - if (it->gles && it->versionMajor >= 3) - it = attribslist.erase(it); - else - ++it; - } + return a.gles && a.versionMajor >= 3; + }); } // Move OpenGL ES to the front of the list if we should prefer GLES. if (preferGLES) std::rotate(attribslist.begin(), attribslist.begin() + 1, attribslist.end()); + return attribslist; +} + +bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa) +{ + std::vector attribslist = getContextAttribsList(); + std::string windowerror; std::string contexterror; std::string glversion; @@ -350,6 +360,9 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla if (window && context) { + // Store the successful context attributes so we can re-use them in + // subsequent calls to createWindowAndContext. + contextAttribs = attribs; love::graphics::setGammaCorrect(curSRGB); break; } diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index b459a2173..c678d707b 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -122,6 +122,7 @@ private: void setGLFramebufferAttributes(int msaa, bool sRGB); void setGLContextAttributes(const ContextAttribs &attribs); bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion); + std::vector getContextAttribsList() const; bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa); // Update the saved window settings based on the window's actual state. @@ -147,6 +148,7 @@ private: bool displayedWindowError; bool hasSDL203orEarlier; + ContextAttribs contextAttribs; }; // Window