From d861a4f42753b632e5a6f4d07e69d1ec319e5164 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 20 Jul 2018 23:40:21 -0500 Subject: [PATCH] Load OpenGL ES 2.0 function procs Load functions procs supported by OpenGL ES 2.0, though there is not a compatible renderer yet. Change argument for GLimp_Init from coreContext to fixedFunction. --- code/renderercommon/qgl.h | 16 ++++-- code/renderercommon/tr_common.h | 2 +- code/renderergl1/tr_init.c | 2 +- code/renderergl2/tr_extensions.c | 24 +-------- code/renderergl2/tr_init.c | 2 +- code/renderergl2/tr_local.h | 1 + code/sdl/sdl_glimp.c | 84 ++++++++++++++++++++++---------- 7 files changed, 77 insertions(+), 54 deletions(-) diff --git a/code/renderercommon/qgl.h b/code/renderercommon/qgl.h index a8c451e4..38f9919f 100644 --- a/code/renderercommon/qgl.h +++ b/code/renderercommon/qgl.h @@ -123,11 +123,14 @@ extern void (APIENTRYP qglUnlockArraysEXT) (void); GLE(void, Vertex3f, GLfloat x, GLfloat y, GLfloat z) \ GLE(void, Vertex3fv, const GLfloat *v) \ -// OpenGL ES 1.1 but not desktop OpenGL 1.x +// OpenGL ES 1.1 and OpenGL ES 2.0 but not desktop OpenGL 1.x #define QGL_ES_1_1_PROCS \ GLE(void, ClearDepthf, GLclampf depth) \ - GLE(void, ClipPlanef, GLenum plane, const GLfloat *equation) \ GLE(void, DepthRangef, GLclampf near_val, GLclampf far_val) \ + +// OpenGL ES 1.1 but not OpenGL ES 2.0 or desktop OpenGL 1.x +#define QGL_ES_1_1_FIXED_FUNCTION_PROCS \ + GLE(void, ClipPlanef, GLenum plane, const GLfloat *equation) \ GLE(void, Frustumf, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near_val, GLfloat far_val) \ GLE(void, Orthof, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near_val, GLfloat far_val) \ @@ -137,14 +140,17 @@ extern void (APIENTRYP qglUnlockArraysEXT) (void); GLE(void, CompressedTexImage2D, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data) \ GLE(void, CompressedTexSubImage2D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) \ -// OpenGL 1.5, was GL_ARB_vertex_buffer_object and GL_ARB_occlusion_query -#define QGL_1_5_PROCS \ +// GL_ARB_occlusion_query, built-in to OpenGL 1.5 but not OpenGL ES 2.0 +#define QGL_ARB_occlusion_query_PROCS \ GLE(void, GenQueries, GLsizei n, GLuint *ids) \ GLE(void, DeleteQueries, GLsizei n, const GLuint *ids) \ GLE(void, BeginQuery, GLenum target, GLuint id) \ GLE(void, EndQuery, GLenum target) \ GLE(void, GetQueryObjectiv, GLuint id, GLenum pname, GLint *params) \ GLE(void, GetQueryObjectuiv, GLuint id, GLenum pname, GLuint *params) \ + +// OpenGL 1.5, was GL_ARB_vertex_buffer_object +#define QGL_1_5_PROCS \ GLE(void, BindBuffer, GLenum target, GLuint buffer) \ GLE(void, DeleteBuffers, GLsizei n, const GLuint *buffers) \ GLE(void, GenBuffers, GLsizei n, GLuint *buffers) \ @@ -313,10 +319,12 @@ QGL_1_1_FIXED_FUNCTION_PROCS; QGL_DESKTOP_1_1_PROCS; QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS; QGL_ES_1_1_PROCS; +QGL_ES_1_1_FIXED_FUNCTION_PROCS; QGL_1_3_PROCS; QGL_1_5_PROCS; QGL_2_0_PROCS; QGL_3_0_PROCS; +QGL_ARB_occlusion_query_PROCS; QGL_ARB_framebuffer_object_PROCS; QGL_ARB_vertex_array_object_PROCS; QGL_EXT_direct_state_access_PROCS; diff --git a/code/renderercommon/tr_common.h b/code/renderercommon/tr_common.h index eb79fdfc..9c7e176b 100644 --- a/code/renderercommon/tr_common.h +++ b/code/renderercommon/tr_common.h @@ -155,7 +155,7 @@ IMPLEMENTATION SPECIFIC FUNCTIONS ==================================================================== */ -void GLimp_Init( qboolean ); +void GLimp_Init( qboolean fixedFunction ); void GLimp_Shutdown( void ); void GLimp_EndFrame( void ); diff --git a/code/renderergl1/tr_init.c b/code/renderergl1/tr_init.c index be95195a..2c7d91de 100644 --- a/code/renderergl1/tr_init.c +++ b/code/renderergl1/tr_init.c @@ -193,7 +193,7 @@ static void InitOpenGL( void ) { GLint temp; - GLimp_Init( qfalse ); + GLimp_Init( qtrue ); // OpenGL driver constants qglGetIntegerv( GL_MAX_TEXTURE_SIZE, &temp ); diff --git a/code/renderergl2/tr_extensions.c b/code/renderergl2/tr_extensions.c index 59cfab53..9e5a2939 100644 --- a/code/renderergl2/tr_extensions.c +++ b/code/renderergl2/tr_extensions.c @@ -30,15 +30,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "tr_local.h" #include "tr_dsa.h" -#define GLE(ret, name, ...) name##proc * qgl##name; -QGL_1_3_PROCS; -QGL_1_5_PROCS; -QGL_2_0_PROCS; -QGL_ARB_framebuffer_object_PROCS; -QGL_ARB_vertex_array_object_PROCS; -QGL_EXT_direct_state_access_PROCS; -#undef GLE - void GLimp_InitExtraExtensions() { char *extension; @@ -46,11 +37,6 @@ void GLimp_InitExtraExtensions() qboolean q_gl_version_at_least_3_0; qboolean q_gl_version_at_least_3_2; - // Check OpenGL version - if ( !QGL_VERSION_ATLEAST( 2, 0 ) ) - ri.Error(ERR_FATAL, "OpenGL 2.0 required!"); - ri.Printf(PRINT_ALL, "...using OpenGL %s\n", glConfig.version_string); - q_gl_version_at_least_3_0 = QGL_VERSION_ATLEAST( 3, 0 ); q_gl_version_at_least_3_2 = QGL_VERSION_ATLEAST( 3, 2 ); @@ -67,15 +53,9 @@ void GLimp_InitExtraExtensions() // GL function loader, based on https://gist.github.com/rygorous/16796a0c876cf8a5f542caddb55bce8a #define GLE(ret, name, ...) qgl##name = (name##proc *) SDL_GL_GetProcAddress("gl" #name); - // OpenGL 1.3, was GL_ARB_texture_compression - QGL_1_3_PROCS; - - // OpenGL 1.5, was GL_ARB_vertex_buffer_object and GL_ARB_occlusion_query - QGL_1_5_PROCS; + // OpenGL 1.5 - GL_ARB_occlusion_query glRefConfig.occlusionQuery = qtrue; - - // OpenGL 2.0, was GL_ARB_shading_language_100, GL_ARB_vertex_program, GL_ARB_shader_objects, and GL_ARB_vertex_shader - QGL_2_0_PROCS; + QGL_ARB_occlusion_query_PROCS; // OpenGL 3.0 - GL_ARB_framebuffer_object extension = "GL_ARB_framebuffer_object"; diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index b12d338d..85c02dc1 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -258,7 +258,7 @@ static void InitOpenGL( void ) { GLint temp; - GLimp_Init( qtrue ); + GLimp_Init( qfalse ); GLimp_InitExtraExtensions(); // OpenGL driver constants diff --git a/code/renderergl2/tr_local.h b/code/renderergl2/tr_local.h index 55222b14..c83f65de 100644 --- a/code/renderergl2/tr_local.h +++ b/code/renderergl2/tr_local.h @@ -43,6 +43,7 @@ QGL_1_3_PROCS; QGL_1_5_PROCS; QGL_2_0_PROCS; QGL_3_0_PROCS; +QGL_ARB_occlusion_query_PROCS; QGL_ARB_framebuffer_object_PROCS; QGL_ARB_vertex_array_object_PROCS; QGL_EXT_direct_state_access_PROCS; diff --git a/code/sdl/sdl_glimp.c b/code/sdl/sdl_glimp.c index 5a37bb33..a6527900 100644 --- a/code/sdl/sdl_glimp.c +++ b/code/sdl/sdl_glimp.c @@ -69,7 +69,15 @@ QGL_1_1_FIXED_FUNCTION_PROCS; QGL_DESKTOP_1_1_PROCS; QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS; QGL_ES_1_1_PROCS; +QGL_ES_1_1_FIXED_FUNCTION_PROCS; +QGL_1_3_PROCS; +QGL_1_5_PROCS; +QGL_2_0_PROCS; QGL_3_0_PROCS; +QGL_ARB_occlusion_query_PROCS; +QGL_ARB_framebuffer_object_PROCS; +QGL_ARB_vertex_array_object_PROCS; +QGL_EXT_direct_state_access_PROCS; #undef GLE /* @@ -229,7 +237,7 @@ GLimp_GetProcAddresses Get addresses for OpenGL functions. =============== */ -static qboolean GLimp_GetProcAddresses( qboolean coreContext ) { +static qboolean GLimp_GetProcAddresses( qboolean fixedFunction ) { qboolean success = qtrue; const char *version; @@ -268,23 +276,41 @@ static qboolean GLimp_GetProcAddresses( qboolean coreContext ) { sscanf( version, "%d.%d", &qglMajorVersion, &qglMinorVersion ); } - if ( coreContext && QGL_VERSION_ATLEAST( 3, 2 ) ) { - QGL_1_1_PROCS; - QGL_DESKTOP_1_1_PROCS; - } else if ( QGL_VERSION_ATLEAST( 1, 2 ) ) { - QGL_1_1_PROCS; - QGL_1_1_FIXED_FUNCTION_PROCS; - QGL_DESKTOP_1_1_PROCS; - QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS; - } else if ( qglesMajorVersion == 1 && qglesMinorVersion >= 1 ) { - // OpenGL ES 1.1 (2.0 is not backward compatible) - QGL_1_1_PROCS; - QGL_1_1_FIXED_FUNCTION_PROCS; - QGL_ES_1_1_PROCS; - // error so this doesn't segfault due to NULL desktop GL functions being used - Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s\n", version ); + if ( fixedFunction ) { + if ( QGL_VERSION_ATLEAST( 1, 2 ) ) { + QGL_1_1_PROCS; + QGL_1_1_FIXED_FUNCTION_PROCS; + QGL_DESKTOP_1_1_PROCS; + QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS; + } else if ( qglesMajorVersion == 1 && qglesMinorVersion >= 1 ) { + // OpenGL ES 1.1 (2.0 is not backward compatible) + QGL_1_1_PROCS; + QGL_1_1_FIXED_FUNCTION_PROCS; + QGL_ES_1_1_PROCS; + QGL_ES_1_1_FIXED_FUNCTION_PROCS; + // error so this doesn't segfault due to NULL desktop GL functions being used + Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s\n", version ); + } else { + Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 1.2 is required\n", version ); + } } else { - Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s\n", version ); + if ( QGL_VERSION_ATLEAST( 2, 0 ) ) { + QGL_1_1_PROCS; + QGL_DESKTOP_1_1_PROCS; + QGL_1_3_PROCS; + QGL_1_5_PROCS; + QGL_2_0_PROCS; + } else if ( QGLES_VERSION_ATLEAST( 2, 0 ) ) { + QGL_1_1_PROCS; + QGL_ES_1_1_PROCS; + QGL_1_3_PROCS; + QGL_1_5_PROCS; + QGL_2_0_PROCS; + // error so this doesn't segfault due to NULL desktop GL functions being used + Com_Error( ERR_FATAL, "Unsupported OpenGL Version: %s\n", version ); + } else { + Com_Error( ERR_FATAL, "Unsupported OpenGL Version (%s), OpenGL 2.0 is required\n", version ); + } } if ( QGL_VERSION_ATLEAST( 3, 0 ) || QGLES_VERSION_ATLEAST( 3, 0 ) ) { @@ -316,7 +342,15 @@ static void GLimp_ClearProcAddresses( void ) { QGL_DESKTOP_1_1_PROCS; QGL_DESKTOP_1_1_FIXED_FUNCTION_PROCS; QGL_ES_1_1_PROCS; + QGL_ES_1_1_FIXED_FUNCTION_PROCS; + QGL_1_3_PROCS; + QGL_1_5_PROCS; + QGL_2_0_PROCS; QGL_3_0_PROCS; + QGL_ARB_occlusion_query_PROCS; + QGL_ARB_framebuffer_object_PROCS; + QGL_ARB_vertex_array_object_PROCS; + QGL_EXT_direct_state_access_PROCS; qglActiveTextureARB = NULL; qglClientActiveTextureARB = NULL; @@ -333,7 +367,7 @@ static void GLimp_ClearProcAddresses( void ) { GLimp_SetMode =============== */ -static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean coreContext) +static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qboolean fixedFunction) { const char *glstring; int perChannelColorBits; @@ -597,7 +631,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool SDL_SetWindowIcon( SDL_window, icon ); - if (coreContext) + if (!fixedFunction) { int profileMask, majorVersion, minorVersion; SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask); @@ -623,7 +657,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool ri.Printf(PRINT_ALL, "SDL_GL_CreateContext succeeded.\n"); - if ( GLimp_GetProcAddresses( qtrue ) ) + if ( GLimp_GetProcAddresses( fixedFunction ) ) { renderer = (const char *)qglGetString(GL_RENDERER); } @@ -663,7 +697,7 @@ static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder, qbool continue; } - if ( !GLimp_GetProcAddresses( qfalse ) ) + if ( !GLimp_GetProcAddresses( fixedFunction ) ) { ri.Printf( PRINT_ALL, "GLimp_GetProcAddresses() failed\n" ); GLimp_ClearProcAddresses(); @@ -940,7 +974,7 @@ This routine is responsible for initializing the OS specific portions of OpenGL =============== */ -void GLimp_Init( qboolean coreContext) +void GLimp_Init( qboolean fixedFunction ) { ri.Printf( PRINT_DEVELOPER, "Glimp_Init( )\n" ); @@ -960,13 +994,13 @@ void GLimp_Init( qboolean coreContext) ri.Sys_GLimpInit( ); // Create the window and set up the context - if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, r_noborder->integer, coreContext)) + if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, r_noborder->integer, fixedFunction)) goto success; // Try again, this time in a platform specific "safe mode" ri.Sys_GLimpSafeInit( ); - if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, qfalse, coreContext)) + if(GLimp_StartDriverAndSetMode(r_mode->integer, r_fullscreen->integer, qfalse, fixedFunction)) goto success; // Finally, try the default screen resolution @@ -975,7 +1009,7 @@ void GLimp_Init( qboolean coreContext) ri.Printf( PRINT_ALL, "Setting r_mode %d failed, falling back on r_mode %d\n", r_mode->integer, R_MODE_FALLBACK ); - if(GLimp_StartDriverAndSetMode(R_MODE_FALLBACK, qfalse, qfalse, coreContext)) + if(GLimp_StartDriverAndSetMode(R_MODE_FALLBACK, qfalse, qfalse, fixedFunction)) goto success; }