- took the game dependent model render functions out of the FModelRenderer class.

This makes FModelRenderer game independent - the 3 functions in question may just be global functions instead.
This commit is contained in:
Christoph Oelckers 2020-04-27 00:25:53 +02:00
parent 6afa73bdcd
commit 8ea0a0c5f8
5 changed files with 23 additions and 17 deletions

View file

@ -57,7 +57,10 @@ extern TDeletingArray<FVoxelDef *> VoxelDefs;
TDeletingArray<FModel*> Models;
void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, double ticFrac)
void RenderFrameModels(FModelRenderer* renderer, FLevelLocals* Level, const FSpriteModelFrame* smf, const FState* curState, const int curTics, const PClass* ti, int translation);
void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, double ticFrac)
{
// Setup transformation.
@ -174,12 +177,12 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s
float orientation = scaleFactorX * scaleFactorY * scaleFactorZ;
BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0);
RenderFrameModels(actor->Level, smf, actor->state, actor->tics, actor->GetClass(), translation);
EndDrawModel(actor->RenderStyle, smf);
renderer->BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0);
RenderFrameModels(renderer, actor->Level, smf, actor->state, actor->tics, actor->GetClass(), translation);
renderer->EndDrawModel(actor->RenderStyle, smf);
}
void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY)
void RenderHUDModel(FModelRenderer *renderer, DPSprite *psp, float ofsX, float ofsY)
{
AActor * playermo = players[consoleplayer].camera;
FSpriteModelFrame *smf = FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetSprite(), psp->GetFrame(), false);
@ -190,7 +193,7 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY)
// The model position and orientation has to be drawn independently from the position of the player,
// but we need to position it correctly in the world for light to work properly.
VSMatrix objectToWorldMatrix = GetViewToWorldMatrix();
VSMatrix objectToWorldMatrix = renderer->GetViewToWorldMatrix();
// Scaling model (y scale for a sprite means height, i.e. z in the world!).
objectToWorldMatrix.scale(smf->xscale, smf->zscale, smf->yscale);
@ -212,12 +215,12 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY)
float orientation = smf->xscale * smf->yscale * smf->zscale;
BeginDrawHUDModel(playermo->RenderStyle, objectToWorldMatrix, orientation < 0);
RenderFrameModels(playermo->Level, smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), psp->Flags & PSPF_PLAYERTRANSLATED ? psp->Owner->mo->Translation : 0);
EndDrawHUDModel(playermo->RenderStyle);
renderer->BeginDrawHUDModel(playermo->RenderStyle, objectToWorldMatrix, orientation < 0);
RenderFrameModels(renderer, playermo->Level, smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), psp->Flags & PSPF_PLAYERTRANSLATED ? psp->Owner->mo->Translation : 0);
renderer->EndDrawHUDModel(playermo->RenderStyle);
}
void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation)
void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation)
{
// [BB] Frame interpolation: Find the FSpriteModelFrame smfNext which follows after smf in the animation
// and the scalar value inter ( element of [0,1) ), both necessary to determine the interpolated frame.
@ -271,14 +274,14 @@ void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFr
{
FModel * mdl = Models[smf->modelIDs[i]];
auto tex = smf->skinIDs[i].isValid() ? TexMan.GetGameTexture(smf->skinIDs[i], true) : nullptr;
mdl->BuildVertexBuffer(this);
mdl->BuildVertexBuffer(renderer);
mdl->PushSpriteMDLFrame(smf, i);
if (smfNext && smf->modelframes[i] != smfNext->modelframes[i])
mdl->RenderFrame(this, tex, smf->modelframes[i], smfNext->modelframes[i], inter, translation);
mdl->RenderFrame(renderer, tex, smf->modelframes[i], smfNext->modelframes[i], inter, translation);
else
mdl->RenderFrame(this, tex, smf->modelframes[i], smf->modelframes[i], 0.f, translation);
mdl->RenderFrame(renderer, tex, smf->modelframes[i], smf->modelframes[i], 0.f, translation);
}
}
}

View file

@ -441,4 +441,7 @@ void BSPWalkCircle(FLevelLocals *Level, float x, float y, float radiusSquared, c
BSPNodeWalkCircle(Level->HeadNode(), x, y, radiusSquared, callback);
}
void RenderModel(FModelRenderer* renderer, float x, float y, float z, FSpriteModelFrame* smf, AActor* actor, double ticFrac);
void RenderHUDModel(FModelRenderer* renderer, DPSprite* psp, float ofsX, float ofsY);
#endif

View file

@ -293,7 +293,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent)
else
{
FHWModelRenderer renderer(di, state, dynlightindex);
renderer.RenderModel(x, y, z, modelframe, actor, di->Viewpoint.TicFrac);
RenderModel(&renderer, x, y, z, modelframe, actor, di->Viewpoint.TicFrac);
state.SetVertexBuffer(screen->mVertexData);
}
}

View file

@ -89,7 +89,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state)
state.AlphaFunc(Alpha_GEqual, 0);
FHWModelRenderer renderer(this, state, huds->lightindex);
renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my);
RenderHUDModel(&renderer, huds->weapon, huds->mx, huds->my);
state.SetVertexBuffer(screen->mVertexData);
}
else

View file

@ -94,7 +94,7 @@ namespace swrenderer
renderer.Translation = actor->Translation;
renderer.AddLights(actor);
renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac);
RenderModel(&renderer, x, y, z, smf, actor, r_viewpoint.TicFrac);
PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
#endif
}
@ -143,7 +143,7 @@ namespace swrenderer
renderer.fillcolor = fullbrightSprite ? ThingColor : ThingColor.Modulate(playermo->Sector->SpecialColors[sector_t::sprites]);
renderer.Translation = 0xffffffff;// playermo->Translation;
renderer.RenderHUDModel(psp, ofsx, ofsy);
RenderHUDModel(&renderer, psp, ofsx, ofsy);
PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f);
#endif
}