From 9608da5bf9a2c36a016a2a22ac5e3e1b0f30edcf Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 2 Nov 2024 21:22:56 +0300 Subject: [PATCH] engine: move debug hulls rendering from renderer, implement through TriAPI Bump RefAPI version to 9. --- engine/client/mod_dbghulls.c | 61 +++++++++++++++++++++-- engine/client/ref_common.c | 3 +- engine/common/mod_local.h | 4 +- engine/ref_api.h | 7 ++- ref/gl/gl_dbghulls.c | 93 ------------------------------------ ref/gl/gl_rsurf.c | 9 +++- 6 files changed, 74 insertions(+), 103 deletions(-) delete mode 100644 ref/gl/gl_dbghulls.c diff --git a/engine/client/mod_dbghulls.c b/engine/client/mod_dbghulls.c index 6cc5ae06..2832c9c4 100644 --- a/engine/client/mod_dbghulls.c +++ b/engine/client/mod_dbghulls.c @@ -1,6 +1,8 @@ /* mod_dbghulls.c - loading & handling world and brushmodels Copyright (C) 2016 Uncle Mike +Copyright (C) 2005 Kevin Shanahan +Copyright (C) 1996-1997 Id Software, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -659,7 +661,7 @@ static void make_hull_windings( hull_t *hull, hull_model_t *model ) Con_Reportf( "%i hull polys\n", model->num_polys ); } -void Mod_InitDebugHulls( model_t *loadmodel ) +static void Mod_InitDebugHulls( model_t *loadmodel ) { int i; @@ -675,14 +677,14 @@ void Mod_InitDebugHulls( model_t *loadmodel ) } } -void Mod_CreatePolygonsForHull( int hullnum ) +static void Mod_CreatePolygonsForHull( int hullnum ) { model_t *mod = cl.worldmodel; double start, end; char name[8]; int i; - if( hullnum < 1 || hullnum > 3 ) + if( hullnum < 0 || hullnum > 3 ) return; if( !world.num_hull_models ) @@ -704,6 +706,59 @@ void Mod_CreatePolygonsForHull( int hullnum ) Con_Printf( "build time %.3f secs\n", end - start ); } +static void R_DrawHull( hull_model_t *hull ) +{ + winding_t *poly; + + ref.dllFuncs.GL_Bind( XASH_TEXTURE0, R_GetBuiltinTexture( REF_WHITE_TEXTURE )); + ref.dllFuncs.TriRenderMode( kRenderNormal ); + list_for_each_entry( poly, &hull->polys, chain ) + { + int i; + + srand((unsigned int)poly ); + ref.dllFuncs.Color4ub( rand() & 255, rand() & 255, rand() & 255, 255 ); + + ref.dllFuncs.Begin( TRI_POLYGON ); + for( i = 0; i < poly->numpoints; i++ ) + ref.dllFuncs.Vertex3fv( poly->p[i] ); + ref.dllFuncs.End(); + } +} + +void R_DrawWorldHull( void ) +{ + if( r_showhull.value <= 0.0f ) + return; + + if( FBitSet( r_showhull.flags, FCVAR_CHANGED )) + { + int val = r_showhull.value; + if( val > 3 ) val = 0; + Mod_CreatePolygonsForHull( val ); + ClearBits( r_showhull.flags, FCVAR_CHANGED ); + } + + R_DrawHull( &world.hull_models[0] ); +} + +void R_DrawModelHull( model_t *mod ) +{ + int i; + + if( r_showhull.value <= 0.0f ) + return; + + if( !mod || mod->name[0] != '*' ) + return; + + i = atoi( mod->name + 1 ); + if( i < 1 || i >= world.num_hull_models ) + return; + + R_DrawHull( &world.hull_models[i] ); +} + void Mod_ReleaseHullPolygons( void ) { int i; diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index a4b9f4e2..dc0b8817 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -342,7 +342,8 @@ static const ref_api_t gEngfuncs = Mod_SampleSizeForFace, Mod_BoxVisible, Mod_PointInLeaf, - Mod_CreatePolygonsForHull, + R_DrawWorldHull, + R_DrawModelHull, R_StudioGetAnim, pfnStudioEvent, diff --git a/engine/common/mod_local.h b/engine/common/mod_local.h index 459b9d54..c01f344a 100644 --- a/engine/common/mod_local.h +++ b/engine/common/mod_local.h @@ -182,8 +182,8 @@ void Mod_PrintWorldStats_f( void ); // // mod_dbghulls.c // -void Mod_InitDebugHulls( model_t *mod ); -void Mod_CreatePolygonsForHull( int hullnum ); +void R_DrawWorldHull( void ); +void R_DrawModelHull( model_t *mod ); void Mod_ReleaseHullPolygons( void ); // diff --git a/engine/ref_api.h b/engine/ref_api.h index 273fe0e1..2f162740 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -51,7 +51,9 @@ GNU General Public License for more details. // PARM_SKY_SPHERE and PARM_SURF_SAMPLESIZE are now handled at engine side. // VGUI rendering code is mostly moved back to engine. // Implemented texture replacement. -#define REF_API_VERSION 8 +// 9. Removed gamma functions. Renderer is supposed to get them through PARM_GET_*_PTR. +// Move hulls rendering back to engine +#define REF_API_VERSION 9 #define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP|TF_ALLOW_NEAREST) #define TF_FONT (TF_NOMIPMAP|TF_CLAMP|TF_ALLOW_NEAREST) @@ -344,7 +346,8 @@ typedef struct ref_api_s int (*Mod_SampleSizeForFace)( const struct msurface_s *surf ); qboolean (*Mod_BoxVisible)( const vec3_t mins, const vec3_t maxs, const byte *visbits ); mleaf_t *(*Mod_PointInLeaf)( const vec3_t p, mnode_t *node ); - void (*Mod_CreatePolygonsForHull)( int hullnum ); + void (*R_DrawWorldHull)( void ); + void (*R_DrawModelHull)( model_t *mod ); // studio models void *(*R_StudioGetAnim)( studiohdr_t *m_pStudioHeader, model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc ); diff --git a/ref/gl/gl_dbghulls.c b/ref/gl/gl_dbghulls.c deleted file mode 100644 index 3cb9e267..00000000 --- a/ref/gl/gl_dbghulls.c +++ /dev/null @@ -1,93 +0,0 @@ -/* -gl_dbghulls.c - loading & handling world and brushmodels -Copyright (C) 2016 Uncle Mike - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. -*/ - -#include "gl_local.h" -#include "mod_local.h" - -#define list_entry( ptr, type, member ) \ - ((type *)((char *)(ptr) - (size_t)(&((type *)0)->member))) - -// iterate over each entry in the list -#define list_for_each_entry( pos, head, member ) \ - for( pos = list_entry( (head)->next, winding_t, member ); \ - &pos->member != (head); \ - pos = list_entry( pos->member.next, winding_t, member )) - -// REFTODO: rewrite in triapi -void R_DrawWorldHull( void ) -{ - hull_model_t *hull; - winding_t *poly; - int i; - - if( FBitSet( r_showhull->flags, FCVAR_CHANGED )) - { - int val = bound( 0, (int)r_showhull->value, 3 ); - if( val ) gEngfuncs.Mod_CreatePolygonsForHull( val ); - ClearBits( r_showhull->flags, FCVAR_CHANGED ); - } - - if( !r_showhull->value ) - return; - - hull = &tr.world->hull_models[0]; - - pglDisable( GL_TEXTURE_2D ); - - list_for_each_entry( poly, &hull->polys, chain ) - { - srand((unsigned int)poly); - pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); - pglBegin( GL_POLYGON ); - for( i = 0; i < poly->numpoints; i++ ) - pglVertex3fv( poly->p[i] ); - pglEnd(); - } - pglEnable( GL_TEXTURE_2D ); -} - -void R_DrawModelHull( void ) -{ - hull_model_t *hull; - winding_t *poly; - int i; - - if( !r_showhull->value ) - return; - - if( !RI.currentmodel || RI.currentmodel->name[0] != '*' ) - return; - - i = atoi( RI.currentmodel->name + 1 ); - if( i < 1 || i >= tr.world->num_hull_models ) - return; - - hull = &tr.world->hull_models[i]; - - pglPolygonOffset( 1.0f, 2.0 ); - pglEnable( GL_POLYGON_OFFSET_FILL ); - pglDisable( GL_TEXTURE_2D ); - list_for_each_entry( poly, &hull->polys, chain ) - { - srand((unsigned int)poly); - pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); - pglBegin( GL_POLYGON ); - for( i = 0; i < poly->numpoints; i++ ) - pglVertex3fv( poly->p[i] ); - pglEnd(); - } - pglEnable( GL_TEXTURE_2D ); - pglDisable( GL_POLYGON_OFFSET_FILL ); -} diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index 428e2b87..9abeb2eb 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -1745,7 +1745,12 @@ void R_DrawBrushModel( cl_entity_t *e ) pglAlphaFunc( GL_GREATER, DEFAULT_ALPHATEST ); pglDisable( GL_BLEND ); pglDepthMask( GL_TRUE ); - R_DrawModelHull(); // draw before restore + + pglPolygonOffset( 1.0f, 2.0f ); + pglEnable( GL_POLYGON_OFFSET_FILL ); + gEngfuncs.R_DrawModelHull( clmodel ); // draw before restore + pglDisable( GL_POLYGON_OFFSET_FILL ); + R_LoadIdentity(); // restore worldmatrix } @@ -3626,7 +3631,7 @@ void R_DrawWorld( void ) R_DrawTriangleOutlines (); - R_DrawWorldHull(); + gEngfuncs.R_DrawWorldHull(); } /*