Skip to content

Commit 328aa34

Browse files
committed
change batch render to take span of InstanceData
1 parent 5285e78 commit 328aa34

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

include/nbl/ext/DebugDraw/CDrawAABB.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,10 @@ class DrawAABB final : public core::IReferenceCounted
5858
// records draw command for single AABB, user has to set pipeline outside
5959
bool renderSingle(video::IGPUCommandBuffer* commandBuffer, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color, const hlsl::float32_t4x4& cameraMat);
6060

61-
bool render(video::IGPUCommandBuffer* commandBuffer, video::ISemaphore::SWaitInfo waitInfo, const hlsl::float32_t4x4& cameraMat);
61+
bool render(video::IGPUCommandBuffer* commandBuffer, video::ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances, const hlsl::float32_t4x4& cameraMat);
6262

6363
static hlsl::float32_t4x4 getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb);
6464

65-
void addAABB(const hlsl::shapes::AABB<3,float>& aabb, const hlsl::float32_t4& color = { 1,0,0,1 });
66-
void addOBB(const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4x4& transform, const hlsl::float32_t4& color = { 1,0,0,1 });
67-
void clearAABBs();
68-
6965
protected:
7066
DrawAABB(SCreationParameters&& _params, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> singlePipeline, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> batchPipeline,
7167
core::smart_refctd_ptr<video::IGPUBuffer> indicesBuffer, core::smart_refctd_ptr<video::IGPUBuffer> verticesBuffer);
@@ -77,7 +73,6 @@ class DrawAABB final : public core::IReferenceCounted
7773
static core::smart_refctd_ptr<video::IGPUBuffer> createIndicesBuffer(SCreationParameters& params);
7874
static core::smart_refctd_ptr<video::IGPUBuffer> createVerticesBuffer(SCreationParameters& params);
7975

80-
std::vector<debug_draw::InstanceData> m_instances;
8176
core::smart_refctd_ptr<video::IGPUBuffer> m_indicesBuffer;
8277
core::smart_refctd_ptr<video::IGPUBuffer> m_verticesBuffer;
8378

src/nbl/ext/DebugDraw/CDrawAABB.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ bool DrawAABB::renderSingle(IGPUCommandBuffer* commandBuffer, const hlsl::shapes
336336
return true;
337337
}
338338

339-
bool DrawAABB::render(IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo waitInfo, const hlsl::float32_t4x4& cameraMat)
339+
bool DrawAABB::render(IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances, const hlsl::float32_t4x4& cameraMat)
340340
{
341341
using offset_t = SCachedCreationParameters::streaming_buffer_t::size_type;
342342
constexpr auto MdiSizes = std::to_array<offset_t>({ sizeof(float32_t3), sizeof(InstanceData) });
@@ -355,9 +355,11 @@ bool DrawAABB::render(IGPUCommandBuffer* commandBuffer, ISemaphore::SWaitInfo wa
355355
asset::SBufferBinding<video::IGPUBuffer> indexBinding = { .offset = 0, .buffer = m_indicesBuffer };
356356
commandBuffer->bindIndexBuffer(indexBinding, asset::EIT_32BIT);
357357

358-
auto instances = m_instances;
359-
for (auto& inst : instances)
358+
std::vector<InstanceData> instances(aabbInstances.size());
359+
for (uint32_t i = 0; i < aabbInstances.size(); i++)
360360
{
361+
auto& inst = instances[i];
362+
inst = aabbInstances[i];
361363
inst.transform = hlsl::mul(cameraMat, inst.transform);
362364
}
363365

@@ -409,25 +411,4 @@ hlsl::float32_t4x4 DrawAABB::getTransformFromAABB(const hlsl::shapes::AABB<3, fl
409411
return transform;
410412
}
411413

412-
void DrawAABB::addAABB(const hlsl::shapes::AABB<3,float>& aabb, const hlsl::float32_t4& color)
413-
{
414-
const auto transform = hlsl::float32_t4x4(1);
415-
addOBB(aabb, transform, color);
416-
}
417-
418-
void DrawAABB::addOBB(const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4x4& transform, const hlsl::float32_t4& color)
419-
{
420-
InstanceData instance;
421-
instance.color = color;
422-
423-
hlsl::float32_t4x4 instanceTransform = getTransformFromAABB(aabb);
424-
instance.transform = math::linalg::promoted_mul(transform, instanceTransform);
425-
m_instances.push_back(instance);
426-
}
427-
428-
void DrawAABB::clearAABBs()
429-
{
430-
m_instances.clear();
431-
}
432-
433414
}

0 commit comments

Comments
 (0)