mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 23:23:34 +00:00
working text pipeline
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/07 16:40:09 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/08 18:41:44 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/11 12:30:28 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -25,25 +25,6 @@ namespace mlx
|
||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
Image::createSampler();
|
||||
|
||||
_color = 0xFFFFFFFF;
|
||||
|
||||
float red = (_color & 0x00FF0000) / 255;
|
||||
float green = (_color & 0x0000FF00) / 255;
|
||||
float blue = (_color & 0x000000FF) / 255;
|
||||
|
||||
std::vector<Vertex> vertexData = {
|
||||
{{0, 0}, {red, green, blue, 1.f}, {0.0f, 0.0f}},
|
||||
{{20, 0}, {red, green, blue, 1.f}, {1.0f, 0.0f}},
|
||||
{{20, 20}, {red, green, blue, 1.f}, {1.0f, 1.0f}},
|
||||
{{0, 20}, {red, green, blue, 1.f}, {0.0f, 1.0f}}
|
||||
};
|
||||
|
||||
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
_vbo.create(sizeof(Vertex) * vertexData.size());
|
||||
_vbo.setData(sizeof(Vertex) * vertexData.size(), vertexData.data());
|
||||
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data());
|
||||
|
||||
if(pixels != nullptr)
|
||||
{
|
||||
Buffer staging_buffer;
|
||||
@@ -54,33 +35,17 @@ namespace mlx
|
||||
}
|
||||
}
|
||||
|
||||
void TextureAtlas::render(Renderer& renderer, int x, int y, std::array<glm::vec2, 4> pos, std::array<glm::vec2, 4> uv)
|
||||
void TextureAtlas::render(Renderer& renderer, int x, int y, uint32_t ibo_size)
|
||||
{
|
||||
auto cmd = renderer.getActiveCmdBuffer().get();
|
||||
|
||||
float red = (_color & 0x00FF0000) / 255;
|
||||
float green = (_color & 0x0000FF00) / 255;
|
||||
float blue = (_color & 0x000000FF) / 255;
|
||||
|
||||
std::vector<Vertex> vertexData = {
|
||||
{pos[0], {red, green, blue, 1.f}, uv[0]},
|
||||
{pos[1], {red, green, blue, 1.f}, uv[1]},
|
||||
{pos[2], {red, green, blue, 1.f}, uv[2]},
|
||||
{pos[3], {red, green, blue, 1.f}, uv[3]}
|
||||
};
|
||||
_vbo.setData(sizeof(Vertex) * vertexData.size(), vertexData.data());
|
||||
|
||||
_vbo.bind(renderer);
|
||||
_ibo.bind(renderer);
|
||||
glm::vec2 translate(x, y);
|
||||
vkCmdPushConstants(cmd, renderer.getPipeline().getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(translate), &translate);
|
||||
vkCmdDrawIndexed(cmd, static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
|
||||
vkCmdDrawIndexed(cmd, ibo_size / sizeof(uint16_t), 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
void TextureAtlas::destroy() noexcept
|
||||
{
|
||||
Image::destroy();
|
||||
_vbo.destroy();
|
||||
_ibo.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/08 00:27:46 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/11 12:04:16 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -25,11 +25,9 @@ namespace mlx
|
||||
TextureAtlas() = default;
|
||||
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
|
||||
void render(class Renderer& renderer, int x, int y, std::array<glm::vec2, 4> pos, std::array<glm::vec2, 4> uv);
|
||||
void render(class Renderer& renderer, int x, int y, uint32_t ibo_size);
|
||||
void destroy() noexcept override;
|
||||
|
||||
inline void setColor(int color) noexcept { _color = color; }
|
||||
|
||||
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
||||
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
||||
inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, getImageView(), getSampler()); }
|
||||
@@ -37,10 +35,7 @@ namespace mlx
|
||||
~TextureAtlas() = default;
|
||||
|
||||
private:
|
||||
VBO _vbo;
|
||||
C_IBO _ibo;
|
||||
DescriptorSet _set;
|
||||
int _color;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/08 18:41:15 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/11 13:20:26 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace mlx
|
||||
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
info.magFilter = VK_FILTER_LINEAR;
|
||||
info.minFilter = VK_FILTER_LINEAR;
|
||||
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
|
||||
info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
|
||||
Reference in New Issue
Block a user