1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
|
#include "gtest/gtest.h"
#include <limits>
#include <numeric>
#include <random>
#include "render/GeometryStore.h"
#include "testutil/TestBufferObjectProvider.h"
#include "testutil/TestSyncObjectProvider.h"
#include "testutil/RenderUtils.h"
namespace test
{
namespace
{
TestBufferObjectProvider _testBufferObjectProvider;
inline void verifyAllocation(render::IGeometryStore& store, render::IGeometryStore::Slot slot,
const std::vector<render::RenderVertex>& vertices, const std::vector<unsigned int>& indices)
{
auto renderParms = store.getBufferAddresses(slot);
auto expectedIndex = indices.begin();
auto firstVertex = renderParms.clientBufferStart + renderParms.firstVertex;
EXPECT_EQ(renderParms.indexCount, indices.size()) << "Index count mismatch";
for (auto idxPtr = renderParms.clientFirstIndex; idxPtr < renderParms.clientFirstIndex + renderParms.indexCount; ++idxPtr)
{
auto index = *idxPtr;
EXPECT_EQ(index, *expectedIndex) << "Index disorder";
// Pick the vertex from our local expectation
const auto& expectedVertex = vertices.at(index);
// Pick the vertex from the stored set
const auto& vertex = *(firstVertex + index);
EXPECT_TRUE(math::isNear(vertex.vertex, expectedVertex.vertex, 0.01)) << "Vertex data mismatch";
EXPECT_TRUE(math::isNear(vertex.texcoord, expectedVertex.texcoord, 0.01)) << "Texcoord data mismatch";
EXPECT_TRUE(math::isNear(vertex.normal, expectedVertex.normal, 0.01)) << "Normal data mismatch";
++expectedIndex;
}
}
struct Allocation
{
render::IGeometryStore::Slot slot;
std::vector<render::RenderVertex> vertices;
std::vector<unsigned int> indices;
bool operator<(const Allocation& other) const
{
return slot < other.slot;
}
};
inline void verifyAllAllocations(render::IGeometryStore& store, const std::vector<Allocation>& allocations)
{
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
}
}
TEST(GeometryStore, AllocateAndDeallocate)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
std::vector<render::IGeometryStore::Slot> allocatedSlots;
// Allocate 10 slots of various sizes
for (auto i = 0; i < 10; ++i)
{
auto slot = store.allocateSlot((i + 5) * 20, (i + 5) * 23);
EXPECT_NE(slot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
allocatedSlots.push_back(slot);
}
for (auto slot : allocatedSlots)
{
EXPECT_NO_THROW(store.deallocateSlot(slot));
}
}
TEST(GeometryStore, UpdateData)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
std::set<Allocation> allocations;
// Allocate 10 slots of various sizes, store some data in there
for (auto i = 0; i < 10; ++i)
{
auto vertices = generateVertices(i, (i + 5) * 20);
auto indices = generateIndices(vertices);
auto slot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(slot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Uploading the data should succeed
EXPECT_NO_THROW(store.updateData(slot, vertices, indices));
allocations.emplace(Allocation{ slot, vertices, indices });
// Verify the data after each allocation, it should not affect the others
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
}
// Verify the data
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
// Now de-allocate one slot after the other and verify the remaining ones
while (!allocations.empty())
{
auto slot = allocations.begin()->slot;
allocations.erase(allocations.begin());
EXPECT_NO_THROW(store.deallocateSlot(slot));
// Verify the remaining slots, they should still be intact
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
}
}
TEST(GeometryStore, UpdateSubData)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
std::set<Allocation> allocations;
// Allocate 10 slots of various sizes, store some data in there
auto margin = 13;
for (auto i = 0; i < 10; ++i)
{
auto vertices = generateVertices(13, 17 * 20);
auto indices = generateIndices(vertices);
auto slot = store.allocateSlot(vertices.size() + margin, indices.size() + margin);
EXPECT_NE(slot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// We locally keep track of what the data should look like in the store
std::vector<render::RenderVertex> localVertexCopy(vertices.size());
std::vector<unsigned int> localIndexCopy(indices.size());
// Upload part of the data (with some increasing offset)
for (auto offset = 0; offset < margin; ++offset)
{
EXPECT_NO_THROW(store.updateSubData(slot, offset, vertices, offset, indices));
// Update our local copy accordingly
localVertexCopy.resize(vertices.size() + offset);
localIndexCopy.resize(indices.size() + offset);
std::copy(vertices.begin(), vertices.end(), localVertexCopy.begin() + offset);
std::copy(indices.begin(), indices.end(), localIndexCopy.begin() + offset);
verifyAllocation(store, slot, localVertexCopy, localIndexCopy);
}
// Finally, upload the whole data
store.updateData(slot, vertices, indices);
allocations.emplace(Allocation{ slot, vertices, indices });
// Verify the data after each round, it should not affect the other data
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
}
// Verify the data
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
// Now de-allocate one slot after the other and verify the remaining ones
while (!allocations.empty())
{
auto slot = allocations.begin()->slot;
allocations.erase(allocations.begin());
EXPECT_NO_THROW(store.deallocateSlot(slot));
// Verify the remaining slots, they should still be intact
for (auto allocation : allocations)
{
verifyAllocation(store, allocation.slot, allocation.vertices, allocation.indices);
}
}
}
TEST(GeometryStore, ResizeData)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a few dummy slots
store.allocateSlot(17, 27);
store.allocateSlot(31, 67);
store.allocateSlot(5, 37);
// Generate an indexed vertex set
auto vertices = generateVertices(13, 17 * 20);
auto indices = generateIndices(vertices);
auto slot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(slot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Store everything into the buffer
store.updateData(slot, vertices, indices);
// We locally keep track of what the data should look like in the store
std::vector<render::RenderVertex> localVertexCopy = vertices;
std::vector<unsigned int> localIndexCopy = indices;
// Reduce the data in the allocation, step by step
auto newVertexSize = localVertexCopy.size();
auto newIndexSize = localIndexCopy.size();
auto steps = std::min(newIndexSize, newVertexSize);
EXPECT_GT(steps, 4) << "Too few data elements";
steps -= 4;
for (auto i = 0; i < steps; ++i)
{
// Cut off one index at the end
// Keep the vertex buffer intact, we don't want out-of-bounds errors
localIndexCopy.resize(localIndexCopy.size() - 1);
--newVertexSize;
EXPECT_NO_THROW(store.resizeData(slot, newVertexSize, localIndexCopy.size()));
verifyAllocation(store, slot, localVertexCopy, localIndexCopy);
}
}
TEST(GeometryStore, FrameBufferSwitching)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
store.onFrameStart();
std::vector<Allocation> allocations;
// Allocate 10 slots of various sizes, store some data in there
for (auto i = 0; i < 10; ++i)
{
auto vertices = generateVertices(i, (i + 5) * 20);
auto indices = generateIndices(vertices);
auto slot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(slot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Uploading the data should succeed
EXPECT_NO_THROW(store.updateData(slot, vertices, indices));
allocations.emplace_back(Allocation{ slot, vertices, indices });
}
// Verify all
verifyAllAllocations(store, allocations);
store.onFrameFinished();
// Begin a new frame, the data in the new buffer should be up to date
store.onFrameStart();
verifyAllAllocations(store, allocations);
store.onFrameFinished();
auto dataUpdates = 0;
auto subDataUpdates = 0;
auto dataResizes = 0;
auto allocationCount = 0;
auto deallocationCount = 0;
std::minstd_rand rand(17); // fixed seed
// Run a few updates
for (auto frame = 0; frame < 100; ++frame)
{
store.onFrameStart();
// Verify all allocations at the start of every frame
verifyAllAllocations(store, allocations);
// Do something random with every allocation
for (auto a = 0; a < allocations.size(); ++a)
{
auto& allocation = allocations[a];
// Perform a random action
switch (rand() % 7)
{
case 1: // updateSubData
{
subDataUpdates++;
// Update 50% of the data
auto newVertices = generateVertices(rand() % 9, allocation.vertices.size() >> 2);
auto newIndices = generateIndices(newVertices);
// Overwrite some of the data
std::copy(newVertices.begin(), newVertices.end(), allocation.vertices.begin());
std::copy(newIndices.begin(), newIndices.end(), allocation.indices.begin());
store.updateSubData(allocation.slot, 0, newVertices, 0, newIndices);
break;
}
case 2: // updateData
{
dataUpdates++;
allocation.vertices = generateVertices(rand() % 9, allocation.vertices.size());
allocation.indices = generateIndices(allocation.vertices);
store.updateData(allocation.slot, allocation.vertices, allocation.indices);
break;
}
case 3: // resize
{
dataResizes++;
// Don't touch vertices below a minimum size
if (allocation.vertices.size() < 10) break;
// Allow 10% shrinking of the data
auto newSize = allocation.vertices.size() - (rand() % (allocation.vertices.size() / 10));
allocation.vertices.resize(newSize);
allocation.indices = generateIndices(allocation.vertices);
store.resizeData(allocation.slot, allocation.vertices.size(), allocation.indices.size());
// after resize, we have to update the data too, unfortunately, otherwise the indices are out of bounds
store.updateData(allocation.slot, allocation.vertices, allocation.indices);
break;
}
case 4: // allocations
{
allocationCount++;
auto vertices = generateVertices(rand() % 9, rand() % 100);
auto indices = generateIndices(vertices);
auto slot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(slot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
EXPECT_NO_THROW(store.updateData(slot, vertices, indices));
allocations.emplace_back(Allocation{ slot, vertices, indices });
break;
}
case 5: // dellocation
{
deallocationCount++;
store.deallocateSlot(allocations[a].slot);
allocations.erase(allocations.begin() + a);
// We're going to skip one loop iteration, but that's not very important
break;
}
} // switch
}
// Verify all allocations at the end of every frame
verifyAllAllocations(store, allocations);
store.onFrameFinished();
}
// One final check
store.onFrameStart();
verifyAllAllocations(store, allocations);
store.onFrameFinished();
EXPECT_GT(dataUpdates, 0) << "No data update operations performed";
EXPECT_GT(subDataUpdates, 0) << "No sub data update operations performed";
EXPECT_GT(dataResizes, 0) << "No resize operations performed";
EXPECT_GT(allocationCount, 0) << "No allocation operations performed";
EXPECT_GT(deallocationCount, 0) << "No deallocation operations performed";
}
TEST(GeometryStore, SyncObjectAcquisition)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
TestSyncObjectProvider::Instance().invocationCount = 0;
for (int i = 0; i < 5; ++i)
{
store.onFrameStart();
store.onFrameFinished();
}
EXPECT_EQ(TestSyncObjectProvider::Instance().invocationCount, 5) <<
"GeometryStore should have performed 5 frame buffer switches";
}
TEST(GeometryStore, AllocateIndexRemap)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto primarySlot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(primarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Uploading the data should succeed
EXPECT_NO_THROW(store.updateData(primarySlot, vertices, indices));
auto secondarySlot = store.allocateIndexSlot(primarySlot, 20);
EXPECT_NE(secondarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Deallocation through the regular method should succeed
EXPECT_NO_THROW(store.deallocateSlot(secondarySlot));
}
TEST(GeometryStore, AllocateInvalidIndexRemap)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto primarySlot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(primarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// This allocation is valid and will be a remap type
auto secondarySlot = store.allocateIndexSlot(primarySlot, 20);
EXPECT_NE(secondarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// This call is not valid and should throw, since the secondary slot cannot be re-used
EXPECT_THROW(store.allocateIndexSlot(secondarySlot, 10), std::logic_error);
}
TEST(GeometryStore, UpdateIndexRemapData)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto primarySlot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(primarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
EXPECT_NO_THROW(store.updateData(primarySlot, vertices, indices));
// Now allocate an index remapping slot, containing a straight, sequential set of indices 0..n-1
std::vector<unsigned int> remap;
remap.resize(vertices.size());
std::iota(remap.begin(), remap.end(), 0);
auto secondarySlot = store.allocateIndexSlot(primarySlot, remap.size());
EXPECT_NE(secondarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Update the index data through updateData()
EXPECT_NO_THROW(store.updateData(secondarySlot, {}, remap));
// The render params should effectively point us the re-used vertices, in remapped order
verifyAllocation(store, secondarySlot, vertices, remap);
// Reverse the index order for testing the second way of uploading data
std::reverse(remap.begin(), remap.end());
EXPECT_NO_THROW(store.updateIndexData(secondarySlot, remap));
verifyAllocation(store, secondarySlot, vertices, remap);
// We expect an exception when trying to store vertex data
EXPECT_THROW(store.updateData(secondarySlot, vertices, remap), std::logic_error);
}
TEST(GeometryStore, UpdateIndexRemapSubData)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto primarySlot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(primarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
EXPECT_NO_THROW(store.updateData(primarySlot, vertices, indices));
// Now allocate an index remapping slot, containing a straight, sequential set of indices 0..n-1
std::vector<unsigned int> remap;
remap.resize(vertices.size());
std::iota(remap.begin(), remap.end(), 0);
auto secondarySlot = store.allocateIndexSlot(primarySlot, remap.size());
EXPECT_NE(secondarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
// Upload the sequential set of indices
EXPECT_NO_THROW(store.updateIndexData(secondarySlot, remap));
verifyAllocation(store, secondarySlot, vertices, remap);
// Generate a new set of indices, and make it half as large than the original remap
std::vector<unsigned int> indexSubset;
indexSubset.resize(remap.size() / 2);
std::iota(indexSubset.begin(), indexSubset.end(), 0); // [0..N-1]
std::reverse(indexSubset.begin(), indexSubset.end()); // make it [N-1...0]
// Apply the subset to the local remap copy
auto offset = indexSubset.size() / 4;
std::copy(indexSubset.begin(), indexSubset.end(), remap.begin() + offset);
// Apply the subset to the data in the store
EXPECT_NO_THROW(store.updateIndexSubData(secondarySlot, offset, indexSubset));
// The new subset should now be used when effective
verifyAllocation(store, secondarySlot, vertices, remap);
// We expect boundaries to be respected, this should be out of range
EXPECT_THROW(store.updateIndexSubData(secondarySlot, remap.size() - 1, indexSubset), std::logic_error);
}
TEST(GeometryStore, ResizeIndexRemapData)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto primarySlot = store.allocateSlot(vertices.size(), indices.size());
EXPECT_NE(primarySlot, std::numeric_limits<render::IGeometryStore::Slot>::max()) << "Invalid slot";
EXPECT_NO_THROW(store.updateData(primarySlot, vertices, indices));
// Now allocate an index remapping slot, containing a straight, sequential set of indices 0..n-1
std::vector<unsigned int> remap;
remap.resize(vertices.size());
std::iota(remap.begin(), remap.end(), 0);
auto secondarySlot = store.allocateIndexSlot(primarySlot, remap.size());
store.updateIndexData(secondarySlot, remap);
verifyAllocation(store, secondarySlot, vertices, remap);
// Cut off a few remap indices
remap.resize(remap.size() - remap.size() / 3);
EXPECT_NO_THROW(store.resizeData(secondarySlot, 0, remap.size()));
// Verify this has taken effect
verifyAllocation(store, secondarySlot, vertices, remap);
// Cut off more indices, use the dedicated method this time
remap.resize(remap.size() - remap.size() / 2);
EXPECT_NO_THROW(store.resizeIndexData(secondarySlot, remap.size()));
verifyAllocation(store, secondarySlot, vertices, remap);
// We expect an exception if the index size is out of bounds
EXPECT_THROW(store.resizeIndexData(secondarySlot, remap.size() * 20), std::logic_error);
// And we cannot set the vertex size of an index remap slot
EXPECT_THROW(store.resizeData(secondarySlot, 6, remap.size()), std::logic_error);
}
TEST(GeometryStore, RegularSlotBounds)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto slot = store.allocateSlot(vertices.size(), indices.size());
store.updateData(slot, vertices, indices);
// This slot's indices are referencing all vertices, so the bounds
// calculated should match the bounds of the entire vertex set.
AABB localBounds;
for (const auto& vertex : vertices)
{
const auto& v = vertex.vertex;
localBounds.includePoint({ v.x(), v.y(), v.z() });
}
auto slotBounds = store.getBounds(slot);
EXPECT_TRUE(math::isNear(slotBounds.getOrigin(), localBounds.getOrigin(), 0.01)) << "Bounds origin mismatch";
EXPECT_TRUE(math::isNear(slotBounds.getExtents(), localBounds.getExtents(), 0.01)) << "Bounds extents mismatch";
// Store a new set of indices in this slot that is just using every second vertex
std::vector<unsigned int> newIndices;
for (auto i = 0; i < vertices.size(); i += 2)
{
newIndices.push_back(i);
}
store.updateData(slot, vertices, newIndices);
localBounds = AABB();
for (auto index : newIndices)
{
const auto& v = vertices[index].vertex;
localBounds.includePoint({ v.x(), v.y(), v.z() });
}
slotBounds = store.getBounds(slot);
EXPECT_TRUE(math::isNear(slotBounds.getOrigin(), localBounds.getOrigin(), 0.01)) << "Bounds origin mismatch";
EXPECT_TRUE(math::isNear(slotBounds.getExtents(), localBounds.getExtents(), 0.01)) << "Bounds extents mismatch";
}
TEST(GeometryStore, IndexRemappingSlotBounds)
{
render::GeometryStore store(TestSyncObjectProvider::Instance(), _testBufferObjectProvider);
// Allocate a slot to hold indexed vertices
auto vertices = generateVertices(3, 15 * 20);
auto indices = generateIndices(vertices);
auto primarySlot = store.allocateSlot(vertices.size(), indices.size());
store.updateData(primarySlot, vertices, indices);
// Set up a remapping slot with a smaller set of indices referencing the primary slot vertices
std::vector<unsigned int> newIndices(vertices.size() / 4);
std::iota(newIndices.begin(), newIndices.end(), 0);
auto indexSlot = store.allocateIndexSlot(primarySlot, newIndices.size());
store.updateIndexData(indexSlot, newIndices);
// Calculate the bounds of our offline mapping
AABB localBounds;
for (auto index : newIndices)
{
const auto& v = vertices[index].vertex;
localBounds.includePoint({ v.x(), v.y(), v.z() });
}
// Query the bounds of this index slot, it should be the same
auto slotBounds = store.getBounds(indexSlot);
EXPECT_TRUE(math::isNear(slotBounds.getOrigin(), localBounds.getOrigin(), 0.01)) << "Bounds origin mismatch";
EXPECT_TRUE(math::isNear(slotBounds.getExtents(), localBounds.getExtents(), 0.01)) << "Bounds extents mismatch";
}
}
|