mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-17 01:31:25 +00:00
Change the matrix interface on RenderState so the backend doesn't have to try detect changes on each Apply
Include the texture matrix in the mesh builder
This commit is contained in:
parent
fd3febaf7a
commit
bc2105eab9
17 changed files with 126 additions and 136 deletions
|
@ -43,6 +43,7 @@ void Mesh::Draw(FRenderState& renderstate)
|
|||
origState.applyData.TextureModeFlags = renderstate.mTextureModeFlags;
|
||||
origState.streamData = renderstate.mStreamData;
|
||||
origState.material = renderstate.mMaterial;
|
||||
origState.textureMatrix.loadIdentity();
|
||||
|
||||
int applyIndex = -1;
|
||||
int depthFunc = -1;
|
||||
|
@ -107,4 +108,5 @@ void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state)
|
|||
renderstate.mTextureModeFlags = state.applyData.TextureModeFlags;
|
||||
renderstate.mStreamData = state.streamData;
|
||||
renderstate.mMaterial = state.material;
|
||||
renderstate.SetTextureMatrix(state.textureMatrix);
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ void MeshBuilder::Apply()
|
|||
state.applyData.TextureModeFlags = mTextureModeFlags;
|
||||
state.streamData = mStreamData;
|
||||
state.material = mMaterial;
|
||||
state.textureMatrix = mTextureMatrix;
|
||||
|
||||
state.streamData.uVertexNormal = FVector4(0.0f, 0.0f, 0.0f, 0.0f); // Grr, this should be part of the vertex!!
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
ApplyData applyData;
|
||||
StreamData streamData;
|
||||
FMaterialState material;
|
||||
VSMatrix textureMatrix;
|
||||
|
||||
bool operator<(const MeshApplyState& other) const
|
||||
{
|
||||
|
@ -43,6 +44,10 @@ public:
|
|||
if (result != 0)
|
||||
return result < 0;
|
||||
|
||||
result = memcmp(&textureMatrix, &other.textureMatrix, sizeof(VSMatrix));
|
||||
if (result != 0)
|
||||
return result < 0;
|
||||
|
||||
result = memcmp(&streamData, &other.streamData, sizeof(StreamData));
|
||||
return result < 0;
|
||||
}
|
||||
|
@ -68,6 +73,8 @@ public:
|
|||
// Buffers
|
||||
int SetViewpoint(const HWViewpointUniforms& vp) override { return 0; }
|
||||
void SetViewpoint(int index) override { }
|
||||
void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) override { }
|
||||
void SetTextureMatrix(const VSMatrix& matrix) override { mTextureMatrix = matrix; }
|
||||
int UploadLights(const FDynLightData& lightdata) override { return -1; }
|
||||
int UploadBones(const TArray<VSMatrix>& bones) override { return -1; }
|
||||
|
||||
|
@ -109,4 +116,6 @@ private:
|
|||
|
||||
TArray<FFlatVertex> mVertices;
|
||||
int mDepthFunc = 0;
|
||||
|
||||
VSMatrix mTextureMatrix = VSMatrix::identity();
|
||||
};
|
||||
|
|
|
@ -228,8 +228,6 @@ protected:
|
|||
uint8_t mTextureEnabled:1;
|
||||
uint8_t mGlowEnabled : 1;
|
||||
uint8_t mGradientEnabled : 1;
|
||||
uint8_t mModelMatrixEnabled : 1;
|
||||
uint8_t mTextureMatrixEnabled : 1;
|
||||
uint8_t mSplitEnabled : 1;
|
||||
uint8_t mBrightmapEnabled : 1;
|
||||
|
||||
|
@ -262,10 +260,6 @@ protected:
|
|||
public:
|
||||
|
||||
uint64_t firstFrame = 0;
|
||||
VSMatrix mModelMatrix;
|
||||
VSMatrix mTextureMatrix;
|
||||
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
|
@ -278,8 +272,6 @@ public:
|
|||
mTextureModeFlags = 0;
|
||||
mStreamData.uDesaturationFactor = 0.0f;
|
||||
mStreamData.uAlphaThreshold = 0.5f;
|
||||
mModelMatrixEnabled = false;
|
||||
mTextureMatrixEnabled = false;
|
||||
mSplitEnabled = false;
|
||||
mStreamData.uAddColor = 0;
|
||||
mStreamData.uObjectColor = 0xffffffff;
|
||||
|
@ -322,8 +314,6 @@ public:
|
|||
#ifdef NPOT_EMULATION
|
||||
mStreamData.uNpotEmulation = { 0,0,0,0 };
|
||||
#endif
|
||||
mModelMatrix.loadIdentity();
|
||||
mTextureMatrix.loadIdentity();
|
||||
ClearClipSplit();
|
||||
}
|
||||
|
||||
|
@ -448,16 +438,6 @@ public:
|
|||
mSplitEnabled = on;
|
||||
}
|
||||
|
||||
void EnableModelMatrix(bool on)
|
||||
{
|
||||
mModelMatrixEnabled = on;
|
||||
}
|
||||
|
||||
void EnableTextureMatrix(bool on)
|
||||
{
|
||||
mTextureMatrixEnabled = on;
|
||||
}
|
||||
|
||||
void SetGlowParams(float *t, float *b)
|
||||
{
|
||||
mStreamData.uGlowTopColor = { t[0], t[1], t[2], t[3] };
|
||||
|
@ -759,6 +739,8 @@ public:
|
|||
// Buffers
|
||||
virtual int SetViewpoint(const HWViewpointUniforms& vp) = 0;
|
||||
virtual void SetViewpoint(int index) = 0;
|
||||
virtual void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) = 0;
|
||||
virtual void SetTextureMatrix(const VSMatrix& matrix) = 0;
|
||||
virtual int UploadLights(const FDynLightData& lightdata) = 0;
|
||||
virtual int UploadBones(const TArray<VSMatrix>& bones) = 0;
|
||||
|
||||
|
|
|
@ -384,11 +384,12 @@ void FSkyVertexBuffer::CreateDome()
|
|||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void FSkyVertexBuffer::SetupMatrices(FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix, bool tiled, float xscale, float yscale)
|
||||
void FSkyVertexBuffer::SetupMatrices(FRenderState& state, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale, float yscale)
|
||||
{
|
||||
float texw = tex->GetDisplayWidth();
|
||||
float texh = tex->GetDisplayHeight();
|
||||
|
||||
VSMatrix modelMatrix;
|
||||
modelMatrix.loadIdentity();
|
||||
modelMatrix.rotate(-180.0f + x_offset, 0.f, 1.f, 0.f);
|
||||
|
||||
|
@ -433,9 +434,16 @@ void FSkyVertexBuffer::SetupMatrices(FGameTexture *tex, float x_offset, float y_
|
|||
modelMatrix.translate(0.f, (-40 + texskyoffset) * skyoffsetfactor, 0.f);
|
||||
modelMatrix.scale(1.f, 0.8f * 1.17f, 1.f);
|
||||
}
|
||||
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
state.SetModelMatrix(modelMatrix, normalModelMatrix);
|
||||
|
||||
VSMatrix textureMatrix;
|
||||
textureMatrix.loadIdentity();
|
||||
textureMatrix.scale(mirror ? -xscale : xscale, yscale, 1.f);
|
||||
textureMatrix.translate(1.f, y_offset / texh, 1.f);
|
||||
state.SetTextureMatrix(textureMatrix);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -461,8 +469,6 @@ void FSkyVertexBuffer::DoRenderDome(FRenderState& state, FGameTexture* tex, int
|
|||
if (tex && tex->isValid())
|
||||
{
|
||||
state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1);
|
||||
state.EnableModelMatrix(true);
|
||||
state.EnableTextureMatrix(true);
|
||||
}
|
||||
|
||||
int rc = mRows + 1;
|
||||
|
@ -494,8 +500,8 @@ void FSkyVertexBuffer::DoRenderDome(FRenderState& state, FGameTexture* tex, int
|
|||
RenderRow(state, DT_TriangleStrip, rc + i, primStart, false);
|
||||
}
|
||||
|
||||
state.EnableTextureMatrix(false);
|
||||
state.EnableModelMatrix(false);
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
}
|
||||
|
||||
|
||||
|
@ -509,7 +515,7 @@ void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float
|
|||
{
|
||||
if (tex)
|
||||
{
|
||||
SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix, tiled, xscale, yscale);
|
||||
SetupMatrices(state, tex, x_offset, y_offset, mirror, mode, tiled, xscale, yscale);
|
||||
}
|
||||
DoRenderDome(state, tex, mode, false, color);
|
||||
}
|
||||
|
@ -526,14 +532,19 @@ void FSkyVertexBuffer::RenderBox(FRenderState& state, FSkyBox* tex, float x_offs
|
|||
int faces;
|
||||
|
||||
state.SetObjectColor(color);
|
||||
state.EnableModelMatrix(true);
|
||||
state.mModelMatrix.loadIdentity();
|
||||
state.mModelMatrix.scale(1, 1 / stretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes.
|
||||
|
||||
VSMatrix modelMatrix;
|
||||
modelMatrix.loadIdentity();
|
||||
modelMatrix.scale(1, 1 / stretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes.
|
||||
|
||||
if (!sky2)
|
||||
state.mModelMatrix.rotate(-180.0f + x_offset, skyrotatevector.X, skyrotatevector.Z, skyrotatevector.Y);
|
||||
modelMatrix.rotate(-180.0f + x_offset, skyrotatevector.X, skyrotatevector.Z, skyrotatevector.Y);
|
||||
else
|
||||
state.mModelMatrix.rotate(-180.0f + x_offset, skyrotatevector2.X, skyrotatevector2.Z, skyrotatevector2.Y);
|
||||
modelMatrix.rotate(-180.0f + x_offset, skyrotatevector2.X, skyrotatevector2.Z, skyrotatevector2.Y);
|
||||
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
state.SetModelMatrix(modelMatrix, normalModelMatrix);
|
||||
|
||||
if (tex->GetSkyFace(5))
|
||||
{
|
||||
|
@ -570,7 +581,7 @@ void FSkyVertexBuffer::RenderBox(FRenderState& state, FSkyBox* tex, float x_offs
|
|||
state.SetMaterial(tex->GetSkyFace(faces + 1), UF_Texture, 0, CLAMP_XY, 0, -1);
|
||||
state.Draw(DT_TriangleStrip, FaceStart(4), 4);
|
||||
|
||||
state.EnableModelMatrix(false);
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
state.SetObjectColor(0xffffffff);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
|
||||
FSkyVertexBuffer(DFrameBuffer* fb);
|
||||
~FSkyVertexBuffer();
|
||||
void SetupMatrices(FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix, bool tiled, float xscale = 0, float vertscale = 0);
|
||||
void SetupMatrices(FRenderState& state, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale = 0, float vertscale = 0);
|
||||
std::pair<IBuffer*, IBuffer*> GetBufferObjects() const
|
||||
{
|
||||
return std::make_pair(mVertexBuffer, nullptr);
|
||||
|
|
|
@ -169,8 +169,13 @@ void Draw2D(F2DDrawer* drawer, FRenderState& state, int x, int y, int width, int
|
|||
{
|
||||
m[4 * 3 + i] = (FLOATTYPE) cmd.transform.Cells[i][2];
|
||||
}
|
||||
state.mModelMatrix.loadMatrix(m);
|
||||
state.EnableModelMatrix(true);
|
||||
|
||||
VSMatrix modelMatrix;
|
||||
modelMatrix.loadMatrix(m);
|
||||
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
state.SetModelMatrix(modelMatrix, normalModelMatrix);
|
||||
}
|
||||
|
||||
if (cmd.mTexture != nullptr && cmd.mTexture->isValid())
|
||||
|
@ -184,10 +189,11 @@ void Draw2D(F2DDrawer* drawer, FRenderState& state, int x, int y, int width, int
|
|||
// Canvas textures are stored upside down
|
||||
if (cmd.mTexture->isHardwareCanvas())
|
||||
{
|
||||
state.mTextureMatrix.loadIdentity();
|
||||
state.mTextureMatrix.scale(1.f, -1.f, 1.f);
|
||||
state.mTextureMatrix.translate(0.f, 1.f, 0.0f);
|
||||
state.EnableTextureMatrix(true);
|
||||
VSMatrix textureMatrix;
|
||||
textureMatrix.loadIdentity();
|
||||
textureMatrix.scale(1.f, -1.f, 1.f);
|
||||
textureMatrix.translate(0.f, 1.f, 0.0f);
|
||||
state.SetTextureMatrix(textureMatrix);
|
||||
}
|
||||
if (cmd.mFlags & F2DDrawer::DTF_Burn)
|
||||
{
|
||||
|
@ -238,8 +244,10 @@ void Draw2D(F2DDrawer* drawer, FRenderState& state, int x, int y, int width, int
|
|||
state.SetObjectColor(0xffffffff);
|
||||
state.SetObjectColor2(0);
|
||||
state.SetAddColor(0);
|
||||
state.EnableTextureMatrix(false);
|
||||
state.EnableModelMatrix(false);
|
||||
if (cmd.mTexture != nullptr && cmd.mTexture->isValid() && cmd.mTexture->isHardwareCanvas())
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
if (cmd.useTransform)
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
state.SetEffect(EFF_NONE);
|
||||
|
||||
}
|
||||
|
|
|
@ -58,61 +58,16 @@ void VkStreamBufferWriter::Reset()
|
|||
VkMatrixBufferWriter::VkMatrixBufferWriter(VulkanRenderDevice* fb)
|
||||
{
|
||||
mBuffer = fb->GetBufferManager()->MatrixBuffer.get();
|
||||
mIdentityMatrix.loadIdentity();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void BufferedSet(bool& modified, T& dst, const T& src)
|
||||
bool VkMatrixBufferWriter::Write(const MatricesUBO& matrices)
|
||||
{
|
||||
if (dst == src)
|
||||
return;
|
||||
dst = src;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
static void BufferedSet(bool& modified, VSMatrix& dst, const VSMatrix& src)
|
||||
{
|
||||
if (memcmp(dst.get(), src.get(), sizeof(FLOATTYPE) * 16) == 0)
|
||||
return;
|
||||
dst = src;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
bool VkMatrixBufferWriter::Write(const VSMatrix& modelMatrix, bool modelMatrixEnabled, const VSMatrix& textureMatrix, bool textureMatrixEnabled)
|
||||
{
|
||||
bool modified = (mOffset == 0); // always modified first call
|
||||
|
||||
if (modelMatrixEnabled)
|
||||
{
|
||||
BufferedSet(modified, mMatrices.ModelMatrix, modelMatrix);
|
||||
if (modified)
|
||||
mMatrices.NormalModelMatrix.computeNormalMatrix(modelMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedSet(modified, mMatrices.ModelMatrix, mIdentityMatrix);
|
||||
BufferedSet(modified, mMatrices.NormalModelMatrix, mIdentityMatrix);
|
||||
}
|
||||
|
||||
if (textureMatrixEnabled)
|
||||
{
|
||||
BufferedSet(modified, mMatrices.TextureMatrix, textureMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
BufferedSet(modified, mMatrices.TextureMatrix, mIdentityMatrix);
|
||||
}
|
||||
|
||||
if (modified)
|
||||
{
|
||||
mOffset = mBuffer->NextStreamDataBlock();
|
||||
if (mOffset == 0xffffffff)
|
||||
return false;
|
||||
|
||||
uint8_t* ptr = (uint8_t*)mBuffer->Data;
|
||||
memcpy(ptr + mOffset, &mMatrices, sizeof(MatricesUBO));
|
||||
}
|
||||
mOffset = mBuffer->NextStreamDataBlock();
|
||||
if (mOffset == 0xffffffff)
|
||||
return false;
|
||||
|
||||
uint8_t* ptr = (uint8_t*)mBuffer->Data;
|
||||
memcpy(ptr + mOffset, &matrices, sizeof(MatricesUBO));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "vulkan/shaders/vk_shader.h"
|
||||
|
||||
class VkStreamBuffer;
|
||||
class VkMatrixBuffer;
|
||||
|
||||
class VkStreamBufferWriter
|
||||
{
|
||||
|
@ -29,14 +28,12 @@ class VkMatrixBufferWriter
|
|||
public:
|
||||
VkMatrixBufferWriter(VulkanRenderDevice* fb);
|
||||
|
||||
bool Write(const VSMatrix& modelMatrix, bool modelMatrixEnabled, const VSMatrix& textureMatrix, bool textureMatrixEnabled);
|
||||
bool Write(const MatricesUBO& matrices);
|
||||
void Reset();
|
||||
|
||||
uint32_t Offset() const { return mOffset; }
|
||||
|
||||
private:
|
||||
VkStreamBuffer* mBuffer;
|
||||
MatricesUBO mMatrices = {};
|
||||
VSMatrix mIdentityMatrix;
|
||||
uint32_t mOffset = 0;
|
||||
};
|
||||
|
|
|
@ -42,6 +42,10 @@ EXTERN_CVAR(Bool, r_skipmats)
|
|||
|
||||
VkRenderState::VkRenderState(VulkanRenderDevice* fb) : fb(fb), mStreamBufferWriter(fb), mMatrixBufferWriter(fb)
|
||||
{
|
||||
mMatrices.ModelMatrix.loadIdentity();
|
||||
mMatrices.NormalModelMatrix.loadIdentity();
|
||||
mMatrices.TextureMatrix.loadIdentity();
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
@ -411,10 +415,14 @@ void VkRenderState::ApplyPushConstants()
|
|||
|
||||
void VkRenderState::ApplyMatrices()
|
||||
{
|
||||
if (!mMatrixBufferWriter.Write(mModelMatrix, mModelMatrixEnabled, mTextureMatrix, mTextureMatrixEnabled))
|
||||
if (mMatricesChanged)
|
||||
{
|
||||
WaitForStreamBuffers();
|
||||
mMatrixBufferWriter.Write(mModelMatrix, mModelMatrixEnabled, mTextureMatrix, mTextureMatrixEnabled);
|
||||
if (!mMatrixBufferWriter.Write(mMatrices))
|
||||
{
|
||||
WaitForStreamBuffers();
|
||||
mMatrixBufferWriter.Write(mMatrices);
|
||||
}
|
||||
mMatricesChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,6 +511,21 @@ void VkRenderState::SetViewpoint(int index)
|
|||
mNeedApply = true;
|
||||
}
|
||||
|
||||
void VkRenderState::SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix)
|
||||
{
|
||||
mMatrices.ModelMatrix = matrix;
|
||||
mMatrices.NormalModelMatrix = normalMatrix;
|
||||
mMatricesChanged = true;
|
||||
mNeedApply = true;
|
||||
}
|
||||
|
||||
void VkRenderState::SetTextureMatrix(const VSMatrix& matrix)
|
||||
{
|
||||
mMatrices.TextureMatrix = matrix;
|
||||
mMatricesChanged = true;
|
||||
mNeedApply = true;
|
||||
}
|
||||
|
||||
int VkRenderState::UploadLights(const FDynLightData& data)
|
||||
{
|
||||
auto buffers = fb->GetBufferManager();
|
||||
|
@ -598,8 +621,6 @@ void VkRenderState::EndRenderPass()
|
|||
mLastViewpointOffset = 0xffffffff;
|
||||
mLastVertexBuffer = nullptr;
|
||||
mLastIndexBuffer = nullptr;
|
||||
mLastModelMatrixEnabled = true;
|
||||
mLastTextureMatrixEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,8 @@ public:
|
|||
// Buffers
|
||||
int SetViewpoint(const HWViewpointUniforms& vp) override;
|
||||
void SetViewpoint(int index) override;
|
||||
void SetModelMatrix(const VSMatrix& matrix, const VSMatrix& normalMatrix) override;
|
||||
void SetTextureMatrix(const VSMatrix& matrix) override;
|
||||
int UploadLights(const FDynLightData& lightdata) override;
|
||||
int UploadBones(const TArray<VSMatrix>& bones) override;
|
||||
|
||||
|
@ -110,8 +112,8 @@ protected:
|
|||
IBuffer* mLastVertexBuffer = nullptr;
|
||||
IBuffer* mLastIndexBuffer = nullptr;
|
||||
|
||||
bool mLastModelMatrixEnabled = true;
|
||||
bool mLastTextureMatrixEnabled = true;
|
||||
MatricesUBO mMatrices = {};
|
||||
bool mMatricesChanged = true;
|
||||
|
||||
int mApplyCount = 0;
|
||||
|
||||
|
|
|
@ -40,6 +40,13 @@ class VSMatrix {
|
|||
loadIdentity();
|
||||
}
|
||||
|
||||
static VSMatrix identity()
|
||||
{
|
||||
VSMatrix m;
|
||||
m.loadIdentity();
|
||||
return m;
|
||||
}
|
||||
|
||||
void translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||
void scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||
void rotate(FLOATTYPE angle, FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||
|
|
|
@ -73,14 +73,15 @@ void FHWModelRenderer::BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf
|
|||
state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CCW : Cull_CW);
|
||||
}
|
||||
|
||||
state.mModelMatrix = objectToWorldMatrix;
|
||||
state.EnableModelMatrix(true);
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(objectToWorldMatrix);
|
||||
state.SetModelMatrix(objectToWorldMatrix, normalModelMatrix);
|
||||
}
|
||||
|
||||
void FHWModelRenderer::EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf)
|
||||
{
|
||||
state.SetBoneIndexBase(-1);
|
||||
state.EnableModelMatrix(false);
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
state.SetDepthFunc(DF_Less);
|
||||
if (!(style == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES))
|
||||
state.SetCulling(Cull_None);
|
||||
|
@ -107,14 +108,15 @@ void FHWModelRenderer::BeginDrawHUDModel(FRenderStyle style, const VSMatrix &obj
|
|||
state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CW : Cull_CCW);
|
||||
}
|
||||
|
||||
state.mModelMatrix = objectToWorldMatrix;
|
||||
state.EnableModelMatrix(true);
|
||||
VSMatrix normalModelMatrix;
|
||||
normalModelMatrix.computeNormalMatrix(objectToWorldMatrix);
|
||||
state.SetModelMatrix(objectToWorldMatrix, normalModelMatrix);
|
||||
}
|
||||
|
||||
void FHWModelRenderer::EndDrawHUDModel(FRenderStyle style)
|
||||
{
|
||||
state.SetBoneIndexBase(-1);
|
||||
state.EnableModelMatrix(false);
|
||||
state.SetModelMatrix(VSMatrix::identity(), VSMatrix::identity());
|
||||
|
||||
state.SetDepthFunc(DF_Less);
|
||||
if (!(style == DefaultRenderStyle()))
|
||||
|
|
|
@ -432,7 +432,6 @@ inline float Dist2(float x1,float y1,float x2,float y2)
|
|||
return sqrtf((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
|
||||
}
|
||||
|
||||
bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * gltexture, VSMatrix &mat);
|
||||
void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata);
|
||||
|
||||
extern const float LARGE_VALUE;
|
||||
|
|
|
@ -57,7 +57,7 @@ CVAR(Int, gl_breaksec, -1, 0)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * gltexture, VSMatrix &dest)
|
||||
bool SetPlaneTextureRotation(FRenderState& state, HWSectorPlane* secplane, FGameTexture* gltexture)
|
||||
{
|
||||
// only manipulate the texture matrix if needed.
|
||||
if (!secplane->Offs.isZero() ||
|
||||
|
@ -80,24 +80,18 @@ bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * g
|
|||
float xscale2 = 64.f / gltexture->GetDisplayWidth();
|
||||
float yscale2 = 64.f / gltexture->GetDisplayHeight();
|
||||
|
||||
dest.loadIdentity();
|
||||
dest.scale(xscale1, yscale1, 1.0f);
|
||||
dest.translate(uoffs, voffs, 0.0f);
|
||||
dest.scale(xscale2, yscale2, 1.0f);
|
||||
dest.rotate(angle, 0.0f, 0.0f, 1.0f);
|
||||
VSMatrix mat;
|
||||
mat.loadIdentity();
|
||||
mat.scale(xscale1, yscale1, 1.0f);
|
||||
mat.translate(uoffs, voffs, 0.0f);
|
||||
mat.scale(xscale2, yscale2, 1.0f);
|
||||
mat.rotate(angle, 0.0f, 0.0f, 1.0f);
|
||||
state.SetTextureMatrix(mat);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetPlaneTextureRotation(FRenderState &state, HWSectorPlane* plane, FGameTexture* texture)
|
||||
{
|
||||
if (hw_SetPlaneTextureRotation(plane, texture, state.mTextureMatrix))
|
||||
{
|
||||
state.EnableTextureMatrix(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==========================================================================
|
||||
|
@ -334,9 +328,10 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent)
|
|||
if (sector->special != GLSector_Skybox)
|
||||
{
|
||||
state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1);
|
||||
SetPlaneTextureRotation(state, &plane, texture);
|
||||
bool texmatrix = SetPlaneTextureRotation(state, &plane, texture);
|
||||
DrawSubsectors(di, state);
|
||||
state.EnableTextureMatrix(false);
|
||||
if (texmatrix)
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
}
|
||||
else if (!hacktype)
|
||||
{
|
||||
|
@ -362,9 +357,10 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent)
|
|||
if (!texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold);
|
||||
else state.AlphaFunc(Alpha_GEqual, 0.f);
|
||||
state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1);
|
||||
SetPlaneTextureRotation(state, &plane, texture);
|
||||
bool texmatrix = SetPlaneTextureRotation(state, &plane, texture);
|
||||
DrawSubsectors(di, state);
|
||||
state.EnableTextureMatrix(false);
|
||||
if (texmatrix)
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
}
|
||||
state.SetRenderStyle(DefaultRenderStyle());
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
EXTERN_CVAR(Int, r_mirror_recursions)
|
||||
EXTERN_CVAR(Bool, gl_portals)
|
||||
|
||||
void SetPlaneTextureRotation(FRenderState& state, HWSectorPlane* plane, FGameTexture* texture);
|
||||
bool SetPlaneTextureRotation(FRenderState& state, HWSectorPlane* plane, FGameTexture* texture);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
|
@ -986,18 +986,19 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state)
|
|||
state.EnableBrightmap(true);
|
||||
state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1);
|
||||
state.SetObjectColor(origin->specialcolor);
|
||||
|
||||
SetPlaneTextureRotation(state, sp, texture);
|
||||
state.AlphaFunc(Alpha_GEqual, 0.f);
|
||||
state.SetRenderStyle(STYLE_Source);
|
||||
|
||||
bool texmatrix = SetPlaneTextureRotation(state, sp, texture);
|
||||
|
||||
for (unsigned i = 0; i < vcount; i += 4)
|
||||
{
|
||||
state.Draw(DT_TriangleStrip, voffset + i, 4, true);// i == 0);
|
||||
}
|
||||
state.Draw(DT_TriangleStrip, voffset + vcount, 10, false);
|
||||
|
||||
state.EnableTextureMatrix(false);
|
||||
if (texmatrix)
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -122,9 +122,6 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state)
|
|||
|
||||
state.SetDepthFunc(DF_LEqual);
|
||||
|
||||
// we use texture coordinates and texture matrix to pass the normal stuff to the shader so that the default vertex buffer format can be used as is.
|
||||
state.EnableTextureMatrix(true);
|
||||
|
||||
// Use sphere mapping for this
|
||||
state.SetEffect(EFF_SPHEREMAP);
|
||||
di->SetColor(state, lightlevel, 0, di->isFullbrightScene(), Colormap, 0.1f);
|
||||
|
@ -138,7 +135,7 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state)
|
|||
flags &= ~HWWall::HWF_GLOW;
|
||||
RenderWall(di, state, HWWall::RWF_BLANK);
|
||||
|
||||
state.EnableTextureMatrix(false);
|
||||
state.SetTextureMatrix(VSMatrix::identity());
|
||||
state.SetEffect(EFF_NONE);
|
||||
state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold);
|
||||
|
||||
|
|
Loading…
Reference in a new issue