Skip to content

Commit

Permalink
[rend2] Rework precaching to init the renderer now
Browse files Browse the repository at this point in the history
  • Loading branch information
SomaZ committed May 3, 2024
1 parent 4d58063 commit b86845c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
24 changes: 16 additions & 8 deletions code/rd-rend2/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,7 @@ void R_ClearStuffToStopGhoul2CrashingThings(void)
memset(&tr, 0, sizeof(tr));
}

static bool r_inited = false;
/*
===============
R_Init
Expand All @@ -1979,6 +1980,9 @@ R_Init
void R_Init( void ) {
byte *ptr;
int i;

if (r_inited)
return;

ri.Printf( PRINT_ALL, "----- R_Init -----\n" );

Expand Down Expand Up @@ -2092,6 +2096,7 @@ void R_Init( void ) {

// print info
GfxInfo_f();
r_inited = true;
ri.Printf( PRINT_ALL, "----- finished R_Init -----\n" );
}

Expand All @@ -2117,21 +2122,23 @@ void RE_Shutdown( qboolean destroyWindow, qboolean restarting ) {
R_ShutdownWeatherSystem();

R_ShutdownFonts();
if ( tr.registered ) {

if (r_inited)
{
R_ShutDownQueries();
FBO_Shutdown();
R_DeleteTextures();
R_DestroyGPUBuffers();
GLSL_ShutdownGPUShaders();
}

if ( destroyWindow && restarting )
{
ri.Z_Free((void *)glConfig.extensions_string);
ri.Z_Free((void *)glConfigExt.originalExtensionString);
if (destroyWindow && restarting && tr.registered)
{
ri.Z_Free((void *)glConfig.extensions_string);
ri.Z_Free((void *)glConfigExt.originalExtensionString);

qglDeleteVertexArrays(1, &tr.globalVao);
SaveGhoul2InfoArray();
}
qglDeleteVertexArrays(1, &tr.globalVao);
SaveGhoul2InfoArray();
}

// shut down platform specific OpenGL stuff
Expand All @@ -2140,6 +2147,7 @@ void RE_Shutdown( qboolean destroyWindow, qboolean restarting ) {
}

tr.registered = qfalse;
r_inited = false;
backEndData = NULL;
}

Expand Down
24 changes: 16 additions & 8 deletions codemp/rd-rend2/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,7 @@ static void R_ShutdownBackEndFrameData()
}
}

static bool r_inited = false;
/*
===============
R_Init
Expand All @@ -1918,6 +1919,9 @@ void R_Init( void ) {
byte *ptr;
int i;

if (r_inited)
return;

ri.Printf( PRINT_ALL, "----- R_Init -----\n" );

// clear all our internal state
Expand Down Expand Up @@ -2030,6 +2034,7 @@ void R_Init( void ) {

// print info
GfxInfo_f();
r_inited = true;
ri.Printf( PRINT_ALL, "----- finished R_Init -----\n" );
}

Expand All @@ -2055,21 +2060,23 @@ void RE_Shutdown( qboolean destroyWindow, qboolean restarting ) {
R_ShutdownWeatherSystem();

R_ShutdownFonts();
if ( tr.registered ) {

if (r_inited)
{
R_ShutDownQueries();
FBO_Shutdown();
R_DeleteTextures();
R_DestroyGPUBuffers();
GLSL_ShutdownGPUShaders();
}

if ( destroyWindow && restarting )
{
ri.Z_Free((void *)glConfig.extensions_string);
ri.Z_Free((void *)glConfigExt.originalExtensionString);
if (destroyWindow && restarting && tr.registered)
{
ri.Z_Free((void *)glConfig.extensions_string);
ri.Z_Free((void *)glConfigExt.originalExtensionString);

qglDeleteVertexArrays(1, &tr.globalVao);
SaveGhoul2InfoArray();
}
qglDeleteVertexArrays(1, &tr.globalVao);
SaveGhoul2InfoArray();
}

// shut down platform specific OpenGL stuff
Expand All @@ -2078,6 +2085,7 @@ void RE_Shutdown( qboolean destroyWindow, qboolean restarting ) {
}

tr.registered = qfalse;
r_inited = false;
backEndData = NULL;
}

Expand Down
15 changes: 5 additions & 10 deletions shared/rd-rend2/tr_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,16 +1592,11 @@ void RE_BeginRegistration( glconfig_t *glconfigOut ) {

void R_SVModelInit()
{
#ifdef REND2_SP
tr.numShaders = 0;
tr.numImages = 0;

R_InitImagesPool();
R_InitImages();
R_InitShaders(qfalse);
#endif

R_ModelInit();
// Vanilla SP setups textures, shaders and models only
// Rend2 requires gpu buffer access for shaders already so, just do renderer setup already
// Shouldn't hurt to do so in MP too
// R_Init now makes sure its only doing its thing once unless everything is destructed again
R_Init();
}

/*
Expand Down

0 comments on commit b86845c

Please sign in to comment.