Browse Source

Don't consider different OpenGL versions when re-creating the window after a previous window and OpenGL context has been created. love.graphics has never supported switching GL versions mid-game, so we should prevent it from ever happening.

--HG--
branch : minor
Alex Szpakowski 9 years ago
parent
commit
11328a23cf

+ 2 - 2
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<float>(L, startidx, shader, components, count);
 	float *values = _getNumbers<float>(L, startidx, shader, components, count);
 
 
-	if (colors && love::graphics::isGammaCorrect())
+	if (colors && graphics::isGammaCorrect())
 	{
 	{
 		// alpha is always linear (when present).
 		// alpha is always linear (when present).
 		int gammacomponents = std::min(components, 3);
 		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 i = 0; i < count; i++)
 		{
 		{
 			for (int j = 0; j < gammacomponents; j++)
 			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]);
 		}
 		}
 	}
 	}
 
 

+ 22 - 9
src/modules/window/sdl/Window.cpp

@@ -62,6 +62,7 @@ Window::Window()
 	, context(nullptr)
 	, context(nullptr)
 	, displayedWindowError(false)
 	, displayedWindowError(false)
 	, hasSDL203orEarlier(false)
 	, hasSDL203orEarlier(false)
+	, contextAttribs()
 {
 {
 	if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
 	if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
 		throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError());
 		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;
 	return true;
 }
 }
 
 
-bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa)
+std::vector<Window::ContextAttribs> 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>{contextAttribs};
+
 	bool preferGLES = false;
 	bool preferGLES = false;
 
 
 #ifdef LOVE_GRAPHICS_USE_OPENGLES
 #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
 #ifdef LOVE_WINDOWS_UWP
 	removeES3 = true;
 	removeES3 = true;
 #endif
 #endif
-	
+
 	if (removeES3)
 	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.
 	// Move OpenGL ES to the front of the list if we should prefer GLES.
 	if (preferGLES)
 	if (preferGLES)
 		std::rotate(attribslist.begin(), attribslist.begin() + 1, attribslist.end());
 		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<ContextAttribs> attribslist = getContextAttribsList();
+
 	std::string windowerror;
 	std::string windowerror;
 	std::string contexterror;
 	std::string contexterror;
 	std::string glversion;
 	std::string glversion;
@@ -350,6 +360,9 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
 
 
 		if (window && context)
 		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);
 			love::graphics::setGammaCorrect(curSRGB);
 			break;
 			break;
 		}
 		}

+ 2 - 0
src/modules/window/sdl/Window.h

@@ -122,6 +122,7 @@ private:
 	void setGLFramebufferAttributes(int msaa, bool sRGB);
 	void setGLFramebufferAttributes(int msaa, bool sRGB);
 	void setGLContextAttributes(const ContextAttribs &attribs);
 	void setGLContextAttributes(const ContextAttribs &attribs);
 	bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion);
 	bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion);
+	std::vector<ContextAttribs> getContextAttribsList() const;
 	bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa);
 	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.
 	// Update the saved window settings based on the window's actual state.
@@ -147,6 +148,7 @@ private:
 
 
 	bool displayedWindowError;
 	bool displayedWindowError;
 	bool hasSDL203orEarlier;
 	bool hasSDL203orEarlier;
+	ContextAttribs contextAttribs;
 
 
 }; // Window
 }; // Window