From 5308cacd2322493a893ead4d175048124c984ea0 Mon Sep 17 00:00:00 2001 From: Brett Date: Sun, 20 Nov 2022 13:07:45 -0500 Subject: [PATCH] Added the ability to recusively load shader files include statements are the only form of file chaining supported. define statements can now be replaced at load time with global variable. --- Step 3/CMakeLists.txt | 7 +- .../CMakeFiles/clion-log.txt | 1 + Step 3/cmake-build-debug/build.ninja | 44 ++++++- Step 3/include/engine/math/bvh.h | 8 +- Step 3/include/engine/math/colliders.h | 11 ++ Step 3/include/engine/math/vectors.h | 30 +++++ Step 3/include/engine/util/loaders.h | 21 ++++ Step 3/include/engine/world.h | 2 +- Step 3/include/opencl/cl.h | 37 ++++++ Step 3/resources/shaders/test.h | 7 ++ Step 3/resources/shaders/world.vs | 2 + Step 3/src/engine/main.cpp | 10 ++ Step 3/src/engine/math/bvh.cpp | 12 +- Step 3/src/engine/math/colliders.cpp | 23 ++++ Step 3/src/engine/util/loaders.cpp | 110 ++++++++++++++++++ Step 3/src/engine/world.cpp | 6 +- Step 3/src/graphics/debug_gui.cpp | 6 +- Step 3/src/graphics/gl/shader.cpp | 2 + Step 3/src/graphics/graphics.cpp | 2 +- Step 3/src/opencl/cl.cpp | 34 ++++++ 20 files changed, 355 insertions(+), 20 deletions(-) create mode 100644 Step 3/include/engine/util/loaders.h create mode 100644 Step 3/include/opencl/cl.h create mode 100644 Step 3/resources/shaders/test.h create mode 100644 Step 3/src/engine/util/loaders.cpp create mode 100644 Step 3/src/opencl/cl.cpp diff --git a/Step 3/CMakeLists.txt b/Step 3/CMakeLists.txt index 9bc44bd..2be52f4 100644 --- a/Step 3/CMakeLists.txt +++ b/Step 3/CMakeLists.txt @@ -101,7 +101,7 @@ endif() # Windows should be able to handle opencl no problem. # i decided that i wanted to use opencl due to it having a much nicer c99 language. if (COMPILE_OPENCL MATCHES ON) - find_package(OpenCL) + find_package(OpenCL REQUIRED) if (NOT OpenCL_FOUND) message("Unable to find OpenCL on your system. Do you have the required libs?") @@ -132,8 +132,11 @@ if (USE_GLFW MATCHES ON AND glfw3_FOUND) target_link_libraries(${PROJECT_NAME} glfw) endif () -if (COMPILE_OPENCL MATCHES ON) +if (COMPILE_OPENCL) + message("Compiling OpenCL ${OpenCL_LIBRARIES} || ${OpenCL_LIBRARY}") target_link_libraries(${PROJECT_NAME} ${OpenCL_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} ${OpenCL_LIBRARY}) + target_compile_definitions(${PROJECT_NAME} PRIVATE CL_TARGET_OPENCL_VERSION=220) endif () if (USE_OPENMP) diff --git a/Step 3/cmake-build-debug/CMakeFiles/clion-log.txt b/Step 3/cmake-build-debug/CMakeFiles/clion-log.txt index 09d5c8e..ce2c9be 100644 --- a/Step 3/cmake-build-debug/CMakeFiles/clion-log.txt +++ b/Step 3/cmake-build-debug/CMakeFiles/clion-log.txt @@ -3,6 +3,7 @@ Building for Debug release mode Compiling with GUI. Found GLFW3! +Compiling OpenCL /usr/lib/x86_64-linux-gnu/libOpenCL.so || /usr/lib/x86_64-linux-gnu/libOpenCL.so -- Configuring done -- Generating done -- Build files have been written to: /home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug diff --git a/Step 3/cmake-build-debug/build.ninja b/Step 3/cmake-build-debug/build.ninja index 3e53191..8492a05 100644 --- a/Step 3/cmake-build-debug/build.ninja +++ b/Step 3/cmake-build-debug/build.ninja @@ -50,6 +50,7 @@ cmake_ninja_workdir = /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/cmake build cmake_object_order_depends_target_Step_3: phony || CMakeFiles/Step_3.dir build CMakeFiles/Step_3.dir/src/engine/globals.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/globals.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/globals.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -57,6 +58,7 @@ build CMakeFiles/Step_3.dir/src/engine/globals.cpp.o: CXX_COMPILER__Step_3_Debug OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine build CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/image/image.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -64,6 +66,7 @@ build CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o: CXX_COMPILER__Step_3_D OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/image build CMakeFiles/Step_3.dir/src/engine/main.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/main.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/main.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -71,6 +74,7 @@ build CMakeFiles/Step_3.dir/src/engine/main.cpp.o: CXX_COMPILER__Step_3_Debug /h OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine build CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/math/bvh.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -78,6 +82,7 @@ build CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o: CXX_COMPILER__Step_3_Debu OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/math build CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/math/colliders.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -85,6 +90,7 @@ build CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o: CXX_COMPILER__Step_ OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/math build CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/raytracing.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -92,13 +98,23 @@ build CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o: CXX_COMPILER__Step_3_De OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine build CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/util/debug.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" OBJECT_DIR = CMakeFiles/Step_3.dir OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/util +build CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/util/loaders.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 + DEP_FILE = CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o.d + FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 + INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" + OBJECT_DIR = CMakeFiles/Step_3.dir + OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/util + build CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/util/models.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -106,6 +122,7 @@ build CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o: CXX_COMPILER__Step_3_D OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/util build CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/util/parser.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -113,6 +130,7 @@ build CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o: CXX_COMPILER__Step_3_D OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine/util build CMakeFiles/Step_3.dir/src/engine/world.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/engine/world.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/engine/world.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -120,6 +138,7 @@ build CMakeFiles/Step_3.dir/src/engine/world.cpp.o: CXX_COMPILER__Step_3_Debug / OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/engine build CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/debug_gui.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -127,6 +146,7 @@ build CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o: CXX_COMPILER__Step_3_D OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics build CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o: C_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/gl/gl.c || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o.d FLAGS = -g -fsanitize=address INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -134,6 +154,7 @@ build CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o: C_COMPILER__Step_3_Debug /ho OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/gl build CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/gl/gl.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -141,6 +162,7 @@ build CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o: CXX_COMPILER__Step_3_Debug OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/gl build CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/gl/shader.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -148,6 +170,7 @@ build CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o: CXX_COMPILER__Step_3_D OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/gl build CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/graphics.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -155,6 +178,7 @@ build CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o: CXX_COMPILER__Step_3_De OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -162,6 +186,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o: CXX_COMPILER__Step_3 OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_demo.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -169,6 +194,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o: CXX_COMPILER__S OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_draw.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -176,6 +202,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o: CXX_COMPILER__S OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_impl_glfw.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -183,6 +210,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o: CXX_COMPIL OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_impl_opengl3.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -190,6 +218,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o: CXX_COM OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_impl_x11.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -197,6 +226,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o: CXX_COMPILE OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_tables.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -204,6 +234,7 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o: CXX_COMPILER_ OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/imgui/imgui_widgets.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" @@ -211,12 +242,21 @@ build CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o: CXX_COMPILER OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics/imgui build CMakeFiles/Step_3.dir/src/graphics/input.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/graphics/input.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 DEP_FILE = CMakeFiles/Step_3.dir/src/graphics/input.cpp.o.d FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" OBJECT_DIR = CMakeFiles/Step_3.dir OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/graphics +build CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o: CXX_COMPILER__Step_3_Debug /home/brett/Documents/Brock/CS$ 3P93/Project/Step$ 3/src/opencl/cl.cpp || cmake_object_order_depends_target_Step_3 + DEFINES = -DCL_TARGET_OPENCL_VERSION=220 + DEP_FILE = CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o.d + FLAGS = -fsanitize=address -g -march=native -g -fsanitize=address -std=gnu++20 + INCLUDES = -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/cmake-build-debug" -I"/home/brett/Documents/Brock/CS 3P93/Project/Step 3/include" + OBJECT_DIR = CMakeFiles/Step_3.dir + OBJECT_FILE_DIR = CMakeFiles/Step_3.dir/src/opencl + # ============================================================================= # Link build statements for EXECUTABLE target Step_3 @@ -225,10 +265,10 @@ build CMakeFiles/Step_3.dir/src/graphics/input.cpp.o: CXX_COMPILER__Step_3_Debug ############################################# # Link the executable Step_3 -build Step_3: CXX_EXECUTABLE_LINKER__Step_3_Debug CMakeFiles/Step_3.dir/src/engine/globals.cpp.o CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o CMakeFiles/Step_3.dir/src/engine/main.cpp.o CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o CMakeFiles/Step_3.dir/src/engine/world.cpp.o CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o CMakeFiles/Step_3.dir/src/graphics/input.cpp.o | /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so +build Step_3: CXX_EXECUTABLE_LINKER__Step_3_Debug CMakeFiles/Step_3.dir/src/engine/globals.cpp.o CMakeFiles/Step_3.dir/src/engine/image/image.cpp.o CMakeFiles/Step_3.dir/src/engine/main.cpp.o CMakeFiles/Step_3.dir/src/engine/math/bvh.cpp.o CMakeFiles/Step_3.dir/src/engine/math/colliders.cpp.o CMakeFiles/Step_3.dir/src/engine/raytracing.cpp.o CMakeFiles/Step_3.dir/src/engine/util/debug.cpp.o CMakeFiles/Step_3.dir/src/engine/util/loaders.cpp.o CMakeFiles/Step_3.dir/src/engine/util/models.cpp.o CMakeFiles/Step_3.dir/src/engine/util/parser.cpp.o CMakeFiles/Step_3.dir/src/engine/world.cpp.o CMakeFiles/Step_3.dir/src/graphics/debug_gui.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.c.o CMakeFiles/Step_3.dir/src/graphics/gl/gl.cpp.o CMakeFiles/Step_3.dir/src/graphics/gl/shader.cpp.o CMakeFiles/Step_3.dir/src/graphics/graphics.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_demo.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_draw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_glfw.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_opengl3.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_impl_x11.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_tables.cpp.o CMakeFiles/Step_3.dir/src/graphics/imgui/imgui_widgets.cpp.o CMakeFiles/Step_3.dir/src/graphics/input.cpp.o CMakeFiles/Step_3.dir/src/opencl/cl.cpp.o | /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so FLAGS = -fsanitize=address -g -march=native -g LINK_FLAGS = -fsanitize=address - LINK_LIBRARIES = -lpthread /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so + LINK_LIBRARIES = -lpthread /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libglfw.so.3.3 /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libOpenCL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libOpenGL.so OBJECT_DIR = CMakeFiles/Step_3.dir POST_BUILD = : PRE_LINK = : diff --git a/Step 3/include/engine/math/bvh.h b/Step 3/include/engine/math/bvh.h index 034408b..ff9b541 100644 --- a/Step 3/include/engine/math/bvh.h +++ b/Step 3/include/engine/math/bvh.h @@ -114,11 +114,11 @@ namespace Raytracing { if (left.left.size() != right.left.size() || left.right.size() != right.right.size()) return false; for (int i = 0; i < left.left.size(); i++) { - if (left.left[i].aabb != right.left[i].aabb) + if (!(left.left[i].aabb == right.left[i].aabb)) return false; } for (int i = 0; i < left.right.size(); i++) { - if (left.right[i].aabb != right.right[i].aabb) + if (!(left.right[i].aabb == right.right[i].aabb)) return false; } return true; @@ -138,7 +138,7 @@ namespace Raytracing { int index, hit = 0; BVHHitData firstHitRayIntersectTraversal(const Ray& r, PRECISION_TYPE min, PRECISION_TYPE max); TriangleBVHNode(std::vector objs, AABB aabb, TriangleBVHNode* left, TriangleBVHNode* right) - : objs(std::move(objs)), aabb(std::move(aabb)), left(left), right(right) {} + : objs(std::move(objs)), aabb(std::move(aabb)), left(left), right(right) {index = count++;} ~TriangleBVHNode() { delete (left); delete (right); @@ -152,6 +152,7 @@ namespace Raytracing { static TriangleBVHPartitionedSpace partition(const std::pair& aabbs, const std::vector& objs); TriangleBVHNode* addObjectsRecursively(const std::vector& objects, const TriangleBVHPartitionedSpace& prevSpace); public: + int index; explicit TriangleBVHTree(const std::vector& objectsInWorld) { addObjects(objectsInWorld); #ifdef COMPILE_GUI @@ -159,6 +160,7 @@ namespace Raytracing { if (aabbVAO == nullptr) aabbVAO = std::make_shared(aabbVertexData.cubeVerticesRaw, aabbVertexData.cubeUVs); #endif + index = count++; } void addObjects(const std::vector& objects); diff --git a/Step 3/include/engine/math/colliders.h b/Step 3/include/engine/math/colliders.h index ee07546..88fe458 100644 --- a/Step 3/include/engine/math/colliders.h +++ b/Step 3/include/engine/math/colliders.h @@ -110,6 +110,7 @@ namespace Raytracing { [[nodiscard]] PRECISION_TYPE longestAxisLength() const; [[nodiscard]] std::pair splitByLongestAxis(); [[nodiscard]] std::pair splitAlongAxis(AABBAxis axis); + [[nodiscard]] std::pair splitAlongAxis(); [[nodiscard]] PRECISION_TYPE avgDistanceFromCenter() const; @@ -140,6 +141,16 @@ namespace Raytracing { const auto& bMin = b.getMin(); return aMax == bMax && aMin == bMin; } + + inline bool operator&=(const AABB& a, const AABB& b) { + const auto& aMax = a.getMax(); + const auto& aMin = a.getMin(); + const auto& bMax = b.getMax(); + const auto& bMin = b.getMin(); + PRECISION_TYPE E = 0.5; + return (aMax < bMax + E && aMax > bMax - E && aMin < bMin + E && aMin > bMin - E); + return aMax == bMax && aMin == bMin; + } inline std::ostream& operator<<(std::ostream& out, const AABB& v) { auto max = v.getMax(); diff --git a/Step 3/include/engine/math/vectors.h b/Step 3/include/engine/math/vectors.h index 3ce6036..4e1f3b9 100644 --- a/Step 3/include/engine/math/vectors.h +++ b/Step 3/include/engine/math/vectors.h @@ -349,11 +349,41 @@ namespace Raytracing { return {left.x() + right.x(), left.y() + right.y(), left.z() + right.z(), left.w() + right.w()}; } + // adds all vector axis with a constant + inline Vec4 operator+(const Vec4& left, const PRECISION_TYPE right) { + return {left.x() + right, left.y() + right, left.z() + right, left.w() + right}; + } + + // checks if the 3 major axis on the left are less than the right + inline bool operator<(const Vec4& left, const Vec4& right) { + return left.x() < right.x() && left.y() < right.y() && left.z() < right.z(); + } + + // checks if the 3 major axis on the left are greater than the right + inline bool operator>(const Vec4& left, const Vec4& right) { + return left.x() > right.x() && left.y() > right.y() && left.z() > right.z(); + } + + // checks if the 3 major axis on the left are less equal than the right + inline bool operator<=(const Vec4& left, const Vec4& right) { + return left.x() <= right.x() && left.y() <= right.y() && left.z() <= right.z() && left.w() <= right.w(); + } + + // checks if all major axis on the left are greater equal than the right + inline bool operator>=(const Vec4& left, const Vec4& right) { + return left.x() >= right.x() && left.y() >= right.y() && left.z() >= right.z() && left.w() >= right.w(); + } + // subtracts the right vector from the left. inline Vec4 operator-(const Vec4& left, const Vec4& right) { return {left.x() - right.x(), left.y() - right.y(), left.z() - right.z(), left.w() - right.w()}; } + // subtracts all vector axis with a constant + inline Vec4 operator-(const Vec4& left, const PRECISION_TYPE right) { + return {left.x() - right, left.y() - right, left.z() - right, left.w() - right}; + } + // multiples the left with the right inline Vec4 operator*(const Vec4& left, const Vec4& right) { return {left.x() * right.x(), left.y() * right.y(), left.z() * right.z(), left.w() * right.w()}; diff --git a/Step 3/include/engine/util/loaders.h b/Step 3/include/engine/util/loaders.h new file mode 100644 index 0000000..b22d1e6 --- /dev/null +++ b/Step 3/include/engine/util/loaders.h @@ -0,0 +1,21 @@ +/* + * Created by Brett Terpstra 6920201 on 20/11/22. + * Copyright (c) 2022 Brett Terpstra. All Rights Reserved. + */ + +#ifndef STEP_3_LOADERS_H +#define STEP_3_LOADERS_H + +#include + +namespace Raytracing { + + class ShaderLoader { + public: + static void define(const std::string& key, const std::string& replacement); + static std::string loadShaderFile(const std::string& path); + }; + +} + +#endif //STEP_3_LOADERS_H diff --git a/Step 3/include/engine/world.h b/Step 3/include/engine/world.h index b0a076f..4cab61e 100644 --- a/Step 3/include/engine/world.h +++ b/Step 3/include/engine/world.h @@ -100,7 +100,7 @@ namespace Raytracing { bool padding[7]{}; Shader& worldShader; - WorldConfig(Shader& shader): worldShader(shader) {} + explicit WorldConfig(Shader& shader): worldShader(shader) {} }; class World { diff --git a/Step 3/include/opencl/cl.h b/Step 3/include/opencl/cl.h new file mode 100644 index 0000000..b2fb7f1 --- /dev/null +++ b/Step 3/include/opencl/cl.h @@ -0,0 +1,37 @@ +/* + * Created by Brett Terpstra 6920201 on 20/11/22. + * Copyright (c) 2022 Brett Terpstra. All Rights Reserved. + */ + +#ifndef STEP_3_CL_H +#define STEP_3_CL_H + +// OpenCL includes +#include + +#include + +namespace Raytracing { + + class OpenCL { + private: + cl_int CL_err; + cl_uint numPlatforms; + int activePlatform; + cl_int platformIDResult; + + cl_platform_id* platformsIDs; + cl_uint numOfPlatformIDs; + + void printDeviceInfo(cl_device_id device); + + public: + explicit OpenCL(int platformID); + static void init(); + + ~OpenCL(); + }; + +} + +#endif //STEP_3_CL_H diff --git a/Step 3/resources/shaders/test.h b/Step 3/resources/shaders/test.h new file mode 100644 index 0000000..fd6aea7 --- /dev/null +++ b/Step 3/resources/shaders/test.h @@ -0,0 +1,7 @@ + + +#define IAMVERYGAY + +int tester(int i){ + return i * i; +} \ No newline at end of file diff --git a/Step 3/resources/shaders/world.vs b/Step 3/resources/shaders/world.vs index 4d5538f..97836d5 100644 --- a/Step 3/resources/shaders/world.vs +++ b/Step 3/resources/shaders/world.vs @@ -1,5 +1,7 @@ #version 330 core +#include + layout (location = 0) in vec3 inPos; layout (location = 1) in vec2 inUv; layout (location = 2) in vec3 inNormal; diff --git a/Step 3/src/engine/main.cpp b/Step 3/src/engine/main.cpp index 85f8b95..fd9700f 100644 --- a/Step 3/src/engine/main.cpp +++ b/Step 3/src/engine/main.cpp @@ -18,6 +18,12 @@ #endif +#ifdef COMPILE_OPENCL + + #include + +#endif + /** * Brett Terpstra 6920201 @@ -90,6 +96,10 @@ int main(int argc, char** args) { // not perfect (contains duplicates) but good enough. parser.printAllInInfo(); + #ifdef COMPILE_OPENCL + OpenCL::init(); + #endif + #ifdef COMPILE_GUI XWindow* window; if (parser.hasOption("--gui") || parser.hasOption("-g")) diff --git a/Step 3/src/engine/math/bvh.cpp b/Step 3/src/engine/math/bvh.cpp index 6969d53..bab0ae7 100644 --- a/Step 3/src/engine/math/bvh.cpp +++ b/Step 3/src/engine/math/bvh.cpp @@ -315,12 +315,12 @@ namespace Raytracing { } /** - * Returns all the objects intersected by the provided ray. The returned objects are in no particular order. - * @param ray to use in AABB intersection - * @param min min t allowed for intersection search - * @param max max t allowed - * @return a unordered array of objects intersected by ray in this BVH. - */ + * Returns all the objects intersected by the provided ray. The returned objects are in no particular order. + * @param ray to use in AABB intersection + * @param min min t allowed for intersection search + * @param max max t allowed + * @return a unordered array of objects intersected by ray in this BVH. + */ std::vector TriangleBVHTree::rayAnyHitIntersect(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) { std::queue nodes{}; std::vector objects; diff --git a/Step 3/src/engine/math/colliders.cpp b/Step 3/src/engine/math/colliders.cpp index ce6d7c1..445a1c0 100644 --- a/Step 3/src/engine/math/colliders.cpp +++ b/Step 3/src/engine/math/colliders.cpp @@ -143,4 +143,27 @@ namespace Raytracing { transform.scale(float(xRadius), float(yRadius), float(zRadius)); return transform; } + int lastAxis = 2; + + std::pair AABB::splitAlongAxis() { + lastAxis %= 3; + lastAxis += 1; + // return the new split AABBs based on the calculated max lengths, but only in their respective axis. + if (lastAxis == 1){ + PRECISION_TYPE X = std::abs(max.x() - min.x()); + PRECISION_TYPE X2 = X/2; + // end the first at half the parent. + return {{min.x(), min.y(), min.z(), max.x()-X2, max.y(), max.z()}, + // start the second AABB at the end of the first AABB. + {min.x()+X2, min.y(), min.z(), max.x(), max.y(), max.z()}}; + } else if (lastAxis == 2) { + PRECISION_TYPE Y = std::abs(max.y() - min.y()); + PRECISION_TYPE Y2 = Y/2; + return {{min.x(), min.y(), min.z(), max.x(), max.y()-Y2, max.z()}, {min.x(), min.y()+Y2, min.z(), max.x(), max.y(), max.z()}}; + } else { + PRECISION_TYPE Z = std::abs(max.z() - min.z()); + PRECISION_TYPE Z2 = Z/2; + return {{min.x(), min.y(), min.z(), max.x(), max.y(), max.z()-Z2}, {min.x(), min.y(), min.z()+Z2, max.x(), max.y(), max.z()}}; + } + } } \ No newline at end of file diff --git a/Step 3/src/engine/util/loaders.cpp b/Step 3/src/engine/util/loaders.cpp new file mode 100644 index 0000000..ae55125 --- /dev/null +++ b/Step 3/src/engine/util/loaders.cpp @@ -0,0 +1,110 @@ +/* + * Created by Brett Terpstra 6920201 on 20/11/22. + * Copyright (c) 2022 Brett Terpstra. All Rights Reserved. + */ +#include +#include +#include + +namespace Raytracing { + + std::unordered_map defines; + + std::vector getLinesFromFile(const std::string& path){ + std::string shaderSource; + std::ifstream shaderFile; + RTAssert(shaderFile.good()); + // ensure ifstream objects can throw exceptions: + shaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); + try { + // open file + shaderFile.open(path); + std::stringstream shaderStream; + // read file's buffer contents into streams + shaderStream << shaderFile.rdbuf(); + // close file handlers + shaderFile.close(); + // convert stream into std::string + shaderSource = shaderStream.str(); + } catch(std::ifstream::failure& e) { + flog << "Unable to read file! " << path << "\n"; + } + + // split the shader into the lines, this way we can get out the #include statements. + return String::split(shaderSource, "\n"); + } + + std::vector includeDescent(const std::string& path){ + std::string pathOnly = path.substr(0, path.find_last_of('/')); + + auto mainLines = getLinesFromFile(path); + std::unordered_map> includes; + + for (int i = 0; i < mainLines.size(); i++){ + auto& line = mainLines[i]; + // if the line is an include statement then we want to add lines recursively. + if (line.starts_with("#include")){ + std::vector statement1 = String::split(line, "<"); + std::vector statement2 = String::split(line, "\""); + String::trim(line); + if ( !(line.ends_with(">") || line.ends_with("\"")) ) { + flog << "Shader file contains an invalid #include statement. (Missing terminator)\n"; + throw std::runtime_error(""); + } + try { + // filter out the > | " at the end of the include statement. + std::string file = statement1.empty() ? statement2[1].substr(0, statement2[1].size()-1) : statement1[1].substr(0, statement1[1].size()-1); + + tlog << "Recusing into " << (pathOnly + "/" + file) << "\n"; + + includes.insert({i, includeDescent((pathOnly + "/" + file))}); + } catch (std::exception& e){ + flog << "Shader file contains an invalid #include statement. (Missing < or \")\n"; + } + } + } + + std::vector returnLines; + + // now combine all the loaded files while respecing the include's position in the file. + for (int i = 0; i < mainLines.size(); i++){ + if (includes.contains(i)){ + auto includedFileLines = includes[i]; + + for (const auto& line : includedFileLines) + returnLines.push_back(line); + } else + returnLines.push_back(mainLines[i]); + } + return returnLines; + } + + std::string ShaderLoader::loadShaderFile(const std::string& path) { + std::stringstream stringStream; + + auto lines = includeDescent(path); + + for (const auto& line : lines){ + // now process the defines, if they exist + if (line.starts_with("#define")){ + auto defineParts = String::split(line, " "); + // create a new define statement in the defines place but with the respective value. + if (defines.contains(defineParts[1])){ + stringStream << "#define "; + stringStream << defineParts[1] << " "; + stringStream << defines[defineParts[1]]; + } + } else { + stringStream << line; + stringStream << "\n"; + } + } + + tlog << stringStream.str(); + + return stringStream.str(); + } + void ShaderLoader::define(const std::string& key, const std::string& replacement) { + defines.insert({key, replacement}); + } +} \ No newline at end of file diff --git a/Step 3/src/engine/world.cpp b/Step 3/src/engine/world.cpp index d370936..ba04630 100644 --- a/Step 3/src/engine/world.cpp +++ b/Step 3/src/engine/world.cpp @@ -182,13 +182,13 @@ namespace Raytracing { HitData ModelObject::checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const { auto hResult = HitData{false, Vec4(), Vec4(), max}; - auto tris = triangleBVH->rayAnyHitIntersect(ray, min, max); + //auto tris = triangleBVH->rayAnyHitIntersect(ray, min, max); // must check through all the triangles in the object // respecting depth along the way // but reducing the max it can reach my the last longest vector length. - for (const auto& t : tris) { - auto cResult = checkIfTriangleGotHit(*t.tri, position, ray, min, hResult.length); + for (const auto& t : triangles) { + auto cResult = checkIfTriangleGotHit(*t, position, ray, min, hResult.length); if (cResult.hit) hResult = cResult; } diff --git a/Step 3/src/graphics/debug_gui.cpp b/Step 3/src/graphics/debug_gui.cpp index c9bc851..67757cb 100644 --- a/Step 3/src/graphics/debug_gui.cpp +++ b/Step 3/src/graphics/debug_gui.cpp @@ -232,6 +232,7 @@ namespace Raytracing { } void DebugBVH::render() { + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if (m_bvhTree != nullptr) { ImGui::Begin(("BVH Data "), nullptr, ImGuiWindowFlags_NoCollapse); m_shader.use(); @@ -257,12 +258,12 @@ namespace Raytracing { ImGui::End(); } if (m_triangleBVHTree) { - ImGui::Begin(("TBVH Data "), nullptr, ImGuiWindowFlags_NoCollapse); + ImGui::Begin((std::string("TBVH Data ") + std::to_string(m_triangleBVHTree->index)).c_str(), nullptr, ImGuiWindowFlags_NoCollapse); m_shader.use(); m_shader.setInt("useWhite", 1); m_shader.setVec3("color", {1.0, 1.0, 1.0}); { - ImGui::BeginChild("left pane", ImVec2(180, 0), true); + ImGui::BeginChild("left pane", ImVec2(280, 0), true); guiNodesRecur(m_triangleBVHTree->getRoot()); ImGui::EndChild(); } @@ -280,6 +281,7 @@ namespace Raytracing { m_shader.setInt("useWhite", 0); ImGui::End(); } + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } DebugBVH::~DebugBVH() { DebugMenus::remove(std::shared_ptr(this)); diff --git a/Step 3/src/graphics/gl/shader.cpp b/Step 3/src/graphics/gl/shader.cpp index b74df28..35105d2 100644 --- a/Step 3/src/graphics/gl/shader.cpp +++ b/Step 3/src/graphics/gl/shader.cpp @@ -6,6 +6,7 @@ #include "graphics/gl/shader.h" #include #include +#include namespace Raytracing { Shader::Shader(const std::string& vertex, const std::string& fragment, bool loadString) { @@ -103,6 +104,7 @@ namespace Raytracing { return -1; } + shaderSource = ShaderLoader::loadShaderFile(file); const char* shaderCode = shaderSource.c_str(); // creates a Shader unsigned int shaderID = glCreateShader(type); diff --git a/Step 3/src/graphics/graphics.cpp b/Step 3/src/graphics/graphics.cpp index d8bdb94..01b422d 100644 --- a/Step 3/src/graphics/graphics.cpp +++ b/Step 3/src/graphics/graphics.cpp @@ -507,7 +507,6 @@ namespace Raytracing { }); if (debug){ - DebugMenus::render(); auto projection = m_camera.project(); if (m_window.isMouseGrabbed()) { yaw += (float) Input::getMouseDelta().x * (1000.0f / ImGui::GetIO().Framerate / 1000.0f) * 3; @@ -582,6 +581,7 @@ namespace Raytracing { obj->getVAO()->draw(m_worldShader, {obj->getPosition()}); } } + DebugMenus::render(); } else { m_imageShader.use(); m_mainImage.updateImage(); diff --git a/Step 3/src/opencl/cl.cpp b/Step 3/src/opencl/cl.cpp new file mode 100644 index 0000000..f58c40a --- /dev/null +++ b/Step 3/src/opencl/cl.cpp @@ -0,0 +1,34 @@ +/* + * Created by Brett Terpstra 6920201 on 20/11/22. + * Copyright (c) 2022 Brett Terpstra. All Rights Reserved. + */ +#include + +namespace Raytracing { + + OpenCL openCl {0}; + + void OpenCL::init() { + openCl = OpenCL{0}; + } + OpenCL::OpenCL(int platformID): activePlatform(platformID) { + CL_err = CL_SUCCESS; + numPlatforms = 0; + CL_err = clGetPlatformIDs( 0, NULL, &numPlatforms ); + + if (CL_err == CL_SUCCESS) + dlog << "We found " << numPlatforms << " OpenCL Platforms.\n"; + else + elog << "OpenCL Error! " << CL_err; + + platformsIDs = new cl_platform_id[numPlatforms]; + platformIDResult = clGetPlatformIDs(numPlatforms, platformsIDs, &numOfPlatformIDs); + + } + OpenCL::~OpenCL() { + delete[](platformsIDs); + } + void OpenCL::printDeviceInfo(cl_device_id device) { + + } +} \ No newline at end of file