mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
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
This commit is contained in:
@@ -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);
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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::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;
|
||||
|
||||
#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<ContextAttribs> 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;
|
||||
}
|
||||
|
||||
@@ -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<ContextAttribs> 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user