mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
adding possible new feature
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/11 19:46:49 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 21:04:48 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ namespace mlx::core
|
|||||||
|
|
||||||
inline void getScreenSize(int* w, int* h) noexcept;
|
inline void getScreenSize(int* w, int* h) noexcept;
|
||||||
|
|
||||||
inline void* newGraphicsSuport(std::size_t w, std::size_t h, std::string title);
|
inline void* newGraphicsSuport(std::size_t w, std::size_t h, const char* title);
|
||||||
inline void clearGraphicsSupport(void* win);
|
inline void clearGraphicsSupport(void* win);
|
||||||
inline void destroyGraphicsSupport(void* win);
|
inline void destroyGraphicsSupport(void* win);
|
||||||
|
|
||||||
|
|||||||
@@ -54,10 +54,19 @@ namespace mlx::core
|
|||||||
*h = DM.h;
|
*h = DM.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, std::string title)
|
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, const char* title)
|
||||||
{
|
{
|
||||||
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size()));
|
auto it = std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture)
|
||||||
_in->addWindow(_graphics.back()->getWindow());
|
{
|
||||||
|
return &texture == reinterpret_cast<Texture*>(const_cast<char*>(title));
|
||||||
|
});
|
||||||
|
if(it != _textures.end())
|
||||||
|
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, reinterpret_cast<Texture*>(const_cast<char*>(title)), _graphics.size()));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size()));
|
||||||
|
_in->addWindow(_graphics.back()->getWindow());
|
||||||
|
}
|
||||||
return static_cast<void*>(&_graphics.back()->getID());
|
return static_cast<void*>(&_graphics.back()->getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
|
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/15 21:04:50 by maldavid ### ########.fr */
|
/* Updated: 2023/12/22 23:10:51 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -14,14 +14,30 @@
|
|||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id) :
|
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)
|
||||||
|
{
|
||||||
|
_renderer->setWindow(nullptr);
|
||||||
|
_renderer->init(render_target);
|
||||||
|
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||||
|
_text_put_pipeline->init(_renderer.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||||
_window(std::make_shared<MLX_Window>(w, h, title)),
|
_window(std::make_shared<MLX_Window>(w, h, title)),
|
||||||
_text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
_text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||||
_renderer(std::make_unique<Renderer>()),
|
_renderer(std::make_unique<Renderer>()),
|
||||||
|
_width(w),
|
||||||
|
_height(h),
|
||||||
_id(id)
|
_id(id)
|
||||||
{
|
{
|
||||||
_renderer->setWindow(_window.get());
|
_renderer->setWindow(_window.get());
|
||||||
_renderer->init();
|
_renderer->init(nullptr);
|
||||||
_pixel_put_pipeline.init(w, h, *_renderer);
|
_pixel_put_pipeline.init(w, h, *_renderer);
|
||||||
_text_put_pipeline->init(_renderer.get());
|
_text_put_pipeline->init(_renderer.get());
|
||||||
}
|
}
|
||||||
@@ -76,6 +92,7 @@ namespace mlx
|
|||||||
_text_put_pipeline->destroy();
|
_text_put_pipeline->destroy();
|
||||||
_pixel_put_pipeline.destroy();
|
_pixel_put_pipeline.destroy();
|
||||||
_renderer->destroy();
|
_renderer->destroy();
|
||||||
_window->destroy();
|
if(_window)
|
||||||
|
_window->destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/11 19:47:03 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 23:10:14 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -33,7 +33,8 @@ namespace mlx
|
|||||||
class GraphicsSupport : public non_copyable
|
class GraphicsSupport : public non_copyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id);
|
GraphicsSupport(std::size_t w, std::size_t h, Texture* render_target, int id);
|
||||||
|
GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id);
|
||||||
|
|
||||||
inline int& getID() noexcept;
|
inline int& getID() noexcept;
|
||||||
inline std::shared_ptr<MLX_Window> getWindow();
|
inline std::shared_ptr<MLX_Window> getWindow();
|
||||||
@@ -56,6 +57,8 @@ namespace mlx
|
|||||||
std::shared_ptr<MLX_Window> _window;
|
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<TextPutPipeline> _text_put_pipeline; // unique_ptr because of the size of the class
|
||||||
std::unique_ptr<Renderer> _renderer;
|
std::unique_ptr<Renderer> _renderer;
|
||||||
|
std::size_t _width = 0;
|
||||||
|
std::size_t _height = 0;
|
||||||
int _id;
|
int _id;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
if(!_renderer->beginFrame())
|
if(!_renderer->beginFrame())
|
||||||
return;
|
return;
|
||||||
_proj = glm::ortho<float>(0, _window->getWidth(), 0, _window->getHeight());
|
_proj = glm::ortho<float>(0, _width, 0, _height);
|
||||||
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
|
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/10 22:46:08 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 23:07:44 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||||
{
|
{
|
||||||
Image::create(width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, name, dedicated_memory);
|
Image::create(width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, name, dedicated_memory);
|
||||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||||
Image::createSampler();
|
Image::createSampler();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/15 21:44:30 by maldavid ### ########.fr */
|
/* Updated: 2023/12/22 23:02:54 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -53,6 +53,7 @@ namespace mlx
|
|||||||
inline VkImageView getImageView() const noexcept { return _image_view; }
|
inline VkImageView getImageView() const noexcept { return _image_view; }
|
||||||
inline VkFormat getFormat() const noexcept { return _format; }
|
inline VkFormat getFormat() const noexcept { return _format; }
|
||||||
inline VkImageTiling getTiling() const noexcept { return _tiling; }
|
inline VkImageTiling getTiling() const noexcept { return _tiling; }
|
||||||
|
inline VkImageLayout getLayout() const noexcept { return _layout; }
|
||||||
inline VkSampler getSampler() const noexcept { return _sampler; }
|
inline VkSampler getSampler() const noexcept { return _sampler; }
|
||||||
inline uint32_t getWidth() const noexcept { return _width; }
|
inline uint32_t getWidth() const noexcept { return _width; }
|
||||||
inline uint32_t getHeight() const noexcept { return _height; }
|
inline uint32_t getHeight() const noexcept { return _height; }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
|
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/11/25 10:23:20 by maldavid ### ########.fr */
|
/* Updated: 2023/12/22 22:00:37 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -222,14 +222,14 @@ namespace mlx
|
|||||||
VkViewport viewport{};
|
VkViewport viewport{};
|
||||||
viewport.x = 0.0f;
|
viewport.x = 0.0f;
|
||||||
viewport.y = 0.0f;
|
viewport.y = 0.0f;
|
||||||
viewport.width = (float)renderer.getSwapChain().getExtent().width;
|
viewport.width = (float)renderer.getFrameBuffer(0).getWidth();
|
||||||
viewport.height = (float)renderer.getSwapChain().getExtent().height;
|
viewport.height = (float)renderer.getFrameBuffer(0).getHeight();
|
||||||
viewport.minDepth = 0.0f;
|
viewport.minDepth = 0.0f;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
|
|
||||||
VkRect2D scissor{};
|
VkRect2D scissor{};
|
||||||
scissor.offset = { 0, 0 };
|
scissor.offset = { 0, 0 };
|
||||||
scissor.extent = renderer.getSwapChain().getExtent();
|
scissor.extent = { renderer.getFrameBuffer(0).getWidth(), renderer.getFrameBuffer(0).getHeight()};
|
||||||
|
|
||||||
VkPipelineViewportStateCreateInfo viewportState{};
|
VkPipelineViewportStateCreateInfo viewportState{};
|
||||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||||
|
|||||||
@@ -6,25 +6,36 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/10 22:21:10 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 23:16:10 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <renderer/renderer.h>
|
#include <renderer/renderer.h>
|
||||||
|
#include <renderer/images/texture.h>
|
||||||
#include <renderer/core/render_core.h>
|
#include <renderer/core/render_core.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
void Renderer::init()
|
void Renderer::init(Texture* render_target)
|
||||||
{
|
{
|
||||||
_surface.create(*this);
|
if(render_target == nullptr)
|
||||||
_swapchain.init(this);
|
{
|
||||||
_pass.init(_swapchain.getImagesFormat());
|
_surface.create(*this);
|
||||||
|
_swapchain.init(this);
|
||||||
|
_pass.init(_swapchain.getImagesFormat(), VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||||
|
for(std::size_t i = 0; i < _swapchain.getImagesNumber(); i++)
|
||||||
|
_framebuffers.emplace_back().init(_pass, _swapchain.getImage(i));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_render_target = render_target;
|
||||||
|
_render_target->transitionLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||||
|
_pass.init(_render_target->getFormat(), _render_target->getLayout());
|
||||||
|
_framebuffers.emplace_back().init(_pass, *static_cast<Image*>(_render_target));
|
||||||
|
}
|
||||||
_cmd.init();
|
_cmd.init();
|
||||||
|
|
||||||
for(std::size_t i = 0; i < _swapchain.getImagesNumber(); i++)
|
|
||||||
_framebuffers.emplace_back().init(_pass, _swapchain.getImage(i));
|
|
||||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||||
_semaphores[i].init();
|
_semaphores[i].init();
|
||||||
|
|
||||||
@@ -65,15 +76,20 @@ namespace mlx
|
|||||||
_cmd.getCmdBuffer(_current_frame_index).waitForExecution();
|
_cmd.getCmdBuffer(_current_frame_index).waitForExecution();
|
||||||
_cmd.getCmdBuffer(_current_frame_index).reset();
|
_cmd.getCmdBuffer(_current_frame_index).reset();
|
||||||
|
|
||||||
VkResult result = vkAcquireNextImageKHR(device, _swapchain(), UINT64_MAX, _semaphores[_current_frame_index].getImageSemaphore(), VK_NULL_HANDLE, &_image_index);
|
if(_render_target == nullptr)
|
||||||
|
|
||||||
if(result == VK_ERROR_OUT_OF_DATE_KHR)
|
|
||||||
{
|
{
|
||||||
_swapchain.recreate();
|
VkResult result = vkAcquireNextImageKHR(device, _swapchain(), UINT64_MAX, _semaphores[_current_frame_index].getImageSemaphore(), VK_NULL_HANDLE, &_image_index);
|
||||||
return false;
|
|
||||||
|
if(result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||||
|
{
|
||||||
|
_swapchain.recreate();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
||||||
|
core::error::report(e_kind::fatal_error, "Vulkan error : failed to acquire swapchain image");
|
||||||
}
|
}
|
||||||
else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
else
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to acquire swapchain image");
|
_image_index = 0;
|
||||||
|
|
||||||
_cmd.getCmdBuffer(_current_frame_index).beginRecord();
|
_cmd.getCmdBuffer(_current_frame_index).beginRecord();
|
||||||
auto& fb = _framebuffers[_image_index];
|
auto& fb = _framebuffers[_image_index];
|
||||||
@@ -102,28 +118,34 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
_pass.end(getActiveCmdBuffer());
|
_pass.end(getActiveCmdBuffer());
|
||||||
_cmd.getCmdBuffer(_current_frame_index).endRecord();
|
_cmd.getCmdBuffer(_current_frame_index).endRecord();
|
||||||
_cmd.getCmdBuffer(_current_frame_index).submit(_semaphores[_current_frame_index]);
|
|
||||||
|
|
||||||
VkSwapchainKHR swapchain = _swapchain();
|
if(_render_target == nullptr)
|
||||||
VkSemaphore signalSemaphores[] = { _semaphores[_current_frame_index].getRenderImageSemaphore() };
|
|
||||||
|
|
||||||
VkPresentInfoKHR presentInfo{};
|
|
||||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
||||||
presentInfo.waitSemaphoreCount = 1;
|
|
||||||
presentInfo.pWaitSemaphores = signalSemaphores;
|
|
||||||
presentInfo.swapchainCount = 1;
|
|
||||||
presentInfo.pSwapchains = &swapchain;
|
|
||||||
presentInfo.pImageIndices = &_image_index;
|
|
||||||
|
|
||||||
VkResult result = vkQueuePresentKHR(Render_Core::get().getQueue().getPresent(), &presentInfo);
|
|
||||||
|
|
||||||
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || _framebufferResized)
|
|
||||||
{
|
{
|
||||||
_framebufferResized = false;
|
_cmd.getCmdBuffer(_current_frame_index).submit(_semaphores[_current_frame_index]);
|
||||||
_swapchain.recreate();
|
|
||||||
|
VkSwapchainKHR swapchain = _swapchain();
|
||||||
|
VkSemaphore signalSemaphores[] = { _semaphores[_current_frame_index].getRenderImageSemaphore() };
|
||||||
|
|
||||||
|
VkPresentInfoKHR presentInfo{};
|
||||||
|
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
|
presentInfo.waitSemaphoreCount = 1;
|
||||||
|
presentInfo.pWaitSemaphores = signalSemaphores;
|
||||||
|
presentInfo.swapchainCount = 1;
|
||||||
|
presentInfo.pSwapchains = &swapchain;
|
||||||
|
presentInfo.pImageIndices = &_image_index;
|
||||||
|
|
||||||
|
VkResult result = vkQueuePresentKHR(Render_Core::get().getQueue().getPresent(), &presentInfo);
|
||||||
|
|
||||||
|
if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || _framebufferResized)
|
||||||
|
{
|
||||||
|
_framebufferResized = false;
|
||||||
|
_swapchain.recreate();
|
||||||
|
}
|
||||||
|
else if(result != VK_SUCCESS)
|
||||||
|
core::error::report(e_kind::fatal_error, "Vulkan error : failed to present swap chain image");
|
||||||
}
|
}
|
||||||
else if(result != VK_SUCCESS)
|
else
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to present swap chain image");
|
_cmd.getCmdBuffer(_current_frame_index).submitIdle();
|
||||||
|
|
||||||
_current_frame_index = (_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
_current_frame_index = (_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||||
}
|
}
|
||||||
@@ -139,11 +161,13 @@ namespace mlx
|
|||||||
_cmd.destroy();
|
_cmd.destroy();
|
||||||
_desc_pool.destroy();
|
_desc_pool.destroy();
|
||||||
_pass.destroy();
|
_pass.destroy();
|
||||||
_swapchain.destroy();
|
if(_render_target == nullptr)
|
||||||
|
_swapchain.destroy();
|
||||||
for(auto& fb : _framebuffers)
|
for(auto& fb : _framebuffers)
|
||||||
fb.destroy();
|
fb.destroy();
|
||||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||||
_semaphores[i].destroy();
|
_semaphores[i].destroy();
|
||||||
_surface.destroy();
|
if(_render_target == nullptr)
|
||||||
|
_surface.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/10 22:19:41 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 21:59:15 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ namespace mlx
|
|||||||
public:
|
public:
|
||||||
Renderer() = default;
|
Renderer() = default;
|
||||||
|
|
||||||
void init();
|
void init(class Texture* render_target);
|
||||||
|
|
||||||
bool beginFrame();
|
bool beginFrame();
|
||||||
void endFrame();
|
void endFrame();
|
||||||
@@ -102,6 +102,7 @@ namespace mlx
|
|||||||
inline GraphicPipeline& getPipeline() noexcept { return _pipeline; }
|
inline GraphicPipeline& getPipeline() noexcept { return _pipeline; }
|
||||||
inline CmdBuffer& getCmdBuffer(int i) noexcept { return _cmd.getCmdBuffer(i); }
|
inline CmdBuffer& getCmdBuffer(int i) noexcept { return _cmd.getCmdBuffer(i); }
|
||||||
inline CmdBuffer& getActiveCmdBuffer() noexcept { return _cmd.getCmdBuffer(_current_frame_index); }
|
inline CmdBuffer& getActiveCmdBuffer() noexcept { return _cmd.getCmdBuffer(_current_frame_index); }
|
||||||
|
inline FrameBuffer& getFrameBuffer(int i) noexcept { return _framebuffers[i]; }
|
||||||
inline DescriptorSet& getVertDescriptorSet() noexcept { return _vert_set; }
|
inline DescriptorSet& getVertDescriptorSet() noexcept { return _vert_set; }
|
||||||
inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; }
|
inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; }
|
||||||
inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; }
|
inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; }
|
||||||
@@ -133,6 +134,7 @@ namespace mlx
|
|||||||
std::unique_ptr<UBO> _uniform_buffer;
|
std::unique_ptr<UBO> _uniform_buffer;
|
||||||
|
|
||||||
class MLX_Window* _window = nullptr;
|
class MLX_Window* _window = nullptr;
|
||||||
|
class Texture* _render_target = nullptr;
|
||||||
|
|
||||||
uint32_t _current_frame_index = 0;
|
uint32_t _current_frame_index = 0;
|
||||||
uint32_t _image_index = 0;
|
uint32_t _image_index = 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/06 18:21:36 by maldavid #+# #+# */
|
/* Created: 2022/10/06 18:21:36 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/10 22:32:27 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 23:05:38 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
static const VkClearValue clearColor = {{{ 0.0f, 0.0f, 0.0f, 1.0f }}}; // wtf, this mess to satisfy a warning
|
static const VkClearValue clearColor = {{{ 0.0f, 0.0f, 0.0f, 1.0f }}}; // wtf, this mess to satisfy a warning
|
||||||
|
|
||||||
void RenderPass::init(VkFormat attachement_format)
|
void RenderPass::init(VkFormat attachement_format, VkImageLayout layout)
|
||||||
{
|
{
|
||||||
VkAttachmentDescription colorAttachment{};
|
VkAttachmentDescription colorAttachment{};
|
||||||
colorAttachment.format = attachement_format;
|
colorAttachment.format = attachement_format;
|
||||||
@@ -30,11 +30,11 @@ namespace mlx
|
|||||||
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
colorAttachment.finalLayout = layout;
|
||||||
|
|
||||||
VkAttachmentReference colorAttachmentRef{};
|
VkAttachmentReference colorAttachmentRef{};
|
||||||
colorAttachmentRef.attachment = 0;
|
colorAttachmentRef.attachment = 0;
|
||||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colorAttachmentRef.layout = (layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : layout);
|
||||||
|
|
||||||
VkSubpassDescription subpass{};
|
VkSubpassDescription subpass{};
|
||||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/06 18:22:00 by maldavid #+# #+# */
|
/* Created: 2022/10/06 18:22:00 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/08 19:11:14 by kbz_8 ### ########.fr */
|
/* Updated: 2023/12/22 23:00:00 by kbz_8 ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ namespace mlx
|
|||||||
class RenderPass
|
class RenderPass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void init(VkFormat attachement_format);
|
void init(VkFormat attachement_format, VkImageLayout layout);
|
||||||
void destroy() noexcept;
|
void destroy() noexcept;
|
||||||
|
|
||||||
void begin(class CmdBuffer& cmd, class FrameBuffer& fb);
|
void begin(class CmdBuffer& cmd, class FrameBuffer& fb);
|
||||||
|
|||||||
Reference in New Issue
Block a user