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,7 +26,8 @@ static void HeldBlockRenderer_RenderModel(void) {
Gfx_SetFaceCulling(true); Gfx_SetFaceCulling(true);
Gfx_SetDepthTest(false); Gfx_SetDepthTest(false);
/* TODO: Need to properly reallocate per model VB here */
if (Blocks.Draw[held_block] == DRAW_GAS) { if (Blocks.Draw[held_block] == DRAW_GAS) {
model = LocalPlayer_Instance.Base.Model; model = LocalPlayer_Instance.Base.Model;
Vec3_Set(held_entity.ModelScale, 1.0f,1.0f,1.0f); Vec3_Set(held_entity.ModelScale, 1.0f,1.0f,1.0f);

View File

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