diff options
-rw-r--r-- | source/gl_local.h | 7 | ||||
-rw-r--r-- | source/gl_main.c | 19 | ||||
-rw-r--r-- | source/gl_surf.c | 6 | ||||
-rw-r--r-- | source/gl_tess.c | 114 |
4 files changed, 85 insertions, 61 deletions
diff --git a/source/gl_local.h b/source/gl_local.h index 0c4cb78..f952786 100644 --- a/source/gl_local.h +++ b/source/gl_local.h @@ -44,7 +44,7 @@ typedef struct { qboolean registering; uint32 palette[256]; /* cinematic palette */ GLuint prog_warp, prog_light; - vec_t *vbo; + vec_t *vertices; } glStatic_t; typedef struct { @@ -333,10 +333,9 @@ qhandle_t R_RegisterPic( const char *name ); #define TESS_MAX_INDICES ( 3 * TESS_MAX_VERTICES ) typedef struct { - vec_t vertices[4*TESS_MAX_VERTICES]; - byte colors[4*TESS_MAX_VERTICES]; - tcoord_t tcoords[TESS_MAX_VERTICES]; + vec_t vertices[VERTEX_SIZE*TESS_MAX_VERTICES]; int indices[TESS_MAX_INDICES]; + byte colors[4*TESS_MAX_VERTICES]; int texnum[MAX_TMUS]; int numVertices; int numIndices; diff --git a/source/gl_main.c b/source/gl_main.c index 3ac9ef0..aa807be 100644 --- a/source/gl_main.c +++ b/source/gl_main.c @@ -709,7 +709,7 @@ static void GL_Register( void ) { gl_fullbright = cvar.Get( "r_fullbright", "0", CVAR_CHEAT ); gl_showerrors = cvar.Get( "gl_showerrors", "1", 0 ); gl_fragment_program = cvar.Get( "gl_fragment_program", "0", CVAR_LATCHED ); - gl_vertex_buffer_object = cvar.Get( "gl_vertex_buffer_object", "1", CVAR_LATCHED ); + gl_vertex_buffer_object = cvar.Get( "gl_vertex_buffer_object", "0", CVAR_LATCHED ); cmd.AddCommand( "screenshot", GL_ScreenShot_f ); #if USE_JPEG @@ -753,8 +753,8 @@ static qboolean GL_SetupExtensions( void ) { gl_static.numTextureUnits = 1; if( strstr( extensions, "GL_ARB_multitexture" ) ) { qglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &integer ); - if( integer > 1 ) { - Com_Printf( "...enabling GL_ARB_multitexture (%d texture units)\n", integer ); + if( integer >= 2 ) { + Com_Printf( "...enabling GL_ARB_multitexture (%d TMUs)\n", integer ); GPA( glActiveTextureARB ); GPA( glClientActiveTextureARB ); if( integer > MAX_TMUS ) { @@ -763,7 +763,7 @@ static qboolean GL_SetupExtensions( void ) { gl_static.numTextureUnits = integer; } else { Com_Printf( "...ignoring GL_ARB_multitexture,\n" - "not enough texture units supported (%d)\n", integer ); + "%d TMU is not enough\n", integer ); } } else { Com_Printf( "GL_ARB_multitexture not found\n" ); @@ -773,12 +773,11 @@ static qboolean GL_SetupExtensions( void ) { if( strstr( extensions, "GL_EXT_texture_filter_anisotropic" ) ) { qglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &value ); if( value >= 2 ) { - Com_Printf( "...enabling GL_EXT_texture_filter_anisotropic\n" - "(max anisotropy is %.1f)\n", value ); + Com_Printf( "...enabling GL_EXT_texture_filter_anisotropic (%d max)\n", ( int )value ); gl_config.maxAnisotropy = value; } else { Com_Printf( "...ignoring GL_EXT_texture_filter_anisotropic,\n" - "not enough anisotropy supported (%.1f)\n", value ); + "%d anisotropy is not enough\n", ( int )value ); } } else { Com_Printf( "GL_EXT_texture_filter_anisotropic not found\n" ); @@ -907,7 +906,7 @@ static qboolean GL_Init( qboolean total ) { } if( !GL_SetupExtensions() ) { - Com_EPrintf( "Some of the required OpenGL extensions are missing\n" ); + Com_EPrintf( "Required OpenGL extensions are missing\n" ); goto fail; } @@ -945,11 +944,11 @@ static void GL_FreeWorld( void ) { Bsp_FreeWorld(); - if( !gl_static.vbo && qglDeleteBuffersARB ) { + if( !gl_static.vertices && qglDeleteBuffersARB ) { qglDeleteBuffersARB( 1, &buf ); } - gl_static.vbo = NULL; + gl_static.vertices = NULL; } /* diff --git a/source/gl_surf.c b/source/gl_surf.c index 3e4bbcf..bdc90da 100644 --- a/source/gl_surf.c +++ b/source/gl_surf.c @@ -397,7 +397,7 @@ void GL_EndPostProcessing( void ) { vbo = qglMapBufferARB( GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB ); if( vbo ) { - gl_static.vbo = NULL; + gl_static.vertices = NULL; Com_DPrintf( "%s: %d bytes of vertex data as VBO\n", __func__, size ); } else { Com_EPrintf( "Failed to map VBO data in client memory\n" ); @@ -406,7 +406,7 @@ void GL_EndPostProcessing( void ) { } if( !vbo ) { - gl_static.vbo = vbo = sys.HunkAlloc( &r_world.pool, size ); + gl_static.vertices = vbo = sys.HunkAlloc( &r_world.pool, size ); Com_DPrintf( "%s: %d bytes of vertex data on hunk\n", __func__, size ); } @@ -428,7 +428,7 @@ void GL_EndPostProcessing( void ) { vbo += surf->numVerts * VERTEX_SIZE; } - if( qglBindBufferARB && !gl_static.vbo ) { + if( qglBindBufferARB && !gl_static.vertices ) { qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 1 ); if( !qglUnmapBufferARB( GL_ARRAY_BUFFER_ARB ) ) { Com_Error( ERR_DROP, "Failed to unmap VBO data" ); diff --git a/source/gl_tess.c b/source/gl_tess.c index eda9706..187ca22 100644 --- a/source/gl_tess.c +++ b/source/gl_tess.c @@ -49,8 +49,8 @@ void GL_Flush2D( void ) { qglEnableClientState( GL_COLOR_ARRAY ); qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors ); - qglTexCoordPointer( 2, GL_FLOAT, 0, tess.tcoords ); - qglVertexPointer( 3, GL_FLOAT, 16, tess.vertices ); + qglTexCoordPointer( 2, GL_FLOAT, 16, tess.vertices + 2 ); + qglVertexPointer( 2, GL_FLOAT, 16, tess.vertices ); if( qglLockArraysEXT ) { qglLockArraysEXT( 0, tess.numVertices ); @@ -80,7 +80,6 @@ void GL_StretchPic( float x, float y, float w, float h, const byte *color, image_t *image ) { vec_t *dst_vert; - tcoord_t *dst_tc; uint32 *dst_color; if( tess.numVertices + 4 > TESS_MAX_VERTICES || @@ -92,10 +91,10 @@ void GL_StretchPic( float x, float y, float w, float h, tess.texnum[0] = image->texnum; dst_vert = tess.vertices + tess.numVertices * 4; - VectorSet( dst_vert, x, y, 0 ); - VectorSet( dst_vert + 4, x + w, y, 0 ); - VectorSet( dst_vert + 8, x + w, y + h, 0 ); - VectorSet( dst_vert + 12, x, y + h, 0 ); + Vector4Set( dst_vert, x, y, s1, t1 ); + Vector4Set( dst_vert + 4, x + w, y, s2, t1 ); + Vector4Set( dst_vert + 8, x + w, y + h, s2, t2 ); + Vector4Set( dst_vert + 12, x, y + h, s1, t2 ); dst_color = ( uint32 * )tess.colors + tess.numVertices; dst_color[0] = *( const uint32 * )color; @@ -114,12 +113,6 @@ void GL_StretchPic( float x, float y, float w, float h, tess.flags |= 2; } - dst_tc = tess.tcoords + tess.numVertices; - dst_tc[0].st[0] = s1; dst_tc[0].st[1] = t1; - dst_tc[1].st[0] = s2; dst_tc[1].st[1] = t1; - dst_tc[2].st[0] = s2; dst_tc[2].st[1] = t2; - dst_tc[3].st[0] = s1; dst_tc[3].st[1] = t2; - tess.numVertices += 4; } @@ -132,7 +125,6 @@ void GL_DrawParticles( void ) { int numVertices; vec_t *dst_vert; uint32 *dst_color; - tcoord_t *dst_tc; if( !glr.fd.num_particles ) { return; @@ -144,8 +136,8 @@ void GL_DrawParticles( void ) { qglEnableClientState( GL_COLOR_ARRAY ); qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors ); - qglTexCoordPointer( 2, GL_FLOAT, 0, tess.tcoords ); - qglVertexPointer( 3, GL_FLOAT, 16, tess.vertices ); + qglTexCoordPointer( 2, GL_FLOAT, 20, tess.vertices + 3 ); + qglVertexPointer( 3, GL_FLOAT, 20, tess.vertices ); numVertices = 0; for( i = 0, p = glr.fd.particles; i < glr.fd.num_particles; i++, p++ ) { @@ -169,22 +161,21 @@ void GL_DrawParticles( void ) { numVertices = 0; } - dst_vert = tess.vertices + numVertices * 4; + dst_vert = tess.vertices + numVertices * 5; // VectorMA( p->origin, -scale*0.5f, glr.viewaxis[2], dst_vert ); VectorMA( p->origin, scale*0.5f, glr.viewaxis[1], dst_vert ); - VectorMA( dst_vert, scale, glr.viewaxis[2], dst_vert + 4 ); - VectorMA( dst_vert, -scale, glr.viewaxis[1], dst_vert + 8 ); + VectorMA( dst_vert, scale, glr.viewaxis[2], dst_vert + 5 ); + VectorMA( dst_vert, -scale, glr.viewaxis[1], dst_vert + 10 ); + + dst_vert[3] = 0.0625f; dst_vert[4] = 0.0625f; + dst_vert[8] = 1.0625f; dst_vert[9] = 0.0625f; + dst_vert[13] = 0.0625f; dst_vert[14] = 1.0625f; dst_color = ( uint32 * )tess.colors + numVertices; dst_color[0] = *( uint32 * )color; dst_color[1] = *( uint32 * )color; dst_color[2] = *( uint32 * )color; - dst_tc = tess.tcoords + numVertices; - dst_tc[0].st[0] = 0.0625f; dst_tc[0].st[1] = 0.0625f; - dst_tc[1].st[0] = 1.0625f; dst_tc[1].st[1] = 0.0625f; - dst_tc[2].st[0] = 0.0625f; dst_tc[2].st[1] = 1.0625f; - numVertices += 3; } @@ -199,7 +190,6 @@ void GL_DrawBeams( void ) { color_t color; vec_t *dst_vert; uint32 *dst_color; - tcoord_t *dst_tc; vec_t length; int numVertices; entity_t *ent; @@ -214,8 +204,8 @@ void GL_DrawBeams( void ) { GL_Bits( GLS_BLEND_ADD | GLS_DEPTHMASK_FALSE ); qglEnableClientState( GL_COLOR_ARRAY ); qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors ); - qglTexCoordPointer( 2, GL_FLOAT, 0, tess.tcoords ); - qglVertexPointer( 3, GL_FLOAT, 16, tess.vertices ); + qglTexCoordPointer( 2, GL_FLOAT, 20, tess.vertices + 3 ); + qglVertexPointer( 3, GL_FLOAT, 20, tess.vertices ); numVertices = 0; for( i = 0, ent = glr.fd.entities; i < glr.fd.num_entities; i++, ent++ ) { @@ -245,11 +235,16 @@ void GL_DrawBeams( void ) { numVertices = 0; } - dst_vert = tess.vertices + numVertices * 4; + dst_vert = tess.vertices + numVertices * 5; VectorAdd( start, d3, dst_vert ); - VectorSubtract( start, d3, dst_vert + 4 ); - VectorSubtract( end, d3, dst_vert + 8 ); - VectorAdd( end, d3, dst_vert + 12 ); + VectorSubtract( start, d3, dst_vert + 5 ); + VectorSubtract( end, d3, dst_vert + 10 ); + VectorAdd( end, d3, dst_vert + 15 ); + + dst_vert[3] = 0; dst_vert[4] = 0; + dst_vert[8] = 1; dst_vert[9] = 0; + dst_vert[13] = 1; dst_vert[14] = length; + dst_vert[18] = 0; dst_vert[19] = length; dst_color = ( uint32 * )tess.colors + numVertices; dst_color[0] = *( uint32 * )color; @@ -257,12 +252,6 @@ void GL_DrawBeams( void ) { dst_color[2] = *( uint32 * )color; dst_color[3] = *( uint32 * )color; - dst_tc = tess.tcoords + numVertices; - dst_tc[0].st[0] = 0; dst_tc[0].st[1] = 0; - dst_tc[1].st[0] = 1; dst_tc[1].st[1] = 0; - dst_tc[2].st[0] = 1; dst_tc[2].st[1] = length; - dst_tc[3].st[0] = 0; dst_tc[3].st[1] = length; - numVertices += 4; } @@ -271,23 +260,26 @@ void GL_DrawBeams( void ) { } static void GL_BindArrays( void ) { - vec_t *vbo = gl_static.vbo; + vec_t *ptr; - if( !vbo && qglBindBufferARB ) { + if( gl_static.vertices ) { + ptr = tess.vertices; + } else { + ptr = NULL; qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 1 ); } - qglVertexPointer( 3, GL_FLOAT, 4*VERTEX_SIZE, vbo + 0 ); - qglTexCoordPointer( 2, GL_FLOAT, 4*VERTEX_SIZE, vbo + 3 ); + qglVertexPointer( 3, GL_FLOAT, 4*VERTEX_SIZE, ptr + 0 ); + qglTexCoordPointer( 2, GL_FLOAT, 4*VERTEX_SIZE, ptr + 3 ); qglClientActiveTextureARB( GL_TEXTURE1_ARB ); qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); - qglTexCoordPointer( 2, GL_FLOAT, 4*VERTEX_SIZE, vbo + 5 ); + qglTexCoordPointer( 2, GL_FLOAT, 4*VERTEX_SIZE, ptr + 5 ); qglClientActiveTextureARB( GL_TEXTURE0_ARB ); } static void GL_UnbindArrays( void ) { - if( qglBindBufferARB ) { + if( !gl_static.vertices ) { qglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); } qglClientActiveTextureARB( GL_TEXTURE1_ARB ); @@ -315,6 +307,10 @@ static void GL_Flush3D( void ) { GL_BindTexture( tess.texnum[1] ); } + if( gl_static.vertices && qglLockArraysEXT ) { + qglLockArraysEXT( 0, tess.numVertices ); + } + qglDrawElements( GL_TRIANGLES, tess.numIndices, GL_UNSIGNED_INT, tess.indices ); if( tess.texnum[1] ) { @@ -328,16 +324,39 @@ static void GL_Flush3D( void ) { GL_DisableOutlines(); } + if( gl_static.vertices && qglUnlockArraysEXT ) { + qglUnlockArraysEXT(); + } + c.batchesDrawn++; tess.texnum[0] = tess.texnum[1] = 0; tess.numIndices = 0; + tess.numVertices = 0; tess.flags = 0; } +static void GL_CopyVerts( bspSurface_t *surf ) { + uint32 *src_vert, *dst_vert; + int i, j; + + if( tess.numVertices + surf->numVerts > TESS_MAX_VERTICES ) { + GL_Flush3D(); + } + + src_vert = ( uint32 * )gl_static.vertices + surf->firstVert * VERTEX_SIZE; + dst_vert = ( uint32 * )tess.vertices + tess.numVertices * VERTEX_SIZE; + for( i = 0; i < surf->numVerts; i++ ) { + for( j = 0; j < VERTEX_SIZE; j++ ) { + *dst_vert++ = *src_vert++; + } + } + tess.numVertices += surf->numVerts; +} + static void GL_DrawFace( bspSurface_t *surf ) { int *dst_indices; - int i, j = surf->firstVert; + int i, j; if( tess.texnum[0] != surf->texnum[0] || tess.texnum[1] != surf->texnum[1] || @@ -347,6 +366,13 @@ static void GL_DrawFace( bspSurface_t *surf ) { GL_Flush3D(); } + if( gl_static.vertices ) { + j = tess.numVertices; + GL_CopyVerts( surf ); + } else { + j = surf->firstVert; + } + tess.texnum[0] = surf->texnum[0]; tess.texnum[1] = surf->texnum[1]; tess.flags = surf->texflags; |