diff --git a/src/common/models/model.h b/src/common/models/model.h index 9a4435d396..300661d250 100644 --- a/src/common/models/model.h +++ b/src/common/models/model.h @@ -61,19 +61,15 @@ public: virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; virtual int FindFrame(const char * name) = 0; - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids) = 0; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) = 0; virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; - virtual void AddSkins(uint8_t *hitlist) = 0; + virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) = 0; virtual float getAspectFactor(float vscale) { return 1.f; } void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } void DestroyVertexBuffer(); - const FSpriteModelFrame* curSpriteMDLFrame; - int curMDLIndex; - void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; }; - FString mFileName; private: diff --git a/src/common/models/model_kvx.h b/src/common/models/model_kvx.h index 9f5a0e013e..4c107db5c6 100644 --- a/src/common/models/model_kvx.h +++ b/src/common/models/model_kvx.h @@ -59,8 +59,8 @@ public: bool Load(const char * fn, int lumpnum, const char * buffer, int length) override; void Initialize(); virtual int FindFrame(const char * name) override; - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids) override; - virtual void AddSkins(uint8_t *hitlist) override; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override; + virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override; FTextureID GetPaletteTexture() const { return mPalette; } void BuildVertexBuffer(FModelRenderer *renderer) override; float getAspectFactor(float vscale) override; diff --git a/src/common/models/model_md2.h b/src/common/models/model_md2.h index 50f7e19521..966a38975c 100644 --- a/src/common/models/model_md2.h +++ b/src/common/models/model_md2.h @@ -111,11 +111,11 @@ public: } virtual ~FDMDModel(); - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids); + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) override; + virtual int FindFrame(const char * name) override; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override; virtual void LoadGeometry(); - virtual void AddSkins(uint8_t *hitlist); + virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override; void UnloadGeometry(); void BuildVertexBuffer(FModelRenderer *renderer); diff --git a/src/common/models/model_md3.h b/src/common/models/model_md3.h index 257c41906d..e79a4c98b9 100644 --- a/src/common/models/model_md3.h +++ b/src/common/models/model_md3.h @@ -65,11 +65,11 @@ class FMD3Model : public FModel public: FMD3Model() = default; - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids); + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) override; + virtual int FindFrame(const char * name) override; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override; void LoadGeometry(); void BuildVertexBuffer(FModelRenderer *renderer); - virtual void AddSkins(uint8_t *hitlist); + virtual void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override; }; diff --git a/src/common/models/model_obj.h b/src/common/models/model_obj.h index 38cc0c27c4..a07090900d 100644 --- a/src/common/models/model_obj.h +++ b/src/common/models/model_obj.h @@ -98,9 +98,9 @@ public: ~FOBJModel(); bool Load(const char* fn, int lumpnum, const char* buffer, int length) override; int FindFrame(const char* name) override; - void RenderFrame(FModelRenderer* renderer, FGameTexture* skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids) override; + void RenderFrame(FModelRenderer* renderer, FGameTexture* skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override; void BuildVertexBuffer(FModelRenderer* renderer) override; - void AddSkins(uint8_t* hitlist) override; + void AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) override; }; #endif diff --git a/src/common/models/model_ue1.h b/src/common/models/model_ue1.h index b69e21a1cb..2d29c2eff9 100644 --- a/src/common/models/model_ue1.h +++ b/src/common/models/model_ue1.h @@ -26,9 +26,9 @@ public: bool Load(const char * fn, int lumpnum, const char * buffer, int length) override; int FindFrame(const char * name) override; - void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids) override; + void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) override; void BuildVertexBuffer(FModelRenderer *renderer) override; - void AddSkins(uint8_t *hitlist) override; + void AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) override; void LoadGeometry(); void UnloadGeometry(); FUE1Model() diff --git a/src/common/models/models_md2.cpp b/src/common/models/models_md2.cpp index 84b64ec627..f384723016 100644 --- a/src/common/models/models_md2.cpp +++ b/src/common/models/models_md2.cpp @@ -332,7 +332,7 @@ void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer) // //=========================================================================== -void FDMDModel::AddSkins(uint8_t *hitlist) +void FDMDModel::AddSkins(uint8_t *hitlist, const FTextureID*) { for (int i = 0; i < info.numSkins; i++) { @@ -363,7 +363,7 @@ int FDMDModel::FindFrame(const char * name) // //=========================================================================== -void FDMDModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const TArray&) +void FDMDModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const FTextureID*) { if (frameno >= info.numFrames || frameno2 >= info.numFrames) return; diff --git a/src/common/models/models_md3.cpp b/src/common/models/models_md3.cpp index 9b545dae53..29db7aa6fa 100644 --- a/src/common/models/models_md3.cpp +++ b/src/common/models/models_md3.cpp @@ -302,14 +302,13 @@ void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) // //=========================================================================== -void FMD3Model::AddSkins(uint8_t *hitlist) +void FMD3Model::AddSkins(uint8_t *hitlist, const FTextureID* surfaceskinids) { for (unsigned i = 0; i < Surfaces.Size(); i++) { - int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES; - if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid()) + if (surfaceskinids && surfaceskinids[i].isValid()) { - hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat; + hitlist[surfaceskinids[i].GetIndex()] |= FTextureManager::HIT_Flat; } MD3Surface * surf = &Surfaces[i]; @@ -344,7 +343,7 @@ int FMD3Model::FindFrame(const char * name) // //=========================================================================== -void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const TArray& surfaceskinids) +void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const FTextureID* surfaceskinids) { if ((unsigned)frameno >= Frames.Size() || (unsigned)frameno2 >= Frames.Size()) return; @@ -358,10 +357,9 @@ void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f FGameTexture *surfaceSkin = skin; if (!surfaceSkin) { - int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES; - if (surfaceskinids[ssIndex].isValid()) + if (surfaceskinids && surfaceskinids[i].isValid()) { - surfaceSkin = TexMan.GetGameTexture(surfaceskinids[ssIndex], true); + surfaceSkin = TexMan.GetGameTexture(surfaceskinids[i], true); } else if (surf->numSkins > 0 && surf->Skins[0].isValid()) { diff --git a/src/common/models/models_obj.cpp b/src/common/models/models_obj.cpp index e91f9622c5..5d4aefd3bf 100644 --- a/src/common/models/models_obj.cpp +++ b/src/common/models/models_obj.cpp @@ -628,7 +628,7 @@ int FOBJModel::FindFrame(const char* name) * @param inter The amount to interpolate the two frames. * @param translation The translation for the skin */ -void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const TArray& surfaceskinids) +void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation, const FTextureID* surfaceskinids) { // Prevent the model from rendering if the frame number is < 0 if (frameno < 0 || frameno2 < 0) return; @@ -640,10 +640,9 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f FGameTexture *userSkin = skin; if (!userSkin) { - int ssIndex = i + curMDLIndex * MD3_MAX_SURFACES; - if (i < MD3_MAX_SURFACES && surfaceskinids[ssIndex].isValid()) + if (surfaceskinids && surfaceskinids[i].isValid()) { - userSkin = TexMan.GetGameTexture(surfaceskinids[ssIndex], true); + userSkin = TexMan.GetGameTexture(surfaceskinids[i], true); } else if (surf->skin.isValid()) { @@ -668,18 +667,17 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f * * @param hitlist The list of textures */ -void FOBJModel::AddSkins(uint8_t* hitlist) +void FOBJModel::AddSkins(uint8_t* hitlist, const FTextureID* surfaceskinids) { for (size_t i = 0; i < surfaces.Size(); i++) { - size_t ssIndex = i + curMDLIndex * MD3_MAX_SURFACES; - if (curSpriteMDLFrame && i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid()) + if (surfaceskinids && i < MD3_MAX_SURFACES && surfaceskinids[i].isValid()) { // Precache skins manually reassigned by the user. // On OBJs with lots of skins, such as Doom map OBJs exported from GZDB, // there may be too many skins for the user to manually change, unless // the limit is bumped or surfaceskinIDs is changed to a TArray. - hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat; + hitlist[surfaceskinids[i].GetIndex()] |= FTextureManager::HIT_Flat; return; // No need to precache skin that was replaced } diff --git a/src/common/models/models_ue1.cpp b/src/common/models/models_ue1.cpp index 650d6a7c07..f76f13eff1 100644 --- a/src/common/models/models_ue1.cpp +++ b/src/common/models/models_ue1.cpp @@ -227,7 +227,7 @@ int FUE1Model::FindFrame( const char *name ) return -1; } -void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation, const TArray& surfaceskinids) +void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation, const FTextureID* surfaceskinids) { // the moment of magic if ( (frame >= numFrames) || (frame2 >= numFrames) ) return; @@ -246,9 +246,8 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int f FGameTexture *sskin = skin; if ( !sskin ) { - int ssIndex = groups[i].texNum + curMDLIndex * MD3_MAX_SURFACES; - if (surfaceskinids[ssIndex].isValid()) - sskin = TexMan.GetGameTexture(surfaceskinids[ssIndex], true); + if (surfaceskinids && surfaceskinids[i].isValid()) + sskin = TexMan.GetGameTexture(surfaceskinids[i], true); if ( !sskin ) { vofs += vsize; @@ -305,13 +304,12 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer ) vbuf->UnlockVertexBuffer(); } -void FUE1Model::AddSkins( uint8_t *hitlist ) +void FUE1Model::AddSkins( uint8_t *hitlist, const FTextureID* surfaceskinids) { for (int i = 0; i < numGroups; i++) { - int ssIndex = groups[i].texNum + curMDLIndex * MD3_MAX_SURFACES; - if (curSpriteMDLFrame && curSpriteMDLFrame->surfaceskinIDs[ssIndex].isValid()) - hitlist[curSpriteMDLFrame->surfaceskinIDs[ssIndex].GetIndex()] |= FTextureManager::HIT_Flat; + if (surfaceskinids && surfaceskinids[i].isValid()) + hitlist[surfaceskinids[i].GetIndex()] |= FTextureManager::HIT_Flat; } } diff --git a/src/common/models/models_voxel.cpp b/src/common/models/models_voxel.cpp index 77450941f6..6db0c9e5f9 100644 --- a/src/common/models/models_voxel.cpp +++ b/src/common/models/models_voxel.cpp @@ -356,7 +356,7 @@ void FVoxelModel::BuildVertexBuffer(FModelRenderer *renderer) // //=========================================================================== -void FVoxelModel::AddSkins(uint8_t *hitlist) +void FVoxelModel::AddSkins(uint8_t *hitlist, const FTextureID*) { hitlist[mPalette.GetIndex()] |= FTextureManager::HIT_Flat; } @@ -400,7 +400,7 @@ float FVoxelModel::getAspectFactor(float stretch) // //=========================================================================== -void FVoxelModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const TArray&) +void FVoxelModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation, const FTextureID*) { renderer->SetMaterial(skin, true, translation); renderer->SetupFrame(this, 0, 0, 0); diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 7d85f05c05..81fd60d0c0 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -339,12 +339,13 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr auto tex = skinid.isValid() ? TexMan.GetGameTexture(skinid, true) : nullptr; mdl->BuildVertexBuffer(renderer); - mdl->PushSpriteMDLFrame(smf, i); + auto& ssids = surfaceskinids.Size() > 0 ? surfaceskinids : smf->surfaceskinIDs; + auto ssidp = (unsigned)(i * MD3_MAX_SURFACES) < ssids.Size() ? &ssids[i * MD3_MAX_SURFACES] : nullptr; if (smfNext && modelframe != modelframenext) - mdl->RenderFrame(renderer, tex, modelframe, modelframenext, inter, translation, surfaceskinids.Size() > 0? surfaceskinids : smf->surfaceskinIDs); + mdl->RenderFrame(renderer, tex, modelframe, modelframenext, inter, translation, ssidp); else - mdl->RenderFrame(renderer, tex, modelframe, modelframe, 0.f, translation, surfaceskinids.Size() > 0 ? surfaceskinids : smf->surfaceskinIDs); + mdl->RenderFrame(renderer, tex, modelframe, modelframe, 0.f, translation, ssidp); } } } diff --git a/src/rendering/hwrenderer/hw_precache.cpp b/src/rendering/hwrenderer/hw_precache.cpp index 7ad9192bcc..7ea1ecb388 100644 --- a/src/rendering/hwrenderer/hw_precache.cpp +++ b/src/rendering/hwrenderer/hw_precache.cpp @@ -170,8 +170,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl } else if (smf->modelIDs[i] != -1) { - Models[smf->modelIDs[i]]->PushSpriteMDLFrame(smf, i); - Models[smf->modelIDs[i]]->AddSkins(texhitlist); + Models[smf->modelIDs[i]]->AddSkins(texhitlist, (unsigned)(i * MD3_MAX_SURFACES) < smf->surfaceskinIDs.Size()? &smf->surfaceskinIDs[i * MD3_MAX_SURFACES] : nullptr); } if (smf->modelIDs[i] != -1) {