From a36311b2e1e21ccf775aff5afe98574f84b48be4 Mon Sep 17 00:00:00 2001 From: kj16609 Date: Wed, 28 Feb 2024 03:25:49 -0500 Subject: [PATCH] Move Primitive to it's own hpp file --- src/engine/model/Model.hpp | 45 +---------------- src/engine/model/OrientedBoundingBox.hpp | 25 ++++++---- src/engine/model/Primitive.hpp | 53 +++++++++++++++++++++ src/engine/systems/EntityRendererSystem.hpp | 4 ++ 4 files changed, 76 insertions(+), 51 deletions(-) create mode 100644 src/engine/model/Primitive.hpp diff --git a/src/engine/model/Model.hpp b/src/engine/model/Model.hpp index 238714f..19b095a 100644 --- a/src/engine/model/Model.hpp +++ b/src/engine/model/Model.hpp @@ -13,13 +13,13 @@ #include #include "OrientedBoundingBox.hpp" +#include "Primitive.hpp" #include "Vertex.hpp" #include "engine/Device.hpp" #include "engine/buffers/Buffer.hpp" #include "engine/buffers/BufferSuballocation.hpp" #include "engine/buffers/vector/DeviceVector.hpp" #include "engine/buffers/vector/HostVector.hpp" -#include "engine/texture/Texture.hpp" #include "engine/utils.hpp" namespace fgl::engine @@ -31,53 +31,12 @@ namespace fgl::engine std::uint32_t texture_idx; }; - using VertexBufferSuballocation = DeviceVector< Vertex >; - - using IndexBufferSuballocation = DeviceVector< std::uint32_t >; - - using DrawParameterBufferSuballocation = HostVector< vk::DrawIndexedIndirectCommand >; - - using ModelMatrixInfoBufferSuballocation = HostVector< ModelMatrixInfo >; - - struct Primitive - { - VertexBufferSuballocation m_vertex_buffer; - IndexBufferSuballocation m_index_buffer; - OrientedBoundingBox< CoordinateSpace::Model > m_bounding_box; - - std::optional< Texture > m_texture { std::nullopt }; - - Primitive( - VertexBufferSuballocation&& vertex_buffer, - IndexBufferSuballocation&& index_buffer, - OrientedBoundingBox< CoordinateSpace::Model >& bounding_box ) : - m_vertex_buffer( std::move( vertex_buffer ) ), - m_index_buffer( std::move( index_buffer ) ), - m_bounding_box( bounding_box ) - {} - - Primitive( - VertexBufferSuballocation&& vertex_buffer, - IndexBufferSuballocation&& index_buffer, - OrientedBoundingBox< CoordinateSpace::Model >& bounding_box, - Texture&& texture ) : - m_vertex_buffer( std::move( vertex_buffer ) ), - m_index_buffer( std::move( index_buffer ) ), - m_bounding_box( bounding_box ), - m_texture( std::move( texture ) ) - {} - - Primitive() = delete; - Primitive( const Primitive& other ) = delete; - Primitive( Primitive&& other ) = default; - }; - struct ModelBuilder { Buffer& m_vertex_buffer; Buffer& m_index_buffer; - std::vector< ::fgl::engine::Primitive > m_primitives {}; + std::vector< Primitive > m_primitives {}; ModelBuilder() = delete; diff --git a/src/engine/model/OrientedBoundingBox.hpp b/src/engine/model/OrientedBoundingBox.hpp index 338b668..2174380 100644 --- a/src/engine/model/OrientedBoundingBox.hpp +++ b/src/engine/model/OrientedBoundingBox.hpp @@ -5,28 +5,40 @@ #pragma once #include -#include #include #include #include "engine/constants.hpp" #include "engine/primitives/Coordinate.hpp" -#include "engine/primitives/Line.hpp" #include "engine/primitives/Matrix.hpp" +#include "engine/primitives/Rotation.hpp" namespace fgl::engine { - template < CoordinateSpace type > + template < CoordinateSpace CType > struct Frustum; + template < CoordinateSpace CType > + struct Line; + struct Vertex; template < CoordinateSpace CType > struct OrientedBoundingBox { - Coordinate< CType > middle { constants::DEFAULT_VEC3 }; - glm::vec3 scale { 0.0f }; + Coordinate< CType > middle; + glm::vec3 scale; + Rotation rotation; + + OrientedBoundingBox() : middle( constants::DEFAULT_VEC3 ), scale( 0.0f ), rotation( 0.0f, 0.0f, 0.0f ) {} + + OrientedBoundingBox( + const Coordinate< CType > pos, glm::vec3 inital_scale, const Rotation inital_rotation = {} ) : + middle( pos ), + scale( inital_scale ), + rotation( inital_rotation ) + {} //! Returns the top left (-x, -y, -z) coordinate inline glm::vec3 bottomLeftBack() const { return middle - scale; } @@ -61,9 +73,6 @@ namespace fgl::engine OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< Vertex >& points ); - template < CoordinateSpace CType > - using OBoundingBox = OrientedBoundingBox< CType >; - using ModelBoundingBox = OrientedBoundingBox< CoordinateSpace::Model >; } // namespace fgl::engine diff --git a/src/engine/model/Primitive.hpp b/src/engine/model/Primitive.hpp new file mode 100644 index 0000000..a759d24 --- /dev/null +++ b/src/engine/model/Primitive.hpp @@ -0,0 +1,53 @@ +// +// Created by kj16609 on 2/28/24. +// + +#pragma once + +#include + +#include "Vertex.hpp" +#include "engine/buffers/vector/DeviceVector.hpp" +#include "engine/texture/Texture.hpp" + +namespace fgl::engine +{ + + using VertexBufferSuballocation = DeviceVector< Vertex >; + + using IndexBufferSuballocation = DeviceVector< std::uint32_t >; + + struct Primitive + { + VertexBufferSuballocation m_vertex_buffer; + IndexBufferSuballocation m_index_buffer; + OrientedBoundingBox< CoordinateSpace::Model > m_bounding_box; + + std::optional< Texture > m_texture { std::nullopt }; + + Primitive( + VertexBufferSuballocation&& vertex_buffer, + IndexBufferSuballocation&& index_buffer, + OrientedBoundingBox< CoordinateSpace::Model >& bounding_box ) : + m_vertex_buffer( std::move( vertex_buffer ) ), + m_index_buffer( std::move( index_buffer ) ), + m_bounding_box( bounding_box ) + {} + + Primitive( + VertexBufferSuballocation&& vertex_buffer, + IndexBufferSuballocation&& index_buffer, + OrientedBoundingBox< CoordinateSpace::Model >& bounding_box, + Texture&& texture ) : + m_vertex_buffer( std::move( vertex_buffer ) ), + m_index_buffer( std::move( index_buffer ) ), + m_bounding_box( bounding_box ), + m_texture( std::move( texture ) ) + {} + + Primitive() = delete; + Primitive( const Primitive& other ) = delete; + Primitive( Primitive&& other ) = default; + }; + +} // namespace fgl::engine diff --git a/src/engine/systems/EntityRendererSystem.hpp b/src/engine/systems/EntityRendererSystem.hpp index 4f1aa5d..1ecea3f 100644 --- a/src/engine/systems/EntityRendererSystem.hpp +++ b/src/engine/systems/EntityRendererSystem.hpp @@ -31,6 +31,10 @@ namespace fgl::engine std::unique_ptr< Buffer > m_vertex_buffer { nullptr }; std::unique_ptr< Buffer > m_index_buffer { nullptr }; + using DrawParameterBufferSuballocation = HostVector< vk::DrawIndexedIndirectCommand >; + + using ModelMatrixInfoBufferSuballocation = HostVector< ModelMatrixInfo >; + std::array< std::unique_ptr< DrawParameterBufferSuballocation >, SwapChain::MAX_FRAMES_IN_FLIGHT > m_draw_parameter_buffers {};