ref: gl: implement generating VBO only when gl_vbo was set to 1
* Make it safer by creating a function that returns VBO state, was it generated or enabled by user
This commit is contained in:
parent
ac50c762d7
commit
55c1bddac5
4 changed files with 56 additions and 21 deletions
|
@ -445,6 +445,9 @@ void R_GenerateVBO( void );
|
||||||
void R_ClearVBO( void );
|
void R_ClearVBO( void );
|
||||||
void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf );
|
void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf );
|
||||||
void R_LightmapCoord( const vec3_t v, const msurface_t *surf, const float sample_size, vec2_t coords );
|
void R_LightmapCoord( const vec3_t v, const msurface_t *surf, const float sample_size, vec2_t coords );
|
||||||
|
qboolean R_HasGeneratedVBO( void );
|
||||||
|
void R_EnableVBO( qboolean enable );
|
||||||
|
qboolean R_HasEnabledVBO( void );
|
||||||
|
|
||||||
//
|
//
|
||||||
// gl_rpart.c
|
// gl_rpart.c
|
||||||
|
|
|
@ -1010,21 +1010,32 @@ void R_GammaChanged( qboolean do_reset_gamma )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void R_CheckGamma( void )
|
static void R_CheckCvars( void )
|
||||||
{
|
{
|
||||||
qboolean rebuild = false;
|
qboolean rebuild = false;
|
||||||
|
|
||||||
if( FBitSet( gl_overbright.flags, FCVAR_CHANGED ))
|
if( FBitSet( gl_overbright.flags, FCVAR_CHANGED ))
|
||||||
{
|
{
|
||||||
rebuild = true;
|
|
||||||
ClearBits( gl_overbright.flags, FCVAR_CHANGED );
|
ClearBits( gl_overbright.flags, FCVAR_CHANGED );
|
||||||
|
rebuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( gl_overbright.value && ( FBitSet( r_vbo.flags, FCVAR_CHANGED ) || FBitSet( r_vbo_overbrightmode.flags, FCVAR_CHANGED ) ) )
|
if( FBitSet( r_vbo.flags, FCVAR_CHANGED ))
|
||||||
{
|
{
|
||||||
rebuild = true;
|
|
||||||
ClearBits( r_vbo.flags, FCVAR_CHANGED );
|
ClearBits( r_vbo.flags, FCVAR_CHANGED );
|
||||||
|
|
||||||
|
R_EnableVBO( r_vbo.value ? true : false );
|
||||||
|
if( R_HasEnabledVBO( ))
|
||||||
|
R_GenerateVBO();
|
||||||
|
|
||||||
|
if( gl_overbright.value )
|
||||||
|
rebuild = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( FBitSet( r_vbo_overbrightmode.flags, FCVAR_CHANGED ) && gl_overbright.value )
|
||||||
|
{
|
||||||
ClearBits( r_vbo_overbrightmode.flags, FCVAR_CHANGED );
|
ClearBits( r_vbo_overbrightmode.flags, FCVAR_CHANGED );
|
||||||
|
rebuild = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( rebuild )
|
if( rebuild )
|
||||||
|
@ -1046,7 +1057,7 @@ void R_BeginFrame( qboolean clearScene )
|
||||||
pglClear( GL_COLOR_BUFFER_BIT );
|
pglClear( GL_COLOR_BUFFER_BIT );
|
||||||
}
|
}
|
||||||
|
|
||||||
R_CheckGamma();
|
R_CheckCvars();
|
||||||
|
|
||||||
R_Set2DMode( true );
|
R_Set2DMode( true );
|
||||||
|
|
||||||
|
|
|
@ -147,7 +147,10 @@ void R_NewMap( void )
|
||||||
}
|
}
|
||||||
|
|
||||||
GL_BuildLightmaps ();
|
GL_BuildLightmaps ();
|
||||||
R_GenerateVBO();
|
|
||||||
|
R_ClearVBO();
|
||||||
|
if( R_HasEnabledVBO( ))
|
||||||
|
R_GenerateVBO();
|
||||||
R_ResetRipples();
|
R_ResetRipples();
|
||||||
|
|
||||||
if( gEngfuncs.drawFuncs->R_NewMap != NULL )
|
if( gEngfuncs.drawFuncs->R_NewMap != NULL )
|
||||||
|
|
|
@ -718,7 +718,7 @@ static void R_BuildLightMap( msurface_t *surf, byte *dest, int stride, qboolean
|
||||||
tmax = ( info->lightextents[1] / sample_size ) + 1;
|
tmax = ( info->lightextents[1] / sample_size ) + 1;
|
||||||
size = smax * tmax;
|
size = smax * tmax;
|
||||||
if( gl_overbright.value )
|
if( gl_overbright.value )
|
||||||
lightscale = (r_vbo.value && !r_vbo_overbrightmode.value) ? 171 : 256;
|
lightscale = ( R_HasEnabledVBO() && !r_vbo_overbrightmode.value) ? 171 : 256;
|
||||||
else lightscale = ( pow( 2.0f, 1.0f / v_lightgamma->value ) * 256 ) + 0.5;
|
else lightscale = ( pow( 2.0f, 1.0f / v_lightgamma->value ) * 256 ) + 0.5;
|
||||||
|
|
||||||
lm = surf->samples;
|
lm = surf->samples;
|
||||||
|
@ -927,7 +927,7 @@ static void R_BlendLightmaps( void )
|
||||||
if( gl_overbright.value )
|
if( gl_overbright.value )
|
||||||
{
|
{
|
||||||
pglBlendFunc( GL_DST_COLOR, GL_SRC_COLOR );
|
pglBlendFunc( GL_DST_COLOR, GL_SRC_COLOR );
|
||||||
if(!( r_vbo.value && !r_vbo_overbrightmode.value ))
|
if(!( R_HasEnabledVBO() && !r_vbo_overbrightmode.value ))
|
||||||
pglColor4f( 128.0f / 192.0f, 128.0f / 192.0f, 128.0f / 192.0f, 1.0f );
|
pglColor4f( 128.0f / 192.0f, 128.0f / 192.0f, 128.0f / 192.0f, 1.0f );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1583,7 +1583,7 @@ void R_DrawBrushModel( cl_entity_t *e )
|
||||||
model_t *clmodel;
|
model_t *clmodel;
|
||||||
qboolean rotated;
|
qboolean rotated;
|
||||||
dlight_t *l;
|
dlight_t *l;
|
||||||
qboolean allow_vbo = r_vbo.value;
|
qboolean allow_vbo = R_HasEnabledVBO();
|
||||||
|
|
||||||
if( !RI.drawWorld ) return;
|
if( !RI.drawWorld ) return;
|
||||||
|
|
||||||
|
@ -1833,6 +1833,10 @@ struct vbo_static_s
|
||||||
int maxarraysplit_tex;
|
int maxarraysplit_tex;
|
||||||
int minarraysplit_lm;
|
int minarraysplit_lm;
|
||||||
int maxarraysplit_lm;
|
int maxarraysplit_lm;
|
||||||
|
|
||||||
|
// cvar state potentially might be changed during frame
|
||||||
|
// so only enable VBO at the beginning of frame
|
||||||
|
qboolean enabled;
|
||||||
} vbos;
|
} vbos;
|
||||||
|
|
||||||
struct multitexturestate_s
|
struct multitexturestate_s
|
||||||
|
@ -1869,7 +1873,6 @@ enum lightmap_state_e
|
||||||
VBO_LIGHTMAP_DYNAMIC
|
VBO_LIGHTMAP_DYNAMIC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct arraystate_s
|
static struct arraystate_s
|
||||||
{
|
{
|
||||||
enum array_state_e astate;
|
enum array_state_e astate;
|
||||||
|
@ -1879,6 +1882,20 @@ static struct arraystate_s
|
||||||
qboolean decal_mode;
|
qboolean decal_mode;
|
||||||
} vboarray;
|
} vboarray;
|
||||||
|
|
||||||
|
qboolean R_HasGeneratedVBO( void )
|
||||||
|
{
|
||||||
|
return vbos.mempool != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void R_EnableVBO( qboolean enable )
|
||||||
|
{
|
||||||
|
vbos.enabled = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
qboolean R_HasEnabledVBO( void )
|
||||||
|
{
|
||||||
|
return vbos.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===================
|
===================
|
||||||
|
@ -1890,22 +1907,23 @@ Allocate memory for arrays, fill it with vertex attribs and upload to GPU
|
||||||
void R_GenerateVBO( void )
|
void R_GenerateVBO( void )
|
||||||
{
|
{
|
||||||
model_t *world = WORLDMODEL;
|
model_t *world = WORLDMODEL;
|
||||||
msurface_t *surfaces = world->surfaces;
|
msurface_t *surfaces;
|
||||||
int numsurfaces = world->numsurfaces;
|
int numsurfaces;
|
||||||
int numtextures = world->numtextures;
|
int numtextures;
|
||||||
int numlightmaps = gl_lms.current_lightmap_texture;
|
const int numlightmaps = gl_lms.current_lightmap_texture;
|
||||||
int k, len = 0;
|
int k, len = 0;
|
||||||
vboarray_t *vbo;
|
vboarray_t *vbo;
|
||||||
uint maxindex = 0;
|
uint maxindex = 0;
|
||||||
double t1, t2, t3;
|
double t1, t2, t3;
|
||||||
|
|
||||||
R_ClearVBO();
|
if( R_HasGeneratedVBO() || !world || !world->surfaces )
|
||||||
|
return;
|
||||||
|
|
||||||
t1 = gEngfuncs.pfnTime();
|
t1 = gEngfuncs.pfnTime();
|
||||||
|
|
||||||
// save in config if enabled manually
|
surfaces = world->surfaces;
|
||||||
if( r_vbo.value )
|
numsurfaces = world->numsurfaces;
|
||||||
r_vbo.flags |= FCVAR_ARCHIVE;
|
numtextures = world->numtextures;
|
||||||
|
|
||||||
vbos.mempool = Mem_AllocPool("Render VBO Zone");
|
vbos.mempool = Mem_AllocPool("Render VBO Zone");
|
||||||
|
|
||||||
|
@ -3056,7 +3074,7 @@ void R_DrawVBO( qboolean drawlightmap, qboolean drawtextures )
|
||||||
int k;
|
int k;
|
||||||
vboarray_t *vbo = vbos.arraylist;
|
vboarray_t *vbo = vbos.arraylist;
|
||||||
|
|
||||||
if( !r_vbo.value )
|
if( !R_HasGeneratedVBO() || !R_HasEnabledVBO() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GL_SetupFogColorForSurfacesEx( 1, 0.5f, false );
|
GL_SetupFogColorForSurfacesEx( 1, 0.5f, false );
|
||||||
|
@ -3163,7 +3181,7 @@ qboolean R_AddSurfToVBO( msurface_t *surf, qboolean buildlightmap )
|
||||||
vbotexture_t *vbotex;
|
vbotexture_t *vbotex;
|
||||||
int texturenum;
|
int texturenum;
|
||||||
|
|
||||||
if( !r_vbo.value )
|
if( !R_HasGeneratedVBO() || !R_HasEnabledVBO( ))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// find vbotexture_t assotiated with this surface
|
// find vbotexture_t assotiated with this surface
|
||||||
|
@ -3559,7 +3577,7 @@ void R_DrawWorld( void )
|
||||||
GL_ResetFogColor();
|
GL_ResetFogColor();
|
||||||
R_BlendLightmaps();
|
R_BlendLightmaps();
|
||||||
R_RenderFullbrights();
|
R_RenderFullbrights();
|
||||||
R_RenderDetails( r_vbo.value? 2 : 3 );
|
R_RenderDetails( R_HasEnabledVBO() ? 2 : 3 );
|
||||||
|
|
||||||
if( skychain )
|
if( skychain )
|
||||||
R_DrawSkyBox();
|
R_DrawSkyBox();
|
||||||
|
|
Loading…
Add table
Reference in a new issue