Add in ImGui code for handling game objects.
This commit is contained in:
@@ -117,7 +117,7 @@ namespace fgl::engine
|
|||||||
const float aspect { m_renderer.getAspectRatio() };
|
const float aspect { m_renderer.getAspectRatio() };
|
||||||
|
|
||||||
//camera.setOrthographicProjection( -aspect, aspect, -1, 1, -1, 1 );
|
//camera.setOrthographicProjection( -aspect, aspect, -1, 1, -1, 1 );
|
||||||
camera.setPerspectiveProjection( glm::radians( 50.0f ), aspect, 0.1f, 10.f );
|
camera.setPerspectiveProjection( glm::radians( 50.0f ), aspect, 0.1f, 100.f );
|
||||||
|
|
||||||
if ( auto command_buffer = m_renderer.beginFrame(); command_buffer )
|
if ( auto command_buffer = m_renderer.beginFrame(); command_buffer )
|
||||||
{
|
{
|
||||||
@@ -160,7 +160,6 @@ namespace fgl::engine
|
|||||||
if ( ImGui::CollapsingHeader( "Camera" ) )
|
if ( ImGui::CollapsingHeader( "Camera" ) )
|
||||||
{
|
{
|
||||||
ImGui::PushItemWidth( 80 );
|
ImGui::PushItemWidth( 80 );
|
||||||
ImGui::Text( "Position: " );
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::DragFloat( "Pos X", &viewer.transform.translation.x, 0.1f );
|
ImGui::DragFloat( "Pos X", &viewer.transform.translation.x, 0.1f );
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -172,7 +171,6 @@ namespace fgl::engine
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
ImGui::PushItemWidth( 80 );
|
ImGui::PushItemWidth( 80 );
|
||||||
ImGui::Text( "Rotation: " );
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::DragFloat( "Rot X", &viewer.transform.rotation.x, 0.1f, 0.0f, glm::two_pi< float >() );
|
ImGui::DragFloat( "Rot X", &viewer.transform.rotation.x, 0.1f, 0.0f, glm::two_pi< float >() );
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -182,6 +180,78 @@ namespace fgl::engine
|
|||||||
ImGui::PopItemWidth();
|
ImGui::PopItemWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ImGui::CollapsingHeader( "Models" ) )
|
||||||
|
{
|
||||||
|
for ( auto& [ id, game_object ] : game_objects )
|
||||||
|
{
|
||||||
|
if ( game_object.model == nullptr ) continue;
|
||||||
|
|
||||||
|
if ( ImGui::TreeNode( game_object.model->getName().c_str() ) )
|
||||||
|
{
|
||||||
|
ImGui::PushID( game_object.model->getName().c_str() );
|
||||||
|
{
|
||||||
|
ImGui::PushID( "Position" );
|
||||||
|
ImGui::PushItemWidth( 80 );
|
||||||
|
ImGui::Text( "Position" );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat( "X", &game_object.transform.translation.x, 0.1f );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat( "Y", &game_object.transform.translation.y, 0.1f );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat( "Z", &game_object.transform.translation.z, 0.1f );
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::PushID( "Rotation" );
|
||||||
|
ImGui::PushItemWidth( 80 );
|
||||||
|
ImGui::Text( "Rotation" );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat(
|
||||||
|
"X", &game_object.transform.rotation.x, 0.1f, 0.0f, glm::two_pi< float >() );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat(
|
||||||
|
"Y", &game_object.transform.rotation.y, 0.1f, 0.0f, glm::two_pi< float >() );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat(
|
||||||
|
"Z", &game_object.transform.rotation.z, 0.1f, 0.0f, glm::two_pi< float >() );
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
{
|
||||||
|
ImGui::PushID( "Scale" );
|
||||||
|
ImGui::PushItemWidth( 80 );
|
||||||
|
ImGui::Text( "Scale" );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat( "X", &game_object.transform.scale.x, 0.1f );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat( "Y", &game_object.transform.scale.y, 0.1f );
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat( "Z", &game_object.transform.scale.z, 0.1f );
|
||||||
|
ImGui::TreePop();
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Add in a collapsable header to view all buffers, And their suballocations
|
||||||
|
/*
|
||||||
|
if ( ImGui::CollapsingHeader( "Buffer allocations" ) )
|
||||||
|
{
|
||||||
|
for ( const auto& buffer : Buffer::getActiveBufferHandles() )
|
||||||
|
{
|
||||||
|
ImGui::Text( "Address: %p", buffer.lock()->address() );
|
||||||
|
ImGui::Text( "Size: %zu", buffer.lock()->size() );
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +323,7 @@ namespace fgl::engine
|
|||||||
game_objects.emplace( sponza.getId(), std::move( sponza ) );
|
game_objects.emplace( sponza.getId(), std::move( sponza ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
{
|
{
|
||||||
std::shared_ptr< Model > model { Model::createModel(
|
std::shared_ptr< Model > model { Model::createModel(
|
||||||
Device::getInstance(),
|
Device::getInstance(),
|
||||||
@@ -270,7 +341,6 @@ namespace fgl::engine
|
|||||||
|
|
||||||
game_objects.emplace( smooth_vase.getId(), std::move( smooth_vase ) );
|
game_objects.emplace( smooth_vase.getId(), std::move( smooth_vase ) );
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::shared_ptr< Model > flat_model { Model::createModel(
|
std::shared_ptr< Model > flat_model { Model::createModel(
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ namespace fgl::engine
|
|||||||
|
|
||||||
std::vector< vk::DrawIndexedIndirectCommand > m_draw_parameters;
|
std::vector< vk::DrawIndexedIndirectCommand > m_draw_parameters;
|
||||||
|
|
||||||
|
std::string m_name { "Unnamed model" };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct Builder
|
struct Builder
|
||||||
@@ -109,6 +111,8 @@ namespace fgl::engine
|
|||||||
|
|
||||||
void syncBuffers( vk::CommandBuffer& cmd_buffer );
|
void syncBuffers( vk::CommandBuffer& cmd_buffer );
|
||||||
|
|
||||||
|
const std::string& getName() const { return m_name; }
|
||||||
|
|
||||||
Model( Device& device, Builder& builder );
|
Model( Device& device, Builder& builder );
|
||||||
|
|
||||||
~Model() = default;
|
~Model() = default;
|
||||||
|
|||||||
@@ -86,6 +86,23 @@ namespace fgl::engine
|
|||||||
vmaGetAllocationInfo( Device::getInstance().allocator(), m_allocation, &m_alloc_info );
|
vmaGetAllocationInfo( Device::getInstance().allocator(), m_allocation, &m_alloc_info );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector< std::weak_ptr< BufferHandle > > Buffer::getActiveBufferHandles()
|
||||||
|
{
|
||||||
|
std::vector< std::weak_ptr< BufferHandle > > handles;
|
||||||
|
handles.reserve( m_buffer_handles.size() );
|
||||||
|
|
||||||
|
for ( auto& handle : m_buffer_handles )
|
||||||
|
{
|
||||||
|
if ( auto ptr = handle.lock() )
|
||||||
|
{
|
||||||
|
handles.push_back( ptr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_buffer_handles = handles;
|
||||||
|
return handles;
|
||||||
|
}
|
||||||
|
|
||||||
vk::DeviceSize Buffer::alignment()
|
vk::DeviceSize Buffer::alignment()
|
||||||
{
|
{
|
||||||
vk::DeviceSize size { 0 };
|
vk::DeviceSize size { 0 };
|
||||||
@@ -253,6 +270,7 @@ namespace fgl::engine
|
|||||||
m_memory_properties( memory_properties )
|
m_memory_properties( memory_properties )
|
||||||
{
|
{
|
||||||
m_free_blocks.insert( m_free_blocks.begin(), { 0, memory_size } );
|
m_free_blocks.insert( m_free_blocks.begin(), { 0, memory_size } );
|
||||||
|
m_buffer_handles.emplace_back( m_handle );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fgl::engine
|
} // namespace fgl::engine
|
||||||
|
|||||||
@@ -61,14 +61,22 @@ namespace fgl::engine
|
|||||||
vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memory_properties );
|
vk::DeviceSize memory_size, vk::BufferUsageFlags usage, vk::MemoryPropertyFlags memory_properties );
|
||||||
|
|
||||||
~BufferHandle();
|
~BufferHandle();
|
||||||
|
|
||||||
|
auto address() const { return m_alloc_info.deviceMemory; }
|
||||||
|
|
||||||
|
auto size() const { return m_alloc_info.size; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
|
inline static std::vector< std::weak_ptr< BufferHandle > > m_buffer_handles {};
|
||||||
|
|
||||||
std::shared_ptr< BufferHandle > m_handle;
|
std::shared_ptr< BufferHandle > m_handle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static std::vector< std::weak_ptr< BufferHandle > > getActiveBufferHandles();
|
||||||
|
|
||||||
vk::Buffer& getVkBuffer() { return m_handle->m_buffer; }
|
vk::Buffer& getVkBuffer() { return m_handle->m_buffer; }
|
||||||
|
|
||||||
vk::BufferUsageFlags m_usage;
|
vk::BufferUsageFlags m_usage;
|
||||||
@@ -85,6 +93,7 @@ namespace fgl::engine
|
|||||||
Buffer( const Buffer& other ) = delete;
|
Buffer( const Buffer& other ) = delete;
|
||||||
Buffer( Buffer&& other ) = delete;
|
Buffer( Buffer&& other ) = delete;
|
||||||
Buffer& operator=( const Buffer& other ) = delete;
|
Buffer& operator=( const Buffer& other ) = delete;
|
||||||
|
Buffer& operator=( Buffer&& other ) = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user