mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
adding transformations
This commit is contained in:
@@ -145,7 +145,13 @@ extern "C"
|
||||
void mlx_put_image_to_window(void* mlx, void* win, void* img, int x, int y)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y);
|
||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void mlx_transform_put_image_to_window(void* mlx, void* win, void* img, int x, int y, float scale, float angle)
|
||||
{
|
||||
MLX_CHECK_APPLICATION_POINTER(mlx);
|
||||
static_cast<mlx::Application*>(mlx)->TexturePut(win, img, x, y, scale, angle);
|
||||
}
|
||||
|
||||
void mlx_destroy_image(void* mlx, void* img)
|
||||
|
||||
@@ -12,10 +12,6 @@ namespace mlx
|
||||
};
|
||||
}
|
||||
|
||||
std::uint32_t Logs::s_nesting = 0;
|
||||
|
||||
constexpr int LOGS_TABS_WIDTH = 4;
|
||||
|
||||
void Logs::Report(LogType type, std::string message)
|
||||
{
|
||||
Report(type, 0, {}, {}, std::move(message));
|
||||
@@ -42,14 +38,7 @@ namespace mlx
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case LogType::Debug:
|
||||
{
|
||||
std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << std::flush;
|
||||
std::printf("%*s", s_nesting * LOGS_TABS_WIDTH, "");
|
||||
std::fflush(stdout);
|
||||
std::cout << code_infos << message << std::endl;
|
||||
break;
|
||||
}
|
||||
case LogType::Debug: std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << code_infos << message << std::endl; break;
|
||||
case LogType::Message: std::cout << Ansi::blue << "[MLX Message] " << Ansi::def << code_infos << message << '\n'; break;
|
||||
case LogType::Warning: std::cout << Ansi::magenta << "[MLX Warning] " << Ansi::def << code_infos << message << '\n'; break;
|
||||
case LogType::Error: std::cerr << Ansi::red << "[MLX Error] " << Ansi::def << code_infos << message << '\n'; break;
|
||||
@@ -63,15 +52,4 @@ namespace mlx
|
||||
EventBus::Send("__MlxApplication", Internal::FatalErrorEvent{});
|
||||
}
|
||||
}
|
||||
|
||||
void Logs::BeginSection()
|
||||
{
|
||||
s_nesting++;
|
||||
}
|
||||
|
||||
void Logs::EndSection()
|
||||
{
|
||||
if(s_nesting > 0)
|
||||
s_nesting--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,17 @@ namespace mlx
|
||||
return *sprite;
|
||||
}
|
||||
|
||||
NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const
|
||||
NonOwningPtr<Sprite> Scene::GetSpriteFromTexturePositionScaleRotation(NonOwningPtr<Texture> texture, const Vec2f& position, float scale, float rotation) const
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position](std::shared_ptr<Drawable> drawable)
|
||||
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position, scale, rotation](std::shared_ptr<Drawable> drawable)
|
||||
{
|
||||
if(!drawable || drawable->GetType() != DrawableType::Sprite)
|
||||
return false;
|
||||
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture && drawable->GetPosition() == position;
|
||||
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture &&
|
||||
drawable->GetPosition() == position &&
|
||||
drawable->GetScale() == Vec2f{ scale, scale } &&
|
||||
drawable->GetRotation() == EulerAnglesf{ 0.0f, 0.0f, rotation };
|
||||
});
|
||||
return static_cast<Sprite*>(it != m_drawables.end() ? it->get() : nullptr);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <mlx_profile.h>
|
||||
#include <PreCompiled.h>
|
||||
|
||||
#define VMA_IMPLEMENTATION
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user