Skip to content

Commit

Permalink
#5912: Fix unit tests by exposing the buffer start address in client …
Browse files Browse the repository at this point in the history
…memory
  • Loading branch information
codereader committed Mar 12, 2022
1 parent ecb98d9 commit 0b47200
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions include/igeometrystore.h
Expand Up @@ -170,10 +170,12 @@ class IGeometryStore
// The render parameters suitable for rendering surfaces using gl(Multi)DrawElements
struct RenderParameters
{
MeshVertex* bufferStart; // start of buffer (to pass to gl*Pointer)
unsigned int* firstIndex; // first index location of the given geometry
std::size_t indexCount; // index count of the given geometry
std::size_t firstVertex; // offset to the first vertex of this surface
MeshVertex* bufferStart; // start of buffer (to pass to gl*Pointer, usually nullptr)
MeshVertex* clientBufferStart; // start of buffer in client memory
unsigned int* firstIndex; // first index location of the given geometry (to pass to glDraw*)
unsigned int* clientFirstIndex; // first index location of the given geometry in client memory
std::size_t indexCount; // index count of the given geometry
std::size_t firstVertex; // offset to the first vertex of this surface
};

// Returns the information necessary to render the given slot
Expand Down
8 changes: 6 additions & 2 deletions libs/render/GeometryStore.h
Expand Up @@ -246,10 +246,14 @@ class GeometryStore :

auto& current = getCurrentBuffer();

auto indexOffset = current.indices.getOffset(indexSlot);

return RenderParameters
{
nullptr,
static_cast<unsigned int*>(nullptr) + current.indices.getOffset(indexSlot), // pointer to first index
nullptr, // VBO buffer start
current.vertices.getBufferStart(), // client buffer start
static_cast<unsigned int*>(nullptr) + indexOffset, // pointer to first index
current.indices.getBufferStart() + indexOffset, // pointer to first index in client memory
current.indices.getNumUsedElements(indexSlot), // index count of the given geometry
current.vertices.getOffset(vertexSlot) // offset to the first vertex
};
Expand Down
4 changes: 2 additions & 2 deletions test/GeometryStore.cpp
Expand Up @@ -77,11 +77,11 @@ inline void verifyAllocation(render::IGeometryStore& store, render::IGeometrySto
auto renderParms = store.getRenderParameters(slot);

auto expectedIndex = indices.begin();
auto firstVertex = renderParms.bufferStart + renderParms.firstVertex;
auto firstVertex = renderParms.clientBufferStart + renderParms.firstVertex;

EXPECT_EQ(renderParms.indexCount, indices.size()) << "Index count mismatch";

for (auto idxPtr = renderParms.firstIndex; idxPtr < renderParms.firstIndex + renderParms.indexCount; ++idxPtr)
for (auto idxPtr = renderParms.clientFirstIndex; idxPtr < renderParms.clientFirstIndex + renderParms.indexCount; ++idxPtr)
{
auto index = *idxPtr;
EXPECT_EQ(index, *expectedIndex) << "Index disorder";
Expand Down

0 comments on commit 0b47200

Please sign in to comment.