Bunch of standard cleanup

This commit is contained in:
2024-11-01 15:34:31 -04:00
parent c8b68493d4
commit 6439b1cbf2
77 changed files with 456 additions and 438 deletions

View File

@@ -41,7 +41,7 @@ namespace fgl::engine::filesystem
current = std::make_unique< DirInfo >( test_path );
}
void destroyFileGUI()
void destroyFileGui()
{
folder_texture.reset();
file_texture.reset();
@@ -224,7 +224,7 @@ namespace fgl::engine::filesystem
ImGui::Text( data.filename.c_str() );
std::string str { toHumanByteSize( data.size ) };
const std::string str { toHumanByteSize( data.size ) };
ImGui::Text( str.c_str() );
ImGui::NextColumn();
ImGui::PopID();
@@ -260,7 +260,7 @@ namespace fgl::engine::filesystem
void FileBrowser::drawUp( const std::unique_ptr< DirInfo >& current_dir )
{
auto up { current_dir->up() };
const std::unique_ptr< DirInfo > up { current_dir->up() };
ImGui::PushID( up->m_path.c_str() );

View File

@@ -20,12 +20,12 @@ namespace fgl::engine::filesystem
static void openFolder( const DirInfo& dir );
static void drawUp( const std::unique_ptr< DirInfo >& up );
static void drawUp( const std::unique_ptr< DirInfo >& current_dir );
static void drawGui( FrameInfo& info );
static void drawFile( const FileInfo& data );
static void drawFolder( const DirInfo& data );
};
void destroyFileGUI();
void destroyFileGui();
} // namespace fgl::engine::filesystem

View File

@@ -95,7 +95,7 @@ namespace fgl::engine::gui
void drawCameraOutputs( FrameInfo& info )
{
auto& camera_list { info.m_camera_list };
const auto& camera_list { info.m_camera_list };
for ( const auto& weak_camera_ptr : camera_list )
{
if ( weak_camera_ptr.expired() ) continue;

View File

@@ -107,19 +107,19 @@ namespace fgl::engine::gui
constexpr float right_bar_size { 0.2f };
constexpr float bottom_bar_size { 0.4f };
ImGuiID lb_node {
const ImGuiID lb_node {
ImGui::DockBuilderSplitNode( primary_id, ImGuiDir_Left, left_bar_size, nullptr, &primary_id )
};
ImGuiID rb_node {
const ImGuiID rb_node {
ImGui::DockBuilderSplitNode( primary_id, ImGuiDir_Right, right_bar_size, nullptr, &primary_id )
};
ImGuiID bb_node {
const ImGuiID bb_node {
ImGui::DockBuilderSplitNode( primary_id, ImGuiDir_Down, bottom_bar_size, nullptr, &primary_id )
};
ImGuiID mv_node { primary_id };
const ImGuiID mv_node { primary_id };
//ImGuiID mv_node { ImGui::DockBuilderSplitNode( primary_id, ImGuiDir_Up, 1.0f - 0.3f, &primary_id, nullptr ) };
ImGui::DockBuilderDockWindow( OBJECT_TREE_VIEW_NAME, lb_node );
@@ -136,7 +136,7 @@ namespace fgl::engine::gui
}
// ImGui DockBuilder is still very much not ready for use.
// But let's try it anyways
// But let's try it anyway
void drawDock()
{
// ImGui::PushStyleVar( ImGuiStyleVar_WindowPadding, ImVec2( 0.0f, 0.0f ) );
@@ -297,7 +297,7 @@ namespace fgl::engine::gui
void cleanupImGui()
{
ZoneScoped;
filesystem::destroyFileGUI();
filesystem::destroyFileGui();
ImGui_ImplVulkan_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();

View File

@@ -9,7 +9,7 @@ namespace fgl::engine::gui
{
void drawObject( GameObject& game_object )
{
static std::string name_input_temp { "" };
static std::string name_input_temp {};
name_input_temp = game_object.getName();
ImGui::InputText( "Name", &name_input_temp );
if ( game_object.getName() != name_input_temp ) game_object.setName( name_input_temp );
@@ -22,23 +22,23 @@ namespace fgl::engine::gui
dragFloat3( "Scale", game_object.getScale() );
}
static GameObjectComponentPtr selected_component { nullptr };
static GameObjectComponentPtr SELECTED_COMPONENT { nullptr };
void drawComponentsList( GameObject& game_object )
{
ImGui::SeparatorText( "Components" );
for ( GameObjectComponentPtr component : game_object.getComponents() )
for ( const GameObjectComponentPtr component : game_object.getComponents() )
{
component->drawNode( selected_component );
component->drawNode( SELECTED_COMPONENT );
}
if ( selected_component )
if ( SELECTED_COMPONENT != nullptr )
{
ImGui::SeparatorText( "Selected Component" );
ImGui::PushID( ImGui::GetID( "ComponentEditor" ) );
selected_component->drawImGui();
ImGui::PushID( "ComponentEditor" );
SELECTED_COMPONENT->drawImGui();
ImGui::PopID();
}
}

View File

@@ -68,10 +68,10 @@ namespace fgl::engine::gui
if ( ImGui::TreeNode( "Device" ) )
{
ImGui::Text( "|- %s Allocated", to_string( gpu_allocated ).c_str() );
ImGui::Text( "|- %s Used ", to_string( gpu_used ).c_str() );
ImGui::Text( "|- %s Unused", to_string( gpu.free() ).c_str() );
ImGui::Text( "|- %s Available in most allocated buffer", to_string( gpu.m_largest_free_block ).c_str() );
ImGui::Text( "|- %s Allocated", toString( gpu_allocated ).c_str() );
ImGui::Text( "|- %s Used ", toString( gpu_used ).c_str() );
ImGui::Text( "|- %s Unused", toString( gpu.free() ).c_str() );
ImGui::Text( "|- %s Available in most allocated buffer", toString( gpu.m_largest_free_block ).c_str() );
ImGui::TreePop();
}
@@ -79,10 +79,10 @@ namespace fgl::engine::gui
if ( ImGui::TreeNode( "Host" ) )
{
ImGui::Text( "|- %s Allocated", to_string( host_allocated ).c_str() );
ImGui::Text( "|- %s Used ", to_string( host_used ).c_str() );
ImGui::Text( "|- %s Unused", to_string( host.free() ).c_str() );
ImGui::Text( "|- %s Available in most allocated buffer", to_string( host.m_largest_free_block ).c_str() );
ImGui::Text( "|- %s Allocated", toString( host_allocated ).c_str() );
ImGui::Text( "|- %s Used ", toString( host_used ).c_str() );
ImGui::Text( "|- %s Unused", toString( host.free() ).c_str() );
ImGui::Text( "|- %s Available in most allocated buffer", toString( host.m_largest_free_block ).c_str() );
ImGui::TreePop();
}
ImGui::Separator();
@@ -94,10 +94,10 @@ namespace fgl::engine::gui
ImGui::Text( "Name: %s", buffer->m_debug_name.c_str() );
ImGui::Text(
"Allocated: %s/%s (%2.1f\%)",
to_string( buffer->used() ).c_str(),
to_string( buffer->size() ).c_str(),
toString( buffer->used() ).c_str(),
toString( buffer->size() ).c_str(),
( static_cast< float >( buffer->used() ) / static_cast< float >( buffer->size() ) * 100.0f ) );
ImGui::Text( "Largest block: %s", to_string( buffer->largestBlock() ).c_str() );
ImGui::Text( "Largest block: %s", toString( buffer->largestBlock() ).c_str() );
ImGui::Separator();
}
}
@@ -109,9 +109,9 @@ namespace fgl::engine::gui
ImGui::Text( "FPS: %0.1f", ImGui::GetIO().Framerate );
const auto& counters { profiling::getCounters() };
ImGui::Text( "Models drawn: %zu", counters.models_draw );
ImGui::Text( "Verts drawn: %zu", counters.verts_drawn );
ImGui::Text( "Draw instances: %zu", counters.instance_count );
ImGui::Text( "Models drawn: %zu", counters.m_models_draw );
ImGui::Text( "Verts drawn: %zu", counters.m_verts_drawn );
ImGui::Text( "Draw instances: %zu", counters.m_instance_count );
if ( ImGui::CollapsingHeader( "Memory" ) )
{

View File

@@ -53,7 +53,7 @@ namespace fgl::engine::gui
obj.addFlag( IS_ENTITY | IS_VISIBLE );
std::unique_ptr< ModelComponent > component {
auto component {
std::make_unique< ModelComponent >( std::move( model ) )
};
@@ -208,16 +208,16 @@ namespace fgl::engine::gui
default:
[[fallthrough]];
case Composite:
camera.getSwapchain().g_buffer_composite_img[ frame_index ]->drawImGui( target_size );
camera.getSwapchain().m_g_buffer_composite_img[ frame_index ]->drawImGui( target_size );
break;
case Albedo:
camera.getSwapchain().g_buffer_color_img[ frame_index ]->drawImGui( target_size );
camera.getSwapchain().m_g_buffer_color_img[ frame_index ]->drawImGui( target_size );
break;
case Normal:
camera.getSwapchain().g_buffer_normal_img[ frame_index ]->drawImGui( target_size );
camera.getSwapchain().m_g_buffer_normal_img[ frame_index ]->drawImGui( target_size );
break;
case Position:
camera.getSwapchain().g_buffer_position_img[ frame_index ]->drawImGui( target_size );
camera.getSwapchain().m_g_buffer_position_img[ frame_index ]->drawImGui( target_size );
break;
}

View File

@@ -2,6 +2,9 @@
// Created by kj16609 on 6/5/24.
//
// ReSharper disable CppDFAInfiniteRecursion
// ReSharper disable CppInconsistentNaming
// ReSharper disable CppZeroConstantCanBeReplacedWithNullptr
#pragma once
#pragma GCC diagnostic push
@@ -22,7 +25,7 @@ namespace ImGui
{
//void ImGui::DockBuilderDockWindow(const char* window_name, ImGuiID node_id)
FGL_FORCE_INLINE inline void DockBuilderDockWindow( const std::string_view str, ImGuiID node_id )
FGL_FORCE_INLINE inline void DockBuilderDockWindow( const std::string_view str, const ImGuiID node_id )
{
::ImGui::DockBuilderDockWindow( str.data(), node_id );
}
@@ -42,14 +45,17 @@ namespace ImGui
// IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated.
FGL_FORCE_INLINE inline bool MenuItem(
const std::string_view label, const char* shortcut = NULL, bool selected = false, bool enabled = true )
const std::string_view label,
const char* shortcut = NULL,
const bool selected = false,
const bool enabled = true )
{
return ::ImGui::MenuItem( label.data(), shortcut, selected, enabled );
}
// IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL
FGL_FORCE_INLINE inline bool
MenuItem( const std::string_view label, const char* shortcut, bool* selected, bool enabled = true )
MenuItem( const std::string_view label, const char* shortcut, bool* selected, const bool enabled = true )
{
return ::ImGui::MenuItem( label.data(), shortcut, selected, enabled );
}

View File

@@ -111,7 +111,7 @@ namespace fgl::engine
{
ZoneScoped;
// Get delta time
const auto now { fgl::clock::now() };
const auto now { fgl::Clock::now() };
const std::chrono::duration< double, std::chrono::seconds::period > time_diff { now - last_tick };
last_tick = now;

View File

@@ -83,7 +83,7 @@ namespace fgl::engine
CameraManager m_camera_manager {};
std::chrono::time_point< fgl::clock > last_tick { fgl::clock::now() };
std::chrono::time_point< fgl::Clock > last_tick { fgl::Clock::now() };
double m_delta_time;
public:

View File

@@ -11,7 +11,7 @@
#define FGL_DELETE_MOVE_CTOR( ClassName ) ClassName( ClassName&& ) = delete;
#define FGL_DELETE_COPY( ClassName ) FGL_DELETE_COPY_CTOR( ClassName ) FGL_DELETE_COPY_ASSIGN( ClassName )
#define FGL_DELETE_MOVE( ClassName ) FGL_DELETE_MOVE_CTOR( ClassName ) FGL_DELETE_MOVE_ASSIGN( ClassName )
#define FGL_DELETE_ALL_Ro5( ClassName ) \
#define FGL_DELETE_ALL_RO5( ClassName ) \
FGL_DELETE_DEFAULT_CTOR( ClassName ) FGL_DELETE_COPY( ClassName ) FGL_DELETE_MOVE( ClassName )
#define FGL_DEFAULT_DEFAULT_CTOR( ClassName ) ClassName() = default;
@@ -21,7 +21,7 @@
#define FGL_DEFAULT_MOVE_CTOR( ClassName ) ClassName( ClassName&& ) = default;
#define FGL_DEFAULT_COPY( ClassName ) FGL_DEFAULT_COPY_CTOR( ClassName ) FGL_DEFAULT_COPY_ASSIGN( ClassName )
#define FGL_DEFAULT_MOVE( ClassName ) FGL_DEFAULT_MOVE_CTOR( ClassName ) FGL_DEFAULT_MOVE_ASSIGN( ClassName )
#define FGL_DEFAULT_ALL_Ro5( ClassName ) \
#define FGL_DEFAULT_ALL_RO5( ClassName ) \
FGL_DEFAULT_DEFAULT_CTOR( ClassName ) FGL_DEFAULT_COPY( ClassName ) FGL_DEFAULT_MOVE( ClassName )
#define FGL_PACKED __attribute__( ( packed ) )

View File

@@ -8,11 +8,11 @@
namespace fgl::engine
{
inline static TextureStore tex_store {};
inline static TextureStore TEX_STORE {};
TextureStore& getTextureStore()
{
return tex_store;
return TEX_STORE;
}
} // namespace fgl::engine

View File

@@ -39,7 +39,7 @@ namespace fgl::engine
public:
FGL_DELETE_ALL_Ro5( ImageHandle );
FGL_DELETE_ALL_RO5( ImageHandle );
ImageHandle( vk::Extent2D extent, vk::Format format, vk::Image image, vk::ImageUsageFlags usage ) noexcept;

View File

@@ -253,7 +253,7 @@ namespace fgl::engine::memory
{
log::info(
"Transfer manager created with a buffer size of {}",
fgl::literals::size_literals::to_string( buffer_size ) );
fgl::literals::size_literals::toString( buffer_size ) );
global_transfer_manager = std::make_unique< TransferManager >( device, buffer_size );
}

View File

@@ -80,7 +80,7 @@ namespace fgl::engine::memory
TransferManager( Device& device, std::uint64_t buffer_size );
FGL_DELETE_ALL_Ro5( TransferManager );
FGL_DELETE_ALL_RO5( TransferManager );
vk::raii::Semaphore& getFinishedSem() { return transfer_semaphore; }

View File

@@ -18,13 +18,13 @@ namespace fgl::engine
Matrix< MatrixType::WorldToScreen > Camera::getProjectionViewMatrix() const
{
assert( projection_matrix != constants::MAT4_IDENTITY );
return projection_matrix * view_matrix;
assert( m_projection_matrix != constants::MAT4_IDENTITY );
return m_projection_matrix * m_view_matrix;
}
void Camera::setOrthographicProjection( float left, float right, float top, float bottom, float near, float far )
{
projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::ortho( left, right, bottom, top, near, far ) );
m_projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::ortho( left, right, bottom, top, near, far ) );
//TODO: Figure out frustum culling for orthographic projection. (If we even wanna use it)
}
@@ -32,15 +32,15 @@ namespace fgl::engine
FGL_FLATTEN_HOT void Camera::
setPerspectiveProjection( const float fovy, const float aspect, const float near, const float far )
{
projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspective( fovy, aspect, near, far ) );
m_projection_matrix = Matrix< MatrixType::CameraToScreen >( glm::perspective( fovy, aspect, near, far ) );
base_frustum = createFrustum( aspect, fovy, near, far );
m_base_frustum = createFrustum( aspect, fovy, near, far );
}
Coordinate< CoordinateSpace::World > Camera::getPosition() const
{
//Should maybe store the inverse view matrix
return WorldCoordinate( inverse_view_matrix[ 3 ] );
return WorldCoordinate( m_inverse_view_matrix[ 3 ] );
}
void Camera::updateInfo( const FrameIndex frame_index )
@@ -132,7 +132,7 @@ namespace fgl::engine
void Camera::setName( const std::string_view str )
{
name = str;
m_name = str;
}
float Camera::aspectRatio() const
@@ -262,9 +262,9 @@ namespace fgl::engine
const WorldCoordinate center_pos { pos + forward };
view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAt( pos.vec(), center_pos.vec(), camera_up ) );
m_view_matrix = Matrix< MatrixType::WorldToCamera >( glm::lookAt( pos.vec(), center_pos.vec(), camera_up ) );
inverse_view_matrix = glm::inverse( view_matrix );
m_inverse_view_matrix = glm::inverse( m_view_matrix );
updateFrustum();
}
@@ -295,16 +295,16 @@ namespace fgl::engine
void Camera::updateFrustum()
{
last_frustum_pos = getPosition();
m_last_frustum_pos = getPosition();
const Matrix< MatrixType::ModelToWorld > translation_matrix { frustumTranslationMatrix() };
frustum = translation_matrix * base_frustum;
m_frustum = translation_matrix * m_base_frustum;
}
const std::string& Camera::getName() const
{
return name;
return m_name;
}
constexpr descriptors::Descriptor camera_descriptor { 0,
@@ -324,7 +324,7 @@ namespace fgl::engine
m_target_extent( extent ),
m_camera_frame_info( buffer, SwapChain::MAX_FRAMES_IN_FLIGHT ),
m_swapchain( std::make_shared< CameraSwapchain >( m_camera_renderer->getRenderpass(), m_target_extent ) ),
name()
m_name()
{
this->setPerspectiveProjection( m_fov_y, aspectRatio(), constants::NEAR_PLANE, constants::FAR_PLANE );
this->setView( WorldCoordinate( constants::CENTER ), Rotation( 0.0f, 0.0f, 0.0f ) );
@@ -400,7 +400,7 @@ namespace fgl::engine
WorldCoordinate Camera::getFrustumPosition() const
{
return last_frustum_pos;
return m_last_frustum_pos;
}
Camera::~Camera()
@@ -408,7 +408,7 @@ namespace fgl::engine
CameraIDX Camera::getIDX() const
{
return camera_idx;
return m_camera_idx;
}
} // namespace fgl::engine

View File

@@ -46,7 +46,7 @@ namespace fgl::engine
class Camera
{
inline static CameraIDX camera_counter { 0 };
inline static CameraIDX m_camera_counter { 0 };
std::unique_ptr< CameraRenderer >& m_camera_renderer;
@@ -58,18 +58,18 @@ namespace fgl::engine
bool m_cold { false };
// Const is acceptable, Since this value should never change. EVER
const CameraIDX camera_idx { camera_counter++ };
const CameraIDX m_camera_idx { m_camera_counter++ };
Matrix< MatrixType::CameraToScreen > projection_matrix { 1.0f };
Matrix< MatrixType::CameraToScreen > m_projection_matrix { 1.0f };
Matrix< MatrixType::WorldToCamera > view_matrix { 1.0f };
glm::mat4 inverse_view_matrix { 1.0f };
Matrix< MatrixType::WorldToCamera > m_view_matrix { 1.0f };
glm::mat4 m_inverse_view_matrix { 1.0f };
//! Frustum of the camera in model space relative to the camera
//! @note Must be transformed by the inverse view matrix to get the frustum in world space
FrustumBase base_frustum {};
Frustum frustum {};
WorldCoordinate last_frustum_pos { constants::WORLD_CENTER };
FrustumBase m_base_frustum {};
Frustum m_frustum {};
WorldCoordinate m_last_frustum_pos { constants::WORLD_CENTER };
WorldTransform m_transform;
@@ -85,7 +85,7 @@ namespace fgl::engine
std::shared_ptr< CameraSwapchain > m_old_swapchain { nullptr };
std::shared_ptr< CameraSwapchain > m_swapchain;
std::string name;
std::string m_name;
Matrix< MatrixType::ModelToWorld > frustumTranslationMatrix() const;
@@ -106,7 +106,7 @@ namespace fgl::engine
float& y { m_transform.translation.y };
float& z { m_transform.translation.z };
FGL_DELETE_ALL_Ro5( Camera );
FGL_DELETE_ALL_RO5( Camera );
~Camera();
@@ -128,18 +128,18 @@ namespace fgl::engine
WorldCoordinate getFrustumPosition() const;
const FrustumBase& getBaseFrustum() const { return base_frustum; }
const FrustumBase& getBaseFrustum() const { return m_base_frustum; }
//! Returns the frustum of the camera in world space
const Frustum& getFrustumBounds() const { return frustum; }
const Frustum& getFrustumBounds() const { return m_frustum; }
const Matrix< MatrixType::CameraToScreen >& getProjectionMatrix() const { return projection_matrix; }
const Matrix< MatrixType::CameraToScreen >& getProjectionMatrix() const { return m_projection_matrix; }
const Matrix< MatrixType::WorldToCamera >& getViewMatrix() const { return view_matrix; }
const Matrix< MatrixType::WorldToCamera >& getViewMatrix() const { return m_view_matrix; }
Matrix< MatrixType::WorldToScreen > getProjectionViewMatrix() const;
glm::mat4 getInverseViewMatrix() const { return glm::inverse( view_matrix ); }
glm::mat4 getInverseViewMatrix() const { return glm::inverse( m_view_matrix ); }
enum ViewMode
{
@@ -155,18 +155,23 @@ namespace fgl::engine
FGL_FORCE_INLINE NormalVector getUp() const { return -getDown(); }
FGL_FORCE_INLINE NormalVector getRight() const { return NormalVector( glm::vec3( inverse_view_matrix[ 0 ] ) ); }
FGL_FORCE_INLINE NormalVector getRight() const
{
return NormalVector( glm::vec3( m_inverse_view_matrix[ 0 ] ) );
}
FGL_FORCE_INLINE NormalVector getForward() const
{
return -NormalVector( glm::vec3( inverse_view_matrix[ 2 ] ) );
return -NormalVector( glm::vec3( m_inverse_view_matrix[ 2 ] ) );
}
FGL_FORCE_INLINE NormalVector getLeft() const { return -getRight(); }
FGL_FORCE_INLINE NormalVector getBackward() const { return -getForward(); }
FGL_FORCE_INLINE NormalVector getDown() const { return NormalVector( glm::vec3( inverse_view_matrix[ 1 ] ) ); }
FGL_FORCE_INLINE NormalVector getDown() const
{
return NormalVector( glm::vec3( m_inverse_view_matrix[ 1 ] ) ); }
//! Updates the required info for rendering
void updateInfo( FrameIndex frame_index );

View File

@@ -20,53 +20,53 @@ namespace fgl::engine
// Set formats for each item in the swapchain
//XYZ in world space
auto position { builder.attachment( PositionIndex ) };
auto position { builder.attachment( POSITION_INDEX ) };
position.setFormat( vk::Format::eR16G16B16A16Sfloat ); // position
position.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal );
position.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
//RGBA
auto normal { builder.attachment( NormalIndex ) };
auto normal { builder.attachment( NORMAL_INDEX ) };
normal.setFormat( vk::Format::eR16G16B16A16Sfloat ); // normal
normal.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal );
normal.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
// RGBA
auto color { builder.attachment( ColorIndex ) };
auto color { builder.attachment( COLOR_INDEX ) };
color.setFormat( vk::Format::eR8G8B8A8Unorm ); // color
color.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal );
color.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
// Metallic, Roughness, Occlusion
auto metallic_roughness { builder.attachment( MetallicIndex ) };
auto metallic_roughness { builder.attachment( METALLIC_INDEX ) };
metallic_roughness.setFormat( vk::Format::eR16G16B16A16Sfloat );
metallic_roughness.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal );
metallic_roughness.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
// RGB
auto emissive { builder.attachment( EmissiveIndex ) };
auto emissive { builder.attachment( EMISSIVE_INDEX ) };
emissive.setFormat( vk::Format::eR16G16B16A16Sfloat );
emissive.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal );
emissive.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
auto composite { builder.attachment( CompositeIndex ) };
auto composite { builder.attachment( COMPOSITE_INDEX ) };
//TODO: For HDR I think this needs to be a bigger range then 8bits per channel.
composite.setFormat( vk::Format::eR8G8B8A8Unorm ); // composite
composite.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eShaderReadOnlyOptimal );
composite.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
auto depth { builder.attachment( DepthIndex ) };
auto depth { builder.attachment( DEPTH_INDEX ) };
depth.setLayouts( vk::ImageLayout::eUndefined, vk::ImageLayout::eDepthStencilReadOnlyOptimal );
depth.setFormat( SwapChain::findDepthFormat() ); // depth
depth.setOps( vk::AttachmentLoadOp::eClear, vk::AttachmentStoreOp::eStore );
auto& g_buffer_subpass { builder.createSubpass( 0 ) };
g_buffer_subpass.setDepthLayout( DepthIndex, vk::ImageLayout::eDepthStencilAttachmentOptimal );
g_buffer_subpass.addRenderLayout( ColorIndex, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( PositionIndex, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( NormalIndex, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( MetallicIndex, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( EmissiveIndex, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.setDepthLayout( DEPTH_INDEX, vk::ImageLayout::eDepthStencilAttachmentOptimal );
g_buffer_subpass.addRenderLayout( COLOR_INDEX, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( POSITION_INDEX, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( NORMAL_INDEX, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( METALLIC_INDEX, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addRenderLayout( EMISSIVE_INDEX, vk::ImageLayout::eColorAttachmentOptimal );
g_buffer_subpass.addDependencyFromExternal(
vk::AccessFlagBits::eDepthStencilAttachmentWrite,
@@ -76,12 +76,12 @@ namespace fgl::engine
vk::AccessFlagBits::eColorAttachmentWrite, vk::PipelineStageFlagBits::eColorAttachmentOutput );
auto& composite_subpass { builder.createSubpass( 1 ) };
composite_subpass.addRenderLayout( CompositeIndex, vk::ImageLayout::eColorAttachmentOptimal );
composite_subpass.addInputLayout( ColorIndex, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( PositionIndex, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( NormalIndex, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( MetallicIndex, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( EmissiveIndex, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addRenderLayout( COMPOSITE_INDEX, vk::ImageLayout::eColorAttachmentOptimal );
composite_subpass.addInputLayout( COLOR_INDEX, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( POSITION_INDEX, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( NORMAL_INDEX, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( METALLIC_INDEX, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addInputLayout( EMISSIVE_INDEX, vk::ImageLayout::eShaderReadOnlyOptimal );
composite_subpass.addDependency(
g_buffer_subpass,

View File

@@ -19,15 +19,15 @@ namespace fgl::engine
//auto set { std::make_unique< descriptors::DescriptorSet >( GBufferDescriptorSet::createLayout() ) };
auto set { gbuffer_set.create() };
set->bindAttachment( 0, gbuffer.color.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 0, m_gbuffer.m_color.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 1, gbuffer.position.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 1, m_gbuffer.m_position.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 2, gbuffer.normal.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 2, m_gbuffer.m_normal.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 3, gbuffer.metallic.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 3, m_gbuffer.m_metallic.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 4, gbuffer.emissive.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->bindAttachment( 4, m_gbuffer.m_emissive.getView( i ), vk::ImageLayout::eShaderReadOnlyOptimal );
set->update();
@@ -47,15 +47,15 @@ namespace fgl::engine
{
constexpr auto image_count { SwapChain::MAX_FRAMES_IN_FLIGHT };
gbuffer.color.createResources( image_count, m_extent );
gbuffer.position.createResources( image_count, m_extent );
gbuffer.normal.createResources( image_count, m_extent );
gbuffer.metallic.createResources( image_count, m_extent );
gbuffer.emissive.createResources( image_count, m_extent );
m_gbuffer.m_color.createResources( image_count, m_extent );
m_gbuffer.m_position.createResources( image_count, m_extent );
m_gbuffer.m_normal.createResources( image_count, m_extent );
m_gbuffer.m_metallic.createResources( image_count, m_extent );
m_gbuffer.m_emissive.createResources( image_count, m_extent );
gbuffer.composite.createResources( image_count, m_extent, vk::ImageUsageFlagBits::eTransferSrc );
gbuffer.depth.createResources( image_count, m_extent );
gbuffer.depth.setClear( vk::ClearDepthStencilValue( 1.0f, 0 ) );
m_gbuffer.m_composite.createResources( image_count, m_extent, vk::ImageUsageFlagBits::eTransferSrc );
m_gbuffer.m_depth.createResources( image_count, m_extent );
m_gbuffer.m_depth.setClear( vk::ClearDepthStencilValue( 1.0f, 0 ) );
std::vector< vk::raii::Framebuffer > buffers {};
buffers.reserve( image_count );
@@ -64,13 +64,13 @@ namespace fgl::engine
{
std::vector< vk::ImageView > attachments { getViewsForFrame(
i,
gbuffer.color,
gbuffer.position,
gbuffer.normal,
gbuffer.metallic,
gbuffer.emissive,
gbuffer.composite,
gbuffer.depth ) };
m_gbuffer.m_color,
m_gbuffer.m_position,
m_gbuffer.m_normal,
m_gbuffer.m_metallic,
m_gbuffer.m_emissive,
m_gbuffer.m_composite,
m_gbuffer.m_depth ) };
vk::FramebufferCreateInfo info {};
info.renderPass = m_renderpass;
@@ -81,30 +81,30 @@ namespace fgl::engine
buffers.emplace_back( Device::getInstance()->createFramebuffer( info ) );
g_buffer_color_img.emplace_back( std::make_unique< Texture >( gbuffer.color.m_attachment_resources
m_g_buffer_color_img.emplace_back( std::make_unique< Texture >( m_gbuffer.m_color.m_attachment_resources
.m_images[ i ]
->setName( "GBufferColor" ) ) );
auto& position_resources { gbuffer.position.m_attachment_resources };
auto& position_resources { m_gbuffer.m_position.m_attachment_resources };
assert( position_resources.m_images[ i ] );
assert( position_resources.m_image_views[ i ] );
auto& position_image { *position_resources.m_images[ i ] };
position_image.setName( format_ns::format( "GBufferPosition: {}", i ) );
g_buffer_position_img.emplace_back( std::make_unique< Texture >( position_image ) );
m_g_buffer_position_img.emplace_back( std::make_unique< Texture >( position_image ) );
g_buffer_normal_img.emplace_back( std::make_unique< Texture >( gbuffer.normal.m_attachment_resources
m_g_buffer_normal_img.emplace_back( std::make_unique< Texture >( m_gbuffer.m_normal.m_attachment_resources
.m_images[ i ]
->setName( "GBufferNormal" ) ) );
g_buffer_metallic_img.emplace_back( std::make_unique< Texture >( gbuffer.metallic.m_attachment_resources
m_g_buffer_metallic_img.emplace_back( std::make_unique< Texture >( m_gbuffer.m_metallic.m_attachment_resources
.m_images[ i ]
->setName( "GBufferMetallic" ) ) );
g_buffer_emissive_img.emplace_back( std::make_unique< Texture >( gbuffer.emissive.m_attachment_resources
m_g_buffer_emissive_img.emplace_back( std::make_unique< Texture >( m_gbuffer.m_emissive.m_attachment_resources
.m_images[ i ]
->setName( "GBufferEmissive" ) ) );
g_buffer_composite_img.emplace_back( std::make_unique< Texture >( gbuffer.composite.m_attachment_resources
m_g_buffer_composite_img.emplace_back( std::make_unique< Texture >( m_gbuffer.m_composite.m_attachment_resources
.m_images[ i ]
->setName( "GBufferComposite" ) ) );
}
@@ -129,8 +129,8 @@ namespace fgl::engine
Image& CameraSwapchain::getOutput( const FrameIndex index )
{
assert( index <= this->gbuffer.composite.m_attachment_resources.m_images.size() );
return *gbuffer.composite.m_attachment_resources.m_images[ index ];
assert( index <= this->m_gbuffer.m_composite.m_attachment_resources.m_images.size() );
return *m_gbuffer.m_composite.m_attachment_resources.m_images[ index ];
}
float CameraSwapchain::getAspectRatio()
@@ -143,16 +143,16 @@ namespace fgl::engine
m_renderpass( renderpass ),
m_framebuffers( createFrambuffers() ),
m_clear_values( gatherClearValues(
gbuffer.color,
gbuffer.position,
gbuffer.normal,
gbuffer.metallic,
gbuffer.emissive,
gbuffer.composite,
gbuffer.depth ) ),
m_gbuffer.m_color,
m_gbuffer.m_position,
m_gbuffer.m_normal,
m_gbuffer.m_metallic,
m_gbuffer.m_emissive,
m_gbuffer.m_composite,
m_gbuffer.m_depth ) ),
m_gbuffer_descriptor_set( createGBufferDescriptors() )
{
gbuffer.depth.setName( "Depth" );
m_gbuffer.m_depth.setName( "Depth" );
}
CameraSwapchain::~CameraSwapchain()

View File

@@ -11,38 +11,38 @@
namespace fgl::engine
{
constexpr std::size_t ColorIndex { 0 };
constexpr std::size_t PositionIndex { 1 };
constexpr std::size_t NormalIndex { 2 };
constexpr std::size_t MetallicIndex { 3 };
constexpr std::size_t EmissiveIndex { 4 };
constexpr std::size_t COLOR_INDEX { 0 };
constexpr std::size_t POSITION_INDEX { 1 };
constexpr std::size_t NORMAL_INDEX { 2 };
constexpr std::size_t METALLIC_INDEX { 3 };
constexpr std::size_t EMISSIVE_INDEX { 4 };
constexpr std::size_t CompositeIndex { 5 };
constexpr std::size_t DepthIndex { 6 };
constexpr std::size_t COMPOSITE_INDEX { 5 };
constexpr std::size_t DEPTH_INDEX { 6 };
class CameraSwapchain
{
struct
{
ColorAttachment< ColorIndex > color { vk::Format::eR8G8B8A8Unorm };
ColorAttachment< PositionIndex > position { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< NormalIndex > normal { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< MetallicIndex > metallic { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< EmissiveIndex > emissive { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< COLOR_INDEX > m_color { vk::Format::eR8G8B8A8Unorm };
ColorAttachment< POSITION_INDEX > m_position { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< NORMAL_INDEX > m_normal { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< METALLIC_INDEX > m_metallic { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< EMISSIVE_INDEX > m_emissive { vk::Format::eR16G16B16A16Sfloat };
ColorAttachment< CompositeIndex > composite { vk::Format::eR8G8B8A8Unorm };
DepthAttachment< DepthIndex > depth { SwapChain::findDepthFormat() };
} gbuffer {};
ColorAttachment< COMPOSITE_INDEX > m_composite { vk::Format::eR8G8B8A8Unorm };
DepthAttachment< DEPTH_INDEX > m_depth { SwapChain::findDepthFormat() };
} m_gbuffer {};
public:
std::vector< std::unique_ptr< Texture > > g_buffer_color_img {};
std::vector< std::unique_ptr< Texture > > g_buffer_position_img {};
std::vector< std::unique_ptr< Texture > > g_buffer_normal_img {};
std::vector< std::unique_ptr< Texture > > g_buffer_metallic_img {};
std::vector< std::unique_ptr< Texture > > g_buffer_emissive_img {};
std::vector< std::unique_ptr< Texture > > m_g_buffer_color_img {};
std::vector< std::unique_ptr< Texture > > m_g_buffer_position_img {};
std::vector< std::unique_ptr< Texture > > m_g_buffer_normal_img {};
std::vector< std::unique_ptr< Texture > > m_g_buffer_metallic_img {};
std::vector< std::unique_ptr< Texture > > m_g_buffer_emissive_img {};
std::vector< std::unique_ptr< Texture > > g_buffer_composite_img {};
std::vector< std::unique_ptr< Texture > > m_g_buffer_composite_img {};
private:

View File

@@ -9,11 +9,11 @@
namespace fgl
{
using clock = std::conditional_t<
using Clock = std::conditional_t<
std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock,
std::chrono::steady_clock >;
using profiling_clock = std::chrono::high_resolution_clock;
using ProfilingClock = std::chrono::high_resolution_clock;
} // namespace fgl

View File

@@ -30,7 +30,7 @@ auto format_ns::formatter< std::filesystem::path >::format( const std::filesyste
}
}
auto format_ns::formatter< std::source_location >::format( const std::source_location& loc, format_context& ctx ) const
auto format_ns::formatter< std::source_location >::format( const std::source_location& loc, format_context& ctx )
-> decltype( ctx.out() )
{
return format_ns::

View File

@@ -43,15 +43,15 @@ struct format_ns::formatter< std::filesystem::path >
template <>
struct format_ns::formatter< std::source_location >
{
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
static constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const std::source_location& loc, format_context& ctx ) const;
static format_context::iterator format( const std::source_location& loc, format_context& ctx );
};
template <>
struct format_ns::formatter< format_ns::format_string<> >
{
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
static constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const format_ns::format_string<>& str, format_context& ctx ) const;
};

View File

@@ -11,7 +11,7 @@
template <>
struct std::formatter< glm::quat >
{
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
static constexpr format_parse_context::iterator parse( const format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const glm::quat& quat, format_context& ctx ) const;
};

View File

@@ -10,7 +10,7 @@
template <>
struct std::formatter< glm::vec4 >
{
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
static constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const glm::vec4& vec, format_context& ctx ) const;
};
@@ -18,7 +18,7 @@ struct std::formatter< glm::vec4 >
template <>
struct std::formatter< glm::vec3 >
{
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
static constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const glm::vec3& vec, format_context& ctx ) const;
};
@@ -26,7 +26,7 @@ struct std::formatter< glm::vec3 >
template <>
struct std::formatter< glm::mat4 >
{
constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
static constexpr format_parse_context::iterator parse( format_parse_context& ctx ) { return ctx.begin(); }
format_context::iterator format( const glm::mat4& mat, format_context& ctx ) const;
};

View File

@@ -9,33 +9,33 @@
namespace fgl::engine::profiling
{
inline static Counters counters;
inline static Counters COUNTERS;
Counters& getCounters()
{
return counters;
return COUNTERS;
}
void addModelDrawn( std::size_t n )
{
counters.models_draw += n;
COUNTERS.m_models_draw += n;
}
void addVertexDrawn( std::size_t n )
{
counters.verts_drawn += n;
COUNTERS.m_verts_drawn += n;
}
void addInstances( std::size_t n )
{
counters.instance_count += n;
COUNTERS.m_instance_count += n;
}
void resetCounters()
{
counters.verts_drawn = 0;
counters.models_draw = 0;
counters.instance_count = 0;
COUNTERS.m_verts_drawn = 0;
COUNTERS.m_models_draw = 0;
COUNTERS.m_instance_count = 0;
}
// In order for resetCounters to work we need to ensure we can just zero the struct.

View File

@@ -10,9 +10,9 @@ namespace fgl::engine::profiling
{
struct Counters
{
std::size_t verts_drawn;
std::size_t models_draw;
std::size_t instance_count;
std::size_t m_verts_drawn;
std::size_t m_models_draw;
std::size_t m_instance_count;
};
Counters& getCounters();

View File

@@ -16,21 +16,21 @@ namespace fgl::engine::debug
struct Node
{
std::string_view name { "" };
profiling_clock::time_point start {};
profiling_clock::time_point end {};
std::vector< Node > children {};
Node* parent { nullptr };
std::string_view m_name { "" };
ProfilingClock::time_point m_start {};
ProfilingClock::time_point m_end {};
std::vector< Node > m_children {};
Node* m_parent { nullptr };
void drawImGui() const;
using duration = profiling_clock::duration;
using duration = ProfilingClock::duration;
duration getDuration() const { return end - start; }
duration getDuration() const { return m_end - m_start; }
duration getTotalTime() const
{
if ( parent != nullptr )
return parent->getTotalTime();
if ( m_parent != nullptr )
return m_parent->getTotalTime();
else
return getDuration();
}
@@ -40,25 +40,25 @@ namespace fgl::engine::debug
FGL_DELETE_COPY( Node );
Node( Node&& other ) :
name( std::move( other.name ) ),
start( other.start ),
end( other.end ),
children( std::move( other.children ) ),
parent( other.parent )
m_name( std::move( other.m_name ) ),
m_start( other.m_start ),
m_end( other.m_end ),
m_children( std::move( other.m_children ) ),
m_parent( other.m_parent )
{
for ( auto& child : children ) child.parent = this;
for ( auto& child : m_children ) child.m_parent = this;
}
Node& operator=( Node&& other ) noexcept
{
name = std::move( other.name );
start = other.start;
end = other.end;
children = std::move( other.children );
m_name = std::move( other.m_name );
m_start = other.m_start;
m_end = other.m_end;
m_children = std::move( other.m_children );
for ( auto& child : children ) child.parent = this;
for ( auto& child : m_children ) child.m_parent = this;
parent = other.parent;
m_parent = other.m_parent;
return *this;
}
};
@@ -68,9 +68,9 @@ namespace fgl::engine::debug
void Node::drawImGui() const
{
const auto diff { end - start };
const auto diff { m_end - m_start };
FGL_ASSERT( end > start, "Node ended before it began!" );
FGL_ASSERT( m_end > m_start, "Node ended before it began!" );
const auto time { getDuration() };
@@ -83,25 +83,25 @@ namespace fgl::engine::debug
const auto total_time { getTotalTime() };
percent = ( static_cast< double >( time.count() ) / static_cast< double >( total_time.count() ) ) * 100.0f;
}
else if ( parent )
else if ( m_parent )
{
const auto parent_time { this->parent->getDuration() };
const auto parent_time { this->m_parent->getDuration() };
percent = ( static_cast< double >( time.count() ) / static_cast< double >( parent_time.count() ) ) * 100.0f;
}
const std::string str { std::format(
"{} -- {:2.2f}ms, ({:2.2f}%)",
name,
m_name,
( std::chrono::duration_cast< std::chrono::microseconds >( diff ).count() / 1000.0f ),
percent ) };
ImGuiTreeNodeFlags flags { ImGuiTreeNodeFlags_None };
if ( children.empty() ) flags |= ImGuiTreeNodeFlags_Leaf;
if ( m_children.empty() ) flags |= ImGuiTreeNodeFlags_Leaf;
if ( ImGui::TreeNodeEx( name.data(), flags, str.c_str() ) )
if ( ImGui::TreeNodeEx( m_name.data(), flags, str.c_str() ) )
{
for ( const auto& child : children ) child.drawImGui();
for ( const auto& child : m_children ) child.drawImGui();
ImGui::TreePop();
}
@@ -118,21 +118,21 @@ namespace fgl::engine::debug
void reset()
{
previous_root = std::move( root );
root.name = "Update Time";
root.children.clear();
root.start = profiling_clock::now();
root.m_name = "Update Time";
root.m_children.clear();
root.m_start = ProfilingClock::now();
active = &root;
}
ScopedTimer push( const std::string_view name )
{
Node new_node {};
new_node.name = name;
new_node.parent = active;
new_node.start = profiling_clock::now();
new_node.m_name = name;
new_node.m_parent = active;
new_node.m_start = ProfilingClock::now();
assert( active );
active->children.emplace_back( std::move( new_node ) );
active = &active->children.back();
active->m_children.emplace_back( std::move( new_node ) );
active = &active->m_children.back();
return {};
}
@@ -146,7 +146,7 @@ namespace fgl::engine::debug
std::size_t depth { 0 };
while ( current != nullptr )
{
current = current->parent;
current = current->m_parent;
++depth;
}
return depth;
@@ -160,14 +160,14 @@ namespace fgl::engine::debug
}
FGL_ASSERT( active, "Active node in framegraph was null!" );
active->end = profiling_clock::now();
active->m_end = ProfilingClock::now();
const auto diff { active->end - active->start };
const auto diff { active->m_end - active->m_start };
FGL_ASSERT( diff >= decltype( diff ) { 0 }, "Popped node ended before it began!" );
FGL_ASSERT( active->end > active->start, "Node ended before it began!" );
FGL_ASSERT( active->m_end > active->m_start, "Node ended before it began!" );
active = active->parent;
active = active->m_parent;
}
} // namespace internal

View File

@@ -53,7 +53,7 @@ namespace fgl::engine::descriptors
return *this;
}
void DescriptorSet::bindUniformBuffer( const std::uint32_t binding_idx, memory::BufferSuballocation& buffer )
void DescriptorSet::bindUniformBuffer( const std::uint32_t binding_idx, const memory::BufferSuballocation& buffer )
{
assert( binding_idx < m_infos.size() && "Binding index out of range" );
@@ -65,7 +65,7 @@ namespace fgl::engine::descriptors
write.dstArrayElement = 0;
write.descriptorCount = 1;
write.descriptorType = vk::DescriptorType::eUniformBuffer;
write.pBufferInfo = &( std::get< vk::DescriptorBufferInfo >( m_infos.data()[ binding_idx ] ) );
write.pBufferInfo = &( std::get< vk::DescriptorBufferInfo >( m_infos[ binding_idx ] ) );
write.pImageInfo = VK_NULL_HANDLE;
write.pTexelBufferView = VK_NULL_HANDLE;
@@ -91,15 +91,18 @@ namespace fgl::engine::descriptors
write.dstArrayElement = array_idx;
write.descriptorCount = 1;
write.descriptorType = vk::DescriptorType::eUniformBuffer;
write.pBufferInfo = &( std::get< vk::DescriptorBufferInfo >( m_infos.data()[ binding_idx ] ) );
write.pBufferInfo = &( std::get< vk::DescriptorBufferInfo >( m_infos[ binding_idx ] ) );
write.pImageInfo = VK_NULL_HANDLE;
write.pTexelBufferView = VK_NULL_HANDLE;
descriptor_writes.push_back( write );
}
void DescriptorSet::
bindImage( std::uint32_t binding_idx, ImageView& view, vk::ImageLayout layout, vk::raii::Sampler sampler )
void DescriptorSet::bindImage(
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" );
@@ -113,13 +116,13 @@ namespace fgl::engine::descriptors
write.descriptorCount = 1;
write.descriptorType = vk::DescriptorType::eSampledImage;
write.pBufferInfo = VK_NULL_HANDLE;
write.pImageInfo = &( std::get< vk::DescriptorImageInfo >( m_infos.data()[ binding_idx ] ) );
write.pImageInfo = &( std::get< vk::DescriptorImageInfo >( m_infos[ binding_idx ] ) );
write.pTexelBufferView = VK_NULL_HANDLE;
descriptor_writes.push_back( write );
}
void DescriptorSet::bindTexture( std::uint32_t binding_idx, std::shared_ptr< Texture >& tex_ptr )
void DescriptorSet::bindTexture( const std::uint32_t binding_idx, const std::shared_ptr< Texture >& tex_ptr )
{
assert( binding_idx < m_infos.size() && "Binding index out of range" );
assert(
@@ -188,7 +191,7 @@ namespace fgl::engine::descriptors
descriptor_writes.push_back( write );
}
void DescriptorSet::setName( const std::string& str )
void DescriptorSet::setName( const std::string& str ) const
{
vk::DebugUtilsObjectNameInfoEXT info {};
info.objectType = vk::ObjectType::eDescriptorSet;
@@ -198,22 +201,22 @@ namespace fgl::engine::descriptors
Device::getInstance().setDebugUtilsObjectName( info );
}
inline static std::vector< std::pair< std::uint_fast8_t, std::unique_ptr< DescriptorSet > > > queue {};
inline static std::vector< std::pair< std::uint_fast8_t, std::unique_ptr< DescriptorSet > > > QUEUE {};
void queueDescriptorDeletion( std::unique_ptr< DescriptorSet > set )
{
queue.emplace_back( std::make_pair( 0, std::move( set ) ) );
QUEUE.emplace_back( std::make_pair( 0, std::move( set ) ) );
}
void deleteQueuedDescriptors()
{
for ( auto itter = queue.begin(); itter != queue.end(); itter = itter++ )
for ( auto itter = QUEUE.begin(); itter != QUEUE.end(); itter = itter++ )
{
auto& [ counter, set ] = *itter;
// Prevent deleting a descriptor until we are sure it's been here long enough
if ( counter > SwapChain::MAX_FRAMES_IN_FLIGHT + 1 )
{
itter = queue.erase( itter );
itter = QUEUE.erase( itter );
}
else
++counter;

View File

@@ -68,11 +68,11 @@ namespace fgl::engine::descriptors
void bindImage(
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 bindUniformBuffer( std::uint32_t binding_idx, memory::BufferSuballocation& buffer );
void bindUniformBuffer( std::uint32_t binding_idx, const memory::BufferSuballocation& buffer );
void bindArray(
std::uint32_t binding_idx,
const memory::BufferSuballocation& buffer,
@@ -85,9 +85,9 @@ namespace fgl::engine::descriptors
vk::ImageLayout layout,
const vk::raii::Sampler& sampler = VK_NULL_HANDLE );
void bindTexture( std::uint32_t binding_idx, std::shared_ptr< Texture >& tex_ptr );
void bindTexture( std::uint32_t binding_idx, const std::shared_ptr< Texture >& tex_ptr );
void setName( const std::string& str );
void setName( const std::string& str ) const;
};
//! Queues a descriptor to be deleted.

View File

@@ -13,7 +13,7 @@
namespace fgl::engine
{
void InputRotation( const char* label, Rotation& rot, float speed )
void inputRotation( const char* label, Rotation& rot, const float speed )
{
enum Axis
{
@@ -64,7 +64,7 @@ namespace fgl::engine
ImGui::DragFloat3( "Position", &transform.translation.x, speed );
InputRotation( "Rotation", transform.rotation, speed );
inputRotation( "Rotation", transform.rotation, speed );
ImGui::DragFloat3( "Scale", &transform.scale.x, speed );
}

View File

@@ -12,18 +12,18 @@
namespace fgl::engine
{
constexpr auto indent_amount { 1.0f };
constexpr auto INDENT_AMOUNT { 1.0f };
void GameObjectComponentBase::drawNode( GameObjectComponentPtr& selected_out )
{
ImGui::Indent( indent_amount );
ImGui::Indent( INDENT_AMOUNT );
if ( ImGui::Selectable( this->name().data() ) )
{
selected_out = this;
}
drawChildren( selected_out );
ImGui::Unindent( indent_amount );
ImGui::Unindent( INDENT_AMOUNT );
}
void GameObjectComponentBase::drawChildren( GameObjectComponentPtr& selected_out )

View File

@@ -55,12 +55,12 @@ namespace fgl::engine
const std::array< Coordinate< CType >, BoundingBoxPointCount >& bounding_points )
{
return (
testAxis( frustum.right.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.left.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.near.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.far.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.top.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.bottom.getDirection(), frustum_points, bounding_points ) );
testAxis( frustum.m_right.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.m_left.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.m_near.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.m_far.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.m_top.getDirection(), frustum_points, bounding_points )
|| testAxis( frustum.m_bottom.getDirection(), frustum_points, bounding_points ) );
}
} // namespace fgl::engine

View File

@@ -107,12 +107,12 @@ namespace fgl::engine::intersection
std::vector< WorldCoordinate > enter_intersections { line.getPosition() };
std::vector< WorldCoordinate > exit_intersections { line.getEnd() };
processPlane( frustum.near, line, enter_intersections, exit_intersections );
processPlane( frustum.far, line, enter_intersections, exit_intersections );
processPlane( frustum.left, line, enter_intersections, exit_intersections );
processPlane( frustum.right, line, enter_intersections, exit_intersections );
processPlane( frustum.top, line, enter_intersections, exit_intersections );
processPlane( frustum.bottom, line, enter_intersections, exit_intersections );
processPlane( frustum.m_near, line, enter_intersections, exit_intersections );
processPlane( frustum.m_far, line, enter_intersections, exit_intersections );
processPlane( frustum.m_left, line, enter_intersections, exit_intersections );
processPlane( frustum.m_right, line, enter_intersections, exit_intersections );
processPlane( frustum.m_top, line, enter_intersections, exit_intersections );
processPlane( frustum.m_bottom, line, enter_intersections, exit_intersections );
if ( enter_intersections.size() == 0 ) return false;
if ( exit_intersections.size() == 0 ) return false;

View File

@@ -29,7 +29,7 @@ namespace fgl::literals::size_literals
return size * 1024_MiB;
}
inline std::string to_string( const unsigned long long int size )
inline std::string toString( const unsigned long long int size )
{
if ( size < 1024_B ) return std::to_string( size ) + " B";
if ( size < 1024_KiB ) return std::to_string( size / 1024 ) + " KiB";

View File

@@ -114,7 +114,7 @@ namespace fgl::engine
data[ index ] = color;
data[ index + 1 ] = color;
data[ index + 2 ] = color;
data[ index + 3 ] = std::byte( 255 );
data[ index + 3 ] = static_cast< std::byte >( 255 );
}
}

View File

@@ -8,7 +8,7 @@
namespace fgl::engine
{
Ray constructRay( WorldCoordinate& start, WorldCoordinate& end )
Ray constructRay( const WorldCoordinate& start, const WorldCoordinate& end )
{
const Ray ray { start, start.vectorTo( end ).normalize() };
return ray;

View File

@@ -13,11 +13,11 @@ namespace fgl::engine
struct Ray
{
WorldCoordinate start;
NormalVector vector;
WorldCoordinate m_start;
NormalVector m_vector;
};
Ray constructRay( WorldCoordinate& start, WorldCoordinate& end );
Ray constructRay( const WorldCoordinate& start, const WorldCoordinate& end );
bool rayHit( const Ray& ray, const OrientedBoundingBox< CS::World >& obb, OctTreeNode* root );

View File

@@ -34,19 +34,18 @@ namespace fgl::engine::memory
{
assert( this->m_allocations.size() == 0 );
dealloc();
if ( auto itter = std::find( active_buffers.begin(), active_buffers.end(), this );
itter != active_buffers.end() )
if ( const auto itter = std::ranges::find( active_buffers, this ); itter != active_buffers.end() )
active_buffers.erase( itter );
}
void* Buffer::map( BufferSuballocationHandle& handle )
void* Buffer::map( const BufferSuballocationHandle& handle ) const
{
if ( m_alloc_info.pMappedData == nullptr ) return nullptr;
return static_cast< std::byte* >( m_alloc_info.pMappedData ) + handle.m_offset;
}
void Buffer::dealloc()
void Buffer::dealloc() const
{
vmaDestroyBuffer( Device::getInstance().allocator(), m_buffer, m_allocation );
}
@@ -93,7 +92,7 @@ namespace fgl::engine::memory
vmaGetAllocationInfo( Device::getInstance().allocator(), m_allocation, &m_alloc_info );
}
vk::DeviceSize Buffer::alignment()
vk::DeviceSize Buffer::alignment() const
{
vk::DeviceSize size { 0 };
@@ -262,7 +261,7 @@ namespace fgl::engine::memory
}
}
void Buffer::setDebugName( const std::string str )
void Buffer::setDebugName( const std::string& str )
{
vk::DebugUtilsObjectNameInfoEXT info {};
info.objectType = vk::ObjectType::eBuffer;

View File

@@ -56,7 +56,7 @@ namespace fgl::engine::memory
private:
void alloc( vk::DeviceSize memory_size );
void dealloc();
void dealloc() const;
Buffer() = delete;
Buffer( const Buffer& other ) = delete;
@@ -80,10 +80,10 @@ namespace fgl::engine::memory
private:
void* map( BufferSuballocationHandle& handle );
void* map( const BufferSuballocationHandle& handle ) const;
//! Returns the required alignment for this buffer.
vk::DeviceSize alignment();
vk::DeviceSize alignment() const;
//! @brief List of all active suballocations
//! <offset, size>
@@ -145,7 +145,7 @@ namespace fgl::engine::memory
void mergeFreeBlocks();
void setDebugName( const std::string str );
void setDebugName( const std::string& str );
};
std::vector< Buffer* > getActiveBuffers();

View File

@@ -52,7 +52,7 @@ namespace fgl::engine::memory
return m_handle->mapped;
}
void BufferSuballocation::flush( vk::DeviceSize beg, vk::DeviceSize end )
void BufferSuballocation::flush( const vk::DeviceSize beg, const vk::DeviceSize end ) const
{
assert( beg < end );
assert( m_handle != nullptr );
@@ -74,7 +74,7 @@ namespace fgl::engine::memory
if ( range.size > m_byte_size ) range.size = VK_WHOLE_SIZE;
std::vector< vk::MappedMemoryRange > ranges { range };
const std::vector< vk::MappedMemoryRange > ranges { range };
Device::getInstance()->flushMappedMemoryRanges( ranges );
}
@@ -113,7 +113,7 @@ namespace fgl::engine::memory
BufferSuballocation( buffer.allocate( size ) )
{}
BufferSuballocation::BufferSuballocation( Buffer& buffer, std::size_t t_size, std::uint32_t t_align ) :
BufferSuballocation::BufferSuballocation( Buffer& buffer, const std::size_t t_size, const std::uint32_t t_align ) :
BufferSuballocation( buffer.allocate( t_size, t_align ) )
{}

View File

@@ -25,7 +25,7 @@ namespace fgl::engine::memory
vk::DeviceSize m_offset;
vk::DeviceSize m_byte_size;
void flush( vk::DeviceSize beg, vk::DeviceSize end );
void flush( vk::DeviceSize beg, vk::DeviceSize end ) const;
explicit BufferSuballocation( Buffer& buffer, std::size_t t_size, std::uint32_t t_align );

View File

@@ -10,13 +10,13 @@
namespace fgl::engine::memory
{
vk::Buffer BufferSuballocationHandle::getBuffer()
vk::Buffer BufferSuballocationHandle::getBuffer() const
{
return buffer.getVkBuffer();
}
BufferSuballocationHandle::
BufferSuballocationHandle( Buffer& p_buffer, vk::DeviceSize offset, vk::DeviceSize memory_size ) :
BufferSuballocationHandle( Buffer& p_buffer, const vk::DeviceSize offset, const vk::DeviceSize memory_size ) :
buffer( p_buffer ),
m_size( memory_size ),
m_offset( offset ),
@@ -35,7 +35,8 @@ namespace fgl::engine::memory
buffer.free( *this );
}
vk::BufferCopy BufferSuballocationHandle::copyRegion( BufferSuballocationHandle& target, const std::size_t offset )
vk::BufferCopy BufferSuballocationHandle::
copyRegion( const BufferSuballocationHandle& target, const std::size_t offset ) const
{
vk::BufferCopy copy {};
copy.size = std::min( this->m_size, target.m_size );
@@ -44,8 +45,10 @@ namespace fgl::engine::memory
return copy;
}
void BufferSuballocationHandle::
copyTo( vk::raii::CommandBuffer& cmd_buffer, BufferSuballocationHandle& other, const std::size_t offset )
void BufferSuballocationHandle::copyTo(
const vk::raii::CommandBuffer& cmd_buffer,
const BufferSuballocationHandle& other,
const std::size_t offset ) const
{
const vk::BufferCopy copy_region { copyRegion( other, offset ) };

View File

@@ -33,7 +33,7 @@ namespace fgl::engine::memory
BufferSuballocationHandle() = delete;
BufferSuballocationHandle( Buffer& buffer, vk::DeviceSize memory_size, vk::DeviceSize offset );
BufferSuballocationHandle( Buffer& p_buffer, vk::DeviceSize offset, vk::DeviceSize memory_size );
~BufferSuballocationHandle();
BufferSuballocationHandle( const BufferSuballocationHandle& ) = delete;
@@ -42,14 +42,15 @@ namespace fgl::engine::memory
BufferSuballocationHandle( BufferSuballocationHandle&& ) = delete;
BufferSuballocationHandle& operator=( BufferSuballocationHandle&& ) = delete;
vk::Buffer getBuffer();
vk::Buffer getBuffer() const;
vk::Buffer getVkBuffer() const;
vk::BufferCopy copyRegion( BufferSuballocationHandle& target, std::size_t offset );
vk::BufferCopy copyRegion( const BufferSuballocationHandle& target, std::size_t offset ) const;
vk::DeviceSize getOffset() const { return m_offset; }
void copyTo( vk::raii::CommandBuffer& cmd_buffer, BufferSuballocationHandle& other, std::size_t offset );
void copyTo( const vk::raii::CommandBuffer& cmd_buffer,
const BufferSuballocationHandle& other, std::size_t offset ) const;
bool ready() const { return m_staged; }

View File

@@ -21,7 +21,7 @@ namespace fgl::engine
explicit BufferException( const char* str ) : EngineException( str ) {}
};
struct BufferOOM : public BufferException
struct BufferOOM final : public BufferException
{
explicit BufferOOM() : BufferException( "Buffer OOM" ) {}
};

View File

@@ -30,7 +30,7 @@ namespace fgl::engine
DeviceVector( memory::Buffer& buffer, const std::uint32_t count = 1 ) :
BufferVector( buffer, count, sizeof( T ) )
{
const auto size_str { fgl::literals::size_literals::to_string( count * sizeof( T ) ) };
const auto size_str { fgl::literals::size_literals::toString( count * sizeof( T ) ) };
assert( count != 0 && "BufferSuballocationVector::BufferSuballocationVector() called with count == 0" );
}

View File

@@ -21,8 +21,8 @@ namespace fgl::engine
Frustum operator*( const Matrix< MatrixType::ModelToWorld >& matrix, const FrustumBase& frustum )
{
const Frustum result { matrix * frustum.near, matrix * frustum.far, matrix * frustum.top,
matrix * frustum.bottom, matrix * frustum.right, matrix * frustum.left,
const Frustum result { matrix * frustum.m_near, matrix * frustum.m_far, matrix * frustum.m_top,
matrix * frustum.m_bottom, matrix * frustum.m_right, matrix * frustum.m_left,
matrix * frustum.m_position };
return result;
@@ -32,12 +32,12 @@ namespace fgl::engine
FGL_FORCE_INLINE inline NormalVector Frustum::forwardVec() const
{
return near.getDirection();
return m_near.getDirection();
}
FGL_FORCE_INLINE inline NormalVector Frustum::upVec() const
{
return NormalVector( glm::cross( forwardVec().vec(), left.getDirection().vec() ) );
return NormalVector( glm::cross( forwardVec().vec(), m_left.getDirection().vec() ) );
}
FGL_FORCE_INLINE inline NormalVector Frustum::rightVec() const
@@ -61,8 +61,8 @@ namespace fgl::engine
// We can either make this non-biased by using a projection from distance shot down the FORWARD vector
// Or we can use SIMD to check all the planes at once.
return near.isForward( coord ) && far.isForward( coord ) && bottom.isForward( coord ) && top.isForward( coord )
&& right.isForward( coord ) && left.isForward( coord );
return m_near.isForward( coord ) && m_far.isForward( coord ) && m_bottom.isForward( coord ) && m_top.isForward( coord )
&& m_right.isForward( coord ) && m_left.isForward( coord );
}
bool Frustum::containsAnyPoint( const std::vector< WorldCoordinate >& coords ) const
@@ -82,25 +82,25 @@ namespace fgl::engine
std::array< Coordinate< CoordinateSpace::World >, 4 * 2 > Frustum::points() const
{
const NormalVector pv0 { glm::cross( top.getDirection().vec(), left.getDirection().vec() ) };
const NormalVector pv1 { glm::cross( top.getDirection().vec(), right.getDirection().vec() ) };
const NormalVector pv2 { glm::cross( bottom.getDirection().vec(), left.getDirection().vec() ) };
const NormalVector pv3 { glm::cross( bottom.getDirection().vec(), right.getDirection().vec() ) };
const NormalVector pv0 { glm::cross( m_top.getDirection().vec(), m_left.getDirection().vec() ) };
const NormalVector pv1 { glm::cross( m_top.getDirection().vec(), m_right.getDirection().vec() ) };
const NormalVector pv2 { glm::cross( m_bottom.getDirection().vec(), m_left.getDirection().vec() ) };
const NormalVector pv3 { glm::cross( m_bottom.getDirection().vec(), m_right.getDirection().vec() ) };
const auto l0 { InfiniteLine< CoordinateSpace::World >( m_position, pv0 ) };
const auto l1 { InfiniteLine< CoordinateSpace::World >( m_position, pv1 ) };
const auto l2 { InfiniteLine< CoordinateSpace::World >( m_position, pv2 ) };
const auto l3 { InfiniteLine< CoordinateSpace::World >( m_position, pv3 ) };
const auto p0 { l0.intersection( far ) };
const auto p1 { l1.intersection( far ) };
const auto p2 { l2.intersection( far ) };
const auto p3 { l3.intersection( far ) };
const auto p0 { l0.intersection( m_far ) };
const auto p1 { l1.intersection( m_far ) };
const auto p2 { l2.intersection( m_far ) };
const auto p3 { l3.intersection( m_far ) };
const auto p4 { l0.intersection( near ) };
const auto p5 { l1.intersection( near ) };
const auto p6 { l2.intersection( near ) };
const auto p7 { l3.intersection( near ) };
const auto p4 { l0.intersection( m_near ) };
const auto p5 { l1.intersection( m_near ) };
const auto p6 { l2.intersection( m_near ) };
const auto p7 { l3.intersection( m_near ) };
return { { p0, p1, p2, p3, p4, p5, p6, p7 } };
}

View File

@@ -20,12 +20,12 @@ namespace fgl::engine
//! Frustum constructed in model space (To be translated to a World space frustum later)
struct FrustumBase
{
ModelPlane near { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane far { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane top { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane bottom { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane right { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane left { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane m_near { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane m_far { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane m_top { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane m_bottom { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane m_right { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelPlane m_left { ModelCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
ModelCoordinate m_position {};
@@ -39,24 +39,24 @@ namespace fgl::engine
const ModelPlane& right_plane,
const ModelPlane& left_plane,
const ModelCoordinate position ) :
near( near_plane ),
far( far_plane ),
top( top_plane ),
bottom( bottom_plane ),
right( right_plane ),
left( left_plane ),
m_near( near_plane ),
m_far( far_plane ),
m_top( top_plane ),
m_bottom( bottom_plane ),
m_right( right_plane ),
m_left( left_plane ),
m_position( position )
{}
};
struct Frustum
{
WorldPlane near { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane far { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane top { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane bottom { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane right { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane left { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane m_near { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane m_far { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane m_top { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane m_bottom { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane m_right { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldPlane m_left { WorldCoordinate( constants::WORLD_CENTER ), NormalVector( constants::WORLD_Y ) };
WorldCoordinate m_position {};
@@ -75,12 +75,12 @@ namespace fgl::engine
const WorldPlane& right_plane,
const WorldPlane& left_plane,
const WorldCoordinate position ) :
near( near_plane ),
far( far_plane ),
top( top_plane ),
bottom( bottom_plane ),
right( right_plane ),
left( left_plane ),
m_near( near_plane ),
m_far( far_plane ),
m_top( top_plane ),
m_bottom( bottom_plane ),
m_right( right_plane ),
m_left( left_plane ),
m_position( position )
{}

View File

@@ -15,7 +15,7 @@ namespace fgl::engine
{
template < CoordinateSpace CType >
class InfiniteLine : public LineBase
class InfiniteLine final : public LineBase
{
Coordinate< CType > m_start;
NormalVector m_direction;

View File

@@ -16,8 +16,8 @@ namespace fgl::engine
template < CoordinateSpace CType >
class LineSegment final : public LineBase
{
Coordinate< CType > start { -constants::DEFAULT_VEC3 };
Coordinate< CType > end { constants::DEFAULT_VEC3 };
Coordinate< CType > m_start { -constants::DEFAULT_VEC3 };
Coordinate< CType > m_end { constants::DEFAULT_VEC3 };
glm::vec3 getVec3Position() const override { return getPosition().vec(); }
@@ -28,27 +28,27 @@ namespace fgl::engine
LineSegment() = default;
explicit LineSegment( const Coordinate< CType > i_start, const Coordinate< CType > i_end ) noexcept :
start( i_start ),
end( i_end )
m_start( i_start ),
m_end( i_end )
{}
explicit LineSegment( const glm::vec3 i_start, glm::vec3 i_end ) : start( i_start ), end( i_end ) {}
explicit LineSegment( const glm::vec3 i_start, glm::vec3 i_end ) : m_start( i_start ), m_end( i_end ) {}
NormalVector getDirection() const { return start.normalTo( end ); }
NormalVector getDirection() const { return m_start.normalTo( m_end ); }
Coordinate< CType > getPosition() const { return start; }
Coordinate< CType > getPosition() const { return m_start; }
Coordinate< CType > getStart() const { return start; }
Coordinate< CType > getStart() const { return m_start; }
Coordinate< CType > getEnd() const { return end; }
Coordinate< CType > getEnd() const { return m_end; }
LineSegment flip() const { return LineSegment( end, start ); }
LineSegment flip() const { return LineSegment( m_end, m_start ); }
template < typename T >
requires is_plane< T >
FGL_FLATTEN bool intersects( const T plane ) const
{
return plane.isForward( start ) != plane.isForward( end );
return plane.isForward( m_start ) != plane.isForward( m_end );
}
template < typename T >

View File

@@ -84,7 +84,7 @@ namespace fgl::engine
NormalVector operator*( Matrix< MType > mat, NormalVector );
inline Matrix< MatrixType::WorldToScreen >
operator*( const Matrix< MatrixType::CameraToScreen > lhs, const Matrix< MatrixType::WorldToCamera > rhs )
operator*( const Matrix< MatrixType::CameraToScreen >& lhs, const Matrix< MatrixType::WorldToCamera >& rhs )
{
return Matrix< MatrixType::WorldToScreen >( static_cast< glm::mat4 >( lhs ) * static_cast< glm::mat4 >( rhs ) );
}

View File

@@ -23,7 +23,7 @@ namespace fgl::engine
{}
template < CoordinateSpace CType >
OriginDistancePlane< CType >::OriginDistancePlane( const Vector vector, const float distance ) :
OriginDistancePlane< CType >::OriginDistancePlane( const Vector& vector, const float distance ) :
m_distance( distance ),
m_direction( vector )
{}

View File

@@ -21,13 +21,14 @@ namespace fgl::engine
public:
// ReSharper disable once CppInconsistentNaming
constexpr static auto SpaceType { CType };
OriginDistancePlane();
explicit OriginDistancePlane( const NormalVector vector, const float distance );
explicit OriginDistancePlane( const Vector vector, const float distance );
explicit OriginDistancePlane( const Vector& vector, const float distance );
inline NormalVector getDirection() const { return m_direction; }

View File

@@ -11,32 +11,32 @@ namespace fgl::engine
template < CoordinateSpace CType >
PointPlane< CType >::PointPlane() :
coordinate( constants::WORLD_CENTER ),
vector( NormalVector( constants::WORLD_Y ) )
m_coordinate( constants::WORLD_CENTER ),
m_vector( NormalVector( constants::WORLD_Y ) )
{}
template < CoordinateSpace CType >
PointPlane< CType >::PointPlane( const Coordinate< CType > pos, const Vector vec ) :
coordinate( pos ),
vector( vec )
PointPlane< CType >::PointPlane( const Coordinate< CType > pos, const Vector& vec ) :
m_coordinate( pos ),
m_vector( vec )
{}
template < CoordinateSpace CType >
PointPlane< CType >::PointPlane( const Coordinate< CType > pos, const NormalVector vec ) :
coordinate( pos ),
vector( vec )
m_coordinate( pos ),
m_vector( vec )
{}
template < CoordinateSpace CType >
float PointPlane< CType >::distance() const
{
return glm::dot( vector.vec(), coordinate.vec() );
return glm::dot( m_vector.vec(), m_coordinate.vec() );
}
template < CoordinateSpace CType >
float PointPlane< CType >::distanceFrom( const Coordinate< CType > coord ) const
{
return static_cast< float >( glm::dot( ( coord - coordinate ).vec(), vector.vec() ) );
return static_cast< float >( glm::dot( ( coord - m_coordinate ).vec(), m_vector.vec() ) );
}
template < CoordinateSpace CType >

View File

@@ -17,24 +17,25 @@ namespace fgl::engine
template < CoordinateSpace CType >
class PointPlane
{
Coordinate< CType > coordinate;
NormalVector vector;
Coordinate< CType > m_coordinate;
NormalVector m_vector;
public:
// ReSharper disable once CppInconsistentNaming
constexpr static auto SpaceType { CType };
PointPlane();
PointPlane( Coordinate< CType > pos, Vector vec );
PointPlane( Coordinate< CType > pos, const Vector& vec );
PointPlane( Coordinate< CType > pos, NormalVector vec );
FGL_FORCE_INLINE NormalVector getDirection() const { return vector; }
FGL_FORCE_INLINE NormalVector getDirection() const { return m_vector; }
float distance() const;
FGL_FORCE_INLINE Coordinate< CType > getPosition() const { return coordinate; }
FGL_FORCE_INLINE Coordinate< CType > getPosition() const { return m_coordinate; }
float distanceFrom( const Coordinate< CType > coord ) const;

View File

@@ -9,7 +9,7 @@
namespace fgl::engine
{
NormalVector::NormalVector( const fgl::engine::Vector vector ) : NormalVector( vector.vec() )
NormalVector::NormalVector( const fgl::engine::Vector& vector ) : NormalVector( vector.vec() )
{}
Vector NormalVector::operator*( const float scalar ) const

View File

@@ -21,20 +21,19 @@ namespace fgl::engine
class Vector;
inline constexpr float length( const glm::vec3 vec )
constexpr float length( const glm::vec3 vec )
{
return std::sqrt( std::pow( vec.x, 2.0f ) + std::pow( vec.y, 2.0f ) + std::pow( vec.z, 2.0f ) );
}
inline constexpr glm::vec3 normalize( const glm::vec3 vec )
constexpr glm::vec3 normalize( const glm::vec3 vec )
{
if ( std::is_constant_evaluated() )
if consteval
{
const auto len { length( vec ) };
return glm::vec3( vec.x / len, vec.y / len, vec.z / len );
}
else
return glm::normalize( vec );
return glm::normalize( vec );
}
//! A vector that must be a distance of 1
@@ -46,7 +45,7 @@ namespace fgl::engine
constexpr NormalVector() : glm::vec3( normalize( glm::vec3( 1.0f ) ) ) {}
explicit NormalVector( const Vector vec );
explicit NormalVector( const Vector& vector );
constexpr explicit NormalVector( const glm::vec3 vec ) : glm::vec3( normalize( vec ) ) {}

View File

@@ -36,7 +36,7 @@ namespace fgl::engine
public:
FGL_DELETE_ALL_Ro5( Instance );
FGL_DELETE_ALL_RO5( Instance );
explicit Instance( vk::raii::Context& ctx );

View File

@@ -9,7 +9,7 @@
namespace fgl::engine
{
QueuePool::QueuePool( vk::raii::PhysicalDevice& physical_device, Surface& surface )
QueuePool::QueuePool( const vk::raii::PhysicalDevice& physical_device, Surface& surface )
{
const auto family_props { physical_device.getQueueFamilyProperties() };
@@ -18,7 +18,7 @@ namespace fgl::engine
auto& props { family_props[ i ] };
if ( props.queueCount > 0 )
{
vk::Bool32 can_present { physical_device.getSurfaceSupportKHR( i, surface ) };
const vk::Bool32 can_present { physical_device.getSurfaceSupportKHR( i, surface ) };
queue_info.emplace_back( props, can_present == VK_TRUE, 0 );
}
@@ -40,7 +40,7 @@ namespace fgl::engine
throw std::runtime_error( "Failed to get index of queue family with given flags" );
}
std::uint32_t QueuePool::getPresentIndex()
std::uint32_t QueuePool::getPresentIndex() const
{
for ( std::uint32_t i = 0; i < queue_info.size(); ++i )
{

View File

@@ -26,16 +26,16 @@ namespace fgl::engine
public:
QueuePool( vk::raii::PhysicalDevice&, Surface& );
QueuePool( const vk::raii::PhysicalDevice&, Surface& );
FGL_DELETE_ALL_Ro5( QueuePool );
FGL_DELETE_ALL_RO5( QueuePool );
using QueueIndex = std::uint32_t;
//! Returns a unique list of indexes with the matching flags
QueueIndex getIndex( vk::QueueFlags flags, vk::QueueFlags anti_flags = vk::QueueFlags( 0 ) );
std::uint32_t getPresentIndex();
std::uint32_t getPresentIndex() const;
};
} // namespace fgl::engine

View File

@@ -20,12 +20,12 @@ namespace fgl::engine
Surface( Window& window, Instance& instance );
FGL_DELETE_ALL_Ro5( Surface );
FGL_DELETE_ALL_RO5( Surface );
vk::raii::SurfaceKHR& handle() { return m_surface; }
operator vk::SurfaceKHR() { return m_surface; }
operator VkSurfaceKHR() { return *m_surface; }
operator VkSurfaceKHR() const { return *m_surface; }
};
} // namespace fgl::engine

View File

@@ -101,7 +101,7 @@ namespace fgl::engine
public:
// Not copyable or movable
FGL_DELETE_ALL_Ro5( Device );
FGL_DELETE_ALL_RO5( Device );
vk::CommandPool getCommandPool() { return m_commandPool; }

View File

@@ -19,7 +19,7 @@ namespace fgl::engine
vk::raii::PhysicalDevice m_phy_device;
QueuePool queue_pool;
FGL_DELETE_ALL_Ro5( PhysicalDevice );
FGL_DELETE_ALL_RO5( PhysicalDevice );
//! Picks a device that can render to the desired output window
vk::raii::PhysicalDevice pickPhysicalDevice( Instance& dev, Surface& surface );

View File

@@ -97,7 +97,7 @@ namespace fgl::engine
{
auto& images { m_attachment_resources.m_images };
auto& image_views { m_attachment_resources.m_image_views };
auto& itter { images.emplace_back( std::make_shared< Image >(
const auto& itter { images.emplace_back( std::make_shared< Image >(
extent,
description.format,
usage | vk::ImageUsageFlagBits::eInputAttachment | extra_flags,

View File

@@ -31,7 +31,7 @@ namespace fgl::engine
void AttachmentBuilder::finish()
{
parent.state->color_blend_attachment.emplace_back( color_blend_config );
parent.m_state->color_blend_attachment.emplace_back( color_blend_config );
m_finished = true;
}

View File

@@ -12,7 +12,7 @@ namespace fgl::engine
{
PipelineBuilder::PipelineBuilder( vk::raii::RenderPass& renderpass, const std::uint32_t subpass_stage ) :
state( std::make_unique< BuilderState >( renderpass, subpass_stage ) )
m_state( std::make_unique< BuilderState >( renderpass, subpass_stage ) )
{
addDynamicState( vk::DynamicState::eViewport );
addDynamicState( vk::DynamicState::eScissor );
@@ -20,12 +20,12 @@ namespace fgl::engine
void PipelineBuilder::setVertexShader( std::shared_ptr< Shader >&& shader )
{
state->shaders.vertex = std::forward< std::shared_ptr< Shader > >( shader );
m_state->shaders.vertex = std::forward< std::shared_ptr< Shader > >( shader );
}
void PipelineBuilder::setFragmentShader( std::shared_ptr< Shader >&& shader )
{
state->shaders.fragment = std::forward< std::shared_ptr< Shader > >( shader );
m_state->shaders.fragment = std::forward< std::shared_ptr< Shader > >( shader );
}
descriptors::DescriptorSetLayout empty_set_layout { descriptors::DescriptorSetLayout::createEmptySet() };
@@ -34,15 +34,15 @@ namespace fgl::engine
{
vk::PipelineLayoutCreateInfo info {};
if ( state->push_constant.size > 0 ) info.setPushConstantRanges( state->push_constant );
if ( m_state->push_constant.size > 0 ) info.setPushConstantRanges( m_state->push_constant );
std::vector< vk::DescriptorSetLayout > set_layouts {};
set_layouts.reserve( state->descriptor_set_layouts.size() );
set_layouts.reserve( m_state->descriptor_set_layouts.size() );
SetID max_set_idx { 0 };
for ( const auto& [ set_idx, _ ] : state->descriptor_set_layouts )
for ( const auto& [ set_idx, _ ] : m_state->descriptor_set_layouts )
{
max_set_idx = std::max( max_set_idx, set_idx );
}
@@ -52,8 +52,8 @@ namespace fgl::engine
for ( std::size_t i = 0; i < set_layouts.size(); ++i )
{
auto itter { state->descriptor_set_layouts.find( static_cast< SetID >( i ) ) };
if ( itter == state->descriptor_set_layouts.end() )
auto itter { m_state->descriptor_set_layouts.find( static_cast< SetID >( i ) ) };
if ( itter == m_state->descriptor_set_layouts.end() )
{
// Could not find it. Empty
set_layouts[ i ] = empty_set_layout.layout();
@@ -66,7 +66,7 @@ namespace fgl::engine
}
}
for ( const auto& [ set_idx, layout ] : state->descriptor_set_layouts )
for ( const auto& [ set_idx, layout ] : m_state->descriptor_set_layouts )
{
set_layouts[ set_idx ] = layout;
}
@@ -79,8 +79,8 @@ namespace fgl::engine
void PipelineBuilder::
addDescriptorSet( const SetID idx, const vk::raii::DescriptorSetLayout& descriptor_set_layout )
{
FGL_ASSERT( !state->descriptor_set_layouts.contains( idx ), "Descriptor already set!" );
state->descriptor_set_layouts.insert( std::make_pair( idx, *descriptor_set_layout ) );
FGL_ASSERT( !m_state->descriptor_set_layouts.contains( idx ), "Descriptor already set!" );
m_state->descriptor_set_layouts.insert( std::make_pair( idx, *descriptor_set_layout ) );
}
void PipelineBuilder::addDescriptorSet( descriptors::DescriptorSetLayout& descriptor )
@@ -90,14 +90,14 @@ namespace fgl::engine
void PipelineBuilder::addDynamicState( vk::DynamicState dynamic_state )
{
state->m_dynamic_state.emplace_back( dynamic_state );
m_state->m_dynamic_state.emplace_back( dynamic_state );
}
void PipelineBuilder::setPushConstant( const vk::ShaderStageFlags flags, std::size_t size )
{
state->push_constant.offset = 0;
state->push_constant.size = size;
state->push_constant.stageFlags = flags;
m_state->push_constant.offset = 0;
m_state->push_constant.size = size;
m_state->push_constant.stageFlags = flags;
}
[[nodiscard]] vk::PipelineColorBlendAttachmentState& PipelineBuilder::BuilderState::addColorAttachment()
@@ -161,18 +161,18 @@ namespace fgl::engine
void PipelineBuilder::setTopology( const vk::PrimitiveTopology primitive_topology )
{
state->assembly_info.topology = primitive_topology;
m_state->assembly_info.topology = primitive_topology;
}
void PipelineBuilder::disableVertexInput()
{
state->vertex_input_descriptions.bindings = {};
state->vertex_input_descriptions.attributes = {};
m_state->vertex_input_descriptions.bindings = {};
m_state->vertex_input_descriptions.attributes = {};
}
void PipelineBuilder::disableCulling()
{
state->rasterization_info.cullMode = vk::CullModeFlagBits::eNone;
m_state->rasterization_info.cullMode = vk::CullModeFlagBits::eNone;
}
AttachmentBuilder PipelineBuilder::addAttachment()
@@ -188,13 +188,13 @@ namespace fgl::engine
void PipelineBuilder::setBindingDescriptions( const std::vector< vk::VertexInputBindingDescription >& descriptions )
{
state->vertex_input_descriptions.bindings = descriptions;
m_state->vertex_input_descriptions.bindings = descriptions;
}
void PipelineBuilder::setAttributeDescriptions( const std::vector< vk::VertexInputAttributeDescription >&
descriptions )
{
state->vertex_input_descriptions.attributes = descriptions;
m_state->vertex_input_descriptions.attributes = descriptions;
}
vk::raii::Pipeline PipelineBuilder::createFromState( BuilderState& state, vk::raii::PipelineLayout& layout )
@@ -261,15 +261,15 @@ namespace fgl::engine
{
// Precheck
{
FGL_ASSERT( state->shaders.fragment, "Pipeline requires fragment shader" );
FGL_ASSERT( state->shaders.vertex, "Pipeline requires vertex shader" );
FGL_ASSERT( m_state->shaders.fragment, "Pipeline requires fragment shader" );
FGL_ASSERT( m_state->shaders.vertex, "Pipeline requires vertex shader" );
}
vk::raii::PipelineLayout layout { createLayout() };
vk::raii::Pipeline pipeline { createFromState( *state, layout ) };
vk::raii::Pipeline pipeline { createFromState( *m_state, layout ) };
return std::make_unique< Pipeline >( std::move( pipeline ), std::move( layout ), std::move( state ) );
return std::make_unique< Pipeline >( std::move( pipeline ), std::move( layout ), std::move( m_state ) );
}
void setGBufferOutputAttachments( PipelineBuilder::BuilderState& config )

View File

@@ -88,7 +88,7 @@ namespace fgl::engine
}
};
std::unique_ptr< BuilderState > state;
std::unique_ptr< BuilderState > m_state;
void setTopology( vk::PrimitiveTopology primitive_topology );
void disableVertexInput();

View File

@@ -54,7 +54,7 @@ namespace fgl::engine
ImGui::Begin( "Composition" );
ImGui::InputInt( "Selection", &m_control.flags );
ImGui::InputInt( "Selection", &m_control.m_flags );
ImGui::End();

View File

@@ -20,9 +20,9 @@ namespace fgl::engine
DirectLighting = 5,
Ambient = 6,
Lh = 7,
MAX
Max
};
int flags { 0 };
int m_flags { 0 };
};
} // namespace fgl::engine

View File

@@ -26,7 +26,7 @@ namespace fgl::engine
GuiSystem( vk::raii::RenderPass& render_pass );
FGL_DELETE_ALL_Ro5( GuiSystem );
FGL_DELETE_ALL_RO5( GuiSystem );
void pass( FrameInfo& info );
};

View File

@@ -72,7 +72,7 @@ namespace fgl::engine
.material_id = primitive.m_material->getID() };
// If the textureless flag is on and we have a texture then skip the primitive.c
if ( tree_flags & IS_TEXTURELESS )
if ( tree_flags & IsTextureless )
{
if ( primitive.m_material != nullptr ) continue;
}

View File

@@ -35,15 +35,15 @@ namespace fgl::engine
enum TreeFilterFlags
{
IS_TEXTURELESS = 1 << 0,
DEFAULT_FLAGS = 0,
IsTextureless = 1 << 0,
DefaultFlags = 0,
};
std::pair< std::vector< vk::DrawIndexedIndirectCommand >, std::vector< ModelMatrixInfo > > getDrawCallsFromTree(
OctTreeNode& root,
const Frustum& frustum,
GameObjectFlagType game_object_flags,
TreeFilterFlags tree_flags = DEFAULT_FLAGS,
TreeFilterFlags tree_flags = DefaultFlags,
std::function< bool( const GameObject& ) > filterFunc = &defaultTrueFunc );
} // namespace fgl::engine
@@ -53,7 +53,7 @@ namespace std
template <>
struct hash< fgl::engine::DrawKey >
{
inline size_t operator()( const fgl::engine::DrawKey& key ) const
inline size_t operator()( const fgl::engine::DrawKey& key ) const noexcept
{
const auto id_hash { std::hash< fgl::engine::TextureID >()( key.first ) };
const auto offset_hash { std::hash< vk::DeviceSize >()( key.second ) };

View File

@@ -22,7 +22,7 @@ namespace fgl::engine
public:
FGL_DELETE_ALL_Ro5( LineDrawer );
FGL_DELETE_ALL_RO5( LineDrawer );
vk::raii::CommandBuffer& setupSystem( FrameInfo& info );
void pass( FrameInfo& info );

View File

@@ -43,18 +43,18 @@ namespace fgl::engine
if ( ImGui::Button( "Reorganize Octtree" ) )
{
const auto start { fgl::clock::now() };
const auto start { fgl::Clock::now() };
number_moved = info.game_objects.reorganize();
const auto end { fgl::clock::now() };
const auto end { fgl::Clock::now() };
const auto time_diff { end - start };
time = std::chrono::duration_cast< std::chrono::microseconds >( time_diff );
}
if ( ImGui::Button( "Recalculate Bounds" ) )
{
const auto start { fgl::clock::now() };
const auto start { fgl::Clock::now() };
info.game_objects.recalculateBounds();
const auto end { fgl::clock::now() };
const auto end { fgl::Clock::now() };
const auto time_diff { end - start };
time = std::chrono::duration_cast< std::chrono::microseconds >( time_diff );
}
@@ -133,7 +133,7 @@ namespace fgl::engine
const auto test_dim { glm::greaterThanEqual( coord.vec(), bounds_center ) };
auto& node_array { std::get< OctTreeNodeArray >( m_node_data ) };
const auto& node_array { std::get< OctTreeNodeArray >( m_node_data ) };
const auto& node { node_array[ test_dim.x ? 1 : 0 ][ test_dim.y ? 1 : 0 ][ test_dim.z ? 1 : 0 ] };
assert( node );
assert( node->canContain( coord ) );
@@ -210,7 +210,7 @@ namespace fgl::engine
const bool is_forward { obj_coordinate.y > center.y };
const bool is_up { obj_coordinate.z > center.z };
std::unique_ptr< OctTreeNode >& node { new_nodes[ is_right ][ is_forward ][ is_up ] };
const std::unique_ptr< OctTreeNode >& node { new_nodes[ is_right ][ is_forward ][ is_up ] };
assert( std::holds_alternative< OctTreeNodeLeaf >( node->m_node_data ) );
std::get< OctTreeNodeLeaf >( node->m_node_data ).emplace_back( std::move( obj ) );
@@ -330,7 +330,7 @@ namespace fgl::engine
/**
*
* @return Returns true if the fit bounding box is larger then the virtual bounds
* @return Returns true if the fit bounding box is larger than the virtual bounds
*/
void OctTreeNode::recalculateBounds()
{
@@ -442,7 +442,7 @@ namespace fgl::engine
GameObject OctTreeNode::extract( const GameObject::GameObjectID id )
{
auto itter { getGameObjectItter( id ) };
const auto itter { getGameObjectItter( id ) };
auto game_object { std::move( *itter ) };
auto& game_objects { std::get< OctTreeNodeLeaf >( this->m_node_data ) };
game_objects.erase( itter );
@@ -517,14 +517,14 @@ namespace fgl::engine
FGL_UNREACHABLE();
}
bool OctTreeNode::isBoundsExpanded()
bool OctTreeNode::isBoundsExpanded() const
{
return m_fit_bounding_box == m_bounds;
/*
const auto fit_points { m_fit_bounding_box.points() };
for ( const auto& p : fit_points )
{
// Return true if a point is outside of the bounds. This indicates that out bounding box is bigger then our bounds.
// Return true if a point is outside the bounds. This indicates that out bounding box is bigger than our bounds.
if ( !m_bounds.contains( p ) ) return true;
}
@@ -542,7 +542,7 @@ namespace fgl::engine
FOR_EACH_OCTTREE_NODE
{
// If true then the bounds were bigger then the inital bounding box. So we should try to combine it with out current bounding box.
// If true then the bounds were bigger then the inital bounding box. So we should try to combine it without current bounding box.
m_fit_bounding_box = m_fit_bounding_box.combine( nodes[ x ][ y ][ z ]->m_fit_bounding_box );
}
@@ -561,7 +561,7 @@ namespace fgl::engine
return;
}
// If true, Then the fit has already been set and we should combine with it
// If true, Then the fit has already been set, and we should combine with it
bool fit_set { false };
for ( const auto& game_object : data )
@@ -593,7 +593,7 @@ namespace fgl::engine
}
}
// Have our parent recalculate it's bounds
// Have our parent recalculate its bounds
// if ( isBoundsExpanded() && m_parent )
if ( m_parent ) m_parent->recalculateBounds();
}

View File

@@ -107,7 +107,7 @@ namespace fgl::engine
std::size_t reorganize();
//! Returns true if the fixed bounding box is larger then the inital bounding box
bool isBoundsExpanded();
bool isBoundsExpanded() const;
void recalculateNodeBounds();

View File

@@ -22,7 +22,7 @@ namespace fgl::engine
assert( std::holds_alternative< QuadTreeNodeArray >( m_node_data ) );
const auto test_dim { glm::greaterThanEqual( pos.vec(), this->m_center.vec() ) };
auto& node_array { std::get< QuadTreeNodeArray >( m_node_data ) };
const auto& node_array { std::get< QuadTreeNodeArray >( m_node_data ) };
const auto& node { node_array[ test_dim.x ][ test_dim.y ] };
assert( node );

View File

@@ -12,18 +12,18 @@ namespace fgl::engine
template < typename T >
class IDPool
{
std::queue< T > unused_queue {};
T current;
std::queue< T > m_unused_queue {};
T m_current;
T getNextID() { return current++; }
T getNextID() { return m_current++; }
public:
IDPool() = delete;
IDPool( const T start_value ) : current( start_value ) {}
IDPool( const T start_value ) : m_current( start_value ) {}
void markUnused( const T value ) { unused_queue.push( value ); }
void markUnused( const T value ) { m_unused_queue.push( value ); }
constexpr static bool ALWAYS_NEW_ID { true };
@@ -35,12 +35,12 @@ namespace fgl::engine
}
else
{
if ( unused_queue.empty() )
if ( m_unused_queue.empty() )
return getNextID();
else
{
const auto value { unused_queue.front() };
unused_queue.pop();
const auto value { m_unused_queue.front() };
m_unused_queue.pop();
return value;
}
}