From f70938d2b0f0ad01ced0b7d59e5897552fde0e60 Mon Sep 17 00:00:00 2001 From: Crow-bar Date: Mon, 10 Oct 2022 16:44:48 +0300 Subject: [PATCH] ref_gl: ref_soft: ref_gu: engine: TriAPI update --- engine/client/cl_game.c | 186 +++--------------------------------- engine/client/cl_gameui.c | 12 +-- engine/client/cl_netgraph.c | 20 ++-- engine/client/cl_tent.c | 2 +- engine/client/cl_tent.h | 13 --- engine/client/cl_view.c | 18 ++-- engine/client/client.h | 5 +- engine/client/console.c | 14 +-- engine/client/in_touch.c | 16 ++-- engine/client/ref_common.c | 37 ++----- engine/ref_api.h | 16 +--- ref_gl/gl_backend.c | 10 ++ ref_gl/gl_context.c | 16 +--- ref_gl/gl_local.h | 7 +- ref_gl/gl_triapi.c | 115 ++++++++++++++++------ ref_gu/gu_backend.c | 10 ++ ref_gu/gu_context.c | 16 +--- ref_gu/gu_local.h | 12 +-- ref_gu/gu_triapi.c | 101 ++++++++++++++++++-- ref_soft/r_context.c | 21 ++-- ref_soft/r_local.h | 7 ++ ref_soft/r_triapi.c | 82 ++++++++++++++++ 22 files changed, 374 insertions(+), 362 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index c8397b7a..bd149096 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -94,6 +94,9 @@ static dllfunc_t cdll_new_exports[] = // allowed only in SDK 2.3 and higher { NULL, NULL } }; +// shared between client and server +triangleapi_t gTriApi; + static void pfnSPR_DrawHoles( int frame, int x, int y, const wrect_t *prc ); /* @@ -542,7 +545,7 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei // scale for screen sizes SPR_AdjustSize( &x, &y, &width, &height ); texnum = ref.dllFuncs.R_GetSpriteTexture( clgame.ds.pSprite, frame ); - ref.dllFuncs.Color4ub( clgame.ds.spriteColor[0], clgame.ds.spriteColor[1], clgame.ds.spriteColor[2], clgame.ds.spriteColor[3] ); + ref.dllFuncs.GL_SetColor4ub( clgame.ds.spriteColor[0], clgame.ds.spriteColor[1], clgame.ds.spriteColor[2], clgame.ds.spriteColor[3] ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, texnum ); } @@ -649,14 +652,14 @@ void CL_DrawScreenFade( void ) iFadeAlpha = bound( 0, iFadeAlpha, sf->fadealpha ); } - ref.dllFuncs.Color4ub( sf->fader, sf->fadeg, sf->fadeb, iFadeAlpha ); + ref.dllFuncs.GL_SetColor4ub( sf->fader, sf->fadeg, sf->fadeb, iFadeAlpha ); if( sf->fadeFlags & FFADE_MODULATE ) ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); else ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( 0, 0, refState.width, refState.height, 0, 0, 1, 1, R_GetBuiltinTexture( REF_WHITE_TEXTURE )); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } /* @@ -938,7 +941,7 @@ void CL_DrawCrosshair( void ) VectorAdd( refState.viewangles, cl.crosshairangle, angles ); AngleVectors( angles, forward, NULL, NULL ); VectorAdd( refState.vieworg, forward, point ); - ref.dllFuncs.WorldToScreen( point, screen ); + gTriApi.WorldToScreen( point, screen ); x += ( clgame.viewport[2] >> 1 ) * screen[0] + 0.5f; y += ( clgame.viewport[3] >> 1 ) * screen[1] + 0.5f; @@ -982,7 +985,7 @@ static void CL_DrawLoadingOrPaused( qboolean paused, float percent ) { float step, s2; - ref.dllFuncs.Color4ub( 128, 128, 128, 255 ); + ref.dllFuncs.GL_SetColor4ub( 128, 128, 128, 255 ); ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.loadingBar ); @@ -991,14 +994,14 @@ static void CL_DrawLoadingOrPaused( qboolean paused, float percent ) s2 = (float)right / width; width = right; - ref.dllFuncs.Color4ub( 208, 152, 0, 255 ); + ref.dllFuncs.GL_SetColor4ub( 208, 152, 0, 255 ); ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, s2, 1, cls.loadingBar ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } else { - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.loadingBar ); } @@ -1107,7 +1110,6 @@ void CL_ClearWorld( void ) world.max_recursion = 0; - clgame.ds.cullMode = TRI_FRONT; clgame.numStatics = 0; } @@ -3094,169 +3096,6 @@ char *pfnParseFile( char *data, char *token ) return out; } -/* -================= -TriAPI implementation - -================= -*/ -/* -================= -TriRenderMode -================= -*/ -void TriRenderMode( int mode ) -{ - clgame.ds.renderMode = mode; - ref.dllFuncs.TriRenderMode( mode ); -} - -/* -================= -TriColor4f -================= -*/ -void TriColor4f( float r, float g, float b, float a ) -{ - if( clgame.ds.renderMode == kRenderTransAlpha ) - ref.dllFuncs.Color4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); - else ref.dllFuncs.Color4f( r * a, g * a, b * a, 1.0 ); - - clgame.ds.triRGBA[0] = r; - clgame.ds.triRGBA[1] = g; - clgame.ds.triRGBA[2] = b; - clgame.ds.triRGBA[3] = a; -} - -/* -============= -TriColor4ub -============= -*/ -void TriColor4ub( byte r, byte g, byte b, byte a ) -{ - clgame.ds.triRGBA[0] = r * (1.0f / 255.0f); - clgame.ds.triRGBA[1] = g * (1.0f / 255.0f); - clgame.ds.triRGBA[2] = b * (1.0f / 255.0f); - clgame.ds.triRGBA[3] = a * (1.0f / 255.0f); - - ref.dllFuncs.Color4f( clgame.ds.triRGBA[0], clgame.ds.triRGBA[1], clgame.ds.triRGBA[2], 1.0f ); -} - -/* -============= -TriBrightness -============= -*/ -void TriBrightness( float brightness ) -{ - float r, g, b; - - r = clgame.ds.triRGBA[0] * clgame.ds.triRGBA[3] * brightness; - g = clgame.ds.triRGBA[1] * clgame.ds.triRGBA[3] * brightness; - b = clgame.ds.triRGBA[2] * clgame.ds.triRGBA[3] * brightness; - - ref.dllFuncs.Color4f( r, g, b, 1.0f ); -} - -/* -============= -TriCullFace -============= -*/ -void TriCullFace( TRICULLSTYLE style ) -{ - clgame.ds.cullMode = style; - ref.dllFuncs.CullFace( style ); -} - -/* -============= -TriWorldToScreen -convert world coordinates (x,y,z) into screen (x, y) -============= -*/ -int TriWorldToScreen( const float *world, float *screen ) -{ - int retval; - - retval = ref.dllFuncs.WorldToScreen( world, screen ); - - screen[0] = 0.5f * screen[0] * (float)clgame.viewport[2]; - screen[1] = -0.5f * screen[1] * (float)clgame.viewport[3]; - screen[0] += 0.5f * (float)clgame.viewport[2]; - screen[1] += 0.5f * (float)clgame.viewport[3]; - - return retval; -} - -/* -============= -TriBoxInPVS - -check box in pvs (absmin, absmax) -============= -*/ -int TriBoxInPVS( float *mins, float *maxs ) -{ - return Mod_BoxVisible( mins, maxs, ref.dllFuncs.Mod_GetCurrentVis( )); -} - -/* -============= -TriLightAtPoint -NOTE: dlights are ignored -============= -*/ -void TriLightAtPoint( float *pos, float *value ) -{ - colorVec vLightColor; - - if( !pos || !value ) return; - - vLightColor = ref.dllFuncs.R_LightPoint( pos ); - - value[0] = vLightColor.r; - value[1] = vLightColor.g; - value[2] = vLightColor.b; -} - -/* -============= -TriColor4fRendermode -Heavy legacy of Quake... -============= -*/ -void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ) -{ - if( clgame.ds.renderMode == kRenderTransAlpha ) - { - clgame.ds.triRGBA[3] = a / 255.0f; - ref.dllFuncs.Color4f( r, g, b, a ); - } - else ref.dllFuncs.Color4f( r * a, g * a, b * a, 1.0f ); -} - - -/* -============= -TriSpriteTexture - -bind current texture -============= -*/ -int TriSpriteTexture( model_t *pSpriteModel, int frame ) -{ - int gl_texturenum; - - if(( gl_texturenum = ref.dllFuncs.R_GetSpriteTexture( pSpriteModel, frame )) <= 0 ) - return 0; - - ref.dllFuncs.GL_Bind( XASH_TEXTURE0, gl_texturenum ); - - return 1; -} - /* ================= DemoApi implementation @@ -3616,9 +3455,6 @@ static void GAME_EXPORT VGui_ViewportPaintBackground( int extents[4] ) // stub } -// shared between client and server -triangleapi_t gTriApi; - static efx_api_t gEfxApi = { R_AllocParticle, diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index b5b70325..4453cfce 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -514,7 +514,7 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const PicAdjustSize( &x, &y, &width, &height ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, gameui.ds.gl_texturenum ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } /* @@ -592,7 +592,7 @@ void GAME_EXPORT pfnPIC_Set( HIMAGE hPic, int r, int g, int b, int a ) g = bound( 0, g, 255 ); b = bound( 0, b, 255 ); a = bound( 0, a, 255 ); - ref.dllFuncs.Color4ub( r, g, b, a ); + ref.dllFuncs.GL_SetColor4ub( r, g, b, a ); } /* @@ -691,10 +691,10 @@ static void GAME_EXPORT pfnFillRGBA( int x, int y, int width, int height, int r, g = bound( 0, g, 255 ); b = bound( 0, b, 255 ); a = bound( 0, a, 255 ); - ref.dllFuncs.Color4ub( r, g, b, a ); + ref.dllFuncs.GL_SetColor4ub( r, g, b, a ); ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, R_GetBuiltinTexture( REF_WHITE_TEXTURE ) ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } /* @@ -752,7 +752,7 @@ static void GAME_EXPORT pfnDrawCharacter( int ix, int iy, int iwidth, int iheigh color[0] = (ulRGBA & 0xFF0000) >> 16; color[1] = (ulRGBA & 0xFF00) >> 8; color[2] = (ulRGBA & 0xFF) >> 0; - ref.dllFuncs.Color4ub( color[0], color[1], color[2], color[3] ); + ref.dllFuncs.GL_SetColor4ub( color[0], color[1], color[2], color[3] ); col = (ch & 15) * 0.0625f + (0.5f / 256.0f); row = (ch >> 4) * 0.0625f + (0.5f / 256.0f); @@ -769,7 +769,7 @@ static void GAME_EXPORT pfnDrawCharacter( int ix, int iy, int iwidth, int iheigh ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, hFont ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } /* diff --git a/engine/client/cl_netgraph.c b/engine/client/cl_netgraph.c index 3aa51ce0..945d7301 100644 --- a/engine/client/cl_netgraph.c +++ b/engine/client/cl_netgraph.c @@ -80,12 +80,12 @@ NetGraph_FillRGBA shortcut */ static void NetGraph_DrawRect( wrect_t *rect, byte colors[4] ) { - ref.dllFuncs.Color4ub( colors[0], colors[1], colors[2], colors[3] ); // color for this quad + gTriApi.Color4ub( colors[0], colors[1], colors[2], colors[3] ); // color for this quad - ref.dllFuncs.Vertex3f( rect->left, rect->top, 0 ); - ref.dllFuncs.Vertex3f( rect->left + rect->right, rect->top, 0 ); - ref.dllFuncs.Vertex3f( rect->left + rect->right, rect->top + rect->bottom, 0 ); - ref.dllFuncs.Vertex3f( rect->left, rect->top + rect->bottom, 0 ); + gTriApi.Vertex3f( rect->left, rect->top, 0 ); + gTriApi.Vertex3f( rect->left + rect->right, rect->top, 0 ); + gTriApi.Vertex3f( rect->left + rect->right, rect->top + rect->bottom, 0 ); + gTriApi.Vertex3f( rect->left, rect->top + rect->bottom, 0 ); } /* @@ -657,17 +657,17 @@ void SCR_DrawNetGraph( void ) if( net_graph->value < 3 ) { - ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); + gTriApi.RenderMode( kRenderTransAdd ); - ref.dllFuncs.Begin( TRI_QUADS ); // draw all the fills as a long solid sequence of quads for speedup reasons + gTriApi.Begin( TRI_QUADS ); // draw all the fills as a long solid sequence of quads for speedup reasons // NOTE: fill colors without texture at this point NetGraph_DrawDataUsage( x, y, w ); NetGraph_DrawTimes( rect, x, w ); - ref.dllFuncs.End(); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); - ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); + gTriApi.End(); + gTriApi.Color4ub( 255, 255, 255, 255 ); + gTriApi.RenderMode( kRenderNormal ); } } diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 4c6c03af..ef1daece 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -393,7 +393,7 @@ int CL_TempEntAddEntity( cl_entity_t *pEntity ) VectorAdd( pEntity->origin, pEntity->model->maxs, maxs ); // g-cont. just use PVS from previous frame - if( TriBoxInPVS( mins, maxs )) + if( Mod_BoxVisible( mins, maxs, ref.dllFuncs.Mod_GetCurrentVis( ))) { VectorCopy( pEntity->angles, pEntity->curstate.angles ); VectorCopy( pEntity->origin, pEntity->curstate.origin ); diff --git a/engine/client/cl_tent.h b/engine/client/cl_tent.h index 1cae7155..0e088ae5 100644 --- a/engine/client/cl_tent.h +++ b/engine/client/cl_tent.h @@ -102,19 +102,6 @@ struct beam_s *R_BeamRing( int startEnt, int endEnt, int modelIndex, float life, struct beam_s *R_BeamFollow( int startEnt, int modelIndex, float life, float width, float r, float g, float b, float brightness ); void R_BeamKill( int deadEntity ); - -// TriAPI -void TriRenderMode( int mode ); -void TriColor4f( float r, float g, float b, float a ); -void TriColor4ub( byte r, byte g, byte b, byte a ); -void TriBrightness( float brightness ); -void TriCullFace( TRICULLSTYLE mode ); -int TriWorldToScreen( const float *world, float *screen ); -int TriBoxInPVS( float *mins, float *maxs ); -void TriLightAtPoint( float *pos, float *value ); -void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ); -int TriSpriteTexture( model_t *pSpriteModel, int frame ); - extern model_t *cl_sprite_dot; extern model_t *cl_sprite_shell; diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index 050bdaaf..00759ec8 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -360,10 +360,10 @@ void R_DrawLeafNode( float x, float y, float scale ) void R_DrawNodeConnection( float x, float y, float x2, float y2 ) { - ref.dllFuncs.Begin( TRI_LINES ); - ref.dllFuncs.Vertex3f( x, y, 0 ); - ref.dllFuncs.Vertex3f( x2, y2, 0 ); - ref.dllFuncs.End( ); + gTriApi.Begin( TRI_LINES ); + gTriApi.Vertex3f( x, y, 0 ); + gTriApi.Vertex3f( x2, y2, 0 ); + gTriApi.End( ); } void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes, mleaf_t *viewleaf ) @@ -386,10 +386,10 @@ void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes, if( shownodes == 1 ) { if( cl.worldmodel->leafs == leaf ) - ref.dllFuncs.Color4f( 1.0f, 1.0f, 1.0f, 1.0f ); + gTriApi.Color4f( 1.0f, 1.0f, 1.0f, 1.0f ); else if( viewleaf && viewleaf == leaf ) - ref.dllFuncs.Color4f( 1.0f, 0.0f, 0.0f, 1.0f ); - else ref.dllFuncs.Color4f( 0.0f, 1.0f, 0.0f, 1.0f ); + gTriApi.Color4f( 1.0f, 0.0f, 0.0f, 1.0f ); + else gTriApi.Color4f( 0.0f, 1.0f, 0.0f, 1.0f ); R_DrawLeafNode( x, y, scale ); } world.recursion_level--; @@ -398,7 +398,7 @@ void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes, if( shownodes == 1 ) { - ref.dllFuncs.Color4f( 0.0f, 0.0f, 1.0f, 1.0f ); + gTriApi.Color4f( 0.0f, 0.0f, 1.0f, 1.0f ); R_DrawLeafNode( x, y, scale ); } else if( shownodes == 2 ) @@ -430,7 +430,7 @@ void R_ShowTree( void ) //pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); //pglLineWidth( 2.0f ); - ref.dllFuncs.Color4f( 1, 0.7f, 0, 1.0f ); + gTriApi.Color4f( 1, 0.7f, 0, 1.0f ); //pglDisable( GL_TEXTURE_2D ); R_ShowTree_r( cl.worldmodel->nodes, x, y, world.max_recursion * 3.5f, 2, viewleaf ); //pglEnable( GL_TEXTURE_2D ); diff --git a/engine/client/client.h b/engine/client/client.h index b8bb14a6..5e8e11d1 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -344,13 +344,9 @@ typedef struct qboolean scissor_test; qboolean adjust_size; // allow to adjust scale for fonts - int renderMode; // override kRenderMode from TriAPI - TRICULLSTYLE cullMode; // override CULL FACE from TriAPI - // holds text color rgba_t textColor; rgba_t spriteColor; - vec4_t triRGBA; // crosshair members const model_t *pCrosshair; @@ -1149,5 +1145,6 @@ int Key_ToUpper( int key ); void OSK_Draw( void ); extern rgba_t g_color_table[8]; +extern triangleapi_t gTriApi; #endif//CLIENT_H diff --git a/engine/client/console.c b/engine/client/console.c index bafbcfb6..600586ee 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -908,8 +908,8 @@ static int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) // don't apply color to fixed fonts it's already colored if( con.curFont->type != FONT_FIXED || REF_GET_PARM( PARM_TEX_GLFORMAT, con.curFont->hFontTexture ) == 0x8045 ) // GL_LUMINANCE8_ALPHA8 - ref.dllFuncs.Color4ub( color[0], color[1], color[2], color[3] ); - else ref.dllFuncs.Color4ub( 255, 255, 255, color[3] ); + ref.dllFuncs.GL_SetColor4ub( color[0], color[1], color[2], color[3] ); + else ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, color[3] ); // calc rectangle s1 = (float)rc->left / width; @@ -922,7 +922,7 @@ static int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) if( clgame.ds.adjust_size ) Con_TextAdjustSize( &x, &y, &width, &height ); ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, con.curFont->hFontTexture ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); // don't forget reset color + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); // don't forget reset color return con.curFont->charWidths[number]; } @@ -1083,7 +1083,7 @@ int Con_DrawGenericString( int x, int y, const char *string, rgba_t setColor, qb s++; } - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); return drawLen; } @@ -2039,7 +2039,7 @@ void Con_DrawNotify( void ) Field_DrawInputLine( x + len, y, &con.chat ); } - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } /* @@ -2112,7 +2112,7 @@ void Con_DrawSolidConsole( int lines ) // draw the background ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); // to prevent grab color from screenfade + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); // to prevent grab color from screenfade if( refState.width * 3 / 4 < refState.height && lines >= refState.height ) ref.dllFuncs.R_DrawStretchPic( 0, lines - refState.height, refState.width, refState.height - refState.width * 3 / 4, 0, 0, 1, 1, R_GetBuiltinTexture( REF_BLACK_TEXTURE) ); ref.dllFuncs.R_DrawStretchPic( 0, lines - refState.width * 3 / 4, refState.width, refState.width * 3 / 4, 0, 0, 1, 1, con.background ); @@ -2180,7 +2180,7 @@ void Con_DrawSolidConsole( int lines ) y = lines - ( con.curFont->charHeight * 1.2f ); SCR_DrawFPS( max( y, 4 )); // to avoid to hide fps counter - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } /* diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c index cf754f87..31f0d779 100644 --- a/engine/client/in_touch.c +++ b/engine/client/in_touch.c @@ -1071,7 +1071,7 @@ void Touch_DrawTexture ( float x1, float y1, float x2, float y2, int texture, by if( y1 >= y2 ) return; - ref.dllFuncs.Color4ub( r, g, b, a ); + ref.dllFuncs.GL_SetColor4ub( r, g, b, a ); ref.dllFuncs.R_DrawStretchPic( TO_SCRN_X(x1), TO_SCRN_Y(y1), TO_SCRN_X(x2 - x1), @@ -1154,7 +1154,7 @@ float Touch_DrawText( float x1, float y1, float x2, float y2, const char *s, byt ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); // text is additive and alpha does not work - ref.dllFuncs.Color4ub( color[0] * ( (float)color[3] /255.0f ), color[1] * ( (float)color[3] /255.0f ), + ref.dllFuncs.GL_SetColor4ub( color[0] * ( (float)color[3] /255.0f ), color[1] * ( (float)color[3] /255.0f ), color[2] * ( (float)color[3] /255.0f ), 255 ); while( *s ) @@ -1223,7 +1223,7 @@ void Touch_DrawButtons( touchbuttonlist_t *list ) } if( B(flags) & TOUCH_FL_STROKE ) { - ref.dllFuncs.Color4ub( touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] * B( fade ) ); + ref.dllFuncs.GL_SetColor4ub( touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] * B( fade ) ); ref.dllFuncs.R_DrawStretchPic( TO_SCRN_X(B(x1)), TO_SCRN_Y(B(y1)), touch.swidth, @@ -1244,7 +1244,7 @@ void Touch_DrawButtons( touchbuttonlist_t *list ) TO_SCRN_X(B(x2)-B(x1)) - touch.swidth, touch.swidth, 0, 0, 1, 1, touch.whitetexture ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); } } if( touch.state >= state_edit && !( button->flags & TOUCH_FL_NOEDIT ) ) @@ -1282,7 +1282,7 @@ void Touch_Draw( void ) Touch_DrawTexture( 0, 0, 1, 1, touch.whitetexture, 32, 32, 32, 255 ); else Touch_DrawTexture( 0, 0, 1, 1, touch.whitetexture, 0, 0, 0, 112 ); - ref.dllFuncs.Color4ub( 0, 224, 224, 112 ); + ref.dllFuncs.GL_SetColor4ub( 0, 224, 224, 112 ); for ( x = 0; x < 1 ; x += GRID_X ) ref.dllFuncs.R_DrawStretchPic( TO_SCRN_X(x), 0, @@ -1337,7 +1337,7 @@ void Touch_Draw( void ) } } - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); if( ( touch.move_finger != -1 ) && touch.move_button && touch_move_indicator->value ) { @@ -1358,11 +1358,11 @@ void Touch_Draw( void ) width = (touch.move_button->x2 - touch.move_button->x1)/2; height = (touch.move_button->y2 - touch.move_button->y1)/2; } - ref.dllFuncs.Color4ub( 255, 255, 255, 128 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 128 ); ref.dllFuncs.R_DrawStretchPic( TO_SCRN_X( touch.move_start_x - GRID_X * touch_move_indicator->value ), TO_SCRN_Y( touch.move_start_y - GRID_Y * touch_move_indicator->value ), TO_SCRN_X( GRID_X * 2 * touch_move_indicator->value ), TO_SCRN_Y( GRID_Y * 2 * touch_move_indicator->value ), 0, 0, 1, 1, touch.joytexture ); - ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetColor4ub( 255, 255, 255, 255 ); ref.dllFuncs.R_DrawStretchPic( TO_SCRN_X( touch.move_start_x + touch.side * width - GRID_X * touch_move_indicator->value ), TO_SCRN_Y( touch.move_start_y - touch.forward * height - GRID_Y * touch_move_indicator->value ), TO_SCRN_X( GRID_X * 2 * touch_move_indicator->value ), TO_SCRN_Y( GRID_Y * 2 * touch_move_indicator->value ), 0, 0, 1, 1, touch.joytexture ); diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 8e4aaf81..1e86134c 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -418,33 +418,8 @@ static void R_UnloadProgs( void ) Cmd_Unlink( CMD_REFDLL ); } -static void CL_FillTriAPIFromRef( triangleapi_t *dst, const ref_interface_t *src ) -{ - dst->version = TRI_API_VERSION; - dst->Begin = src->Begin; - dst->RenderMode = TriRenderMode; - dst->End = src->End; - dst->Color4f = TriColor4f; - dst->Color4ub = TriColor4ub; - dst->TexCoord2f = src->TexCoord2f; - dst->Vertex3f = src->Vertex3f; - dst->Vertex3fv = src->Vertex3fv; - dst->Brightness = TriBrightness; - dst->CullFace = TriCullFace; - dst->SpriteTexture = TriSpriteTexture; - dst->WorldToScreen = TriWorldToScreen; - dst->Fog = src->Fog; - dst->ScreenToWorld = src->ScreenToWorld; - dst->GetMatrix = src->GetMatrix; - dst->BoxInPVS = TriBoxInPVS; - dst->LightAtPoint = TriLightAtPoint; - dst->Color4fRendermode = TriColor4fRendermode; - dst->FogParams = src->FogParams; -} - static qboolean R_LoadProgs( const char *name ) { - extern triangleapi_t gTriApi; static ref_api_t gpEngfuncs; REFAPI GetRefAPI; // single export @@ -489,12 +464,18 @@ static qboolean R_LoadProgs( const char *name ) return false; } + // initialize TriAPI callbacks + if( !ref.dllFuncs.getTriAPI( TRI_API_VERSION, &gTriApi )) + { + COM_FreeLibrary( ref.hInstance ); + Con_Reportf( "R_LoadProgs: can't init TriAPI Interface: wrong version, %i must be %i\n", gTriApi.version, TRI_API_VERSION ); + ref.hInstance = NULL; + return false; + } + Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY ); ref.initialized = true; - // initialize TriAPI callbacks - CL_FillTriAPIFromRef( &gTriApi, &ref.dllFuncs ); - return true; } diff --git a/engine/ref_api.h b/engine/ref_api.h index 6abbf799..efc1843e 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -465,6 +465,7 @@ typedef struct ref_interface_s void (*R_ClearScreen)( void ); // clears color buffer on GL void (*R_AllowFog)( qboolean allow ); void (*GL_SetRenderMode)( int renderMode ); + void (*GL_SetColor4ub)( byte r, byte g, byte b, byte a ); qboolean (*R_AddEntity)( struct cl_entity_s *clent, int type ); void (*CL_AddCustomBeam)( cl_entity_t *pEnvBeam ); @@ -592,20 +593,7 @@ typedef struct ref_interface_s // TriAPI Interface // NOTE: implementation isn't required to be compatible - void (*TriRenderMode)( int mode ); - void (*Begin)( int primitiveCode ); - void (*End)( void ); - void (*Color4f)( float r, float g, float b, float a ); // real glColor4f - void (*Color4ub)( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); // real glColor4ub - void (*TexCoord2f)( float u, float v ); - void (*Vertex3fv)( const float *worldPnt ); - void (*Vertex3f)( float x, float y, float z ); - int (*WorldToScreen)( const float *world, float *screen ); // Returns 1 if it's z clipped - void (*Fog)( float flFogColor[3], float flStart, float flEnd, int bOn ); //Works just like GL_FOG, flFogColor is r/g/b. - void (*ScreenToWorld)( const float *screen, float *world ); - void (*GetMatrix)( const int pname, float *matrix ); - void (*FogParams)( float flDensity, int iFogSkybox ); - void (*CullFace)( TRICULLSTYLE mode ); + int (*getTriAPI)( int version, triangleapi_t *api ); // vgui drawing implementation void (*VGUI_DrawInit)( void ); diff --git a/ref_gl/gl_backend.c b/ref_gl/gl_backend.c index 297f7ca4..a3035590 100644 --- a/ref_gl/gl_backend.c +++ b/ref_gl/gl_backend.c @@ -420,6 +420,16 @@ void GL_SetRenderMode( int mode ) } } +/* +================= +GL_SetColor4ub +================= +*/ +void GL_SetColor4ub( byte r, byte g, byte b, byte a ) +{ + pglColor4ub( r, g, b, a ); +} + /* ============================================================================== diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c index 19cec68e..251827ff 100644 --- a/ref_gl/gl_context.c +++ b/ref_gl/gl_context.c @@ -371,6 +371,7 @@ ref_interface_t gReffuncs = R_ClearScreen, R_AllowFog, GL_SetRenderMode, + GL_SetColor4ub, R_AddEntity, CL_AddCustomBeam, @@ -467,20 +468,7 @@ ref_interface_t gReffuncs = R_ClearScene, R_GetProcAddress, - TriRenderMode, - TriBegin, - TriEnd, - _TriColor4f, - _TriColor4ub, - TriTexCoord2f, - TriVertex3fv, - TriVertex3f, - TriWorldToScreen, - TriFog, - R_ScreenToWorld, - TriGetMatrix, - TriFogParams, - TriCullFace, + getTriAPI, VGUI_DrawInit, VGUI_DrawShutdown, diff --git a/ref_gl/gl_local.h b/ref_gl/gl_local.h index 7f80268a..17efaff7 100644 --- a/ref_gl/gl_local.h +++ b/ref_gl/gl_local.h @@ -291,6 +291,7 @@ void GL_CleanupAllTextureUnits( void ); void GL_LoadIdentityTexMatrix( void ); void GL_DisableAllTexGens( void ); void GL_SetRenderMode( int mode ); +void GL_SetColor4ub( byte r, byte g, byte b, byte a ); void GL_TextureTarget( uint target ); void GL_Cull( GLenum cull ); void R_ShowTextures( void ); @@ -574,8 +575,6 @@ void TriEnd( void ); void TriTexCoord2f( float u, float v ); void TriVertex3fv( const float *v ); void TriVertex3f( float x, float y, float z ); -void _TriColor4f( float r, float g, float b, float a ); -void _TriColor4ub( byte r, byte g, byte b, byte a ); void TriColor4f( float r, float g, float b, float a ); void TriColor4ub( byte r, byte g, byte b, byte a ); void TriBrightness( float brightness ); @@ -585,6 +584,10 @@ void TriFog( float flFogColor[3], float flStart, float flEnd, int bOn ); void TriGetMatrix( const int pname, float *matrix ); void TriFogParams( float flDensity, int iFogSkybox ); void TriCullFace( TRICULLSTYLE mode ); +int TriBoxInPVS( float *mins, float *maxs ); +void TriLightAtPoint( float *pos, float *value ); +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ); +int getTriAPI( int version, triangleapi_t *api ); /* ======================================================================= diff --git a/ref_gl/gl_triapi.c b/ref_gl/gl_triapi.c index 4d4bffce..2e19c38b 100644 --- a/ref_gl/gl_triapi.c +++ b/ref_gl/gl_triapi.c @@ -120,29 +120,6 @@ void TriEnd( void ) pglEnd( ); } -/* -============= -_TriColor4f - -============= -*/ -void _TriColor4f( float r, float g, float b, float a ) -{ - pglColor4f( r, g, b, a ); -} - -/* -============= -_TriColor4f - -============= -*/ -void _TriColor4ub( byte r, byte g, byte b, byte a ) -{ - pglColor4ub( r, g, b, a ); -} - - /* ============= TriColor4ub @@ -156,7 +133,7 @@ void TriColor4ub( byte r, byte g, byte b, byte a ) ds.triRGBA[2] = b * (1.0f / 255.0f); ds.triRGBA[3] = a * (1.0f / 255.0f); - _TriColor4f( ds.triRGBA[0], ds.triRGBA[1], ds.triRGBA[2], 1.0f ); + pglColor4f( ds.triRGBA[0], ds.triRGBA[1], ds.triRGBA[2], 1.0f ); } /* @@ -167,8 +144,8 @@ TriColor4f void TriColor4f( float r, float g, float b, float a ) { if( ds.renderMode == kRenderTransAlpha ) - TriColor4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); - else _TriColor4f( r * a, g * a, b * a, 1.0 ); + pglColor4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); + else pglColor4f( r * a, g * a, b * a, 1.0 ); ds.triRGBA[0] = r; ds.triRGBA[1] = g; @@ -338,7 +315,7 @@ void TriCullFace( TRICULLSTYLE mode ) break; } - GL_Cull( mode ); + GL_Cull( glMode ); } /* @@ -354,6 +331,88 @@ void TriBrightness( float brightness ) g = ds.triRGBA[1] * ds.triRGBA[3] * brightness; b = ds.triRGBA[2] * ds.triRGBA[3] * brightness; - _TriColor4f( r, g, b, 1.0f ); + pglColor4f( r, g, b, 1.0f ); } +/* +============= +TriBoxInPVS + +check box in pvs (absmin, absmax) +============= +*/ +int TriBoxInPVS( float *mins, float *maxs ) +{ + return gEngfuncs.Mod_BoxVisible( mins, maxs, Mod_GetCurrentVis( )); +} + +/* +============= +TriLightAtPoint +NOTE: dlights are ignored +============= +*/ +void TriLightAtPoint( float *pos, float *value ) +{ + colorVec vLightColor; + + if( !pos || !value ) return; + + vLightColor = R_LightPoint( pos ); + + value[0] = vLightColor.r; + value[1] = vLightColor.g; + value[2] = vLightColor.b; +} + +/* +============= +TriColor4fRendermode +Heavy legacy of Quake... +============= +*/ +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ) +{ + if( ds.renderMode == kRenderTransAlpha ) + { + ds.triRGBA[3] = a / 255.0f; + pglColor4f( r, g, b, a ); + } + else pglColor4f( r * a, g * a, b * a, 1.0f ); +} + +/* +============= +getTriAPI +export +============= +*/ +int getTriAPI( int version, triangleapi_t *api ) +{ + api->version = TRI_API_VERSION; + + if( version != TRI_API_VERSION ) + return 0; + + api->RenderMode = TriRenderMode; + api->Begin = TriBegin; + api->End = TriEnd; + api->Color4f = TriColor4f; + api->Color4ub = TriColor4ub; + api->TexCoord2f = TriTexCoord2f; + api->Vertex3fv = TriVertex3fv; + api->Vertex3f = TriVertex3f; + api->Brightness = TriBrightness; + api->CullFace = TriCullFace; + api->SpriteTexture = TriSpriteTexture; + api->WorldToScreen = R_WorldToScreen; + api->Fog = TriFog; + api->ScreenToWorld = R_ScreenToWorld; + api->GetMatrix = TriGetMatrix; + api->BoxInPVS = TriBoxInPVS; + api->LightAtPoint = TriLightAtPoint; + api->Color4fRendermode = TriColor4fRendermode; + api->FogParams = TriFogParams; + + return 1; +} diff --git a/ref_gu/gu_backend.c b/ref_gu/gu_backend.c index 88c0ed2f..e6ca717e 100644 --- a/ref_gu/gu_backend.c +++ b/ref_gu/gu_backend.c @@ -309,6 +309,16 @@ void GL_SetRenderMode( int mode ) } } +/* +================= +GL_SetColor4ub +================= +*/ +void GL_SetColor4ub( byte r, byte g, byte b, byte a ) +{ + sceGuColor( GU_RGBA( r, g, b, a )); +} + /* ============================================================================== diff --git a/ref_gu/gu_context.c b/ref_gu/gu_context.c index 0e0e8e2d..3118ceae 100644 --- a/ref_gu/gu_context.c +++ b/ref_gu/gu_context.c @@ -370,6 +370,7 @@ ref_interface_t gReffuncs = R_ClearScreen, R_AllowFog, GL_SetRenderMode, + GL_SetColor4ub, R_AddEntity, CL_AddCustomBeam, @@ -466,20 +467,7 @@ ref_interface_t gReffuncs = R_ClearScene, R_GetProcAddress, - TriRenderMode, - TriBegin, - TriEnd, - _TriColor4f, - _TriColor4ub, - TriTexCoord2f, - TriVertex3fv, - TriVertex3f, - TriWorldToScreen, - TriFog, - R_ScreenToWorld, - TriGetMatrix, - TriFogParams, - TriCullFace, + getTriAPI, VGUI_DrawInit, VGUI_DrawShutdown, diff --git a/ref_gu/gu_local.h b/ref_gu/gu_local.h index cdba1474..c637c5ef 100644 --- a/ref_gu/gu_local.h +++ b/ref_gu/gu_local.h @@ -643,6 +643,7 @@ void Mod_SpriteUnloadTextures( void *data ); void Mod_UnloadAliasModel( struct model_s *mod ); void Mod_AliasUnloadTextures( void *data ); void GL_SetRenderMode( int mode ); +void GL_SetColor4ub( byte r, byte g, byte b, byte a ); void R_RunViewmodelEvents( void ); void R_DrawViewModel( void ); int R_GetSpriteTexture( const struct model_s *m_pSpriteModel, int frame ); @@ -670,8 +671,6 @@ void TriEnd( void ); void TriTexCoord2f( float u, float v ); void TriVertex3fv( const float *v ); void TriVertex3f( float x, float y, float z ); -void _TriColor4f( float r, float g, float b, float a ); -void _TriColor4ub( byte r, byte g, byte b, byte a ); void TriColor4f( float r, float g, float b, float a ); void TriColor4ub( byte r, byte g, byte b, byte a ); void TriBrightness( float brightness ); @@ -681,10 +680,11 @@ void TriFog( float flFogColor[3], float flStart, float flEnd, int bOn ); void TriGetMatrix( const int pname, float *matrix ); void TriFogParams( float flDensity, int iFogSkybox ); void TriCullFace( TRICULLSTYLE mode ); -#if 1 -/* Needs for psp */ -unsigned int getTriBrightness( float brightness ); -#endif +uint getTriBrightness( float brightness ); +int TriBoxInPVS( float *mins, float *maxs ); +void TriLightAtPoint( float *pos, float *value ); +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ); +int getTriAPI( int version, triangleapi_t *api ); // // gu_clipping.c diff --git a/ref_gu/gu_triapi.c b/ref_gu/gu_triapi.c index 9cf25f76..64efe935 100644 --- a/ref_gu/gu_triapi.c +++ b/ref_gu/gu_triapi.c @@ -28,8 +28,8 @@ static struct { byte *start; byte *end; - int count; - int prim; + int count; + int prim; uint flags; float lastTexCord[2]; uint lastColor; @@ -150,7 +150,7 @@ _TriColor4f ============= */ -void _TriColor4f( float r, float g, float b, float a ) +static void _TriColor4f( float r, float g, float b, float a ) { if( triContext.start ) { @@ -169,7 +169,7 @@ _TriColor4ub ============= */ -void _TriColor4ub( byte r, byte g, byte b, byte a ) +static void _TriColor4ub( byte r, byte g, byte b, byte a ) { if( triContext.start ) { @@ -196,7 +196,7 @@ void TriColor4ub( byte r, byte g, byte b, byte a ) ds.triRGBA[2] = b * (1.0f / 255.0f); ds.triRGBA[3] = a * (1.0f / 255.0f); - _TriColor4f( ds.triRGBA[0], ds.triRGBA[1], ds.triRGBA[2], 1.0f ); + _TriColor4ub( r, g, b, 255 ); } /* @@ -207,7 +207,7 @@ TriColor4f void TriColor4f( float r, float g, float b, float a ) { if( ds.renderMode == kRenderTransAlpha ) - TriColor4ub( r * 255.0f, g * 255.0f, b * 255.0f, a * 255.0f ); + _TriColor4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); else _TriColor4f( r * a, g * a, b * a, 1.0 ); ds.triRGBA[0] = r; @@ -460,7 +460,7 @@ void TriCullFace( TRICULLSTYLE mode ) break; } - GL_Cull( mode ); + GL_Cull( glMode ); } /* @@ -483,13 +483,96 @@ unsigned int getTriBrightness( float brightness ) { vec3_t color; - if(brightness < 0.0f) return 0; + if( brightness < 0.0f ) return 0; color[0] = ds.triRGBA[0] * ds.triRGBA[3] * brightness; color[1] = ds.triRGBA[1] * ds.triRGBA[3] * brightness; color[2] = ds.triRGBA[2] * ds.triRGBA[3] * brightness; - VectorNormalizeFast( color ); + //VectorNormalizeFast( color ); return GUCOLOR3FV( color ); } + +/* +============= +TriBoxInPVS + +check box in pvs (absmin, absmax) +============= +*/ +int TriBoxInPVS( float *mins, float *maxs ) +{ + return gEngfuncs.Mod_BoxVisible( mins, maxs, Mod_GetCurrentVis( )); +} + +/* +============= +TriLightAtPoint +NOTE: dlights are ignored +============= +*/ +void TriLightAtPoint( float *pos, float *value ) +{ + colorVec vLightColor; + + if( !pos || !value ) return; + + vLightColor = R_LightPoint( pos ); + + value[0] = vLightColor.r; + value[1] = vLightColor.g; + value[2] = vLightColor.b; +} + +/* +============= +TriColor4fRendermode +Heavy legacy of Quake... +============= +*/ +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ) +{ + if( ds.renderMode == kRenderTransAlpha ) + { + ds.triRGBA[3] = a / 255.0f; + _TriColor4f( r, g, b, a ); + } + else _TriColor4f( r * a, g * a, b * a, 1.0f ); +} + +/* +============= +getTriAPI +export +============= +*/ +int getTriAPI( int version, triangleapi_t *api ) +{ + api->version = TRI_API_VERSION; + + if( version != TRI_API_VERSION ) + return 0; + + api->RenderMode = TriRenderMode; + api->Begin = TriBegin; + api->End = TriEnd; + api->Color4f = TriColor4f; + api->Color4ub = TriColor4ub; + api->TexCoord2f = TriTexCoord2f; + api->Vertex3fv = TriVertex3fv; + api->Vertex3f = TriVertex3f; + api->Brightness = TriBrightness; + api->CullFace = TriCullFace; + api->SpriteTexture = TriSpriteTexture; + api->WorldToScreen = R_WorldToScreen; + api->Fog = TriFog; + api->ScreenToWorld = R_ScreenToWorld; + api->GetMatrix = TriGetMatrix; + api->BoxInPVS = TriBoxInPVS; + api->LightAtPoint = TriLightAtPoint; + api->Color4fRendermode = TriColor4fRendermode; + api->FogParams = TriFogParams; + + return 1; +} diff --git a/ref_soft/r_context.c b/ref_soft/r_context.c index e0b1e6a9..2209dd2a 100644 --- a/ref_soft/r_context.c +++ b/ref_soft/r_context.c @@ -329,6 +329,11 @@ void GAME_EXPORT GL_SetRenderMode(int mode) /// maybe, setup block drawing function pointers here } +void GAME_EXPORT GL_SetColor4ub( byte r, byte g, byte b, byte a ) +{ + _TriColor4ub(r,g,b,a); +} + void GAME_EXPORT R_ShowTextures( void ) { // textures undone too @@ -452,6 +457,7 @@ ref_interface_t gReffuncs = R_ClearScreen, R_AllowFog, GL_SetRenderMode, + GL_SetColor4ub, R_AddEntity, CL_AddCustomBeam, @@ -548,20 +554,7 @@ ref_interface_t gReffuncs = R_ClearScene, R_GetProcAddress, - TriRenderMode, - TriBegin, - TriEnd, - _TriColor4f, - _TriColor4ub, - TriTexCoord2f, - TriVertex3fv, - TriVertex3f, - TriWorldToScreen, - TriFog, - R_ScreenToWorld, - TriGetMatrix, - TriFogParams, - TriCullFace, + getTriAPI, VGUI_DrawInit, VGUI_DrawShutdown, diff --git a/ref_soft/r_local.h b/ref_soft/r_local.h index 99cb2635..487dc49b 100644 --- a/ref_soft/r_local.h +++ b/ref_soft/r_local.h @@ -387,6 +387,7 @@ void GL_CleanupAllTextureUnits( void ); void GL_LoadIdentityTexMatrix( void ); void GL_DisableAllTexGens( void ); void GL_SetRenderMode( int mode ); +void GL_SetColor4ub( byte r, byte g, byte b, byte a ); void GL_TextureTarget( uint target ); void GL_Cull( unsigned int cull ); void R_ShowTextures( void ); @@ -640,6 +641,7 @@ void Mod_SpriteUnloadTextures( void *data ); void Mod_UnloadAliasModel( struct model_s *mod ); void Mod_AliasUnloadTextures( void *data ); void GL_SetRenderMode( int mode ); +void GL_SetColor4ub( byte r, byte g, byte b, byte a ); void R_RunViewmodelEvents( void ); void R_DrawViewModel( void ); int R_GetSpriteTexture( const struct model_s *m_pSpriteModel, int frame ); @@ -674,6 +676,7 @@ void TriEnd( void ); void TriTexCoord2f( float u, float v ); void TriVertex3fv( const float *v ); void TriVertex3f( float x, float y, float z ); +void TriColor4f( float r, float g, float b, float a ); void _TriColor4f( float r, float g, float b, float a ); void TriColor4ub( byte r, byte g, byte b, byte a ); void _TriColor4ub( byte r, byte g, byte b, byte a ); @@ -684,6 +687,10 @@ void TriGetMatrix( const int pname, float *matrix ); void TriFogParams( float flDensity, int iFogSkybox ); void TriCullFace( TRICULLSTYLE mode ); void TriBrightness( float brightness ); +int TriBoxInPVS( float *mins, float *maxs ); +void TriLightAtPoint( float *pos, float *value ); +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ); +int getTriAPI( int version, triangleapi_t *api ); #define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) #define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( (parm), 0 ) diff --git a/ref_soft/r_triapi.c b/ref_soft/r_triapi.c index c98f717c..93b4ddf0 100644 --- a/ref_soft/r_triapi.c +++ b/ref_soft/r_triapi.c @@ -503,3 +503,85 @@ void TriBrightness( float brightness ) _TriColor4f( r, g, b, 1.0f ); } +/* +============= +TriBoxInPVS + +check box in pvs (absmin, absmax) +============= +*/ +int TriBoxInPVS( float *mins, float *maxs ) +{ + return gEngfuncs.Mod_BoxVisible( mins, maxs, Mod_GetCurrentVis( )); +} + +/* +============= +TriLightAtPoint +NOTE: dlights are ignored +============= +*/ +void TriLightAtPoint( float *pos, float *value ) +{ + colorVec vLightColor; + + if( !pos || !value ) return; + + vLightColor = R_LightPoint( pos ); + + value[0] = vLightColor.r; + value[1] = vLightColor.g; + value[2] = vLightColor.b; +} + +/* +============= +TriColor4fRendermode +Heavy legacy of Quake... +============= +*/ +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ) +{ + if( ds.renderMode == kRenderTransAlpha ) + { + ds.triRGBA[3] = a / 255.0f; + _TriColor4f( r, g, b, a ); + } + else _TriColor4f( r * a, g * a, b * a, 1.0f ); +} + +/* +============= +getTriAPI +export +============= +*/ +int getTriAPI( int version, triangleapi_t *api ) +{ + api->version = TRI_API_VERSION; + + if( version != TRI_API_VERSION ) + return 0; + + api->RenderMode = TriRenderMode; + api->Begin = TriBegin; + api->End = TriEnd; + api->Color4f = TriColor4f; + api->Color4ub = TriColor4ub; + api->TexCoord2f = TriTexCoord2f; + api->Vertex3fv = TriVertex3fv; + api->Vertex3f = TriVertex3f; + api->Brightness = TriBrightness; + api->CullFace = TriCullFace; + api->SpriteTexture = TriSpriteTexture; + api->WorldToScreen = R_WorldToScreen; + api->Fog = TriFog; + api->ScreenToWorld = R_ScreenToWorld; + api->GetMatrix = TriGetMatrix; + api->BoxInPVS = TriBoxInPVS; + api->LightAtPoint = TriLightAtPoint; + api->Color4fRendermode = TriColor4fRendermode; + api->FogParams = TriFogParams; + + return 1; +}