From 0b4720035713d69fee0c21275673fa02a1b88dd8 Mon Sep 17 00:00:00 2001 From: codereader Date: Sat, 12 Mar 2022 08:15:04 +0100 Subject: [PATCH] #5912: Fix unit tests by exposing the buffer start address in client memory --- include/igeometrystore.h | 10 ++++++---- libs/render/GeometryStore.h | 8 ++++++-- test/GeometryStore.cpp | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/igeometrystore.h b/include/igeometrystore.h index 2a76885545..ac154cc741 100644 --- a/include/igeometrystore.h +++ b/include/igeometrystore.h @@ -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 diff --git a/libs/render/GeometryStore.h b/libs/render/GeometryStore.h index 80ce43eca9..6e298ba0cb 100644 --- a/libs/render/GeometryStore.h +++ b/libs/render/GeometryStore.h @@ -246,10 +246,14 @@ class GeometryStore : auto& current = getCurrentBuffer(); + auto indexOffset = current.indices.getOffset(indexSlot); + return RenderParameters { - nullptr, - static_cast(nullptr) + current.indices.getOffset(indexSlot), // pointer to first index + nullptr, // VBO buffer start + current.vertices.getBufferStart(), // client buffer start + static_cast(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 }; diff --git a/test/GeometryStore.cpp b/test/GeometryStore.cpp index d515e770bb..2281a04663 100644 --- a/test/GeometryStore.cpp +++ b/test/GeometryStore.cpp @@ -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";