mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
yes
This commit is contained in:
37
runtime/Includes/Graphics/Font.h
git.filemode.normal_file
37
runtime/Includes/Graphics/Font.h
git.filemode.normal_file
@@ -0,0 +1,37 @@
|
||||
#ifndef __MLX_FONT__
|
||||
#define __MLX_FONT__
|
||||
|
||||
#include <Renderer/Image.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class Font
|
||||
{
|
||||
public:
|
||||
Font(const std::filesystem::path& path, float scale) : m_build_data(path), m_name(path.string()), m_scale(scale) {}
|
||||
Font(const std::string& name, const std::vector<std::uint8_t>& ttf_data, float scale) : m_build_data(ttf_data), m_name(name), m_scale(scale) {}
|
||||
|
||||
void Destroy();
|
||||
|
||||
inline const std::string& GetName() const { return m_name; }
|
||||
inline float GetScale() const noexcept { return m_scale; }
|
||||
inline const std::array<stbtt_packedchar, 96>& GetCharData() const { return m_cdata; }
|
||||
inline const Texture& GetTexture() const noexcept { return m_atlas; }
|
||||
inline bool operator==(const Font& rhs) const { return rhs.m_name == m_name && rhs.m_scale == m_scale; }
|
||||
inline bool operator!=(const Font& rhs) const { return rhs.m_name != m_name || rhs.m_scale != m_scale; }
|
||||
|
||||
inline ~Font() { Destroy(); }
|
||||
|
||||
private:
|
||||
void BuildFont();
|
||||
|
||||
private:
|
||||
std::array<stbtt_packedchar, 96> m_cdata;
|
||||
Texture m_atlas;
|
||||
std::variant<std::filesystem::path, std::vector<std::uint8_t>> m_build_data;
|
||||
std::string m_name;
|
||||
float m_scale;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -16,20 +16,7 @@ namespace mlx
|
||||
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(), 0, "mlx_mesh");
|
||||
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(), 0, "mlx_mesh");
|
||||
ibo.SetData(std::move(ib));
|
||||
|
||||
triangle_count = vertices.size() / 3;
|
||||
}
|
||||
inline SubMesh(const std::vector<Vertex>& vertices, const std::vector<std::uint32_t>& indices);
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -48,21 +35,8 @@ namespace mlx
|
||||
private:
|
||||
std::vector<SubMesh> m_sub_meshes;
|
||||
};
|
||||
|
||||
class MeshRegistry
|
||||
{
|
||||
public:
|
||||
MeshRegistry() = default;
|
||||
|
||||
inline void RegisterMesh(std::shared_ptr<Mesh> mesh);
|
||||
inline void UnregisterMesh(std::shared_ptr<Mesh> mesh);
|
||||
inline bool IsMeshKnown(std::shared_ptr<Mesh> mesh);
|
||||
|
||||
~MeshRegistry() = default;
|
||||
|
||||
private:
|
||||
std::unordered_set<std::shared_ptr<Mesh>> m_mesh_registry;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Graphics/Mesh.inl>
|
||||
|
||||
#endif
|
||||
|
||||
20
runtime/Includes/Graphics/Mesh.inl
git.filemode.normal_file
20
runtime/Includes/Graphics/Mesh.inl
git.filemode.normal_file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <Graphics/Mesh.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
Mesh::SubMesh::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(), 0, "mlx_mesh");
|
||||
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(), 0, "mlx_mesh");
|
||||
ibo.SetData(std::move(ib));
|
||||
|
||||
triangle_count = vertices.size() / 3;
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@ namespace mlx
|
||||
PutPixelManager(NonOwningPtr<class Renderer> renderer) : p_renderer(renderer) {}
|
||||
|
||||
// Return a valid pointer when a new texture has been created
|
||||
NonOwningPtr<Texture> DrawPixel(int x, int y, bool insert_new_texture, std::uint32_t color);
|
||||
NonOwningPtr<Texture> DrawPixel(int x, int y, std::uint64_t draw_layer, std::uint32_t color);
|
||||
void ResetRenderData();
|
||||
|
||||
~PutPixelManager();
|
||||
|
||||
private:
|
||||
std::list<Texture> m_textures;
|
||||
std::unordered_map<std::uint64_t, Texture> m_textures;
|
||||
NonOwningPtr<class Renderer> p_renderer;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace mlx
|
||||
|
||||
public:
|
||||
Sprite(NonOwningPtr<Texture> texture);
|
||||
Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture);
|
||||
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = color; }
|
||||
inline void SetPosition(Vec2f position) noexcept { m_position = position; }
|
||||
|
||||
Reference in New Issue
Block a user