Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
88002c3
initial skeleton for debug draw ex
keptsecret Jun 30, 2025
3df145b
use camera with lines
keptsecret Jul 1, 2025
ac56991
merge mesh_loaders
keptsecret Jul 1, 2025
6d5a495
fixes from mesh_loader merge
keptsecret Jul 1, 2025
c5dae98
removed unused files
keptsecret Jul 1, 2025
17b53a8
draw aabb from push constant
keptsecret Jul 1, 2025
a62cbed
move single aabb stuff into CDrawAABB
keptsecret Jul 1, 2025
00185f2
Merge branch 'master' into new_debug_draw
keptsecret Jul 2, 2025
5fa8874
default pipeline creation func
keptsecret Jul 2, 2025
704a0fb
got streaming buffer working and drawing
keptsecret Jul 3, 2025
a81e62f
draw with instances
keptsecret Jul 4, 2025
da63edf
minor bug fix in creating instances
keptsecret Jul 4, 2025
7469300
Merge branch 'master' into new_debug_draw
keptsecret Jul 4, 2025
9ae72f5
move handling instances to CDrawAABB
keptsecret Jul 4, 2025
7a22eef
moved most important streaming stuff to CDrawAABB
keptsecret Jul 4, 2025
f18bf38
moved most core func to CDrawAABB
keptsecret Jul 7, 2025
09ef478
handle streaming buffer overflow
keptsecret Jul 8, 2025
aee85b4
update example scene
keptsecret Jul 8, 2025
738269e
use debug draw extension
keptsecret Jul 8, 2025
c698bb7
Merge branch 'master' into new_debug_draw
keptsecret Jul 8, 2025
61b1c00
removed old mesh loaders
keptsecret Jul 8, 2025
4f1fabd
add debug aabb draws around mesh
keptsecret Jul 9, 2025
b31cfba
merge master, fix conflicts
keptsecret Aug 18, 2025
bfd286e
refactor debug_draw namespace
keptsecret Aug 18, 2025
8518c2b
refactor remove usage of legacy matrices
keptsecret Aug 19, 2025
323c782
refactor examples with latest DrawAabb changes
keptsecret Aug 20, 2025
f75dc21
use draw modes
keptsecret Aug 20, 2025
83a71a8
Merge branch 'master' into new_debug_draw
keptsecret Aug 21, 2025
347933d
merge master, fix conflicts
keptsecret Sep 8, 2025
3b1016e
don't EXCLUDE_ALL new example
keptsecret Sep 8, 2025
36171d7
Merge branch 'master' into new_debug_draw
keptsecret Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 12_MeshLoaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ nbl_create_executable_project("" "" "${NBL_INCLUDE_SERACH_DIRECTORIES}" "${NBL_L
# TODO: Arek temporarily disabled cause I haven't figured out how to make this target yet
# LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} nblExamplesGeometrySpirvBRD)

if (NBL_BUILD_DEBUG_DRAW)
add_dependencies(${EXECUTABLE_NAME} ${NBL_EXT_DEBUG_DRAW_TARGET})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_EXT_DEBUG_DRAW_TARGET})
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_EXT_DEBUG_DRAW_TARGET},INCLUDE_DIRECTORIES>)
endif()


add_dependencies(${EXECUTABLE_NAME} argparse)
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:argparse,INTERFACE_INCLUDE_DIRECTORIES>)
186 changes: 118 additions & 68 deletions 12_MeshLoaders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "nbl/ext/MitsubaLoader/CSerializedLoader.h"
#endif

#ifdef NBL_BUILD_DEBUG_DRAW
#include "nbl/ext/DebugDraw/CDrawAABB.h"
#endif

class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourcesApplication
{
using device_base_t = MonoWindowApplication;
Expand Down Expand Up @@ -88,9 +92,23 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
if (!m_renderer)
return logFail("Failed to create renderer!");

//
if (!reloadModel())
return false;
#ifdef NBL_BUILD_DEBUG_DRAW
{
auto* renderpass = scRes->getRenderpass();
ext::debug_draw::DrawAABB::SCreationParameters params = {};
params.assetManager = m_assetMgr;
params.transfer = getTransferUpQueue();
params.drawMode = ext::debug_draw::DrawAABB::ADM_DRAW_BATCH;
params.batchPipelineLayout = ext::debug_draw::DrawAABB::createDefaultPipelineLayout(m_device.get());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure the push constant range for the layout can be wrong here by accident see review of the main nabla PR

params.renderpass = smart_refctd_ptr<IGPURenderpass>(renderpass);
params.utilities = m_utils;
m_drawAABB = ext::debug_draw::DrawAABB::create(std::move(params));
}
#endif

//
if (!reloadModel())
return false;

camera.mapKeysToArrows();

Expand Down Expand Up @@ -131,48 +149,59 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
};
cb->beginRenderPass(info, IGPUCommandBuffer::SUBPASS_CONTENTS::INLINE);

const SViewport viewport = {
.x = static_cast<float>(currentRenderArea.offset.x),
.y = static_cast<float>(currentRenderArea.offset.y),
.width = static_cast<float>(currentRenderArea.extent.width),
.height = static_cast<float>(currentRenderArea.extent.height)
};
cb->setViewport(0u, 1u, &viewport);

cb->setScissor(0u, 1u, &currentRenderArea);
}
// late latch input
{
bool reload = false;
camera.beginInputProcessing(nextPresentationTimestamp);
mouse.consumeEvents([&](const IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, m_logger.get());
keyboard.consumeEvents([&](const IKeyboardEventChannel::range_t& events) -> void
{
for (const auto& event : events)
if (event.keyCode == E_KEY_CODE::EKC_R && event.action == SKeyboardEvent::ECA_RELEASED)
reload = true;
camera.keyboardProcess(events);
},
m_logger.get()
);
camera.endInputProcessing(nextPresentationTimestamp);
if (reload)
reloadModel();
}
// draw scene
{
const SViewport viewport = {
.x = static_cast<float>(currentRenderArea.offset.x),
.y = static_cast<float>(currentRenderArea.offset.y),
.width = static_cast<float>(currentRenderArea.extent.width),
.height = static_cast<float>(currentRenderArea.extent.height)
};
cb->setViewport(0u,1u,&viewport);

cb->setScissor(0u,1u,&currentRenderArea);
}
// late latch input
{
bool reload = false;
camera.beginInputProcessing(nextPresentationTimestamp);
mouse.consumeEvents([&](const IMouseEventChannel::range_t& events) -> void { camera.mouseProcess(events); }, m_logger.get());
keyboard.consumeEvents([&](const IKeyboardEventChannel::range_t& events) -> void
{
for (const auto& event : events)
{
if (event.keyCode == E_KEY_CODE::EKC_R && event.action == SKeyboardEvent::ECA_RELEASED)
reload = true;
if (event.keyCode == E_KEY_CODE::EKC_B && event.action == SKeyboardEvent::ECA_RELEASED)
m_drawBBs = !m_drawBBs;
}
camera.keyboardProcess(events);
},
m_logger.get()
);
camera.endInputProcessing(nextPresentationTimestamp);
if (reload)
reloadModel();
}
// draw scene
float32_t3x4 viewMatrix;
float32_t4x4 viewProjMatrix;
// TODO: get rid of legacy matrices
{
memcpy(&viewMatrix, camera.getViewMatrix().pointer(), sizeof(viewMatrix));
memcpy(&viewProjMatrix, camera.getConcatenatedMatrix().pointer(), sizeof(viewProjMatrix));
// TODO: get rid of legacy matrices
{
memcpy(&viewMatrix,camera.getViewMatrix().pointer(),sizeof(viewMatrix));
memcpy(&viewProjMatrix,camera.getConcatenatedMatrix().pointer(),sizeof(viewProjMatrix));
}
m_renderer->render(cb,CSimpleDebugRenderer::SViewParams(viewMatrix,viewProjMatrix));
}
#ifdef NBL_BUILD_DEBUG_DRAW
if (m_drawBBs)
{
const ISemaphore::SWaitInfo drawFinished = { .semaphore = m_semaphore.get(),.value = m_realFrameIx + 1u };
m_drawAABB->render(cb, drawFinished, m_aabbInstances, viewProjMatrix);
}
m_renderer->render(cb, CSimpleDebugRenderer::SViewParams(viewMatrix, viewProjMatrix));
#endif
cb->endRenderPass();
}
cb->endRenderPass();
}
cb->end();
cb->end();

IQueue::SSubmitInfo::SSemaphoreInfo retval =
{
Expand Down Expand Up @@ -410,36 +439,51 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
cpar.utilities = m_utils.get();
cpar.transfer = &transfer;

// basically it records all data uploads and submits them right away
auto future = reservation.convert(cpar);
if (future.copy() != IQueue::RESULT::SUCCESS)
{
m_logger->log("Failed to await submission feature!", ILogger::ELL_ERROR);
return false;
// basically it records all data uploads and submits them right away
auto future = reservation.convert(cpar);
if (future.copy()!=IQueue::RESULT::SUCCESS)
{
m_logger->log("Failed to await submission feature!", ILogger::ELL_ERROR);
return false;
}
}
}

auto tmp = hlsl::float32_t4x3(
hlsl::float32_t3(1, 0, 0),
hlsl::float32_t3(0, 1, 0),
hlsl::float32_t3(0, 0, 1),
hlsl::float32_t3(0, 0, 0)
);
core::vector<hlsl::float32_t3x4> worldTforms;
const auto& converted = reservation.getGPUObjects<ICPUPolygonGeometry>();
for (const auto& geom : converted)
{
const auto promoted = geom.value->getAABB<aabb_t>();
printAABB(promoted, "Geometry");
tmp[3].x += promoted.getExtent().x;
const auto promotedWorld = hlsl::float64_t3x4(worldTforms.emplace_back(hlsl::transpose(tmp)));
const auto transformed = hlsl::shapes::util::transform(promotedWorld, promoted);
printAABB(transformed, "Transformed");
bound = hlsl::shapes::util::union_(transformed, bound);
}
printAABB(bound, "Total");
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
return false;
auto tmp = hlsl::float32_t4x3(
hlsl::float32_t3(1,0,0),
hlsl::float32_t3(0,1,0),
hlsl::float32_t3(0,0,1),
hlsl::float32_t3(0,0,0)
);
core::vector<hlsl::float32_t3x4> worldTforms;
const auto& converted = reservation.getGPUObjects<ICPUPolygonGeometry>();
m_aabbInstances.resize(converted.size());
for (uint32_t i = 0; i < converted.size(); i++)
{
const auto& geom = converted[i];
const auto promoted = geom.value->getAABB<aabb_t>();
printAABB(promoted,"Geometry");
tmp[3].x += promoted.getExtent().x;
const auto promotedWorld = hlsl::float64_t3x4(worldTforms.emplace_back(hlsl::transpose(tmp)));
const auto transformed = hlsl::shapes::util::transform(promotedWorld,promoted);
printAABB(transformed,"Transformed");
bound = hlsl::shapes::util::union_(transformed,bound);

#ifdef NBL_BUILD_DEBUG_DRAW
auto& inst = m_aabbInstances[i];
const auto tmpAabb = shapes::AABB<3,float>(promoted.minVx, promoted.maxVx);
hlsl::float32_t4x4 instanceTransform = ext::debug_draw::DrawAABB::getTransformFromAABB(tmpAabb);
const auto tmpWorld = hlsl::float32_t3x4(promotedWorld);
inst.color = { 1,1,1,1 };
inst.transform[0] = tmpWorld[0];
inst.transform[1] = tmpWorld[1];
inst.transform[2] = tmpWorld[2];
inst.transform[3] = float32_t4(0, 0, 0, 1);
inst.transform = hlsl::mul(inst.transform, instanceTransform);
#endif
}
printAABB(bound,"Total");
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
return false;

auto worlTformsIt = worldTforms.begin();
for (const auto& geo : m_renderer->getGeometries())
Expand Down Expand Up @@ -496,6 +540,12 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
// mutables
std::string m_modelPath;

bool m_drawBBs = true;
#ifdef NBL_BUILD_DEBUG_DRAW
smart_refctd_ptr<ext::debug_draw::DrawAABB> m_drawAABB;
std::vector<ext::debug_draw::InstanceData> m_aabbInstances;
#endif

bool m_saveGeom = false;
std::future<void> m_saveGeomTaskFuture;
std::optional<const std::string> m_specifiedGeomSavePath;
Expand Down
11 changes: 11 additions & 0 deletions 34_DebugDraw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if(NBL_BUILD_DEBUG_DRAW)
set(NBL_INCLUDE_SERACH_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)

nbl_create_executable_project("${NBL_EXTRA_SOURCES}" "" "${NBL_INCLUDE_SERACH_DIRECTORIES}" "" "${NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET}")

add_dependencies(${EXECUTABLE_NAME} ${NBL_EXT_DEBUG_DRAW_TARGET})
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${NBL_EXT_DEBUG_DRAW_TARGET})
target_include_directories(${EXECUTABLE_NAME} PUBLIC $<TARGET_PROPERTY:${NBL_EXT_DEBUG_DRAW_TARGET},INCLUDE_DIRECTORIES>)
endif()
28 changes: 28 additions & 0 deletions 34_DebugDraw/config.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"enableParallelBuild": true,
"threadsPerBuildProcess" : 2,
"isExecuted": false,
"scriptPath": "",
"cmake": {
"configurations": [ "Release", "Debug", "RelWithDebInfo" ],
"buildModes": [],
"requiredOptions": []
},
"profiles": [
{
"backend": "vulkan",
"platform": "windows",
"buildModes": [],
"runConfiguration": "Release",
"gpuArchitectures": []
}
],
"dependencies": [],
"data": [
{
"dependencies": [],
"command": [""],
"outputs": []
}
]
}
23 changes: 23 additions & 0 deletions 34_DebugDraw/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__
#define __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__

#include <nabla.h>

#include "nbl/examples/cameras/CCamera.hpp"
#include "nbl/examples/common/SimpleWindowedApplication.hpp"
#include "nbl/examples/common/CEventCallback.hpp"
#include "nbl/examples/examples.hpp"

//#include "nbl/CDrawAABB.h"
#include "nbl/ext/DebugDraw/CDrawAABB.h"

using namespace nbl;
using namespace core;
using namespace hlsl;
using namespace system;
using namespace asset;
using namespace ui;
using namespace video;
using namespace nbl::examples;

#endif // __NBL_THIS_EXAMPLE_COMMON_H_INCLUDED__
Loading