Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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++",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ include_directories(
${FUNGT_BASE_DIR}/Quaternion
${FUNGT_BASE_DIR}/Vector
${FUNGT_BASE_DIR}/Renders
${FUNGT_BASE_DIR}/Loader


)
Expand Down Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions Loader/loader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#if !defined(_LOADER_H_)
#define _LOADER_H_
#include<functional>
#include <tbb/parallel_for_each.h>
#include <tbb/task_group.h>
#include "../SimpleModel/simple_model.hpp"

class ModelLoader{

std::vector<std::function<void()>> tasks;

public:
template<typename ModelType>
void enqueue(std::shared_ptr<ModelType> model,
const ModelPaths & path,
std::function<void(std::shared_ptr<ModelType>)> 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_
229 changes: 229 additions & 0 deletions Samples/tbb_model_loading/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
74 changes: 74 additions & 0 deletions Samples/tbb_model_loading/main.cpp
Original file line number Diff line number Diff line change
@@ -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<<path<<std::endl;
//Path to your shaders and models:
ModelPaths model_ball, model_lamp, model_ground;

//model.path = getAssetPath("Animations/monster_dancing/monster_dancing.dae");
model_ball.path = getAssetPath("Obj/LuxoBall/luxoball.obj");
model_ball.vs_path = getAssetPath("resources/luxoball_vs.glsl");
model_ball.fs_path = getAssetPath("resources/luxoball_fs.glsl");

model_lamp.path = getAssetPath("Obj/LuxoLamp/Luxo.obj");
model_lamp.vs_path = getAssetPath("resources/luxolamp_vs.glsl");
model_lamp.fs_path = getAssetPath("resources/luxolamp_fs.glsl");



//Creates a FunGT Scene to display
FunGTScene myGame = FunGT::createScene(SCREEN_WIDTH,SCREEN_HEIGHT);

//Background color, use 255.f for pure white,
myGame->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<SimpleModel>(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<SimpleModel>(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 *** "<<std::endl;
myGame->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;
}
Loading