Skip to content

Commit bd5a008

Browse files
committed
- Dev: image config always accesible, capture texture better prepared for HDR, CMAKE distribution mode with relative path to resourcess
1 parent 587efdb commit bd5a008

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+796
-747
lines changed

CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ target_link_libraries(ImGuiFileDialog PUBLIC imgui )
5555

5656
# Setup sources
5757
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/add_module_files.cmake)
58-
set(ENGINE_SOURCES "src/utils.cpp")
58+
set(ENGINE_SOURCES "src/utils.cpp" "src/common.cpp")
5959
set(ENGINE_HEADERS "")
6060
add_module_files(core ENGINE_SOURCES ENGINE_HEADERS)
6161
add_module_files(graphics ENGINE_SOURCES ENGINE_HEADERS)
@@ -117,6 +117,24 @@ if(BUILD_TESTS)
117117
enable_testing()
118118
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
119119
endif()
120-
120+
# Choose if building the project for distribution
121+
option(DISTRIBUTION_MODE "Enable distribution mode (copy resources and set macro to build directory)" OFF)
122+
if(DISTRIBUTION_MODE)
123+
message(STATUS "Distribution mode: copying resources to build directory")
124+
125+
# Copy resources for distribution mode
126+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
127+
128+
# Define the macro for code (to be used in the engine)
129+
target_compile_definitions(VulkanEngine PUBLIC DISTRIBUTION_MODE=TRUE)
130+
131+
else()
132+
message(STATUS "Development mode: using resources in-place")
133+
134+
# Define the macro for development mode
135+
target_compile_definitions(VulkanEngine PUBLIC DISTRIBUTION_MODE=FALSE)
136+
137+
endif()
138+
# Set the resource path to the local source directory
121139
target_compile_definitions(VulkanEngine PUBLIC ENGINE_RESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/")
122140

CMakePresets.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,24 @@
8282
"CMAKE_CXX_EXTENSIONS": "OFF",
8383
"CMAKE_BUILD_TYPE": "Release"
8484
}
85-
}
85+
},
86+
{
87+
"name": "distribution",
88+
"displayName": "For Distribution (Ninja)",
89+
"generator": "Ninja",
90+
"binaryDir": "${sourceDir}/build/${presetName}",
91+
"cacheVariables": {
92+
"CMAKE_CXX_COMPILER": "clang++",
93+
"CMAKE_C_COMPILER": "clang",
94+
"CMAKE_CXX_STANDARD": "17",
95+
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
96+
"CMAKE_CXX_EXTENSIONS": "OFF",
97+
"CMAKE_BUILD_TYPE": "Release",
98+
"DISTRIBUTION_MODE": "ON",
99+
"BUILD_TESTS": "OFF",
100+
"BUILD_EXAMPLES": "ON"
101+
}
102+
}
86103

87104
],
88105

@@ -115,5 +132,11 @@
115132
"configurePreset": "GCC-x86_64-release",
116133
"configuration": "Release"
117134
}
135+
,
136+
{
137+
"name": "distribution",
138+
"configurePreset": "distribution",
139+
"configuration": "Release"
140+
}
118141
]
119142
}

examples/raytracing/application.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void Application::init(Systems::RendererSettings settings) {
1818
std::placeholders::_3,
1919
std::placeholders::_4));
2020

21-
Systems::DeferredRenderer* rndr = new Systems::DeferredRenderer(m_window, ShadowResolution::MEDIUM, settings);
21+
Systems::DeferredRenderer* rndr = new Systems::DeferredRenderer(m_window, settings);
2222
// SSAOSettings ao = {};
2323
// ao.type = AOType::RTAO;
2424
// ao.samples = 4;
@@ -52,9 +52,9 @@ void Application::run(int argc, char* argv[]) {
5252
}
5353

5454
void Application::setup() {
55-
const std::string MESH_PATH(EXAMPLES_RESOURCES_PATH "meshes/");
56-
const std::string TEXTURE_PATH(EXAMPLES_RESOURCES_PATH "textures/");
57-
const std::string ENGINE_MESH_PATH(ENGINE_RESOURCES_PATH "meshes/");
55+
const std::string MESH_PATH(GET_RESOURCE_PATH("meshes/"));
56+
const std::string TEXTURE_PATH(GET_RESOURCE_PATH("textures/"));
57+
const std::string ENGINE_MESH_PATH(GET_RESOURCE_PATH("meshes/"));
5858

5959
camera = new Camera();
6060
camera->set_position(Vec3(0.0f, 0.0f, -8.2f));

examples/renderer-app/application.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@ void Application::init(Systems::RendererSettings settings) {
77
m_window->init();
88
m_window->set_window_icon(EXAMPLES_RESOURCES_PATH "textures/ico.png");
99

10-
m_window->set_window_size_callback(
11-
std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
12-
m_window->set_mouse_callback(
13-
std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
14-
m_window->set_key_callback(std::bind(&Application::keyboard_callback,
15-
this,
16-
std::placeholders::_1,
17-
std::placeholders::_2,
18-
std::placeholders::_3,
19-
std::placeholders::_4));
20-
21-
m_renderer = new Systems::ForwardRenderer(m_window, ShadowResolution::MEDIUM, settings);
10+
m_window->set_window_size_callback(std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
11+
m_window->set_mouse_callback(std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
12+
m_window->set_key_callback(
13+
std::bind(&Application::keyboard_callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
14+
15+
m_renderer = new Systems::ForwardRenderer(m_window, settings);
2216

2317
setup();
2418

@@ -327,11 +321,9 @@ void Application::setup() {
327321
}
328322

329323
void Application::setup_gui() {
330-
m_interface.overlay = new Tools::GUIOverlay(
331-
(float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
324+
m_interface.overlay = new Tools::GUIOverlay((float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
332325

333-
Tools::Panel* tutorialPanel =
334-
new Tools::Panel("TUTORIAL", 0, 0.8f, 0.2f, 0.2f, PanelWidgetFlags::NoMove, false, true);
326+
Tools::Panel* tutorialPanel = new Tools::Panel("TUTORIAL", 0, 0.8f, 0.2f, 0.2f, PanelWidgetFlags::NoMove, false, true);
335327

336328
tutorialPanel->add_child(new Tools::Space());
337329
tutorialPanel->add_child(new Tools::Separator("CONTROLS"));
@@ -362,9 +354,8 @@ void Application::setup_gui() {
362354
m_interface.overlay->add_panel(explorerPanel);
363355
m_interface.explorer = explorerPanel;
364356

365-
Tools::Panel* propertiesPanel =
366-
new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
367-
m_interface.object = new Tools::ObjectExplorerWidget();
357+
Tools::Panel* propertiesPanel = new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
358+
m_interface.object = new Tools::ObjectExplorerWidget();
368359
propertiesPanel->add_child(m_interface.object);
369360

370361
m_interface.overlay->add_panel(propertiesPanel);
@@ -382,8 +373,8 @@ void Application::update() {
382373
if (animateLight)
383374
{
384375
float rotationAngle = glm::radians(10.0f * m_time.delta);
385-
float _x = light->get_position().x * cos(rotationAngle) - light->get_position().z * sin(rotationAngle);
386-
float _z = light->get_position().x * sin(rotationAngle) + light->get_position().z * cos(rotationAngle);
376+
float _x = light->get_position().x * cos(rotationAngle) - light->get_position().z * sin(rotationAngle);
377+
float _z = light->get_position().x * sin(rotationAngle) + light->get_position().z * cos(rotationAngle);
387378

388379
light->set_position({_x, light->get_position().y, _z});
389380
}

examples/rotating-kabuto/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ int main() {
3535
settings.samplesMSAA = MSAASamples::x4;
3636
settings.clearColor = Vec4(0.0, 0.0, 0.0, 1.0);
3737

38-
Systems::BaseRenderer* renderer =
39-
new Systems::ForwardRenderer(window,ShadowResolution::VERY_LOW, settings);
38+
Systems::BaseRenderer* renderer = new Systems::ForwardRenderer(window, settings);
4039

4140
Core::Camera* camera = new Core::Camera();
4241
camera->set_position(Vec3(0.0f, 0.15f, -1.0f));

examples/sponza/application.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@ void Application::init(Systems::RendererSettings settings) {
77
m_window->init();
88
m_window->set_window_icon(EXAMPLES_RESOURCES_PATH "textures/ico.png");
99

10-
m_window->set_window_size_callback(
11-
std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
12-
m_window->set_mouse_callback(
13-
std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
14-
m_window->set_key_callback(std::bind(&Application::keyboard_callback,
15-
this,
16-
std::placeholders::_1,
17-
std::placeholders::_2,
18-
std::placeholders::_3,
19-
std::placeholders::_4));
20-
21-
Systems::DeferredRenderer* rndr = new Systems::DeferredRenderer(m_window, ShadowResolution::MEDIUM, settings);
10+
m_window->set_window_size_callback(std::bind(&Application::window_resize_callback, this, std::placeholders::_1, std::placeholders::_2));
11+
m_window->set_mouse_callback(std::bind(&Application::mouse_callback, this, std::placeholders::_1, std::placeholders::_2));
12+
m_window->set_key_callback(
13+
std::bind(&Application::keyboard_callback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
14+
15+
Systems::DeferredRenderer* rndr = new Systems::DeferredRenderer(m_window, settings);
2216
m_renderer = rndr;
2317

2418
setup();
@@ -64,8 +58,7 @@ void Application::setup() {
6458
}
6559

6660
void Application::setup_gui() {
67-
m_interface.overlay = new Tools::GUIOverlay(
68-
(float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
61+
m_interface.overlay = new Tools::GUIOverlay((float)m_window->get_extent().width, (float)m_window->get_extent().height, GuiColorProfileType::DARK);
6962

7063
Tools::Panel* explorerPanel = new Tools::Panel("EXPLORER", 0, 0, 0.2f, 0.7f, PanelWidgetFlags::NoMove, false);
7164
m_interface.scene = new Tools::ExplorerWidget(m_scene, m_renderer);
@@ -80,9 +73,8 @@ void Application::setup_gui() {
8073
m_interface.overlay->add_panel(explorerPanel);
8174
m_interface.explorer = explorerPanel;
8275

83-
Tools::Panel* propertiesPanel =
84-
new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
85-
m_interface.object = new Tools::ObjectExplorerWidget();
76+
Tools::Panel* propertiesPanel = new Tools::Panel("OBJECT PROPERTIES", 0.75f, 0, 0.25f, 0.8f, PanelWidgetFlags::NoMove, true);
77+
m_interface.object = new Tools::ObjectExplorerWidget();
8678
propertiesPanel->add_child(m_interface.object);
8779

8880
m_interface.overlay->add_panel(propertiesPanel);

include/engine/common.h

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define COMMON_H
1111

1212
#ifdef _WIN32
13+
#include <windows.h>
1314
// Windows-specific includes and definitions
1415
#define VK_USE_PLATFORM_WIN32_KHR
1516
// #include <Volk/volk.h>
@@ -20,6 +21,7 @@
2021
#include <GLFW/glfw3native.h>
2122
#elif __linux__
2223
// Linux-specific includes and definitions
24+
#include <unistd.h>
2325
#include <vulkan/vulkan.h>
2426
#define GLFW_INCLUDE_VULKAN
2527
#define VK_USE_PLATFORM_XCB_KHR
@@ -33,6 +35,7 @@
3335
#include <cstdlib>
3436
#include <fstream>
3537
#define GLM_ENABLE_EXPERIMENTAL
38+
#include <filesystem>
3639
#include <glm/glm.hpp>
3740
#include <glm/gtc/matrix_transform.hpp>
3841
#include <glm/gtx/hash.hpp>
@@ -62,27 +65,27 @@
6265
#define PROFILING_FRAME()
6366
#endif
6467

65-
#define _LOG(msg) \
66-
{ \
67-
std::cout << "[VKEngine Log] " << msg << std::endl; \
68+
#define _LOG(msg) \
69+
{ \
70+
std::cout << "[VKEngine Log] " << msg << std::endl; \
6871
}
69-
#define DEBUG_LOG(msg) \
70-
{ \
71-
std::cout << "[VKEngine Debug] " << msg << std::endl; \
72+
#define DEBUG_LOG(msg) \
73+
{ \
74+
std::cout << "[VKEngine Debug] " << msg << std::endl; \
7275
}
73-
#define ERR_LOG(msg) \
74-
{ \
75-
std::cerr << "[VKEngine Error] " << msg << std::endl; \
76+
#define ERR_LOG(msg) \
77+
{ \
78+
std::cerr << "[VKEngine Error] " << msg << std::endl; \
7679
}
77-
#define VK_CHECK(x) \
78-
do \
79-
{ \
80-
VkResult err = x; \
81-
if (err) \
82-
{ \
83-
std::cout << "VKEngine detected a Vulkan error: " << err << std::endl; \
84-
abort(); \
85-
} \
80+
#define VK_CHECK(x) \
81+
do \
82+
{ \
83+
VkResult err = x; \
84+
if (err) \
85+
{ \
86+
std::cout << "VKEngine detected a Vulkan error: " << err << std::endl; \
87+
abort(); \
88+
} \
8689
} while (0)
8790

8891
// Namespace define
@@ -101,11 +104,14 @@
101104
#define PNG "png"
102105
#define HDR "hdr"
103106
#define JPG "jpg"
107+
#define BMP "bmp"
104108
#define TIF "tif"
105109
#define HAIR "hair"
106110

107111
#define CUBEMAP_FACES 6
108112

113+
static std::filesystem::path get_executable_dir();
114+
109115
/// Simple exception class, which stores a human-readable error description
110116
class VKFW_Exception : public std::runtime_error
111117
{
@@ -118,6 +124,12 @@ class VKFW_Exception : public std::runtime_error
118124

119125
VULKAN_ENGINE_NAMESPACE_BEGIN
120126

127+
namespace Paths {
128+
extern const std::filesystem::path RESOURCES_PATH;
129+
}
130+
131+
#define GET_RESOURCE_PATH(relative_path) ((Paths::RESOURCES_PATH / relative_path).string())
132+
121133
// Mathematics library glm
122134
namespace math = glm;
123135
typedef math::vec4 Vec4;
@@ -189,6 +201,11 @@ enum class SoftwareAA
189201
FXAA = 1,
190202
TAA = 2
191203
};
204+
typedef enum class FloatPrecission
205+
{
206+
F16 = 16,
207+
F32 = 32,
208+
} FPrecission;
192209
enum class SyncType
193210
{
194211
NONE = 0, // No framerate cap (POTENTIAL TEARING)
@@ -310,8 +327,7 @@ typedef enum ColorFormatTypeFlagBits
310327
DEPTH_16F = VK_FORMAT_D16_UNORM,
311328
DEPTH_32F = VK_FORMAT_D32_SFLOAT,
312329
RGB10A2 = VK_FORMAT_A2B10G10R10_UNORM_PACK32,
313-
}
314-
ColorFormatType;
330+
} ColorFormatType;
315331
typedef enum MipmapModeFlagsBits
316332
{
317333
MIPMAP_NEAREST = 0x00000001,

0 commit comments

Comments
 (0)