mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-12 05:11:45 +00:00
- fix use after delete
This commit is contained in:
parent
117617aad8
commit
9f8cd68211
5 changed files with 71 additions and 15 deletions
|
@ -76,14 +76,12 @@ void PolyBuffer::Unlock()
|
|||
|
||||
void PolyVertexBuffer::SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs)
|
||||
{
|
||||
for (int j = 0; j < numAttributes; j++)
|
||||
{
|
||||
mOffsets[attrs[j].location] = attrs[j].offset;
|
||||
}
|
||||
mStride = stride;
|
||||
VertexFormat = GetPolyFrameBuffer()->GetRenderState()->GetVertexFormat(numBindingPoints, numAttributes, stride, attrs);
|
||||
}
|
||||
|
||||
void PolyVertexBuffer::Load(PolyTriangleThreadData *thread, const void *vertices, int index)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void PolyVertexInputAssembly::Load(PolyTriangleThreadData *thread, const void *vertices, int index)
|
||||
{
|
||||
const uint8_t *vertex = static_cast<const uint8_t*>(vertices) + mStride * index;
|
||||
const float *attrVertex = reinterpret_cast<const float*>(vertex + mOffsets[VATTR_VERTEX]);
|
||||
|
|
|
@ -39,17 +39,27 @@ private:
|
|||
std::vector<uint32_t> mData;
|
||||
};
|
||||
|
||||
class PolyVertexBuffer : public IVertexBuffer, public PolyBuffer, public PolyInputAssembly
|
||||
class PolyVertexInputAssembly : public PolyInputAssembly
|
||||
{
|
||||
public:
|
||||
size_t mOffsets[VATTR_MAX] = {};
|
||||
size_t mStride = 0;
|
||||
|
||||
int NumBindingPoints;
|
||||
size_t Stride;
|
||||
std::vector<FVertexBufferAttribute> Attrs;
|
||||
int UseVertexData;
|
||||
|
||||
void Load(PolyTriangleThreadData *thread, const void *vertices, int index) override;
|
||||
};
|
||||
|
||||
class PolyVertexBuffer : public IVertexBuffer, public PolyBuffer
|
||||
{
|
||||
public:
|
||||
PolyVertexBuffer() { }
|
||||
void SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs) override;
|
||||
|
||||
void Load(PolyTriangleThreadData *thread, const void *vertices, int index) override;
|
||||
|
||||
private:
|
||||
size_t mOffsets[VATTR_MAX] = {};
|
||||
size_t mStride = 0;
|
||||
PolyVertexInputAssembly *VertexFormat = nullptr;
|
||||
};
|
||||
|
||||
class PolyIndexBuffer : public IIndexBuffer, public PolyBuffer
|
||||
|
|
|
@ -84,13 +84,13 @@ void PolyFrameBuffer::InitializeState()
|
|||
uniformblockalignment = 1;
|
||||
maxuniformblock = 0x7fffffff;
|
||||
|
||||
mRenderState.reset(new PolyRenderState());
|
||||
|
||||
mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight());
|
||||
mSkyData = new FSkyVertexBuffer;
|
||||
mViewpoints = new GLViewpointBuffer;
|
||||
mLights = new FLightBuffer();
|
||||
|
||||
mRenderState.reset(new PolyRenderState());
|
||||
|
||||
CheckCanvas();
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ void PolyRenderState::Apply()
|
|||
|
||||
if (mVertexBuffer) PolyTriangleDrawer::SetVertexBuffer(fb->GetDrawCommands(), mVertexBuffer->Memory());
|
||||
if (mIndexBuffer) PolyTriangleDrawer::SetIndexBuffer(fb->GetDrawCommands(), mIndexBuffer->Memory());
|
||||
PolyTriangleDrawer::SetInputAssembly(fb->GetDrawCommands(), static_cast<PolyVertexBuffer*>(mVertexBuffer));
|
||||
PolyTriangleDrawer::SetInputAssembly(fb->GetDrawCommands(), static_cast<PolyVertexBuffer*>(mVertexBuffer)->VertexFormat);
|
||||
PolyTriangleDrawer::SetRenderStyle(fb->GetDrawCommands(), mRenderStyle);
|
||||
PolyTriangleDrawer::PushStreamData(fb->GetDrawCommands(), mStreamData, constants);
|
||||
ApplyMatrices();
|
||||
|
@ -287,3 +287,48 @@ void PolyRenderState::Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t len
|
|||
PolyTriangleDrawer::SetViewpointUniforms(GetPolyFrameBuffer()->GetDrawCommands(), mViewpointUniforms);
|
||||
}
|
||||
}
|
||||
|
||||
PolyVertexInputAssembly *PolyRenderState::GetVertexFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs)
|
||||
{
|
||||
for (size_t i = 0; i < mVertexFormats.size(); i++)
|
||||
{
|
||||
auto f = mVertexFormats[i].get();
|
||||
if (f->Attrs.size() == (size_t)numAttributes && f->NumBindingPoints == numBindingPoints && f->Stride == stride)
|
||||
{
|
||||
bool matches = true;
|
||||
for (int j = 0; j < numAttributes; j++)
|
||||
{
|
||||
if (memcmp(&f->Attrs[j], &attrs[j], sizeof(FVertexBufferAttribute)) != 0)
|
||||
{
|
||||
matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matches)
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
auto fmt = std::make_unique<PolyVertexInputAssembly>();
|
||||
fmt->NumBindingPoints = numBindingPoints;
|
||||
fmt->Stride = stride;
|
||||
fmt->UseVertexData = 0;
|
||||
for (int j = 0; j < numAttributes; j++)
|
||||
{
|
||||
if (attrs[j].location == VATTR_COLOR)
|
||||
fmt->UseVertexData |= 1;
|
||||
else if (attrs[j].location == VATTR_NORMAL)
|
||||
fmt->UseVertexData |= 2;
|
||||
fmt->Attrs.push_back(attrs[j]);
|
||||
}
|
||||
|
||||
for (int j = 0; j < numAttributes; j++)
|
||||
{
|
||||
fmt->mOffsets[attrs[j].location] = attrs[j].offset;
|
||||
}
|
||||
fmt->mStride = stride;
|
||||
|
||||
mVertexFormats.push_back(std::move(fmt));
|
||||
return mVertexFormats.back().get();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
|
||||
void Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t length);
|
||||
|
||||
PolyVertexInputAssembly *GetVertexFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs);
|
||||
|
||||
private:
|
||||
void Apply();
|
||||
void ApplyMaterial();
|
||||
|
@ -57,6 +59,7 @@ private:
|
|||
bool mFirstMatrixApply = true;
|
||||
|
||||
HWViewpointUniforms *mViewpointUniforms = nullptr;
|
||||
std::vector<std::unique_ptr<PolyVertexInputAssembly>> mVertexFormats;
|
||||
|
||||
bool mDepthClamp = true;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue