diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index dfb1603..55475f0 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -8,7 +8,7 @@ file(GLOB_RECURSE CPP_SOURCES add_library(FGLEngine STATIC ${CPP_SOURCES} ${HPP_SOURCES}) set(CMAKE_CXX_STANDARD 23) -if (DEFINED FGL_ENABLE_PCH) +if (DEFINED FGL_ENABLE_PCH AND FGL_ENABLE_PCH) target_precompile_headers(FGLEngine PRIVATE @@ -54,11 +54,7 @@ else () target_compile_definitions(FGLEngine PUBLIC ENABLE_IMGUI_DRAWERS=0) endif () -if (NOT DEFINED FGL_ENABLE_TESTS) - set(FGL_ENABLE_TESTS 0) -endif () - -if (FGL_ENABLE_TESTS) +if (DEFINED FGL_ENABLE_TESTS AND FGL_ENABLE_TESTS) target_compile_definitions(FGLEngine PUBLIC FGL_TESTS=1) target_link_libraries(FGLEngine PUBLIC Catch2) else () @@ -69,7 +65,12 @@ endif () # with the game itself target_compile_definitions(FGLEngine PUBLIC TRACK_BUFFERS) - #GLM settings # GLM_FORCE_NO_CTOR_INIT target_compile_definitions(FGLEngine PUBLIC GLM_FORCE_RADIANS GLM_FORCE_DEPTH_ZERO_TO_ONE GLM_FORCE_LEFT_HANDED) + +if (DEFINED FGL_ENABLE_CALIBRATED_PROFILING AND FGL_ENABLE_CALIBRATED_PROFILING) + target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=1) +else () + target_compile_definitions(FGLEngine PUBLIC ENABLE_CALIBRATED_PROFILING=0) +endif () diff --git a/src/engine/EngineContext.cpp b/src/engine/EngineContext.cpp index 1bd2d12..35a4508 100644 --- a/src/engine/EngineContext.cpp +++ b/src/engine/EngineContext.cpp @@ -189,7 +189,7 @@ namespace fgl::engine renderFrame(); using namespace std::chrono_literals; - std::this_thread::sleep_for( 13ms ); +// std::this_thread::sleep_for( 13ms ); } Device::getInstance().device().waitIdle(); diff --git a/src/engine/gameobjects/GameObject.hpp b/src/engine/gameobjects/GameObject.hpp index 19c37f0..c8613d5 100644 --- a/src/engine/gameobjects/GameObject.hpp +++ b/src/engine/gameobjects/GameObject.hpp @@ -7,8 +7,8 @@ #include #include -#include "components/GameObjectComponent.hpp" #include "components/ModelComponent.hpp" +#include "engine/gameobjects/components/interface/GameObjectComponent.hpp" #include "engine/primitives/TransformComponent.hpp" namespace fgl::engine diff --git a/src/engine/gameobjects/components/CameraComponent.hpp b/src/engine/gameobjects/components/CameraComponent.hpp index 656ee87..838317a 100644 --- a/src/engine/gameobjects/components/CameraComponent.hpp +++ b/src/engine/gameobjects/components/CameraComponent.hpp @@ -5,20 +5,20 @@ #pragma once #include -#include "GameObjectComponent.hpp" +#include "engine/gameobjects/components/interface/GameObjectComponent.hpp" namespace fgl::engine { class Camera; - class CameraComponent final : public GameObjectComponent< 2 > + COMPONENT_CLASS( CameraComponent, CameraComponentID ) { std::shared_ptr< Camera > m_camera; public: CameraComponent() = delete; - CameraComponent( std::shared_ptr< Camera >& camera ); + CameraComponent( std::shared_ptr< Camera > & camera ); ~CameraComponent(); }; diff --git a/src/engine/gameobjects/components/ComponentIDS.hpp b/src/engine/gameobjects/components/ComponentIDS.hpp new file mode 100644 index 0000000..cc25525 --- /dev/null +++ b/src/engine/gameobjects/components/ComponentIDS.hpp @@ -0,0 +1,21 @@ +// +// Created by kj16609 on 8/8/24. +// + +#pragma once +#define ASSIGN_COMPONENT_ID( name, id ) constexpr ComponentID name { id }; + +#include + +namespace fgl::engine +{ + using ComponentID = std::uint32_t; + + ASSIGN_COMPONENT_ID( ModelComponentID, 1 ); + + ASSIGN_COMPONENT_ID( CameraComponentID, 2 ); + + ASSIGN_COMPONENT_ID( PointLightComponentID, 10 ); + ASSIGN_COMPONENT_ID( DirectionalLightComponentID, 11 ); + +} // namespace fgl::engine diff --git a/src/engine/gameobjects/components/ModelComponent.hpp b/src/engine/gameobjects/components/ModelComponent.hpp index c39e759..bea68be 100644 --- a/src/engine/gameobjects/components/ModelComponent.hpp +++ b/src/engine/gameobjects/components/ModelComponent.hpp @@ -6,19 +6,21 @@ #include #include -#include "GameObjectComponent.hpp" +#include "ComponentIDS.hpp" +#include "engine/gameobjects/components/interface/GameObjectComponent.hpp" namespace fgl::engine { class Model; - class ModelComponent final : public GameObjectComponent< 1 > + COMPONENT_CLASS( ModelComponent, ModelComponentID ) { std::shared_ptr< Model > m_model; public: - ModelComponent( std::shared_ptr< Model >&& model ) : m_model( std::forward< decltype( m_model ) >( model ) ) {} + ModelComponent( std::shared_ptr< Model > && model ) : m_model( std::forward< decltype( m_model ) >( model ) ) + {} #ifdef TITOR_EDITOR void drawImGui() override; @@ -30,11 +32,18 @@ namespace fgl::engine } #endif - virtual ~ModelComponent() override {} + virtual ~ModelComponent() override + {} - Model* operator->() { return m_model.get(); } + Model* operator->() + { + return m_model.get(); + } - const Model* operator->() const { return m_model.get(); } + const Model* operator->() const + { + return m_model.get(); + } }; static_assert( is_component< ModelComponent > ); diff --git a/src/engine/gameobjects/components/PointLightComponent.hpp b/src/engine/gameobjects/components/PointLightComponent.hpp new file mode 100644 index 0000000..0ed0376 --- /dev/null +++ b/src/engine/gameobjects/components/PointLightComponent.hpp @@ -0,0 +1,31 @@ +// +// Created by kj16609 on 8/8/24. +// + +#pragma once + +#include "interface/GameObjectComponent.hpp" + +namespace fgl::engine +{ + + using LightMask = uint32_t; + + COMPONENT_CLASS( PointLightComponent, PointLightComponentID ) + { + glm::vec3 m_color; + float m_brightness; + + //! Objects that fit this mask should be lit by this light + LightMask m_lighting_mask; + + //! Objects that fit this mask should not block this light. + LightMask m_block_mask; + + //! Objects that fit this mask should not be shadowed by this light + LightMask m_shadowed_mask; + + public: + }; + +} // namespace fgl::engine diff --git a/src/engine/gameobjects/components/ComponentEditorInterface.hpp b/src/engine/gameobjects/components/interface/ComponentEditorInterface.hpp similarity index 100% rename from src/engine/gameobjects/components/ComponentEditorInterface.hpp rename to src/engine/gameobjects/components/interface/ComponentEditorInterface.hpp diff --git a/src/engine/gameobjects/components/ComponentEngineInterface.hpp b/src/engine/gameobjects/components/interface/ComponentEngineInterface.hpp similarity index 100% rename from src/engine/gameobjects/components/ComponentEngineInterface.hpp rename to src/engine/gameobjects/components/interface/ComponentEngineInterface.hpp diff --git a/src/engine/gameobjects/components/GameObjectComponent.hpp b/src/engine/gameobjects/components/interface/GameObjectComponent.hpp similarity index 59% rename from src/engine/gameobjects/components/GameObjectComponent.hpp rename to src/engine/gameobjects/components/interface/GameObjectComponent.hpp index 669c3f9..67c83f0 100644 --- a/src/engine/gameobjects/components/GameObjectComponent.hpp +++ b/src/engine/gameobjects/components/interface/GameObjectComponent.hpp @@ -5,17 +5,34 @@ #pragma once #include "ComponentEngineInterface.hpp" +#include "engine/gameobjects/components/ComponentIDS.hpp" #include "engine/primitives/TransformComponent.hpp" +#define COMPONENT_CLASS( class_name, id_name ) class class_name final : public GameObjectComponent< id_name > + namespace fgl::engine { - using ComponentTransform = TransformComponent; + + struct ComponentTransform final : public TransformComponent + { + enum Mode + { + //! Object is non moving, + Static, + //! Object moves in relation to it's parent + Local, + //! Object moves in relation to the world + Global + } m_mode; + }; struct GameObjectComponentBase : public ComponentEditorInterface, public ComponentEngineInterface {}; using GameObjectComponentPtr = GameObjectComponentBase*; + //TODO: Add way to add components to an object in the editor. + template < ComponentEngineInterface::ComponentID T_ID > struct GameObjectComponent : public GameObjectComponentBase { @@ -28,9 +45,7 @@ namespace fgl::engine template < typename T > concept is_component = requires( T t ) { std::is_base_of_v< T, ComponentEngineInterface >; - { - t.ID - } -> std::same_as< const ComponentEngineInterface::ComponentID& >; + { t.ID } -> std::same_as< const ComponentEngineInterface::ComponentID& >; }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/rendering/PhysicalDevice.cpp b/src/engine/rendering/PhysicalDevice.cpp index 15b0b31..5169dea 100644 --- a/src/engine/rendering/PhysicalDevice.cpp +++ b/src/engine/rendering/PhysicalDevice.cpp @@ -77,7 +77,11 @@ namespace fgl::engine } const static std::vector< const char* > required_device_extensions { VK_KHR_SWAPCHAIN_EXTENSION_NAME, - VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME }; + VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, +#if ENABLE_CALIBRATED_PROFILING + VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME +#endif + }; bool PhysicalDevice::supportsRequiredExtensions() { diff --git a/src/engine/rendering/Renderer.cpp b/src/engine/rendering/Renderer.cpp index df77050..55a543b 100644 --- a/src/engine/rendering/Renderer.cpp +++ b/src/engine/rendering/Renderer.cpp @@ -58,7 +58,35 @@ namespace fgl::engine TracyVkCtx createContext( PhysicalDevice& physical_device, Device& device, vk::raii::CommandBuffer& cmd_buffer ) { +#if ENABLE_CALIBRATED_PROFILING + + // The calibrated context wants the calibration extention and two function pointers. + auto getPhysicalDeviceClibrateableTimeDomains { + reinterpret_cast< PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT >( + device->getProcAddr( "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR" ) ) + }; + + auto getCalibratedTimestamps { + reinterpret_cast< PFN_vkGetCalibratedTimestampsEXT >( device + ->getProcAddr( "vkGetCalibratedTimestampsKHR" ) ) + }; + + if ( getPhysicalDeviceClibrateableTimeDomains == nullptr ) + throw std::runtime_error( "Failed to get vkGetPhysicalDeviceCalibratableTimeDomainsEXT" ); + + if ( getCalibratedTimestamps == nullptr ) + throw std::runtime_error( "Failed to get vkGetCalibratedTimestampsEXT" ); + + return TracyVkContextCalibrated( + *physical_device, + *device, + *device.graphicsQueue(), + *cmd_buffer, + getPhysicalDeviceClibrateableTimeDomains, + getCalibratedTimestamps ); +#else return TracyVkContext( *physical_device, *device, *device.graphicsQueue(), *cmd_buffer ); +#endif } void Renderer::createCommandBuffers()