Skip to content

Commit

Permalink
Fix #468
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Oct 11, 2024
1 parent 7ebf24a commit fefe347
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
48 changes: 45 additions & 3 deletions Plugins/Renderer/gl_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,29 @@ void R_PrepareStudioVBOSubmodel(
}
}

studio_vbo_t* R_GetStudioVBOFromStudioHeader(studiohdr_t* studiohdr)
{
for (auto VBOData : g_StudioVBOCache)
{
if (VBOData)
{
auto mod = VBOData->BodyModel;
if (mod && mod->type == mod_studio)
{
if (mod->needload == NL_PRESENT || mod->needload == NL_CLIENT)
{
if (mod->cache.data == studiohdr)
{
return VBOData;
}
}
}
}
}

return nullptr;
}

studio_vbo_t* R_GetStudioVBOFromModel(model_t* mod)
{
int modelindex = EngineGetModelIndex(mod);
Expand Down Expand Up @@ -307,13 +330,15 @@ studio_vbo_t* R_AllocateStudioVBO(model_t* mod, studiohdr_t* studiohdr)
if (!studiohdr->numbodyparts)
return NULL;

studio_vbo_t* VBOData = R_GetStudioVBOFromModel(mod);
auto VBOData = R_GetStudioVBOFromModel(mod);

if (VBOData)
return VBOData;

VBOData = new studio_vbo_t;

VBOData->BodyModel = mod;

R_AllocSlotForStudioVBO(mod, VBOData);

studiohdr->soundtable = EngineGetModelIndex(mod);
Expand Down Expand Up @@ -413,9 +438,23 @@ studio_vbo_t* R_AllocateStudioVBO(model_t* mod, studiohdr_t* studiohdr)
studio_vbo_t *R_GetStudioVBO(studiohdr_t* studiohdr)
{
if (studiohdr->soundtable < 0 || studiohdr->soundtable >= g_StudioVBOCache.size())
return NULL;
return nullptr;

auto VBOData = g_StudioVBOCache[studiohdr->soundtable];
auto mod = VBOData->BodyModel;

if (mod && mod->type == mod_studio)
{
if (mod->needload == NL_PRESENT || mod->needload == NL_CLIENT)
{
if (mod->cache.data == studiohdr)
{
return VBOData;
}
}
}

return g_StudioVBOCache[studiohdr->soundtable];
return nullptr;
}

void R_StudioClearVBOCache(void)
Expand Down Expand Up @@ -2444,6 +2483,9 @@ void R_GLStudioDrawPoints(void)
{
auto VBOData = R_GetStudioVBO((*pstudiohdr));

if (!VBOData)
VBOData = R_GetStudioVBOFromStudioHeader((*pstudiohdr));

if (!VBOData)
return;

Expand Down
2 changes: 2 additions & 0 deletions Plugins/Renderer/gl_studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ typedef struct studio_vbo_s
hEBO = 0;
hVAO = 0;
hStudioUBO = 0;
BodyModel = NULL;
TextureModel = NULL;
bExternalFileLoaded = false;
}
Expand All @@ -199,6 +200,7 @@ typedef struct studio_vbo_s
//Memory Offset -> vbo_submodel_t Mapping Table
std::unordered_map<int, studio_vbo_submodel_t*> mSubmodels;

model_t* BodyModel;
model_t* TextureModel;

studio_celshade_control_t celshade_control;
Expand Down

0 comments on commit fefe347

Please sign in to comment.