Skip to content

Commit 37cc551

Browse files
committed
aabb local transform is 3x4, common draw param struct between single and batch
1 parent fdd675b commit 37cc551

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

include/nbl/ext/DebugDraw/CDrawAABB.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ namespace nbl::ext::debug_draw
6969
}
7070
};
7171

72+
struct DrawParameters
73+
{
74+
video::IGPUCommandBuffer* commandBuffer = nullptr;
75+
hlsl::float32_t4x4 cameraMat = hlsl::float32_t4x4(1);
76+
float lineWidth = 1.f;
77+
};
78+
7279
// creates an instance that can draw one AABB via push constant or multiple using streaming buffer
7380
static core::smart_refctd_ptr<DrawAABB> create(SCreationParameters&& params);
7481

@@ -84,11 +91,11 @@ namespace nbl::ext::debug_draw
8491
inline const SCachedCreationParameters& getCreationParameters() const { return m_cachedCreationParams; }
8592

8693
// records draw command for single AABB, user has to set pipeline outside
87-
bool renderSingle(video::IGPUCommandBuffer* commandBuffer, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color, const hlsl::float32_t4x4& cameraMat);
94+
bool renderSingle(const DrawParameters& params, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color);
8895

8996
// records draw command for rendering batch of AABB instances as InstanceData
9097
// user has to set span of filled-in InstanceData; camera matrix used in push constant
91-
inline bool render(video::IGPUCommandBuffer* commandBuffer, video::ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances, const hlsl::float32_t4x4& cameraMat)
98+
inline bool render(const DrawParameters& params, video::ISemaphore::SWaitInfo waitInfo, std::span<const InstanceData> aabbInstances)
9299
{
93100
if (!(m_cachedCreationParams.drawMode & ADM_DRAW_BATCH))
94101
{
@@ -108,8 +115,9 @@ namespace nbl::ext::debug_draw
108115
auto* const streamingPtr = reinterpret_cast<uint8_t*>(streaming->getBufferPointer());
109116
assert(streamingPtr);
110117

118+
auto& commandBuffer = params.commandBuffer;
111119
commandBuffer->bindGraphicsPipeline(m_batchPipeline.get());
112-
commandBuffer->setLineWidth(1.f);
120+
commandBuffer->setLineWidth(params.lineWidth);
113121
asset::SBufferBinding<video::IGPUBuffer> indexBinding = { .offset = 0, .buffer = m_indicesBuffer };
114122
commandBuffer->bindIndexBuffer(indexBinding, asset::EIT_32BIT);
115123

@@ -118,7 +126,7 @@ namespace nbl::ext::debug_draw
118126
{
119127
auto& inst = instances[i];
120128
inst = aabbInstances[i];
121-
inst.transform = hlsl::mul(cameraMat, inst.transform);
129+
inst.transform = hlsl::mul(params.cameraMat, inst.transform);
122130
}
123131

124132
auto instancesIt = instances.begin();
@@ -154,7 +162,7 @@ namespace nbl::ext::debug_draw
154162
return true;
155163
}
156164

157-
static hlsl::float32_t4x4 getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb);
165+
static hlsl::float32_t3x4 getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb);
158166

159167
protected:
160168
DrawAABB(SCreationParameters&& _params, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> singlePipeline, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> batchPipeline,

src/nbl/ext/DebugDraw/CDrawAABB.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,23 @@ core::smart_refctd_ptr<video::IGPUPipelineLayout> DrawAABB::createDefaultPipelin
304304
return createPipelineLayoutFromPCRange(device, pcRange);
305305
}
306306

307-
bool DrawAABB::renderSingle(IGPUCommandBuffer* commandBuffer, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color, const hlsl::float32_t4x4& cameraMat)
307+
bool DrawAABB::renderSingle(const DrawParameters& params, const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4& color)
308308
{
309309
if (!(m_cachedCreationParams.drawMode & ADM_DRAW_SINGLE))
310310
{
311311
m_cachedCreationParams.utilities->getLogger()->log("DrawAABB has not been enabled for draw single!", ILogger::ELL_ERROR);
312312
return false;
313313
}
314314

315+
auto& commandBuffer = params.commandBuffer;
315316
commandBuffer->bindGraphicsPipeline(m_singlePipeline.get());
316-
commandBuffer->setLineWidth(1.f);
317+
commandBuffer->setLineWidth(params.lineWidth);
317318
asset::SBufferBinding<video::IGPUBuffer> indexBinding = { .offset = 0, .buffer = m_indicesBuffer };
318319
commandBuffer->bindIndexBuffer(indexBinding, asset::EIT_32BIT);
319320

320321
SSinglePushConstants pc;
321-
322-
hlsl::float32_t4x4 instanceTransform = getTransformFromAABB(aabb);
323-
pc.instance.transform = hlsl::mul(cameraMat, instanceTransform);
322+
hlsl::float32_t3x4 instanceTransform = getTransformFromAABB(aabb);
323+
pc.instance.transform = math::linalg::promoted_mul(params.cameraMat, instanceTransform);
324324
pc.instance.color = color;
325325

326326
commandBuffer->pushConstants(m_singlePipeline->getLayout(), ESS_VERTEX, 0, sizeof(SSinglePushConstants), &pc);
@@ -329,14 +329,13 @@ bool DrawAABB::renderSingle(IGPUCommandBuffer* commandBuffer, const hlsl::shapes
329329
return true;
330330
}
331331

332-
hlsl::float32_t4x4 DrawAABB::getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb)
332+
hlsl::float32_t3x4 DrawAABB::getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb)
333333
{
334334
const auto diagonal = aabb.getExtent();
335-
hlsl::float32_t4x4 transform;
335+
hlsl::float32_t3x4 transform;
336336
transform[0][3] = aabb.minVx.x;
337337
transform[1][3] = aabb.minVx.y;
338338
transform[2][3] = aabb.minVx.z;
339-
transform[3][3] = 1.f;
340339
transform[0][0] = diagonal.x;
341340
transform[1][1] = diagonal.y;
342341
transform[2][2] = diagonal.z;

0 commit comments

Comments
 (0)