Make it work with SDL1.2 again

Some things broke when moving the renderer into a DLL, and the GL3
renderer needed some more work to work with it.
This commit is contained in:
Daniel Gibson 2017-04-02 04:49:05 +02:00
parent 9044eb1370
commit a9093fdf98
5 changed files with 47 additions and 7 deletions

View File

@ -400,7 +400,7 @@ int GLimp_GetRefreshRate(void)
return glimp_refreshRate; return glimp_refreshRate;
#else #else
// Asume 60hz. // Asume 60hz.
return 60 return 60;
#endif #endif
} }

View File

@ -393,7 +393,9 @@ int RI_InitContext(void* win)
return false; return false;
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
window = (SDL_Window*)win; window = (SDL_Window*)win;
context = SDL_GL_CreateContext(window); context = SDL_GL_CreateContext(window);
if(context == NULL) if(context == NULL)
{ {
@ -401,6 +403,12 @@ int RI_InitContext(void* win)
window = NULL; window = NULL;
return false; return false;
} }
#else // SDL 1.2
window = (SDL_Surface*)win;
// context is created implicitly with window, nothing to do here
#endif
if (gl_msaa_samples->value) if (gl_msaa_samples->value)
{ {

View File

@ -421,6 +421,9 @@ GL3_SetMode(void)
return true; return true;
} }
// only needed (and allowed!) if using OpenGL compatibility profile, it's not in 3.2 core
enum { QGL_POINT_SPRITE = 0x8861 };
static qboolean static qboolean
GL3_Init(void) GL3_Init(void)
{ {
@ -446,9 +449,6 @@ GL3_Init(void)
GL3_Register(); GL3_Register();
/* initialize our QGL dynamic bindings */
//QGL_Init();
/* initialize OS-specific parts of OpenGL */ /* initialize OS-specific parts of OpenGL */
if (!ri.GLimp_Init()) if (!ri.GLimp_Init())
{ {
@ -510,6 +510,7 @@ GL3_Init(void)
R_Printf(PRINT_ALL, "Not supported\n"); R_Printf(PRINT_ALL, "Not supported\n");
} }
#ifdef SDL2
if(gl3config.debug_output) if(gl3config.debug_output)
{ {
R_Printf(PRINT_ALL, " - OpenGL Debug Output: Supported "); R_Printf(PRINT_ALL, " - OpenGL Debug Output: Supported ");
@ -526,6 +527,18 @@ GL3_Init(void)
{ {
R_Printf(PRINT_ALL, " - OpenGL Debug Output: Not Supported\n"); R_Printf(PRINT_ALL, " - OpenGL Debug Output: Not Supported\n");
} }
#else // SDL1.2 - no debug output
R_Printf(PRINT_ALL, " - OpenGL Debug Output: Not Supported when using SDL1.2\n");
#endif
if(gl3config.compat_profile)
{
// for some fucking reason particles (GL_POINT) don't work in compatibility profiles
// without setting this.. SDL1.2 only gives compat profiles and we might wanna support
// them for SDL2 as well, so broken screengrab software etc that uses GL1 functions still works
// (GL_POINT_SPRITE is not even part of 3.2core, it was only in GL2 and was deprecated afterwards)
glEnable(QGL_POINT_SPRITE);
}
// generate texture handles for all possible lightmaps // generate texture handles for all possible lightmaps
glGenTextures(MAX_LIGHTMAPS*MAX_LIGHTMAPS_PER_SURFACE, gl3state.lightmap_textureIDs[0]); glGenTextures(MAX_LIGHTMAPS*MAX_LIGHTMAPS_PER_SURFACE, gl3state.lightmap_textureIDs[0]);

View File

@ -70,6 +70,7 @@ int GL3_PrepareForWindow(void)
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
@ -82,6 +83,10 @@ int GL3_PrepareForWindow(void)
{ {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextFlags);
} }
gl3config.compat_profile = false;
#else // SDL1.2 doesn't have all this, so we'll have some kind of compatibility profile
gl3config.compat_profile = true;
#endif
#if !SDL_VERSION_ATLEAST(2, 0, 0) #if !SDL_VERSION_ATLEAST(2, 0, 0)
@ -180,15 +185,22 @@ int GL3_InitContext(void* win)
ri.Sys_Error(ERR_FATAL, "R_InitContext() must not be called with NULL argument!"); ri.Sys_Error(ERR_FATAL, "R_InitContext() must not be called with NULL argument!");
return false; return false;
} }
#if SDL_VERSION_ATLEAST(2, 0, 0)
window = (SDL_Window*)win; window = (SDL_Window*)win;
context = SDL_GL_CreateContext(window); context = SDL_GL_CreateContext(window);
if(context == NULL) if(context == NULL)
{ {
R_Printf(PRINT_ALL, "R_InitContext(): Creating OpenGL Context failed: %s\n", SDL_GetError()); R_Printf(PRINT_ALL, "GL3_InitContext(): Creating OpenGL Context failed: %s\n", SDL_GetError());
window = NULL; window = NULL;
return false; return false;
} }
#else // SDL 1.2
window = (SDL_Surface*)win;
// context is created implicitly with window, nothing to do here
#endif
if (gl_msaa_samples->value) if (gl_msaa_samples->value)
{ {
@ -226,8 +238,14 @@ int GL3_InitContext(void* win)
R_Printf(PRINT_ALL, "Successfully loaded OpenGL function pointers using glad!\n"); R_Printf(PRINT_ALL, "Successfully loaded OpenGL function pointers using glad!\n");
} }
gl3config.anisotropic = GLAD_GL_EXT_texture_filter_anisotropic != 0; #if SDL_VERSION_ATLEAST(2, 0, 0)
gl3config.debug_output = GLAD_GL_ARB_debug_output != 0; gl3config.debug_output = GLAD_GL_ARB_debug_output != 0;
#else
gl3config.debug_output = 0; // no debug contexts with SDL1.2 - can't set the context flag!
#endif
gl3config.anisotropic = GLAD_GL_EXT_texture_filter_anisotropic != 0;
gl3config.major_version = GLVersion.major; gl3config.major_version = GLVersion.major;
gl3config.minor_version = GLVersion.minor; gl3config.minor_version = GLVersion.minor;

View File

@ -99,6 +99,7 @@ typedef struct
int major_version; int major_version;
int minor_version; int minor_version;
qboolean compat_profile;
// ---- // ----