Skip to content

Commit 5285e78

Browse files
committed
simplified single AABB draw
1 parent 72e3569 commit 5285e78

File tree

5 files changed

+129
-110
lines changed

5 files changed

+129
-110
lines changed

include/nbl/ext/DebugDraw/CDrawAABB.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class DrawAABB final : public core::IReferenceCounted
1616
{
1717
public:
1818
static constexpr inline uint32_t IndicesCount = 24u;
19+
static constexpr inline uint32_t VerticesCount = 8u;
1920

2021
struct SCachedCreationParameters
2122
{
@@ -35,53 +36,55 @@ class DrawAABB final : public core::IReferenceCounted
3536
video::IQueue* transfer = nullptr;
3637
core::smart_refctd_ptr<asset::IAssetManager> assetManager = nullptr;
3738

38-
core::smart_refctd_ptr<video::IGPUPipelineLayout> pipelineLayout;
39+
core::smart_refctd_ptr<video::IGPUPipelineLayout> singlePipelineLayout;
40+
core::smart_refctd_ptr<video::IGPUPipelineLayout> batchPipelineLayout;
3941
core::smart_refctd_ptr<video::IGPURenderpass> renderpass = nullptr;
4042
};
4143

4244
// creates an instance that can draw one AABB via push constant or multiple using streaming buffer
4345
static core::smart_refctd_ptr<DrawAABB> create(SCreationParameters&& params);
4446

45-
// creates default pipeline layout for push constant version
46-
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createDefaultPipelineLayout(video::ILogicalDevice* device, const asset::SPushConstantRange& pcRange);
47+
// creates pipeline layout from push constant range
48+
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createPipelineLayoutFromPCRange(video::ILogicalDevice* device, const asset::SPushConstantRange& pcRange);
4749

4850
// creates default pipeline layout for streaming version
4951
static core::smart_refctd_ptr<video::IGPUPipelineLayout> createDefaultPipelineLayout(video::ILogicalDevice* device);
5052

51-
static core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createDefaultPipeline(video::ILogicalDevice* device, video::IGPUPipelineLayout* layout, video::IGPURenderpass* renderpass, video::IGPUGraphicsPipeline::SShaderSpecInfo& vertex, video::IGPUGraphicsPipeline::SShaderSpecInfo& fragment);
52-
5353
//! mounts the extension's archive to given system - useful if you want to create your own shaders with common header included
5454
static const core::smart_refctd_ptr<system::IFileArchive> mount(core::smart_refctd_ptr<system::ILogger> logger, system::ISystem* system, const std::string_view archiveAlias = "");
5555

5656
inline const SCachedCreationParameters& getCreationParameters() const { return m_cachedCreationParams; }
5757

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

6161
bool render(video::IGPUCommandBuffer* commandBuffer, video::ISemaphore::SWaitInfo waitInfo, const hlsl::float32_t4x4& cameraMat);
6262

63-
//static std::array<hlsl::float32_t3, 24> getVerticesFromAABB(const core::aabbox3d<float>& aabb);
63+
static hlsl::float32_t4x4 getTransformFromAABB(const hlsl::shapes::AABB<3, float>& aabb);
6464

6565
void addAABB(const hlsl::shapes::AABB<3,float>& aabb, const hlsl::float32_t4& color = { 1,0,0,1 });
6666
void addOBB(const hlsl::shapes::AABB<3, float>& aabb, const hlsl::float32_t4x4& transform, const hlsl::float32_t4& color = { 1,0,0,1 });
6767
void clearAABBs();
6868

6969
protected:
70-
DrawAABB(SCreationParameters&& _params, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> pipeline, core::smart_refctd_ptr<video::IGPUBuffer> indicesBuffer);
70+
DrawAABB(SCreationParameters&& _params, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> singlePipeline, core::smart_refctd_ptr<video::IGPUGraphicsPipeline> batchPipeline,
71+
core::smart_refctd_ptr<video::IGPUBuffer> indicesBuffer, core::smart_refctd_ptr<video::IGPUBuffer> verticesBuffer);
7172
~DrawAABB() override;
7273

7374
private:
74-
static core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createPipeline(SCreationParameters& params);
75+
static core::smart_refctd_ptr<video::IGPUGraphicsPipeline> createPipeline(SCreationParameters& params, const video::IGPUPipelineLayout* pipelineLayout, const std::string& vsPath, const std::string& fsPath);
7576
static bool createStreamingBuffer(SCreationParameters& params);
7677
static core::smart_refctd_ptr<video::IGPUBuffer> createIndicesBuffer(SCreationParameters& params);
78+
static core::smart_refctd_ptr<video::IGPUBuffer> createVerticesBuffer(SCreationParameters& params);
7779

7880
std::vector<debug_draw::InstanceData> m_instances;
79-
std::array<hlsl::float32_t3, 8> m_unitAABBVertices;
8081
core::smart_refctd_ptr<video::IGPUBuffer> m_indicesBuffer;
82+
core::smart_refctd_ptr<video::IGPUBuffer> m_verticesBuffer;
8183

8284
SCachedCreationParameters m_cachedCreationParams;
8385

84-
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_pipeline;
86+
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_singlePipeline;
87+
core::smart_refctd_ptr<video::IGPUGraphicsPipeline> m_batchPipeline;
8588
};
8689
}
8790

include/nbl/ext/DebugDraw/builtin/hlsl/common.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ struct InstanceData
1616
hlsl::float32_t4 color;
1717
};
1818

19+
struct SSinglePushConstants
20+
{
21+
uint64_t pVertexBuffer;
22+
InstanceData instance;
23+
};
24+
1925
struct SPushConstants
2026
{
2127
uint64_t pVertexBuffer;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma shader_stage(vertex)
2+
3+
#include "nbl/builtin/hlsl/math/linalg/fast_affine.hlsl"
4+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
5+
#include "nbl/builtin/hlsl/bda/__ptr.hlsl"
6+
#include "common.hlsl"
7+
8+
using namespace nbl::hlsl;
9+
using namespace nbl::ext::debug_draw;
10+
11+
[[vk::push_constant]] SSinglePushConstants pc;
12+
13+
[shader("vertex")]
14+
PSInput main()
15+
{
16+
PSInput output;
17+
float32_t3 vertex = (bda::__ptr<float32_t3>::create(pc.pVertexBuffer) + glsl::gl_VertexIndex()).deref_restrict().load();
18+
19+
output.position = math::linalg::promoted_mul(pc.instance.transform, vertex);
20+
output.color = pc.instance.color;
21+
22+
return output;
23+
}

0 commit comments

Comments
 (0)