diff options
-rw-r--r-- | src/gl_draw.c | 16 | ||||
-rw-r--r-- | src/gl_main.c | 163 | ||||
-rw-r--r-- | src/gl_sky.c | 27 | ||||
-rw-r--r-- | src/gl_tess.c | 40 | ||||
-rw-r--r-- | src/q_shared.h | 4 |
5 files changed, 142 insertions, 108 deletions
diff --git a/src/gl_draw.c b/src/gl_draw.c index 9e5685b..d503669 100644 --- a/src/gl_draw.c +++ b/src/gl_draw.c @@ -29,8 +29,10 @@ static inline void _GL_StretchPic( { vec_t *dst_vert; uint32_t *dst_color; - + int *dst_indices; + if( tess.numverts + 4 > TESS_MAX_VERTICES || + tess.numindices + 6 > TESS_MAX_INDICES || ( tess.numverts && tess.texnum[0] != texnum ) ) { GL_Flush2D(); @@ -49,7 +51,15 @@ static inline void _GL_StretchPic( dst_color[1] = *( const uint32_t * )color; dst_color[2] = *( const uint32_t * )color; dst_color[3] = *( const uint32_t * )color; - + + dst_indices = tess.indices + tess.numindices; + dst_indices[0] = tess.numverts + 0; + dst_indices[1] = tess.numverts + 2; + dst_indices[2] = tess.numverts + 3; + dst_indices[3] = tess.numverts + 0; + dst_indices[4] = tess.numverts + 1; + dst_indices[5] = tess.numverts + 2; + if( flags & if_transparent ) { if( ( flags & if_paletted ) && draw.scale == 1 ) { tess.flags |= 1; @@ -57,11 +67,13 @@ static inline void _GL_StretchPic( tess.flags |= 2; } } + if( color[3] != 255 ) { tess.flags |= 2; } tess.numverts += 4; + tess.numindices += 6; } #define GL_StretchPic(x,y,w,h,s1,t1,s2,t2,color,image) \ diff --git a/src/gl_main.c b/src/gl_main.c index fc5247d..b504758 100644 --- a/src/gl_main.c +++ b/src/gl_main.c @@ -223,35 +223,24 @@ glCullResult_t GL_CullLocalBox( const vec3_t origin, vec3_t bounds[2] ) { #if 0 void GL_DrawBox( const vec3_t origin, vec3_t bounds[2] ) { - static const int indices[2][4] = { - { 0, 1, 3, 2 }, - { 4, 5, 7, 6 } - }; + static const int indices1[4] = { 0, 1, 3, 2 }; + static const int indices2[4] = { 4, 5, 7, 6 }; + static const int indices3[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; vec3_t points[8]; - int i, j; qglDisable( GL_TEXTURE_2D ); - GL_TexEnv( GL_REPLACE ); qglDisable( GL_DEPTH_TEST ); + qglDisableClientState( GL_TEXTURE_COORD_ARRAY ); qglColor4f( 1, 1, 1, 1 ); make_box_points( origin, bounds, points ); - for( i = 0; i < 2; i++ ) { - qglBegin( GL_LINE_LOOP ); - for( j = 0; j < 4; j++ ) { - qglVertex3fv( points[ indices[i][j] ] ); - } - qglEnd(); - } + qglVertexPointer( 3, GL_FLOAT, 0, points ); + qglDrawElements( GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indices1 ); + qglDrawElements( GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indices2 ); + qglDrawElements( GL_LINES, 8, GL_UNSIGNED_INT, indices3 ); - qglBegin( GL_LINES ); - for( i = 0; i < 4; i++ ) { - qglVertex3fv( points[ i ] ); - qglVertex3fv( points[ i + 4 ] ); - } - qglEnd(); - + qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); qglEnable( GL_DEPTH_TEST ); qglEnable( GL_TEXTURE_2D ); } @@ -296,22 +285,16 @@ qboolean GL_AllocBlock( int width, int height, int *inuse, } static void GL_DrawSpriteModel( model_t *model ) { - vec3_t point; + static const vec_t tcoords[8] = { 0, 1, 0, 0, 1, 1, 1, 0 }; entity_t *e = glr.ent; - mspriteframe_t *frame; - image_t *image; - int bits; - float alpha; - - frame = &model->spriteframes[e->frame % model->numframes]; - image = frame->image; + mspriteframe_t *frame = &model->spriteframes[e->frame % model->numframes]; + image_t *image = frame->image; + float alpha = ( e->flags & RF_TRANSLUCENT ) ? e->alpha : 1; + int bits = GLS_DEPTHMASK_FALSE; + vec3_t up, down, left, right; + vec3_t points[4]; - GL_TexEnv( GL_MODULATE ); - - alpha = ( e->flags & RF_TRANSLUCENT ) ? e->alpha : 1.0f; - - bits = GLS_DEPTHMASK_FALSE; - if( alpha == 1.0f ) { + if( alpha == 1 ) { if( image->flags & if_transparent ) { if( image->flags & if_paletted ) { bits |= GLS_ALPHATEST_ENABLE; @@ -322,60 +305,58 @@ static void GL_DrawSpriteModel( model_t *model ) { } else { bits |= GLS_BLEND_BLEND; } - GL_Bits( bits ); - - qglColor4f( 1, 1, 1, alpha ); + GL_TexEnv( GL_MODULATE ); + GL_Bits( bits ); GL_BindTexture( image->texnum ); + qglColor4f( 1, 1, 1, alpha ); - qglBegin( GL_QUADS ); - - qglTexCoord2f( 0, 1 ); - VectorMA( e->origin, -frame->origin_y, glr.viewaxis[2], point ); - VectorMA( point, frame->origin_x, glr.viewaxis[1], point ); - qglVertex3fv( point ); - - qglTexCoord2f( 0, 0 ); - VectorMA( e->origin, frame->height - frame->origin_y, glr.viewaxis[2], point ); - VectorMA( point, frame->origin_x, glr.viewaxis[1], point ); - qglVertex3fv( point ); - - qglTexCoord2f( 1, 0 ); - VectorMA( e->origin, frame->height - frame->origin_y, glr.viewaxis[2], point ); - VectorMA( point, frame->origin_x - frame->width, glr.viewaxis[1], point ); - qglVertex3fv( point ); + VectorScale( glr.viewaxis[1], frame->origin_x, left ); + VectorScale( glr.viewaxis[1], frame->origin_x - frame->width, right ); + VectorScale( glr.viewaxis[2], -frame->origin_y, down ); + VectorScale( glr.viewaxis[2], frame->height - frame->origin_y, up ); - qglTexCoord2f( 1, 1 ); - VectorMA( e->origin, -frame->origin_y, glr.viewaxis[2], point ); - VectorMA( point, frame->origin_x - frame->width, glr.viewaxis[1], point ); - qglVertex3fv( point ); + VectorAdd3( e->origin, down, left, points[0] ); + VectorAdd3( e->origin, up, left, points[1] ); + VectorAdd3( e->origin, down, right, points[2] ); + VectorAdd3( e->origin, up, right, points[3] ); - qglEnd(); + qglTexCoordPointer( 2, GL_FLOAT, 0, tcoords ); + qglVertexPointer( 3, GL_FLOAT, 0, points ); + qglDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); } static void GL_DrawNullModel( void ) { - vec3_t point; + static const color_t colors[6] = { + { 255, 0, 0, 255 }, + { 255, 0, 0, 255 }, + { 0, 255, 0, 255 }, + { 0, 255, 0, 255 }, + { 0, 0, 255, 255 }, + { 0, 0, 255, 255 } + }; + entity_t *e = glr.ent; + vec3_t points[6]; - qglDisable( GL_TEXTURE_2D ); - //qglDisable( GL_DEPTH_TEST ); - qglBegin( GL_LINES ); + VectorCopy( e->origin, points[0] ); + VectorCopy( e->origin, points[2] ); + VectorCopy( e->origin, points[4] ); - qglColor3f( 1, 0, 0 ); - qglVertex3fv( glr.ent->origin ); - VectorMA( glr.ent->origin, 16, glr.entaxis[0], point ); - qglVertex3fv( point ); + VectorMA( e->origin, 16, glr.entaxis[0], points[1] ); + VectorMA( e->origin, 16, glr.entaxis[1], points[3] ); + VectorMA( e->origin, 16, glr.entaxis[2], points[5] ); - qglColor3f( 0, 1, 0 ); - qglVertex3fv( glr.ent->origin ); - VectorMA( glr.ent->origin, 16, glr.entaxis[1], point ); - qglVertex3fv( point ); + qglDisable( GL_TEXTURE_2D ); + //qglDisable( GL_DEPTH_TEST ); + qglDisableClientState( GL_TEXTURE_COORD_ARRAY ); + qglEnableClientState( GL_COLOR_ARRAY ); - qglColor3f( 0, 0, 1 ); - qglVertex3fv( glr.ent->origin ); - VectorMA( glr.ent->origin, 16, glr.entaxis[2], point ); - qglVertex3fv( point ); + qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors ); + qglVertexPointer( 3, GL_FLOAT, 0, points ); + qglDrawArrays( GL_LINES, 0, 6 ); - qglEnd(); + qglDisableClientState( GL_COLOR_ARRAY ); + qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); //qglEnable( GL_DEPTH_TEST ); qglEnable( GL_TEXTURE_2D ); } @@ -452,24 +433,40 @@ static void GL_DrawEntities( int mask ) { } static void GL_DrawTearing( void ) { + vec2_t points[4]; static int i; - /* alternate colors to make tearing obvious */ + // alternate colors to make tearing obvious i++; - if (i & 1) { - qglClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); - qglColor3f( 1.0f, 1.0f, 1.0f ); + if( i & 1 ) { + qglClearColor( 1, 1, 1, 1 ); + qglColor4f( 1, 1, 1, 1 ); } else { - qglClearColor( 1.0f, 0.0f, 0.0f, 0.0f ); - qglColor3f( 1.0f, 0.0f, 0.0f ); + qglClearColor( 1, 0, 0, 0 ); + qglColor4f( 1, 0, 0, 1 ); } + points[0][0] = 0; + points[0][1] = gl_config.vidHeight; + points[1][0] = 0; + points[1][1] = 0; + points[2][0] = gl_config.vidWidth; + points[2][1] = gl_config.vidHeight; + points[3][0] = gl_config.vidWidth; + points[3][1] = 0; + qglClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + qglDisable( GL_TEXTURE_2D ); - qglRectf( 0, 0, gl_config.vidWidth, gl_config.vidHeight ); + qglDisableClientState( GL_TEXTURE_COORD_ARRAY ); + + qglVertexPointer( 2, GL_FLOAT, 0, points ); + qglDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); + + qglEnableClientState( GL_TEXTURE_COORD_ARRAY ); qglEnable( GL_TEXTURE_2D ); - qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + qglClearColor( 0, 0, 0, 1 ); } static const char *GL_ErrorString( GLenum err ) { diff --git a/src/gl_sky.c b/src/gl_sky.c index a92b468..cfa19d4 100644 --- a/src/gl_sky.c +++ b/src/gl_sky.c @@ -274,9 +274,9 @@ void R_ClearSkyBox( void ) { } -static void MakeSkyVec (float s, float t, int axis) +static void MakeSkyVec (float s, float t, int axis, vec_t *v) { - vec3_t v, b; + vec3_t b; int j, k; b[0] = s*4800;//2300; @@ -305,9 +305,8 @@ static void MakeSkyVec (float s, float t, int axis) else if (t > sky_max) t = sky_max; - t = 1.0 - t; - qglTexCoord2f (s, t); - qglVertex3fv (v); + v[3] = s; + v[4] = 1.0 - t; } #define SKY_VISIBLE( side ) \ @@ -320,8 +319,9 @@ R_DrawSkyBox ============== */ void R_DrawSkyBox( void ) { - int i; static const int skytexorder[6] = {0,2,1,3,4,5}; + vec5_t verts[4]; + int i; if( skyrotate ) { // hack, forces full sky to draw when rotating @@ -352,6 +352,9 @@ void R_DrawSkyBox( void ) { GL_TexEnv( GL_REPLACE ); GL_Bits( GLS_DEFAULT ); + qglVertexPointer( 3, GL_FLOAT, 5*4, &verts[0][0] ); + qglTexCoordPointer( 2, GL_FLOAT, 5*4, &verts[0][3] ); + for( i = 0; i < 6; i++ ) { if( !SKY_VISIBLE( i ) ) { continue; @@ -359,13 +362,13 @@ void R_DrawSkyBox( void ) { GL_BindTexture (sky_images[skytexorder[i]]); - qglBegin (GL_QUADS); - MakeSkyVec (skymins[0][i], skymins[1][i], i); - MakeSkyVec (skymins[0][i], skymaxs[1][i], i); - MakeSkyVec (skymaxs[0][i], skymaxs[1][i], i); - MakeSkyVec (skymaxs[0][i], skymins[1][i], i); - qglEnd (); + MakeSkyVec (skymaxs[0][i], skymins[1][i], i, verts[0]); + MakeSkyVec (skymins[0][i], skymins[1][i], i, verts[1]); + MakeSkyVec (skymaxs[0][i], skymaxs[1][i], i, verts[2]); + MakeSkyVec (skymins[0][i], skymaxs[1][i], i, verts[3]); + qglDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); } + qglPopMatrix (); } diff --git a/src/gl_tess.c b/src/gl_tess.c index 37bb7ad..2cb9e65 100644 --- a/src/gl_tess.c +++ b/src/gl_tess.c @@ -60,12 +60,12 @@ void GL_Flush2D( void ) { if( qglLockArraysEXT ) { qglLockArraysEXT( 0, tess.numverts ); } - - qglDrawArrays( GL_QUADS, 0, tess.numverts ); + + qglDrawElements( GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices ); if( gl_showtris->integer ) { GL_EnableOutlines(); - qglDrawArrays( GL_QUADS, 0, tess.numverts ); + qglDrawElements( GL_TRIANGLES, tess.numindices, GL_UNSIGNED_INT, tess.indices ); GL_DisableOutlines(); } @@ -77,6 +77,7 @@ void GL_Flush2D( void ) { c.batchesDrawn2D++; + tess.numindices = 0; tess.numverts = 0; tess.texnum[0] = 0; tess.flags = 0; @@ -172,8 +173,10 @@ void GL_DrawBeams( void ) { color_t color; vec_t *dst_vert; uint32_t *dst_color; + int *dst_indices; vec_t length; int numverts; + int numindices; entity_t *ent; int i; @@ -184,12 +187,13 @@ void GL_DrawBeams( void ) { GL_BindTexture( TEXNUM_BEAM ); GL_TexEnv( GL_MODULATE ); GL_Bits( GLS_BLEND_BLEND | GLS_DEPTHMASK_FALSE ); + qglEnableClientState( GL_COLOR_ARRAY ); qglColorPointer( 4, GL_UNSIGNED_BYTE, 0, tess.colors ); qglTexCoordPointer( 2, GL_FLOAT, 20, tess.vertices + 3 ); qglVertexPointer( 3, GL_FLOAT, 20, tess.vertices ); - numverts = 0; + numverts = numindices = 0; for( i = 0, ent = glr.fd.entities; i < glr.fd.num_entities; i++, ent++ ) { if( !( ent->flags & RF_BEAM ) ) { continue; @@ -200,8 +204,9 @@ void GL_DrawBeams( void ) { VectorSubtract( end, start, d1 ); VectorSubtract( glr.fd.vieworg, start, d2 ); CrossProduct( d1, d2, d3 ); - VectorNormalize( d3 ); - VectorScale( d3, ent->frame*1.2f, d3 ); + length = VectorLength( d3 ); + length = ent->frame * 1.2f / length; + VectorScale( d3, length, d3 ); length = VectorLength( d1 ); @@ -212,9 +217,12 @@ void GL_DrawBeams( void ) { } color[3] = 255 * ent->alpha; - if( numverts + 4 > TESS_MAX_VERTICES ) { - qglDrawArrays( GL_QUADS, 0, numverts ); - numverts = 0; + if( numverts + 4 > TESS_MAX_VERTICES || + numindices + 6 > TESS_MAX_INDICES ) + { + qglDrawElements( GL_TRIANGLES, numindices, + GL_UNSIGNED_INT, tess.indices ); + numverts = numindices = 0; } dst_vert = tess.vertices + numverts * 5; @@ -234,10 +242,20 @@ void GL_DrawBeams( void ) { dst_color[2] = *( uint32_t * )color; dst_color[3] = *( uint32_t * )color; + dst_indices = tess.indices + numindices; + dst_indices[0] = numverts + 0; + dst_indices[1] = numverts + 2; + dst_indices[2] = numverts + 3; + dst_indices[3] = numverts + 0; + dst_indices[4] = numverts + 1; + dst_indices[5] = numverts + 2; + numverts += 4; + numindices += 6; } - - qglDrawArrays( GL_QUADS, 0, numverts ); + + qglDrawElements( GL_TRIANGLES, numindices, + GL_UNSIGNED_INT, tess.indices ); qglDisableClientState( GL_COLOR_ARRAY ); } diff --git a/src/q_shared.h b/src/q_shared.h index 1abc52a..fa9a812 100644 --- a/src/q_shared.h +++ b/src/q_shared.h @@ -225,6 +225,10 @@ static inline float Q_fabs( float f ) { ((c)[0]=(a)[0]+(b)[0], \ (c)[1]=(a)[1]+(b)[1], \ (c)[2]=(a)[2]+(b)[2]) +#define VectorAdd3(a,b,c,d) \ + ((d)[0]=(a)[0]+(b)[0]+(c)[0], \ + (d)[1]=(a)[1]+(b)[1]+(c)[1], \ + (d)[2]=(a)[2]+(b)[2]+(c)[2]) #define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2]) #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0) #define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2]) |