mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
begenning the refactor
This commit is contained in:
94
runtime/Sources/Core/Graphics.cpp
git.filemode.normal_file
94
runtime/Sources/Core/Graphics.cpp
git.filemode.normal_file
@@ -0,0 +1,94 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* graphics.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
|
||||
/* Updated: 2024/03/27 00:32:34 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <pre_compiled.h>
|
||||
|
||||
#include <core/graphics.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, Texture* render_target, int id) :
|
||||
_window(nullptr),
|
||||
_renderer(std::make_unique<Renderer>()),
|
||||
_width(w),
|
||||
_height(h),
|
||||
_id(id),
|
||||
_has_window(false)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_renderer->setWindow(nullptr);
|
||||
_renderer->init(render_target);
|
||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||
_text_manager.init(*_renderer);
|
||||
}
|
||||
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||
_window(std::make_shared<Window>(w, h, title)),
|
||||
_renderer(std::make_unique<Renderer>()),
|
||||
_width(w),
|
||||
_height(h),
|
||||
_id(id),
|
||||
_has_window(true)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_renderer->setWindow(_window.get());
|
||||
_renderer->init(nullptr);
|
||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||
_text_manager.init(*_renderer);
|
||||
}
|
||||
|
||||
void GraphicsSupport::render() noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(!_renderer->beginFrame())
|
||||
return;
|
||||
_proj = glm::ortho<float>(0, _width, 0, _height);
|
||||
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
|
||||
|
||||
static std::array<VkDescriptorSet, 2> sets = {
|
||||
_renderer->getVertDescriptorSet().get(),
|
||||
VK_NULL_HANDLE
|
||||
};
|
||||
|
||||
for(auto& data : _drawlist)
|
||||
data->render(sets, *_renderer);
|
||||
|
||||
_pixel_put_pipeline.render(sets, *_renderer);
|
||||
|
||||
_renderer->endFrame();
|
||||
|
||||
for(auto& data : _drawlist)
|
||||
data->resetUpdate();
|
||||
|
||||
#ifdef GRAPHICS_MEMORY_DUMP
|
||||
// dump memory to file every two seconds
|
||||
using namespace std::chrono_literals;
|
||||
static std::int64_t timer = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
if(std::chrono::duration<std::uint64_t>{static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()) - timer} >= 1s)
|
||||
{
|
||||
Render_Core::get().getAllocator().dumpMemoryToJson();
|
||||
timer = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GraphicsSupport::~GraphicsSupport()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
_text_manager.destroy();
|
||||
_pixel_put_pipeline.destroy();
|
||||
_renderer->destroy();
|
||||
if(_window)
|
||||
_window->destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user