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
96ac7ba3f0
commit
eba0bee9f6
17 changed files with 126 additions and 136 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue