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:
53
runtime/Includes/Graphics/Mesh.h
git.filemode.normal_file
53
runtime/Includes/Graphics/Mesh.h
git.filemode.normal_file
@@ -0,0 +1,53 @@
|
||||
#ifndef __MLX_RENDERER_MESH__
|
||||
#define __MLX_RENDERER_MESH__
|
||||
|
||||
#include <Renderer/Vertex.h>
|
||||
#include <Renderer/Buffer.h>
|
||||
#include <Utils/Buffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
struct SubMesh
|
||||
{
|
||||
VertexBuffer vbo;
|
||||
IndexBuffer ibo;
|
||||
std::size_t triangle_count = 0;
|
||||
|
||||
inline SubMesh(const std::vector<Vertex>& vertices, const std::vector<std::uint32_t>& indices)
|
||||
{
|
||||
CPUBuffer vb(vertices.size() * sizeof(Vertex));
|
||||
std::memcpy(vb.GetData(), vertices.data(), vb.GetSize());
|
||||
vbo.Init(vb.GetSize());
|
||||
vbo.SetData(std::move(vb));
|
||||
|
||||
CPUBuffer ib(indices.size() * sizeof(std::uint32_t));
|
||||
std::memcpy(ib.GetData(), indices.data(), ib.GetSize());
|
||||
ibo.Init(ib.GetSize());
|
||||
ibo.SetData(std::move(ib));
|
||||
|
||||
triangle_count = vertices.size() / 3;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
Mesh() = default;
|
||||
|
||||
void Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn) const noexcept;
|
||||
void Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn, std::size_t submesh_index) const noexcept;
|
||||
|
||||
inline std::size_t GetSubMeshCount() const { return m_sub_meshes.size(); }
|
||||
|
||||
inline void AddSubMesh(SubMesh mesh) { m_sub_meshes.emplace_back(std::move(mesh)); }
|
||||
[[nodiscard]] inline SubMesh& GetSubMesh(std::size_t index) { return m_sub_meshes.at(index); }
|
||||
|
||||
~Mesh();
|
||||
|
||||
private:
|
||||
std::vector<SubMesh> m_sub_meshes;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
32
runtime/Includes/Graphics/Scene.h
git.filemode.normal_file
32
runtime/Includes/Graphics/Scene.h
git.filemode.normal_file
@@ -0,0 +1,32 @@
|
||||
#ifndef __MLX_SCENE__
|
||||
#define __MLX_SCENE__
|
||||
|
||||
#include <Graphics/Sprite.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
struct SceneDescriptor
|
||||
{
|
||||
NonOwningPtr<Renderer> renderer;
|
||||
// More description may come in future
|
||||
};
|
||||
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene(SceneDescriptor desc);
|
||||
|
||||
Sprite& CreateSprite(std::shared_ptr<class Texture> texture) noexcept;
|
||||
|
||||
[[nodiscard]] inline const std::vector<std::shared_ptr<Sprite>>& GetSprites() const noexcept { return m_sprites; }
|
||||
[[nodiscard]] inline const SceneDescriptor& GetDescription() const noexcept { return m_descriptor; }
|
||||
|
||||
~Scene() = default;
|
||||
|
||||
private:
|
||||
SceneDescriptor m_descriptor;
|
||||
std::vector<std::shared_ptr<Sprite>> m_sprites;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
53
runtime/Includes/Graphics/Sprite.h
git.filemode.normal_file
53
runtime/Includes/Graphics/Sprite.h
git.filemode.normal_file
@@ -0,0 +1,53 @@
|
||||
#ifndef __MLX_SPRITE__
|
||||
#define __MLX_SPRITE__
|
||||
|
||||
#include <Maths/Vec2.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Graphics/Mesh.h>
|
||||
#include <Renderer/Descriptor.h>
|
||||
#include <Renderer/Image.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class Sprite
|
||||
{
|
||||
friend class Render2DPass;
|
||||
|
||||
public:
|
||||
Sprite(std::shared_ptr<Texture> texture);
|
||||
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = color; }
|
||||
inline void SetPosition(Vec2ui position) noexcept { m_position = position; }
|
||||
|
||||
[[nodiscard]] inline const Vec4f& GetColor() const noexcept { return m_color; }
|
||||
[[nodiscard]] inline const Vec2ui& GetPosition() const noexcept { return m_position; }
|
||||
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||
[[nodiscard]] inline std::shared_ptr<Texture> GetTexture() const { return p_texture; }
|
||||
|
||||
~Sprite() = default;
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return m_set.IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return m_set.GetSet(frame_index); }
|
||||
|
||||
inline void UpdateDescriptorSet(const DescriptorSet& set)
|
||||
{
|
||||
m_set = set.Duplicate();
|
||||
}
|
||||
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
m_set.SetImage(frame_index, 0, *p_texture);
|
||||
m_set.Update(frame_index, cmd);
|
||||
}
|
||||
|
||||
private:
|
||||
DescriptorSet m_set;
|
||||
std::shared_ptr<Texture> p_texture;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
Vec2ui m_position = Vec2ui{ 0, 0 };
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user