mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
working textures
This commit is contained in:
@@ -6,13 +6,11 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/01 12:57:32 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/01 15:32:23 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <renderer/buffers/vk_ibo.h>
|
||||
#include <renderer/buffers/vk_vbo.h>
|
||||
#include <renderer/images/vk_image.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <renderer/pixel_put.h>
|
||||
#include <cstring>
|
||||
|
||||
@@ -20,11 +18,8 @@ namespace mlx
|
||||
{
|
||||
struct PixelPutPipeline::_Pimpl
|
||||
{
|
||||
Image image;
|
||||
C_VBO vbo;
|
||||
C_IBO ibo;
|
||||
Texture texture;
|
||||
Buffer buffer;
|
||||
DescriptorSet image_set;
|
||||
void* map = nullptr;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
@@ -34,32 +29,17 @@ namespace mlx
|
||||
|
||||
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
|
||||
{
|
||||
_impl->image.create(width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||
_impl->image.createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
_impl->image.createSampler();
|
||||
_impl->texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM);
|
||||
_impl->texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
||||
|
||||
_impl->buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||
_impl->image_set = renderer.getFragDescriptorSet().duplicate();
|
||||
_impl->width = width;
|
||||
_impl->height = height;
|
||||
|
||||
std::vector<Vertex> vertexData = {
|
||||
{{0, 0}, {1.f, 1.f, 1.f}, {0.0f, 0.0f}},
|
||||
{{_impl->width, 0}, {1.f, 1.f, 1.f}, {1.0f, 0.0f}},
|
||||
{{_impl->width, _impl->height}, {1.f, 1.f, 1.f}, {1.0f, 1.0f}},
|
||||
{{0, _impl->height}, {1.f, 1.f, 1.0}, {0.0f, 1.0f}}
|
||||
};
|
||||
|
||||
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
_impl->vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data());
|
||||
_impl->ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data());
|
||||
}
|
||||
|
||||
VkDescriptorSet& PixelPutPipeline::getDescriptorSet() noexcept
|
||||
VkDescriptorSet PixelPutPipeline::getDescriptorSet() noexcept
|
||||
{
|
||||
return _impl->image_set.get();
|
||||
return _impl->texture.getSet();
|
||||
}
|
||||
|
||||
void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, int color) noexcept
|
||||
@@ -77,23 +57,19 @@ namespace mlx
|
||||
{
|
||||
if(_impl->buffer.isMapped())
|
||||
_impl->buffer.unmapMem();
|
||||
_impl->image.copyBuffer(_impl->buffer);
|
||||
_impl->image_set.writeDescriptor(0, _impl->image.getImageView(), _impl->image.getSampler());
|
||||
_impl->texture.copyBuffer(_impl->buffer);
|
||||
_impl->texture.updateSet(0);
|
||||
}
|
||||
|
||||
void PixelPutPipeline::render(Renderer& renderer) noexcept
|
||||
{
|
||||
_impl->vbo.bind(renderer);
|
||||
_impl->ibo.bind(renderer);
|
||||
vkCmdDrawIndexed(renderer.getActiveCmdBuffer().get(), static_cast<uint32_t>(_impl->ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
|
||||
_impl->texture.render(renderer, 0, 0);
|
||||
}
|
||||
|
||||
void PixelPutPipeline::destroy() noexcept
|
||||
{
|
||||
_impl->vbo.destroy();
|
||||
_impl->ibo.destroy();
|
||||
_impl->buffer.destroy();
|
||||
_impl->image.destroy();
|
||||
_impl->texture.destroy();
|
||||
}
|
||||
|
||||
PixelPutPipeline::~PixelPutPipeline() {}
|
||||
|
||||
Reference in New Issue
Block a user