Modules/RasterRender/public/VulkanRenderTarget.hpp
Шурупов Илья Викторович 6d200eb171 Port rendering stack from OpenGL to Vulkan
Replace the OpenGL rendering backend with Vulkan across the engine:

- Graphics: add VulkanContext (instance/device/swapchain/renderpass with
  depth-stencil), port Canvas to nanovg-on-Vulkan and DebugGUI to the imgui
  Vulkan backend, drop GLEW. Wait for the Wayland configure handshake before
  the first present and rebuild the swapchain to the confirmed size so the
  window maps reliably on fractional-scale outputs.
- RasterRender: reimplement RenderBuffer, shaders and object pipeline on
  Vulkan (offscreen VkImage target with MSAA resolve, SPIR-V pipelines,
  push-constant MVP, depth remap for Vulkan clip space).
- Sketch3D: port the stroke renderer (geometry-shader line expansion) and
  stroke GPU buffers to Vulkan.
- 3DEditor: port the path-tracer texture upload to a Vulkan staging upload
  and keep raster/path-tracer viewports oriented consistently.
- Add a nanovg external-VkImage bridge plus a render-target registry so 3D
  render targets can be shown inside the 2D canvas.
- Prefer the Wayland platform in GLFW regardless of DISPLAY.
- Widgets: make BasicLayout size distribution converge with a sub-pixel
  epsilon instead of an exact-zero comparison, which could otherwise spin
  forever on fractional-scale displays and block the first frame.

Vendor nanovg_vulkan and add a standalone VulkanGraphics module.
2026-10-13 03:04:08 +03:00

59 lines
1.8 KiB
C++

#pragma once
#include "VulkanContext.hpp"
#include <vulkan/vulkan.h>
namespace tp {
class VulkanRenderTarget {
public:
VulkanRenderTarget(VulkanContext* context, int width, int height, uint32_t samples);
~VulkanRenderTarget();
VulkanRenderTarget(const VulkanRenderTarget&) = delete;
VulkanRenderTarget& operator=(const VulkanRenderTarget&) = delete;
void resize(int width, int height);
void beginRenderPass(VkCommandBuffer commandBuffer, const VkClearColorValue& clearColor);
void endRenderPass(VkCommandBuffer commandBuffer);
VkRenderPass renderPass() const { return mRenderPass; }
VkExtent2D extent() const { return mExtent; }
VkSampleCountFlagBits sampleCount() const { return mSampleCount; }
VkImageView resolvedColorView() const { return mResolveView != VK_NULL_HANDLE ? mResolveView : mColorView; }
VkSampler sampler() const { return mSampler; }
VkImage resolvedColorImage() const { return mResolveImage != VK_NULL_HANDLE ? mResolveImage : mColorImage; }
private:
void createResources();
void destroyResources();
void createRenderPass();
void createSampler();
VulkanContext* mContext = nullptr;
VkExtent2D mExtent{};
VkSampleCountFlagBits mSampleCount = VK_SAMPLE_COUNT_1_BIT;
VkFormat mColorFormat = VK_FORMAT_R8G8B8A8_UNORM;
VkFormat mDepthFormat = VK_FORMAT_D24_UNORM_S8_UINT;
VkImage mColorImage = VK_NULL_HANDLE;
VkDeviceMemory mColorMemory = VK_NULL_HANDLE;
VkImageView mColorView = VK_NULL_HANDLE;
VkImage mResolveImage = VK_NULL_HANDLE;
VkDeviceMemory mResolveMemory = VK_NULL_HANDLE;
VkImageView mResolveView = VK_NULL_HANDLE;
VkImage mDepthImage = VK_NULL_HANDLE;
VkDeviceMemory mDepthMemory = VK_NULL_HANDLE;
VkImageView mDepthView = VK_NULL_HANDLE;
VkRenderPass mRenderPass = VK_NULL_HANDLE;
VkFramebuffer mFramebuffer = VK_NULL_HANDLE;
VkSampler mSampler = VK_NULL_HANDLE;
};
}