diff --git a/src/engine/Camera.cpp b/src/engine/Camera.cpp index 2cfbd65..da55ce0 100644 --- a/src/engine/Camera.cpp +++ b/src/engine/Camera.cpp @@ -93,8 +93,8 @@ namespace fgl::engine const ModelCoordinate far_forward { constants::WORLD_FORWARD * far }; const ModelCoordinate right_half { constants::WORLD_RIGHT * half_width }; - const Vector right_forward { far_forward + right_half }; - const Vector left_forward { far_forward - right_half }; + const Vector right_forward { ( far_forward + right_half ).vec() }; + const Vector left_forward { ( far_forward - right_half ).vec() }; const Plane< CoordinateSpace::Model > right_plane { ModelCoordinate( constants::WORLD_CENTER ), @@ -107,8 +107,8 @@ namespace fgl::engine const ModelCoordinate top_half { constants::WORLD_UP * half_height }; - const Vector top_forward { far_forward + top_half }; - const Vector bottom_forward { far_forward - top_half }; + const Vector top_forward { ( far_forward + top_half ).vec() }; + const Vector bottom_forward { ( far_forward - top_half ).vec() }; const Plane< CoordinateSpace::Model > top_plane { ModelCoordinate( constants::WORLD_CENTER ), @@ -131,26 +131,16 @@ namespace fgl::engine Matrix< MatrixType::ModelToWorld > Camera::frustumTranslationMatrix() const { - if ( update_using_alt ) - return frustum_alt_transform.mat(); - else [[likely]] - { - TransformComponent comp {}; - comp.translation = getPosition(); - comp.rotation = current_rotation; + TransformComponent comp {}; + comp.translation = getPosition(); + comp.rotation = current_rotation; - return comp.mat(); - } + return comp.mat(); } WorldCoordinate Camera::getFrustumPosition() const { - if ( update_using_alt ) [[unlikely]] - return frustum_alt_transform.translation; - else if ( update_frustums ) [[likely]] - return getPosition(); - else - return last_frustum_pos; + return last_frustum_pos; } } // namespace fgl::engine diff --git a/src/engine/Camera.hpp b/src/engine/Camera.hpp index 32e1f49..26a5b09 100644 --- a/src/engine/Camera.hpp +++ b/src/engine/Camera.hpp @@ -22,8 +22,7 @@ namespace fgl::engine { class Camera; - Frustum< CoordinateSpace::Model > - createFrustum( const float aspect, const float fovy, const float near, const float far ); + Frustum< CoordinateSpace::Model > createFrustum( float aspect, float fovy, float near, float far ); class Camera { @@ -52,60 +51,53 @@ namespace fgl::engine public: - inline Rotation getRotation() const { return current_rotation; } - - inline static TransformComponent frustum_alt_transform { WorldCoordinate( constants::WORLD_CENTER ), - glm::vec3( 1.0f ), - Rotation() }; - - inline static bool update_frustums { true }; - inline static bool update_using_alt { false }; - Camera() { this->setPerspectiveProjection( 90.0f, 16.0f / 9.0f, constants::NEAR_PLANE, constants::FAR_PLANE ); this->setView( WorldCoordinate( constants::CENTER ), Rotation( 0.0f, 0.0f, 0.0f ) ); } + Rotation getRotation() const { return current_rotation; } + WorldCoordinate getFrustumPosition() const; - inline const Frustum< CoordinateSpace::Model >& getBaseFrustum() const { return base_frustum; } + const Frustum< CoordinateSpace::Model >& getBaseFrustum() const { return base_frustum; } //! Returns the frustum of the camera in world space - inline const Frustum< CoordinateSpace::World >& getFrustumBounds() const { return frustum; } + const Frustum< CoordinateSpace::World >& getFrustumBounds() const { return frustum; } - inline const Matrix< MatrixType::CameraToScreen >& getProjectionMatrix() const { return projection_matrix; } + const Matrix< MatrixType::CameraToScreen >& getProjectionMatrix() const { return projection_matrix; } - inline const Matrix< MatrixType::WorldToCamera >& getViewMatrix() const { return view_matrix; } + const Matrix< MatrixType::WorldToCamera >& getViewMatrix() const { return view_matrix; } - inline Matrix< MatrixType::WorldToScreen > getProjectionViewMatrix() const + Matrix< MatrixType::WorldToScreen > getProjectionViewMatrix() const { assert( projection_matrix != constants::MAT4_IDENTITY ); return projection_matrix * view_matrix; } - inline glm::mat4 getInverseViewMatrix() const { return glm::inverse( view_matrix ); } + glm::mat4 getInverseViewMatrix() const { return glm::inverse( view_matrix ); } void setOrthographicProjection( float left, float right, float top, float bottom, float near, float far ); void setPerspectiveProjection( float fovy, float aspect, float near, float far ); - inline Coordinate< CoordinateSpace::World > getPosition() const + Coordinate< CoordinateSpace::World > getPosition() const { //Should maybe store the inverse view matrix return WorldCoordinate( inverse_view_matrix[ 3 ] ); } - inline Vector getUp() const { return -getDown(); } + Vector getUp() const { return -getDown(); } - inline Vector getRight() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 0 ] ) ) ); } + Vector getRight() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 0 ] ) ) ); } - inline Vector getForward() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 2 ] ) ) ); } + Vector getForward() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 2 ] ) ) ); } - inline Vector getLeft() const { return -getRight(); } + Vector getLeft() const { return -getRight(); } - inline Vector getBackward() const { return -getForward(); } + Vector getBackward() const { return -getForward(); } - inline Vector getDown() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 1 ] ) ) ); } + Vector getDown() const { return Vector( glm::normalize( glm::vec3( inverse_view_matrix[ 1 ] ) ) ); } enum ViewMode { diff --git a/src/engine/GameObject.cpp b/src/engine/GameObject.cpp index 3c71522..3e850f3 100644 --- a/src/engine/GameObject.cpp +++ b/src/engine/GameObject.cpp @@ -32,7 +32,9 @@ namespace fgl::engine gui::dragFloat3( "Scale", scale ); for ( const GameObjectComponentBase* component : components ) - {} + { + //TODO: Draw components + } } OrientedBoundingBox< CoordinateSpace::World > GameObject::getBoundingBox() const diff --git a/src/engine/Window.hpp b/src/engine/Window.hpp index befca81..3ea241d 100644 --- a/src/engine/Window.hpp +++ b/src/engine/Window.hpp @@ -10,10 +10,14 @@ #include #include -#include "rendering/Surface.hpp" +namespace vk::raii +{ + class SurfaceKHR; +} namespace fgl::engine { + class Instance; class Window { diff --git a/src/engine/allocators/globalAllocator.cpp b/src/engine/allocators/globalAllocator.cpp index 9de3703..5ed1c85 100644 --- a/src/engine/allocators/globalAllocator.cpp +++ b/src/engine/allocators/globalAllocator.cpp @@ -6,6 +6,9 @@ #include #include + +// In order to monitor memory we need to overload the new and delete operators + #if TRACY_ENABLE void* operator new( std::size_t count ) diff --git a/src/engine/assets/AssetManager.hpp b/src/engine/assets/AssetManager.hpp index f847257..1d6140b 100644 --- a/src/engine/assets/AssetManager.hpp +++ b/src/engine/assets/AssetManager.hpp @@ -54,7 +54,7 @@ namespace fgl::engine using KeyT = typename T::UIDKeyT; std::unordered_map< KeyT, std::weak_ptr< T > > active_map {}; - std::mutex map_mtx; + std::mutex map_mtx {}; public: diff --git a/src/engine/assets/TransferManager.cpp b/src/engine/assets/TransferManager.cpp index 4bb1561..0e55884 100644 --- a/src/engine/assets/TransferManager.cpp +++ b/src/engine/assets/TransferManager.cpp @@ -4,6 +4,7 @@ #include "TransferManager.hpp" +#include "engine/buffers/Buffer.hpp" #include "engine/buffers/BufferSuballocation.hpp" #include "engine/buffers/vector/HostVector.hpp" #include "engine/image/Image.hpp" @@ -70,6 +71,14 @@ namespace fgl::engine::memory {} ); } + void TransferManager::resizeBuffer( const std::uint64_t size ) + { + staging_buffer = std::make_unique< Buffer >( + size, + vk::BufferUsageFlagBits::eTransferSrc, + vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ); + } + void TransferManager::submitBuffer( vk::raii::CommandBuffer& command_buffer ) { ZoneScoped; @@ -272,6 +281,7 @@ namespace fgl::engine::memory graphics_queue_index( device.phyDevice().queueInfo().getIndex( vk::QueueFlagBits::eGraphics ) ), transfer_queue( device->getQueue( transfer_queue_index, 0 ) ), transfer_semaphore( device->createSemaphore( {} ) ), + cmd_buffer_allocinfo( Device::getInstance().getCommandPool(), vk::CommandBufferLevel::ePrimary, 1 ), transfer_buffers( Device::getInstance().device().allocateCommandBuffers( cmd_buffer_allocinfo ) ), completion_fence( device->createFence( {} ) ) { @@ -304,5 +314,4 @@ namespace fgl::engine::memory processing.clear(); } - -} // namespace fgl::engine +} // namespace fgl::engine::memory diff --git a/src/engine/assets/TransferManager.hpp b/src/engine/assets/TransferManager.hpp index 463e2ce..9410705 100644 --- a/src/engine/assets/TransferManager.hpp +++ b/src/engine/assets/TransferManager.hpp @@ -7,21 +7,27 @@ #include #include -#include #include "TransferData.hpp" #include "engine/FGL_DEFINES.hpp" -#include "engine/buffers/Buffer.hpp" #include "engine/buffers/vector/concepts.hpp" -#include "engine/image/ImageHandle.hpp" + +namespace fgl::engine +{ + class Device; + + namespace memory + { + class BufferVector; + + struct BufferSuballocationHandle; + + class BufferSuballocation; + } // namespace memory +} // namespace fgl::engine namespace fgl::engine::memory { - class BufferVector; - - struct BufferSuballocationHandle; - - class BufferSuballocation; //! Manages transfers from HOST (CPU) to DEVICE (GPU) class TransferManager @@ -48,9 +54,7 @@ namespace fgl::engine::memory //! Signaled once a transfer completes vk::raii::Semaphore transfer_semaphore; - vk::CommandBufferAllocateInfo cmd_buffer_allocinfo { Device::getInstance().getCommandPool(), - vk::CommandBufferLevel::ePrimary, - 1 }; + vk::CommandBufferAllocateInfo cmd_buffer_allocinfo; std::vector< vk::raii::CommandBuffer > transfer_buffers; @@ -74,6 +78,10 @@ namespace fgl::engine::memory public: + TransferManager( Device& device, std::uint64_t buffer_size ); + + FGL_DELETE_ALL_Ro5( TransferManager ); + vk::raii::Semaphore& getFinishedSem() { return transfer_semaphore; } //! Takes ownership of memory regions from the graphics queue via memory barriers. @@ -88,18 +96,8 @@ namespace fgl::engine::memory static void createInstance( Device& device, std::uint64_t buffer_size ); static TransferManager& getInstance(); - TransferManager( Device& device, std::uint64_t buffer_size ); - - FGL_DELETE_ALL_Ro5( TransferManager ); - //! Resizes the staging buffer. - void resizeBuffer( const std::uint64_t size ) - { - staging_buffer = std::make_unique< Buffer >( - size, - vk::BufferUsageFlagBits::eTransferSrc, - vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent ); - } + void resizeBuffer( std::uint64_t size ); //! Queues a buffer to be transfered template < typename DeviceVectorT > diff --git a/src/engine/buffers/Buffer.cpp b/src/engine/buffers/Buffer.cpp index d232369..7cba00c 100644 --- a/src/engine/buffers/Buffer.cpp +++ b/src/engine/buffers/Buffer.cpp @@ -214,12 +214,14 @@ namespace fgl::engine::memory if ( aligned_offset != offset ) { //Insert the space left over before the block starts back into the free blocks - m_free_blocks.emplace_back( std::make_pair( offset, aligned_offset - offset ) ); + const std::size_t leftover_start_size { aligned_offset - offset }; + + m_free_blocks.emplace_back( std::make_pair( offset, leftover_start_size ) ); mergeFreeBlocks(); offset = aligned_offset; - size -= aligned_offset - offset; + size -= leftover_start_size; } //Add the suballocation @@ -263,11 +265,14 @@ namespace fgl::engine::memory auto itter { m_free_blocks.begin() }; auto next_block { std::next( itter ) }; + // Search through all free blocks while ( next_block != m_free_blocks.end() && itter != m_free_blocks.end() ) { //Is the next block adjacent to the current block? auto& [ offset, size ] = *itter; const auto& [ next_offset, next_size ] = *next_block; + + // Is the next block ajacent to us? const bool is_adjacent { offset + size == next_offset }; if ( is_adjacent ) @@ -289,8 +294,6 @@ namespace fgl::engine::memory continue; } } - - return; } void Buffer::setDebugName( const std::string str ) @@ -357,4 +360,4 @@ namespace fgl::engine::memory assert( m_suballocations.size() == 0 && "Buffer destructed while allocations still present" ); } -} // namespace fgl::engine +} // namespace fgl::engine::memory diff --git a/src/engine/buffers/Buffer.hpp b/src/engine/buffers/Buffer.hpp index d7fb182..ecbb6dd 100644 --- a/src/engine/buffers/Buffer.hpp +++ b/src/engine/buffers/Buffer.hpp @@ -166,6 +166,7 @@ namespace fgl::engine::memory std::shared_ptr< BufferSuballocationHandle > suballocate( vk::DeviceSize memory_size, std::uint32_t alignment = 1 ); + //! Frees a given suballocation. After calling this the handle is invalid and accessing it is UB void free( BufferSuballocationHandle& info ); void mergeFreeBlocks(); diff --git a/src/engine/buffers/BufferSuballocation.cpp b/src/engine/buffers/BufferSuballocation.cpp index 99ff579..1e85685 100644 --- a/src/engine/buffers/BufferSuballocation.cpp +++ b/src/engine/buffers/BufferSuballocation.cpp @@ -13,7 +13,7 @@ namespace fgl::engine::memory { - BufferSuballocation& BufferSuballocation::operator=( BufferSuballocation&& other ) + BufferSuballocation& BufferSuballocation::operator=( BufferSuballocation&& other ) noexcept { m_handle = std::move( other.m_handle ); @@ -34,7 +34,7 @@ namespace fgl::engine::memory m_byte_size( m_handle->m_size ) {} - BufferSuballocation::BufferSuballocation( BufferSuballocation&& other ) : + BufferSuballocation::BufferSuballocation( BufferSuballocation&& other ) noexcept : m_handle( std::move( other.m_handle ) ), m_offset( m_handle->m_offset ), m_byte_size( m_handle->m_size ) diff --git a/src/engine/buffers/BufferSuballocation.hpp b/src/engine/buffers/BufferSuballocation.hpp index 1f37af5..96cb187 100644 --- a/src/engine/buffers/BufferSuballocation.hpp +++ b/src/engine/buffers/BufferSuballocation.hpp @@ -5,7 +5,6 @@ #pragma once #include "BufferSuballocationHandle.hpp" -#include "engine/concepts/is_suballocation.hpp" #include "engine/rendering/Device.hpp" namespace fgl::engine::memory @@ -41,15 +40,21 @@ namespace fgl::engine::memory BufferSuballocation( const BufferSuballocation& ) = delete; BufferSuballocation& operator=( const BufferSuballocation& ) = delete; - BufferSuballocation( BufferSuballocation&& other ); - BufferSuballocation& operator=( BufferSuballocation&& other ); + BufferSuballocation( BufferSuballocation&& other ) noexcept; + BufferSuballocation& operator=( BufferSuballocation&& other ) noexcept; SuballocationView view( const vk::DeviceSize offset, const vk::DeviceSize size ) const; + //! Returns true when the buffer has been staged by the StagingManager bool ready() const { return m_handle->ready(); } + //! Returns a mapped pointer. + /** + * @note If the buffer this suballocation is from is unable to be mapped then this function will return nullptr + */ void* ptr() const; + //! Returns the total byte size of the allocation vk::DeviceSize bytesize() const noexcept { return m_byte_size; } Buffer& getBuffer() const; @@ -65,14 +70,4 @@ namespace fgl::engine::memory ~BufferSuballocation() = default; }; - - - template < typename T > - concept is_typed_suballocation = requires( T t ) { - { - t.operator->() - } -> std::same_as< typename T::value_type* >; - requires is_buffer< typename T::BufferT >; - }; - -} // namespace fgl::engine \ No newline at end of file +} // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/buffers/BufferSuballocationHandle.hpp b/src/engine/buffers/BufferSuballocationHandle.hpp index 6da192d..3b27f74 100644 --- a/src/engine/buffers/BufferSuballocationHandle.hpp +++ b/src/engine/buffers/BufferSuballocationHandle.hpp @@ -30,28 +30,28 @@ namespace fgl::engine::memory bool m_staged { false }; BufferSuballocationHandle() = delete; - BufferSuballocationHandle( const BufferSuballocationHandle& ) = delete; - BufferSuballocationHandle& operator=( const BufferSuballocationHandle& ) = delete; - - vk::Buffer getBuffer(); - - BufferSuballocationHandle( BufferSuballocationHandle&& ) = delete; - BufferSuballocationHandle& operator=( BufferSuballocationHandle&& ) = delete; BufferSuballocationHandle( Buffer& buffer, vk::DeviceSize memory_size, vk::DeviceSize offset ); ~BufferSuballocationHandle(); + BufferSuballocationHandle( const BufferSuballocationHandle& ) = delete; + BufferSuballocationHandle& operator=( const BufferSuballocationHandle& ) = delete; + + BufferSuballocationHandle( BufferSuballocationHandle&& ) = delete; + BufferSuballocationHandle& operator=( BufferSuballocationHandle&& ) = delete; + + vk::Buffer getBuffer(); + vk::Buffer getVkBuffer() const; + vk::BufferCopy copyRegion( BufferSuballocationHandle& target ); - void copyTo( vk::raii::CommandBuffer& cmd_buffer, BufferSuballocationHandle& other ); + vk::DeviceSize getOffset() const { return m_offset; } - vk::Buffer getVkBuffer() const; + void copyTo( vk::raii::CommandBuffer& cmd_buffer, BufferSuballocationHandle& other ); bool ready() const { return m_staged; } void setReady( const bool value ) { m_staged = value; } - - vk::DeviceSize getOffset() const { return m_offset; } }; } // namespace fgl::engine::memory diff --git a/src/engine/buffers/SuballocationView.cpp b/src/engine/buffers/SuballocationView.cpp index 86b1b18..1ebd65b 100644 --- a/src/engine/buffers/SuballocationView.cpp +++ b/src/engine/buffers/SuballocationView.cpp @@ -25,4 +25,4 @@ namespace fgl::engine::memory m_offset = offset; } -} // namespace fgl::engine +} // namespace fgl::engine::memory diff --git a/src/engine/buffers/SuballocationView.hpp b/src/engine/buffers/SuballocationView.hpp index 7dc3948..6d63118 100644 --- a/src/engine/buffers/SuballocationView.hpp +++ b/src/engine/buffers/SuballocationView.hpp @@ -21,8 +21,6 @@ namespace fgl::engine::memory public: - void setOffset( vk::DeviceSize offset ); - SuballocationView( std::shared_ptr< BufferSuballocationHandle > handle, vk::DeviceSize offset, vk::DeviceSize size ) : m_suballocation( handle ), @@ -30,6 +28,8 @@ namespace fgl::engine::memory m_size( size ) {} + void setOffset( vk::DeviceSize offset ); + //! Returns the buffer vk::Buffer getVkBuffer(); @@ -37,4 +37,4 @@ namespace fgl::engine::memory vk::DeviceSize getOffset(); }; -} // namespace fgl::engine \ No newline at end of file +} // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/buffers/UniqueFrameSuballocation.hpp b/src/engine/buffers/UniqueFrameSuballocation.hpp index 03236f0..26b11c3 100644 --- a/src/engine/buffers/UniqueFrameSuballocation.hpp +++ b/src/engine/buffers/UniqueFrameSuballocation.hpp @@ -4,6 +4,8 @@ #pragma once +#include "engine/concepts/is_suballocation.hpp" + namespace fgl::engine { diff --git a/src/engine/buffers/vector/BufferVector.cpp b/src/engine/buffers/vector/BufferVector.cpp index 5594462..fc5c846 100644 --- a/src/engine/buffers/vector/BufferVector.cpp +++ b/src/engine/buffers/vector/BufferVector.cpp @@ -5,10 +5,17 @@ #include "BufferVector.hpp" #include "engine/assets/TransferManager.hpp" +#include "engine/buffers/Buffer.hpp" namespace fgl::engine::memory { + [[nodiscard]] BufferVector::BufferVector( Buffer& buffer, std::uint32_t count, std::uint32_t stride ) : + BufferSuballocation( buffer.suballocate( count * stride ) ), + m_count( count ), + m_stride( stride ) + {} + //! Returns the offset count from the start of the buffer to the first element [[nodiscard]] std::uint32_t BufferVector::getOffsetCount() const { @@ -51,4 +58,4 @@ namespace fgl::engine::memory *this = std::move( other ); } -} // namespace fgl::engine \ No newline at end of file +} // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/buffers/vector/BufferVector.hpp b/src/engine/buffers/vector/BufferVector.hpp index 42abea7..0ac5cc3 100644 --- a/src/engine/buffers/vector/BufferVector.hpp +++ b/src/engine/buffers/vector/BufferVector.hpp @@ -28,11 +28,7 @@ namespace fgl::engine::memory BufferVector() = delete; - BufferVector( Buffer& buffer, std::uint32_t count, std::uint32_t stride ) : - BufferSuballocation( buffer.suballocate( count * stride ) ), - m_count( count ), - m_stride( stride ) - {} + BufferVector( Buffer& buffer, std::uint32_t count, std::uint32_t stride ); BufferVector( const BufferVector& ) = delete; diff --git a/src/engine/buffers/vector/HostVector.hpp b/src/engine/buffers/vector/HostVector.hpp index 509447c..a1c0135 100644 --- a/src/engine/buffers/vector/HostVector.hpp +++ b/src/engine/buffers/vector/HostVector.hpp @@ -13,9 +13,8 @@ namespace fgl::engine class DeviceVector; /** - * A vector device with the ability to flush to the device. + * A vector allocated with HOST memory. * @tparam T - * @tparam Buffer */ template < typename T > class HostVector final : public memory::BufferVector diff --git a/src/engine/buffers/vector/concepts.hpp b/src/engine/buffers/vector/concepts.hpp index 4201a3e..a607eca 100644 --- a/src/engine/buffers/vector/concepts.hpp +++ b/src/engine/buffers/vector/concepts.hpp @@ -4,6 +4,8 @@ #pragma once +#include "engine/buffers/BufferSuballocation.hpp" + namespace fgl::engine::memory { struct DeviceVectorBase @@ -15,4 +17,4 @@ namespace fgl::engine::memory requires std::is_base_of_v< BufferSuballocation, T >; }; -} // namespace fgl::engine +} // namespace fgl::engine::memory diff --git a/src/engine/concepts/is_buffer.hpp b/src/engine/concepts/is_buffer.hpp index a6bee23..029e5e8 100644 --- a/src/engine/concepts/is_buffer.hpp +++ b/src/engine/concepts/is_buffer.hpp @@ -12,6 +12,7 @@ namespace fgl::engine::memory { template < typename T > concept is_buffer = std::same_as< T, Buffer >; - template < typename T > concept is_buffer_ref = is_buffer< std::remove_reference_t< T > >; + template < typename T > + concept is_buffer_ref = std::is_reference_v< T > && is_buffer< std::remove_reference_t< T > >; } // namespace fgl::engine::memory \ No newline at end of file diff --git a/src/engine/debug/DrawQueue.cpp b/src/engine/debug/DrawQueue.cpp deleted file mode 100644 index b92e361..0000000 --- a/src/engine/debug/DrawQueue.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// -// Created by kj16609 on 3/6/24. -// diff --git a/src/engine/debug/DrawQueue.hpp b/src/engine/debug/DrawQueue.hpp deleted file mode 100644 index c8ef9a4..0000000 --- a/src/engine/debug/DrawQueue.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// -// Created by kj16609 on 3/6/24. -// - -#pragma once - -namespace fgl::debug -{ - - - - class DrawQueue - { - std::thread draw_consumer; - - //TODO: Replace with ring buffer - std::mutex mtx; - std::queue< > - - - - }; - - -} diff --git a/src/engine/descriptors/Descriptor.hpp b/src/engine/descriptors/Descriptor.hpp index 03cb132..6a8b156 100644 --- a/src/engine/descriptors/Descriptor.hpp +++ b/src/engine/descriptors/Descriptor.hpp @@ -7,12 +7,19 @@ #include #include "engine/buffers/Buffer.hpp" -#include "engine/concepts/is_bindable.hpp" #include "engine/concepts/is_descriptor.hpp" namespace fgl::engine::descriptors { + /** + * + * @tparam binding_idx Index of the descriptor + * @tparam descriptor_type Descriptor flags + * @tparam stage_flags + * @tparam binding_count Number of descriptors to have + * @tparam binding_flags Flags to bind with + */ template < std::uint16_t binding_idx, vk::DescriptorType descriptor_type, diff --git a/src/engine/descriptors/DescriptorPool.hpp b/src/engine/descriptors/DescriptorPool.hpp index 6d0666f..04f83d4 100644 --- a/src/engine/descriptors/DescriptorPool.hpp +++ b/src/engine/descriptors/DescriptorPool.hpp @@ -7,7 +7,6 @@ #include #include -#include #include namespace fgl::engine diff --git a/src/engine/descriptors/DescriptorSet.cpp b/src/engine/descriptors/DescriptorSet.cpp index bd2e206..d2979d4 100644 --- a/src/engine/descriptors/DescriptorSet.cpp +++ b/src/engine/descriptors/DescriptorSet.cpp @@ -6,6 +6,8 @@ #include +#include + #include "DescriptorPool.hpp" #include "engine/buffers/BufferSuballocation.hpp" #include "engine/image/ImageView.hpp" @@ -19,7 +21,7 @@ namespace fgl::engine::descriptors m_set( DescriptorPool::getInstance().allocateSet( m_layout ) ) {} - DescriptorSet::DescriptorSet( DescriptorSet&& other ) : + DescriptorSet::DescriptorSet( DescriptorSet&& other ) noexcept : m_infos( std::move( other.m_infos ) ), descriptor_writes( std::move( other.descriptor_writes ) ), m_resources( std::move( other.m_resources ) ), @@ -30,7 +32,7 @@ namespace fgl::engine::descriptors other.m_set = VK_NULL_HANDLE; } - DescriptorSet& DescriptorSet::operator=( DescriptorSet&& other ) + DescriptorSet& DescriptorSet::operator=( DescriptorSet&& other ) noexcept { m_infos = std::move( other.m_infos ); descriptor_writes = std::move( other.descriptor_writes ); @@ -134,8 +136,11 @@ namespace fgl::engine::descriptors m_infos.resize( max_idx + 1 ); } - void DescriptorSet:: - bindAttachment( std::uint32_t binding_idx, ImageView& view, vk::ImageLayout layout, vk::raii::Sampler sampler ) + void DescriptorSet::bindAttachment( + const std::uint32_t binding_idx, + const ImageView& view, + const vk::ImageLayout layout, + const vk::raii::Sampler& sampler ) { assert( binding_idx < m_infos.size() && "Binding index out of range" ); @@ -155,7 +160,7 @@ namespace fgl::engine::descriptors descriptor_writes.push_back( write ); } - void DescriptorSet::setName( const std::string str ) + void DescriptorSet::setName( const std::string& str ) { vk::DebugUtilsObjectNameInfoEXT info {}; info.objectType = vk::ObjectType::eDescriptorSet; @@ -164,4 +169,4 @@ namespace fgl::engine::descriptors Device::getInstance().setDebugUtilsObjectName( info ); } -} // namespace fgl::engine \ No newline at end of file +} // namespace fgl::engine::descriptors \ No newline at end of file diff --git a/src/engine/descriptors/DescriptorSet.hpp b/src/engine/descriptors/DescriptorSet.hpp index 31871d0..33ce3ad 100644 --- a/src/engine/descriptors/DescriptorSet.hpp +++ b/src/engine/descriptors/DescriptorSet.hpp @@ -46,9 +46,9 @@ namespace fgl::engine::descriptors void setMaxIDX( std::uint32_t max_idx ); - VkDescriptorSet operator*() { return *m_set; } + VkDescriptorSet operator*() const { return *m_set; } - VkDescriptorSet getVkDescriptorSet() { return *m_set; } + VkDescriptorSet getVkDescriptorSet() const { return *m_set; } DescriptorSet() = delete; DescriptorSet( vk::raii::DescriptorSetLayout&& layout ); @@ -58,8 +58,8 @@ namespace fgl::engine::descriptors DescriptorSet& operator=( const DescriptorSet& other ) = delete; //Move - DescriptorSet( DescriptorSet&& other ); - DescriptorSet& operator=( DescriptorSet&& other ); + DescriptorSet( DescriptorSet&& other ) noexcept; + DescriptorSet& operator=( DescriptorSet&& other ) noexcept; void bindImage( std::uint32_t binding_idx, @@ -71,13 +71,13 @@ namespace fgl::engine::descriptors void bindAttachment( std::uint32_t binding_idx, - ImageView& view, + const ImageView& view, vk::ImageLayout layout, - vk::raii::Sampler sampler = VK_NULL_HANDLE ); + const vk::raii::Sampler& sampler = VK_NULL_HANDLE ); void bindTexture( std::uint32_t binding_idx, std::shared_ptr< Texture >& tex_ptr ); - void setName( const std::string str ); + void setName( const std::string& str ); }; } // namespace fgl::engine::descriptors \ No newline at end of file diff --git a/src/engine/descriptors/DescriptorSetCollection.hpp b/src/engine/descriptors/DescriptorSetCollection.hpp index 2376e8a..d3b68a3 100644 --- a/src/engine/descriptors/DescriptorSetCollection.hpp +++ b/src/engine/descriptors/DescriptorSetCollection.hpp @@ -56,11 +56,14 @@ namespace fgl::engine::descriptors static std::vector< vk::raii::DescriptorSetLayout > createDescriptorSets() { - auto vec { createDescriptorSetsT< DescriptorSets... >() }; - assert( vec.size() > 0 ); - assert( vec.size() == binding_sets ); + std::vector< vk::raii::DescriptorSetLayout > layouts {}; + layouts.reserve( binding_sets ); + createDescriptorSetsT< DescriptorSets... >( layouts ); - return vec; + assert( layouts.size() > 0 ); + assert( layouts.size() == binding_sets ); + + return layouts; } template < std::uint64_t IDX > @@ -73,4 +76,4 @@ namespace fgl::engine::descriptors using PushConstantT = BindingSet< 0 >; }; -} // namespace fgl::engine \ No newline at end of file +} // namespace fgl::engine::descriptors \ No newline at end of file diff --git a/src/engine/descriptors/DescriptorSetLayout.hpp b/src/engine/descriptors/DescriptorSetLayout.hpp index e7d28a9..f529ae4 100644 --- a/src/engine/descriptors/DescriptorSetLayout.hpp +++ b/src/engine/descriptors/DescriptorSetLayout.hpp @@ -54,12 +54,14 @@ namespace fgl::engine::descriptors std::array< vk::DescriptorSetLayoutBinding, used_descriptor_count > data {}; for ( std::uint16_t i = 0; i < used_descriptor_count; ++i ) + { data[ i ] = vk::DescriptorSetLayoutBinding( std::numeric_limits< std::uint32_t >::max(), vk::DescriptorType::eUniformBuffer, 1, vk::ShaderStageFlagBits::eAll, nullptr ); + } return data; } diff --git a/src/engine/descriptors/createDescriptorSets.hpp b/src/engine/descriptors/createDescriptorSets.hpp index 7139f4f..658833a 100644 --- a/src/engine/descriptors/createDescriptorSets.hpp +++ b/src/engine/descriptors/createDescriptorSets.hpp @@ -10,8 +10,7 @@ namespace fgl::engine::descriptors { template < is_valid_pipeline_input CurrentSet, is_valid_pipeline_input... Sets > - std::vector< vk::raii::DescriptorSetLayout > createDescriptorSetsT( std::vector< vk::raii::DescriptorSetLayout > - out ) + FGL_FORCE_INLINE inline void createDescriptorSetsT( std::vector< vk::raii::DescriptorSetLayout >& out ) { if constexpr ( is_descriptor_set< CurrentSet > ) { @@ -29,37 +28,8 @@ namespace fgl::engine::descriptors if constexpr ( sizeof...( Sets ) > 0 ) { - return createDescriptorSetsT< Sets... >( std::move( out ) ); + return createDescriptorSetsT< Sets... >( out ); } - - return out; } - template < is_valid_pipeline_input CurrentSet, is_valid_pipeline_input... Sets > - std::vector< vk::raii::DescriptorSetLayout > createDescriptorSetsT() - { - std::vector< vk::raii::DescriptorSetLayout > out {}; - - if constexpr ( is_descriptor_set< CurrentSet > ) - { - vk::raii::DescriptorSetLayout layout { CurrentSet::createDescriptorSetLayout() }; - out.emplace_back( std::move( layout ) ); - } - else if constexpr ( is_constant_range< CurrentSet > ) - { - //noop - } - else - { - static_assert( false, "Invalid input" ); - } - - if constexpr ( sizeof...( Sets ) > 0 ) - { - return createDescriptorSetsT< Sets... >( std::move( out ) ); - } - - return out; - } - -} // namespace fgl::engine \ No newline at end of file +} // namespace fgl::engine::descriptors \ No newline at end of file diff --git a/src/engine/filesystem/FileBrowser.cpp b/src/engine/filesystem/FileBrowser.cpp index aa073c7..4fd450b 100644 --- a/src/engine/filesystem/FileBrowser.cpp +++ b/src/engine/filesystem/FileBrowser.cpp @@ -39,7 +39,7 @@ namespace fgl::engine::filesystem current = std::make_unique< DirInfo >( test_path ); } - void FileBrowser::drawGui( FrameInfo& info ) + void FileBrowser::drawGui( [[maybe_unused]] FrameInfo& info ) { ZoneScoped; std::call_once( flag, prepareFileGUI ); @@ -166,7 +166,7 @@ namespace fgl::engine::filesystem } } - void drawBinary( const FileInfo& info ) + void drawBinary( [[maybe_unused]] const FileInfo& info ) { // file_texture->drawImGui( { 128, 128 } ); file_texture->drawImGuiButton( { desired_size, desired_size } ); @@ -242,15 +242,15 @@ namespace fgl::engine::filesystem current = current->up(); } - void FileBrowser::openFolder( DirInfo dir ) + void FileBrowser::openFolder( const DirInfo& dir ) { file_textures.clear(); current = std::make_unique< DirInfo >( dir.path ); } - void FileBrowser::drawUp( const std::unique_ptr< DirInfo >& data ) + void FileBrowser::drawUp( const std::unique_ptr< DirInfo >& current_dir ) { - auto up { data->up() }; + auto up { current_dir->up() }; ImGui::PushID( up->path.c_str() ); diff --git a/src/engine/filesystem/FileBrowser.hpp b/src/engine/filesystem/FileBrowser.hpp index d9a58df..a575791 100644 --- a/src/engine/filesystem/FileBrowser.hpp +++ b/src/engine/filesystem/FileBrowser.hpp @@ -16,11 +16,9 @@ namespace fgl::engine::filesystem struct FileBrowser { - static FileBrowser& getInstance(); - static void goUp(); - static void openFolder( DirInfo dir ); + static void openFolder( const DirInfo& dir ); static void drawUp( const std::unique_ptr< DirInfo >& up ); static void drawGui( FrameInfo& info ); diff --git a/src/engine/image/Image.cpp b/src/engine/image/Image.cpp index cb13bda..7215388 100644 --- a/src/engine/image/Image.cpp +++ b/src/engine/image/Image.cpp @@ -21,7 +21,7 @@ namespace fgl::engine } } - Image& Image::setName( const std::string str ) + Image& Image::setName( const std::string& str ) { m_handle->setName( str ); return *this; diff --git a/src/engine/image/Image.hpp b/src/engine/image/Image.hpp index c63ee27..ae059cc 100644 --- a/src/engine/image/Image.hpp +++ b/src/engine/image/Image.hpp @@ -29,34 +29,37 @@ namespace fgl::engine Image() = delete; - Image( const vk::Extent2D extent, const vk::Format format, vk::Image image, vk::ImageUsageFlags usage ) noexcept - : + [[nodiscard]] Image( + const vk::Extent2D extent, + const vk::Format format, + const vk::Image image, + const vk::ImageUsageFlags usage ) noexcept : m_handle( std::make_shared< ImageHandle >( extent, format, image, usage ) ) {} - Image& setName( const std::string str ); + Image& setName( const std::string& str ); Image( const vk::Extent2D extent, const vk::Format format, - vk::ImageUsageFlags usage, - vk::ImageLayout inital_layout, - vk::ImageLayout final_layout ) : + const vk::ImageUsageFlags usage, + const vk::ImageLayout inital_layout, + const vk::ImageLayout final_layout ) : m_handle( std::make_shared< ImageHandle >( extent, format, usage, inital_layout, final_layout ) ) {} Image( const Image& other ) : m_handle( other.m_handle ) {} - Image& operator=( const Image& other ) + [[nodiscard]] Image& operator=( const Image& other ) { m_handle = other.m_handle; view = {}; return *this; } - Image( Image&& other ) = default; + [[nodiscard]] Image( Image&& other ) = default; - Image& operator=( Image&& other ) noexcept + [[nodiscard]] Image& operator=( Image&& other ) noexcept { m_handle = std::move( other.m_handle ); view = std::move( other.view ); diff --git a/src/engine/math/hyperplaneSeperationTheorem.hpp b/src/engine/math/hyperplaneSeperationTheorem.hpp deleted file mode 100644 index 9b5b77a..0000000 --- a/src/engine/math/hyperplaneSeperationTheorem.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Created by kj16609 on 3/1/24. -// - -#pragma once - -namespace fgl::engine -{ - -} diff --git a/src/engine/math/midpoint.cpp b/src/engine/math/midpoint.cpp deleted file mode 100644 index 78623d3..0000000 --- a/src/engine/math/midpoint.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Created by kj16609 on 2/29/24. -// - -#include "midpoint.hpp" - -#include "engine/primitives/points/Coordinate.hpp" - -using namespace fgl::engine; - -namespace fgl -{ - - template < CoordinateSpace CType > - Coordinate< CType > midpoint( const Coordinate< CType > left, const Coordinate< CType > right ) - { - const auto x { ( left.vec().x + right.vec().x ) / 2.0f }; - const auto y { ( left.vec().y + right.vec().y ) / 2.0f }; - const auto z { ( left.vec().z + right.vec().z ) / 2.0f }; - - return Coordinate< CType >( x, y, z ); - } - - template Coordinate< CoordinateSpace::Model > - midpoint( const Coordinate< CoordinateSpace::Model >, const Coordinate< CoordinateSpace::Model > ); - template Coordinate< CoordinateSpace::World > - midpoint( const Coordinate< CoordinateSpace::World >, const Coordinate< CoordinateSpace::World > ); - -} // namespace fgl diff --git a/src/engine/math/midpoint.hpp b/src/engine/math/midpoint.hpp deleted file mode 100644 index e4a5f7a..0000000 --- a/src/engine/math/midpoint.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by kj16609 on 2/29/24. -// - -#pragma once - -#include "engine/primitives/CoordinateSpace.hpp" - -namespace fgl -{ - namespace engine - { - template < CoordinateSpace > - class Coordinate; - } - - template < engine::CoordinateSpace CType > - engine::Coordinate< CType > - midpoint( const engine::Coordinate< CType > left, const engine::Coordinate< CType > right ); - -} // namespace fgl diff --git a/src/engine/math/taitBryanMatrix.cpp b/src/engine/math/taitBryanMatrix.cpp index 2e85fbb..df7f443 100644 --- a/src/engine/math/taitBryanMatrix.cpp +++ b/src/engine/math/taitBryanMatrix.cpp @@ -4,8 +4,6 @@ #include "taitBryanMatrix.hpp" -#include - #include #include #include @@ -58,13 +56,11 @@ namespace fgl::engine { glm::mat3 mat { 1.0f }; - //TODO: Debug with Entry, There has got to be a better fix then this. - const auto [ p1, p2, p3 ] = extract( rotation, order ); - const auto [ c1, s1 ] = p1; - const auto [ c2, s2 ] = p2; - const auto [ c3, s3 ] = p3; + const auto& [ c1, s1 ] = p1; + const auto& [ c2, s2 ] = p2; + const auto& [ c3, s3 ] = p3; switch ( order ) { diff --git a/src/engine/model/Model.hpp b/src/engine/model/Model.hpp index 9aab945..4dbd5c4 100644 --- a/src/engine/model/Model.hpp +++ b/src/engine/model/Model.hpp @@ -36,8 +36,6 @@ namespace fgl::engine static OrientedBoundingBox< CoordinateSpace::Model > buildBoundingBox( const std::vector< Primitive >& primitives ); - TransformComponent m_model_transform; - std::vector< vk::DrawIndexedIndirectCommand > m_draw_parameters; std::string m_name { "Unnamed model" }; diff --git a/src/engine/model/Primitive.hpp b/src/engine/model/Primitive.hpp index 5a3c41e..82abf82 100644 --- a/src/engine/model/Primitive.hpp +++ b/src/engine/model/Primitive.hpp @@ -74,7 +74,7 @@ namespace fgl::engine VertexBufferSuballocation&& vertex_buffer, IndexBufferSuballocation&& index_buffer, const OrientedBoundingBox< CoordinateSpace::Model >& bounding_box, - const PrimitiveMode mode ) : + const PrimitiveMode mode ) noexcept : m_vertex_buffer( std::move( vertex_buffer ) ), m_index_buffer( std::move( index_buffer ) ), m_bounding_box( bounding_box ), diff --git a/src/engine/model/builders/ModelBuilder.cpp b/src/engine/model/builders/ModelBuilder.cpp index 132f2c0..e8ad2fa 100644 --- a/src/engine/model/builders/ModelBuilder.cpp +++ b/src/engine/model/builders/ModelBuilder.cpp @@ -16,10 +16,6 @@ namespace fgl::engine { loadObj( filepath ); } - else if ( filepath.extension() == ".gltf" ) - { - loadGltf( filepath ); - } else throw std::runtime_error( "Unknown model file extension" ); } diff --git a/src/engine/model/builders/ModelBuilder.hpp b/src/engine/model/builders/ModelBuilder.hpp index 54b1dcb..fe755ad 100644 --- a/src/engine/model/builders/ModelBuilder.hpp +++ b/src/engine/model/builders/ModelBuilder.hpp @@ -7,6 +7,8 @@ #include #include +#include "engine/primitives/TransformComponent.hpp" + namespace fgl::engine { struct Vertex; diff --git a/src/engine/model/builders/SceneBuilder.cpp b/src/engine/model/builders/SceneBuilder.cpp index 60cc648..c3759da 100644 --- a/src/engine/model/builders/SceneBuilder.cpp +++ b/src/engine/model/builders/SceneBuilder.cpp @@ -370,6 +370,32 @@ namespace fgl::engine return box; } + glm::vec3 convertToVec3( const std::vector< double >& data ) + { + return { static_cast< float >( data[ 0 ] ), + static_cast< float >( data[ 1 ] ), + static_cast< float >( data[ 2 ] ) }; + } + + TransformComponent SceneBuilder::loadTransform( int node_idx, const tinygltf::Model& root ) + { + const auto node { root.nodes[ node_idx ] }; + + const glm::vec3 translation { convertToVec3( node.translation ) }; + const glm::quat rotation { static_cast< float >( node.rotation[ 0 ] ), + static_cast< float >( node.rotation[ 1 ] ), + static_cast< float >( node.rotation[ 2 ] ), + static_cast< float >( node.rotation[ 3 ] ) }; + const glm::vec3 scale { convertToVec3( node.scale ) }; + + TransformComponent transform_component {}; + transform_component.rotation = rotation; + transform_component.scale = scale; + transform_component.translation = WorldCoordinate( translation ); + + return transform_component; + } + std::shared_ptr< Model > SceneBuilder::loadModel( const int mesh_idx, const tinygltf::Model& root ) { ZoneScoped; diff --git a/src/engine/model/builders/SceneBuilder.hpp b/src/engine/model/builders/SceneBuilder.hpp index 7871734..042fb89 100644 --- a/src/engine/model/builders/SceneBuilder.hpp +++ b/src/engine/model/builders/SceneBuilder.hpp @@ -10,6 +10,8 @@ #include #include +#include "engine/primitives/TransformComponent.hpp" + namespace fgl::engine { struct PrimitiveTextures; @@ -47,6 +49,8 @@ namespace fgl::engine void handleScene( const tinygltf::Scene& scene, const tinygltf::Model& root ); void handleNode( const int node_idx, const tinygltf::Model& root ); + + TransformComponent loadTransform( int node_idx, const tinygltf::Model& root ); std::shared_ptr< Model > loadModel( const int mesh_idx, const tinygltf::Model& root ); Primitive loadPrimitive( const tinygltf::Primitive& prim, const tinygltf::Model& model ); diff --git a/src/engine/model/builders/loadGltf.cpp b/src/engine/model/builders/loadGltf.cpp deleted file mode 100644 index 044c878..0000000 --- a/src/engine/model/builders/loadGltf.cpp +++ /dev/null @@ -1,322 +0,0 @@ -// -// Created by kj16609 on 5/18/24. -// - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wold-style-cast" -#pragma GCC diagnostic ignored "-Weffc++" -#include "objectloaders/tiny_gltf.h" -#pragma GCC diagnostic pop - -#include "ModelBuilder.hpp" -#include "engine/assets/TransferManager.hpp" -#include "engine/assets/stores.hpp" -#include "engine/descriptors/DescriptorSet.hpp" -#include "engine/image/ImageView.hpp" -#include "engine/image/Sampler.hpp" -#include "engine/model/Primitive.hpp" -#include "engine/primitives/boxes/OrientedBoundingBox.hpp" -#include "engine/primitives/points/Coordinate.hpp" - -namespace fgl::engine -{ - template < typename T > - std::vector< T > extractData( const tinygltf::Model& model, const tinygltf::Accessor& accessor ) - { - ZoneScoped; - if ( accessor.sparse.isSparse ) - { - //Sparse loading required - throw std::runtime_error( "Sparse loading not implemeneted" ); - } - - const auto& buffer_view { model.bufferViews.at( accessor.bufferView ) }; - const auto& buffer { model.buffers.at( buffer_view.buffer ) }; - - std::vector< T > data {}; - data.reserve( accessor.count ); - - std::uint16_t copy_size { 0 }; - switch ( accessor.componentType ) - { - default: - throw std::runtime_error( "Unhandled access size" ); - case TINYGLTF_COMPONENT_TYPE_FLOAT: - copy_size = 32 / 8; - break; - case TINYGLTF_COMPONENT_TYPE_BYTE: - copy_size = 8 / 8; - break; - case TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT: - copy_size = 32 / 8; - break; - case TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT: - copy_size = 16 / 8; - break; - } - - switch ( accessor.type ) - { - default: - throw std::runtime_error( "Unhandled access type" ); - case TINYGLTF_TYPE_VEC3: - copy_size *= 3; - break; - case TINYGLTF_TYPE_VEC2: - copy_size *= 2; - break; - case TINYGLTF_TYPE_SCALAR: - copy_size *= 1; - break; - } - - constexpr auto T_SIZE { sizeof( T ) }; - - if ( T_SIZE != copy_size ) - throw std::runtime_error( - std::string( "Accessor copy values not matching sizeof(T): sizeof(T) == " ) + std::to_string( T_SIZE ) - + " vs copy_size = " + std::to_string( copy_size ) ); - - const auto real_size { copy_size * accessor.count }; - - data.resize( accessor.count ); - - std::memcpy( data.data(), buffer.data.data() + buffer_view.byteOffset + accessor.byteOffset, real_size ); - - return data; - } - - void ModelBuilder::loadGltf( const std::filesystem::path& filepath ) - { - ZoneScoped; - std::cout << "Loading gltf model " << filepath << std::endl; - - if ( !std::filesystem::exists( filepath ) ) throw std::runtime_error( "File does not exist" ); - - m_primitives.clear(); - - tinygltf::Model model {}; - tinygltf::TinyGLTF loader {}; - std::string err {}; - std::string warn {}; - - loader.RemoveImageLoader(); - - loader.LoadASCIIFromFile( &model, &err, &warn, filepath.string() ); - - if ( !err.empty() ) throw std::runtime_error( err ); - - if ( !warn.empty() ) - std::cout << "Warning while loading model \"" << filepath.string() << "\"\nWarning:" << warn << std::endl; - - for ( const tinygltf::Mesh& mesh : model.meshes ) - { - for ( const tinygltf::Primitive& primitive : mesh.primitives ) - { - //TODO: Implement modes - - //Load indicies - auto& indicies_accessor { model.accessors.at( primitive.indices ) }; - - std::vector< std::uint32_t > indicies_data {}; - - if ( indicies_accessor.componentType == TINYGLTF_COMPONENT_TYPE_INT ) - { - indicies_data = extractData< std::uint32_t >( model, model.accessors.at( primitive.indices ) ); - } - else if ( indicies_accessor.componentType == TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT ) - { - const auto tmp { extractData< std::uint16_t >( model, model.accessors.at( primitive.indices ) ) }; - - indicies_data.reserve( tmp.size() ); - - for ( auto& val : tmp ) indicies_data.emplace_back( val ); - } - - //Load positions - auto& position_accessor { model.accessors.at( primitive.attributes.at( "POSITION" ) ) }; - std::vector< ModelCoordinate > position_data { - extractData< ModelCoordinate >( model, position_accessor ) - }; - - std::vector< glm::vec3 > normals {}; - - if ( primitive.attributes.find( "NORMAL" ) != primitive.attributes.end() ) - { - normals = - extractData< glm::vec3 >( model, model.accessors.at( primitive.attributes.at( "NORMAL" ) ) ); - } - else // TODO: Precompute normals if required - normals.resize( position_data.size() ); - - //TODO: Implement TANGENT reading - std::vector< glm::vec3 > tangents {}; - - std::vector< glm::vec2 > texcoords {}; - - for ( const auto& [ attr_name, attr_idx ] : primitive.attributes ) - { - if ( attr_name.starts_with( "TEXCOORD_" ) ) - { - //Rip out name and figure out index - const auto idx { std::stoi( attr_name.substr( strlen( "TEXCOORD_" ) ) ) }; - - if ( idx != 0 ) throw std::runtime_error( "Multiple tex coordinates not supported" ); - - const auto& texcoord_accessor { model.accessors.at( attr_idx ) }; - - texcoords = extractData< glm::vec2 >( model, texcoord_accessor ); - } - } - - std::vector< Vertex > verts {}; - verts.resize( position_data.size() ); - - assert( verts.size() == normals.size() ); - - for ( std::size_t i = 0; i < position_data.size(); i++ ) - { - //Fix position to be -Z UP - //verts[ i ].m_position = position_data[ i ]; - verts[ i ].m_position = - glm::vec3( position_data[ i ].vec().x, position_data[ i ].vec().z, position_data[ i ].vec().y ); - verts[ i ].m_normal = normals[ i ]; - } - - const ModelBoundingBox bounding_box { generateBoundingFromVerts( verts ) }; - - if ( texcoords.size() > 0 && texcoords.size() != verts.size() ) - { - throw std::runtime_error( - "wtf? " + std::to_string( texcoords.size() ) + " < " + std::to_string( verts.size() ) ); - } - - if ( texcoords.size() == verts.size() ) - { - for ( std::size_t i = 0; i < texcoords.size(); ++i ) verts[ i ].m_uv = texcoords[ i ]; - } - - VertexBufferSuballocation vertex_buffer { m_vertex_buffer, verts }; - IndexBufferSuballocation index_buffer { m_index_buffer, indicies_data }; - - if ( primitive.material >= 0 && primitive.material < static_cast< int >( model.materials.size() ) ) - { - const auto& material { model.materials.at( static_cast< unsigned long >( primitive.material ) ) }; - - //TODO: Implement material normals - - //Color texture - if ( material.values.contains( "baseColorTexture" ) ) - { - const auto& color_texture { material.values.at( "baseColorTexture" ) }; - const auto color_index { color_texture.TextureIndex() }; - - const auto& texture { model.textures.at( static_cast< unsigned long >( color_index ) ) }; - - const auto& source { model.images.at( static_cast< unsigned long >( texture.source ) ) }; - const auto& sampler { model.samplers.at( static_cast< unsigned long >( texture.sampler ) ) }; - - auto translateFilterToVK = []( const int val ) -> vk::Filter - { - switch ( val ) - { - default: - throw std::runtime_error( "Failed to translate filter value to vk filter value" ); - case GL_NEAREST: - return vk::Filter::eNearest; - case GL_LINEAR: - [[fallthrough]]; - case GL_LINEAR_MIPMAP_LINEAR: - return vk::Filter::eLinear; - } - }; - - auto translateWarppingToVk = []( const int val ) -> vk::SamplerAddressMode - { - switch ( val ) - { - default: - throw std:: - runtime_error( "Failed to translate wrapping filter to vk address mode" ); - case GL_REPEAT: - return vk::SamplerAddressMode::eRepeat; -#ifdef GL_CLAMP_TO_BORDER - case GL_CLAMP_TO_BORDER: - return vk::SamplerAddressMode::eClampToBorder; -#endif -#ifdef GL_CLAMP_TO_EDGE - case GL_CLAMP_TO_EDGE: - return vk::SamplerAddressMode::eClampToEdge; -#endif - } - }; - - assert( - sampler.wrapS == sampler.wrapT - && "Can't support different wrap modes for textures on each axis" ); - - //TOOD: Get format from texture info and convert to vkFOrmat - - std::shared_ptr< Texture > tex { - getTextureStore().load( filepath.parent_path() / source.uri, vk::Format::eR8G8B8A8Unorm ) - }; - - Sampler smp { translateFilterToVK( sampler.minFilter ), - translateFilterToVK( sampler.magFilter ), - vk::SamplerMipmapMode::eLinear, - translateWarppingToVk( sampler.wrapS ) }; - - tex->getImageView().getSampler() = std::move( smp ); - tex->createImGuiSet(); - - Texture::getTextureDescriptorSet().bindTexture( 0, tex ); - Texture::getTextureDescriptorSet().update(); - - //Stage texture - auto cmd { Device::getInstance().beginSingleTimeCommands() }; - - PrimitiveTextures primitive_textures {}; - primitive_textures.albedo = tex; - - Primitive prim { std::move( vertex_buffer ), - std::move( index_buffer ), - bounding_box, - std::move( primitive_textures ), - PrimitiveMode::TRIS }; - - m_primitives.emplace_back( std::move( prim ) ); - - continue; - } - } - else - std::cout << "No material" << std::endl; - - Primitive prim { - std::move( vertex_buffer ), std::move( index_buffer ), bounding_box, PrimitiveMode::TRIS - }; - - m_primitives.emplace_back( std::move( prim ) ); - } - - std::cout << "Mesh has " << mesh.primitives.size() << " primitives" << std::endl; - } - - for ( const tinygltf::Scene& scene : model.scenes ) - { - std::cout << "Scene has " << scene.nodes.size() << " nodes" << std::endl; - - for ( auto child : scene.nodes ) - { - std::cout << "Child: " << child << std::endl; - } - } - - std::cout << "Scenes: " << model.scenes.size() << std::endl; - - std::cout << "Meshes: " << model.meshes.size() << std::endl; - - std::cout << "Finished loading model: " << filepath << std::endl; - } - -} // namespace fgl::engine diff --git a/src/engine/model/builders/loadObj.cpp b/src/engine/model/builders/loadObj.cpp index f0a8046..7226c79 100644 --- a/src/engine/model/builders/loadObj.cpp +++ b/src/engine/model/builders/loadObj.cpp @@ -111,6 +111,6 @@ namespace fgl::engine bounding_box, PrimitiveMode::TRIS ); - std::cout << unique_verts.size() << " unique verts" << std::endl; + log::debug( "{} unique verts loading model {}", unique_verts.size(), filepath ); } } // namespace fgl::engine diff --git a/src/engine/model/prebuilt/terrainModel.cpp b/src/engine/model/prebuilt/terrainModel.cpp index 2e9bcc9..c172ae7 100644 --- a/src/engine/model/prebuilt/terrainModel.cpp +++ b/src/engine/model/prebuilt/terrainModel.cpp @@ -5,7 +5,6 @@ #include "terrainModel.hpp" #include "engine/model/Model.hpp" -#include "engine/rendering/Device.hpp" namespace fgl::engine { diff --git a/src/engine/pipeline/PipelineT.hpp b/src/engine/pipeline/PipelineT.hpp index 77d66b2..e38b15f 100644 --- a/src/engine/pipeline/PipelineT.hpp +++ b/src/engine/pipeline/PipelineT.hpp @@ -85,11 +85,11 @@ namespace fgl::engine vk::raii::PipelineLayout createLayout( [[maybe_unused]] Device& device ) { - std::vector< vk::raii::DescriptorSetLayout > layouts { DescriptorSetCollection::createDescriptorSets() }; + const auto layouts { DescriptorSetCollection::createDescriptorSets() }; std::vector< vk::DescriptorSetLayout > vk_layouts {}; vk_layouts.reserve( layouts.size() ); - for ( vk::raii::DescriptorSetLayout& layout : layouts ) + for ( const vk::raii::DescriptorSetLayout& layout : layouts ) { vk_layouts.emplace_back( *layout ); } diff --git a/src/engine/primitives/Rotation.cpp b/src/engine/primitives/Rotation.cpp index 6f6612c..99b1a82 100644 --- a/src/engine/primitives/Rotation.cpp +++ b/src/engine/primitives/Rotation.cpp @@ -12,14 +12,18 @@ namespace fgl::engine { + //! Converts 3-axis rotation (euler) to a quaternion glm::quat toQuat( const float pitch, const float roll, const float yaw ) { - const float cr { glm::cos( roll * 0.5f ) }; - const float sr { glm::sin( roll * 0.5f ) }; - const float cp { glm::cos( pitch * 0.5f ) }; - const float sp { glm::sin( pitch * 0.5f ) }; - const float cy { glm::cos( yaw * 0.5f ) }; - const float sy { glm::sin( yaw * 0.5f ) }; + const glm::vec3 rotation { glm::vec3( pitch, roll, yaw ) * glm::vec3( 0.5f ) }; + const glm::vec3 rot_cos { glm::cos( rotation ) }; + const glm::vec3 rot_sin { glm::sin( rotation ) }; + + auto extractFloats = []( const glm::vec3& vec ) -> std::tuple< const float&, const float&, const float > + { return std::make_tuple( vec.x, vec.y, vec.z ); }; + + const auto& [ cp, cr, cy ] = extractFloats( rot_cos ); + const auto& [ sp, sr, sy ] = extractFloats( rot_sin ); return { sr * cp * sy - cr * sp * sy, cr * sp * cy + sr * cp * sy, @@ -34,15 +38,15 @@ namespace fgl::engine glm::quat( glm::toQuat( taitBryanMatrix( pitch_r, roll_r, yaw_r ) ) ) {} - Rotation& Rotation::operator=( const Rotation other ) + Rotation& Rotation::operator=( const Rotation& rotation ) { - glm::quat::operator=( other ); + glm::quat::operator=( rotation ); return *this; } - Rotation& Rotation::operator+=( const Rotation i_vec ) + Rotation& Rotation::operator+=( const Rotation& rotation ) { - glm::quat::operator+=( i_vec ); + glm::quat::operator+=( rotation ); return *this; } diff --git a/src/engine/primitives/Rotation.hpp b/src/engine/primitives/Rotation.hpp index 41e48d0..fd6955a 100644 --- a/src/engine/primitives/Rotation.hpp +++ b/src/engine/primitives/Rotation.hpp @@ -102,9 +102,9 @@ namespace fgl::engine return std::atan2( siny_cosp, cosy_cosp ); } - Rotation& operator=( const Rotation other ); + Rotation& operator=( const Rotation& rotation ); - Rotation& operator+=( const Rotation vec ); + Rotation& operator+=( const Rotation& rotation ); NormalVector forward() const; diff --git a/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp b/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp index 603b0c1..ebfaf31 100644 --- a/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp +++ b/src/engine/primitives/boxes/AxisAlignedBoundingBox.hpp @@ -5,7 +5,7 @@ #pragma once #include "BoundingBox.hpp" -#include "engine/math/midpoint.hpp" +#include "engine/primitives/Scale.hpp" #include "engine/primitives/points/Coordinate.hpp" #include "engine/primitives/vectors/NormalVector.hpp" @@ -55,7 +55,7 @@ namespace fgl::engine virtual Coordinate< CType > getPosition() const final { - return fgl::midpoint( m_top_right_forward, m_bottom_left_back ); + return midpoint( m_top_right_forward, m_bottom_left_back ); } virtual inline Coordinate< CType > topLeftForward() const final { return m_top_right_forward; } diff --git a/src/engine/primitives/boxes/OrientedBoundingBox.hpp b/src/engine/primitives/boxes/OrientedBoundingBox.hpp index 4caf547..5d38843 100644 --- a/src/engine/primitives/boxes/OrientedBoundingBox.hpp +++ b/src/engine/primitives/boxes/OrientedBoundingBox.hpp @@ -4,14 +4,13 @@ #pragma once -#include - #include #include #include "BoundingBox.hpp" #include "engine/constants.hpp" #include "engine/primitives/Rotation.hpp" +#include "engine/primitives/Scale.hpp" #include "engine/primitives/matricies/Matrix.hpp" #include "engine/primitives/points/Coordinate.hpp" diff --git a/src/engine/primitives/lines/LineSegment.hpp b/src/engine/primitives/lines/LineSegment.hpp index 7797fbe..db28161 100644 --- a/src/engine/primitives/lines/LineSegment.hpp +++ b/src/engine/primitives/lines/LineSegment.hpp @@ -34,13 +34,13 @@ namespace fgl::engine explicit LineSegment( const glm::vec3 i_start, glm::vec3 i_end ) : start( i_start ), end( i_end ) {} - NormalVector getDirection() const { return NormalVector( end - start ); } + NormalVector getDirection() const { return start.normalTo( end ); } Coordinate< CType > getPosition() const { return start; } Coordinate< CType > getEnd() const { return end; } - inline LineSegment flip() const { return LineSegment( end, start ); } + LineSegment flip() const { return LineSegment( end, start ); } template < typename T > requires is_plane< T > diff --git a/src/engine/primitives/points/Coordinate.cpp b/src/engine/primitives/points/Coordinate.cpp index 41d349e..c9ee263 100644 --- a/src/engine/primitives/points/Coordinate.cpp +++ b/src/engine/primitives/points/Coordinate.cpp @@ -77,6 +77,18 @@ namespace fgl::engine return Coordinate< CType >( vec() - other ); } + template < CoordinateSpace CType > + FGL_FLATTEN NormalVector Coordinate< CType >::normalTo( const Coordinate< CType >& target ) const + { + return NormalVector( ( *this - target ).vec() ); + } + + template < CoordinateSpace CType > + FGL_FLATTEN Vector Coordinate< CType >::vectorTo( const Coordinate< CType >& target ) const + { + return Vector( ( *this - target ).vec() ); + } + template class Coordinate< CoordinateSpace::Model >; template class Coordinate< CoordinateSpace::World >; template class Coordinate< CoordinateSpace::Screen >; diff --git a/src/engine/primitives/points/Coordinate.hpp b/src/engine/primitives/points/Coordinate.hpp index a38ed05..6c58432 100644 --- a/src/engine/primitives/points/Coordinate.hpp +++ b/src/engine/primitives/points/Coordinate.hpp @@ -10,7 +10,6 @@ #include "engine/constants.hpp" #include "engine/primitives/CoordinateSpace.hpp" -#include "engine/primitives/Scale.hpp" #include "engine/primitives/matricies/Matrix.hpp" namespace fgl::engine @@ -75,6 +74,9 @@ namespace fgl::engine Coordinate& operator=( Coordinate&& other ) = default; bool operator==( const Coordinate& other ) const = default; + + NormalVector normalTo( const Coordinate& target ) const; + Vector vectorTo( const Coordinate& target ) const; }; using ModelCoordinate = Coordinate< CoordinateSpace::Model >; @@ -82,16 +84,21 @@ namespace fgl::engine static_assert( sizeof( glm::vec3 ) == sizeof( ModelCoordinate ) ); - template < CoordinateSpace CType > - inline ::std::ostream& operator<<( ::std::ostream& os, const Coordinate< CType > coordinate ) - { - return os << "(" << coordinate.x << ", " << coordinate.y << ", " << coordinate.z << ")"; - } - template < CoordinateSpace CType > inline double distance( const Coordinate< CType >& p1, const Coordinate< CType >& p2 ) { return length( p1.vec() - p2.vec() ); } + template < engine::CoordinateSpace CType > + inline engine::Coordinate< CType > + midpoint( const engine::Coordinate< CType > left, const engine::Coordinate< CType > right ) + { + const auto x { ( left.vec().x + right.vec().x ) / 2.0f }; + const auto y { ( left.vec().y + right.vec().y ) / 2.0f }; + const auto z { ( left.vec().z + right.vec().z ) / 2.0f }; + + return Coordinate< CType >( x, y, z ); + } + } // namespace fgl::engine diff --git a/src/engine/primitives/vectors/NormalVector.hpp b/src/engine/primitives/vectors/NormalVector.hpp index 7724be8..6f04233 100644 --- a/src/engine/primitives/vectors/NormalVector.hpp +++ b/src/engine/primitives/vectors/NormalVector.hpp @@ -8,7 +8,6 @@ #include #include "engine/primitives/CoordinateSpace.hpp" -#include "engine/primitives/points/concepts.hpp" namespace fgl::engine { @@ -18,6 +17,7 @@ namespace fgl::engine class Vector; + //! A vector that must be a distance of 1 class NormalVector : private glm::vec3 { constexpr explicit NormalVector( const glm::vec3 point, [[maybe_unused]] const bool ) : glm::vec3( point ) {} @@ -37,11 +37,6 @@ namespace fgl::engine explicit NormalVector( const glm::vec3 vec ); - template < typename T > - requires is_coordinate< T > - explicit NormalVector( const T vec ) : NormalVector( vec.vec() ) - {} - Vector operator*( const float scalar ) const; NormalVector operator-() const { return NormalVector( -static_cast< glm::vec3 >( *this ) ); } diff --git a/src/engine/primitives/vectors/Vector.hpp b/src/engine/primitives/vectors/Vector.hpp index e119dd6..5930600 100644 --- a/src/engine/primitives/vectors/Vector.hpp +++ b/src/engine/primitives/vectors/Vector.hpp @@ -9,7 +9,6 @@ #include "engine/FGL_DEFINES.hpp" #include "engine/constants.hpp" #include "engine/primitives/CoordinateSpace.hpp" -#include "engine/primitives/points/concepts.hpp" namespace fgl::engine { @@ -34,11 +33,6 @@ namespace fgl::engine constexpr explicit Vector( const glm::vec3 i_vec ) : glm::vec3( i_vec ) {} - template < typename T > - requires is_coordinate< T > - explicit Vector( const T coord ) : glm::vec3( coord.vec() ) - {} - explicit Vector( const NormalVector normal_vector ); constexpr explicit Vector( const float i_x, const float i_y, const float i_z ) : glm::vec3( i_x, i_y, i_z ) {} diff --git a/src/engine/rendering/Device.hpp b/src/engine/rendering/Device.hpp index 491b0ef..6cd8801 100644 --- a/src/engine/rendering/Device.hpp +++ b/src/engine/rendering/Device.hpp @@ -7,6 +7,7 @@ #include "Instance.hpp" #include "PhysicalDevice.hpp" +#include "Surface.hpp" #include "engine/Window.hpp" #include "vma/vma_impl.hpp" diff --git a/src/engine/rendering/Instance.hpp b/src/engine/rendering/Instance.hpp index 2054a8a..f1d5dd8 100644 --- a/src/engine/rendering/Instance.hpp +++ b/src/engine/rendering/Instance.hpp @@ -36,18 +36,16 @@ namespace fgl::engine public: - FGL_DELETE_DEFAULT_CTOR( Instance ) - FGL_DELETE_COPY( Instance ) - FGL_DELETE_MOVE( Instance ) + FGL_DELETE_ALL_Ro5( Instance ); - Instance( vk::raii::Context& ctx ); + explicit Instance( vk::raii::Context& ctx ); ~Instance(); - inline vk::raii::Instance& handle() { return m_instance; } + vk::raii::Instance& handle() { return m_instance; } - inline operator vk::Instance() { return m_instance; } + operator vk::Instance() { return m_instance; } - inline operator VkInstance() { return *m_instance; } + operator VkInstance() const { return *m_instance; } }; } // namespace fgl::engine \ No newline at end of file diff --git a/src/engine/rendering/PhysicalDevice.hpp b/src/engine/rendering/PhysicalDevice.hpp index 0dcc8de..288794f 100644 --- a/src/engine/rendering/PhysicalDevice.hpp +++ b/src/engine/rendering/PhysicalDevice.hpp @@ -35,7 +35,7 @@ namespace fgl::engine operator vk::raii::PhysicalDevice() { return m_phy_device; } - VkPhysicalDevice operator*() { return *m_phy_device; } + VkPhysicalDevice operator*() const { return *m_phy_device; } vk::raii::PhysicalDevice* operator->() { return &m_phy_device; } }; diff --git a/src/engine/rendering/QueuePool.hpp b/src/engine/rendering/QueuePool.hpp index b2544aa..1d88c61 100644 --- a/src/engine/rendering/QueuePool.hpp +++ b/src/engine/rendering/QueuePool.hpp @@ -6,8 +6,6 @@ #include #include -#include - #include "engine/FGL_DEFINES.hpp" namespace fgl::engine @@ -15,8 +13,6 @@ namespace fgl::engine class Surface; class PhysicalDevice; - class Queue; - class QueuePool { struct QueueInfo @@ -34,13 +30,10 @@ namespace fgl::engine FGL_DELETE_ALL_Ro5( QueuePool ); - Queue allocate(); - Queue allocateIndex( const std::uint32_t idx ); - using QueueIndex = std::uint32_t; //! Returns a unique list of indexes with the matching flags - QueueIndex getIndex( const vk::QueueFlags flags, const vk::QueueFlags anti_flags = vk::QueueFlags( 0 ) ); + QueueIndex getIndex( vk::QueueFlags flags, vk::QueueFlags anti_flags = vk::QueueFlags( 0 ) ); std::uint32_t getPresentIndex(); }; diff --git a/src/engine/rendering/Renderer.hpp b/src/engine/rendering/Renderer.hpp index 2ef41f3..995fcfb 100644 --- a/src/engine/rendering/Renderer.hpp +++ b/src/engine/rendering/Renderer.hpp @@ -32,13 +32,13 @@ namespace fgl::engine std::optional< TracyVkCtx > m_tracy_ctx { std::nullopt }; - void createCommandBuffers(); - void recreateSwapchain(); - uint32_t current_image_idx { std::numeric_limits< std::uint32_t >::max() }; std::uint16_t current_frame_idx { 0 }; bool is_frame_started { false }; + void createCommandBuffers(); + void recreateSwapchain(); + public: descriptors::DescriptorSet& getGBufferDescriptor( std::uint16_t frame_idx ) const diff --git a/src/engine/rendering/SwapChain.cpp b/src/engine/rendering/SwapChain.cpp index 4c56600..ee2b2e4 100644 --- a/src/engine/rendering/SwapChain.cpp +++ b/src/engine/rendering/SwapChain.cpp @@ -48,8 +48,6 @@ namespace fgl::engine != vk::Result::eSuccess ) throw std::runtime_error( "failed to wait for fences!" ); - std::uint32_t image_idx { 0 }; - auto result { swapChain.acquireNextImage( std::numeric_limits< uint64_t >::max(), imageAvailableSemaphores[ currentFrame ] // must be a not signaled semaphore diff --git a/src/engine/rendering/rendering.puml b/src/engine/rendering/rendering.puml deleted file mode 100644 index 931ec7d..0000000 --- a/src/engine/rendering/rendering.puml +++ /dev/null @@ -1,37 +0,0 @@ -@startuml -'https://plantuml.com/sequence-diagram - -participant EntityRenderer -participant TerrainRenderer - -collections GBuffer - -participant CompositeSystem - -collections GBufferComposite - -participant GuiSystem - -EntityRenderer -> GBuffer -TerrainRenderer -> GBuffer - -GBuffer -> CompositeSystem - -CompositeSystem -> GBufferComposite - -GBufferComposite -> - - - - - - - - - - - - - - -@enduml \ No newline at end of file diff --git a/src/engine/texture/Texture.cpp b/src/engine/texture/Texture.cpp index 9da1ac9..71d8614 100644 --- a/src/engine/texture/Texture.cpp +++ b/src/engine/texture/Texture.cpp @@ -114,20 +114,17 @@ namespace fgl::engine Texture::Texture( std::vector< std::byte >&& data, const vk::Extent2D extent, const vk::Format format ) : m_texture_id( getNextID() ), - m_extent( extent ) + m_extent( extent ), + m_image( std::make_shared< Image >( + extent, + format, + vk::ImageUsageFlagBits::eTransferDst | vk::ImageUsageFlagBits::eSampled, + vk::ImageLayout::eUndefined, + vk::ImageLayout::eShaderReadOnlyOptimal ) ), + m_image_view( m_image->getView() ) { - ZoneScoped; - - auto image = std::make_shared< Image >( - extent, - format, - vk::ImageUsageFlagBits::eTransferDst | vk::ImageUsageFlagBits::eSampled, - vk::ImageLayout::eUndefined, - vk::ImageLayout::eShaderReadOnlyOptimal ); - - m_image_view = image->getView(); - - memory::TransferManager::getInstance().copyToImage( std::forward< std::vector< std::byte > >( data ), *image ); + memory::TransferManager::getInstance() + .copyToImage( std::forward< std::vector< std::byte > >( data ), *m_image ); } Texture::Texture( const std::filesystem::path& path, const vk::Format format ) : diff --git a/src/engine/texture/Texture.hpp b/src/engine/texture/Texture.hpp index 0e97cb6..ff6ea63 100644 --- a/src/engine/texture/Texture.hpp +++ b/src/engine/texture/Texture.hpp @@ -51,6 +51,7 @@ namespace fgl::engine //TODO: Implement reusing texture ids TextureID m_texture_id; + std::shared_ptr< Image > m_image; std::shared_ptr< ImageView > m_image_view; vk::Extent2D m_extent; @@ -78,7 +79,10 @@ namespace fgl::engine inline static UIDKeyT extractKey( const std::filesystem::path& path ) { return path; } - inline static UIDKeyT extractKey( const std::filesystem::path& path, const vk::Format format ) { return path; } + inline static UIDKeyT extractKey( const std::filesystem::path& path, [[maybe_unused]] const vk::Format format ) + { + return path; + } Texture() = delete;