fixing issue with fonts vulkan descriptor destroyed

This commit is contained in:
2024-01-08 22:18:45 +01:00
parent c88d9f1d9d
commit c64cb4ac67
5 changed files with 40 additions and 26 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */ /* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2024/01/07 01:24:29 by maldavid ### ########.fr */ /* Updated: 2024/01/08 22:17:57 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -32,8 +32,8 @@ int update(void *param)
mlx = (t_mlx *)param; mlx = (t_mlx *)param;
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100);
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60); mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
if (i == 0) //if (i == 0)
mlx_set_font_scale(mlx->mlx, mlx->win, "font.ttf", 16.f); // mlx_set_font_scale(mlx->mlx, mlx->win, "font.ttf", 16.f);
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text"); mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
j = 0; j = 0;
k = 0; k = 0;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */ /* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/01/07 01:31:44 by maldavid ### ########.fr */ /* Updated: 2023/12/27 21:30:10 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -38,19 +38,12 @@ namespace mlx::core
{ {
_in->update(); _in->update();
Render_Core::get().getSingleTimeCmdManager().updateSingleTimesCmdBuffersSubmitState();
if(_loop_hook) if(_loop_hook)
_loop_hook(_param); _loop_hook(_param);
for(auto& gs : _graphics) for(auto& gs : _graphics)
gs->render(); gs->render();
} }
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) void* Application::newTexture(int w, int h)
@@ -71,16 +64,9 @@ namespace mlx::core
void Application::destroyTexture(void* ptr) void Application::destroyTexture(void* ptr)
{ {
if(ptr == nullptr) vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than stopping all the GPU process
{
core::error::report(e_kind::error, "wrong texture (NULL)");
return;
}
Texture* texture = static_cast<Texture*>(ptr); Texture* texture = static_cast<Texture*>(ptr);
if(!texture->isInit()) texture->destroy();
core::error::report(e_kind::error, "trying to destroy a texture that has already been destroyed");
else
texture->destroy();
} }
Application::~Application() Application::~Application()

View File

@@ -64,6 +64,11 @@ namespace mlx::core
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, reinterpret_cast<Texture*>(const_cast<char*>(title)), _graphics.size())); _graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, reinterpret_cast<Texture*>(const_cast<char*>(title)), _graphics.size()));
else else
{ {
if(title == NULL)
{
core::error::report(e_kind::fatal_error, "invalid window title (NULL)");
return nullptr;
}
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size())); _graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size()));
_in->addWindow(_graphics.back()->getWindow()); _in->addWindow(_graphics.back()->getWindow());
} }
@@ -91,6 +96,16 @@ namespace mlx::core
void Application::stringPut(void* win, int x, int y, int color, char* str) void Application::stringPut(void* win, int x, int y, int color, char* str)
{ {
CHECK_WINDOW_PTR(win); CHECK_WINDOW_PTR(win);
if(str == nullptr)
{
core::error::report(e_kind::error, "wrong text (NULL)");
return;
}
if(std::strlen(str) == 0)
{
core::error::report(e_kind::error, "trying to put an empty text");
return;
}
_graphics[*static_cast<int*>(win)]->stringPut(x, y, color, str); _graphics[*static_cast<int*>(win)]->stringPut(x, y, color, str);
} }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */ /* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */
/* Updated: 2023/12/23 18:49:25 by kbz_8 ### ########.fr */ /* Updated: 2024/01/08 21:42:31 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -31,12 +31,15 @@ namespace mlx
inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; } inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; }
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; } inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
inline void updateSet(int binding) const noexcept { _set.writeDescriptor(binding, *this); } inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, *this); _has_been_updated = true; }
inline bool hasBeenUpdated() const noexcept { return _has_been_updated; }
inline constexpr void resetUpdate() noexcept { _has_been_updated = false; }
~TextureAtlas() = default; ~TextureAtlas() = default;
private: private:
DescriptorSet _set; DescriptorSet _set;
bool _has_been_updated = false;
}; };
} }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */ /* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */ /* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
/* Updated: 2023/12/14 17:49:37 by maldavid ### ########.fr */ /* Updated: 2024/01/08 21:42:15 by maldavid ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -46,7 +46,7 @@ namespace mlx
for(char c : text) for(char c : text)
{ {
if(c < 32) if(c < 32 && c != '\n')
continue; continue;
stbtt_aligned_quad q; stbtt_aligned_quad q;
@@ -110,13 +110,23 @@ namespace mlx
for(auto& draw : _drawlist) for(auto& draw : _drawlist)
{ {
std::shared_ptr<TextData> draw_data = _library.getTextData(draw.id); std::shared_ptr<TextData> draw_data = _library.getTextData(draw.id);
const TextureAtlas& atlas = draw_data->getFontInUse().getAtlas(); TextureAtlas& atlas = const_cast<TextureAtlas&>(draw_data->getFontInUse().getAtlas());
draw_data->bind(*_renderer); draw_data->bind(*_renderer);
atlas.updateSet(0); if(atlas.getSet() == VK_NULL_HANDLE)
atlas.setDescriptor(_renderer->getFragDescriptorSet().duplicate());
if(!atlas.hasBeenUpdated())
atlas.updateSet(0);
sets[1] = const_cast<TextureAtlas&>(atlas).getSet(); sets[1] = const_cast<TextureAtlas&>(atlas).getSet();
vkCmdBindDescriptorSets(_renderer->getActiveCmdBuffer().get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr); vkCmdBindDescriptorSets(_renderer->getActiveCmdBuffer().get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
atlas.render(*_renderer, draw.x, draw.y, draw_data->getIBOsize()); atlas.render(*_renderer, draw.x, draw.y, draw_data->getIBOsize());
} }
for(auto& draw : _drawlist)
{
std::shared_ptr<TextData> draw_data = _library.getTextData(draw.id);
TextureAtlas& atlas = const_cast<TextureAtlas&>(draw_data->getFontInUse().getAtlas());
atlas.resetUpdate();
}
} }
void TextPutPipeline::destroy() noexcept void TextPutPipeline::destroy() noexcept