mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 15:13:34 +00:00
big refactoring ! ci skip
This commit is contained in:
31
runtime/Sources/Graphics/Mesh.cpp
git.filemode.normal_file
31
runtime/Sources/Graphics/Mesh.cpp
git.filemode.normal_file
@@ -0,0 +1,31 @@
|
||||
#include <PreCompiled.h>
|
||||
#include <Graphics/Mesh.h>
|
||||
#include <Utils/Buffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Mesh::Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn) const noexcept
|
||||
{
|
||||
for(std::size_t i = 0; i < m_sub_meshes.size(); i++)
|
||||
Draw(cmd, drawcalls, polygondrawn, i);
|
||||
}
|
||||
|
||||
void Mesh::Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn, std::size_t submesh_index) const noexcept
|
||||
{
|
||||
Verify(submesh_index < m_sub_meshes.size(), "invalid submesh index");
|
||||
m_sub_meshes[submesh_index].vbo.Bind(cmd);
|
||||
m_sub_meshes[submesh_index].ibo.Bind(cmd);
|
||||
vkCmdDrawIndexed(cmd, static_cast<std::uint32_t>(m_sub_meshes[submesh_index].ibo.GetSize() / sizeof(std::uint32_t)), 1, 0, 0, 0);
|
||||
polygondrawn += m_sub_meshes[submesh_index].triangle_count;
|
||||
drawcalls++;
|
||||
}
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
for(auto& mesh : m_sub_meshes)
|
||||
{
|
||||
mesh.vbo.Destroy();
|
||||
mesh.ibo.Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
runtime/Sources/Graphics/Scene.cpp
git.filemode.normal_file
19
runtime/Sources/Graphics/Scene.cpp
git.filemode.normal_file
@@ -0,0 +1,19 @@
|
||||
#include <PreCompiled.h>
|
||||
#include <Graphics/Scene.h>
|
||||
#include <Renderer/Renderer.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
Scene::Scene(SceneDescriptor desc)
|
||||
: m_descriptor(std::move(desc))
|
||||
{
|
||||
}
|
||||
|
||||
Sprite& Scene::CreateSprite(std::shared_ptr<Texture> texture) noexcept
|
||||
{
|
||||
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(texture);
|
||||
m_sprites.push_back(sprite);
|
||||
return *sprite;
|
||||
}
|
||||
}
|
||||
44
runtime/Sources/Graphics/Sprite.cpp
git.filemode.normal_file
44
runtime/Sources/Graphics/Sprite.cpp
git.filemode.normal_file
@@ -0,0 +1,44 @@
|
||||
#include <PreCompiled.h>
|
||||
#include <Graphics/Sprite.h>
|
||||
#include <Renderer/Image.h>
|
||||
#include <Renderer/Vertex.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
std::shared_ptr<Mesh> CreateQuad(float x, float y, float width, float height)
|
||||
{
|
||||
std::vector<Vertex> data(4);
|
||||
|
||||
data[0].position = Vec4f(x, y, 0.0f, 1.0f);
|
||||
data[0].uv = Vec2f(1.0f, 1.0f);
|
||||
|
||||
data[1].position = Vec4f(x + width, y, 0.0f, 1.0f);
|
||||
data[1].uv = Vec2f(0.0f, 1.0f);
|
||||
|
||||
data[2].position = Vec4f(x + width, y + height, 0.0f, 1.0f);
|
||||
data[2].uv = Vec2f(0.0f, 0.0f);
|
||||
|
||||
data[3].position = Vec4f(x, y + height, 0.0f, 1.0f);
|
||||
data[3].uv = Vec2f(1.0f, 0.0f);
|
||||
|
||||
std::vector<std::uint32_t> indices = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
};
|
||||
|
||||
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
|
||||
mesh->AddSubMesh({ std::move(data), std::move(indices) });
|
||||
return mesh;
|
||||
}
|
||||
|
||||
Sprite::Sprite(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
Verify((bool)texture, "Sprite: invalid texture");
|
||||
p_mesh = CreateQuad(0, 0, texture->GetWidth(), texture->GetHeight());
|
||||
p_texture = texture;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user