- 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
parent b58e3172fc
commit 67a50d084a
30 changed files with 179 additions and 168 deletions

View file

@ -37,6 +37,7 @@
#include "gl_buffers.h"
#include "gl_renderstate.h"
#include "v_video.h"
#include "flatvertices.h"
namespace OpenGLRenderer
{

View file

@ -23,16 +23,13 @@
#ifndef __GL_RENDERSTATE_H
#define __GL_RENDERSTATE_H
#include <algorithm>
#include <string.h>
#include "gl_interface.h"
#include "matrix.h"
#include "hwrenderer/scene//hw_drawstructs.h"
#include "hw_renderstate.h"
#include "hw_material.h"
#include "c_cvars.h"
#include "r_defs.h"
#include "r_data/r_translate.h"
#include "g_levellocals.h"
namespace OpenGLRenderer
{
@ -110,7 +107,7 @@ public:
void EnableDrawBuffers(int count, bool apply = false) override
{
count = MIN(count, 3);
count = std::min(count, 3);
if (mNumDrawBuffers != count)
{
static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };

View file

@ -33,12 +33,13 @@
#include "engineerrors.h"
#include "cmdlib.h"
#include "md5.h"
#include "m_misc.h"
#include "gl_shader.h"
#include "hw_shaderpatcher.h"
#include "hwrenderer/data/shaderuniforms.h"
#include "shaderuniforms.h"
#include "hw_viewpointuniforms.h"
#include "hw_lightbuffer.h"
#include "i_specialpaths.h"
#include "printf.h"
#include "gl_interface.h"
#include "gl_debug.h"

View file

@ -43,6 +43,12 @@
#include "menu/menu.h"
CUSTOM_CVAR(Int, gl_fogmode, 1, CVAR_ARCHIVE | CVAR_NOINITCALL)
{
if (self > 2) self = 2;
if (self < 0) self = 0;
}
// OpenGL stuff moved here
// GL related CVARs

View file

@ -1,6 +1,5 @@
#pragma once
#include "v_palette.h"
#include "vectors.h"
#include "matrix.h"
#include "hw_material.h"

View file

@ -1652,12 +1652,12 @@ typedef uint8_t lighttable_t; // This could be wider for >8 bit display.
//
//----------------------------------------------------------------------------------
inline bool FBoundingBox::inRange(const line_t *ld) const
inline bool inRange(const FBoundingBox &box, const line_t *ld)
{
return Left() < ld->bbox[BOXRIGHT] &&
Right() > ld->bbox[BOXLEFT] &&
Top() > ld->bbox[BOXBOTTOM] &&
Bottom() < ld->bbox[BOXTOP];
return box.Left() < ld->bbox[BOXRIGHT] &&
box.Right() > ld->bbox[BOXLEFT] &&
box.Top() > ld->bbox[BOXBOTTOM] &&
box.Bottom() < ld->bbox[BOXTOP];
}

View file

@ -875,8 +875,8 @@ void P_NewChaseDir(AActor * actor)
while ((line = it.Next()))
{
if (line->backsector && // Ignore one-sided linedefs
box.inRange(line) &&
box.BoxOnLineSide(line) == -1)
inRange(box, line) &&
BoxOnLineSide(box, line) == -1)
{
double front = line->frontsector->floorplane.ZatPoint(actor->PosRelative(line));
double back = line->backsector->floorplane.ZatPoint(actor->PosRelative(line));

View file

@ -204,7 +204,7 @@ static bool PIT_FindFloorCeiling(FMultiBlockLinesIterator &mit, FMultiBlockLines
{
line_t *ld = cres.line;
if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1)
if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1)
return true;
// A line has been hit
@ -776,7 +776,7 @@ bool PIT_CheckLine(FMultiBlockLinesIterator &mit, FMultiBlockLinesIterator::Chec
line_t *ld = cres.line;
bool rail = false;
if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1)
if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1)
return true;
// A line has been hit
@ -1073,7 +1073,7 @@ static bool PIT_CheckPortal(FMultiBlockLinesIterator &mit, FMultiBlockLinesItera
// if in another vertical section let's just ignore it.
if (cres.portalflags & (FFCF_NOCEILING | FFCF_NOFLOOR)) return false;
if (!box.inRange(cres.line) || box.BoxOnLineSide(cres.line) != -1)
if (!inRange(box, cres.line) || BoxOnLineSide(box, cres.line) != -1)
return false;
line_t *lp = cres.line->getPortalDestination();
@ -1095,7 +1095,7 @@ static bool PIT_CheckPortal(FMultiBlockLinesIterator &mit, FMultiBlockLinesItera
// Check all lines at the destination
while ((ld = it.Next()))
{
if (!pbox.inRange(ld) || pbox.BoxOnLineSide(ld) != -1)
if (!inRange(pbox, ld) || BoxOnLineSide(pbox, ld) != -1)
continue;
if (ld->backsector == NULL)
@ -3453,7 +3453,7 @@ bool FSlide::BounceWall(AActor *mo)
movelen = mo->Vel.XY().Length() * mo->wallbouncefactor;
FBoundingBox box(mo->X(), mo->Y(), mo->radius);
if (box.BoxOnLineSide(line) == -1)
if (BoxOnLineSide(box, line) == -1)
{
DVector2 ofs = deltaangle.ToVector(mo->radius);
DVector3 pos = mo->Vec3Offset(ofs.X, ofs.Y, 0.);

View file

@ -2017,3 +2017,52 @@ subsector_t *FLevelLocals::PointInRenderSubsector (fixed_t x, fixed_t y)
return (subsector_t *)((uint8_t *)node - 1);
}
//==========================================================================
//
// FBoundingBox :: BoxOnLineSide
//
// Considers the line to be infinite
// Returns side 0 or 1, -1 if box crosses the line.
//
//==========================================================================
int BoxOnLineSide(const FBoundingBox &box, const line_t* ld)
{
int p1;
int p2;
if (ld->Delta().X == 0)
{ // ST_VERTICAL
p1 = box.Right() < ld->v1->fX();
p2 = box.Left() < ld->v1->fX();
if (ld->Delta().Y < 0)
{
p1 ^= 1;
p2 ^= 1;
}
}
else if (ld->Delta().Y == 0)
{ // ST_HORIZONTAL:
p1 = box.Top() > ld->v1->fY();
p2 = box.Bottom() > ld->v1->fY();
if (ld->Delta().X < 0)
{
p1 ^= 1;
p2 ^= 1;
}
}
else if ((ld->Delta().X * ld->Delta().Y) >= 0)
{ // ST_POSITIVE:
p1 = P_PointOnLineSide(box.Left(), box.Top(), ld);
p2 = P_PointOnLineSide(box.Right(), box.Bottom(), ld);
}
else
{ // ST_NEGATIVE:
p1 = P_PointOnLineSide(box.Right(), box.Top(), ld);
p2 = P_PointOnLineSide(box.Left(), box.Bottom(), ld);
}
return (p1 == p2) ? p1 : -1;
}

View file

@ -417,4 +417,6 @@ double P_InterceptVector(const divline_t *v2, const divline_t *v1);
#define PT_COMPATIBLE 4
#define PT_DELTA 8 // x2,y2 is passed as a delta, not as an endpoint
int BoxOnLineSide(const FBoundingBox& box, const line_t* ld);
#endif

View file

@ -242,7 +242,7 @@ msecnode_t *P_CreateSecNodeList(AActor *thing, double radius, msecnode_t *sector
while ((ld = it.Next()))
{
if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1)
if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1)
continue;
// This line crosses through the object.
@ -398,7 +398,7 @@ void AActor::UpdateRenderSectorList()
for (auto &p : Level->linePortals)
{
if (p.mType == PORTT_VISUAL) continue;
if (bb.inRange(p.mOrigin) && bb.BoxOnLineSide(p.mOrigin))
if (inRange(bb, p.mOrigin) && BoxOnLineSide(bb, p.mOrigin))
{
touching_lineportallist = P_AddPortalnode(&p, this, touching_lineportallist);
}

View file

@ -1103,7 +1103,7 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd)
DVector2 pos = mobj->PosRelative(ld);
FBoundingBox box(pos.X, pos.Y, mobj->radius);
if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1)
if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1)
{
continue;
}

View file

@ -1079,7 +1079,7 @@ bool FLevelLocals::CollectConnectedGroups(int startgroup, const DVector3 &positi
FBoundingBox box(position.X + disp.pos.X, position.Y + disp.pos.Y, checkradius);
if (!box.inRange(ld) || box.BoxOnLineSide(linkedPortals[i]->mOrigin) != -1) continue; // not touched
if (!inRange(box, ld) || BoxOnLineSide(box, linkedPortals[i]->mOrigin) != -1) continue; // not touched
foundPortals.Push(linkedPortals[i]);
}
bool foundone = true;
@ -1138,7 +1138,7 @@ bool FLevelLocals::CollectConnectedGroups(int startgroup, const DVector3 &positi
line_t *ld;
while ((ld = it.Next()))
{
if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1)
if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1)
continue;
if (!(thisgroup & FPortalGroupArray::LOWER))

View file

@ -4,6 +4,9 @@
#include "basics.h"
#include "m_bbox.h"
struct line_t;
struct sector_t;
struct FPortalGroupArray;
struct portnode_t;
struct subsector_t;

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;
}
//===========================================================================

View file

@ -39,6 +39,7 @@
#include "hw_dynlightdata.h"
#include "hwrenderer/utility/hw_clock.h"
#include "flatvertices.h"
#include "v_palette.h"
#include "hw_lightbuffer.h"
#include "hw_cvars.h"

View file

@ -52,7 +52,7 @@ VSMatrix FHWModelRenderer::GetViewToWorldMatrix()
return objectToWorldMatrix;
}
void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
void FHWModelRenderer::BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
state.SetDepthFunc(DF_LEqual);
state.EnableTexture(true);
@ -60,7 +60,7 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con
// This solves a few of the problems caused by the lack of depth sorting.
// [Nash] Don't do back face culling if explicitly specified in MODELDEF
// TO-DO: Implement proper depth sorting.
if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
if (!(style == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
{
state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CCW : Cull_CW);
}
@ -69,22 +69,22 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con
state.EnableModelMatrix(true);
}
void FHWModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
void FHWModelRenderer::EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf)
{
state.EnableModelMatrix(false);
state.SetDepthFunc(DF_Less);
if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
if (!(style == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
state.SetCulling(Cull_None);
}
void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored)
void FHWModelRenderer::BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
state.SetDepthFunc(DF_LEqual);
// [BB] In case the model should be rendered translucent, do back face culling.
// This solves a few of the problems caused by the lack of depth sorting.
// TO-DO: Implement proper depth sorting.
if (!(actor->RenderStyle == DefaultRenderStyle()))
if (!(style == DefaultRenderStyle()))
{
state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CW : Cull_CCW);
}
@ -93,12 +93,12 @@ void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectTo
state.EnableModelMatrix(true);
}
void FHWModelRenderer::EndDrawHUDModel(AActor *actor)
void FHWModelRenderer::EndDrawHUDModel(FRenderStyle style)
{
state.EnableModelMatrix(false);
state.SetDepthFunc(DF_Less);
if (!(actor->RenderStyle == DefaultRenderStyle()))
if (!(style == DefaultRenderStyle()))
state.SetCulling(Cull_None);
}
@ -136,7 +136,7 @@ void FHWModelRenderer::DrawElements(int numIndices, size_t offset)
void FHWModelRenderer::SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size)
{
auto mdbuff = static_cast<FModelVertexBuffer*>(model->GetVertexBuffer(this));
auto mdbuff = static_cast<FModelVertexBuffer*>(model->GetVertexBuffer(GetType()));
state.SetVertexBuffer(mdbuff->vertexBuffer(), frame1, frame2);
if (mdbuff->indexBuffer()) state.SetIndexBuffer(mdbuff->indexBuffer());
}

View file

@ -28,6 +28,7 @@
#include "r_data/models/models.h"
#include "hwrenderer/data/buffers.h"
#include "hw_modelvertexbuffer.h"
#include "r_data/models/modelrenderer.h"
class HWSprite;
struct HWDrawInfo;
@ -44,12 +45,12 @@ public:
FHWModelRenderer(HWDrawInfo *d, FRenderState &st, int mli) : modellightindex(mli), di(d), state(st)
{}
ModelRendererType GetType() const override { return GLModelRendererType; }
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override;
void BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) override;
IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override;
VSMatrix GetViewToWorldMatrix() override;
void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawHUDModel(AActor *actor) override;
void BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawHUDModel(FRenderStyle style) override;
void SetInterpolation(double interpolation) override;
void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) override;
void DrawArrays(int start, int count) override;

View file

@ -70,13 +70,6 @@ CUSTOM_CVAR(Int, gl_distfog, 70, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
}
}
CUSTOM_CVAR(Int,gl_fogmode,1,CVAR_ARCHIVE|CVAR_NOINITCALL)
{
if (self>2) self=2;
if (self<0) self=0;
}
//==========================================================================
//
// Get current light level

View file

@ -223,7 +223,7 @@ namespace swrenderer
}
}
void SWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
void SWModelRenderer::BeginDrawModel(FRenderStyale style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.Matrix);
@ -261,14 +261,14 @@ namespace swrenderer
SetTransform();
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES))
if (style == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES))
PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, true);
PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, !(mirrored ^ MirrorWorldToClip));
}
void SWModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf)
void SWModelRenderer::EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf)
{
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES))
if (style == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES))
PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false);
PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true);
}
@ -314,7 +314,7 @@ namespace swrenderer
return objectToWorld;
}
void SWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored)
void SWModelRenderer::BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored)
{
const_cast<VSMatrix &>(objectToWorldMatrix).copy(ObjectToWorld.Matrix);
ClipTop = {};
@ -322,16 +322,16 @@ namespace swrenderer
SetTransform();
PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, true);
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal])
if (style == LegacyRenderStyles[STYLE_Normal])
PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, true);
PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, !(mirrored ^ MirrorWorldToClip));
}
void SWModelRenderer::EndDrawHUDModel(AActor *actor)
void SWModelRenderer::EndDrawHUDModel(FRenderStyle style)
{
PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false);
if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal])
if (style == LegacyRenderStyles[STYLE_Normal])
PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false);
PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true);
}

View file

@ -63,12 +63,12 @@ namespace swrenderer
ModelRendererType GetType() const override { return SWModelRendererType; }
void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override;
void BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) override;
IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override;
VSMatrix GetViewToWorldMatrix() override;
void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawHUDModel(AActor *actor) override;
void BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) override;
void EndDrawHUDModel(FRenderStyle style) override;
void SetInterpolation(double interpolation) override;
void SetMaterial(FTexture *skin, bool clampNoFilter, int translation) override;
void DrawArrays(int start, int count) override;

View file

@ -47,51 +47,3 @@ void FBoundingBox::AddToBox (const DVector2 &pos)
m_Box[BOXTOP] = pos.Y;
}
//==========================================================================
//
// FBoundingBox :: BoxOnLineSide
//
// Considers the line to be infinite
// Returns side 0 or 1, -1 if box crosses the line.
//
//==========================================================================
int FBoundingBox::BoxOnLineSide (const line_t *ld) const
{
int p1;
int p2;
if (ld->Delta().X == 0)
{ // ST_VERTICAL
p1 = m_Box[BOXRIGHT] < ld->v1->fX();
p2 = m_Box[BOXLEFT] < ld->v1->fX();
if (ld->Delta().Y < 0)
{
p1 ^= 1;
p2 ^= 1;
}
}
else if (ld->Delta().Y == 0)
{ // ST_HORIZONTAL:
p1 = m_Box[BOXTOP] > ld->v1->fY();
p2 = m_Box[BOXBOTTOM] > ld->v1->fY();
if (ld->Delta().X < 0)
{
p1 ^= 1;
p2 ^= 1;
}
}
else if ((ld->Delta().X * ld->Delta().Y) >= 0)
{ // ST_POSITIVE:
p1 = P_PointOnLineSide (m_Box[BOXLEFT], m_Box[BOXTOP], ld);
p2 = P_PointOnLineSide (m_Box[BOXRIGHT], m_Box[BOXBOTTOM], ld);
}
else
{ // ST_NEGATIVE:
p1 = P_PointOnLineSide (m_Box[BOXRIGHT], m_Box[BOXTOP], ld);
p2 = P_PointOnLineSide (m_Box[BOXLEFT], m_Box[BOXBOTTOM], ld);
}
return (p1 == p2) ? p1 : -1;
}

View file

@ -31,9 +31,6 @@
#include "vectors.h"
#include "m_fixed.h"
struct line_t;
struct node_t;
enum
{
BOXTOP,
@ -95,10 +92,6 @@ public:
inline double Left () const { return m_Box[BOXLEFT]; }
inline double Right () const { return m_Box[BOXRIGHT]; }
bool inRange(const line_t *ld) const;
int BoxOnLineSide (const line_t *ld) const;
void Set(int index, double value) {m_Box[index] = value;}
protected: