Cleanup of other code and performance profiling with better logging
This commit is contained in:
@@ -5,11 +5,11 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "engine/EngineContext.hpp"
|
||||
#include "engine/logging.hpp"
|
||||
#include "engine/logging/logging.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
spdlog::set_level( spdlog::level::debug );
|
||||
fgl::engine::log::set_level( spdlog::level::debug );
|
||||
|
||||
fgl::engine::EngineContext engine_ctx {};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "EngineContext.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <tracy/TracyC.h>
|
||||
#include <tracy/TracyVulkan.hpp>
|
||||
|
||||
#include <chrono>
|
||||
@@ -27,6 +28,7 @@ namespace fgl::engine
|
||||
|
||||
EngineContext::EngineContext()
|
||||
{
|
||||
ZoneScoped;
|
||||
using namespace fgl::literals::size_literals;
|
||||
initGlobalStagingBuffer( 512_MiB );
|
||||
#if ENABLE_IMGUI
|
||||
@@ -39,6 +41,7 @@ namespace fgl::engine
|
||||
|
||||
void EngineContext::run()
|
||||
{
|
||||
TracyCZoneN( TRACY_PrepareEngine, "Inital Run", true );
|
||||
std::cout << "Starting main loop run" << std::endl;
|
||||
using namespace fgl::literals::size_literals;
|
||||
Buffer global_ubo_buffer { 512_KiB,
|
||||
@@ -109,6 +112,8 @@ namespace fgl::engine
|
||||
|
||||
const auto old_aspect_ratio { m_renderer.getAspectRatio() };
|
||||
|
||||
TracyCZoneEnd( TRACY_PrepareEngine );
|
||||
|
||||
while ( !m_window.shouldClose() )
|
||||
{
|
||||
ZoneScopedN( "Poll" );
|
||||
@@ -196,6 +201,7 @@ namespace fgl::engine
|
||||
|
||||
void EngineContext::loadGameObjects()
|
||||
{
|
||||
ZoneScoped;
|
||||
std::cout << "Loading game objects" << std::endl;
|
||||
auto command_buffer { Device::getInstance().beginSingleTimeCommands() };
|
||||
|
||||
@@ -254,6 +260,7 @@ namespace fgl::engine
|
||||
}*/
|
||||
|
||||
{
|
||||
ZoneScopedN( "Load phyiscs test" );
|
||||
std::vector< std::shared_ptr< Model > > models { Model::createModelsFromScene(
|
||||
Device::getInstance(),
|
||||
"models/PhysicsTest.glb",
|
||||
@@ -275,6 +282,7 @@ namespace fgl::engine
|
||||
}
|
||||
|
||||
{
|
||||
ZoneScopedN( "Load terrain" );
|
||||
auto model {
|
||||
generateTerrainModel( m_terrain_system.getVertexBuffer(), m_terrain_system.getIndexBuffer() )
|
||||
};
|
||||
@@ -380,5 +388,4 @@ namespace fgl::engine
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace fgl::engine
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "GameObject.hpp"
|
||||
|
||||
#include "engine/gui/helpers.hpp"
|
||||
#include "engine/gui/safe_include.hpp"
|
||||
#include "engine/model/Model.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
@@ -11,10 +13,30 @@ namespace fgl::engine
|
||||
|
||||
GameObject GameObject::createGameObject()
|
||||
{
|
||||
static ID current_id { 0 };
|
||||
static GameObjectID current_id { 0 };
|
||||
return { current_id++ };
|
||||
}
|
||||
|
||||
void GameObject::drawImGui()
|
||||
{
|
||||
ImGui::InputText( "Name", &this->name );
|
||||
|
||||
// Transform - Position
|
||||
WorldCoordinate& translation { this->m_transform.translation };
|
||||
gui::dragFloat3( "Position", translation.vec() );
|
||||
|
||||
Rotation& rotation { this->m_transform.rotation };
|
||||
gui::dragFloat3Rot( "Rotation", rotation );
|
||||
|
||||
auto& scale { this->m_transform.scale };
|
||||
gui::dragFloat3( "Scale", scale );
|
||||
|
||||
for ( const GameObjectComponentBase* component : components )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::World > GameObject::getBoundingBox() const
|
||||
{
|
||||
assert( this->m_transform.translation.vec() != constants::DEFAULT_VEC3 );
|
||||
|
||||
@@ -36,29 +36,86 @@ namespace fgl::engine
|
||||
TEXTURELESS = 1 << 0,
|
||||
};
|
||||
|
||||
struct ComponentImGuiInterface
|
||||
{
|
||||
virtual void drawImGui() = 0;
|
||||
virtual ~ComponentImGuiInterface() = default;
|
||||
};
|
||||
|
||||
struct GameObjectComponentBase
|
||||
{
|
||||
using ComponentID = std::uint8_t;
|
||||
virtual ComponentID id() const = 0;
|
||||
virtual std::string_view name() const = 0;
|
||||
|
||||
virtual ~GameObjectComponentBase() = default;
|
||||
};
|
||||
|
||||
template < GameObjectComponentBase::ComponentID T_ID >
|
||||
struct GameObjectComponent : ComponentImGuiInterface, GameObjectComponentBase
|
||||
{
|
||||
constexpr static ComponentID ID { T_ID };
|
||||
|
||||
virtual ComponentID id() const override final { return ID; }
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
concept is_component = requires( T t ) {
|
||||
std::is_base_of_v< T, GameObjectComponentBase >;
|
||||
{
|
||||
t.ID
|
||||
} -> std::same_as< GameObjectComponentBase::ComponentID >;
|
||||
};
|
||||
|
||||
class ModelComponent final : public GameObjectComponent< 1 >
|
||||
{
|
||||
std::shared_ptr<Model> m_model;
|
||||
|
||||
public:
|
||||
|
||||
void drawImGui() override;
|
||||
std::string_view name() const override;
|
||||
~ModelComponent() override;
|
||||
};
|
||||
|
||||
class GameObject
|
||||
{
|
||||
public:
|
||||
|
||||
using ID = unsigned int;
|
||||
using Map = std::unordered_map< ID, GameObject >;
|
||||
using GameObjectID = unsigned int;
|
||||
using Map = std::unordered_map< GameObjectID, GameObject >;
|
||||
|
||||
static constexpr ID INVALID_ID { std::numeric_limits< ID >::max() };
|
||||
static constexpr GameObjectID INVALID_ID { std::numeric_limits< GameObjectID >::max() };
|
||||
|
||||
ID m_id { INVALID_ID };
|
||||
GameObjectID m_id { INVALID_ID };
|
||||
GameObjectFlagType object_flags { GameObjectFlagMask::MASK_DEFAULT };
|
||||
TransformComponent m_transform {};
|
||||
|
||||
std::vector< GameObjectComponentBase* > components {};
|
||||
|
||||
std::shared_ptr< Model > m_model { nullptr };
|
||||
std::string name { "Unnamed Game Object" };
|
||||
|
||||
private:
|
||||
|
||||
GameObject( ID obj_id ) : m_id( obj_id ) {}
|
||||
GameObject( GameObjectID obj_id ) : m_id( obj_id ) {}
|
||||
|
||||
GameObject() = delete;
|
||||
|
||||
public:
|
||||
|
||||
template < typename T >
|
||||
requires is_component< T >
|
||||
bool hasComponent()
|
||||
{
|
||||
for ( const GameObjectComponentBase* comp : components )
|
||||
{
|
||||
if ( comp->id() == T::ID ) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
GameObject( const GameObject& other ) = delete;
|
||||
GameObject& operator=( const GameObject& other ) = delete;
|
||||
|
||||
@@ -73,7 +130,9 @@ namespace fgl::engine
|
||||
|
||||
static GameObject createGameObject();
|
||||
|
||||
inline ID getId() const { return m_id; }
|
||||
inline GameObjectID getId() const { return m_id; }
|
||||
|
||||
void drawImGui();
|
||||
};
|
||||
|
||||
// static_assert( offsetof( GameObject, hot_limter ) < 64, "Hot limit reached" );
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "BufferVector.hpp"
|
||||
#include "HostVector.hpp"
|
||||
#include "engine/logging.hpp"
|
||||
#include "engine/logging/logging.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace fgl::engine
|
||||
|
||||
DeviceVector( Buffer& buffer, const std::uint32_t count = 1 ) : BufferVector( buffer, count, sizeof( T ) )
|
||||
{
|
||||
spdlog::debug( "Creating DeviceVector of size {}", count );
|
||||
log::debug( "Creating DeviceVector of size {}", count );
|
||||
assert( count != 0 && "BufferSuballocationVector::BufferSuballocationVector() called with count == 0" );
|
||||
}
|
||||
|
||||
|
||||
38
src/engine/logging/formatters/filesystem.cpp
Normal file
38
src/engine/logging/formatters/filesystem.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by kj16609 on 6/5/24.
|
||||
//
|
||||
|
||||
#include "filesystem.hpp"
|
||||
|
||||
auto format_ns::formatter< std::filesystem::path >::format( const std::filesystem::path& path, format_context& ctx )
|
||||
const -> decltype( ctx.out() )
|
||||
{
|
||||
if ( print_canonical && std::filesystem::exists( path ) )
|
||||
{
|
||||
if ( print_exists )
|
||||
return format_ns::format_to(
|
||||
ctx.out(),
|
||||
"[\"{}\", (Canonical: \"{}\") Exists: \"{}\"]",
|
||||
path.string(),
|
||||
std::filesystem::canonical( path ).string(),
|
||||
std::filesystem::exists( path ) ? "True" : "False" );
|
||||
else
|
||||
return format_ns::format_to(
|
||||
ctx.out(), "[\"{}\" (Canonical: \"{}\")]", path.string(), std::filesystem::canonical( path ).string() );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( print_exists )
|
||||
return format_ns::
|
||||
format_to( ctx.out(), "[\"{}\"]", path.string(), std::filesystem::exists( path ) ? "True" : "False" );
|
||||
else
|
||||
return format_ns::format_to( ctx.out(), "[\"{}\"]", path.string() );
|
||||
}
|
||||
}
|
||||
|
||||
auto format_ns::formatter< std::source_location >::format( const std::source_location& loc, format_context& ctx ) const
|
||||
-> decltype( ctx.out() )
|
||||
{
|
||||
return format_ns::
|
||||
format_to( ctx.out(), "File: {}:{}\n\tFunction: {}\n\t", loc.file_name(), loc.line(), loc.function_name() );
|
||||
}
|
||||
79
src/engine/logging/formatters/filesystem.hpp
Normal file
79
src/engine/logging/formatters/filesystem.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Created by kj16609 on 6/5/24.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HAVE_STD_FORMAT
|
||||
#include <format>
|
||||
namespace format_ns = std;
|
||||
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
#pragma GCC diagnostic ignored "-Wswitch-default"
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#endif
|
||||
|
||||
#include <fmt/format.h>
|
||||
namespace format_ns = fmt;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#include <filesystem>
|
||||
#include <source_location>
|
||||
|
||||
template <>
|
||||
struct format_ns::formatter< std::filesystem::path >
|
||||
{
|
||||
bool print_canonical { false };
|
||||
bool print_exists { false };
|
||||
|
||||
constexpr format_parse_context::iterator parse( format_parse_context& ctx )
|
||||
{
|
||||
//Check if ctx has 'c' 'ce' or 'e' and return the itterator after it
|
||||
auto idx { ctx.begin() };
|
||||
const auto end { ctx.end() };
|
||||
|
||||
if ( idx != end && *idx == 'c' )
|
||||
{
|
||||
print_canonical = true;
|
||||
++idx;
|
||||
}
|
||||
|
||||
if ( idx != end && *idx == 'e' )
|
||||
{
|
||||
print_exists = true;
|
||||
++idx;
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
format_context::iterator format( const std::filesystem::path& path, format_context& ctx ) const;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct format_ns::formatter< std::source_location >
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct format_ns::formatter< format_ns::format_string<> >
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
#include <spdlog/spdlog.h>
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "formatters/filesystem.hpp"
|
||||
|
||||
namespace fgl::engine::log
|
||||
{
|
||||
using namespace ::spdlog;
|
||||
}
|
||||
@@ -68,6 +68,7 @@ namespace fgl::engine
|
||||
std::vector< std::byte >
|
||||
generatePerlinImage( const glm::vec< 2, std::size_t > size, const int octives, const std::size_t seed )
|
||||
{
|
||||
ZoneScoped;
|
||||
constexpr std::size_t channel_count { 4 }; // RGBA
|
||||
std::vector< std::byte > data { size.x * size.y * channel_count };
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace fgl::engine
|
||||
|
||||
std::vector< vk::DrawIndexedIndirectCommand > Model::buildParameters( const std::vector< Primitive >& primitives )
|
||||
{
|
||||
ZoneScoped;
|
||||
std::vector< vk::DrawIndexedIndirectCommand > draw_parameters {};
|
||||
draw_parameters.reserve( primitives.size() );
|
||||
|
||||
@@ -40,6 +41,7 @@ namespace fgl::engine
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > Model::buildBoundingBox( const std::vector< Primitive >& primitives )
|
||||
{
|
||||
ZoneScoped;
|
||||
assert( primitives.size() > 0 );
|
||||
if ( primitives.size() <= 0 ) return {};
|
||||
|
||||
@@ -52,6 +54,7 @@ namespace fgl::engine
|
||||
|
||||
std::vector< vk::DrawIndexedIndirectCommand > Model::getDrawCommand( const std::uint32_t index ) const
|
||||
{
|
||||
ZoneScoped;
|
||||
std::vector< vk::DrawIndexedIndirectCommand > draw_commands {};
|
||||
draw_commands.reserve( m_primitives.size() );
|
||||
for ( const auto& cmd : m_draw_parameters )
|
||||
@@ -85,6 +88,7 @@ namespace fgl::engine
|
||||
std::shared_ptr< Model > Model::
|
||||
createModel( Device& device, const std::filesystem::path& path, Buffer& vertex_buffer, Buffer& index_buffer )
|
||||
{
|
||||
ZoneScoped;
|
||||
std::cout << "Creating model: " << path << std::endl;
|
||||
ModelBuilder builder { vertex_buffer, index_buffer };
|
||||
builder.loadModel( path );
|
||||
@@ -101,6 +105,7 @@ namespace fgl::engine
|
||||
std::vector< std::shared_ptr< Model > > Model::createModelsFromScene(
|
||||
Device& device, const std::filesystem::path& path, Buffer& vertex_buffer, Buffer& index_buffer )
|
||||
{
|
||||
ZoneScoped;
|
||||
std::cout << "Loading scene: " << path << std::endl;
|
||||
SceneBuilder builder { vertex_buffer, index_buffer };
|
||||
builder.loadScene( path );
|
||||
@@ -117,6 +122,7 @@ namespace fgl::engine
|
||||
Buffer& vertex_buffer,
|
||||
Buffer& index_buffer )
|
||||
{
|
||||
ZoneScoped;
|
||||
ModelBuilder builder { vertex_buffer, index_buffer };
|
||||
builder.loadVerts( std::move( verts ), std::move( indicies ) );
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace fgl::engine
|
||||
|
||||
void ModelBuilder::loadModel( const std::filesystem::path& filepath )
|
||||
{
|
||||
ZoneScoped;
|
||||
if ( filepath.extension() == ".obj" )
|
||||
{
|
||||
loadObj( filepath );
|
||||
@@ -25,6 +26,7 @@ namespace fgl::engine
|
||||
|
||||
void ModelBuilder::loadVerts( std::vector< Vertex > verts, std::vector< std::uint32_t > indicies )
|
||||
{
|
||||
ZoneScoped;
|
||||
VertexBufferSuballocation vertex_suballoc { this->m_vertex_buffer, verts };
|
||||
IndexBufferSuballocation index_suballoc { this->m_index_buffer, std::move( indicies ) };
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "objectloaders/tiny_gltf.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include <engine/logging.hpp>
|
||||
#include <engine/logging/logging.hpp>
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -24,6 +24,7 @@ namespace fgl::engine
|
||||
|
||||
int SceneBuilder::getTexcoordCount( const tinygltf::Primitive& prim ) const
|
||||
{
|
||||
ZoneScoped;
|
||||
int counter { 0 };
|
||||
for ( const auto& [ key, value ] : prim.attributes )
|
||||
{
|
||||
@@ -35,6 +36,7 @@ namespace fgl::engine
|
||||
template < typename T >
|
||||
std::vector< T > extractData( const tinygltf::Model& model, const tinygltf::Accessor& accessor )
|
||||
{
|
||||
ZoneScoped;
|
||||
if ( accessor.sparse.isSparse )
|
||||
{
|
||||
//Sparse loading required
|
||||
@@ -85,8 +87,7 @@ namespace fgl::engine
|
||||
|
||||
if ( T_SIZE != copy_size )
|
||||
throw std::runtime_error(
|
||||
std::string( "Accessor copy values not matching sizeof(T): sizeof(" )
|
||||
+ std::string( typeid( T ).name() ) + ") == " + std::to_string( T_SIZE )
|
||||
std::string( "Accessor copy values not matching sizeof(T): sizeof(T) == " ) + std::to_string( T_SIZE )
|
||||
+ " vs copy_size = " + std::to_string( copy_size ) );
|
||||
|
||||
const auto real_size { copy_size * accessor.count };
|
||||
@@ -101,6 +102,7 @@ namespace fgl::engine
|
||||
std::vector< std::uint32_t > SceneBuilder::
|
||||
extractIndicies( const tinygltf::Primitive& prim, const tinygltf::Model& model )
|
||||
{
|
||||
ZoneScoped;
|
||||
const auto& indicies_accessor { model.accessors.at( prim.indices ) };
|
||||
|
||||
if ( indicies_accessor.componentType == TINYGLTF_COMPONENT_TYPE_INT )
|
||||
@@ -125,11 +127,13 @@ namespace fgl::engine
|
||||
const tinygltf::Accessor& SceneBuilder::getAccessorForAttribute(
|
||||
const tinygltf::Primitive& prim, const tinygltf::Model& root, const std::string attrib ) const
|
||||
{
|
||||
ZoneScoped;
|
||||
return root.accessors.at( prim.attributes.at( attrib ) );
|
||||
}
|
||||
|
||||
Texture SceneBuilder::loadTexture( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
const auto mat_idx { prim.material };
|
||||
if ( mat_idx == -1 )
|
||||
{
|
||||
@@ -141,7 +145,7 @@ namespace fgl::engine
|
||||
|
||||
for ( const auto& [ key, value ] : material.values )
|
||||
{
|
||||
spdlog::debug( "Parsing texture for key {}", key );
|
||||
log::debug( "Parsing texture for key {}", key );
|
||||
}
|
||||
|
||||
//TODO:
|
||||
@@ -150,6 +154,7 @@ namespace fgl::engine
|
||||
|
||||
std::vector< std::shared_ptr< Model > > SceneBuilder::getModels()
|
||||
{
|
||||
ZoneScoped;
|
||||
std::vector< std::shared_ptr< Model > > new_models { std::move( models ) };
|
||||
|
||||
return new_models;
|
||||
@@ -158,6 +163,7 @@ namespace fgl::engine
|
||||
std::vector< glm::vec3 > SceneBuilder::
|
||||
extractPositionInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
const tinygltf::Accessor& accessor { getAccessorForAttribute( prim, root, "POSITION" ) };
|
||||
|
||||
return extractData< glm::vec3 >( root, accessor );
|
||||
@@ -166,6 +172,7 @@ namespace fgl::engine
|
||||
std::vector< glm::vec3 > SceneBuilder::
|
||||
extractNormalInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
if ( !hasAttribute( prim, "NORMAL" ) ) return {};
|
||||
const tinygltf::Accessor& accessor { getAccessorForAttribute( prim, root, "NORMAL" ) };
|
||||
|
||||
@@ -174,7 +181,8 @@ namespace fgl::engine
|
||||
|
||||
std::vector< glm::vec2 > SceneBuilder::extractUVInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
spdlog::debug( "Extracting UV info" );
|
||||
ZoneScoped;
|
||||
log::debug( "Extracting UV info" );
|
||||
|
||||
//TODO: Figure out how I can use multiple textures for various things.
|
||||
if ( !hasAttribute( prim, "TEXCOORD_0" ) ) return {};
|
||||
@@ -186,13 +194,15 @@ namespace fgl::engine
|
||||
|
||||
bool SceneBuilder::hasAttribute( const tinygltf::Primitive& prim, const std::string_view str )
|
||||
{
|
||||
ZoneScoped;
|
||||
return prim.attributes.contains( std::string( str ) );
|
||||
}
|
||||
|
||||
std::vector< Vertex > SceneBuilder::
|
||||
extractVertexInfo( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
spdlog::debug( "Extracting vert info" );
|
||||
ZoneScoped;
|
||||
log::debug( "Extracting vert info" );
|
||||
const auto pos { extractPositionInfo( prim, root ) };
|
||||
|
||||
std::vector< Vertex > verts {};
|
||||
@@ -219,7 +229,7 @@ namespace fgl::engine
|
||||
verts.emplace_back( vert );
|
||||
}
|
||||
|
||||
spdlog::debug(
|
||||
log::debug(
|
||||
"Found {} verts.\n\t- Has UV info: {}\n\t- Has normals: {}",
|
||||
verts.size(),
|
||||
has_uv ? "Yes" : "No",
|
||||
@@ -230,12 +240,13 @@ namespace fgl::engine
|
||||
|
||||
Primitive SceneBuilder::loadPrimitive( const tinygltf::Primitive& prim, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
std::string att_str;
|
||||
for ( const auto& attrib : prim.attributes )
|
||||
{
|
||||
att_str += "Attribute: " + attrib.first + "\n";
|
||||
}
|
||||
spdlog::debug( "Attributes for primitive:\n{}", att_str );
|
||||
log::debug( "Attributes for primitive:\n{}", att_str );
|
||||
|
||||
const bool has_normal { hasAttribute( prim, "NORMAL" ) };
|
||||
const bool has_position { hasAttribute( prim, "POSITION" ) };
|
||||
@@ -278,7 +289,7 @@ namespace fgl::engine
|
||||
}
|
||||
default:
|
||||
{
|
||||
spdlog::error( "Unsupported mode for primtiive loading: {}", prim.mode );
|
||||
log::error( "Unsupported mode for primtiive loading: {}", prim.mode );
|
||||
throw std::runtime_error( "Unsupported mode for primitive loading" );
|
||||
}
|
||||
}
|
||||
@@ -288,6 +299,7 @@ namespace fgl::engine
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > createModelBoundingBox( const std::vector< Primitive >& primitives )
|
||||
{
|
||||
ZoneScoped;
|
||||
if ( primitives.size() <= 0 ) return {};
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > box { primitives.at( 0 ).m_bounding_box };
|
||||
@@ -299,10 +311,11 @@ namespace fgl::engine
|
||||
|
||||
std::shared_ptr< Model > SceneBuilder::loadModel( const int mesh_idx, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
const auto mesh { root.meshes[ mesh_idx ] };
|
||||
const auto& primitives { mesh.primitives };
|
||||
|
||||
spdlog::debug( "Mesh idx {} has {} primitives", mesh_idx, primitives.size() );
|
||||
log::debug( "Mesh idx {} has {} primitives", mesh_idx, primitives.size() );
|
||||
|
||||
std::vector< Primitive > finished_primitives {};
|
||||
|
||||
@@ -312,7 +325,7 @@ namespace fgl::engine
|
||||
finished_primitives.emplace_back( std::move( primitive ) );
|
||||
}
|
||||
|
||||
spdlog::debug( "Finished loading model with {} primitives", finished_primitives.size() );
|
||||
log::debug( "Finished loading model with {} primitives", finished_primitives.size() );
|
||||
|
||||
const auto bounding_box { createModelBoundingBox( finished_primitives ) };
|
||||
|
||||
@@ -321,14 +334,15 @@ namespace fgl::engine
|
||||
|
||||
void SceneBuilder::handleNode( const int node_idx, const tinygltf::Model& root )
|
||||
{
|
||||
ZoneScoped;
|
||||
const auto& node { root.nodes[ node_idx ] };
|
||||
spdlog::debug( "Handling node: Index:{} Name:\"{}\"", node_idx, node.name );
|
||||
log::debug( "Handling node: Index:{} Name:\"{}\"", node_idx, node.name );
|
||||
|
||||
const auto mesh_idx { node.mesh };
|
||||
const auto skin_idx { node.skin };
|
||||
|
||||
spdlog::debug( "Mesh IDX: {}", mesh_idx );
|
||||
spdlog::debug( "Skin IDX: {}", skin_idx );
|
||||
log::debug( "Mesh IDX: {}", mesh_idx );
|
||||
log::debug( "Skin IDX: {}", skin_idx );
|
||||
|
||||
std::shared_ptr< Model > model { loadModel( mesh_idx, root ) };
|
||||
|
||||
@@ -340,9 +354,10 @@ namespace fgl::engine
|
||||
|
||||
void SceneBuilder::handleScene( const tinygltf::Scene& scene, const tinygltf::Model& root )
|
||||
{
|
||||
spdlog::debug( "Handling scene: ", scene.name );
|
||||
ZoneScoped;
|
||||
log::debug( "Handling scene: ", scene.name );
|
||||
|
||||
spdlog::debug( "Scene has {} nodes", scene.nodes.size() );
|
||||
log::debug( "Scene has {} nodes", scene.nodes.size() );
|
||||
for ( const auto node_idx : scene.nodes )
|
||||
{
|
||||
handleNode( node_idx, root );
|
||||
@@ -351,6 +366,7 @@ namespace fgl::engine
|
||||
|
||||
void SceneBuilder::loadScene( const std::filesystem::path path )
|
||||
{
|
||||
ZoneScoped;
|
||||
if ( !std::filesystem::exists( path ) ) throw std::runtime_error( "Failed to find scene at filepath" );
|
||||
|
||||
tinygltf::TinyGLTF loader {};
|
||||
@@ -366,13 +382,13 @@ namespace fgl::engine
|
||||
|
||||
if ( !err.empty() )
|
||||
{
|
||||
spdlog::error( "Error loading model {}: \"{}\"", path.string(), err );
|
||||
log::error( "Error loading model {}: \"{}\"", path.string(), err );
|
||||
throw std::runtime_error( err );
|
||||
}
|
||||
|
||||
if ( !warn.empty() )
|
||||
{
|
||||
spdlog::warn( "Warning loading model {}: \"{}\"", path.string(), warn );
|
||||
log::warn( "Warning loading model {}: \"{}\"", path.string(), warn );
|
||||
}
|
||||
|
||||
const auto scenes { gltf_model.scenes };
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace fgl::engine
|
||||
template < typename T >
|
||||
std::vector< T > extractData( const tinygltf::Model& model, const tinygltf::Accessor& accessor )
|
||||
{
|
||||
ZoneScoped;
|
||||
if ( accessor.sparse.isSparse )
|
||||
{
|
||||
//Sparse loading required
|
||||
@@ -71,8 +72,7 @@ namespace fgl::engine
|
||||
|
||||
if ( T_SIZE != copy_size )
|
||||
throw std::runtime_error(
|
||||
std::string( "Accessor copy values not matching sizeof(T): sizeof(" )
|
||||
+ std::string( typeid( T ).name() ) + ") == " + std::to_string( T_SIZE )
|
||||
std::string( "Accessor copy values not matching sizeof(T): sizeof(T) == " ) + std::to_string( T_SIZE )
|
||||
+ " vs copy_size = " + std::to_string( copy_size ) );
|
||||
|
||||
const auto real_size { copy_size * accessor.count };
|
||||
@@ -86,6 +86,7 @@ namespace fgl::engine
|
||||
|
||||
void ModelBuilder::loadGltf( const std::filesystem::path& filepath )
|
||||
{
|
||||
ZoneScoped;
|
||||
std::cout << "Loading gltf model " << filepath << std::endl;
|
||||
|
||||
if ( !std::filesystem::exists( filepath ) ) throw std::runtime_error( "File does not exist" );
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "engine/logging.hpp"
|
||||
#include "engine/logging/logging.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace fgl::engine
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::critical( "Failed to load shader module {}. Path not found", path.string() );
|
||||
log::critical( "Failed to load shader module {}. Path not found", path.string() );
|
||||
throw std::runtime_error( "Failed to load shader module. Path not found" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingBox.hpp"
|
||||
#include "engine/primitives/boxes/AxisAlignedBoundingCube.hpp"
|
||||
#include "engine/primitives/boxes/OrientedBoundingBox.hpp"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
@@ -173,6 +172,7 @@ namespace fgl::engine
|
||||
|
||||
void imGuiFrustumSettings()
|
||||
{
|
||||
/*
|
||||
#if ENABLE_IMGUI
|
||||
//Check if any of the box's points are inside the frustum
|
||||
if ( ImGui::CollapsingHeader( "Frustum intersection settings" ) )
|
||||
@@ -189,6 +189,7 @@ namespace fgl::engine
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
@@ -74,13 +74,13 @@ namespace fgl::engine
|
||||
|
||||
Rotation( const glm::quat other ) : glm::quat( other ) {}
|
||||
|
||||
auto pitch() { return RotationModifier< RotationModifierType::Pitch >( *this ); }
|
||||
FGL_FORCE_INLINE_FLATTEN auto pitch() { return RotationModifier< RotationModifierType::Pitch >( *this ); }
|
||||
|
||||
auto roll() { return RotationModifier< RotationModifierType::Roll >( *this ); }
|
||||
FGL_FORCE_INLINE_FLATTEN auto roll() { return RotationModifier< RotationModifierType::Roll >( *this ); }
|
||||
|
||||
auto yaw() { return RotationModifier< RotationModifierType::Yaw >( *this ); }
|
||||
FGL_FORCE_INLINE_FLATTEN auto yaw() { return RotationModifier< RotationModifierType::Yaw >( *this ); }
|
||||
|
||||
float pitch() const
|
||||
FGL_FORCE_INLINE float pitch() const
|
||||
{
|
||||
//TODO: Ask entry to explain this stuff
|
||||
const float sinr_cosp { 2.0f * ( w * x + y * z ) };
|
||||
@@ -88,14 +88,14 @@ namespace fgl::engine
|
||||
return std::atan2( sinr_cosp, cosr_cosp );
|
||||
}
|
||||
|
||||
float roll() const
|
||||
FGL_FORCE_INLINE float roll() const
|
||||
{
|
||||
const float sinp { glm::sqrt( 1.0f + 2.0f * ( w * y - x * z ) ) };
|
||||
const float cosp { glm::sqrt( 1.0f - 2.0f * ( w * y - x * z ) ) };
|
||||
return 2.0f * std::atan2( sinp, cosp ) - ( std::numbers::pi_v< float > / 2.0f );
|
||||
}
|
||||
|
||||
float yaw() const
|
||||
FGL_FORCE_INLINE float yaw() const
|
||||
{
|
||||
const float siny_cosp { 2.0f * ( w * z + x * y ) };
|
||||
const float cosy_cosp { 1.0f - 2.0f * ( y * y + z * z ) };
|
||||
@@ -120,7 +120,7 @@ namespace fgl::engine
|
||||
};
|
||||
|
||||
template < RotationModifierType ModifierType >
|
||||
RotationModifier< ModifierType >::operator float() const
|
||||
FGL_FORCE_INLINE_FLATTEN RotationModifier< ModifierType >::operator float() const
|
||||
{
|
||||
switch ( ModifierType )
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "engine/logging.hpp"
|
||||
#include "engine/logging/logging.hpp"
|
||||
#include "engine/model/Vertex.hpp"
|
||||
#include "engine/primitives/lines/LineSegment.hpp"
|
||||
#include "engine/primitives/points/Coordinate.hpp"
|
||||
@@ -238,7 +238,7 @@ namespace fgl::engine
|
||||
|
||||
OrientedBoundingBox< CoordinateSpace::Model > generateBoundingFromVerts( const std::vector< Vertex >& verts )
|
||||
{
|
||||
spdlog::debug( "Generating bounding box for {} verts", verts.size() );
|
||||
log::debug( "Generating bounding box for {} verts", verts.size() );
|
||||
// neg (min)
|
||||
glm::vec3 top_right_forward { verts[ 0 ].m_position };
|
||||
// pos (max)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "engine/logging.hpp"
|
||||
#include "engine/logging/logging.hpp"
|
||||
|
||||
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT { nullptr };
|
||||
PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT { nullptr };
|
||||
@@ -22,23 +22,24 @@ static VKAPI_ATTR vk::Bool32 VKAPI_CALL debugCallback(
|
||||
[[maybe_unused]] void* pUserData )
|
||||
{
|
||||
using Bits = VkDebugUtilsMessageSeverityFlagBitsEXT;
|
||||
using namespace fgl::engine;
|
||||
|
||||
if ( pCallbackData->flags & Bits::VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT )
|
||||
{
|
||||
spdlog::info( pCallbackData->pMessage );
|
||||
log::info( pCallbackData->pMessage );
|
||||
}
|
||||
else if ( pCallbackData->flags & Bits::VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT )
|
||||
{
|
||||
spdlog::warn( pCallbackData->pMessage );
|
||||
log::warn( pCallbackData->pMessage );
|
||||
}
|
||||
else if ( pCallbackData->flags & Bits::VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT )
|
||||
{
|
||||
spdlog::error( pCallbackData->pMessage );
|
||||
log::error( pCallbackData->pMessage );
|
||||
std::abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
//spdlog::critical( "Unknown severity message: {}", pCallbackData->pMessage );
|
||||
//log::critical( "Unknown severity message: {}", pCallbackData->pMessage );
|
||||
//std::abort();
|
||||
}
|
||||
|
||||
@@ -570,6 +571,7 @@ namespace fgl::engine
|
||||
|
||||
vk::CommandBuffer Device::beginSingleTimeCommands()
|
||||
{
|
||||
ZoneScoped;
|
||||
vk::CommandBufferAllocateInfo allocInfo {};
|
||||
allocInfo.level = vk::CommandBufferLevel::ePrimary;
|
||||
allocInfo.commandPool = m_commandPool;
|
||||
@@ -589,6 +591,7 @@ namespace fgl::engine
|
||||
|
||||
void Device::endSingleTimeCommands( vk::CommandBuffer commandBuffer )
|
||||
{
|
||||
ZoneScoped;
|
||||
vkEndCommandBuffer( commandBuffer );
|
||||
|
||||
vk::SubmitInfo submitInfo {};
|
||||
@@ -606,6 +609,7 @@ namespace fgl::engine
|
||||
void Device::
|
||||
copyBufferToImage( vk::Buffer buffer, vk::Image image, uint32_t width, uint32_t height, uint32_t layerCount )
|
||||
{
|
||||
ZoneScoped;
|
||||
vk::CommandBuffer commandBuffer { beginSingleTimeCommands() };
|
||||
|
||||
vk::BufferImageCopy region {};
|
||||
|
||||
@@ -4,14 +4,12 @@
|
||||
|
||||
#include "EntityRendererSystem.hpp"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <tracy/TracyC.h>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "DrawPair.hpp"
|
||||
#include "engine/debug/drawers.hpp"
|
||||
#include "engine/literals/size.hpp"
|
||||
#include "engine/tree/octtree/OctTreeNode.hpp"
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "imgui/backends/imgui_impl_vulkan.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#include "engine/logging/logging.hpp"
|
||||
|
||||
namespace fgl::engine
|
||||
{
|
||||
|
||||
@@ -53,6 +55,7 @@ namespace fgl::engine
|
||||
Texture Texture::loadFromFile( const std::filesystem::path& path )
|
||||
{
|
||||
ZoneScoped;
|
||||
log::debug( "Loading texture: {}", path );
|
||||
//TODO: Make some way of cleaning the map when loading textures
|
||||
|
||||
if ( texture_map.contains( path.string() ) )
|
||||
@@ -74,11 +77,42 @@ namespace fgl::engine
|
||||
|
||||
texture_map.emplace( path.string(), tex.m_handle );
|
||||
|
||||
log::debug( "Loaded texture at {} with res {}x{}", path, tex.getExtent().width, tex.getExtent().height );
|
||||
|
||||
return std::move( tex );
|
||||
}
|
||||
|
||||
void Texture::drawImGui( vk::Extent2D extent )
|
||||
{
|
||||
if ( this->m_handle->m_imgui_set == VK_NULL_HANDLE ) createImGuiSet();
|
||||
|
||||
if ( extent == vk::Extent2D() )
|
||||
{
|
||||
extent = getExtent();
|
||||
}
|
||||
|
||||
const ImVec2 imgui_size { static_cast< float >( extent.width ), static_cast< float >( extent.height ) };
|
||||
|
||||
ImGui::Image( static_cast< ImTextureID >( getImGuiDescriptorSet() ), imgui_size );
|
||||
}
|
||||
|
||||
bool Texture::drawImGuiButton( vk::Extent2D extent )
|
||||
{
|
||||
if ( this->m_handle->m_imgui_set == VK_NULL_HANDLE ) createImGuiSet();
|
||||
|
||||
if ( extent == vk::Extent2D() )
|
||||
{
|
||||
extent = getExtent();
|
||||
}
|
||||
|
||||
const ImVec2 imgui_size { static_cast< float >( extent.width ), static_cast< float >( extent.height ) };
|
||||
|
||||
return ImGui::ImageButton( static_cast< ImTextureID >( getImGuiDescriptorSet() ), imgui_size );
|
||||
}
|
||||
|
||||
Texture Texture::generateFromPerlinNoise( int x_size, int y_size, std::size_t seed )
|
||||
{
|
||||
ZoneScoped;
|
||||
const std::vector< std::byte > data { generatePerlinImage( { x_size, y_size }, 15, seed ) };
|
||||
|
||||
Texture tex { data, x_size, y_size, 4 };
|
||||
@@ -207,7 +241,12 @@ namespace fgl::engine
|
||||
|
||||
auto& view { m_handle->m_image_view };
|
||||
|
||||
assert( view );
|
||||
|
||||
VkImageView vk_view { view->getVkView() };
|
||||
assert( vk_view );
|
||||
|
||||
assert( view->getSampler() );
|
||||
VkSampler vk_sampler { view->getSampler()->getVkSampler() };
|
||||
|
||||
m_handle->m_imgui_set =
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace fgl::engine
|
||||
[[nodiscard]] static Texture generateFromPerlinNoise( int x_size, int y_size, std::size_t seed = 0 );
|
||||
[[nodiscard]] static Texture loadFromFile( const std::filesystem::path& path );
|
||||
|
||||
void drawImGui( vk::Extent2D extent = {} );
|
||||
bool drawImGuiButton(vk::Extent2D extent = {});
|
||||
|
||||
static DescriptorSet& getTextureDescriptorSet();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user