Skip to content

Commit

Permalink
#5912: Move WindingRenderer to core binary. It is using the ObjectRen…
Browse files Browse the repository at this point in the history
…derer to submit all its windings now. Fix a couple of bugs.
  • Loading branch information
codereader committed Mar 4, 2022
1 parent e8207fa commit d2edf2e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion radiantcore/rendersystem/backend/OpenGLShader.h
Expand Up @@ -6,7 +6,7 @@
#include "irender.h"
#include "ishaders.h"
#include "string/string.h"
#include "render/WindingRenderer.h"
#include "WindingRenderer.h"
#include "GeometryRenderer.h"
#include "SurfaceRenderer.h"

Expand Down
Expand Up @@ -4,7 +4,8 @@
#include "irender.h"
#include <limits>
#include "iwindingrenderer.h"
#include "CompactWindingVertexBuffer.h"
#include "ObjectRenderer.h"
#include "render/CompactWindingVertexBuffer.h"
#include "debugging/gl.h"

namespace render
Expand Down Expand Up @@ -323,6 +324,7 @@ class WindingRenderer final :
{
_geometryStore.deallocateSlot(bucket.storageHandle);
bucket.storageHandle = InvalidStorageHandle;
bucket.storageCapacity = 0;
}
}
}
Expand Down Expand Up @@ -443,6 +445,7 @@ class WindingRenderer final :
commitDeletions(bucketIndex);
syncWithGeometryStore(bucket);

#if 0
if (bucket.buffer.getVertices().empty()) continue;

const auto& vertices = bucket.buffer.getVertices();
Expand All @@ -467,6 +470,12 @@ class WindingRenderer final :
glDrawElements(primitiveMode, static_cast<GLsizei>(indices.size()), GL_UNSIGNED_INT, &indices.front());

debug::checkGLErrors();
#else
if (bucket.storageHandle == InvalidStorageHandle) continue; // nothing here

auto primitiveMode = RenderingTraits<WindingIndexerT>::Mode();
ObjectRenderer::SubmitGeometry(bucket.storageHandle, primitiveMode, _geometryStore);
#endif
}
}

Expand Down Expand Up @@ -516,7 +525,7 @@ class WindingRenderer final :
return; // no changes
}

auto numberOfStoredWindings = bucket.buffer.getNumberOfStoredWindings();
auto numberOfStoredWindings = static_cast<typename VertexBuffer::Slot>(bucket.buffer.getNumberOfStoredWindings());

if (numberOfStoredWindings == 0)
{
Expand All @@ -525,6 +534,7 @@ class WindingRenderer final :
{
_geometryStore.deallocateSlot(bucket.storageHandle);
bucket.storageHandle = InvalidStorageHandle;
bucket.storageCapacity = 0;
}

bucket.modifiedSlotRange.first = InvalidVertexBufferSlot;
Expand All @@ -535,29 +545,32 @@ class WindingRenderer final :
// Constrain modified range to actual bounds of our vertex storage
if (bucket.modifiedSlotRange.first >= numberOfStoredWindings)
{
bucket.modifiedSlotRange.first = numberOfStoredWindings;
bucket.modifiedSlotRange.first = numberOfStoredWindings - 1;
}

if (bucket.modifiedSlotRange.second >= numberOfStoredWindings)
{
bucket.modifiedSlotRange.second = numberOfStoredWindings;
bucket.modifiedSlotRange.second = numberOfStoredWindings - 1;
}

const auto& vertices = bucket.buffer.getVertices();
const auto& indices = bucket.buffer.getIndices();

// Ensure our storage allocation is large enough
if (bucket.storageCapacity < bucket.buffer.getNumberOfStoredWindings())
if (bucket.storageCapacity < numberOfStoredWindings)
{
// (Re-)allocate a chunk that is large enough
// Release the old one first
if (bucket.storageHandle != InvalidStorageHandle)
{
_geometryStore.deallocateSlot(bucket.storageHandle);
bucket.storageHandle = InvalidStorageHandle;
bucket.storageCapacity = 0;
}

bucket.storageHandle = _geometryStore.allocateSlot(vertices.size(), indices.size());
bucket.storageCapacity = numberOfStoredWindings;

_geometryStore.updateData(bucket.storageHandle, vertices, indices);
}
else
Expand All @@ -568,14 +581,14 @@ class WindingRenderer final :
std::vector<ArbitraryMeshVertex> vertexSubData;

auto firstVertex = bucket.modifiedSlotRange.first * bucket.buffer.getWindingSize();
auto highestVertex = bucket.modifiedSlotRange.second * bucket.buffer.getWindingSize();
auto highestVertex = (bucket.modifiedSlotRange.second + 1) * bucket.buffer.getWindingSize();
vertexSubData.reserve(highestVertex - firstVertex);

std::copy(vertices.begin() + firstVertex, vertices.begin() + highestVertex, std::back_inserter(vertexSubData));

std::vector<unsigned int> indexSubData;
auto firstIndex = bucket.modifiedSlotRange.first * bucket.buffer.getNumIndicesPerWinding();
auto highestIndex = bucket.modifiedSlotRange.second * bucket.buffer.getNumIndicesPerWinding();
auto highestIndex = (bucket.modifiedSlotRange.second + 1) * bucket.buffer.getNumIndicesPerWinding();
indexSubData.reserve(highestIndex - firstIndex);

std::copy(indices.begin() + firstIndex, indices.begin() + highestIndex, std::back_inserter(indexSubData));
Expand Down
1 change: 0 additions & 1 deletion test/WindingRendering.cpp
@@ -1,6 +1,5 @@
#include "gtest/gtest.h"
#include "render/ArbitraryMeshVertex.h"
#include "render/WindingRenderer.h"
#include "render/CompactWindingVertexBuffer.h"

namespace test
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -1017,6 +1017,7 @@
<ClInclude Include="..\..\radiantcore\rendersystem\backend\SurfaceRenderer.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\TextRenderer.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\GeometryStore.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\WindingRenderer.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\debug\SpacePartitionRenderer.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\GLFont.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\LightingModeRenderResult.h" />
Expand Down
3 changes: 3 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -2358,5 +2358,8 @@
<ClInclude Include="..\..\radiantcore\skins\SkinDeclParser.h">
<Filter>src\skins</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\rendersystem\backend\WindingRenderer.h">
<Filter>src\rendersystem\backend</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion tools/msvc/libs.vcxproj
Expand Up @@ -239,7 +239,6 @@
<ClInclude Include="..\..\libs\render\VertexNCb.h" />
<ClInclude Include="..\..\libs\render\VertexNT.h" />
<ClInclude Include="..\..\libs\render\View.h" />
<ClInclude Include="..\..\libs\render\WindingRenderer.h" />
<ClInclude Include="..\..\libs\RGBAImage.h" />
<ClInclude Include="..\..\libs\scenelib.h" />
<ClInclude Include="..\..\libs\selectionlib.h" />
Expand Down
3 changes: 0 additions & 3 deletions tools/msvc/libs.vcxproj.filters
Expand Up @@ -326,9 +326,6 @@
<ClInclude Include="..\..\libs\messages\MapOperationMessage.h">
<Filter>messages</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\render\WindingRenderer.h">
<Filter>render</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\render\CompactWindingVertexBuffer.h">
<Filter>render</Filter>
</ClInclude>
Expand Down

0 comments on commit d2edf2e

Please sign in to comment.