mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Improve backbuffer depth buffer.
- Setting the depth buffer for the backbuffer is now done as a boolean instead of a bit depth integer, in love.conf or love.window.setMode. - Error if depth writes are enabled when the active canvas setup or backbuffer does not have a depth buffer (now it matches stencil behaviour). - Don't allocate a backbuffer depth-stencil buffer if they're not requested. Metal also determines the format for that buffer based on which combination of depth and stencil is requested. OpenGL still has to allocate the depth-stencil buffer for the backbuffer all the time, because changing it requires the context to be recreated.
This commit is contained in:
@@ -587,9 +587,10 @@ void Graphics::present(void *screenshotCallbackdata)
|
||||
beginFrame();
|
||||
}
|
||||
|
||||
void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelheight)
|
||||
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
{
|
||||
if (swapChain != VK_NULL_HANDLE && (pixelwidth != this->pixelWidth || pixelheight != this->pixelHeight || width != this->width || height != this->height))
|
||||
if (swapChain != VK_NULL_HANDLE && (pixelwidth != this->pixelWidth || pixelheight != this->pixelHeight || width != this->width || height != this->height
|
||||
|| backbufferstencil != this->backbufferHasStencil || backbufferdepth != this->backbufferHasDepth || msaa != requestedMsaa))
|
||||
requestSwapchainRecreation();
|
||||
|
||||
this->width = width;
|
||||
@@ -597,17 +598,21 @@ void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelh
|
||||
this->pixelWidth = pixelwidth;
|
||||
this->pixelHeight = pixelheight;
|
||||
|
||||
this->backbufferHasStencil = backbufferstencil;
|
||||
this->backbufferHasDepth = backbufferdepth;
|
||||
this->requestedMsaa = msaa;
|
||||
|
||||
if (!isRenderTargetActive())
|
||||
resetProjection();
|
||||
|
||||
if (swapChain != VK_NULL_HANDLE)
|
||||
msaaSamples = getMsaaCount(requestedMsaa);
|
||||
}
|
||||
|
||||
bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool windowhasstencil, int msaa)
|
||||
bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
|
||||
{
|
||||
requestedMsaa = msaa;
|
||||
windowHasStencil = windowhasstencil;
|
||||
|
||||
// Must be called before the swapchain is created.
|
||||
setViewportSize(width, height, pixelwidth, pixelheight);
|
||||
backbufferChanged(width, height, pixelwidth, pixelheight, backbufferstencil, backbufferdepth, msaa);
|
||||
|
||||
cleanUpFunctions.clear();
|
||||
cleanUpFunctions.resize(MAX_FRAMES_IN_FLIGHT);
|
||||
@@ -1003,16 +1008,7 @@ void Graphics::setScissor()
|
||||
|
||||
void Graphics::setStencilState(const StencilState &s)
|
||||
{
|
||||
if (s.action != STENCIL_KEEP)
|
||||
{
|
||||
const auto& rts = states.back().renderTargets;
|
||||
auto dsTexture = rts.depthStencil.texture.get();
|
||||
|
||||
if (!isRenderTargetActive() && !windowHasStencil)
|
||||
throw love::Exception("The window must have stenciling enabled to draw to the main screen's stencil buffer");
|
||||
else if (isRenderTargetActive() && (rts.temporaryRTFlags & TEMPORARY_RT_STENCIL) == 0 && (dsTexture == nullptr || !isPixelFormatStencil(dsTexture->getPixelFormat())))
|
||||
throw love::Exception("drawing to the stencil buffer with a render target active requires either stencil=true or a custom stencil-type to be used, in setRenderTarget");
|
||||
}
|
||||
validateStencilState(s);
|
||||
|
||||
flushBatchedDraws();
|
||||
|
||||
@@ -1033,6 +1029,8 @@ void Graphics::setStencilState(const StencilState &s)
|
||||
|
||||
void Graphics::setDepthMode(CompareMode compare, bool write)
|
||||
{
|
||||
validateDepthState(write);
|
||||
|
||||
flushBatchedDraws();
|
||||
|
||||
if (optionalDeviceExtensions.extendedDynamicState)
|
||||
@@ -1284,11 +1282,12 @@ void Graphics::beginFrame()
|
||||
|
||||
if (transitionColorDepthLayouts)
|
||||
{
|
||||
Vulkan::cmdTransitionImageLayout(
|
||||
commandBuffers.at(currentFrame),
|
||||
depthImage,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
if (depthImage)
|
||||
Vulkan::cmdTransitionImageLayout(
|
||||
commandBuffers.at(currentFrame),
|
||||
depthImage,
|
||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
|
||||
if (colorImage)
|
||||
Vulkan::cmdTransitionImageLayout(
|
||||
@@ -2935,6 +2934,13 @@ VkFormat Graphics::findDepthFormat()
|
||||
|
||||
void Graphics::createDepthResources()
|
||||
{
|
||||
if (!backbufferHasDepth && !backbufferHasStencil)
|
||||
{
|
||||
depthImage = VK_NULL_HANDLE;
|
||||
depthImageView = VK_NULL_HANDLE;
|
||||
return;
|
||||
}
|
||||
|
||||
VkImageCreateInfo imageInfo{};
|
||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||
@@ -2966,8 +2972,9 @@ void Graphics::createDepthResources()
|
||||
imageViewInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
imageViewInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
imageViewInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
imageViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
if (windowHasStencil)
|
||||
if (backbufferHasDepth)
|
||||
imageViewInfo.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
if (backbufferHasStencil)
|
||||
imageViewInfo.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
imageViewInfo.subresourceRange.baseMipLevel = 0;
|
||||
imageViewInfo.subresourceRange.levelCount = 1;
|
||||
@@ -3076,8 +3083,11 @@ void Graphics::cleanupSwapChain()
|
||||
vkDestroyImageView(device, colorImageView, nullptr);
|
||||
vmaDestroyImage(vmaAllocator, colorImage, colorImageAllocation);
|
||||
}
|
||||
vkDestroyImageView(device, depthImageView, nullptr);
|
||||
vmaDestroyImage(vmaAllocator, depthImage, depthImageAllocation);
|
||||
if (depthImage)
|
||||
{
|
||||
vkDestroyImageView(device, depthImageView, nullptr);
|
||||
vmaDestroyImage(vmaAllocator, depthImage, depthImageAllocation);
|
||||
}
|
||||
for (const auto &swapChainImageView : swapChainImageViews)
|
||||
vkDestroyImageView(device, swapChainImageView, nullptr);
|
||||
swapChainImageViews.clear();
|
||||
|
||||
Reference in New Issue
Block a user