vk: studio: handle first half of entity reuse

Detect whether studio model has changed, and replace it with a new one.
It does (as predicted) run into a gpu sync issue if reuse happened while previous frame with the old user is still being drawn.
This commit is contained in:
Ivan 'provod' Avdeev 2023-08-25 13:44:53 -04:00 committed by Ivan Avdeev
parent 567d014ada
commit c42cf2088c
4 changed files with 7 additions and 13 deletions

View File

@ -44,7 +44,7 @@ void VK_EntityDataSet(const struct cl_entity_s* entity, void *userdata, entity_d
entry->dtor(entry->userdata);
entry->userdata = userdata;
entry->dtor = dtor;
break;
return;
}
}

View File

@ -2198,6 +2198,7 @@ static void studioEntityModelDestroy(void *userdata) {
static r_studio_entity_model_t *studioEntityModelCreate(const cl_entity_t *entity) {
r_studio_entity_model_t *const entmodel = Mem_Calloc(vk_core.pool, sizeof(r_studio_entity_model_t));
entmodel->studio_header = m_pStudioHeader;
entmodel->num_submodels = m_pStudioHeader->numbodyparts; // TODO is this correct number?
entmodel->submodels = Mem_Calloc(vk_core.pool, sizeof(*entmodel->submodels) * entmodel->num_submodels);
@ -2211,7 +2212,7 @@ static r_studio_entity_model_t *studioEntityModelCreate(const cl_entity_t *entit
static r_studio_entity_model_t *studioEntityModelGet(const cl_entity_t* entity) {
r_studio_entity_model_t *entmodel = (r_studio_entity_model_t*)VK_EntityDataGet(entity);
if (entmodel)
if (entmodel && entmodel->studio_header == m_pStudioHeader)
return entmodel;
entmodel = studioEntityModelCreate(entity);

View File

@ -41,7 +41,8 @@ static struct {
void studioRenderSubmodelDestroy( r_studio_render_submodel_t *submodel ) {
R_RenderModelDestroy(&submodel->model);
R_GeometryRangeFree(&submodel->geometry_range);
Mem_Free(submodel->geometries);
if (submodel->geometries)
Mem_Free(submodel->geometries);
submodel->geometries = NULL;
submodel->geometries_count = 0;
submodel->vertex_count = 0;

View File

@ -62,19 +62,16 @@ void VK_StudioModelInit(void);
// Entity model cache/pool
typedef struct {
const studiohdr_t *studio_header;
const r_studio_model_info_t *model_info;
// ??? probably unnecessary matrix3x4 transform;
matrix3x4 prev_transform;
// TODO vec3_t *prev_verts;
// FIXME this is bodyparts, not submodels. Body parts can theoretically switch submodels used at runtime.
int num_submodels;
r_studio_render_submodel_t *submodels;
// TODO: coalesce submodels into as few allocations as possible
//vk_render_model_t render_model;
//r_geometry_range_t geometry_range;
//vk_render_geometry_t *geometries;
} r_studio_entity_model_t;
//r_studio_entity_model_t *studioEntityModelGet(const cl_entity_t *ent);
@ -83,11 +80,6 @@ typedef struct {
//void studioEntityModelClear(void);
// TODO need:
// 1. studio entity:
// - transform
// - tracks visited submodels. clears on next frame / m_pStudioHeader set/entity draw
void studioRenderSubmodelDestroy( r_studio_render_submodel_t *submodel );
r_studio_model_info_t *getStudioModelInfo(model_t *model);