working on event system

This commit is contained in:
2023-04-04 12:40:47 +02:00
parent 21962dda90
commit d02f04c294
11 changed files with 122 additions and 57 deletions

View File

@@ -6,78 +6,72 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
/* Updated: 2023/04/02 20:02:30 by maldavid ### ########.fr */
/* Updated: 2023/04/03 14:22:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <renderer/images/texture.h>
#include <renderer/pixel_put.h>
#include <cstring>
namespace mlx
{
struct PixelPutPipeline::_Pimpl
{
Texture texture;
Buffer buffer;
void* map = nullptr;
uint32_t width = 0;
uint32_t height = 0;
};
PixelPutPipeline::PixelPutPipeline() : _impl(std::make_unique<_Pimpl>()) {}
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
{
_impl->texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM);
_impl->texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
_texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM);
_texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
_impl->buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
_impl->width = width;
_impl->height = height;
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
_width = width;
_height = height;
}
VkDescriptorSet PixelPutPipeline::getDescriptorSet() noexcept
{
return _impl->texture.getSet();
return _texture.getSet();
}
void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, int color) noexcept
{
if(x < 0 || y < 0 || x > _impl->width || y > _impl->height)
if(x < 0 || y < 0 || x > _width || y > _height)
return;
if(!_impl->buffer.isMapped())
_impl->buffer.mapMem(&_impl->map);
unsigned char* mem = static_cast<unsigned char*>(_impl->map) + (y * _impl->width * sizeof(uint32_t)) + (x * sizeof(uint32_t));
*reinterpret_cast<uint32_t*>(mem) = color;
if(!_buffer.isMapped())
_buffer.mapMem(&_map);
unsigned char* mem = static_cast<unsigned char*>(_map) + (y * _width * sizeof(uint32_t)) + (x * sizeof(uint32_t));
int new_color = color & 0xFFFFFF00;
new_color >>= 8;
new_color |= (color << 24) & 0xFF000000;
*reinterpret_cast<uint32_t*>(mem) = new_color;
_has_been_modified = true;
}
void PixelPutPipeline::clear()
{
if(!_impl->buffer.isMapped())
_impl->buffer.mapMem(&_impl->map);
unsigned char* mem = static_cast<unsigned char*>(_impl->map);
std::memset(mem, 0, sizeof(uint32_t) * (_impl->width * _impl->height));
if(!_buffer.isMapped())
_buffer.mapMem(&_map);
unsigned char* mem = static_cast<unsigned char*>(_map);
std::memset(mem, 0, sizeof(uint32_t) * (_width * _height));
_has_been_modified = true;
}
void PixelPutPipeline::present() noexcept
{
if(_impl->buffer.isMapped())
_impl->buffer.unmapMem();
_impl->texture.copyFromBuffer(_impl->buffer);
_impl->texture.updateSet(0);
if(_has_been_modified)
{
_texture.copyFromBuffer(_buffer);
_has_been_modified = false;
}
_texture.updateSet(0);
}
void PixelPutPipeline::render(Renderer& renderer) noexcept
{
_impl->texture.render(renderer, 0, 0);
_texture.render(renderer, 0, 0);
}
void PixelPutPipeline::destroy() noexcept
{
_impl->buffer.destroy();
_impl->texture.destroy();
_buffer.destroy();
_texture.destroy();
}
PixelPutPipeline::~PixelPutPipeline() {}

View File

@@ -6,13 +6,14 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 13:18:50 by maldavid #+# #+# */
/* Updated: 2023/04/01 17:26:46 by maldavid ### ########.fr */
/* Updated: 2023/04/03 14:22:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_PIXEL_PUT__
#define __MLX_PIXEL_PUT__
#include <renderer/images/texture.h>
#include <renderer/descriptors/vk_descriptor_set.h>
namespace mlx
@@ -20,7 +21,7 @@ namespace mlx
class PixelPutPipeline
{
public:
PixelPutPipeline();
PixelPutPipeline() = default;
void init(uint32_t width, uint32_t height, class Renderer& renderer) noexcept;
@@ -36,8 +37,12 @@ namespace mlx
~PixelPutPipeline();
private:
struct _Pimpl;
std::unique_ptr<_Pimpl> _impl;
Texture _texture;
Buffer _buffer;
void* _map = nullptr;
uint32_t _width = 0;
uint32_t _height = 0;
bool _has_been_modified = true;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
/* Updated: 2023/04/02 18:09:14 by maldavid ### ########.fr */
/* Updated: 2023/04/03 14:23:46 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,7 +17,6 @@
#include <vector>
#include <memory>
#include <renderer/pixel_put.h>
#include <renderer/buffers/vk_ubo.h>
#include <renderer/core/vk_surface.h>
#include <renderer/core/render_core.h>