Consoles: Switch to per entity model vertex buffers

This commit is contained in:
UnknownShadow200 2023-11-12 11:21:40 +11:00
parent 066bb0f67e
commit 071b14f02d
2 changed files with 18 additions and 16 deletions

View File

@ -26,6 +26,7 @@ static void HeldBlockRenderer_RenderModel(void) {
Gfx_SetFaceCulling(true);
Gfx_SetDepthTest(false);
/* TODO: Need to properly reallocate per model VB here */
if (Blocks.Draw[held_block] == DRAW_GAS) {
model = LocalPlayer_Instance.Base.Model;

View File

@ -168,6 +168,8 @@ void Model_ApplyTexture(struct Entity* e) {
void Model_UpdateVB(void) {
struct Model* model = Models.Active;
if (!Models.Vb)
Models.Vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, Models.MaxVertices);
Gfx_SetDynamicVbData(Models.Vb, Models.Vertices, model->index);
Gfx_DrawVb_IndexedTris(model->index);
@ -179,13 +181,19 @@ static struct VertexTextured* real_vertices;
static GfxResourceID modelVB;
void Model_LockVB(struct Entity* entity, int verticesCount) {
real_vertices = Models.Vertices;
/*if (!entity->ModelVB) {
#ifdef CC_BUILD_LOWMEM
if (!entity->ModelVB) {
entity->ModelVB = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, Models.Active->maxVertices);
}
modelVB = entity->ModelVB;*/
modelVB = entity->ModelVB;
#else
if (!Models.Vb) {
Models.Vb = Gfx_CreateDynamicVb(VERTEX_FORMAT_TEXTURED, Models.MaxVertices);
}
modelVB = Models.Vb;
#endif
real_vertices = Models.Vertices;
Models.Vertices = Gfx_LockDynamicVb(modelVB, VERTEX_FORMAT_TEXTURED, verticesCount);
}
@ -841,8 +849,7 @@ static void CheckMaxVertices(void) {
if (Models.MaxVertices < MODELS_MAX_VERTICES) {
Platform_LogConst("CheckMaxVertices found smaller buffer, resetting Models.Vb");
Models.MaxVertices = MODELS_MAX_VERTICES;
Gfx_RecreateDynamicVb(&Models.Vb, VERTEX_FORMAT_TEXTURED, Models.MaxVertices);
Gfx_DeleteDynamicVb(&Models.Vb);
}
}
@ -2386,25 +2393,19 @@ static void OnContextLost(void* obj) {
Gfx_DeleteDynamicVb(&Models.Vb);
if (Gfx.ManagedTextures) return;
for (tex = textures_head; tex; tex = tex->next) {
for (tex = textures_head; tex; tex = tex->next)
{
Gfx_DeleteTexture(&tex->texID);
}
}
static void OnContextRecreated(void* obj) {
Gfx_RecreateDynamicVb(&Models.Vb, VERTEX_FORMAT_TEXTURED, Models.MaxVertices);
}
static void OnInit(void) {
Models.MaxVertices = MODELS_MAX_VERTICES;
RegisterDefaultModels();
OnContextRecreated(NULL);
Models.ClassicArms = Options_GetBool(OPT_CLASSIC_ARM_MODEL, Game_ClassicMode);
Event_Register_(&TextureEvents.FileChanged, NULL, Models_TextureChanged);
Event_Register_(&GfxEvents.ContextLost, NULL, OnContextLost);
Event_Register_(&GfxEvents.ContextRecreated, NULL, OnContextRecreated);
}
static void OnFree(void) {