From a9093fdf98fd5ae5e6890eafd79168879c357a6d Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 2 Apr 2017 04:49:05 +0200 Subject: [PATCH] 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. --- src/backends/sdl/refresh.c | 2 +- src/client/refresh/gl/r_sdl.c | 8 ++++++++ src/client/refresh/gl3/gl3_main.c | 19 ++++++++++++++++--- src/client/refresh/gl3/gl3_sdl.c | 24 +++++++++++++++++++++--- src/client/refresh/gl3/header/local.h | 1 + 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/backends/sdl/refresh.c b/src/backends/sdl/refresh.c index 76255e7b..8e1891e5 100644 --- a/src/backends/sdl/refresh.c +++ b/src/backends/sdl/refresh.c @@ -400,7 +400,7 @@ int GLimp_GetRefreshRate(void) return glimp_refreshRate; #else // Asume 60hz. - return 60 + return 60; #endif } diff --git a/src/client/refresh/gl/r_sdl.c b/src/client/refresh/gl/r_sdl.c index 8ab9110e..dd64c3c6 100644 --- a/src/client/refresh/gl/r_sdl.c +++ b/src/client/refresh/gl/r_sdl.c @@ -393,7 +393,9 @@ int RI_InitContext(void* win) return false; } +#if SDL_VERSION_ATLEAST(2, 0, 0) window = (SDL_Window*)win; + context = SDL_GL_CreateContext(window); if(context == NULL) { @@ -401,6 +403,12 @@ int RI_InitContext(void* win) window = NULL; 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) { diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index 1911cdf7..76d9981b 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -421,6 +421,9 @@ GL3_SetMode(void) 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 GL3_Init(void) { @@ -446,9 +449,6 @@ GL3_Init(void) GL3_Register(); - /* initialize our QGL dynamic bindings */ - //QGL_Init(); - /* initialize OS-specific parts of OpenGL */ if (!ri.GLimp_Init()) { @@ -510,6 +510,7 @@ GL3_Init(void) R_Printf(PRINT_ALL, "Not supported\n"); } +#ifdef SDL2 if(gl3config.debug_output) { 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"); } +#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 glGenTextures(MAX_LIGHTMAPS*MAX_LIGHTMAPS_PER_SURFACE, gl3state.lightmap_textureIDs[0]); diff --git a/src/client/refresh/gl3/gl3_sdl.c b/src/client/refresh/gl3/gl3_sdl.c index 9cb9f150..45519c6c 100644 --- a/src/client/refresh/gl3/gl3_sdl.c +++ b/src/client/refresh/gl3/gl3_sdl.c @@ -70,6 +70,7 @@ int GL3_PrepareForWindow(void) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 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_MINOR_VERSION, 2); 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); } + 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) @@ -180,15 +185,22 @@ int GL3_InitContext(void* win) ri.Sys_Error(ERR_FATAL, "R_InitContext() must not be called with NULL argument!"); return false; } - +#if SDL_VERSION_ATLEAST(2, 0, 0) window = (SDL_Window*)win; + context = SDL_GL_CreateContext(window); 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; 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) { @@ -226,8 +238,14 @@ int GL3_InitContext(void* win) 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; +#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.minor_version = GLVersion.minor; diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index c267997e..829ce99c 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -99,6 +99,7 @@ typedef struct int major_version; int minor_version; + qboolean compat_profile; // ----