- started cleanup of model code.

* refactored FBoundingBox so that the game dependent members are global functions now.
* changed some methods of the model renderer to take a render style parameter instead of a full actor.
This commit is contained in:
Christoph Oelckers 2020-04-27 00:03:23 +02:00
commit 67a50d084a
30 changed files with 179 additions and 168 deletions

View file

@ -0,0 +1,37 @@
#include "models.h"
#include "actor.h"
#include "p_pspr.h"
#include "info.h"
#include "g_levellocals.h"
class FModelRenderer
{
public:
virtual ~FModelRenderer() { }
void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac);
void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy);
virtual ModelRendererType GetType() const = 0;
virtual void BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0;
virtual void EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) = 0;
virtual IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) = 0;
virtual VSMatrix GetViewToWorldMatrix() = 0;
virtual void BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0;
virtual void EndDrawHUDModel(FRenderStyle style) = 0;
virtual void SetInterpolation(double interpolation) = 0;
virtual void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) = 0;
virtual void DrawArrays(int start, int count) = 0;
virtual void DrawElements(int numIndices, size_t offset) = 0;
virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0;
private:
void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation);
};

View file

@ -43,6 +43,7 @@
#include "r_data/models/models_obj.h"
#include "i_time.h"
#include "texturemanager.h"
#include "modelrenderer.h"
#ifdef _MSC_VER
#pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data
@ -168,14 +169,14 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s
objectToWorldMatrix.rotate(-smf->rolloffset, 1, 0, 0);
// consider the pixel stretching. For non-voxels this must be factored out here
float stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level) : 1.f) / actor->Level->info->pixelstretch;
float stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch;
objectToWorldMatrix.scale(1, stretch, 1);
float orientation = scaleFactorX * scaleFactorY * scaleFactorZ;
BeginDrawModel(actor, smf, objectToWorldMatrix, orientation < 0);
BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0);
RenderFrameModels(actor->Level, smf, actor->state, actor->tics, actor->GetClass(), translation);
EndDrawModel(actor, smf);
EndDrawModel(actor->RenderStyle, smf);
}
void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY)
@ -211,9 +212,9 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY)
float orientation = smf->xscale * smf->yscale * smf->zscale;
BeginDrawHUDModel(playermo, objectToWorldMatrix, orientation < 0);
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);
EndDrawHUDModel(playermo->RenderStyle);
}
void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation)

View file

@ -25,14 +25,14 @@
#include "tarray.h"
#include "matrix.h"
#include "actor.h"
#include "dobject.h"
#include "p_pspr.h"
#include "r_data/voxels.h"
#include "info.h"
#include "m_bbox.h"
#include "r_defs.h"
#include "g_levellocals.h"
#include "r_data/voxels.h"
#include "i_modelvertexbuffer.h"
class FModelRenderer;
#define MAX_LODS 4
enum { VX, VZ, VY };
@ -58,36 +58,6 @@ enum ModelRendererType
NumModelRendererTypes
};
class FModelRenderer
{
public:
virtual ~FModelRenderer() { }
void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac);
void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy);
virtual ModelRendererType GetType() const = 0;
virtual void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0;
virtual void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) = 0;
virtual IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) = 0;
virtual VSMatrix GetViewToWorldMatrix() = 0;
virtual void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0;
virtual void EndDrawHUDModel(AActor *actor) = 0;
virtual void SetInterpolation(double interpolation) = 0;
virtual void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) = 0;
virtual void DrawArrays(int start, int count) = 0;
virtual void DrawElements(int numIndices, size_t offset) = 0;
virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0;
private:
void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation);
};
class FModel
{
public:
@ -99,10 +69,10 @@ public:
virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0;
virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0;
virtual void AddSkins(uint8_t *hitlist) = 0;
virtual float getAspectFactor(FLevelLocals *) { return 1.f; }
virtual float getAspectFactor(float vscale) { return 1.f; }
void SetVertexBuffer(FModelRenderer *renderer, IModelVertexBuffer *buffer) { mVBuf[renderer->GetType()] = buffer; }
IModelVertexBuffer *GetVertexBuffer(FModelRenderer *renderer) const { return mVBuf[renderer->GetType()]; }
void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; }
IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; }
void DestroyVertexBuffer();
const FSpriteModelFrame *curSpriteMDLFrame;
@ -368,7 +338,7 @@ public:
virtual void AddSkins(uint8_t *hitlist);
FTextureID GetPaletteTexture() const { return mPalette; }
void BuildVertexBuffer(FModelRenderer *renderer);
float getAspectFactor(FLevelLocals *) override;
float getAspectFactor(float vscale) override;
};

View file

@ -29,6 +29,7 @@
#include "filesystem.h"
#include "r_data/models/models.h"
#include "texturemanager.h"
#include "modelrenderer.h"
#ifdef _MSC_VER
#pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data
@ -280,7 +281,7 @@ FDMDModel::~FDMDModel()
void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer)
{
if (!GetVertexBuffer(renderer))
if (!GetVertexBuffer(renderer->GetType()))
{
LoadGeometry();
@ -288,7 +289,7 @@ void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer)
unsigned int vindex = 0;
auto vbuf = renderer->CreateVertexBuffer(false, info.numFrames == 1);
SetVertexBuffer(renderer, vbuf);
SetVertexBuffer(renderer->GetType(), vbuf);
FModelVertex *vertptr = vbuf->LockVertexBuffer(VertexBufferSize);

View file

@ -24,6 +24,7 @@
#include "cmdlib.h"
#include "r_data/models/models.h"
#include "texturemanager.h"
#include "modelrenderer.h"
#define MAX_QPATH 64
@ -239,7 +240,7 @@ void FMD3Model::LoadGeometry()
void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer)
{
if (!GetVertexBuffer(renderer))
if (!GetVertexBuffer(renderer->GetType()))
{
LoadGeometry();
@ -254,7 +255,7 @@ void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer)
}
auto vbuf = renderer->CreateVertexBuffer(true, Frames.Size() == 1);
SetVertexBuffer(renderer, vbuf);
SetVertexBuffer(renderer->GetType(), vbuf);
FModelVertex *vertptr = vbuf->LockVertexBuffer(vbufsize);
unsigned int *indxptr = vbuf->LockIndexBuffer(ibufsize);

View file

@ -22,6 +22,7 @@
#include "filesystem.h"
#include "r_data/models/models_obj.h"
#include "texturemanager.h"
#include "modelrenderer.h"
/**
* Load an OBJ model
@ -355,7 +356,7 @@ int FOBJModel::ResolveIndex(int origIndex, FaceElement el)
*/
void FOBJModel::BuildVertexBuffer(FModelRenderer *renderer)
{
if (GetVertexBuffer(renderer))
if (GetVertexBuffer(renderer->GetType()))
{
return;
}
@ -375,7 +376,7 @@ void FOBJModel::BuildVertexBuffer(FModelRenderer *renderer)
}
auto vbuf = renderer->CreateVertexBuffer(false,true);
SetVertexBuffer(renderer, vbuf);
SetVertexBuffer(renderer->GetType(), vbuf);
FModelVertex *vertptr = vbuf->LockVertexBuffer(vbufsize);

View file

@ -24,6 +24,7 @@
#include "cmdlib.h"
#include "r_data/models/models_ue1.h"
#include "texturemanager.h"
#include "modelrenderer.h"
float unpackuvert( uint32_t n, int c )
{
@ -255,7 +256,7 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int f
void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer )
{
if (GetVertexBuffer(renderer))
if (GetVertexBuffer(renderer->GetType()))
return;
if ( !mDataLoaded )
LoadGeometry();
@ -264,7 +265,7 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer )
vsize += groups[i].numPolys*3;
vsize *= numFrames;
auto vbuf = renderer->CreateVertexBuffer(false,numFrames==1);
SetVertexBuffer(renderer, vbuf);
SetVertexBuffer(renderer->GetType(), vbuf);
FModelVertex *vptr = vbuf->LockVertexBuffer(vsize);
int vidx = 0;
for ( int i=0; i<numFrames; i++ )

View file

@ -34,6 +34,7 @@
#include "models.h"
#include "image.h"
#include "texturemanager.h"
#include "modelrenderer.h"
#ifdef _MSC_VER
#pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data
@ -319,12 +320,12 @@ void FVoxelModel::Initialize()
void FVoxelModel::BuildVertexBuffer(FModelRenderer *renderer)
{
if (!GetVertexBuffer(renderer))
if (!GetVertexBuffer(renderer->GetType()))
{
Initialize();
auto vbuf = renderer->CreateVertexBuffer(true, true);
SetVertexBuffer(renderer, vbuf);
SetVertexBuffer(renderer->GetType(), vbuf);
FModelVertex *vertptr = vbuf->LockVertexBuffer(mVertices.Size());
unsigned int *indxptr = vbuf->LockIndexBuffer(mIndices.Size());
@ -384,9 +385,9 @@ int FVoxelModel::FindFrame(const char * name)
//
//===========================================================================
float FVoxelModel::getAspectFactor(FLevelLocals *Level)
float FVoxelModel::getAspectFactor(float stretch)
{
return Level->info->pixelstretch;
return stretch;
}
//===========================================================================