Upload vertices to vertex buffers
This commit is contained in:
parent
26dcb77f5e
commit
a5a0279fd2
3 changed files with 40 additions and 1 deletions
|
|
@ -1,11 +1,37 @@
|
|||
|
||||
#include "hw_mesh.h"
|
||||
#include "v_video.h"
|
||||
|
||||
#define USE_MESH_VERTEX_BUFFER
|
||||
|
||||
void Mesh::Draw(FRenderState& renderstate)
|
||||
{
|
||||
#ifdef USE_MESH_VERTEX_BUFFER
|
||||
|
||||
if (!mVertexBuffer && mVertices.Size() != 0)
|
||||
{
|
||||
mVertexBuffer.reset(screen->CreateVertexBuffer());
|
||||
mVertexBuffer->SetData(mVertices.Size() * sizeof(FFlatVertex), mVertices.Data(), BufferUsageType::Static);
|
||||
|
||||
static const FVertexBufferAttribute format[] =
|
||||
{
|
||||
{ 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FFlatVertex, x) },
|
||||
{ 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FFlatVertex, u) },
|
||||
{ 0, VATTR_LIGHTMAP, VFmt_Float3, (int)myoffsetof(FFlatVertex, lu) },
|
||||
};
|
||||
mVertexBuffer->SetFormat(1, 3, sizeof(FFlatVertex), format);
|
||||
}
|
||||
|
||||
if (mVertexBuffer)
|
||||
renderstate.SetVertexBuffer(mVertexBuffer.get(), 0, 0);
|
||||
|
||||
#else
|
||||
|
||||
auto pair = renderstate.AllocVertices(mVertices.Size());
|
||||
memcpy(pair.first, mVertices.Data(), mVertices.Size() * sizeof(FFlatVertex));
|
||||
|
||||
#endif
|
||||
|
||||
MeshApplyState origState;
|
||||
origState.RenderStyle = renderstate.mRenderStyle;
|
||||
origState.SpecialEffect = renderstate.mSpecialEffect;
|
||||
|
|
@ -42,9 +68,19 @@ void Mesh::Draw(FRenderState& renderstate)
|
|||
applyIndex = cmd.ApplyIndex;
|
||||
Apply(renderstate, mApplys[cmd.ApplyIndex]);
|
||||
}
|
||||
|
||||
#ifdef USE_MESH_VERTEX_BUFFER
|
||||
renderstate.Draw(cmd.DrawType, cmd.Start, cmd.Count, apply);
|
||||
#else
|
||||
renderstate.Draw(cmd.DrawType, pair.second + cmd.Start, cmd.Count, apply);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_MESH_VERTEX_BUFFER
|
||||
if (mVertexBuffer)
|
||||
renderstate.SetVertexBuffer(screen->mVertexData);
|
||||
#endif
|
||||
|
||||
for (const MeshDrawCommand& cmd : mIndexedDraws)
|
||||
{
|
||||
bool apply = applyIndex != cmd.ApplyIndex;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ private:
|
|||
TArray<MeshDrawCommand> mDraws;
|
||||
TArray<MeshDrawCommand> mIndexedDraws;
|
||||
TArray<FFlatVertex> mVertices;
|
||||
std::unique_ptr<IVertexBuffer> mVertexBuffer;
|
||||
|
||||
friend class MeshBuilder;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ void HWMeshCache::Update(FRenderViewpoint& vp)
|
|||
}
|
||||
}
|
||||
|
||||
// Refresh 10 sectors per frame. Shouldn't be needed but for some reason some initial flats are black!!
|
||||
#if 0
|
||||
// Refresh 10 sectors per frame.
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (nextRefresh < count)
|
||||
|
|
@ -54,6 +55,7 @@ void HWMeshCache::Update(FRenderViewpoint& vp)
|
|||
if (count > 0)
|
||||
nextRefresh = (nextRefresh + 1) % count;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update changed sectors
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue