Forces GL 2.1 core context creation in VideoMode.

This was SVN commit r26031.
This commit is contained in:
vladislavbelov 2021-12-04 22:01:20 +00:00
parent 670f5f9a40
commit e4907bdb6e
2 changed files with 24 additions and 10 deletions

View file

@ -279,8 +279,8 @@ bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
return false;
}
SDL_GLContext context = SDL_GL_CreateContext(m_Window);
if (!context)
m_Context = SDL_GL_CreateContext(m_Window);
if (!m_Context)
{
LOGERROR("SetVideoMode failed in SDL_GL_CreateContext: %dx%d:%d %d (\"%s\")",
w, h, bpp, fullscreen ? 1 : 0, SDL_GetError());
@ -385,17 +385,11 @@ bool CVideoMode::InitSDL()
int bpp = GetBestBPP();
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#if CONFIG2_GLES
// Require GLES 2.0
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif
bool forceGLVersion = false;
CFG_GET_VAL("forceglversion", forceGLVersion);
if (forceGLVersion)
@ -426,6 +420,19 @@ bool CVideoMode::InitSDL()
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, forceGLMinorVersion);
}
}
else
{
#if CONFIG2_GLES
// Require GLES 2.0
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#endif
}
if (!SetVideoMode(w, h, bpp, m_ConfigFullscreen))
{
@ -486,10 +493,15 @@ void CVideoMode::Shutdown()
m_IsFullscreen = false;
m_IsInitialised = false;
if (m_Context)
{
SDL_GL_DeleteContext(m_Context);
m_Context = nullptr;
}
if (m_Window)
{
SDL_DestroyWindow(m_Window);
m_Window = NULL;
m_Window = nullptr;
}
}

View file

@ -23,6 +23,7 @@
#include <memory>
typedef struct SDL_Window SDL_Window;
typedef void* SDL_GLContext;
class CVideoMode
{
@ -116,6 +117,7 @@ private:
bool m_IsInitialised = false;
SDL_Window* m_Window = nullptr;
SDL_GLContext m_Context = nullptr;
// Initial desktop settings.
// Frequency is in Hz, and BPP means bits per pixels (not bytes per pixels).