From 23d0f33ad1f699bcf1b7e012f797f99de4e912b3 Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 7 Feb 2019 00:12:33 +0700 Subject: [PATCH] Refactor extension detection, add VBO detection --- engine/client/gl_local.h | 1 + engine/platform/sdl/vid_sdl.c | 320 ++++++++++++++++++---------------- 2 files changed, 168 insertions(+), 153 deletions(-) diff --git a/engine/client/gl_local.h b/engine/client/gl_local.h index fcc77848..0cddcbd4 100644 --- a/engine/client/gl_local.h +++ b/engine/client/gl_local.h @@ -523,6 +523,7 @@ enum GL_EXT_GPU_SHADER4, // shaders only GL_DEPTH_TEXTURE, GL_DEBUG_OUTPUT, + GL_ARB_VERTEX_BUFFER_OBJECT_EXT, GL_EXTCOUNT, // must be last }; diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 4c62d37b..80ba4e05 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -25,176 +25,189 @@ GNU General Public License for more details. static vidmode_t *vidmodes = NULL; static int num_vidmodes = 0; static int context_flags = 0; - +#define GL_CALL( x ) #x, (void**)&p##x static dllfunc_t opengl_110funcs[] = { -{ "glClearColor" , (void **)&pglClearColor }, -{ "glClear" , (void **)&pglClear }, -{ "glAlphaFunc" , (void **)&pglAlphaFunc }, -{ "glBlendFunc" , (void **)&pglBlendFunc }, -{ "glCullFace" , (void **)&pglCullFace }, -{ "glDrawBuffer" , (void **)&pglDrawBuffer }, -{ "glReadBuffer" , (void **)&pglReadBuffer }, -{ "glAccum" , (void **)&pglAccum }, -{ "glEnable" , (void **)&pglEnable }, -{ "glDisable" , (void **)&pglDisable }, -{ "glEnableClientState" , (void **)&pglEnableClientState }, -{ "glDisableClientState" , (void **)&pglDisableClientState }, -{ "glGetBooleanv" , (void **)&pglGetBooleanv }, -{ "glGetDoublev" , (void **)&pglGetDoublev }, -{ "glGetFloatv" , (void **)&pglGetFloatv }, -{ "glGetIntegerv" , (void **)&pglGetIntegerv }, -{ "glGetError" , (void **)&pglGetError }, -{ "glGetString" , (void **)&pglGetString }, -{ "glFinish" , (void **)&pglFinish }, -{ "glFlush" , (void **)&pglFlush }, -{ "glClearDepth" , (void **)&pglClearDepth }, -{ "glDepthFunc" , (void **)&pglDepthFunc }, -{ "glDepthMask" , (void **)&pglDepthMask }, -{ "glDepthRange" , (void **)&pglDepthRange }, -{ "glFrontFace" , (void **)&pglFrontFace }, -{ "glDrawElements" , (void **)&pglDrawElements }, -{ "glDrawArrays" , (void **)&pglDrawArrays }, -{ "glColorMask" , (void **)&pglColorMask }, -{ "glIndexPointer" , (void **)&pglIndexPointer }, -{ "glVertexPointer" , (void **)&pglVertexPointer }, -{ "glNormalPointer" , (void **)&pglNormalPointer }, -{ "glColorPointer" , (void **)&pglColorPointer }, -{ "glTexCoordPointer" , (void **)&pglTexCoordPointer }, -{ "glArrayElement" , (void **)&pglArrayElement }, -{ "glColor3f" , (void **)&pglColor3f }, -{ "glColor3fv" , (void **)&pglColor3fv }, -{ "glColor4f" , (void **)&pglColor4f }, -{ "glColor4fv" , (void **)&pglColor4fv }, -{ "glColor3ub" , (void **)&pglColor3ub }, -{ "glColor4ub" , (void **)&pglColor4ub }, -{ "glColor4ubv" , (void **)&pglColor4ubv }, -{ "glTexCoord1f" , (void **)&pglTexCoord1f }, -{ "glTexCoord2f" , (void **)&pglTexCoord2f }, -{ "glTexCoord3f" , (void **)&pglTexCoord3f }, -{ "glTexCoord4f" , (void **)&pglTexCoord4f }, -{ "glTexCoord1fv" , (void **)&pglTexCoord1fv }, -{ "glTexCoord2fv" , (void **)&pglTexCoord2fv }, -{ "glTexCoord3fv" , (void **)&pglTexCoord3fv }, -{ "glTexCoord4fv" , (void **)&pglTexCoord4fv }, -{ "glTexGenf" , (void **)&pglTexGenf }, -{ "glTexGenfv" , (void **)&pglTexGenfv }, -{ "glTexGeni" , (void **)&pglTexGeni }, -{ "glVertex2f" , (void **)&pglVertex2f }, -{ "glVertex3f" , (void **)&pglVertex3f }, -{ "glVertex3fv" , (void **)&pglVertex3fv }, -{ "glNormal3f" , (void **)&pglNormal3f }, -{ "glNormal3fv" , (void **)&pglNormal3fv }, -{ "glBegin" , (void **)&pglBegin }, -{ "glEnd" , (void **)&pglEnd }, -{ "glLineWidth" , (void**)&pglLineWidth }, -{ "glPointSize" , (void**)&pglPointSize }, -{ "glMatrixMode" , (void **)&pglMatrixMode }, -{ "glOrtho" , (void **)&pglOrtho }, -{ "glRasterPos2f" , (void **) &pglRasterPos2f }, -{ "glFrustum" , (void **)&pglFrustum }, -{ "glViewport" , (void **)&pglViewport }, -{ "glPushMatrix" , (void **)&pglPushMatrix }, -{ "glPopMatrix" , (void **)&pglPopMatrix }, -{ "glPushAttrib" , (void **)&pglPushAttrib }, -{ "glPopAttrib" , (void **)&pglPopAttrib }, -{ "glLoadIdentity" , (void **)&pglLoadIdentity }, -{ "glLoadMatrixd" , (void **)&pglLoadMatrixd }, -{ "glLoadMatrixf" , (void **)&pglLoadMatrixf }, -{ "glMultMatrixd" , (void **)&pglMultMatrixd }, -{ "glMultMatrixf" , (void **)&pglMultMatrixf }, -{ "glRotated" , (void **)&pglRotated }, -{ "glRotatef" , (void **)&pglRotatef }, -{ "glScaled" , (void **)&pglScaled }, -{ "glScalef" , (void **)&pglScalef }, -{ "glTranslated" , (void **)&pglTranslated }, -{ "glTranslatef" , (void **)&pglTranslatef }, -{ "glReadPixels" , (void **)&pglReadPixels }, -{ "glDrawPixels" , (void **)&pglDrawPixels }, -{ "glStencilFunc" , (void **)&pglStencilFunc }, -{ "glStencilMask" , (void **)&pglStencilMask }, -{ "glStencilOp" , (void **)&pglStencilOp }, -{ "glClearStencil" , (void **)&pglClearStencil }, -{ "glIsEnabled" , (void **)&pglIsEnabled }, -{ "glIsList" , (void **)&pglIsList }, -{ "glIsTexture" , (void **)&pglIsTexture }, -{ "glTexEnvf" , (void **)&pglTexEnvf }, -{ "glTexEnvfv" , (void **)&pglTexEnvfv }, -{ "glTexEnvi" , (void **)&pglTexEnvi }, -{ "glTexParameterf" , (void **)&pglTexParameterf }, -{ "glTexParameterfv" , (void **)&pglTexParameterfv }, -{ "glTexParameteri" , (void **)&pglTexParameteri }, -{ "glHint" , (void **)&pglHint }, -{ "glPixelStoref" , (void **)&pglPixelStoref }, -{ "glPixelStorei" , (void **)&pglPixelStorei }, -{ "glGenTextures" , (void **)&pglGenTextures }, -{ "glDeleteTextures" , (void **)&pglDeleteTextures }, -{ "glBindTexture" , (void **)&pglBindTexture }, -{ "glTexImage1D" , (void **)&pglTexImage1D }, -{ "glTexImage2D" , (void **)&pglTexImage2D }, -{ "glTexSubImage1D" , (void **)&pglTexSubImage1D }, -{ "glTexSubImage2D" , (void **)&pglTexSubImage2D }, -{ "glCopyTexImage1D" , (void **)&pglCopyTexImage1D }, -{ "glCopyTexImage2D" , (void **)&pglCopyTexImage2D }, -{ "glCopyTexSubImage1D" , (void **)&pglCopyTexSubImage1D }, -{ "glCopyTexSubImage2D" , (void **)&pglCopyTexSubImage2D }, -{ "glScissor" , (void **)&pglScissor }, -{ "glGetTexImage" , (void **)&pglGetTexImage }, -{ "glGetTexEnviv" , (void **)&pglGetTexEnviv }, -{ "glPolygonOffset" , (void **)&pglPolygonOffset }, -{ "glPolygonMode" , (void **)&pglPolygonMode }, -{ "glPolygonStipple" , (void **)&pglPolygonStipple }, -{ "glClipPlane" , (void **)&pglClipPlane }, -{ "glGetClipPlane" , (void **)&pglGetClipPlane }, -{ "glShadeModel" , (void **)&pglShadeModel }, -{ "glGetTexLevelParameteriv" , (void **)&pglGetTexLevelParameteriv }, -{ "glGetTexLevelParameterfv" , (void **)&pglGetTexLevelParameterfv }, -{ "glFogfv" , (void **)&pglFogfv }, -{ "glFogf" , (void **)&pglFogf }, -{ "glFogi" , (void **)&pglFogi }, -{ NULL , NULL } + { GL_CALL( glClearColor ) }, + { GL_CALL( glClear ) }, + { GL_CALL( glAlphaFunc ) }, + { GL_CALL( glBlendFunc ) }, + { GL_CALL( glCullFace ) }, + { GL_CALL( glDrawBuffer ) }, + { GL_CALL( glReadBuffer ) }, + { GL_CALL( glAccum ) }, + { GL_CALL( glEnable ) }, + { GL_CALL( glDisable ) }, + { GL_CALL( glEnableClientState ) }, + { GL_CALL( glDisableClientState ) }, + { GL_CALL( glGetBooleanv ) }, + { GL_CALL( glGetDoublev ) }, + { GL_CALL( glGetFloatv ) }, + { GL_CALL( glGetIntegerv ) }, + { GL_CALL( glGetError ) }, + { GL_CALL( glGetString ) }, + { GL_CALL( glFinish ) }, + { GL_CALL( glFlush ) }, + { GL_CALL( glClearDepth ) }, + { GL_CALL( glDepthFunc ) }, + { GL_CALL( glDepthMask ) }, + { GL_CALL( glDepthRange ) }, + { GL_CALL( glFrontFace ) }, + { GL_CALL( glDrawElements ) }, + { GL_CALL( glDrawArrays ) }, + { GL_CALL( glColorMask ) }, + { GL_CALL( glIndexPointer ) }, + { GL_CALL( glVertexPointer ) }, + { GL_CALL( glNormalPointer ) }, + { GL_CALL( glColorPointer ) }, + { GL_CALL( glTexCoordPointer ) }, + { GL_CALL( glArrayElement ) }, + { GL_CALL( glColor3f ) }, + { GL_CALL( glColor3fv ) }, + { GL_CALL( glColor4f ) }, + { GL_CALL( glColor4fv ) }, + { GL_CALL( glColor3ub ) }, + { GL_CALL( glColor4ub ) }, + { GL_CALL( glColor4ubv ) }, + { GL_CALL( glTexCoord1f ) }, + { GL_CALL( glTexCoord2f ) }, + { GL_CALL( glTexCoord3f ) }, + { GL_CALL( glTexCoord4f ) }, + { GL_CALL( glTexCoord1fv ) }, + { GL_CALL( glTexCoord2fv ) }, + { GL_CALL( glTexCoord3fv ) }, + { GL_CALL( glTexCoord4fv ) }, + { GL_CALL( glTexGenf ) }, + { GL_CALL( glTexGenfv ) }, + { GL_CALL( glTexGeni ) }, + { GL_CALL( glVertex2f ) }, + { GL_CALL( glVertex3f ) }, + { GL_CALL( glVertex3fv ) }, + { GL_CALL( glNormal3f ) }, + { GL_CALL( glNormal3fv ) }, + { GL_CALL( glBegin ) }, + { GL_CALL( glEnd ) }, + { GL_CALL( glLineWidth ) }, + { GL_CALL( glPointSize ) }, + { GL_CALL( glMatrixMode ) }, + { GL_CALL( glOrtho ) }, + { GL_CALL( glRasterPos2f ) }, + { GL_CALL( glFrustum ) }, + { GL_CALL( glViewport ) }, + { GL_CALL( glPushMatrix ) }, + { GL_CALL( glPopMatrix ) }, + { GL_CALL( glPushAttrib ) }, + { GL_CALL( glPopAttrib ) }, + { GL_CALL( glLoadIdentity ) }, + { GL_CALL( glLoadMatrixd ) }, + { GL_CALL( glLoadMatrixf ) }, + { GL_CALL( glMultMatrixd ) }, + { GL_CALL( glMultMatrixf ) }, + { GL_CALL( glRotated ) }, + { GL_CALL( glRotatef ) }, + { GL_CALL( glScaled ) }, + { GL_CALL( glScalef ) }, + { GL_CALL( glTranslated ) }, + { GL_CALL( glTranslatef ) }, + { GL_CALL( glReadPixels ) }, + { GL_CALL( glDrawPixels ) }, + { GL_CALL( glStencilFunc ) }, + { GL_CALL( glStencilMask ) }, + { GL_CALL( glStencilOp ) }, + { GL_CALL( glClearStencil ) }, + { GL_CALL( glIsEnabled ) }, + { GL_CALL( glIsList ) }, + { GL_CALL( glIsTexture ) }, + { GL_CALL( glTexEnvf ) }, + { GL_CALL( glTexEnvfv ) }, + { GL_CALL( glTexEnvi ) }, + { GL_CALL( glTexParameterf ) }, + { GL_CALL( glTexParameterfv ) }, + { GL_CALL( glTexParameteri ) }, + { GL_CALL( glHint ) }, + { GL_CALL( glPixelStoref ) }, + { GL_CALL( glPixelStorei ) }, + { GL_CALL( glGenTextures ) }, + { GL_CALL( glDeleteTextures ) }, + { GL_CALL( glBindTexture ) }, + { GL_CALL( glTexImage1D ) }, + { GL_CALL( glTexImage2D ) }, + { GL_CALL( glTexSubImage1D ) }, + { GL_CALL( glTexSubImage2D ) }, + { GL_CALL( glCopyTexImage1D ) }, + { GL_CALL( glCopyTexImage2D ) }, + { GL_CALL( glCopyTexSubImage1D ) }, + { GL_CALL( glCopyTexSubImage2D ) }, + { GL_CALL( glScissor ) }, + { GL_CALL( glGetTexImage ) }, + { GL_CALL( glGetTexEnviv ) }, + { GL_CALL( glPolygonOffset ) }, + { GL_CALL( glPolygonMode ) }, + { GL_CALL( glPolygonStipple ) }, + { GL_CALL( glClipPlane ) }, + { GL_CALL( glGetClipPlane ) }, + { GL_CALL( glShadeModel ) }, + { GL_CALL( glGetTexLevelParameteriv ) }, + { GL_CALL( glGetTexLevelParameterfv ) }, + { GL_CALL( glFogfv ) }, + { GL_CALL( glFogf ) }, + { GL_CALL( glFogi ) }, + { NULL , NULL } }; static dllfunc_t debugoutputfuncs[] = { -{ "glDebugMessageControlARB" , (void **)&pglDebugMessageControlARB }, -{ "glDebugMessageInsertARB" , (void **)&pglDebugMessageInsertARB }, -{ "glDebugMessageCallbackARB" , (void **)&pglDebugMessageCallbackARB }, -{ "glGetDebugMessageLogARB" , (void **)&pglGetDebugMessageLogARB }, -{ NULL , NULL } + { GL_CALL( glDebugMessageControlARB ) }, + { GL_CALL( glDebugMessageInsertARB ) }, + { GL_CALL( glDebugMessageCallbackARB ) }, + { GL_CALL( glGetDebugMessageLogARB ) }, + { NULL , NULL } }; static dllfunc_t multitexturefuncs[] = { -{ "glMultiTexCoord1fARB" , (void **)&pglMultiTexCoord1f }, -{ "glMultiTexCoord2fARB" , (void **)&pglMultiTexCoord2f }, -{ "glMultiTexCoord3fARB" , (void **)&pglMultiTexCoord3f }, -{ "glMultiTexCoord4fARB" , (void **)&pglMultiTexCoord4f }, -{ "glActiveTextureARB" , (void **)&pglActiveTexture }, -{ "glActiveTextureARB" , (void **)&pglActiveTextureARB }, -{ "glClientActiveTextureARB" , (void **)&pglClientActiveTexture }, -{ "glClientActiveTextureARB" , (void **)&pglClientActiveTextureARB }, -{ NULL , NULL } + { GL_CALL( glMultiTexCoord1f ) }, + { GL_CALL( glMultiTexCoord2f ) }, + { GL_CALL( glMultiTexCoord3f ) }, + { GL_CALL( glMultiTexCoord4f ) }, + { GL_CALL( glActiveTexture ) }, + { GL_CALL( glActiveTextureARB ) }, + { GL_CALL( glClientActiveTexture ) }, + { GL_CALL( glClientActiveTextureARB ) }, + { NULL , NULL } }; static dllfunc_t texture3dextfuncs[] = { -{ "glTexImage3DEXT" , (void **)&pglTexImage3D }, -{ "glTexSubImage3DEXT" , (void **)&pglTexSubImage3D }, -{ "glCopyTexSubImage3DEXT" , (void **)&pglCopyTexSubImage3D }, -{ NULL , NULL } + { GL_CALL( glTexImage3D ) }, + { GL_CALL( glTexSubImage3D ) }, + { GL_CALL( glCopyTexSubImage3D ) }, + { NULL , NULL } }; static dllfunc_t texturecompressionfuncs[] = { -{ "glCompressedTexImage3DARB" , (void **)&pglCompressedTexImage3DARB }, -{ "glCompressedTexImage2DARB" , (void **)&pglCompressedTexImage2DARB }, -{ "glCompressedTexImage1DARB" , (void **)&pglCompressedTexImage1DARB }, -{ "glCompressedTexSubImage3DARB" , (void **)&pglCompressedTexSubImage3DARB }, -{ "glCompressedTexSubImage2DARB" , (void **)&pglCompressedTexSubImage2DARB }, -{ "glCompressedTexSubImage1DARB" , (void **)&pglCompressedTexSubImage1DARB }, -{ "glGetCompressedTexImageARB" , (void **)&pglGetCompressedTexImage }, -{ NULL , NULL } + { GL_CALL( glCompressedTexImage3DARB ) }, + { GL_CALL( glCompressedTexImage2DARB ) }, + { GL_CALL( glCompressedTexImage1DARB ) }, + { GL_CALL( glCompressedTexSubImage3DARB ) }, + { GL_CALL( glCompressedTexSubImage2DARB ) }, + { GL_CALL( glCompressedTexSubImage1DARB ) }, + { GL_CALL( glGetCompressedTexImage ) }, + { NULL , NULL } +}; + +static dllfunc_t vbofuncs[] = +{ + { GL_CALL( glBindBufferARB ) }, + { GL_CALL( glDeleteBuffersARB ) }, + { GL_CALL( glGenBuffersARB ) }, + { GL_CALL( glIsBufferARB ) }, + { GL_CALL( glMapBufferARB ) }, + { GL_CALL( glUnmapBufferARB ) }, // , + { GL_CALL( glBufferDataARB ) }, + { GL_CALL( glBufferSubDataARB ) }, + { NULL, NULL} }; static void GL_SetupAttributes( void ); @@ -884,7 +897,6 @@ qboolean R_Init_Video( void ) return true; } - #ifdef XASH_GLES void GL_InitExtensionsGLES( void ) { @@ -1039,6 +1051,8 @@ void GL_InitExtensionsBigGL() GL_CheckExtension( "GL_ARB_depth_buffer_float", NULL, "gl_arb_depth_float", GL_ARB_DEPTH_FLOAT_EXT ); GL_CheckExtension( "GL_EXT_gpu_shader4", NULL, NULL, GL_EXT_GPU_SHADER4 ); // don't confuse users GL_CheckExtension( "GL_ARB_shading_language_100", NULL, "gl_glslprogram", GL_SHADER_GLSL100_EXT ); + GL_CheckExtension( "GL_ARB_vertex_buffer_object", vbofuncs, "gl_vertex_buffer_object", GL_ARB_VERTEX_BUFFER_OBJECT_EXT ); + // rectangle textures support GL_CheckExtension( "GL_ARB_texture_rectangle", NULL, "gl_texture_rectangle", GL_TEXTURE_2D_RECT_EXT );