From 8f9800eb3cd0ed13e8a18528ba3aa0f4e331f874 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sat, 27 Jul 2019 13:27:40 +0300 Subject: [PATCH] ref: move R_DrawTree from refdll to engine, implement using ref's triapi --- engine/client/cl_game.c | 18 +++---- engine/client/cl_view.c | 96 +++++++++++++++++++++++++++++++++++++- engine/client/client.h | 1 + engine/client/ref_common.c | 2 + engine/common/mod_local.h | 4 ++ engine/ref_api.h | 2 +- ref_gl/gl_backend.c | 92 ------------------------------------ ref_gl/gl_context.c | 1 - ref_gl/gl_image.c | 2 +- ref_gl/gl_local.h | 7 +-- ref_gl/gl_opengl.c | 2 - ref_gl/gl_rmisc.c | 1 - 12 files changed, 115 insertions(+), 113 deletions(-) diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index a87a366f..3e4b8ce5 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1103,14 +1103,16 @@ void CL_FreeEntity( cl_entity_t *pEdict ) void CL_ClearWorld( void ) { - cl_entity_t *world; - - world = clgame.entities; - world->curstate.modelindex = 1; // world model - world->curstate.solid = SOLID_BSP; - world->curstate.movetype = MOVETYPE_PUSH; - world->model = cl.worldmodel; - world->index = 0; + cl_entity_t *worldmodel; + + worldmodel = clgame.entities; + worldmodel->curstate.modelindex = 1; // world model + worldmodel->curstate.solid = SOLID_BSP; + worldmodel->curstate.movetype = MOVETYPE_PUSH; + worldmodel->model = cl.worldmodel; + worldmodel->index = 0; + + world.max_recursion = 0; clgame.ds.cullMode = TRI_FRONT; clgame.numStatics = 0; diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index 313acccb..a94ffc96 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -346,6 +346,100 @@ void V_RenderView( void ) ref.dllFuncs.GL_BackendEndFrame (); } +#define POINT_SIZE 16.0f +#define NODE_INTERVAL_X(x) (x * 16.0f) +#define NODE_INTERVAL_Y(x) (x * 16.0f) + +void R_DrawLeafNode( float x, float y, float scale ) +{ + float downScale = scale * 0.25f;// * POINT_SIZE; + + ref.dllFuncs.R_DrawStretchPic( x - downScale * 0.5f, y - downScale * 0.5f, downScale, downScale, 0, 0, 1, 1, R_GetBuiltinTexture( REF_PARTICLE_TEXTURE ) ); +} + +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( ); +} + +void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes, mleaf_t *viewleaf ) +{ + float downScale = scale * 0.8f; + + downScale = Q_max( downScale, 1.0f ); + + if( !node ) return; + + world.recursion_level++; + + if( node->contents < 0 ) + { + mleaf_t *leaf = (mleaf_t *)node; + + if( world.recursion_level > world.max_recursion ) + world.max_recursion = world.recursion_level; + + if( shownodes == 1 ) + { + if( cl.worldmodel->leafs == leaf ) + ref.dllFuncs.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 ); + R_DrawLeafNode( x, y, scale ); + } + world.recursion_level--; + return; + } + + if( shownodes == 1 ) + { + ref.dllFuncs.Color4f( 0.0f, 0.0f, 1.0f, 1.0f ); + R_DrawLeafNode( x, y, scale ); + } + else if( shownodes == 2 ) + { + R_DrawNodeConnection( x, y, x - scale, y + scale ); + R_DrawNodeConnection( x, y, x + scale, y + scale ); + } + + R_ShowTree_r( node->children[1], x - scale, y + scale, downScale, shownodes, viewleaf ); + R_ShowTree_r( node->children[0], x + scale, y + scale, downScale, shownodes, viewleaf ); + + world.recursion_level--; +} + +void R_ShowTree( void ) +{ + float x = (float)((refState.width - (int)POINT_SIZE) >> 1); + float y = NODE_INTERVAL_Y(1.0); + mleaf_t *viewleaf; + + if( !cl.worldmodel || !CVAR_TO_BOOL( r_showtree )) + return; + + world.recursion_level = 0; + viewleaf = Mod_PointInLeaf( refState.vieworg, cl.worldmodel->nodes ); + + //pglEnable( GL_BLEND ); + //pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + //pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + //pglLineWidth( 2.0f ); + ref.dllFuncs.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 ); + //pglLineWidth( 1.0f ); + + R_ShowTree_r( cl.worldmodel->nodes, x, y, world.max_recursion * 3.5f, 1, viewleaf ); + + Con_NPrintf( 0, "max recursion %d\n", world.max_recursion ); +} + /* ================== V_PostRender @@ -385,7 +479,7 @@ void V_PostRender( void ) CL_DrawDemoRecording(); CL_DrawHUD( CL_CHANGELEVEL ); ref.dllFuncs.R_ShowTextures(); - ref.dllFuncs.R_ShowTree(); + R_ShowTree(); Con_DrawConsole(); UI_UpdateMenu( host.realtime ); Con_DrawVersion(); diff --git a/engine/client/client.h b/engine/client/client.h index 011f334d..3b382ae8 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -690,6 +690,7 @@ extern convar_t *v_dark; // start from dark extern convar_t *net_graph; extern convar_t *rate; extern convar_t *m_ignore; +extern convar_t *r_showtree; //============================================================================= diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index f93cc53d..967d4ed8 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -12,6 +12,7 @@ convar_t *gl_vsync; convar_t *gl_showtextures; convar_t *r_decals; convar_t *r_adjust_fov; +convar_t *r_showtree; convar_t *gl_wgl_msaa_samples; convar_t *gl_clear; @@ -538,6 +539,7 @@ qboolean R_Init( void ) r_decals = Cvar_Get( "r_decals", "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" ); gl_wgl_msaa_samples = Cvar_Get( "gl_wgl_msaa_samples", "0", FCVAR_GLCONFIG, "samples number for multisample anti-aliasing" ); gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" ); + r_showtree = Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" ); if( !R_LoadProgs( refdll )) { diff --git a/engine/common/mod_local.h b/engine/common/mod_local.h index 3ef7bbde..386a3057 100644 --- a/engine/common/mod_local.h +++ b/engine/common/mod_local.h @@ -108,6 +108,10 @@ typedef struct world_static_s vec3_t mins; // real accuracy world bounds vec3_t maxs; vec3_t size; + + // tree visualization stuff + int recursion_level; + int max_recursion; } world_static_t; #ifndef REF_DLL diff --git a/engine/ref_api.h b/engine/ref_api.h index c429a5c2..5f0d33b0 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -129,6 +129,7 @@ enum // r_speeds counters #define REF_GRAY_TEXTURE "*gray" #define REF_WHITE_TEXTURE "*white" #define REF_BLACK_TEXTURE "*black" +#define REF_PARTICLE_TEXTURE "*particle" #define REF_SOLIDSKY_TEXTURE "solid_sky" #define REF_ALPHASKY_TEXTURE "alpha_sky" @@ -458,7 +459,6 @@ typedef struct ref_interface_s // debug void (*R_ShowTextures)( void ); - void (*R_ShowTree)( void ); // texture management const byte *(*R_GetTextureOriginalBuffer)( unsigned int idx ); // not always available diff --git a/ref_gl/gl_backend.c b/ref_gl/gl_backend.c index 6038e459..6db0a84c 100644 --- a/ref_gl/gl_backend.c +++ b/ref_gl/gl_backend.c @@ -714,98 +714,6 @@ rebuild_page: pglFinish(); } -#define POINT_SIZE 16.0f -#define NODE_INTERVAL_X(x) (x * 16.0f) -#define NODE_INTERVAL_Y(x) (x * 16.0f) - -void R_DrawLeafNode( float x, float y, float scale ) -{ - float downScale = scale * 0.25f;// * POINT_SIZE; - - R_DrawStretchPic( x - downScale * 0.5f, y - downScale * 0.5f, downScale, downScale, 0, 0, 1, 1, tr.particleTexture ); -} - -void R_DrawNodeConnection( float x, float y, float x2, float y2 ) -{ - pglBegin( GL_LINES ); - pglVertex2f( x, y ); - pglVertex2f( x2, y2 ); - pglEnd(); -} - -void R_ShowTree_r( mnode_t *node, float x, float y, float scale, int shownodes ) -{ - float downScale = scale * 0.8f; - - downScale = Q_max( downScale, 1.0f ); - - if( !node ) return; - - tr.recursion_level++; - - if( node->contents < 0 ) - { - mleaf_t *leaf = (mleaf_t *)node; - - if( tr.recursion_level > tr.max_recursion ) - tr.max_recursion = tr.recursion_level; - - if( shownodes == 1 ) - { - if( WORLDMODEL->leafs == leaf ) - pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); - else if( RI.viewleaf && RI.viewleaf == leaf ) - pglColor4f( 1.0f, 0.0f, 0.0f, 1.0f ); - else pglColor4f( 0.0f, 1.0f, 0.0f, 1.0f ); - R_DrawLeafNode( x, y, scale ); - } - tr.recursion_level--; - return; - } - - if( shownodes == 1 ) - { - pglColor4f( 0.0f, 0.0f, 1.0f, 1.0f ); - R_DrawLeafNode( x, y, scale ); - } - else if( shownodes == 2 ) - { - R_DrawNodeConnection( x, y, x - scale, y + scale ); - R_DrawNodeConnection( x, y, x + scale, y + scale ); - } - - R_ShowTree_r( node->children[1], x - scale, y + scale, downScale, shownodes ); - R_ShowTree_r( node->children[0], x + scale, y + scale, downScale, shownodes ); - - tr.recursion_level--; -} - -void R_ShowTree( void ) -{ - float x = (float)((gpGlobals->width - (int)POINT_SIZE) >> 1); - float y = NODE_INTERVAL_Y(1.0); - - if( !WORLDMODEL || !CVAR_TO_BOOL( r_showtree )) - return; - - tr.recursion_level = 0; - - pglEnable( GL_BLEND ); - pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - - pglLineWidth( 2.0f ); - pglColor3f( 1, 0.7f, 0 ); - pglDisable( GL_TEXTURE_2D ); - R_ShowTree_r( WORLDMODEL->nodes, x, y, tr.max_recursion * 3.5f, 2 ); - pglEnable( GL_TEXTURE_2D ); - pglLineWidth( 1.0f ); - - R_ShowTree_r( WORLDMODEL->nodes, x, y, tr.max_recursion * 3.5f, 1 ); - - gEngfuncs.Con_NPrintf( 0, "max recursion %d\n", tr.max_recursion ); -} - /* ================ SCR_TimeRefresh_f diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c index 10675f9c..dcb24822 100644 --- a/ref_gl/gl_context.c +++ b/ref_gl/gl_context.c @@ -335,7 +335,6 @@ ref_interface_t gReffuncs = R_ProcessEntData, R_ShowTextures, - R_ShowTree, R_GetTextureOriginalBuffer, GL_LoadTextureFromBuffer, diff --git a/ref_gl/gl_image.c b/ref_gl/gl_image.c index f7134e05..edcd97f7 100644 --- a/ref_gl/gl_image.c +++ b/ref_gl/gl_image.c @@ -1974,7 +1974,7 @@ static void GL_CreateInternalTextures( void ) } } - tr.particleTexture = GL_LoadTextureInternal( "*particle", pic, TF_CLAMP ); + tr.particleTexture = GL_LoadTextureInternal( REF_PARTICLE_TEXTURE, pic, TF_CLAMP ); // white texture pic = GL_FakeImage( 4, 4, 1, IMAGE_HAS_COLOR ); diff --git a/ref_gl/gl_local.h b/ref_gl/gl_local.h index 00bf7b69..053f3dd0 100644 --- a/ref_gl/gl_local.h +++ b/ref_gl/gl_local.h @@ -231,10 +231,7 @@ typedef struct qboolean fResetVis; qboolean fFlipViewModel; - // tree visualization stuff - int recursion_level; - int max_recursion; - + byte visbytes[(MAX_MAP_LEAFS+7)/8]; // member custom PVS int lightstylevalue[MAX_LIGHTSTYLES]; // value 0 - 65536 int block_size; // lightmap blocksize @@ -296,7 +293,6 @@ void GL_SetRenderMode( int mode ); void GL_TextureTarget( uint target ); void GL_Cull( GLenum cull ); void R_ShowTextures( void ); -void R_ShowTree( void ); void SCR_TimeRefresh_f( void ); // @@ -741,7 +737,6 @@ extern cvar_t *gl_stencilbits; extern cvar_t *r_speeds; extern cvar_t *r_fullbright; extern cvar_t *r_norefresh; -extern cvar_t *r_showtree; // build graph of visible hull extern cvar_t *r_lighting_extended; extern cvar_t *r_lighting_modulate; extern cvar_t *r_lighting_ambient; diff --git a/ref_gl/gl_opengl.c b/ref_gl/gl_opengl.c index 284e82c1..751ae1fc 100644 --- a/ref_gl/gl_opengl.c +++ b/ref_gl/gl_opengl.c @@ -22,7 +22,6 @@ cvar_t *gl_stencilbits; cvar_t *r_speeds; cvar_t *r_fullbright; cvar_t *r_norefresh; -cvar_t *r_showtree; cvar_t *r_lighting_extended; cvar_t *r_lighting_modulate; cvar_t *r_lighting_ambient; @@ -780,7 +779,6 @@ void GL_InitCommands( void ) r_speeds = gEngfuncs.Cvar_Get( "r_speeds", "0", FCVAR_ARCHIVE, "shows renderer speeds" ); r_fullbright = gEngfuncs.Cvar_Get( "r_fullbright", "0", FCVAR_CHEAT, "disable lightmaps, get fullbright for entities" ); r_norefresh = gEngfuncs.Cvar_Get( "r_norefresh", "0", 0, "disable 3D rendering (use with caution)" ); - r_showtree = gEngfuncs.Cvar_Get( "r_showtree", "0", FCVAR_ARCHIVE, "build the graph of visible BSP tree" ); r_lighting_extended = gEngfuncs.Cvar_Get( "r_lighting_extended", "1", FCVAR_ARCHIVE, "allow to get lighting from world and bmodels" ); r_lighting_modulate = gEngfuncs.Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" ); r_lighting_ambient = gEngfuncs.Cvar_Get( "r_lighting_ambient", "0.3", FCVAR_ARCHIVE, "map ambient lighting scale" ); diff --git a/ref_gl/gl_rmisc.c b/ref_gl/gl_rmisc.c index 7fcca6f4..0514206e 100644 --- a/ref_gl/gl_rmisc.c +++ b/ref_gl/gl_rmisc.c @@ -159,7 +159,6 @@ void R_NewMap( void ) glState.isFogEnabled = false; tr.skytexturenum = -1; - tr.max_recursion = 0; pglDisable( GL_FOG ); // clearing texture chains