aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am61
-rw-r--r--src/engine.cpp27
-rw-r--r--src/path_utils.cpp14
-rw-r--r--src/path_utils.hpp20
-rw-r--r--src/spvshaders/Makefile.am9
-rw-r--r--src/spvshaders/shader.slang (renamed from src/shaders/shader.slang)0
6 files changed, 115 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..00e76ac
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,61 @@
+include ../common.am
+
+bin_PROGRAMS = engine
+
+engine_SOURCES = \
+ engine.cpp \
+ renderer.hpp renderer.cpp \
+ obj_parser.hpp obj_parser.cpp \
+ vulkan_utils.hpp \
+ path_utils.hpp path_utils.cpp \
+ stb_image.h \
+ stb_image.cpp \
+ fb/fb.hpp \
+ fb/chfb.hpp fb/chfb.cpp \
+ fb/pixfb.hpp fb/pixfb.cpp \
+ math/utils.hpp \
+ math/vector.hpp \
+ math/mat4.hpp \
+ math/quat.hpp \
+ math/tform.hpp \
+ o3d/mesh.hpp o3d/mesh.cpp \
+ o3d/obj3d.hpp \
+ o3d/vertex.hpp \
+ o3d/deriv_vertex.hpp \
+ o3d/tri.hpp \
+ o3d/tri_deriv.hpp \
+ o3d/polygon.hpp \
+ o3d/camera.hpp \
+ o3d/scene.hpp \
+ ctrl/keyboard.hpp \
+ ctrl/mouse.hpp \
+ shaders/shaders.hpp \
+ shaders/simple_shaders.hpp shaders/simple_shaders.cpp
+
+if DEBUG
+BINDIR_CXX = $(abs_builddir)
+SPVSHADERSDIR_CXX = $(abs_builddir)/spvshaders
+PKGDATADIR_CXX = $(abs_top_srcdir)
+else
+BINDIR_CXX = $(bindir)
+SPVSHADERSDIR_CXX = $(spvshadersdir)
+PKGDATADIR_CXX = $(pkgdatadir)
+endif
+
+engine_CPPFLAGS = -std=gnu++23 -Wall -Wextra -I'$(srcdir)/src' \
+ -DBINDIR='"$(BINDIR_CXX)"' \
+ -DPKGDATADIR='"$(PKGDATADIR_CXX)"' \
+ -DSPVSHADERSDIR='"$(SPVSHADERSDIR_CXX)"' \
+ $(GLFW3_CFLAGS) $(VULKAN_CFLAGS)
+if !DEBUG
+engine_CPPFLAGS += -DNDEBUG
+endif
+engine_LDFLAGS = -std=gnu++23 -Wall -Wextra
+engine_LDADD = $(GLFW3_LIBS) $(VULKAN_LIBS)
+
+if HAVE_NCURSES
+engine_CPPFLAGS += $(NCURSES_CFLAGS)
+engine_LDADD += $(NCURSES_LIBS)
+endif
+
+engine-stb_image.$(OBJEXT): CXXFLAGS += -Wno-unused-but-set-variable
diff --git a/src/engine.cpp b/src/engine.cpp
index a9991c4..1f57bd7 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -194,7 +194,7 @@ static void render_software(Renderer<FrameBuffer, Shaders>& renderer, const Matr
#ifdef HAVE_NCURSES
#define MKEY_ESC 27
-static int main_term(const std::filesystem::path& files_root, Scene& scene) {
+static int main_term(const engine::path_utils::Paths& paths, Scene& scene) {
// init
std::setlocale(LC_ALL, "");
initscr();
@@ -206,7 +206,7 @@ static int main_term(const std::filesystem::path& files_root, Scene& scene) {
curs_set(0);
int texture_w, texture_h, texture_channels;
- const auto texture_path = std::filesystem::path(files_root).append(ASSETS_TEXTURES_DIR "/viking_room.png");
+ const auto texture_path = paths.assets_textures() / "viking_room.png";
#ifdef _WIN32
const auto texture_path_wcstr = texture_path.c_str();
const auto texture_path_cstr_size = stbi_convert_wchar_to_utf8(nullptr, 0, texture_path_wcstr);
@@ -907,7 +907,7 @@ static void generate_mipmaps(VkCommandBuffer cmd_buf, VkPhysicalDevice physical_
}
}
-static int main_graphical(const std::filesystem::path& files_root, Scene& scene) {
+static int main_graphical(const engine::path_utils::Paths& paths, Scene& scene) {
// init window
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
@@ -1581,7 +1581,7 @@ static int main_graphical(const std::filesystem::path& files_root, Scene& scene)
// reading shader file
auto shader_module = [&] {
auto shader_code = [&] {
- const auto shader_path = std::filesystem::path(files_root).append(SHADERS_DIR "/shader.spv");
+ const auto shader_path = paths.spvshaders() / "shader.spv";
const auto shader_file_name = shader_path.c_str();
std::ifstream shader_file(shader_file_name, std::ios::ate | std::ios::binary);
if (!shader_file.is_open()) {
@@ -1832,7 +1832,7 @@ static int main_graphical(const std::filesystem::path& files_root, Scene& scene)
// create texture image
auto [texture_img, texture_mip_lvls, texture_img_device_mem, texture_w, texture_h, texture_pixels] = [&] {
int w, h, channels;
- const auto texture_path = std::filesystem::path(files_root).append(ASSETS_TEXTURES_DIR "/viking_room.png");
+ const auto texture_path = paths.assets_textures() / "viking_room.png";
#ifdef _WIN32
const auto texture_path_wcstr = texture_path.c_str();
const auto texture_path_cstr_size = stbi_convert_wchar_to_utf8(nullptr, 0, texture_path_wcstr);
@@ -2892,12 +2892,7 @@ static void parse_args(const std::vector<std::string_view>& args, Mode& mode) {
}
int main(int argc, char *argv[]) {
- const auto exe_path_opt = engine::path_utils::exe_path();
- if (!exe_path_opt) {
- std::cerr << "cannot find path of executable" << std::endl;
- exit(1);
- }
- const auto files_root = (*exe_path_opt).parent_path();
+ const auto paths = engine::path_utils::Paths();
Mode mode = Mode::graphical;
parse_args(convert_args(argc, argv), mode);
@@ -2920,7 +2915,7 @@ int main(int argc, char *argv[]) {
case GameType::suzanne:
return {
{
- engine::parse_object(std::filesystem::path(files_root).append(ASSETS_OBJS_DIR "/suzanne.obj")),
+ engine::parse_object(paths.assets_objs() / "suzanne.obj"),
{
Vector3(0.f, 0.f, 0.f),
Quaternion::one(),
@@ -2939,7 +2934,7 @@ int main(int argc, char *argv[]) {
}
},
{
- engine::parse_object(std::filesystem::path(files_root).append(ASSETS_OBJS_DIR "/suzanne.obj")),
+ engine::parse_object(paths.assets_objs() / "suzanne.obj"),
{
Vector3(0.f, 1.f, 0.f),
Quaternion::one(),
@@ -2950,7 +2945,7 @@ int main(int argc, char *argv[]) {
case GameType::test:
return {
{
- engine::parse_object(std::filesystem::path(files_root).append(ASSETS_OBJS_DIR "/viking_room.obj")),
+ engine::parse_object(paths.assets_objs() / "viking_room.obj"),
{
Vector3(0.f, .5f, 0.f),
Quaternion::look_towards({ -1.f, 0.f, 0.f }, { 0.f, 0.f, 1.f }).conjugate(),
@@ -2969,13 +2964,13 @@ int main(int argc, char *argv[]) {
return EXIT_SUCCESS;
case Mode::term:
#ifdef HAVE_NCURSES
- return main_term(files_root, scene);
+ return main_term(paths, scene);
#else
std::cerr << "Error: ncurses was not enabled during compilation." << std::endl;
return EXIT_FAILURE;
#endif
case Mode::graphical:
- return main_graphical(files_root, scene);
+ return main_graphical(paths, scene);
default:
std::unreachable();
}
diff --git a/src/path_utils.cpp b/src/path_utils.cpp
index df35ef1..94bbba5 100644
--- a/src/path_utils.cpp
+++ b/src/path_utils.cpp
@@ -1,4 +1,5 @@
#include "path_utils.hpp"
+#include <iostream>
#include <optional>
#include <filesystem>
#ifdef _WIN32
@@ -18,3 +19,16 @@ std::optional<std::filesystem::path> engine::path_utils::exe_path() noexcept {
# error "operating system not supported"
#endif
}
+
+engine::path_utils::Paths::Paths() noexcept {
+ const auto exe_path_opt = engine::path_utils::exe_path();
+ if (!exe_path_opt) {
+ std::cerr << "cannot find path of executable" << std::endl;
+ exit(1);
+ }
+ const auto files_root = (*exe_path_opt).parent_path();
+
+ m_assets_objs = files_root / std::filesystem::relative(PKGDATADIR "/assets/objs", BINDIR);
+ m_assets_textures = files_root / std::filesystem::relative(PKGDATADIR "/assets/textures", BINDIR);
+ m_spvshaders = files_root / std::filesystem::relative(SPVSHADERSDIR, BINDIR);
+}
diff --git a/src/path_utils.hpp b/src/path_utils.hpp
index e87aad6..76567bc 100644
--- a/src/path_utils.hpp
+++ b/src/path_utils.hpp
@@ -8,6 +8,26 @@ namespace engine::path_utils {
std::optional<std::filesystem::path> exe_path() noexcept;
+class Paths {
+ public:
+ Paths() noexcept;
+
+ const std::filesystem::path& assets_objs() const & noexcept {
+ return m_assets_objs;
+ }
+
+ const std::filesystem::path& assets_textures() const & noexcept {
+ return m_assets_textures;
+ }
+
+ const std::filesystem::path& spvshaders() const & noexcept {
+ return m_spvshaders;
+ }
+
+ private:
+ std::filesystem::path m_assets_objs, m_assets_textures, m_spvshaders;
+};
+
}
#endif // PATH_UTILS_HPP
diff --git a/src/spvshaders/Makefile.am b/src/spvshaders/Makefile.am
new file mode 100644
index 0000000..5a5a362
--- /dev/null
+++ b/src/spvshaders/Makefile.am
@@ -0,0 +1,9 @@
+include ../../common.am
+
+spvshaders_DATA = shader.spv
+CLEANFILES = shader.spv
+
+shader_spv_SLANGFLAGS = -target spirv -profile spirv_1_4 -emit-spirv-directly -fvk-use-entrypoint-name -entry vert_main -entry frag_main
+
+shader.spv: $(srcdir)/shader.slang
+ $(SLANGC) $(shader_spv_SLANGFLAGS) -o $@ $<
diff --git a/src/shaders/shader.slang b/src/spvshaders/shader.slang
index 245df4b..245df4b 100644
--- a/src/shaders/shader.slang
+++ b/src/spvshaders/shader.slang