adding transformations

This commit is contained in:
2024-11-13 12:17:59 +01:00
parent eaf5be3061
commit e29ea92202
18 changed files with 141 additions and 130 deletions

View File

@@ -1,4 +1,3 @@
#include <mlx_profile.h>
#include <PreCompiled.h>
#define VMA_IMPLEMENTATION

View File

@@ -56,7 +56,6 @@ namespace mlx
return;
s_instance = this;
Logs::BeginSection();
loader = std::make_unique<VulkanLoader>();
LoadKVFGlobalVulkanFunctionPointers();
@@ -80,7 +79,6 @@ namespace mlx
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
Logs::BeginSection();
m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface);
// just for style
@@ -96,12 +94,10 @@ namespace mlx
loader->LoadDevice(m_device);
LoadKVFDeviceVulkanFunctionPointers();
Logs::EndSection();
vkDestroySurfaceKHR(m_instance, surface, nullptr);
m_allocator.Init();
Logs::EndSection();
}
#undef MLX_LOAD_FUNCTION

View File

@@ -8,10 +8,10 @@
namespace mlx
{
struct SpriteData
struct DrawableData
{
Mat4f model_matrix;
Vec4f color;
Vec2f position;
};
void Render2DPass::Init()
@@ -25,7 +25,7 @@ namespace mlx
{ 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }
})
}
}, { ShaderPushConstantLayout({ 0, sizeof(SpriteData) }) }
}, { ShaderPushConstantLayout({ 0, sizeof(DrawableData) }) }
);
std::vector<std::uint8_t> vertex_shader_code = {
#include <Embedded/Shader2DVertex.spv.h>
@@ -105,15 +105,19 @@ namespace mlx
m_pipeline.BindPipeline(cmd, 0, {});
for(auto& drawable : drawables)
{
SpriteData drawable_data;
drawable_data.position = drawable->GetPosition();
DrawableData drawable_data;
drawable_data.color = drawable->GetColor();
drawable_data.model_matrix = Mat4f::Identity();
drawable_data.model_matrix.SetTranslation(Vec3f{ drawable->GetPosition(), 0.0f });
drawable_data.model_matrix.SetScale(Vec3f{ drawable->GetScale(), 1.0f });
drawable_data.model_matrix.SetRotation(drawable->GetRotation());
//drawable_data.model_matrix = Mat4f::Translate(-Vec3f{ drawable->GetCenter(), 0.0f }) * Mat4f::Rotate(drawable->GetRotation()) * drawable_data.model_matrix;
drawable->Bind(frame_index, cmd);
std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), drawable->GetSet(frame_index) };
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &drawable_data);
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(DrawableData), &drawable_data);
RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
drawable->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef());