From d098866a447f8fdaf1bca7b5ad2583f3bec88ded Mon Sep 17 00:00:00 2001 From: juanchuletas Date: Tue, 14 Oct 2025 18:20:47 -0600 Subject: [PATCH 1/4] vscode --- .vscode/settings.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e80ba92..72aa22a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -64,7 +64,11 @@ "streambuf": "cpp", "thread": "cpp", "typeinfo": "cpp", - "variant": "cpp" + "variant": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "shared_mutex": "cpp", + "format": "cpp" }, "cmake.sourceDirectory": "/home/juanchuletas/Documents/Development/FunGT/main", "editor.formatOnPaste": true From 812127165f0e11fd6525a758fa06aa9c895bb3ef Mon Sep 17 00:00:00 2001 From: juanchuletas Date: Fri, 10 Oct 2025 23:57:50 -0600 Subject: [PATCH 2/4] feat: adding tbb --- CMakeLists.txt | 7 + Loader/loader.hpp | 36 ++++ Samples/tbb_model_loading/CMakeLists.txt | 229 +++++++++++++++++++++++ Samples/tbb_model_loading/main.cpp | 74 ++++++++ 4 files changed, 346 insertions(+) create mode 100644 Loader/loader.hpp create mode 100644 Samples/tbb_model_loading/CMakeLists.txt create mode 100644 Samples/tbb_model_loading/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 05d1c1f..2626ddf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,7 @@ include_directories( ${FUNGT_BASE_DIR}/Quaternion ${FUNGT_BASE_DIR}/Vector ${FUNGT_BASE_DIR}/Renders + ${FUNGT_BASE_DIR}/Loader ) @@ -207,8 +208,14 @@ elseif (UNIX) message(FATAL_ERROR "glm not found!") endif() target_include_directories(FunGT PRIVATE ${OpenCL_INCLUDE_DIRS}) + # --- TBB paths (adjust for your system) --- + set(TBB_INCLUDE_DIR "/opt/intel/oneapi-tbb-2022.0.0/include") + set(TBB_LIBRARY_DIR "/opt/intel/oclcpuexp-2024.18.10.0.08/x64") + target_include_directories(FunGT PRIVATE ${TBB_INCLUDE_DIR}) + target_link_directories(FunGT PRIVATE ${TBB_LIBRARY_DIR}) target_link_libraries(FunGT PRIVATE + tbb OpenGL::GL glfw GLEW::GLEW diff --git a/Loader/loader.hpp b/Loader/loader.hpp new file mode 100644 index 0000000..3f772ed --- /dev/null +++ b/Loader/loader.hpp @@ -0,0 +1,36 @@ +#if !defined(_LOADER_H_) +#define _LOADER_H_ +#include +#include +#include +#include "../SimpleModel/simple_model.hpp" + +class ModelLoader{ + + std::vector> tasks; + +public: + template + void enqueue(std::shared_ptr model, + const ModelPaths & path, + std::function)> callback) { + + // store a type-erased lambda in the tasks vector + tasks.push_back([=]() { + model->load(path); // CPU-heavy load + callback(model); // safe to call directly here + }); + + + } + + void waitForAll() { + tbb::parallel_for_each(tasks.begin(), tasks.end(), [](auto& task) { + task(); + }); + tasks.clear(); + } + +}; + +#endif // _LOADER_H_ diff --git a/Samples/tbb_model_loading/CMakeLists.txt b/Samples/tbb_model_loading/CMakeLists.txt new file mode 100644 index 0000000..35495e3 --- /dev/null +++ b/Samples/tbb_model_loading/CMakeLists.txt @@ -0,0 +1,229 @@ +cmake_minimum_required(VERSION 3.15) +project(FunGT) + +# Allow FUNGT_BASE_DIR to be set externally (command line, environment, or cache) +# Priority: 1. Cache variable, 2. Environment variable, 3. Default fallback +if(NOT DEFINED FUNGT_BASE_DIR) + # Check if it's set as an environment variable + if(DEFINED ENV{FUNGT_BASE_DIR}) + set(FUNGT_BASE_DIR $ENV{FUNGT_BASE_DIR} CACHE PATH "FunGT base directory") + message(STATUS "Using FUNGT_BASE_DIR from environment: ${FUNGT_BASE_DIR}") + else() + # Use a default fallback (you must specify this via -DFUNGT_BASE_DIR or environment) + message(FATAL_ERROR "FUNGT_BASE_DIR not specified. Please set it via:\n" + " cmake -DFUNGT_BASE_DIR=/path/to/FunGT ..\n" + " or export FUNGT_BASE_DIR=/path/to/FunGT") + endif() +else() + message(STATUS "Using pre-defined FUNGT_BASE_DIR: ${FUNGT_BASE_DIR}") +endif() + +# Validate that the base directory exists and contains expected subdirectories +if(NOT EXISTS "${FUNGT_BASE_DIR}") + message(FATAL_ERROR "FUNGT_BASE_DIR does not exist: ${FUNGT_BASE_DIR}") +endif() + +if(NOT EXISTS "${FUNGT_BASE_DIR}/VertexGL" OR NOT EXISTS "${FUNGT_BASE_DIR}/Shaders") + message(FATAL_ERROR "FUNGT_BASE_DIR does not appear to be a valid FunGT directory: ${FUNGT_BASE_DIR}") +endif() +# Set the C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +if(UNIX) + # Set the build type to Release + set(CMAKE_BUILD_TYPE Release) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release/linux) + set(CMAKE_CXX_COMPILER /home/juanchuletas/Documents/Development/sycl_workspace/llvm/build/bin/clang++) + # Add the prebuilt ImGui library + add_library(imgui STATIC IMPORTED) + set_target_properties(imgui PROPERTIES + IMPORTED_LOCATION "${FUNGT_BASE_DIR}/vendor/imgui/lib/libimgui.a" + INTERFACE_INCLUDE_DIRECTORIES "${FUNGT_BASE_DIR}/vendor/imgui" + ) + # Add funlib + set(FUNLIB_DIR ${FUNGT_BASE_DIR}/vendor/funlib) + add_library(funlib STATIC IMPORTED GLOBAL) + set_target_properties(funlib PROPERTIES + IMPORTED_LOCATION ${FUNLIB_DIR}/lib/libfunlib.a + INTERFACE_INCLUDE_DIRECTORIES ${FUNLIB_DIR}/include + ) +endif() +if (WIN32) + # Add the macro definition + add_definitions(-DGLM_ENABLE_EXPERIMENTAL) + # Set vcpkg toolchain file + set(CMAKE_TOOLCHAIN_FILE "C:/Users/juang/Documents/Development/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") + # Set CMake prefix path for vcpkg packages + set(CMAKE_PREFIX_PATH "C:/Users/juang/Documents/Development/vcpkg/installed/x64-windows") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGL_VENDOR_NVIDIA") + set(GLFW_BUILD_STATIC ON) + #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + message(STATUS "Working Dir: " ${CMAKE_CURRENT_SOURCE_DIR}) +endif() +# Include directories +include_directories( + ${FUNGT_BASE_DIR}/VertexGL + ${FUNGT_BASE_DIR}/Shaders + ${FUNGT_BASE_DIR}/funGT + ${FUNGT_BASE_DIR}/AnimatedModel + ${FUNGT_BASE_DIR}/Textures + ${FUNGT_BASE_DIR}/vendor/stb_image + ${FUNGT_BASE_DIR}/Imgui_Setup + ${FUNGT_BASE_DIR}/Material + ${FUNGT_BASE_DIR}/Mesh + ${FUNGT_BASE_DIR}/Camera + ${FUNGT_BASE_DIR}/Geometries + ${FUNGT_BASE_DIR}/Model + ${FUNGT_BASE_DIR}/Helpers + ${FUNGT_BASE_DIR}/Animation + ${FUNGT_BASE_DIR}/Bone + ${FUNGT_BASE_DIR}/Matrix + ${FUNGT_BASE_DIR}/SceneManager + ${FUNGT_BASE_DIR}/CubeMap + ${FUNGT_BASE_DIR}/ParticleSimulation + ${FUNGT_BASE_DIR}/Random + ${FUNGT_BASE_DIR}/Path_Manager + ${FUNGT_BASE_DIR}/InfoWindow + ${FUNGT_BASE_DIR}/GUI + ${FUNGT_BASE_DIR}/SimpleModel + ${FUNGT_BASE_DIR}/Physics/CollisionManager + ${FUNGT_BASE_DIR}/Physics/Contact + ${FUNGT_BASE_DIR}/Physics/RigidBody + ${FUNGT_BASE_DIR}/Physics/Shapes + ${FUNGT_BASE_DIR}/Physics/Integrators + ${FUNGT_BASE_DIR}/Physics/ContactHelpers + ${FUNGT_BASE_DIR}/Physics/PhysicsWorld + ${FUNGT_BASE_DIR}/Physics/Clothing + ${FUNGT_BASE_DIR}/Quaternion + ${FUNGT_BASE_DIR}/Vector + ${FUNGT_BASE_DIR}/Loader + + +) +# Source files +set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp + ${FUNGT_BASE_DIR}/VertexGL/vertexArrayObjects.cpp + ${FUNGT_BASE_DIR}/VertexGL/vertexBuffers.cpp + ${FUNGT_BASE_DIR}/VertexGL/vertexIndices.cpp + ${FUNGT_BASE_DIR}/Shaders/shader.cpp + ${FUNGT_BASE_DIR}/funGT/fungt.cpp + ${FUNGT_BASE_DIR}/AnimatedModel/animated_model.cpp + ${FUNGT_BASE_DIR}/Textures/textures.cpp + ${FUNGT_BASE_DIR}/vendor/stb_image/stb_image.cpp + ${FUNGT_BASE_DIR}/Imgui_Setup/imgui_setup.cpp + ${FUNGT_BASE_DIR}/Material/material.cpp + ${FUNGT_BASE_DIR}/Mesh/mesh.cpp + ${FUNGT_BASE_DIR}/Camera/camera.cpp + ${FUNGT_BASE_DIR}/Geometries/cube.cpp + ${FUNGT_BASE_DIR}/Geometries/plane.cpp + ${FUNGT_BASE_DIR}/Geometries/primitives.cpp + ${FUNGT_BASE_DIR}/Geometries/pyramid.cpp + ${FUNGT_BASE_DIR}/Geometries/shape.cpp + ${FUNGT_BASE_DIR}/Geometries/square.cpp + ${FUNGT_BASE_DIR}/Model/model.cpp + ${FUNGT_BASE_DIR}/Helpers/helpers.cpp + ${FUNGT_BASE_DIR}/Animation/animation.cpp + ${FUNGT_BASE_DIR}/Bone/bone.cpp + ${FUNGT_BASE_DIR}/Matrix/matrix4x4f.cpp + ${FUNGT_BASE_DIR}/Matrix/matrix3x3f.cpp + ${FUNGT_BASE_DIR}/SceneManager/scene_manager.cpp + ${FUNGT_BASE_DIR}/CubeMap/cube_map.cpp + #${FUNGT_BASE_DIR}/Physics/ParticleSystem/particle_sys.cpp + #${FUNGT_BASE_DIR}/Physics/ParticleSystem/particle.cpp + ${FUNGT_BASE_DIR}/ParticleSimulation/particle_simulation.cpp + ${FUNGT_BASE_DIR}/Random/random.cpp + ${FUNGT_BASE_DIR}/Path_Manager/path_manager.cpp + ${FUNGT_BASE_DIR}/InfoWindow/infowindow.cpp + ${FUNGT_BASE_DIR}/GUI/gui.cpp + ${FUNGT_BASE_DIR}/SimpleModel/simple_model.cpp + ${FUNGT_BASE_DIR}/Physics/Collisions/simple_collision.cpp + ${FUNGT_BASE_DIR}/Physics/Collider/collider.cpp + ${FUNGT_BASE_DIR}/Physics/Clothing/clothing.cpp +) + +# Add executable +add_executable(FunGT ${SOURCE_FILES}) + +# Platform-specific configurations +if (WIN32) + # Use vcpkg packages on Windows + find_package(OpenGL REQUIRED) + find_package(GLEW REQUIRED) + find_package(glfw3 REQUIRED) + find_package(assimp REQUIRED) + find_package(glm REQUIRED) + target_link_libraries(FunGT + PRIVATE + OpenGL::GL + glfw + GLEW::GLEW + assimp::assimp + glm::glm + ) +elseif (UNIX) + # Linux-specific settings + message(STATUS "Configuring for Linux") + message(STATUS "CMakeLists.txt location: ${FUNGT_BASE_DIR}") + find_package(OpenCL REQUIRED) + if (OpenCL_FOUND) + message(STATUS "OpenCL found") + message(STATUS "OpenCL include dirs: ${OpenCL_INCLUDE_DIRS}") + else() + message(FATAL_ERROR "OpenCL library not found!") + endif() + find_package(OpenGL REQUIRED) + if (OpenGL_FOUND) + message(STATUS "OpenGL found") + else() + message(FATAL_ERROR "OpenGL library not found!") + endif() + + find_package(glfw3 REQUIRED) + if (glfw3_FOUND) + message(STATUS "GLFW found") + else() + message(FATAL_ERROR "GLFW library not found!") + endif() + + find_package(GLEW REQUIRED) + if (GLEW_FOUND) + message(STATUS "GLEW found") + else() + message(FATAL_ERROR "GLEW library not found!") + endif() + + find_package(assimp REQUIRED) + if (assimp_FOUND) + message(STATUS "Assimp found") + else() + message(FATAL_ERROR "Assimp library not found!") + endif() + find_package(glm CONFIG REQUIRED) + if(glm_FOUND) + message(STATUS "glm found") + else() + message(FATAL_ERROR "glm not found!") + endif() + target_include_directories(FunGT PRIVATE ${OpenCL_INCLUDE_DIRS}) + # --- TBB paths (adjust for your system) --- + set(TBB_INCLUDE_DIR "/opt/intel/oneapi-tbb-2022.0.0/include") + set(TBB_LIBRARY_DIR "/opt/intel/oclcpuexp-2024.18.10.0.08/x64") + target_include_directories(FunGT PRIVATE ${TBB_INCLUDE_DIR}) + target_link_directories(FunGT PRIVATE ${TBB_LIBRARY_DIR}) + target_link_libraries(FunGT + PRIVATE + tbb + OpenGL::GL + glfw + GLEW::GLEW + assimp::assimp + glm::glm + dl + funlib + imgui + ${OpenCL_LIBRARIES} + ) + target_compile_options(FunGT PRIVATE -fsycl) + target_link_options(FunGT PRIVATE -fsycl) +endif() diff --git a/Samples/tbb_model_loading/main.cpp b/Samples/tbb_model_loading/main.cpp new file mode 100644 index 0000000..93cb78c --- /dev/null +++ b/Samples/tbb_model_loading/main.cpp @@ -0,0 +1,74 @@ +#include "../funGT/fungt.hpp" +#include "../../Physics/PhysicsWorld/physics_world.hpp" +const unsigned int SCREEN_WIDTH = 2100; +const unsigned int SCREEN_HEIGHT = 1200; + +int main(){ + std::string path = findProjectRoot(); + std::cout<setBackgroundColor(); + + //Initializes the Graphics Stuff + myGame->initGL(); + + FunGTSceneManager scene_manager = myGame->getSceneManager(); + + //Shows infowindow: + + FunGTInfoWindow infowindow = myGame->getInfoWindow(); + + // Creates an animation object + + FunGTSModel pixarBall = SimpleModel::create(); //returns shared_ptr + ModelLoader model_loader; + model_loader.enqueue(pixarBall, model_ball, [](FunGTSModel m) { + m->position(10.f, 1.f, -10.f); + m->rotation(-30.f, 0.f, 0.f); + }); + + + //Loads Pixar Lamp data + FunGTSModel lamp = SimpleModel::create(); + model_loader.enqueue(lamp, model_ball, [](FunGTSModel m) { + m->position(-10.f, -0.5f, -20.f); + m->rotation(0.f, 90, 0.f); + m->scale(1.f); + }); + model_loader.waitForAll(); + std::cout<<" *** All models loaded *** "<set([&](){ // Sets up all the scenes in your game + + // Adds the renderable objects to the SceneManager + scene_manager->addRenderableObj(pixarBall); + scene_manager->addRenderableObj(lamp); + + }); + float lastTime = glfwGetTime(); + myGame->render([&](){ // Renders the entire scene using data from the SceneManager + + scene_manager->renderScene(); + infowindow->renderGUI(); + }); + + //End of the game + + return 0; +} \ No newline at end of file From 5b226fd77adcb50027a4b5c390bbca99d33e36c8 Mon Sep 17 00:00:00 2001 From: juanchuletas Date: Sat, 11 Oct 2025 00:25:12 -0600 Subject: [PATCH 3/4] tbb includes --- .vscode/c_cpp_properties.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index d67b17c..cd3475d 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,7 +6,8 @@ "${workspaceFolder}", "${workspaceFolder}/**", "/home/juanchuletas/Documents/Development/sycl_workspace/llvm/build/include", - "/home/juanchuletas/Documents/Development/FunGT/vendor/funlib/include" + "/home/juanchuletas/Documents/Development/FunGT/vendor/funlib/include", + "/opt/intel/oneapi-tbb-2022.0.0/include" ], "defines": [], "compilerPath": "/home/juanchuletas/Documents/Development/sycl_workspace/llvm/build/bin/clang++", From 8ea62ade78c64497940f9a508f2ea6e77c106bb3 Mon Sep 17 00:00:00 2001 From: juanchuletas Date: Sun, 12 Oct 2025 21:18:12 -0600 Subject: [PATCH 4/4] Loader --- SimpleModel/simple_model.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SimpleModel/simple_model.hpp b/SimpleModel/simple_model.hpp index 1089647..eb4d81e 100644 --- a/SimpleModel/simple_model.hpp +++ b/SimpleModel/simple_model.hpp @@ -5,6 +5,7 @@ #include "../DataPaths/datapaths.hpp" #include "../Physics/RigidBody/rigid_body.hpp" #include "../Physics/CollisionManager/collision_manager.hpp" +#include "../Loader/loader.hpp" #include class SimpleModel : public Renderable { @@ -52,5 +53,4 @@ class SimpleModel : public Renderable { - #endif // _SIMPLE_MODEL_HPP_