diff --git a/.idea/editor.xml b/.idea/editor.xml
index 907ea1b..2f7424b 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -287,7 +287,5 @@
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index efc4599..309514d 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,26 +2,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 13c04d7..369cb4d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
-project(gpu-particles VERSION 0.0.17)
+project(gpu-particles VERSION 0.0.18)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
@@ -12,6 +12,53 @@ add_subdirectory(lib/blt-with-graphics)
include_directories(include/)
file(GLOB_RECURSE PROJECT_BUILD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
+function(embed_file_as_raw_string INPUT OUTPUT NAMESPACE VAR_NAME)
+ file(READ "${INPUT}" CONTENTS)
+ file(WRITE "${OUTPUT}" "// Generated from ${INPUT}\n")
+ file(APPEND "${OUTPUT}" "#pragma once\n\n")
+ file(APPEND "${OUTPUT}" "namespace ${NAMESPACE} {\n\n")
+ file(APPEND "${OUTPUT}" "static constexpr char ${VAR_NAME}_str[] = R\"(\"${CONTENTS}\")\";\n\n}")
+endfunction()
+
+function(embed_directory INPUT_DIR)
+ # Get the name of the directory the user is trying to embed
+ get_filename_component(parent_name "${INPUT_DIR}" NAME)
+ # make sure directory uses forward slashes
+ file(TO_CMAKE_PATH "${INPUT_DIR}" INPUT_DIR)
+ set(OUTPUT_DIR "${CMAKE_BINARY_DIR}/embedded/${parent_name}")
+ # find all directories within the user folder relative to the input directory
+ file(GLOB_RECURSE INPUT_FILES RELATIVE "${INPUT_DIR}" "${INPUT_DIR}/*")
+
+ foreach(REL_PATH IN LISTS INPUT_FILES)
+ set(ABS_INPUT_PATH "${INPUT_DIR}/${REL_PATH}")
+ set(OUTPUT_HEADER "${OUTPUT_DIR}/${REL_PATH}.h")
+
+ get_filename_component(OUTPUT_HEADER_DIR "${OUTPUT_HEADER}" DIRECTORY)
+ file(MAKE_DIRECTORY "${OUTPUT_HEADER_DIR}")
+
+ # Get the name, extension and relative directory of the input path + file
+ get_filename_component(VAR_NAME "${REL_PATH}" NAME_WE)
+ get_filename_component(VAR_EXT "${REL_PATH}" EXT)
+ get_filename_component(VAR_DIR "${parent_name}/${REL_PATH}" DIRECTORY)
+ set(FILE_PATH "${VAR_NAME}_${VAR_EXT}")
+ # replace non-alphanum chars with "_" for the variable
+ string(REGEX REPLACE "[^a-zA-Z0-9]" "_" FILE_PATH "${FILE_PATH}")
+ string(REGEX REPLACE "__+" "_" FILE_PATH "${FILE_PATH}")
+
+ # replace non-alphanum chars with : for the namespace
+ string(REGEX REPLACE "[^a-zA-Z0-9]" "::" VAR_DIR ${VAR_DIR})
+ string(REGEX REPLACE ":::+" "::" VAR_DIR ${VAR_DIR})
+
+ message(STATUS "Converting file '${REL_PATH}' into variable '${VAR_NAME}' with namespace '${VAR_DIR}'")
+
+ embed_file_as_raw_string("${ABS_INPUT_PATH}" "${OUTPUT_HEADER}" "${VAR_DIR}" "${FILE_PATH}")
+ endforeach()
+
+ include_directories("${CMAKE_BINARY_DIR}/embedded")
+endfunction()
+
+embed_directory("${CMAKE_SOURCE_DIR}/shaders")
+
add_executable(gpu-particles ${PROJECT_BUILD_FILES})
target_compile_options(gpu-particles PRIVATE -Wall -Wextra -Wpedantic -Wno-comment)
diff --git a/lib/blt-with-graphics b/lib/blt-with-graphics
index 1808af6..dd3a242 160000
--- a/lib/blt-with-graphics
+++ b/lib/blt-with-graphics
@@ -1 +1 @@
-Subproject commit 1808af68b55e6bbcbc8ce82dcccbe12c21a7b38a
+Subproject commit dd3a242b4110552f9a9b9252d9abd28093e66d22
diff --git a/include/shaders/particle.frag b/shaders/particle.frag
similarity index 78%
rename from include/shaders/particle.frag
rename to shaders/particle.frag
index 572360a..f4d9ff1 100644
--- a/include/shaders/particle.frag
+++ b/shaders/particle.frag
@@ -1,6 +1,3 @@
-#ifdef __cplusplus
-#include
-const std::string shader_particle_2d_frag = R"("
#version 300 es
precision mediump float;
@@ -19,7 +16,4 @@ void main()
FragColor = texture(tex1, vec2(x, y));
else
FragColor = texture(tex2, vec2(x, y));
-}
-
-")";
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/include/shaders/particle.vert b/shaders/particle.vert
similarity index 80%
rename from include/shaders/particle.vert
rename to shaders/particle.vert
index 3e0f927..b40c57c 100644
--- a/include/shaders/particle.vert
+++ b/shaders/particle.vert
@@ -1,6 +1,3 @@
-#ifdef __cplusplus
-#include
-const std::string shader_particle_2d_vert = R"("
#version 300 es
precision mediump float;
@@ -24,7 +21,4 @@ void main()
else
silly = 0.0f;
gl_Position = ovm * vec4(position.x, position.y, 0.0, 1.0);
-}
-
-")";
-#endif
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 9a5d392..56d118b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,8 +19,8 @@
#include
#include
#include
-#include
-#include
+#include
+#include
#include "blt/gfx/renderer/batch_2d_renderer.h"
#include "blt/gfx/renderer/camera.h"
#include "blt/gfx/renderer/resource_manager.h"
@@ -62,7 +62,7 @@ public:
alive_particles.push_back(i);
}
- particle_shader = std::unique_ptr(shader_t::make(shader_particle_2d_vert, shader_particle_2d_frag));
+ particle_shader = std::unique_ptr(shader_t::make(shaders::particle_vert_str, shaders::particle_frag_str));
unique_vbo_t particle_vbo(GL_ARRAY_BUFFER);
particle_vbo.bind().upload(sizeof(particle_t) * particles.size(), particles.data(), GL_DYNAMIC_DRAW);