mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
new text management, texts and textures are on the same level, new texture rendering management, fixing issues
This commit is contained in:
@@ -6,11 +6,12 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/10 16:44:14 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/11 05:08:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "application.h"
|
||||
#include <renderer/texts/text_library.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
@@ -44,6 +45,14 @@ namespace mlx::core
|
||||
for(auto& gs : _graphics)
|
||||
gs->render();
|
||||
}
|
||||
|
||||
Render_Core::get().getSingleTimeCmdManager().updateSingleTimesCmdBuffersSubmitState();
|
||||
|
||||
for(auto& gs : _graphics)
|
||||
{
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
gs->getRenderer().getCmdBuffer(i).waitForExecution();
|
||||
}
|
||||
}
|
||||
|
||||
void* Application::newTexture(int w, int h)
|
||||
@@ -74,6 +83,7 @@ namespace mlx::core
|
||||
|
||||
Application::~Application()
|
||||
{
|
||||
TextLibrary::get().clearLibrary();
|
||||
if(__drop_sdl_responsability)
|
||||
return;
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
|
||||
|
||||
@@ -35,6 +35,11 @@ namespace mlx::core
|
||||
void Application::mouseMove(void* win, int x, int y) noexcept
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
if(!_graphics[*static_cast<int*>(win)]->hasWindow())
|
||||
{
|
||||
error::report(e_kind::warning, "trying to move the mouse relative to a window that is targeting an image and not a real window, this is not allowed (move ignored)");
|
||||
return;
|
||||
}
|
||||
SDL_WarpMouseInWindow(_graphics[*static_cast<int*>(win)]->getWindow()->getNativeWindow(), x, y);
|
||||
SDL_PumpEvents();
|
||||
SDL_FlushEvent(SDL_MOUSEMOTION);
|
||||
@@ -43,6 +48,11 @@ namespace mlx::core
|
||||
void Application::onEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept
|
||||
{
|
||||
CHECK_WINDOW_PTR(win);
|
||||
if(!_graphics[*static_cast<int*>(win)]->hasWindow())
|
||||
{
|
||||
error::report(e_kind::warning, "trying to add event hook for a window that is targeting an image and not a real window, this is not allowed (hook ignored)");
|
||||
return;
|
||||
}
|
||||
_in->onEvent(_graphics[*static_cast<int*>(win)]->getWindow()->getID(), event, funct_ptr, param);
|
||||
}
|
||||
|
||||
@@ -82,7 +92,7 @@ namespace mlx::core
|
||||
CHECK_WINDOW_PTR(win);
|
||||
_graphics[*static_cast<int*>(win)]->clearRenderData();
|
||||
}
|
||||
|
||||
|
||||
void Application::destroyGraphicsSupport(void* win)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
@@ -108,7 +118,7 @@ namespace mlx::core
|
||||
}
|
||||
if(std::strlen(str) == 0)
|
||||
{
|
||||
core::error::report(e_kind::error, "trying to put an empty text");
|
||||
core::error::report(e_kind::warning, "trying to put an empty text");
|
||||
return;
|
||||
}
|
||||
_graphics[*static_cast<int*>(win)]->stringPut(x, y, color, str);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/10 18:23:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/11 04:38:53 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,32 +16,32 @@ namespace mlx
|
||||
{
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, Texture* render_target, int id) :
|
||||
_window(nullptr),
|
||||
_text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||
_renderer(std::make_unique<Renderer>()),
|
||||
_width(w),
|
||||
_height(h),
|
||||
_id(id)
|
||||
_id(id),
|
||||
_has_window(false)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_renderer->setWindow(nullptr);
|
||||
_renderer->init(render_target);
|
||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||
_text_put_pipeline->init(_renderer.get());
|
||||
_text_manager.init(*_renderer);
|
||||
}
|
||||
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||
_window(std::make_shared<MLX_Window>(w, h, title)),
|
||||
_text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||
_renderer(std::make_unique<Renderer>()),
|
||||
_width(w),
|
||||
_height(h),
|
||||
_id(id)
|
||||
_id(id),
|
||||
_has_window(true)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_renderer->setWindow(_window.get());
|
||||
_renderer->init(nullptr);
|
||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||
_text_put_pipeline->init(_renderer.get());
|
||||
_text_manager.init(*_renderer);
|
||||
}
|
||||
|
||||
void GraphicsSupport::render() noexcept
|
||||
@@ -51,39 +51,21 @@ namespace mlx
|
||||
return;
|
||||
_proj = glm::ortho<float>(0, _width, 0, _height);
|
||||
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
|
||||
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
|
||||
|
||||
static std::array<VkDescriptorSet, 2> sets = {
|
||||
_renderer->getVertDescriptorSet().get(),
|
||||
VK_NULL_HANDLE
|
||||
};
|
||||
|
||||
for(auto& data : _textures_to_render)
|
||||
{
|
||||
if(!data.texture->isInit())
|
||||
continue;
|
||||
if(data.texture->getSet() == VK_NULL_HANDLE)
|
||||
data.texture->setDescriptor(_renderer->getFragDescriptorSet().duplicate());
|
||||
if(data.texture->getLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||
data.texture->transitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
if(!data.texture->hasBeenUpdated())
|
||||
data.texture->updateSet(0);
|
||||
sets[1] = data.texture->getSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
data.texture->render(*_renderer, data.x, data.y);
|
||||
}
|
||||
for(auto& data : _drawlist)
|
||||
data->render(sets, *_renderer);
|
||||
|
||||
_pixel_put_pipeline.present();
|
||||
sets[1] = _pixel_put_pipeline.getDescriptorSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
_pixel_put_pipeline.render(*_renderer);
|
||||
|
||||
_text_put_pipeline->render(sets);
|
||||
_pixel_put_pipeline.render(sets, *_renderer);
|
||||
|
||||
_renderer->endFrame();
|
||||
|
||||
for(auto& data : _textures_to_render)
|
||||
data.texture->resetUpdate();
|
||||
for(auto& data : _drawlist)
|
||||
data->resetUpdate();
|
||||
|
||||
#ifdef GRAPHICS_MEMORY_DUMP
|
||||
// dump memory to file every two seconds
|
||||
@@ -100,7 +82,7 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
_text_put_pipeline->destroy();
|
||||
_text_manager.destroy();
|
||||
_pixel_put_pipeline.destroy();
|
||||
_renderer->destroy();
|
||||
if(_window)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
||||
/* Updated: 2024/01/10 19:59:58 by maldavid ### ########.fr */
|
||||
/* Updated: 2024/01/11 04:39:23 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#include <platform/window.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <renderer/pixel_put.h>
|
||||
#include <renderer/text_pipeline.h>
|
||||
#include <renderer/core/drawable_resource.h>
|
||||
#include <renderer/images/texture_manager.h>
|
||||
#include <renderer/texts/text_manager.h>
|
||||
#include <utils/non_copyable.h>
|
||||
#include <renderer/images/texture.h>
|
||||
#include <mlx_profile.h>
|
||||
@@ -48,20 +50,31 @@ namespace mlx
|
||||
inline void texturePut(Texture* texture, int x, int y);
|
||||
inline void loadFont(const std::filesystem::path& filepath, float scale);
|
||||
|
||||
inline bool hasWindow() const noexcept { return _has_window; }
|
||||
|
||||
inline Renderer& getRenderer() { return *_renderer; }
|
||||
|
||||
~GraphicsSupport();
|
||||
|
||||
private:
|
||||
std::vector<TextureRenderData> _textures_to_render;
|
||||
std::vector<DrawableResource*> _drawlist;
|
||||
|
||||
PixelPutPipeline _pixel_put_pipeline;
|
||||
|
||||
TextManager _text_manager;
|
||||
TextureManager _texture_manager;
|
||||
|
||||
glm::mat4 _proj = glm::mat4(1.0);
|
||||
|
||||
std::shared_ptr<MLX_Window> _window;
|
||||
std::unique_ptr<TextPutPipeline> _text_put_pipeline; // unique_ptr because of the size of the class
|
||||
std::unique_ptr<Renderer> _renderer;
|
||||
|
||||
std::size_t _width = 0;
|
||||
std::size_t _height = 0;
|
||||
|
||||
int _id;
|
||||
|
||||
bool _has_window;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <core/graphics.h>
|
||||
#include <type_traits>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -21,9 +21,10 @@ namespace mlx
|
||||
void GraphicsSupport::clearRenderData() noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_textures_to_render.clear();
|
||||
_drawlist.clear();
|
||||
_pixel_put_pipeline.clear();
|
||||
_text_put_pipeline->clear();
|
||||
_text_manager.clear();
|
||||
_texture_manager.clear();
|
||||
}
|
||||
|
||||
void GraphicsSupport::pixelPut(int x, int y, uint32_t color) noexcept
|
||||
@@ -35,21 +36,32 @@ namespace mlx
|
||||
void GraphicsSupport::stringPut(int x, int y, uint32_t color, std::string str)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_text_put_pipeline->put(x, y, color, str);
|
||||
std::pair<DrawableResource*, bool> res = _text_manager.registerText(x, y, color, str);
|
||||
if(!res.second) // if this is not a completly new text draw
|
||||
{
|
||||
auto it = std::find(_drawlist.begin(), _drawlist.end(), res.first);
|
||||
if(it != _drawlist.end())
|
||||
_drawlist.erase(it);
|
||||
}
|
||||
_drawlist.push_back(res.first);
|
||||
}
|
||||
|
||||
void GraphicsSupport::texturePut(Texture* texture, int x, int y)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_textures_to_render.emplace_back(texture, x, y);
|
||||
auto it = std::find(_textures_to_render.begin(), _textures_to_render.end() - 1, _textures_to_render.back());
|
||||
if(it != _textures_to_render.end() - 1)
|
||||
_textures_to_render.erase(it);
|
||||
auto res = _texture_manager.registerTexture(texture, x, y);
|
||||
if(!res.second) // if this is not a completly new texture draw
|
||||
{
|
||||
auto it = std::find(_drawlist.begin(), _drawlist.end(), res.first);
|
||||
if(it != _drawlist.end())
|
||||
_drawlist.erase(it);
|
||||
}
|
||||
_drawlist.push_back(res.first);
|
||||
}
|
||||
|
||||
void GraphicsSupport::loadFont(const std::filesystem::path& filepath, float scale)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
_text_put_pipeline->loadFont(filepath, scale);
|
||||
_text_manager.loadFont(*_renderer, filepath, scale);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user