Move Primitive to it's own hpp file

This commit is contained in:
2024-02-28 03:25:49 -05:00
parent db8ad26ddc
commit a36311b2e1
4 changed files with 76 additions and 51 deletions

View File

@@ -13,13 +13,13 @@
#include <vector>
#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;

View File

@@ -5,28 +5,40 @@
#pragma once
#include <glm/vec3.hpp>
#include <tracy/Tracy.hpp>
#include <array>
#include <vector>
#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

View File

@@ -0,0 +1,53 @@
//
// Created by kj16609 on 2/28/24.
//
#pragma once
#include <cstdint>
#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

View File

@@ -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 {};