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:
Sasha Szpakowski
2024-01-06 15:21:06 -04:00
parent 621a7547d2
commit aaab9791d5
11 changed files with 183 additions and 110 deletions
+35
View File
@@ -185,6 +185,8 @@ Graphics::Graphics()
, height(0)
, pixelWidth(0)
, pixelHeight(0)
, backbufferHasStencil(false)
, backbufferHasDepth(false)
, created(false)
, active(true)
, batchedDrawState()
@@ -617,6 +619,34 @@ Texture *Graphics::getTextureOrDefaultForActiveShader(Texture *tex)
return getDefaultTexture(TEXTURE_2D, DATA_BASETYPE_FLOAT);
}
void Graphics::validateStencilState(const StencilState &s) const
{
if (s.action != STENCIL_KEEP)
{
const auto &rts = states.back().renderTargets;
love::graphics::Texture *dstexture = rts.depthStencil.texture.get();
if (!isRenderTargetActive() && !backbufferHasStencil)
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 Canvas active requires either stencil=true or a custom stencil-type Canvas to be used, in setCanvas.");
}
}
void Graphics::validateDepthState(bool depthwrite) const
{
if (depthwrite)
{
const auto &rts = states.back().renderTargets;
love::graphics::Texture *dstexture = rts.depthStencil.texture.get();
if (!isRenderTargetActive() && !backbufferHasDepth)
throw love::Exception("The window must have depth enabled to draw to the main screen's depth buffer.");
else if (isRenderTargetActive() && (rts.temporaryRTFlags & TEMPORARY_RT_DEPTH) == 0 && (dstexture == nullptr || !isPixelFormatDepth(dstexture->getPixelFormat())))
throw love::Exception("Drawing to the depth buffer with a Canvas active requires either depth=true or a custom depth-type Canvas to be used, in setCanvas.");
}
}
int Graphics::getWidth() const
{
return width;
@@ -671,6 +701,11 @@ void Graphics::reset()
origin();
}
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight)
{
backbufferChanged(width, height, pixelwidth, pixelheight, backbufferHasStencil, backbufferHasDepth, getRequestedBackbufferMSAA());
}
/**
* State functions.
**/