- Depth image (D32_SFLOAT) + image view created in VulkanSwapchain - VkPipelineDepthStencilStateCreateInfo: depth test + write enabled, CompareOp=Less - Push constant changed from float angle (4B) to mat4 model (64B) - 3D rotation: RotateY * RotateX in renderer, applied via push constant - Vertex shader: gl_Position = vp * model * vec4(pos, 1.0) - Depth attachment in VkRenderingInfo + depth clear (1.0) - Depth image layout transition (Undefined → DepthStencilAttachmentOptimal) - New Vulkan functions: vkCreateImage, vkDestroyImage, vkGetImageMemoryRequirements, vkBindImageMemory - New structs: VkPipelineDepthStencilStateCreateInfo, VkStencilOpState, VkImageCreateInfo - New enums: VkCompareOp, VkImageType, VkImageTiling - 0 validation errors
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using Engine.Core;
|
|
|
|
namespace Engine.Graphics.Vulkan;
|
|
|
|
internal sealed class VulkanRenderContext : IRenderContext
|
|
{
|
|
private readonly VulkanContext _ctx;
|
|
private readonly VulkanSwapchain _swapchain;
|
|
private readonly IWindow _window;
|
|
private bool _disposed;
|
|
|
|
public IWindow Window => _window;
|
|
|
|
public VulkanRenderContext(IWindow window, bool enableValidation)
|
|
{
|
|
_window = window;
|
|
_ctx = new VulkanContext(window, enableValidation);
|
|
|
|
var surfaceFormat = new VkSurfaceFormatKHR
|
|
{
|
|
format = _ctx.SurfaceFormat,
|
|
colorSpace = _ctx.SurfaceColorSpace,
|
|
};
|
|
|
|
_swapchain = new VulkanSwapchain(_ctx.Device, _ctx.PhysicalDevice, _ctx.Surface,
|
|
surfaceFormat, window.Width, window.Height, _ctx);
|
|
}
|
|
|
|
public IRenderer CreateRenderer()
|
|
{
|
|
return new VulkanRenderer(_ctx, _swapchain);
|
|
}
|
|
|
|
public void Resize(int width, int height)
|
|
{
|
|
_swapchain.Recreate(width, height);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (_disposed) return;
|
|
_disposed = true;
|
|
|
|
_swapchain?.Dispose();
|
|
_ctx?.Dispose();
|
|
_window?.Dispose();
|
|
}
|
|
}
|