Skip to content
Open
Show file tree
Hide file tree
Changes from 23 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
8 changes: 7 additions & 1 deletion 12_MeshLoaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ endif()
# TODO; Arek I removed `NBL_EXECUTABLE_PROJECT_CREATION_PCH_TARGET` from the last parameter here, doesn't this macro have 4 arguments anyway !?
nbl_create_executable_project("" "" "${NBL_INCLUDE_SERACH_DIRECTORIES}" "${NBL_LIBRARIES}")
# TODO: Arek temporarily disabled cause I haven't figured out how to make this target yet
# LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} nblExamplesGeometrySpirvBRD)
# 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()
58 changes: 55 additions & 3 deletions 12_MeshLoaders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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 @@ -48,6 +52,18 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
if (!m_renderer)
return logFail("Failed to create renderer!");

#ifdef NBL_BUILD_DEBUG_DRAW
{
auto* renderpass = scRes->getRenderpass();
ext::debugdraw::DrawAABB::SCreationParameters params = {};
params.assetManager = m_assetMgr;
params.pipelineLayout = ext::debugdraw::DrawAABB::createDefaultPipelineLayout(m_device.get());
params.renderpass = smart_refctd_ptr<IGPURenderpass>(renderpass);
params.utilities = m_utils;
drawAABB = ext::debugdraw::DrawAABB::create(std::move(params));
}
#endif

//
if (!reloadModel())
return false;
Expand Down Expand Up @@ -109,8 +125,12 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
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_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()
Expand All @@ -130,6 +150,24 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
}
m_renderer->render(cb,CSimpleDebugRenderer::SViewParams(viewMatrix,viewProjMatrix));
}
#ifdef NBL_BUILD_DEBUG_DRAW
if (m_drawBBs)
{
core::matrix4SIMD modelViewProjectionMatrix;
{
const auto viewMatrix = camera.getViewMatrix();
const auto projectionMatrix = camera.getProjectionMatrix();
const auto viewProjectionMatrix = camera.getConcatenatedMatrix();

core::matrix3x4SIMD modelMatrix;
modelMatrix.setTranslation(nbl::core::vectorSIMDf(0, 0, 0, 0));
modelMatrix.setRotation(quaternion(0, 0, 0));
modelViewProjectionMatrix = core::concatenateBFollowedByA(viewProjectionMatrix, modelMatrix);
}
const ISemaphore::SWaitInfo drawFinished = { .semaphore = m_semaphore.get(),.value = m_realFrameIx + 1u };
drawAABB->render(cb, drawFinished, modelViewProjectionMatrix.pointer());
}
#endif
cb->endRenderPass();
}
cb->end();
Expand Down Expand Up @@ -349,7 +387,10 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
return false;
}
}


#ifdef NBL_BUILD_DEBUG_DRAW
drawAABB->clearAABBs();
#endif
auto tmp = hlsl::float32_t4x3(
hlsl::float32_t3(1,0,0),
hlsl::float32_t3(0,1,0),
Expand All @@ -367,6 +408,12 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
const auto transformed = hlsl::shapes::util::transform(promotedWorld,promoted);
printAABB(transformed,"Transformed");
bound = hlsl::shapes::util::union_(transformed,bound);

#ifdef NBL_BUILD_DEBUG_DRAW
const auto tmpAabb = shapes::AABB<3,float>(promoted.minVx, promoted.maxVx);
const auto tmpWorld = hlsl::float32_t3x4(promotedWorld);
drawAABB->addOBB(tmpAabb, tmpWorld, hlsl::float32_t4{ 1,1,1,1 });
#endif
}
printAABB(bound,"Total");
if (!m_renderer->addGeometries({ &converted.front().get(),converted.size() }))
Expand Down Expand Up @@ -416,6 +463,11 @@ class MeshLoadersApp final : public MonoWindowApplication, public BuiltinResourc
Camera camera = Camera(core::vectorSIMDf(0, 0, 0), core::vectorSIMDf(0, 0, 0), core::matrix4SIMD());
// mutables
std::string m_modelPath;

bool m_drawBBs = true;
#ifdef NBL_BUILD_DEBUG_DRAW
smart_refctd_ptr<nbl::ext::debugdraw::DrawAABB> drawAABB;
#endif
};

NBL_MAIN_FUNC(MeshLoadersApp)
29 changes: 29 additions & 0 deletions 34_DebugDraw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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>)

if(NBL_EMBED_BUILTIN_RESOURCES)
set(_BR_TARGET_ ${EXECUTABLE_NAME}_builtinResourceData)
set(RESOURCE_DIR "app_resources")

get_filename_component(_SEARCH_DIRECTORIES_ "${CMAKE_CURRENT_SOURCE_DIR}" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE)
get_filename_component(_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE)

file(GLOB_RECURSE BUILTIN_RESOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${RESOURCE_DIR}/*")
foreach(RES_FILE ${BUILTIN_RESOURCE_FILES})
LIST_BUILTIN_RESOURCE(RESOURCES_TO_EMBED "${RES_FILE}")
endforeach()

ADD_CUSTOM_BUILTIN_RESOURCES(${_BR_TARGET_} RESOURCES_TO_EMBED "${_SEARCH_DIRECTORIES_}" "${RESOURCE_DIR}" "nbl::this_example::builtin" "${_OUTPUT_DIRECTORY_HEADER_}" "${_OUTPUT_DIRECTORY_SOURCE_}")

LINK_BUILTIN_RESOURCES_TO_TARGET(${EXECUTABLE_NAME} ${_BR_TARGET_})
endif()
endif()
11 changes: 11 additions & 0 deletions 34_DebugDraw/app_resources/simple.fragment.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma shader_stage(fragment)

#include "simple_common.hlsl"

[shader("pixel")]
float32_t4 main(PSInput input) : SV_TARGET
{
float32_t4 outColor = input.color;

return outColor;
}
21 changes: 21 additions & 0 deletions 34_DebugDraw/app_resources/simple.vertex.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma shader_stage(vertex)

#include "nbl/builtin/hlsl/bda/__ptr.hlsl"
#include "simple_common.hlsl"

using namespace nbl::hlsl;

[[vk::push_constant]] SSimplePushConstants pc;

[shader("vertex")]
PSInput main(uint vertexID : SV_VertexID)
{
PSInput output;

float32_t3 vertex = (bda::__ptr<float32_t3>::create(pc.pVertices) + vertexID).deref_restrict().load();

output.position = mul(pc.MVP, float32_t4(vertex, 1));
output.color = float32_t4(1, 0, 0, 1);

return output;
}
24 changes: 24 additions & 0 deletions 34_DebugDraw/app_resources/simple_common.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef _DRAW_AABB_SIMPLE_COMMON_HLSL
#define _DRAW_AABB_SIMPLE_COMMON_HLSL

#include "nbl/builtin/hlsl/cpp_compat.hlsl"

struct SSimplePushConstants
{
#ifdef __HLSL_VERSION
float32_t4x4 MVP;
#else
float MVP[4*4];
#endif
uint64_t pVertices;
};

#ifdef __HLSL_VERSION
struct PSInput
{
float32_t4 position : SV_Position;
float32_t4 color : TEXCOORD0;
};
#endif

#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