diff --git a/ref/soft/r_beams.c b/ref/soft/r_beams.c index a28b6662..3a3f2748 100644 --- a/ref/soft/r_beams.c +++ b/ref/soft/r_beams.c @@ -118,41 +118,8 @@ Cull the beam by bbox */ qboolean GAME_EXPORT R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ) { - vec3_t mins, maxs; - int i; + // culling is undone in ref_soft return false; -/* - for( i = 0; i < 3; i++ ) - { - if( start[i] < end[i] ) - { - mins[i] = start[i]; - maxs[i] = end[i]; - } - else - { - mins[i] = end[i]; - maxs[i] = start[i]; - } - - // don't let it be zero sized - if( mins[i] == maxs[i] ) - maxs[i] += 1.0f; - } - - // check bbox - if( gEngfuncs.Mod_BoxVisible( mins, maxs, Mod_GetCurrentVis( ))) - { - if( pvsOnly || !R_CullBox( mins, maxs )) - { - // beam is visible - return false; - } - } - - // beam is culled - return true; - */ } /* diff --git a/ref/soft/r_bsp.c b/ref/soft/r_bsp.c index 074f7e19..ec7a5b70 100644 --- a/ref/soft/r_bsp.c +++ b/ref/soft/r_bsp.c @@ -27,25 +27,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. vec3_t r_entorigin; // the currently rendering entity in world // coordinates -float entity_rotation[3][3]; +static float entity_rotation[3][3]; int r_currentbkey; -typedef enum {touchessolid, drawnode, nodrawnode} solidstate_t; - #define MAX_BMODEL_VERTS 1000 // 12K #define MAX_BMODEL_EDGES 2000 // 24K static mvertex_t *pbverts; static bedge_t *pbedges; static int numbverts, numbedges; - static mvertex_t *pfrontenter, *pfrontexit; - static qboolean makeclippededge; - - /* ================ R_ConcatRotations diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index c81373bf..00723ae5 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -62,7 +62,45 @@ static void GAME_EXPORT CL_FillRGBA( int rendermode, float _x, float _y, float _ Draw_Fill( _x, _y, _w, _h ); } -void Mod_UnloadTextures( model_t *mod ); +static void Mod_BrushUnloadTextures( model_t *mod ) +{ + int i; + + gEngfuncs.Con_Printf( "Unloading world\n" ); + tr.map_unload = true; + + for( i = 0; i < mod->numtextures; i++ ) + { + texture_t *tx = mod->textures[i]; + if( !tx || tx->gl_texturenum == tr.defaultTexture ) + continue; // free slot + + GL_FreeTexture( tx->gl_texturenum ); // main texture + GL_FreeTexture( tx->fb_texturenum ); // luma texture + } +} + +static void Mod_UnloadTextures( model_t *mod ) +{ + Assert( mod != NULL ); + + switch( mod->type ) + { + case mod_studio: + // Mod_StudioUnloadTextures( mod->cache.data ); + break; + case mod_alias: + // Mod_AliasUnloadTextures( mod->cache.data ); + break; + case mod_brush: + Mod_BrushUnloadTextures( mod ); + break; + case mod_sprite: + Mod_SpriteUnloadTextures( mod->cache.data ); + break; + default: gEngfuncs.Host_Error( "%s: unsupported type %d\n", __func__, mod->type ); + } +} static qboolean GAME_EXPORT Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf, size_t buffersize ) { @@ -173,12 +211,10 @@ static int GL_RefGetParm( int parm, int arg ) static void GAME_EXPORT R_GetDetailScaleForTexture( int texture, float *xScale, float *yScale ) { - image_t *glt = R_GetTexture( texture ); + // details are not implemented in ref_soft - if( xScale ) - *xScale = glt->xscale; - if( yScale ) - *yScale = glt->yscale; + if( xScale ) *xScale = 0.0f; + if( yScale ) *yScale = 0.0f; } static void GAME_EXPORT R_GetExtraParmsForTexture( int texture, byte *red, byte *green, byte *blue, byte *density ) @@ -231,49 +267,6 @@ static const byte * GAME_EXPORT GL_TextureData( unsigned int texnum ) return NULL; } -static void Mod_BrushUnloadTextures( model_t *mod ) -{ - int i; - - - gEngfuncs.Con_Printf( "Unloading world\n" ); - tr.map_unload = true; - - for( i = 0; i < mod->numtextures; i++ ) - { - texture_t *tx = mod->textures[i]; - if( !tx || tx->gl_texturenum == tr.defaultTexture ) - continue; // free slot - - GL_FreeTexture( tx->gl_texturenum ); // main texture - GL_FreeTexture( tx->fb_texturenum ); // luma texture - } -} - -void Mod_UnloadTextures( model_t *mod ) -{ - int i, j; - - Assert( mod != NULL ); - - switch( mod->type ) - { - case mod_studio: - // Mod_StudioUnloadTextures( mod->cache.data ); - break; - case mod_alias: - // Mod_AliasUnloadTextures( mod->cache.data ); - break; - case mod_brush: - Mod_BrushUnloadTextures( mod ); - break; - case mod_sprite: - Mod_SpriteUnloadTextures( mod->cache.data ); - break; - default: gEngfuncs.Host_Error( "%s: unsupported type %d\n", __func__, mod->type ); - } -} - static void GAME_EXPORT R_ProcessEntData( qboolean allocate, cl_entity_t *entities, unsigned int max_entities ) { tr.entities = entities; diff --git a/ref/soft/r_decals.c b/ref/soft/r_decals.c index 8ae13327..302bc535 100644 --- a/ref/soft/r_decals.c +++ b/ref/soft/r_decals.c @@ -380,13 +380,11 @@ static float *R_DecalVertsClip( decal_t *pDecal, msurface_t *surf, int texture, static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) { float s, t; - mtexinfo_t *tex; mextrasurf_t *info = surf->info; float sample_size; int j; sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - tex = surf->texinfo; for( j = 0; j < vertCount; j++, v += VERTEXSIZE ) { diff --git a/ref/soft/r_draw.c b/ref/soft/r_draw.c index c01d4697..2ea1e040 100644 --- a/ref/soft/r_draw.c +++ b/ref/soft/r_draw.c @@ -257,17 +257,6 @@ R_DrawStretchRaw */ void GAME_EXPORT R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty ) { - byte *raw = NULL; - image_t *tex; - - raw = (byte *)data; - - // pglDisable( GL_BLEND ); - // pglDisable( GL_ALPHA_TEST ); - // pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); - - tex = R_GetTexture( tr.cinTexture ); - GL_Bind( XASH_TEXTURE0, tr.cinTexture ); } /* @@ -277,14 +266,6 @@ R_UploadStretchRaw */ void GAME_EXPORT R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, const byte *data ) { - byte *raw = NULL; - image_t *tex; - raw = (byte *)data; - - tex = R_GetTexture( texture ); - GL_Bind( GL_KEEP_UNIT, texture ); - tex->width = cols; - tex->height = rows; } /* diff --git a/ref/soft/r_edge.c b/ref/soft/r_edge.c index a523ed66..c7912f41 100644 --- a/ref/soft/r_edge.c +++ b/ref/soft/r_edge.c @@ -39,15 +39,11 @@ int r_currentkey; int current_iv; -int edge_head_u_shift20, edge_tail_u_shift20; +static int edge_head_u_shift20, edge_tail_u_shift20; -static void (*pdrawfunc)( void ); +static void (*pdrawfunc)( void ); -edge_t edge_head; -edge_t edge_tail; - -edge_t edge_aftertail; -edge_t edge_sentinel; +static edge_t edge_head, edge_tail, edge_aftertail, edge_sentinel; static float fv; @@ -766,17 +762,13 @@ D_CalcGradients */ static void D_CalcGradients( msurface_t *pface ) { - mplane_t *pplane; float mipscale; vec3_t p_temp1; vec3_t p_saxis, p_taxis; float t; - pplane = pface->plane; - mipscale = 1.0f / (float)( 1 << miplevel ); - if( pface->texinfo->flags & TEX_WORLD_LUXELS ) { TransformVector( pface->texinfo->vecs[0], p_saxis ); diff --git a/ref/soft/r_glblit.c b/ref/soft/r_glblit.c index 6a83c349..5128f954 100644 --- a/ref/soft/r_glblit.c +++ b/ref/soft/r_glblit.c @@ -50,6 +50,7 @@ DebugCallback For ARB_debug_output ======================== */ +#if GLDEBUG static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLuint severity, GLint length, const GLcharARB *message, GLvoid *userParam ) { switch( type ) @@ -71,10 +72,9 @@ static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLui break; } } - +#endif // GLDEBUG static unsigned short *glbuf; -static int tex; #define LOAD( x ) p ## x = gEngfuncs.GL_GetProcAddress(#x ); \ gEngfuncs.Con_Printf(#x " : %p\n", p ## x ) @@ -192,28 +192,6 @@ static void *R_Lock_GL1( void ) return glbuf; } -static void R_Unlock_GL1( void ) -{ - - pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glbuf ); - // gEngfuncs.Con_Printf("%d\n",pglGetError()); - pglBegin( GL_QUADS ); - pglTexCoord2f( 0, 0 ); - pglVertex2f( 0, 0 ); - - pglTexCoord2f( 1, 0 ); - pglVertex2f( 1, 0 ); - - pglTexCoord2f( 1, 1 ); - pglVertex2f( 1, 1 ); - - pglTexCoord2f( 0, 1 ); - pglVertex2f( 0, 1 ); - pglEnd(); - gEngfuncs.GL_SwapBuffers(); -} - - static void R_Unlock_GLES1( void ) { pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vid.width, vid.height, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, glbuf ); @@ -222,33 +200,6 @@ static void R_Unlock_GLES1( void ) gEngfuncs.GL_SwapBuffers(); } -static qboolean R_CreateBuffer_GL1( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ) -{ - pglViewport( 0, 0, width, height ); - pglMatrixMode( GL_PROJECTION ); - pglLoadIdentity(); - pglOrtho( 0, 1, 1, 0, -99999, 99999 ); - pglMatrixMode( GL_MODELVIEW ); - pglLoadIdentity(); - - pglEnable( GL_TEXTURE_2D ); - pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); - pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - - if( glbuf ) - Mem_Free( glbuf ); - - glbuf = Mem_Malloc( r_temppool, width * height * 2 ); - - *stride = width; - *bpp = 2; - *r = MASK( 5 ) << ( 6 + 5 ); - *g = MASK( 6 ) << 5; - *b = MASK( 5 ); - - return true; -} - static qboolean R_CreateBuffer_GLES1( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ) { float data[] = { @@ -346,49 +297,14 @@ static void R_Unlock_GLES3( void ) static qboolean R_CreateBuffer_GLES3( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ) { - float data[] = { - // quad verts match texcoords - 0, 0, - 1, 0, - 1, 1, - 0, 1, - }; - GLuint vbo, pbo, fbo, to; + GLuint pbo, fbo, to; // shitty fbo does not work without texture objects :( pglGenTextures( 1, &to ); pglBindTexture( GL_TEXTURE_2D, to ); pglViewport( 0, 0, width, height ); - /* - pglMatrixMode( GL_PROJECTION ); - pglLoadIdentity(); - // project 0..1 to screen size - pglOrtho( 0, 1, 1, 0, -99999, 99999 ); - pglMatrixMode( GL_MODELVIEW ); - pglLoadIdentity(); - pglEnable( GL_TEXTURE_2D ); - pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); - pglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); - - if( vbo ) - pglDeleteBuffers( 1,&vbo ); - - if( pbo ) - pglDeleteBuffers( 1,&pbo ); - */ - - // pglGenBuffers( 1,&vbo ); pglGenBuffers( 1, &pbo ); - // pglBindBuffer( GL_ARRAY_BUFFER_ARB, vbo ); - // pglBufferData( GL_ARRAY_BUFFER_ARB, sizeof(data), data, GL_STATIC_DRAW_ARB ); - - // pglEnableClientState( GL_VERTEX_ARRAY ); - // pglEnableClientState( GL_TEXTURE_COORD_ARRAY ); - - // pglVertexPointer( 2, GL_FLOAT, 8, 0 ); - // pglTexCoordPointer( 2, GL_FLOAT, 8, 0 ); - // pglBindBuffer( GL_ARRAY_BUFFER_ARB, 0 ); pglBindBuffer( GL_PIXEL_UNPACK_BUFFER, pbo ); pglBufferData( GL_PIXEL_UNPACK_BUFFER, width * height * 2, 0, GL_STREAM_DRAW_ARB ); @@ -399,9 +315,6 @@ static qboolean R_CreateBuffer_GLES3( int width, int height, uint *stride, uint pglFramebufferTexture2D( GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, to, 0 ); pglBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); - // pglColor4f( 1, 1, 1, 1 ); - - *stride = width; *bpp = 2; *r = MASK( 5 ) << ( 6 + 5 ); @@ -411,8 +324,6 @@ static qboolean R_CreateBuffer_GLES3( int width, int height, uint *stride, uint return true; } - - static int FIRST_BIT( uint mask ) { uint i; @@ -502,14 +413,13 @@ static void R_BuildBlendMaps( void ) { unsigned int r1, g1, b1; unsigned int r2, g2, b2; - unsigned int i, j; + unsigned int i; FOR_EACH_COLOR( 1 ) FOR_EACH_COLOR( 2 ) { unsigned int r, g, b; unsigned short index1 = r1 << ( 2 + 3 ) | g1 << 2 | b1; unsigned short index2 = ( r2 << ( 2 + 3 ) | g2 << 2 | b2 ) << 8; - unsigned int a; r = r1 + r2; g = g1 + g2; diff --git a/ref/soft/r_image.c b/ref/soft/r_image.c index be9d1ae2..c08b74ff 100644 --- a/ref/soft/r_image.c +++ b/ref/soft/r_image.c @@ -42,10 +42,7 @@ GL_Bind */ void GAME_EXPORT GL_Bind( int tmu, unsigned int texnum ) { - image_t *image; - - image = &r_images[texnum]; - // vid.rendermode = kRenderNormal; + image_t *image = &r_images[texnum]; if( vid.rendermode == kRenderNormal ) { @@ -77,48 +74,6 @@ void GAME_EXPORT GL_Bind( int tmu, unsigned int texnum ) r_affinetridesc.skinheight = image->height; } -/* -================= -GL_ApplyTextureParams -================= -*/ -void GL_ApplyTextureParams( image_t *tex ) -{ - - Assert( tex != NULL ); -} - -/* -================= -GL_UpdateTextureParams -================= -*/ -static void GL_UpdateTextureParams( int iTexture ) -{ - image_t *tex = &r_images[iTexture]; - - Assert( tex != NULL ); - - if( !tex->pixels ) - return; // free slot - - GL_Bind( XASH_TEXTURE0, iTexture ); -} - -/* -================= -R_SetTextureParameters -================= -*/ -void R_SetTextureParameters( void ) -{ - int i; - - // change all the existing mipmapped texture objects - for( i = 0; i < r_numImages; i++ ) - GL_UpdateTextureParams( i ); -} - /* ================== GL_CalcTextureSize @@ -129,32 +84,6 @@ static size_t GL_CalcTextureSize( int width, int height, int depth ) return width * height * 2; } -static int GL_CalcMipmapCount( image_t *tex, qboolean haveBuffer ) -{ - int width, height; - int mipcount; - - Assert( tex != NULL ); - - if( !haveBuffer ) - return 1; - - // generate mip-levels by user request - if( FBitSet( tex->flags, TF_NOMIPMAP )) - return 1; - - // mip-maps can't exceeds 4 - for( mipcount = 0; mipcount < 4; mipcount++ ) - { - width = Q_max( 1, ( tex->width >> mipcount )); - height = Q_max( 1, ( tex->height >> mipcount )); - if( width == 1 && height == 1 ) - break; - } - - return mipcount + 1; -} - /* ================ GL_SetTextureDimensions @@ -186,38 +115,6 @@ static void GL_SetTextureDimensions( image_t *tex, int width, int height, int de tex->depth = Q_max( 1, depth ); } -/* -=============== -GL_SetTextureTarget -=============== -*/ -static void GL_SetTextureTarget( image_t *tex, rgbdata_t *pic ) -{ - Assert( pic != NULL ); - Assert( tex != NULL ); - - // correct depth size - pic->depth = Q_max( 1, pic->depth ); - tex->numMips = 0; // begin counting - - // correct mip count - pic->numMips = Q_max( 1, pic->numMips ); -} - -/* -=============== -GL_SetTextureFormat -=============== -*/ -static void GL_SetTextureFormat( image_t *tex, pixformat_t format, int channelMask ) -{ - qboolean haveColor = ( channelMask & IMAGE_HAS_COLOR ); - qboolean haveAlpha = ( channelMask & IMAGE_HAS_ALPHA ); - - Assert( tex != NULL ); - // tex->transparent = !!( channelMask & IMAGE_HAS_ALPHA ); -} - /* ================= GL_ResampleTexture @@ -310,78 +207,6 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out return scaledImage; } -/* -================= -GL_BoxFilter3x3 - -box filter 3x3 -================= -*/ -static void GL_BoxFilter3x3( byte *out, const byte *in, int w, int h, int x, int y ) -{ - int r = 0, g = 0, b = 0, a = 0; - int count = 0, acount = 0; - int i, j, u, v; - const byte *pixel; - - for( i = 0; i < 3; i++ ) - { - u = ( i - 1 ) + x; - - for( j = 0; j < 3; j++ ) - { - v = ( j - 1 ) + y; - - if( u >= 0 && u < w && v >= 0 && v < h ) - { - pixel = &in[( u + v * w ) * 4]; - - if( pixel[3] != 0 ) - { - r += pixel[0]; - g += pixel[1]; - b += pixel[2]; - a += pixel[3]; - acount++; - } - } - } - } - - if( acount == 0 ) - acount = 1; - - out[0] = r / acount; - out[1] = g / acount; - out[2] = b / acount; -// out[3] = (int)( SimpleSpline( ( a / 12.0f ) / 255.0f ) * 255 ); -} - -/* -================= -GL_ApplyFilter - -Apply box-filter to 1-bit alpha -================= -*/ -static byte *GL_ApplyFilter( const byte *source, int width, int height ) -{ - byte *in = (byte *)source; - byte *out = (byte *)source; - int i; - - if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE )) - return in; - - for( i = 0; source && i < width * height; i++, in += 4 ) - { - if( in[0] == 0 && in[1] == 0 && in[2] == 0 && in[3] == 0 ) - GL_BoxFilter3x3( in, source, width, height, i % width, i / width ); - } - - return out; -} - /* ================= GL_BuildMipMap @@ -484,12 +309,10 @@ upload texture into video memory static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) { byte *buf, *data; - size_t texsize, size; + size_t texsize; uint width, height; - uint i, j, numSides; - uint offset = 0; + uint i, j; qboolean normalMap = false; - const byte *bufend; int mipCount; tex->fogParams[0] = pic->fogParams[0]; @@ -497,7 +320,6 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) tex->fogParams[2] = pic->fogParams[2]; tex->fogParams[3] = pic->fogParams[3]; GL_SetTextureDimensions( tex, pic->width, pic->height, pic->depth ); - GL_SetTextureFormat( tex, pic->type, pic->flags ); // gEngfuncs.Con_Printf("%s %d %d\n", tex->name, tex->width, tex->height ); @@ -509,7 +331,7 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) buf = pic->buffer; - mipCount = 4; // GL_CalcMipmapCount( tex, ( buf != NULL )); + mipCount = 4; // NOTE: only single uncompressed textures can be resamples, no mips, no layers, no sides if((( pic->width != tex->width ) || ( pic->height != tex->height ))) @@ -517,27 +339,17 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) else data = buf; - // if( !ImageCompressed( pic->type ) && !FBitSet( tex->flags, TF_NOMIPMAP ) && FBitSet( pic->flags, IMAGE_ONEBIT_ALPHA )) - // data = GL_ApplyFilter( data, tex->width, tex->height ); - // mips will be auto-generated if desired for( j = 0; j < mipCount; j++ ) { - int x, y; width = Q_max( 1, ( tex->width >> j )); height = Q_max( 1, ( tex->height >> j )); texsize = GL_CalcTextureSize( width, height, tex->depth ); - size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, tex->depth ); - // GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data ); + // increase size to workaround triangle renderer bugs // it seems to assume memory readable. maybe it was pointed to WAD? - // tex->pixels[j] = (byte*)Mem_Calloc( r_temppool, width * height * sizeof(pixel_t) + 1024 ) + 512; tex->pixels[j] = (pixel_t *)Mem_Calloc( r_temppool, width * height * sizeof( pixel_t )); - - // memset( (byte*)tex->pixels[j] - 512, 0xFF, 512 ); - // memset( (byte*)tex->pixels[j] + width * height * sizeof(pixel_t), 0xFF, 512 ); - if( j == 0 && tex->flags & TF_HAS_ALPHA ) tex->alpha_pixels = (pixel_t *)Mem_Calloc( r_temppool, width * height * sizeof( pixel_t )); @@ -571,8 +383,6 @@ static qboolean GL_UploadTexture( image_t *tex, rgbdata_t *pic ) tex->size += texsize; tex->numMips++; - - // GL_CheckTexImageError( tex ); } return true; @@ -844,7 +654,6 @@ int GAME_EXPORT GL_LoadTexture( const char *name, const byte *buf, size_t size, return 0; } - GL_ApplyTextureParams( tex ); // update texture filter, wrap etc gEngfuncs.FS_FreeImage( pic ); // release source texture // NOTE: always return texnum as index in array or engine will stop work !!! @@ -900,7 +709,6 @@ int GAME_EXPORT GL_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texF return 0; } - GL_ApplyTextureParams( tex ); // update texture filter, wrap etc return( tex - r_images ); } @@ -1043,7 +851,6 @@ void GAME_EXPORT GL_ProcessTexture( int texnum, float gamma, int topColor, int b gEngfuncs.Image_Process( &pic, topColor, bottomColor, flags, 0.0f ); GL_UploadTexture( image, pic ); - GL_ApplyTextureParams( image ); // update texture filter, wrap etc gEngfuncs.FS_FreeImage( pic ); } @@ -1256,7 +1063,6 @@ void R_InitImages( void ) r_numImages = 1; // validate cvars - R_SetTextureParameters(); GL_CreateInternalTextures(); gEngfuncs.Cmd_AddCommand( "texturelist", R_TextureList_f, "display loaded textures list" ); diff --git a/ref/soft/r_light.c b/ref/soft/r_light.c index b9eeadaf..1b4b936e 100644 --- a/ref/soft/r_light.c +++ b/ref/soft/r_light.c @@ -176,9 +176,6 @@ void R_PushDlights( void ) if( l->die < gp_cl->time || !l->radius ) continue; - // if( GL_FrustumCullSphere( &RI.frustum, l->origin, l->radius, 15 )) - // continue; - R_MarkLights( l, 1 << i, RI.currentmodel->nodes ); } } @@ -208,7 +205,6 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, color24 *lm, *dm; mextrasurf_t *info; msurface_t *surf; - mtexinfo_t *tex; matrix3x4 tbn; vec3_t mid; mnode_t *children[2]; @@ -256,7 +252,6 @@ static qboolean R_RecursiveLightPoint( model_t *model, mnode_t *node, float p1f, { int smax, tmax; - tex = surf->texinfo; info = surf->info; if( FBitSet( surf->flags, SURF_DRAWTILED )) diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 09285a85..117e0c2c 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -95,26 +95,6 @@ extern poolhandle_t r_temppool; #define MOVE_BIT( s, f, t ) ( GET_BIT( s, f ) << t ) -/* - skins will be outline flood filled and mip mapped - pics and sprites with alpha will be outline flood filled - pic won't be mip mapped - model skin - sprite frame - wall texture - pic -*/ - -typedef enum -{ - it_skin, - it_sprite, - it_wall, - it_pic, - it_sky -} imagetype_t; - - // =================================================================== typedef unsigned short pixel_t; @@ -355,11 +335,6 @@ typedef struct image_s // debug info size_t size; // upload size for debug targets - // detail textures stuff - float xscale; - float yscale; - - imagetype_t type; pixel_t *pixels[4]; // mip levels pixel_t *alpha_pixels; // mip levels @@ -394,7 +369,6 @@ void R_UploadStretchRaw( int texture, int cols, int rows, int width, int height, // gl_image.c // -void R_SetTextureParameters( void ); image_t *R_GetTexture( unsigned int texnum ); #define GL_LoadTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, false ) #define GL_UpdateTextureInternal( name, pic, flags ) GL_LoadTextureFromBuffer( name, pic, flags, true ) @@ -406,7 +380,6 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe int GL_CreateTextureArray( const char *name, int width, int height, int depth, const void *buffer, texFlags_t flags ); void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor ); void GL_UpdateTexSize( int texnum, int width, int height, int depth ); -void GL_ApplyTextureParams( image_t *tex ); int GL_FindTexture( const char *name ); void GL_FreeTexture( unsigned int texnum ); const char *GL_Target( unsigned int target ); @@ -1008,7 +981,6 @@ extern int r_screenwidth; extern int sintable[1280]; -extern int intsintable[1280]; extern int blanktable[1280]; // PGM extern surf_t *surfaces, *surface_p, *surf_max; diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index 7c133a80..c93f3475 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -362,16 +362,6 @@ qboolean GAME_EXPORT R_AddEntity( struct cl_entity_s *clent, int type ) return true; } -/* -============= -R_Clear -============= -*/ -static void R_Clear( int bitMask ) -{ - memset( vid.buffer, 0, vid.width * vid.height * 2 ); -} - // ============================================================================= /* =============== @@ -512,81 +502,6 @@ static void R_SetupFrame( void ) R_SetupFrameQ(); } -/* -============= -R_RecursiveFindWaterTexture - -using to find source waterleaf with -watertexture to grab fog values from it -============= -*/ -static image_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mnode_t *ignore, qboolean down ) -{ - image_t *tex = NULL; - mnode_t *children[2]; - - // assure the initial node is not null - // we could check it here, but we would rather check it - // outside the call to get rid of one additional recursion level - Assert( node != NULL ); - - // ignore solid nodes - if( node->contents == CONTENTS_SOLID ) - return NULL; - - if( node->contents < 0 ) - { - mleaf_t *pleaf; - msurface_t **mark; - int i, c; - - // ignore non-liquid leaves - if( node->contents != CONTENTS_WATER && node->contents != CONTENTS_LAVA && node->contents != CONTENTS_SLIME ) - return NULL; - - // find texture - pleaf = (mleaf_t *)node; - mark = pleaf->firstmarksurface; - c = pleaf->nummarksurfaces; - - for( i = 0; i < c; i++, mark++ ) - { - if(( *mark )->flags & SURF_DRAWTURB && ( *mark )->texinfo && ( *mark )->texinfo->texture ) - return R_GetTexture(( *mark )->texinfo->texture->gl_texturenum ); - } - - // texture not found - return NULL; - } - - // this is a regular node - // traverse children - node_children( children, node, WORLDMODEL ); - - if( children[0] && ( children[0] != ignore )) - { - tex = R_RecursiveFindWaterTexture( children[0], node, true ); - if( tex ) return tex; - } - - if( children[1] && ( children[1] != ignore )) - { - tex = R_RecursiveFindWaterTexture( children[1], node, true ); - if( tex ) return tex; - } - - // for down recursion, return immediately - if( down ) - return NULL; - - // texture not found, step up if any - if( node->parent ) - return R_RecursiveFindWaterTexture( node->parent, node, false ); - - // top-level node, bail out - return NULL; -} - /* ============= R_DrawEntitiesOnList @@ -968,7 +883,7 @@ R_DrawBEntitiesOnList */ void R_DrawBrushModel( cl_entity_t *pent ) { - int i, clipflags; + int clipflags; vec3_t oldorigin; vec3_t mins, maxs; float minmaxs[6]; @@ -1250,10 +1165,6 @@ void GAME_EXPORT R_BeginFrame( qboolean clearScene ) // draw buffer stuff // pglDrawBuffer( GL_BACK ); - // update texture parameters - // if( FBitSet( gl_texture_nearest->flags|gl_lightmap_nearest->flags|gl_texture_anisotropy->flags|gl_texture_lodbias->flags, FCVAR_CHANGED )) - // R_SetTextureParameters(); - gEngfuncs.CL_ExtraUpdate(); } @@ -1476,7 +1387,6 @@ static void R_InitTurb( void ) for( i = 0; i < 1280; i++ ) { sintable[i] = AMP + sin( i * 3.14159 * 2 / CYCLE ) * AMP; - intsintable[i] = AMP2 + sin( i * 3.14159 * 2 / CYCLE ) * AMP2; // AMP2, not 20 blanktable[i] = 0; // PGM } } diff --git a/ref/soft/r_math.c b/ref/soft/r_math.c index bf377d4f..a73bf088 100644 --- a/ref/soft/r_math.c +++ b/ref/soft/r_math.c @@ -151,46 +151,6 @@ void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float out[3][3] = 1.0f; } -static void Matrix4x4_CreateScale( matrix4x4 out, float x ) -{ - out[0][0] = x; - out[0][1] = 0.0f; - out[0][2] = 0.0f; - out[0][3] = 0.0f; - out[1][0] = 0.0f; - out[1][1] = x; - out[1][2] = 0.0f; - out[1][3] = 0.0f; - out[2][0] = 0.0f; - out[2][1] = 0.0f; - out[2][2] = x; - out[2][3] = 0.0f; - out[3][0] = 0.0f; - out[3][1] = 0.0f; - out[3][2] = 0.0f; - out[3][3] = 1.0f; -} - -static void Matrix4x4_CreateScale3( matrix4x4 out, float x, float y, float z ) -{ - out[0][0] = x; - out[0][1] = 0.0f; - out[0][2] = 0.0f; - out[0][3] = 0.0f; - out[1][0] = 0.0f; - out[1][1] = y; - out[1][2] = 0.0f; - out[1][3] = 0.0f; - out[2][0] = 0.0f; - out[2][1] = 0.0f; - out[2][2] = z; - out[2][3] = 0.0f; - out[3][0] = 0.0f; - out[3][1] = 0.0f; - out[3][2] = 0.0f; - out[3][3] = 1.0f; -} - void Matrix4x4_ConcatTranslate( matrix4x4 out, float x, float y, float z ) { matrix4x4 base, temp; diff --git a/ref/soft/r_part.c b/ref/soft/r_part.c index c414fe64..fe4bfad2 100644 --- a/ref/soft/r_part.c +++ b/ref/soft/r_part.c @@ -127,33 +127,8 @@ check tracer bbox */ static qboolean CL_CullTracer( particle_t *p, const vec3_t start, const vec3_t end ) { - vec3_t mins, maxs; - int i; + // culling is undone in ref_soft return false; -/* - // compute the bounding box - for( i = 0; i < 3; i++ ) - { - if( start[i] < end[i] ) - { - mins[i] = start[i]; - maxs[i] = end[i]; - } - else - { - mins[i] = end[i]; - maxs[i] = start[i]; - } - - // don't let it be zero sized - if( mins[i] == maxs[i] ) - { - maxs[i] += gTracerSize[p->type] * 2.0f; - } - } - - // check bbox - return R_CullBox( mins, maxs );*/ } /* @@ -297,7 +272,6 @@ void GAME_EXPORT CL_DrawParticlesExternal( const ref_viewpass_t *rvp, qboolean t R_SetupRefParams( rvp ); R_SetupFrustum(); -// R_SetupGL( false ); // don't touch GL-states // setup PVS for frame memcpy( RI.visbytes, tr.visbytes, gpGlobals->visbytes ); diff --git a/ref/soft/r_polyse.c b/ref/soft/r_polyse.c index 4cc19083..886a39b1 100644 --- a/ref/soft/r_polyse.c +++ b/ref/soft/r_polyse.c @@ -42,13 +42,10 @@ typedef struct aliastriangleparms_t aliastriangleparms; -int r_p0[6], r_p1[6], r_p2[6]; - -int d_xdenom; - -edgetable *pedgetable; - -edgetable edgetables[12] = { +static int r_p0[6], r_p1[6], r_p2[6]; +static int d_xdenom; +static edgetable *pedgetable; +static edgetable edgetables[12] = { {0, 1, r_p0, r_p2, NULL, 2, r_p0, r_p1, r_p2 }, {0, 2, r_p1, r_p0, r_p2, 1, r_p1, r_p2, NULL}, {1, 1, r_p0, r_p2, NULL, 1, r_p1, r_p2, NULL}, @@ -63,24 +60,23 @@ edgetable edgetables[12] = { {0, 1, r_p0, r_p2, NULL, 1, r_p0, r_p1, NULL}, }; -// FIXME: some of these can become statics -int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole; -int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy; -int r_zistepx, r_zistepy; -int d_aspancount, d_countextrastep; +static int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole; +static int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy; +static int r_zistepx, r_zistepy; +static int d_aspancount, d_countextrastep; -spanpackage_t *a_spans; -spanpackage_t *d_pedgespanpackage; -static int ystart; -pixel_t *d_pdest, *d_ptex; -short *d_pz; -int d_sfrac, d_tfrac, d_light, d_zi; -int d_ptexextrastep, d_sfracextrastep; -int d_tfracextrastep, d_lightextrastep, d_pdestextrastep; -int d_lightbasestep, d_pdestbasestep, d_ptexbasestep; -int d_sfracbasestep, d_tfracbasestep; -int d_ziextrastep, d_zibasestep; -int d_pzextrastep, d_pzbasestep; +static spanpackage_t *a_spans; +static spanpackage_t *d_pedgespanpackage; +static int ystart; +static pixel_t *d_pdest, *d_ptex; +static short *d_pz; +static int d_sfrac, d_tfrac, d_light, d_zi; +static int d_ptexextrastep, d_sfracextrastep; +static int d_tfracextrastep, d_lightextrastep, d_pdestextrastep; +static int d_lightbasestep, d_pdestbasestep, d_ptexbasestep; +static int d_sfracbasestep, d_tfracbasestep; +static int d_ziextrastep, d_zibasestep; +static int d_pzextrastep, d_pzbasestep; static int ubasestep, errorterm, erroradjustup, erroradjustdown; @@ -90,13 +86,11 @@ typedef struct int remainder; } adivtab_t; -static adivtab_t adivtab[32 * 32] = { +static const adivtab_t adivtab[32 * 32] = { #include "adivtab.h" }; -byte *skintable[MAX_LBM_HEIGHT]; -int skinwidth; -byte *skinstart; +static pixel_t *skinend; void (*d_pdrawspans)( spanpackage_t *pspanpackage ); @@ -105,118 +99,73 @@ static void R_PolysetStub( spanpackage_t *pspanpackage ) } -void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage ); -void R_PolysetDrawSpans8_66( spanpackage_t *pspanpackage ); -void R_PolysetDrawSpans8_Opaque( spanpackage_t *pspanpackage ); - -qboolean R_PolysetCalcGradients( int skinwidth ); -void R_DrawNonSubdiv( void ); -void R_PolysetSetEdgeTable( void ); -void R_RasterizeAliasPolySmooth( void ); -void R_PolysetScanLeftEdge( int height ); -qboolean R_PolysetScanLeftEdge_C( int height ); - /* ================ -R_DrawTriangle +R_PolysetSetEdgeTable ================ */ -void R_DrawTriangle( void ) +static void R_PolysetSetEdgeTable( void ) { - spanpackage_t spans[DPS_MAXSPANS]; + int edgetableindex; - int dv1_ab, dv0_ac; - int dv0_ab, dv1_ac; + edgetableindex = 0; // assume the vertices are already in + // top to bottom order - /* - d_xdenom = ( aliastriangleparms.a->v[1] - aliastriangleparms.b->v[1] ) * ( aliastriangleparms.a->v[0] - aliastriangleparms.c->v[0] ) - - ( aliastriangleparms.a->v[0] - aliastriangleparms.b->v[0] ) * ( aliastriangleparms.a->v[1] - aliastriangleparms.c->v[1] ); - */ - - dv0_ab = aliastriangleparms.a->u - aliastriangleparms.b->u; - dv1_ab = aliastriangleparms.a->v - aliastriangleparms.b->v; - - if( !( dv0_ab | dv1_ab )) - return; - - dv0_ac = aliastriangleparms.a->u - aliastriangleparms.c->u; - dv1_ac = aliastriangleparms.a->v - aliastriangleparms.c->v; - - if( !( dv0_ac | dv1_ac )) - return; - - d_xdenom = ( dv0_ac * dv1_ab ) - ( dv0_ab * dv1_ac ); - - if( d_xdenom < 0 ) +// +// determine which edges are right & left, and the order in which +// to rasterize them +// + if( r_p0[1] >= r_p1[1] ) { - a_spans = spans; + if( r_p0[1] == r_p1[1] ) + { + if( r_p0[1] < r_p2[1] ) + pedgetable = &edgetables[2]; + else + pedgetable = &edgetables[5]; - r_p0[0] = aliastriangleparms.a->u; // u - r_p0[1] = aliastriangleparms.a->v; // v - r_p0[2] = aliastriangleparms.a->s; // s - r_p0[3] = aliastriangleparms.a->t; // t - r_p0[4] = aliastriangleparms.a->l; // light - r_p0[5] = aliastriangleparms.a->zi; // iz - - r_p1[0] = aliastriangleparms.b->u; - r_p1[1] = aliastriangleparms.b->v; - r_p1[2] = aliastriangleparms.b->s; - r_p1[3] = aliastriangleparms.b->t; - r_p1[4] = aliastriangleparms.b->l; - r_p1[5] = aliastriangleparms.b->zi; - - r_p2[0] = aliastriangleparms.c->u; - r_p2[1] = aliastriangleparms.c->v; - r_p2[2] = aliastriangleparms.c->s; - r_p2[3] = aliastriangleparms.c->t; - r_p2[4] = aliastriangleparms.c->l; - r_p2[5] = aliastriangleparms.c->zi; - - R_PolysetSetEdgeTable(); - R_RasterizeAliasPolySmooth(); + return; + } + else + { + edgetableindex = 1; + } } + + if( r_p0[1] == r_p2[1] ) + { + if( edgetableindex ) + pedgetable = &edgetables[8]; + else + pedgetable = &edgetables[9]; + + return; + } + else if( r_p1[1] == r_p2[1] ) + { + if( edgetableindex ) + pedgetable = &edgetables[10]; + else + pedgetable = &edgetables[11]; + + return; + } + + if( r_p0[1] > r_p2[1] ) + edgetableindex += 2; + + if( r_p1[1] > r_p2[1] ) + edgetableindex += 4; + + pedgetable = &edgetables[edgetableindex]; } - -static pixel_t *skinend; - -static inline qboolean R_DrawCheckBounds( pixel_t *lptex ) -{ - pixel_t *skin = r_affinetridesc.pskin; - if( lptex - skin < 0 || lptex - skinend >= 0 ) - return false; - return true; -} - -static inline qboolean R_PolysetCheckBounds( pixel_t *lptex, int lsfrac, int ltfrac, int lcount ) -{ - pixel_t *start, *end; - start = r_affinetridesc.pskin; - end = skinend; - - // span is linear, so only need to check first and last - if( lptex - start < 0 || lptex - end >= 0 ) - return false; - - if( !( --lcount )) - return true; - - lptex = lptex + a_ststepxwhole * lcount + (( lsfrac + ( a_sstepxfrac * lcount )) >> 16 ) + (( ltfrac + ( a_tstepxfrac * lcount )) >> 16 ) * r_affinetridesc.skinwidth; - - if( lptex - start < 0 || lptex - end >= 0 ) - return false; - - - return true; -} - - /* =================== R_PolysetScanLeftEdge_C ==================== */ -qboolean R_PolysetScanLeftEdge_C( int height ) +static qboolean R_PolysetScanLeftEdge_C( int height ) { do { @@ -289,15 +238,13 @@ quotient must fit in 32 bits. FIXME: GET RID OF THIS! (FloorDivMod) ==================== */ -static void FloorDivMod( float numer, float denom, int *quotient, - int *rem ) +static void FloorDivMod( float numer, float denom, int *quotient, int *rem ) { int q, r; float x; if( numer >= 0.0f ) { - x = floor( numer / denom ); q = (int)x; r = (int)floor( numer - ( x * denom )); @@ -316,9 +263,9 @@ static void FloorDivMod( float numer, float denom, int *quotient, r = (int)denom - r; } } + if( q > INT_MAX / 2 || q < INT_MIN / 2 ) { - int i; d_pdrawspans = R_PolysetStub; gEngfuncs.Con_Printf( S_ERROR "%s: q overflow!\n", __func__ ); q = 1; @@ -326,7 +273,6 @@ static void FloorDivMod( float numer, float denom, int *quotient, if( r > INT_MAX / 2 || r < INT_MIN / 2 ) { - int i; d_pdrawspans = R_PolysetStub; gEngfuncs.Con_Printf( S_ERROR "%s: r overflow!\n", __func__ ); r = 1; @@ -336,18 +282,16 @@ static void FloorDivMod( float numer, float denom, int *quotient, *rem = r; } - /* =================== R_PolysetSetUpForLineScan ==================== */ -static void R_PolysetSetUpForLineScan( fixed8_t startvertu, fixed8_t startvertv, - fixed8_t endvertu, fixed8_t endvertv ) +static void R_PolysetSetUpForLineScan( fixed8_t startvertu, fixed8_t startvertv, fixed8_t endvertu, fixed8_t endvertv ) { float dm, dn; int tm, tn; - adivtab_t *ptemp; + ; // TODO: implement x86 version @@ -359,7 +303,7 @@ static void R_PolysetSetUpForLineScan( fixed8_t startvertu, fixed8_t startvertv, if((( tm <= 16 ) && ( tm >= -15 )) && (( tn <= 16 ) && ( tn >= -15 ))) { - ptemp = &adivtab[(( tm + 15 ) << 5 ) + ( tn + 15 )]; + const adivtab_t *ptemp = &adivtab[(( tm + 15 ) << 5 ) + ( tn + 15 )]; ubasestep = ptemp->quotient; erroradjustup = ptemp->remainder; erroradjustdown = tn; @@ -375,14 +319,12 @@ static void R_PolysetSetUpForLineScan( fixed8_t startvertu, fixed8_t startvertv, } } - - /* ================ R_PolysetCalcGradients ================ */ -qboolean R_PolysetCalcGradients( int skinwidth ) +static qboolean R_PolysetCalcGradients( int skinwidth ) { float xstepdenominv, ystepdenominv, t0, t1; float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20; @@ -443,6 +385,343 @@ qboolean R_PolysetCalcGradients( int skinwidth ) return true; } +/* +================ +R_RasterizeAliasPolySmooth +================ +*/ +static void R_RasterizeAliasPolySmooth( void ) +{ + int initialleftheight, initialrightheight; + int *plefttop, *prighttop, *pleftbottom, *prightbottom; + int working_lstepx, originalcount; + + plefttop = pedgetable->pleftedgevert0; + prighttop = pedgetable->prightedgevert0; + + pleftbottom = pedgetable->pleftedgevert1; + prightbottom = pedgetable->prightedgevert1; + + initialleftheight = pleftbottom[1] - plefttop[1]; + initialrightheight = prightbottom[1] - prighttop[1]; + +// +// set the s, t, and light gradients, which are consistent across the triangle +// because being a triangle, things are affine +// + if( !R_PolysetCalcGradients( r_affinetridesc.skinwidth )) + return; +// +// rasterize the polygon +// + +// +// scan out the top (and possibly only) part of the left edge +// + d_pedgespanpackage = a_spans; + + ystart = plefttop[1]; + d_aspancount = plefttop[0] - prighttop[0]; + + d_ptex = (pixel_t *)r_affinetridesc.pskin + ( plefttop[2] >> 16 ) + + ( plefttop[3] >> 16 ) * r_affinetridesc.skinwidth; + + { + d_sfrac = plefttop[2] & 0xFFFF; + d_tfrac = plefttop[3] & 0xFFFF; + } + d_light = plefttop[4]; + d_zi = plefttop[5]; + + d_pdest = (pixel_t *)d_viewbuffer + + ystart * r_screenwidth + plefttop[0]; + d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0]; + + if( initialleftheight == 1 ) + { + + d_pedgespanpackage->pdest = d_pdest; + d_pedgespanpackage->pz = d_pz; + d_pedgespanpackage->count = d_aspancount; + d_pedgespanpackage->ptex = d_ptex; + + d_pedgespanpackage->sfrac = d_sfrac; + d_pedgespanpackage->tfrac = d_tfrac; + + // FIXME: need to clamp l, s, t, at both ends? + d_pedgespanpackage->light = d_light; + d_pedgespanpackage->zi = d_zi; + d_pedgespanpackage++; + } + else + { + R_PolysetSetUpForLineScan( plefttop[0], plefttop[1], + pleftbottom[0], pleftbottom[1] ); + + { + d_pzbasestep = d_zwidth + ubasestep; + d_pzextrastep = d_pzbasestep + 1; + } + + d_pdestbasestep = r_screenwidth + ubasestep; + d_pdestextrastep = d_pdestbasestep + 1; + + // TODO: can reuse partial expressions here + + // for negative steps in x along left edge, bias toward overflow rather than + // underflow (sort of turning the floor () we did in the gradient calcs into + // ceil (), but plus a little bit) + if( ubasestep < 0 ) + working_lstepx = r_lstepx - 1; + else + working_lstepx = r_lstepx; + + d_countextrastep = ubasestep + 1; + d_ptexbasestep = (( r_sstepy + r_sstepx * ubasestep ) >> 16 ) + + (( r_tstepy + r_tstepx * ubasestep ) >> 16 ) + * r_affinetridesc.skinwidth; + { + d_sfracbasestep = ( r_sstepy + r_sstepx * ubasestep ) & 0xFFFF; + d_tfracbasestep = ( r_tstepy + r_tstepx * ubasestep ) & 0xFFFF; + } + d_lightbasestep = r_lstepy + working_lstepx * ubasestep; + d_zibasestep = r_zistepy + r_zistepx * ubasestep; + + d_ptexextrastep = (( r_sstepy + r_sstepx * d_countextrastep ) >> 16 ) + + (( r_tstepy + r_tstepx * d_countextrastep ) >> 16 ) + * r_affinetridesc.skinwidth; + { + d_sfracextrastep = ( r_sstepy + r_sstepx * d_countextrastep ) & 0xFFFF; + d_tfracextrastep = ( r_tstepy + r_tstepx * d_countextrastep ) & 0xFFFF; + } + d_lightextrastep = d_lightbasestep + working_lstepx; + d_ziextrastep = d_zibasestep + r_zistepx; + + { + if( !R_PolysetScanLeftEdge_C( initialleftheight )) + return; + } + } + +// +// scan out the bottom part of the left edge, if it exists +// + if( pedgetable->numleftedges == 2 ) + { + int height; + + plefttop = pleftbottom; + pleftbottom = pedgetable->pleftedgevert2; + + height = pleftbottom[1] - plefttop[1]; + +// TODO: make this a function; modularize this function in general + + ystart = plefttop[1]; + d_aspancount = plefttop[0] - prighttop[0]; + d_ptex = (pixel_t *)r_affinetridesc.pskin + ( plefttop[2] >> 16 ) + + ( plefttop[3] >> 16 ) * r_affinetridesc.skinwidth; + + d_sfrac = 0; + d_tfrac = 0; + d_light = plefttop[4]; + d_zi = plefttop[5]; + + d_pdest = (pixel_t *)d_viewbuffer + ystart * r_screenwidth + plefttop[0]; + d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0]; + + + + if( height == 1 ) + { + d_pedgespanpackage->pdest = d_pdest; + d_pedgespanpackage->pz = d_pz; + d_pedgespanpackage->count = d_aspancount; + d_pedgespanpackage->ptex = d_ptex; + + d_pedgespanpackage->sfrac = d_sfrac; + d_pedgespanpackage->tfrac = d_tfrac; + + // FIXME: need to clamp l, s, t, at both ends? + d_pedgespanpackage->light = d_light; + d_pedgespanpackage->zi = d_zi; + d_pedgespanpackage++; + } + else + { + R_PolysetSetUpForLineScan( plefttop[0], plefttop[1], + pleftbottom[0], pleftbottom[1] ); + + d_pdestbasestep = r_screenwidth + ubasestep; + d_pdestextrastep = d_pdestbasestep + 1; + + { + d_pzbasestep = d_zwidth + ubasestep; + d_pzextrastep = d_pzbasestep + 1; + } + + if( ubasestep < 0 ) + working_lstepx = r_lstepx - 1; + else + working_lstepx = r_lstepx; + + d_countextrastep = ubasestep + 1; + d_ptexbasestep = (( r_sstepy + r_sstepx * ubasestep ) >> 16 ) + + (( r_tstepy + r_tstepx * ubasestep ) >> 16 ) + * r_affinetridesc.skinwidth; + { + d_sfracbasestep = ( r_sstepy + r_sstepx * ubasestep ) & 0xFFFF; + d_tfracbasestep = ( r_tstepy + r_tstepx * ubasestep ) & 0xFFFF; + } + d_lightbasestep = r_lstepy + working_lstepx * ubasestep; + d_zibasestep = r_zistepy + r_zistepx * ubasestep; + + d_ptexextrastep = (( r_sstepy + r_sstepx * d_countextrastep ) >> 16 ) + + (( r_tstepy + r_tstepx * d_countextrastep ) >> 16 ) + * r_affinetridesc.skinwidth; + { + d_sfracextrastep = ( r_sstepy + r_sstepx * d_countextrastep ) & 0xFFFF; + d_tfracextrastep = ( r_tstepy + r_tstepx * d_countextrastep ) & 0xFFFF; + } + d_lightextrastep = d_lightbasestep + working_lstepx; + d_ziextrastep = d_zibasestep + r_zistepx; + + { + if( !R_PolysetScanLeftEdge_C( height )) + return; + } + } + } + +// scan out the top (and possibly only) part of the right edge, updating the +// count field + d_pedgespanpackage = a_spans; + + R_PolysetSetUpForLineScan( prighttop[0], prighttop[1], + prightbottom[0], prightbottom[1] ); + d_aspancount = 0; + d_countextrastep = ubasestep + 1; + originalcount = a_spans[initialrightheight].count; + a_spans[initialrightheight].count = -999999; // mark end of the spanpackages + + ( *d_pdrawspans )( a_spans ); + +// scan out the bottom part of the right edge, if it exists + if( pedgetable->numrightedges == 2 ) + { + int height; + spanpackage_t *pstart; + + pstart = a_spans + initialrightheight; + pstart->count = originalcount; + + d_aspancount = prightbottom[0] - prighttop[0]; + + prighttop = prightbottom; + prightbottom = pedgetable->prightedgevert2; + + height = prightbottom[1] - prighttop[1]; + + R_PolysetSetUpForLineScan( prighttop[0], prighttop[1], + prightbottom[0], prightbottom[1] ); + + d_countextrastep = ubasestep + 1; + a_spans[initialrightheight + height].count = -999999; + // mark end of the spanpackages + ( *d_pdrawspans )( pstart ); + } +} + +/* +================ +R_DrawTriangle +================ +*/ +void R_DrawTriangle( void ) +{ + spanpackage_t spans[DPS_MAXSPANS]; + + int dv1_ab, dv0_ac; + int dv0_ab, dv1_ac; + + /* + d_xdenom = ( aliastriangleparms.a->v[1] - aliastriangleparms.b->v[1] ) * ( aliastriangleparms.a->v[0] - aliastriangleparms.c->v[0] ) - + ( aliastriangleparms.a->v[0] - aliastriangleparms.b->v[0] ) * ( aliastriangleparms.a->v[1] - aliastriangleparms.c->v[1] ); + */ + + dv0_ab = aliastriangleparms.a->u - aliastriangleparms.b->u; + dv1_ab = aliastriangleparms.a->v - aliastriangleparms.b->v; + + if( !( dv0_ab | dv1_ab )) + return; + + dv0_ac = aliastriangleparms.a->u - aliastriangleparms.c->u; + dv1_ac = aliastriangleparms.a->v - aliastriangleparms.c->v; + + if( !( dv0_ac | dv1_ac )) + return; + + d_xdenom = ( dv0_ac * dv1_ab ) - ( dv0_ab * dv1_ac ); + + if( d_xdenom < 0 ) + { + a_spans = spans; + + r_p0[0] = aliastriangleparms.a->u; // u + r_p0[1] = aliastriangleparms.a->v; // v + r_p0[2] = aliastriangleparms.a->s; // s + r_p0[3] = aliastriangleparms.a->t; // t + r_p0[4] = aliastriangleparms.a->l; // light + r_p0[5] = aliastriangleparms.a->zi; // iz + + r_p1[0] = aliastriangleparms.b->u; + r_p1[1] = aliastriangleparms.b->v; + r_p1[2] = aliastriangleparms.b->s; + r_p1[3] = aliastriangleparms.b->t; + r_p1[4] = aliastriangleparms.b->l; + r_p1[5] = aliastriangleparms.b->zi; + + r_p2[0] = aliastriangleparms.c->u; + r_p2[1] = aliastriangleparms.c->v; + r_p2[2] = aliastriangleparms.c->s; + r_p2[3] = aliastriangleparms.c->t; + r_p2[4] = aliastriangleparms.c->l; + r_p2[5] = aliastriangleparms.c->zi; + + R_PolysetSetEdgeTable(); + R_RasterizeAliasPolySmooth(); + } +} + +static inline qboolean R_DrawCheckBounds( pixel_t *lptex ) +{ + pixel_t *skin = r_affinetridesc.pskin; + if( lptex - skin < 0 || lptex - skinend >= 0 ) + return false; + return true; +} + +static inline qboolean R_PolysetCheckBounds( pixel_t *lptex, int lsfrac, int ltfrac, int lcount ) +{ + pixel_t *start, *end; + start = r_affinetridesc.pskin; + end = skinend; + + // span is linear, so only need to check first and last + if( lptex - start < 0 || lptex - end >= 0 ) + return false; + + if( !( --lcount )) + return true; + + lptex = lptex + a_ststepxwhole * lcount + (( lsfrac + ( a_sstepxfrac * lcount )) >> 16 ) + (( ltfrac + ( a_tstepxfrac * lcount )) >> 16 ) * r_affinetridesc.skinwidth; + + if( lptex - start < 0 || lptex - end >= 0 ) + return false; + + + return true; +} /* ================ @@ -859,236 +1138,6 @@ void R_PolysetDrawSpans8_33( spanpackage_t *pspanpackage ) while( pspanpackage->count != -999999 ); } -void R_PolysetDrawSpansConstant8_33( spanpackage_t *pspanpackage ) -{ - int lcount; - pixel_t *lpdest; - int lzi; - short *lpz; - - do - { - lcount = d_aspancount - pspanpackage->count; - - errorterm += erroradjustup; - if( errorterm >= 0 ) - { - d_aspancount += d_countextrastep; - errorterm -= erroradjustdown; - } - else - { - d_aspancount += ubasestep; - } - - if( lcount ) - { - lpdest = pspanpackage->pdest; - lpz = pspanpackage->pz; - lzi = pspanpackage->zi; - - do - { - if(( lzi >> 16 ) >= *lpz ) - { - *lpdest = BLEND_ALPHA( 2, r_aliasblendcolor, *lpdest ); // vid.alphamap[r_aliasblendcolor + *lpdest*256]; - } - lpdest++; - lzi += r_zistepx; - lpz++; - } - while( --lcount ); - } - - pspanpackage++; - } - while( pspanpackage->count != -999999 ); -} - -void R_PolysetDrawSpans8_66( spanpackage_t *pspanpackage ) -{ - int lcount; - pixel_t *lpdest; - pixel_t *lptex; - int lsfrac, ltfrac; - int llight; - int lzi; - short *lpz; - - do - { - lcount = d_aspancount - pspanpackage->count; - - errorterm += erroradjustup; - if( errorterm >= 0 ) - { - d_aspancount += d_countextrastep; - errorterm -= erroradjustdown; - } - else - { - d_aspancount += ubasestep; - } - - if( lcount ) - { - lpdest = pspanpackage->pdest; - lptex = pspanpackage->ptex; - lpz = pspanpackage->pz; - lsfrac = pspanpackage->sfrac; - ltfrac = pspanpackage->tfrac; - llight = pspanpackage->light; - lzi = pspanpackage->zi; - - do - { - if(( lzi >> 16 ) >= *lpz ) - { - int temp = vid.colormap[*lptex + ( llight & 0xFF00 )]; - - *lpdest = BLEND_ALPHA( 5, temp, *lpdest ); // vid.alphamap[temp*256 + *lpdest]; - *lpz = lzi >> 16; - } - lpdest++; - lzi += r_zistepx; - lpz++; - llight += r_lstepx; - lptex += a_ststepxwhole; - lsfrac += a_sstepxfrac; - lptex += lsfrac >> 16; - lsfrac &= 0xFFFF; - ltfrac += a_tstepxfrac; - if( ltfrac & 0x10000 ) - { - lptex += r_affinetridesc.skinwidth; - ltfrac &= 0xFFFF; - } - } - while( --lcount ); - } - - pspanpackage++; - } - while( pspanpackage->count != -999999 ); -} - -static void R_PolysetDrawSpansConstant8_66( spanpackage_t *pspanpackage ) -{ - int lcount; - pixel_t *lpdest; - int lzi; - short *lpz; - - do - { - lcount = d_aspancount - pspanpackage->count; - - errorterm += erroradjustup; - if( errorterm >= 0 ) - { - d_aspancount += d_countextrastep; - errorterm -= erroradjustdown; - } - else - { - d_aspancount += ubasestep; - } - - if( lcount ) - { - lpdest = pspanpackage->pdest; - lpz = pspanpackage->pz; - lzi = pspanpackage->zi; - - do - { - if(( lzi >> 16 ) >= *lpz ) - { - *lpdest = BLEND_ALPHA( 5, r_aliasblendcolor, *lpdest ); // vid.alphamap[r_aliasblendcolor*256 + *lpdest]; - } - lpdest++; - lzi += r_zistepx; - lpz++; - } - while( --lcount ); - } - - pspanpackage++; - } - while( pspanpackage->count != -999999 ); -} - -void R_PolysetDrawSpans8_Opaque( spanpackage_t *pspanpackage ) -{ - int lcount; - - do - { - lcount = d_aspancount - pspanpackage->count; - - errorterm += erroradjustup; - if( errorterm >= 0 ) - { - d_aspancount += d_countextrastep; - errorterm -= erroradjustdown; - } - else - { - d_aspancount += ubasestep; - } - - if( lcount ) - { - int lsfrac, ltfrac; - pixel_t *lpdest; - pixel_t *lptex; - int llight; - int lzi; - short *lpz; - - lpdest = pspanpackage->pdest; - lptex = pspanpackage->ptex; - lpz = pspanpackage->pz; - lsfrac = pspanpackage->sfrac; - ltfrac = pspanpackage->tfrac; - llight = pspanpackage->light; - lzi = pspanpackage->zi; - - do - { - if(( lzi >> 16 ) >= *lpz ) - { -// PGM - /*if(r_newrefdef.rdflags & RDF_IRGOGGLES && RI.currententity->flags & RF_IR_VISIBLE) - *lpdest = ((byte *)vid.colormap)[irtable[*lptex]]; - else*/ - *lpdest = ((byte *)vid.colormap )[*lptex + ( llight & 0xFF00 )]; -// PGM - *lpz = lzi >> 16; - } - lpdest++; - lzi += r_zistepx; - lpz++; - llight += r_lstepx; - lptex += a_ststepxwhole; - lsfrac += a_sstepxfrac; - lptex += lsfrac >> 16; - lsfrac &= 0xFFFF; - ltfrac += a_tstepxfrac; - if( ltfrac & 0x10000 ) - { - lptex += r_affinetridesc.skinwidth; - ltfrac &= 0xFFFF; - } - } - while( --lcount ); - } - - pspanpackage++; - } - while( pspanpackage->count != -999999 ); -} - void R_PolysetFillSpans8( spanpackage_t *pspanpackage ) { // int color; @@ -1171,313 +1220,4 @@ void R_PolysetFillSpans8( spanpackage_t *pspanpackage ) while( pspanpackage->count != -999999 ); } -/* -================ -R_RasterizeAliasPolySmooth -================ -*/ -void R_RasterizeAliasPolySmooth( void ) -{ - int initialleftheight, initialrightheight; - int *plefttop, *prighttop, *pleftbottom, *prightbottom; - int working_lstepx, originalcount; - - plefttop = pedgetable->pleftedgevert0; - prighttop = pedgetable->prightedgevert0; - - pleftbottom = pedgetable->pleftedgevert1; - prightbottom = pedgetable->prightedgevert1; - - initialleftheight = pleftbottom[1] - plefttop[1]; - initialrightheight = prightbottom[1] - prighttop[1]; - -// -// set the s, t, and light gradients, which are consistent across the triangle -// because being a triangle, things are affine -// - if( !R_PolysetCalcGradients( r_affinetridesc.skinwidth )) - return; -// -// rasterize the polygon -// - -// -// scan out the top (and possibly only) part of the left edge -// - d_pedgespanpackage = a_spans; - - ystart = plefttop[1]; - d_aspancount = plefttop[0] - prighttop[0]; - - d_ptex = (pixel_t *)r_affinetridesc.pskin + ( plefttop[2] >> 16 ) - + ( plefttop[3] >> 16 ) * r_affinetridesc.skinwidth; - - { - d_sfrac = plefttop[2] & 0xFFFF; - d_tfrac = plefttop[3] & 0xFFFF; - } - d_light = plefttop[4]; - d_zi = plefttop[5]; - - d_pdest = (pixel_t *)d_viewbuffer - + ystart * r_screenwidth + plefttop[0]; - d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0]; - - if( initialleftheight == 1 ) - { - - d_pedgespanpackage->pdest = d_pdest; - d_pedgespanpackage->pz = d_pz; - d_pedgespanpackage->count = d_aspancount; - d_pedgespanpackage->ptex = d_ptex; - - d_pedgespanpackage->sfrac = d_sfrac; - d_pedgespanpackage->tfrac = d_tfrac; - - // FIXME: need to clamp l, s, t, at both ends? - d_pedgespanpackage->light = d_light; - d_pedgespanpackage->zi = d_zi; - d_pedgespanpackage++; - } - else - { - R_PolysetSetUpForLineScan( plefttop[0], plefttop[1], - pleftbottom[0], pleftbottom[1] ); - - { - d_pzbasestep = d_zwidth + ubasestep; - d_pzextrastep = d_pzbasestep + 1; - } - - d_pdestbasestep = r_screenwidth + ubasestep; - d_pdestextrastep = d_pdestbasestep + 1; - - // TODO: can reuse partial expressions here - - // for negative steps in x along left edge, bias toward overflow rather than - // underflow (sort of turning the floor () we did in the gradient calcs into - // ceil (), but plus a little bit) - if( ubasestep < 0 ) - working_lstepx = r_lstepx - 1; - else - working_lstepx = r_lstepx; - - d_countextrastep = ubasestep + 1; - d_ptexbasestep = (( r_sstepy + r_sstepx * ubasestep ) >> 16 ) - + (( r_tstepy + r_tstepx * ubasestep ) >> 16 ) - * r_affinetridesc.skinwidth; - { - d_sfracbasestep = ( r_sstepy + r_sstepx * ubasestep ) & 0xFFFF; - d_tfracbasestep = ( r_tstepy + r_tstepx * ubasestep ) & 0xFFFF; - } - d_lightbasestep = r_lstepy + working_lstepx * ubasestep; - d_zibasestep = r_zistepy + r_zistepx * ubasestep; - - d_ptexextrastep = (( r_sstepy + r_sstepx * d_countextrastep ) >> 16 ) - + (( r_tstepy + r_tstepx * d_countextrastep ) >> 16 ) - * r_affinetridesc.skinwidth; - { - d_sfracextrastep = ( r_sstepy + r_sstepx * d_countextrastep ) & 0xFFFF; - d_tfracextrastep = ( r_tstepy + r_tstepx * d_countextrastep ) & 0xFFFF; - } - d_lightextrastep = d_lightbasestep + working_lstepx; - d_ziextrastep = d_zibasestep + r_zistepx; - - { - if( !R_PolysetScanLeftEdge_C( initialleftheight )) - return; - } - } - -// -// scan out the bottom part of the left edge, if it exists -// - if( pedgetable->numleftedges == 2 ) - { - int height; - - plefttop = pleftbottom; - pleftbottom = pedgetable->pleftedgevert2; - - height = pleftbottom[1] - plefttop[1]; - -// TODO: make this a function; modularize this function in general - - ystart = plefttop[1]; - d_aspancount = plefttop[0] - prighttop[0]; - d_ptex = (pixel_t *)r_affinetridesc.pskin + ( plefttop[2] >> 16 ) - + ( plefttop[3] >> 16 ) * r_affinetridesc.skinwidth; - - d_sfrac = 0; - d_tfrac = 0; - d_light = plefttop[4]; - d_zi = plefttop[5]; - - d_pdest = (pixel_t *)d_viewbuffer + ystart * r_screenwidth + plefttop[0]; - d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0]; - - - - if( height == 1 ) - { - d_pedgespanpackage->pdest = d_pdest; - d_pedgespanpackage->pz = d_pz; - d_pedgespanpackage->count = d_aspancount; - d_pedgespanpackage->ptex = d_ptex; - - d_pedgespanpackage->sfrac = d_sfrac; - d_pedgespanpackage->tfrac = d_tfrac; - - // FIXME: need to clamp l, s, t, at both ends? - d_pedgespanpackage->light = d_light; - d_pedgespanpackage->zi = d_zi; - d_pedgespanpackage++; - } - else - { - R_PolysetSetUpForLineScan( plefttop[0], plefttop[1], - pleftbottom[0], pleftbottom[1] ); - - d_pdestbasestep = r_screenwidth + ubasestep; - d_pdestextrastep = d_pdestbasestep + 1; - - { - d_pzbasestep = d_zwidth + ubasestep; - d_pzextrastep = d_pzbasestep + 1; - } - - if( ubasestep < 0 ) - working_lstepx = r_lstepx - 1; - else - working_lstepx = r_lstepx; - - d_countextrastep = ubasestep + 1; - d_ptexbasestep = (( r_sstepy + r_sstepx * ubasestep ) >> 16 ) - + (( r_tstepy + r_tstepx * ubasestep ) >> 16 ) - * r_affinetridesc.skinwidth; - { - d_sfracbasestep = ( r_sstepy + r_sstepx * ubasestep ) & 0xFFFF; - d_tfracbasestep = ( r_tstepy + r_tstepx * ubasestep ) & 0xFFFF; - } - d_lightbasestep = r_lstepy + working_lstepx * ubasestep; - d_zibasestep = r_zistepy + r_zistepx * ubasestep; - - d_ptexextrastep = (( r_sstepy + r_sstepx * d_countextrastep ) >> 16 ) - + (( r_tstepy + r_tstepx * d_countextrastep ) >> 16 ) - * r_affinetridesc.skinwidth; - { - d_sfracextrastep = ( r_sstepy + r_sstepx * d_countextrastep ) & 0xFFFF; - d_tfracextrastep = ( r_tstepy + r_tstepx * d_countextrastep ) & 0xFFFF; - } - d_lightextrastep = d_lightbasestep + working_lstepx; - d_ziextrastep = d_zibasestep + r_zistepx; - - { - if( !R_PolysetScanLeftEdge_C( height )) - return; - } - } - } - -// scan out the top (and possibly only) part of the right edge, updating the -// count field - d_pedgespanpackage = a_spans; - - R_PolysetSetUpForLineScan( prighttop[0], prighttop[1], - prightbottom[0], prightbottom[1] ); - d_aspancount = 0; - d_countextrastep = ubasestep + 1; - originalcount = a_spans[initialrightheight].count; - a_spans[initialrightheight].count = -999999; // mark end of the spanpackages - - ( *d_pdrawspans )( a_spans ); - -// scan out the bottom part of the right edge, if it exists - if( pedgetable->numrightedges == 2 ) - { - int height; - spanpackage_t *pstart; - - pstart = a_spans + initialrightheight; - pstart->count = originalcount; - - d_aspancount = prightbottom[0] - prighttop[0]; - - prighttop = prightbottom; - prightbottom = pedgetable->prightedgevert2; - - height = prightbottom[1] - prighttop[1]; - - R_PolysetSetUpForLineScan( prighttop[0], prighttop[1], - prightbottom[0], prightbottom[1] ); - - d_countextrastep = ubasestep + 1; - a_spans[initialrightheight + height].count = -999999; - // mark end of the spanpackages - ( *d_pdrawspans )( pstart ); - } -} - - -/* -================ -R_PolysetSetEdgeTable -================ -*/ -void R_PolysetSetEdgeTable( void ) -{ - int edgetableindex; - - edgetableindex = 0; // assume the vertices are already in - // top to bottom order - -// -// determine which edges are right & left, and the order in which -// to rasterize them -// - if( r_p0[1] >= r_p1[1] ) - { - if( r_p0[1] == r_p1[1] ) - { - if( r_p0[1] < r_p2[1] ) - pedgetable = &edgetables[2]; - else - pedgetable = &edgetables[5]; - - return; - } - else - { - edgetableindex = 1; - } - } - - if( r_p0[1] == r_p2[1] ) - { - if( edgetableindex ) - pedgetable = &edgetables[8]; - else - pedgetable = &edgetables[9]; - - return; - } - else if( r_p1[1] == r_p2[1] ) - { - if( edgetableindex ) - pedgetable = &edgetables[10]; - else - pedgetable = &edgetables[11]; - - return; - } - - if( r_p0[1] > r_p2[1] ) - edgetableindex += 2; - - if( r_p1[1] > r_p2[1] ) - edgetableindex += 4; - - pedgetable = &edgetables[edgetableindex]; -} - diff --git a/ref/soft/r_rast.c b/ref/soft/r_rast.c index 3dff5d94..b29f74ab 100644 --- a/ref/soft/r_rast.c +++ b/ref/soft/r_rast.c @@ -29,26 +29,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define FULLY_CLIPPED_CACHED 0x80000000 #define FRAMECOUNT_MASK 0x7FFFFFFF -unsigned int cacheoffset; - -int c_faceclip; // number of faces clipped - - -clipplane_t *entity_clipplanes; -clipplane_t world_clipplanes[16]; - -medge16_t *r_pedge; - -qboolean r_leftclipped, r_rightclipped; +static unsigned int cacheoffset; +static int c_faceclip; // number of faces clipped +static medge16_t *r_pedge; +static qboolean r_leftclipped, r_rightclipped; static qboolean makeleftedge, makerightedge; -qboolean r_nearzionly; +static qboolean r_nearzionly; int sintable[1280]; -int intsintable[1280]; int blanktable[1280]; // PGM -mvertex_t r_leftenter, r_leftexit; -mvertex_t r_rightenter, r_rightexit; +static mvertex_t r_leftenter, r_leftexit; +static mvertex_t r_rightenter, r_rightexit; typedef struct { @@ -56,52 +48,12 @@ typedef struct int ceilv; } evert_t; -int r_emitted; -float r_nearzi; -float r_u1, r_v1, r_lzi1; -int r_ceilv1; +static int r_emitted; +static float r_nearzi; +static float r_u1, r_v1, r_lzi1; +static int r_ceilv1; -qboolean r_lastvertvalid; -int r_skyframe; - -msurface_t *r_skyfaces; -mplane_t r_skyplanes[6]; -mtexinfo_t r_skytexinfo[6]; -mvertex_t *r_skyverts; -medge16_t *r_skyedges; -int *r_skysurfedges; - -// I just copied this data from a box map... -int skybox_planes[12] = {2, -128, 0, -128, 2, 128, 1, 128, 0, 128, 1, -128}; - -int box_surfedges[24] = { 1, 2, 3, 4, -1, 5, 6, 7, 8, 9, -6, 10, -2, -7, -9, 11, - 12, -3, -11, -8, -12, -10, -5, -4}; -int box_edges[24] = { 1, 2, 2, 3, 3, 4, 4, 1, 1, 5, 5, 6, 6, 2, 7, 8, 8, 6, 5, 7, 8, 3, 7, 4}; - -int box_faces[6] = {0, 0, 2, 2, 2, 0}; - -vec3_t box_vecs[6][2] = { - { {0, -1, 0}, {-1, 0, 0} }, - { {0, 1, 0}, {0, 0, -1} }, - { {0, -1, 0}, {1, 0, 0} }, - { {1, 0, 0}, {0, 0, -1} }, - { {0, -1, 0}, {0, 0, -1} }, - { {-1, 0, 0}, {0, 0, -1} } -}; - -float box_verts[8][3] = { - {-1, -1, -1}, - {-1, 1, -1}, - {1, 1, -1}, - {1, -1, -1}, - {-1, -1, 1}, - {-1, 1, 1}, - {1, -1, 1}, - {1, 1, 1} -}; - -// down, west, up, north, east, south -// {"rt", "bk", "lf", "ft", "up", "dn"}; +static qboolean r_lastvertvalid; /* ================ diff --git a/ref/soft/r_scan.c b/ref/soft/r_scan.c index 631609ad..bb23d5ff 100644 --- a/ref/soft/r_scan.c +++ b/ref/soft/r_scan.c @@ -36,7 +36,7 @@ int alpha; D_DrawTurbulent8Span ============= */ -void D_DrawTurbulent8Span( void ) +static void D_DrawTurbulent8Span( void ) { int sturb, tturb; diff --git a/ref/soft/r_sprite.c b/ref/soft/r_sprite.c index e1b1548f..b77c285d 100644 --- a/ref/soft/r_sprite.c +++ b/ref/soft/r_sprite.c @@ -332,182 +332,6 @@ mspriteframe_t *R_GetSpriteFrame( const model_t *pModel, int frame, float yaw ) return pspriteframe; } -/* -================ -R_GetSpriteFrameInterpolant - -NOTE: we using prevblending[0] and [1] for holds interval -between frames where are we lerping -================ -*/ -static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **oldframe, mspriteframe_t **curframe ) -{ - msprite_t *psprite; - mspritegroup_t *pspritegroup; - int i, j, numframes, frame; - float lerpFrac, time, jtime, jinterval; - float *pintervals, fullinterval, targettime; - int m_fDoInterp; - - psprite = ent->model->cache.data; - frame = (int)ent->curstate.frame; - lerpFrac = 1.0f; - - // misc info - m_fDoInterp = ( ent->curstate.effects & EF_NOINTERP ) ? false : true; - - if( frame < 0 ) - { - frame = 0; - } - else if( frame >= psprite->numframes ) - { - gEngfuncs.Con_Reportf( S_WARN "%s: no such frame %d (%s)\n", __func__, frame, ent->model->name ); - frame = psprite->numframes - 1; - } - - if( psprite->frames[frame].type == FRAME_SINGLE ) - { - if( m_fDoInterp ) - { - if( ent->latched.prevblending[0] >= psprite->numframes || psprite->frames[ent->latched.prevblending[0]].type != FRAME_SINGLE ) - { - // this can be happens when rendering switched between single and angled frames - // or change model on replace delta-entity - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 1.0f; - } - - if( ent->latched.sequencetime < gp_cl->time ) - { - if( frame != ent->latched.prevblending[1] ) - { - ent->latched.prevblending[0] = ent->latched.prevblending[1]; - ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 0.0f; - } - else - lerpFrac = ( gp_cl->time - ent->latched.sequencetime ) * 11.0f; - } - else - { - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 0.0f; - } - } - else - { - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - lerpFrac = 1.0f; - } - - if( ent->latched.prevblending[0] >= psprite->numframes ) - { - // reset interpolation on change model - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 0.0f; - } - - // get the interpolated frames - if( oldframe ) - *oldframe = psprite->frames[ent->latched.prevblending[0]].frameptr; - if( curframe ) - *curframe = psprite->frames[frame].frameptr; - } - else if( psprite->frames[frame].type == FRAME_GROUP ) - { - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - pintervals = pspritegroup->intervals; - numframes = pspritegroup->numframes; - fullinterval = pintervals[numframes - 1]; - jinterval = pintervals[1] - pintervals[0]; - time = gp_cl->time; - jtime = 0.0f; - - // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values - // are positive, so we don't have to worry about division by zero - targettime = time - ((int)( time / fullinterval )) * fullinterval; - - // LordHavoc: since I can't measure the time properly when it loops from numframes - 1 to 0, - // i instead measure the time of the first frame, hoping it is consistent - for( i = 0, j = numframes - 1; i < ( numframes - 1 ); i++ ) - { - if( pintervals[i] > targettime ) - break; - j = i; - jinterval = pintervals[i] - jtime; - jtime = pintervals[i]; - } - - if( m_fDoInterp ) - lerpFrac = ( targettime - jtime ) / jinterval; - else - j = i; // no lerping - - // get the interpolated frames - if( oldframe ) - *oldframe = pspritegroup->frames[j]; - if( curframe ) - *curframe = pspritegroup->frames[i]; - } - else if( psprite->frames[frame].type == FRAME_ANGLED ) - { - // e.g. doom-style sprite monsters - float yaw = ent->angles[YAW]; - int angleframe = (int)( Q_rint(( RI.viewangles[1] - yaw + 45.0f ) / 360 * 8 ) - 4 ) & 7; - - if( m_fDoInterp ) - { - if( ent->latched.prevblending[0] >= psprite->numframes || psprite->frames[ent->latched.prevblending[0]].type != FRAME_ANGLED ) - { - // this can be happens when rendering switched between single and angled frames - // or change model on replace delta-entity - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 1.0f; - } - - if( ent->latched.sequencetime < gp_cl->time ) - { - if( frame != ent->latched.prevblending[1] ) - { - ent->latched.prevblending[0] = ent->latched.prevblending[1]; - ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 0.0f; - } - else - lerpFrac = ( gp_cl->time - ent->latched.sequencetime ) * ent->curstate.framerate; - } - else - { - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - ent->latched.sequencetime = gp_cl->time; - lerpFrac = 0.0f; - } - } - else - { - ent->latched.prevblending[0] = ent->latched.prevblending[1] = frame; - lerpFrac = 1.0f; - } - - pspritegroup = (mspritegroup_t *)psprite->frames[ent->latched.prevblending[0]].frameptr; - if( oldframe ) - *oldframe = pspritegroup->frames[angleframe]; - - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - if( curframe ) - *curframe = pspritegroup->frames[angleframe]; - } - - return lerpFrac; -} - /* ================ R_CullSpriteModel @@ -616,7 +440,6 @@ R_DrawSpriteQuad static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale ) { vec3_t point; - image_t *image; r_stats.c_sprite_polys++; /*image = R_GetTexture(frame->gl_texturenum); @@ -644,55 +467,6 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, TriEnd(); } -static qboolean R_SpriteHasLightmap( cl_entity_t *e, int texFormat ) -{ - if( !r_sprite_lighting->value ) - return false; - - if( texFormat != SPR_ALPHTEST ) - return false; - - if( e->curstate.effects & EF_FULLBRIGHT ) - return false; - - if( e->curstate.renderamt <= 127 ) - return false; - - switch( e->curstate.rendermode ) - { - case kRenderNormal: - case kRenderTransAlpha: - case kRenderTransTexture: - break; - default: - return false; - } - - return true; -} - -/* -================= -R_SpriteAllowLerping -================= -*/ -static qboolean R_SpriteAllowLerping( cl_entity_t *e, msprite_t *psprite ) -{ - if( !r_sprite_lerping->value ) - return false; - - if( psprite->numframes <= 1 ) - return false; - - if( psprite->texFormat != SPR_ADDITIVE ) - return false; - - if( e->curstate.rendermode == kRenderNormal || e->curstate.rendermode == kRenderTransAlpha ) - return false; - - return true; -} - /* ================= R_DrawSpriteModel @@ -700,14 +474,13 @@ R_DrawSpriteModel */ void R_DrawSpriteModel( cl_entity_t *e ) { - mspriteframe_t *frame = NULL, *oldframe = NULL; + mspriteframe_t *frame = NULL; msprite_t *psprite; model_t *model; int i, type; - float angle, dot, sr, cr; - float lerp = 1.0f, ilerp, scale; + float angle, dot, sr, cr, scale; vec3_t v_forward, v_right, v_up; - vec3_t origin, color, color2; + vec3_t origin, color; if( RI.params & RP_ENVVIEW ) return; @@ -763,21 +536,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) color[2] = 1.0f; } - if( R_SpriteHasLightmap( e, psprite->texFormat )) - { - colorVec lightColor = R_LightPoint( origin ); - // FIXME: collect light from dlights? - color2[0] = (float)lightColor.r * ( 1.0f / 255.0f ); - color2[1] = (float)lightColor.g * ( 1.0f / 255.0f ); - color2[2] = (float)lightColor.b * ( 1.0f / 255.0f ); - // NOTE: sprites with 'lightmap' looks ugly when alpha func is GL_GREATER 0.0 - // pglAlphaFunc( GL_GREATER, 0.5f ); - } - - if( R_SpriteAllowLerping( e, psprite )) - lerp = R_GetSpriteFrameInterpolant( e, &oldframe, &frame ); - else - frame = oldframe = R_GetSpriteFrame( model, e->curstate.frame, e->angles[YAW] ); + frame = R_GetSpriteFrame( model, e->curstate.frame, e->angles[YAW] ); type = psprite->type; @@ -824,31 +583,8 @@ void R_DrawSpriteModel( cl_entity_t *e ) // if( psprite->facecull == SPR_CULL_NONE ) // GL_Cull( GL_NONE ); - if( oldframe == frame ) - { - // draw the single non-lerped frame - _TriColor4f( color[0], color[1], color[2], tr.blend ); - GL_Bind( XASH_TEXTURE0, frame->gl_texturenum ); - R_DrawSpriteQuad( frame, origin, v_right, v_up, scale ); - } - else - { - // draw two combined lerped frames - lerp = bound( 0.0f, lerp, 1.0f ); - ilerp = 1.0f - lerp; - - if( ilerp != 0.0f ) - { - _TriColor4f( color[0], color[1], color[2], tr.blend * ilerp ); - GL_Bind( XASH_TEXTURE0, oldframe->gl_texturenum ); - R_DrawSpriteQuad( oldframe, origin, v_right, v_up, scale ); - } - - if( lerp != 0.0f ) - { - _TriColor4f( color[0], color[1], color[2], tr.blend * lerp ); - GL_Bind( XASH_TEXTURE0, frame->gl_texturenum ); - R_DrawSpriteQuad( frame, origin, v_right, v_up, scale ); - } - } + // draw the single non-lerped frame + _TriColor4f( color[0], color[1], color[2], tr.blend ); + GL_Bind( XASH_TEXTURE0, frame->gl_texturenum ); + R_DrawSpriteQuad( frame, origin, v_right, v_up, scale ); } diff --git a/ref/soft/r_studio.c b/ref/soft/r_studio.c index 7a8ea3fe..336f79c8 100644 --- a/ref/soft/r_studio.c +++ b/ref/soft/r_studio.c @@ -33,18 +33,6 @@ typedef struct CVAR_DEFINE_AUTO( r_shadows, "0", 0, "draw ugly shadows" ); -static const vec3_t hullcolor[8] = -{ - { 1.0f, 1.0f, 1.0f }, - { 1.0f, 0.5f, 0.5f }, - { 0.5f, 1.0f, 0.5f }, - { 1.0f, 1.0f, 0.5f }, - { 0.5f, 0.5f, 1.0f }, - { 1.0f, 0.5f, 1.0f }, - { 0.5f, 1.0f, 1.0f }, - { 1.0f, 1.0f, 1.0f }, -}; - typedef struct sortedmesh_s { mstudiomesh_t *mesh; @@ -1548,7 +1536,7 @@ static void R_StudioEntityLight( alight_t *lightinfo ) float minstrength, dist2, f, r2; float lstrength[MAX_LOCALLIGHTS]; cl_entity_t *ent = RI.currententity; - vec3_t mid, origin, pos; + vec3_t mid, origin; dlight_t *el; g_studio.numlocallights = 0; @@ -1580,7 +1568,6 @@ static void R_StudioEntityLight( alight_t *lightinfo ) VectorCopy( ent->origin, el->origin ); } - VectorCopy( el->origin, pos ); VectorSubtract( origin, el->origin, mid ); f = DotProduct( mid, mid ); @@ -1959,7 +1946,6 @@ generic path */ static void R_StudioDrawNormalMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t ) { - float *lv; int i; while(( i = *( ptricmds++ ))) @@ -1993,7 +1979,6 @@ generic path */ static void R_StudioDrawFloatMesh( short *ptricmds, vec3_t *pstudionorms ) { - float *lv; int i; while(( i = *( ptricmds++ ))) @@ -2602,70 +2587,6 @@ static int pfnIsHardware( void ) return 1; // 0 is Software, 1 is OpenGL, 2 is Direct3D } -/* -=============== -R_StudioDrawPointsShadow - -=============== -*/ -static void R_StudioDrawPointsShadow( void ) -{ - float *av, height; - float vec_x, vec_y; - mstudiomesh_t *pmesh; - vec3_t point; - int i, k; - - if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW )) - return; - - // if( glState.stencilEnabled ) - // pglEnable( GL_STENCIL_TEST ); - - height = g_studio.lightspot[2] + 1.0f; - vec_x = -g_studio.lightvec[0] * 8.0f; - vec_y = -g_studio.lightvec[1] * 8.0f; - - for( k = 0; k < m_pSubModel->nummesh; k++ ) - { - short *ptricmds; - - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex ) + k; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex ); - - r_stats.c_studio_polys += pmesh->numtris; - - while(( i = *( ptricmds++ ))) - { - if( i < 0 ) - { - TriBegin( TRI_TRIANGLE_FAN ); - i = -i; - } - else - { - TriBegin( TRI_TRIANGLE_STRIP ); - } - - - for( ; i > 0; i--, ptricmds += 4 ) - { - av = g_studio.verts[ptricmds[0]]; - point[0] = av[0] - ( vec_x * ( av[2] - g_studio.lightspot[2] )); - point[1] = av[1] - ( vec_y * ( av[2] - g_studio.lightspot[2] )); - point[2] = g_studio.lightspot[2] + 1.0f; - - TriVertex3fv( point ); - } - - TriEnd(); - } - } - - // if( glState.stencilEnabled ) - // pglDisable( GL_STENCIL_TEST ); -} - /* =============== GL_StudioSetRenderMode diff --git a/ref/soft/r_surf.c b/ref/soft/r_surf.c index 3a08f1b4..2692f5e2 100644 --- a/ref/soft/r_surf.c +++ b/ref/soft/r_surf.c @@ -24,18 +24,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. drawsurf_t r_drawsurf; -uint lightleft, sourcesstep, blocksize, sourcetstep; -uint lightdelta, lightdeltastep; -uint lightright, lightleftstep, lightrightstep, blockdivshift; -unsigned blockdivmask; -void *prowdestbase; -pixel_t *pbasesource; -int surfrowbytes; // used by ASM files -unsigned *r_lightptr; -int r_stepback; -int r_lightwidth; -int r_numhblocks, r_numvblocks; -pixel_t *r_source, *r_sourcemax; +static uint lightleft, blocksize, sourcetstep; +static uint lightright, lightleftstep, lightrightstep, blockdivshift; +static unsigned blockdivmask; +static void *prowdestbase; +static pixel_t *pbasesource; +static int surfrowbytes; // used by ASM files +static unsigned *r_lightptr; +static int r_stepback; +static int r_lightwidth; +static int r_numhblocks, r_numvblocks; +static pixel_t *r_source, *r_sourcemax; void R_DrawSurfaceBlock8_mip0( void ); void R_DrawSurfaceBlock8_mip1( void ); @@ -56,11 +55,12 @@ static void (*surfmiptable[4])( void ) = { // void R_BuildLightMap (void); extern unsigned blocklights[10240]; // allow some very large lightmaps -float surfscale; -qboolean r_cache_thrash; // set if surface cache is thrashing +static float surfscale; +static qboolean r_cache_thrash; // set if surface cache is thrashing -int sc_size; -surfcache_t *sc_rover, *sc_base; +static int sc_size; +surfcache_t *sc_rover; +static surfcache_t *sc_base; static int rtable[MOD_FRAMES][MOD_FRAMES]; @@ -253,57 +253,6 @@ void GL_InitRandomTable( void ) gEngfuncs.COM_SetRandomSeed( 0 ); } -/* -=============== -R_TextureAnim - -Returns the proper texture for a given time and base texture, do not process random tiling -=============== -*/ -static texture_t *R_TextureAnim( texture_t *b ) -{ - texture_t *base = b; - int count, reletive; - - if( RI.currententity->curstate.frame ) - { - if( base->alternate_anims ) - base = base->alternate_anims; - } - - if( !base->anim_total ) - return base; - if( base->name[0] == '-' ) - { - return b; // already tiled - } - else - { - int speed; - - // Quake1 textures uses 10 frames per second - if( FBitSet( R_GetTexture( base->gl_texturenum )->flags, TF_QUAKEPAL )) - speed = 10; - else - speed = 20; - - reletive = (int)( gp_cl->time * speed ) % base->anim_total; - } - - - count = 0; - - while( base->anim_min > reletive || base->anim_max <= reletive ) - { - base = base->anim_next; - - if( !base || ++count > MOD_FRAMES ) - return b; - } - - return base; -} - /* =============== R_TextureAnimation diff --git a/ref/soft/r_trialias.c b/ref/soft/r_trialias.c index 07c43539..c9bf2864 100644 --- a/ref/soft/r_trialias.c +++ b/ref/soft/r_trialias.c @@ -9,9 +9,9 @@ affinetridesc_t r_affinetridesc; int r_aliasblendcolor; -float aliastransform[3][4]; -float aliasworldtransform[3][4]; -float aliasoldworldtransform[3][4]; +static float aliastransform[3][4]; +static float aliasworldtransform[3][4]; +static float aliasoldworldtransform[3][4]; float s_ziscale; static vec3_t s_alias_forward, s_alias_right, s_alias_up; @@ -27,9 +27,6 @@ float r_avertexnormals[NUMVERTEXNORMALS][3] = { void R_AliasSetUpTransform( void ); void R_AliasProjectAndClipTestFinalVert( finalvert_t *fv ); -void R_AliasTransformFinalVerts( int numpoints, finalvert_t *fv, dtrivertx_t *oldv, dtrivertx_t *newv ); - - /* ================ R_AliasCheckBBox