mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
still refactor
This commit is contained in:
@@ -1,70 +1,67 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* pixel_put.cpp :+: :+: :+: */
|
||||
/* PixelPut.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
||||
/* Updated: 2024/03/25 19:03:45 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/04/24 01:46:06 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <pre_compiled.h>
|
||||
#include <PreCompiled.h>
|
||||
|
||||
#include <renderer/pixel_put.h>
|
||||
#include <core/profiler.h>
|
||||
#include <Renderer/PixelPut.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void PixelPutPipeline::init(std::uint32_t width, std::uint32_t height, Renderer& renderer) noexcept
|
||||
void PixelPutPipeline::Init(std::uint32_t width, std::uint32_t height, Renderer& renderer) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_pixel_put_pipeline_texture", true);
|
||||
_texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
||||
m_texture.Create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_pixel_put_pipeline_texture", true);
|
||||
m_texture.SetDescriptor(renderer.GetFragDescriptorSet().Duplicate());
|
||||
|
||||
_buffer.create(Buffer::kind::dynamic, sizeof(std::uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, "__mlx_pixel_put_pipeline_texture");
|
||||
_buffer.mapMem(&_buffer_map);
|
||||
_cpu_map = std::vector<std::uint32_t>(height * width + 1, 0);
|
||||
_width = width;
|
||||
_height = height;
|
||||
m_buffer.Create(BufferType::HighDynamic, sizeof(std::uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, "__mlx_pixel_put_pipeline_texture");
|
||||
m_buffer.MapMem(&_buffer_map);
|
||||
m_cpu_map = std::vector<std::uint32_t>(height * width + 1, 0);
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
}
|
||||
|
||||
void PixelPutPipeline::setPixel(int x, int y, std::uint32_t color) noexcept
|
||||
void PixelPutPipeline::SetPixel(int x, int y, std::uint32_t color) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(x < 0 || y < 0 || x > static_cast<int>(_width) || y > static_cast<int>(_height))
|
||||
if(x < 0 || y < 0 || x > static_cast<int>(m_width) || y > static_cast<int>(m_height))
|
||||
return;
|
||||
_cpu_map[(y * _width) + x] = color;
|
||||
_has_been_modified = true;
|
||||
m_cpu_map[(y * m_width) + x] = color;
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
|
||||
void PixelPutPipeline::clear()
|
||||
void PixelPutPipeline::Clear()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_cpu_map.assign(_width * _height, 0);
|
||||
_has_been_modified = true;
|
||||
m_cpu_map.assign(m_width * m_height, 0);
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
|
||||
void PixelPutPipeline::render(std::array<VkDescriptorSet, 2>& sets, Renderer& renderer) noexcept
|
||||
void PixelPutPipeline::Render(Renderer& renderer) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(_has_been_modified)
|
||||
if(m_has_been_modified)
|
||||
{
|
||||
std::memcpy(_buffer_map, _cpu_map.data(), sizeof(std::uint32_t) * _cpu_map.size());
|
||||
_texture.copyFromBuffer(_buffer);
|
||||
_has_been_modified = false;
|
||||
std::memcpy(m_buffer_map, m_cpu_map.data(), sizeof(std::uint32_t) * m_cpu_map.size());
|
||||
m_texture.CopyFromBuffer(m_buffer);
|
||||
m_has_been_modified = false;
|
||||
}
|
||||
_texture.updateSet(0);
|
||||
_texture.render(sets, renderer, 0, 0);
|
||||
m_texture.UpdateSet(0);
|
||||
m_texture.Render(renderer, 0, 0);
|
||||
}
|
||||
|
||||
void PixelPutPipeline::destroy() noexcept
|
||||
void PixelPutPipeline::Destroy() noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_buffer.destroy();
|
||||
_texture.destroy();
|
||||
m_buffer.Destroy();
|
||||
m_texture.Destroy();
|
||||
}
|
||||
|
||||
PixelPutPipeline::~PixelPutPipeline() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user