aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2026-05-05 00:50:13 +0200
committerladevieq <ladevie.quentin@gmail.com>2026-05-05 00:50:49 +0200
commit37fdcb8a0f435c42f737252450626f2bd38bbd0f (patch)
tree7eeb45a2d2d08483409a04c74fbc74fb2bbcde9f /include
parent6818cbfe21beefc04e4a174d44a92159c34cead1 (diff)
Clean up around included files
Diffstat (limited to 'include')
-rw-r--r--include/aabb.hpp3
-rw-r--r--include/bvh.hpp5
-rw-r--r--include/camera.hpp2
-rw-r--r--include/gltf.hpp67
-rw-r--r--include/material.hpp15
-rw-r--r--include/mesh.hpp22
-rw-r--r--include/scene.hpp60
-rw-r--r--include/utils.hpp76
-rw-r--r--include/vec3.hpp2
-rw-r--r--include/vulkan-loader.hpp23
-rw-r--r--include/window.hpp89
11 files changed, 177 insertions, 187 deletions
diff --git a/include/aabb.hpp b/include/aabb.hpp
index adeb1fb..4e47a8f 100644
--- a/include/aabb.hpp
+++ b/include/aabb.hpp
@@ -1,8 +1,9 @@
#ifndef __AABB_HPP_
#define __AABB_HPP_
+#include <cstdint>
+
#include "vec3.hpp"
-#include "triangle.hpp"
class aabb {
public:
diff --git a/include/bvh.hpp b/include/bvh.hpp
index 2b66dcb..28a8554 100644
--- a/include/bvh.hpp
+++ b/include/bvh.hpp
@@ -1,10 +1,9 @@
#pragma once
-#include <vector>
+#include <cstdint>
-#include "aabb.hpp"
-// #include "sphere.hpp"
#include "triangle.hpp"
+#include "aabb.hpp"
struct bvh_node {
aabb bounding_box;
diff --git a/include/camera.hpp b/include/camera.hpp
index 5c1db61..ab81896 100644
--- a/include/camera.hpp
+++ b/include/camera.hpp
@@ -1,8 +1,6 @@
#ifndef __CAMERA_HPP_
#define __CAMERA_HPP_
-#include "vec3.hpp"
-
class camera {
public:
camera(
diff --git a/include/gltf.hpp b/include/gltf.hpp
index 1ccaf56..72d757c 100644
--- a/include/gltf.hpp
+++ b/include/gltf.hpp
@@ -3,59 +3,60 @@
#include <vector>
-#include <nlohmann/json.hpp>
-
-using json = nlohmann::json;
-
-#include "material.hpp"
+#include "utils.hpp"
+#include "handle.hpp"
#include "mesh.hpp"
+#include "material.hpp"
struct node {
- std::vector<node> children;
- Mesh* mesh = nullptr;
+ std::vector<uint32_t> children;
+ u32 mesh;
};
struct raw_image {
int32_t width;
int32_t height;
int32_t channels;
- uint8_t *data;
+ const uint8_t *data;
};
-namespace std::filesystem {
- class path;
-}
+struct buffer {
+ u8* bytes;
+ size_t size;
+};
class gltf {
public:
- gltf(const std::filesystem::path &filepath);
-
- node root_node;
-
-private:
-
- void load_node(uint32_t index, node &parent);
+ gltf(const char* filepath);
+ void deinit();
- void load_meshes();
+ std::vector<u32> root_nodes;
- Mesh::submesh load_primitive(const json &primitive);
-
- Mesh::attribute load_attribute(uint32_t accessor_index);
-
- void load_textures(const std::filesystem::path &path);
-
- void load_materials();
-
- json gltf_json;
+ std::vector<node> nodes;
std::vector<Mesh> meshes;
std::vector<material> materials;
-#ifdef API_TEST
std::vector<handle<device_texture>> textures;
// handle<device_sampler> samplers;
-#else
- std::vector<Texture*> textures;
-#endif // API_TEST
- std::vector<std::vector<uint8_t>> buffers;
+ std::vector<struct buffer> buffers;
+
+
+ // gbl only
+ struct glb_chunk {
+ u32 length;
+ u32 type;
+ u8 data[1];
+ };
+
+ struct glb_header {
+ u32 magic;
+ u32 version;
+ u32 length;
+ };
+ std::vector<struct glb_chunk*> chunks;
+ glb_header* header;
+
+ // TODO: remove
+ bool is_glb;
};
#endif
diff --git a/include/material.hpp b/include/material.hpp
index 35710d2..167e58e 100644
--- a/include/material.hpp
+++ b/include/material.hpp
@@ -1,24 +1,9 @@
#pragma once
-#include <cstdint>
-
-#include "vec3.hpp"
-
-#ifdef API_TEST
-#include "vk-device-types.hpp"
-#else
-class Texture;
-#endif
-
struct material {
color base_color;
-#ifdef API_TEST
handle<device_texture> base_color_texture;
handle<device_texture> metallic_roughness_texture;
-#else
- Texture* base_color_texture;
- Texture* metallic_roughness_texture;
-#endif // API_TEST
float metalness = 1.f;
float roughness = 1.f;
};
diff --git a/include/mesh.hpp b/include/mesh.hpp
index b88896d..c396814 100644
--- a/include/mesh.hpp
+++ b/include/mesh.hpp
@@ -1,15 +1,5 @@
#pragma once
-#include <cstdint>
-#include <vector>
-#include <array>
-
-#ifdef API_TEST
-#include "vk-device-types.hpp"
-#else
-#include "vk-renderer.hpp"
-#endif // API_TEST
-
enum ATTRIBUTE_TYPE {
POSITION,
NORMAL,
@@ -34,15 +24,15 @@ public:
};
struct attribute {
- uint8_t* data = nullptr;
+ const uint8_t* data = nullptr;
size_t length = 0;
};
struct submesh {
attribute indices;
std::array<attribute, ATTRIBUTE_TYPE::MAX_ATTRIBUTE> attributes;
- uint32_t vertex_count = 0;
- uint32_t index_count = 0;
+ u32 vertex_count = 0;
+ u32 index_count = 0;
// material& material;
};
@@ -93,15 +83,9 @@ private:
std::vector<submesh_info> submeshes;
struct gpu_mesh {
-#ifdef API_TEST
std::array<handle<device_buffer>, ATTRIBUTE_TYPE::MAX_ATTRIBUTE> attributes;
const device_buffer& indices;
const device_buffer& submeshes;
-#else
- std::array<Buffer*, ATTRIBUTE_TYPE::MAX_ATTRIBUTE> attributes;
- Buffer* indices;
- Buffer* submeshes;
-#endif // API_TEST
};
// allocate gpu mesh upon instanciation
diff --git a/include/scene.hpp b/include/scene.hpp
index 091e4fc..a1c76e2 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -1,44 +1,36 @@
#ifndef __SCENE_HPP_
#define __SCENE_HPP_
-#include <cstdint>
-
-#ifdef API_TEST
-#include "vk-device-types.hpp"
-#include "vk-device.hpp"
-#endif // API_TEST
-#include "camera.hpp"
-
class Buffer;
-class scene {
- struct metadata {
- camera cam;
+struct metadata {
+ camera cam;
- uint32_t max_bounce = 3;
- uint32_t min_bounce = 1;
+ uint32_t max_bounce = 3;
+ uint32_t min_bounce = 1;
- uint32_t width;
- uint32_t height;
+ uint32_t width;
+ uint32_t height;
- uint32_t sample_index = 0;
+ uint32_t sample_index = 1;
- uint32_t enable_dof = (uint32_t)false;
- uint32_t debug_bvh = (uint32_t)false;
- int32_t downscale_factor = 2;
+ uint32_t enable_dof = (uint32_t)false;
+ uint32_t debug_bvh = (uint32_t)false;
+ int32_t downscale_factor = 1;
- metadata(const camera &cam, uint32_t width, uint32_t height);
- };
+ metadata(const camera &cam, uint32_t width, uint32_t height);
+};
+class scene {
// void random_scene();
+ gltf model;
public:
scene(const camera& cam, uint32_t width, uint32_t height);
+ void deinit();
metadata meta;
-#ifdef API_TEST
- handle<device_buffer> scene_buffer_handle;
handle<device_buffer> indices_buffer_handle;
handle<device_buffer> positions_buffer_handle;
handle<device_buffer> normals_buffer_handle;
@@ -46,22 +38,12 @@ public:
handle<device_buffer> bvh_buffer_handle;
handle<device_buffer> materials_buffer_handle;
- uint64_t scene_buffer_address() { return vkdevice::get_render_device().get_buffer(scene_buffer_handle).device_address; };
- uint64_t indices_buffer_address() { return vkdevice::get_render_device().get_buffer(indices_buffer_handle).device_address; };
- uint64_t positions_buffer_address() { return vkdevice::get_render_device().get_buffer(positions_buffer_handle).device_address; };
- uint64_t normals_buffer_address() { return vkdevice::get_render_device().get_buffer(normals_buffer_handle).device_address; };
- uint64_t uvs_buffer_address() { return vkdevice::get_render_device().get_buffer(uvs_buffer_handle).device_address; };
- uint64_t bvh_buffer_address() { return vkdevice::get_render_device().get_buffer(bvh_buffer_handle).device_address; };
- uint64_t materials_buffer_address() { return vkdevice::get_render_device().get_buffer(materials_buffer_handle).device_address; };
-#else
- Buffer* scene_buffer;
- Buffer* indices_buffer;
- Buffer* positions_buffer;
- Buffer* normals_buffer;
- Buffer* uvs_buffer;
- Buffer* bvh_buffer;
- Buffer* materials_buffer;
-#endif // API_TEST
+ uint64_t indices_buffer_address() { return vkdevice::get().get_buffer(indices_buffer_handle).device_address; };
+ uint64_t positions_buffer_address() { return vkdevice::get().get_buffer(positions_buffer_handle).device_address; };
+ uint64_t normals_buffer_address() { return vkdevice::get().get_buffer(normals_buffer_handle).device_address; };
+ uint64_t uvs_buffer_address() { return vkdevice::get().get_buffer(uvs_buffer_handle).device_address; };
+ uint64_t bvh_buffer_address() { return vkdevice::get().get_buffer(bvh_buffer_handle).device_address; };
+ uint64_t materials_buffer_address() { return vkdevice::get().get_buffer(materials_buffer_handle).device_address; };
};
#endif // !__SCENE_HPP_
diff --git a/include/utils.hpp b/include/utils.hpp
index e49b218..19a5d9f 100644
--- a/include/utils.hpp
+++ b/include/utils.hpp
@@ -1,13 +1,56 @@
#pragma once
-#include <vector>
-#include <unordered_map>
+static constexpr size_t KB = 1024U;
+static constexpr size_t MB = 1024U * KB;
+static constexpr size_t GB = 1024U * MB;
+const char* DUMMY_NAME = "NO_NAME";
-std::vector<uint8_t> read_file(const char* path);
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef int8_t s8;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef int64_t s64;
+
+uint8_t* read_file(const char* path, size_t size);
+
+const uint32_t max_markers = 1024U;
+// hashmap ?
+uint32_t marker_count = 0U;
+const char* marker_names[max_markers] = { 0 };
+uint64_t marker_counter_start[max_markers] = { 0 };
+uint64_t marker_counter_end[max_markers] = { 0 };
+
+#define BEGIN_MARKER(name) \
+ static uint32_t marker_##name##_index = UINT32_MAX; \
+ do { \
+ if (marker_##name##_index == UINT32_MAX) { \
+ marker_##name##_index = marker_count++; \
+ marker_names[marker_##name##_index] = #name; \
+ } \
+ { \
+ LARGE_INTEGER start_qpc; \
+ QueryPerformanceCounter(&start_qpc); \
+ marker_counter_start[marker_##name##_index] = start_qpc.QuadPart; \
+ } \
+ } while(0);
+
+#define END_MARKER(name) \
+ do { \
+ LARGE_INTEGER end_qpc; \
+ QueryPerformanceCounter(&end_qpc); \
+ marker_counter_end[marker_##name##_index] = end_qpc.QuadPart; \
+ } while(0);
#define PI 3.14159265359
#define EPSILON 0.000001
+
+#define ALIGN(value, alignment) \
+ (((value) + ((alignment) - 1)) & ~((alignment) - 1))
+
inline float deg_to_rad(float deg) {
return static_cast<float>(deg * PI / 180.f);
}
@@ -31,31 +74,14 @@ inline float clamp(float x, float min, float max) {
}
-#if defined(WINDOWS)
-
-#include <windows.h>
+#if _WIN32
void log_last_error();
-class watcher {
-public:
- typedef void(*func)(void);
-
- static bool watch_file(const char* filepath, func callback);
-
- static bool watch_dir(const char* dir_path);
-
- static void pull_changes();
-
-private:
+typedef void(*func)(void);
+bool watch_file(const char* filepath, func callback);
- struct watch_data {
- HANDLE dir_handle;
- OVERLAPPED overlapped;
- DWORD buffer[512];
- };
+bool watch_dir(const char* dir_path);
- inline static std::unordered_map<const char*, func> callbacks;
- inline static std::unordered_map<const char*, watch_data> watched_dirs;
-};
+void pull_changes();
#endif
diff --git a/include/vec3.hpp b/include/vec3.hpp
index 42172e6..5fd143d 100644
--- a/include/vec3.hpp
+++ b/include/vec3.hpp
@@ -1,7 +1,6 @@
#ifndef __VEC3_HPP_
#define __VEC3_HPP_
-#include <xmmintrin.h>
#include <cstdint>
struct vec3u {
@@ -60,6 +59,7 @@ class vec3 {
vec3& normalize();
[[nodiscard]] bool near_zero() const;
+ [[nodiscard]] bool is_zero() const;
void print() const;
diff --git a/include/vulkan-loader.hpp b/include/vulkan-loader.hpp
index ec1464d..7a3a68e 100644
--- a/include/vulkan-loader.hpp
+++ b/include/vulkan-loader.hpp
@@ -3,8 +3,7 @@
#define VK_NO_PROTOTYPES
-#if defined(WINDOWS)
-#include <vulkan/vk_platform.h>
+#if _WIN32
#include <vulkan/vulkan_core.h>
typedef unsigned long DWORD;
typedef const wchar_t* LPCWSTR;
@@ -24,7 +23,6 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
X(vkGetInstanceProcAddr) \
X(vkGetDeviceProcAddr)
-
#define VULKAN_APPLICATION_FUNCTIONS \
X(vkCreateInstance) \
X(vkEnumerateInstanceVersion) \
@@ -154,32 +152,15 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
X(vkDestroyBuffer) \
X(vkDestroyRenderPass)
+
#define X(name) extern PFN_##name name;
- VULKAN_EXPORTED_FUNCTIONS
VULKAN_APPLICATION_FUNCTIONS
VULKAN_INSTANCE_FUNCTIONS
VULKAN_DEVICE_FUNCTIONS
#undef X
-
-#define X(name) void Load_##name();
- VULKAN_EXPORTED_FUNCTIONS
- VULKAN_APPLICATION_FUNCTIONS
-#undef X
-
-#define X(name) void Load_##name(VkInstance _instance);
- VULKAN_INSTANCE_FUNCTIONS
-#undef X
-
-#define X(name) void Load_##name(VkDevice _device);
- VULKAN_DEVICE_FUNCTIONS
-#undef X
-
-
void load_vulkan();
-
void load_instance_functions(VkInstance instance);
-
void load_device_functions(VkDevice device);
#endif // !__VULKAN_LOADER_HPP_
diff --git a/include/window.hpp b/include/window.hpp
index 2484742..9c79614 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -1,23 +1,10 @@
#ifndef __WINDOW_HPP_
#define __WINDOW_HPP_
-#include <vector>
-
-class vkrenderer;
-
#if defined(LINUX)
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
-#elif defined(WINDOWS)
-// #include <Windows.h>
-typedef struct HWND__* HWND;
-typedef int64_t LRESULT;
-typedef int64_t LPARAM;
-typedef uint64_t WPARAM;
-typedef unsigned int UINT;
-typedef void* LPVOID;
-#define CALLBACK __stdcall
#endif
// enum MODIFIERS: uint32_t {
@@ -37,14 +24,22 @@ typedef void* LPVOID;
// };
// TODO improve this
-#if defined(WINDOWS)
-enum KEYS: uint32_t {
+#if _WIN32
+enum KEY: uint32_t {
LSHIFT = 0x10,
RSHIFT = 0x10,
LCTRL = 0x11,
RCTRL = 0x11,
ALT,
SPACE = 0x20,
+ PAGE_UP,
+ PAGE_DOWN,
+ END,
+ HOME,
+ LEFT_ARROW,
+ UP_ARROW,
+ RIGHT_ARROW,
+ DOWN_ARROW,
A = 0x41,
B,
C,
@@ -71,10 +66,22 @@ enum KEYS: uint32_t {
X,
Y,
Z,
- MAX_KEYS = 255
+ F1 = 0x70,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
+ MAX_KEY = 0xff
};
#else
-enum KEYS: uint32_t {
+enum KEY: uint32_t {
SPACE = 32,
A = 0x61,
B,
@@ -108,25 +115,43 @@ enum KEYS: uint32_t {
RCTRL,
LALT = 65513,
RALT,
- MAX_KEYS = 0xffff
+ MAX_KEY = 0xffff
};
#endif
-enum BUTTONS: uint32_t {
+enum BUTTON: uint32_t {
LEFT,
RIGHT,
MIDDLE,
- MAX_BUTTONS = 255
+ MAX_BUTTON = 255
};
-enum EVENT_TYPES: int32_t {
+enum EVENT_TYPE: int32_t {
QUIT,
RESIZE,
KEY_PRESS,
+ KEY_DOWN,
KEY_RELEASE,
+ KEY_UP,
BUTTON_PRESS,
BUTTON_RELEASE,
- MOUSE_MOVE
+ MOUSE_MOVE,
+ MOUSE_WHEEL,
+};
+
+enum CURSOR_TYPE: int32_t {
+ ARROW,
+ TEXT_INPUT,
+ SIZE_ALL,
+ SIZE_NS,
+ SIZE_WE,
+ SIZE_NESW,
+ SIZE_NWSE,
+ HAND,
+ WAIT,
+ PROGRESS,
+ NOT_ALLOWED,
+ MAX_CURSOR,
};
// struct event {
@@ -148,10 +173,14 @@ struct event {
int32_t x;
int32_t y;
} position;
- KEYS key;
- BUTTONS button;
+ struct {
+ int32_t x;
+ int32_t y;
+ } delta;
+ KEY key;
+ BUTTON button;
} data;
- EVENT_TYPES type;
+ EVENT_TYPE type;
};
class window {
@@ -161,13 +190,15 @@ class window {
void poll_events();
-#if defined(WINDOWS)
+#if _WIN32
void message_loop();
LRESULT message_handler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
+ static void set_cursor(enum CURSOR_TYPE type);
+
HWND handle {};
const char* window_class_name;
LPVOID main_fiber;
@@ -190,8 +221,10 @@ class window {
bool isOpen;
- bool keyboard[KEYS::MAX_KEYS] { false };
- bool mouse[BUTTONS::MAX_BUTTONS] { false };
+ bool keyboard[KEY::MAX_KEY] { false };
+ bool mouse[BUTTON::MAX_BUTTON] { false };
+
+ static HCURSOR cursors[CURSOR_TYPE::MAX_CURSOR];
};
#endif // !__WINDOW_HPP_