diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index f9ee6532f..0291f7de7 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -891,10 +891,10 @@ void Graphics::setRenderTargets(const RenderTargets &rts) realRTs.depthStencil.texture = getTemporaryTexture(dsformat, pixelw, pixelh, reqmsaa); realRTs.depthStencil.slice = 0; - setRenderTargetsInternal(realRTs, w, h, pixelw, pixelh, hasSRGBtexture); + setRenderTargetsInternal(realRTs, pixelw, pixelh, hasSRGBtexture); } else - setRenderTargetsInternal(rts, w, h, pixelw, pixelh, hasSRGBtexture); + setRenderTargetsInternal(rts, pixelw, pixelh, hasSRGBtexture); RenderTargetsStrongRef refs; refs.colors.reserve(rts.colors.size()); @@ -920,7 +920,7 @@ void Graphics::setRenderTarget() return; flushBatchedDraws(); - setRenderTargetsInternal(RenderTargets(), width, height, pixelWidth, pixelHeight, isGammaCorrect()); + setRenderTargetsInternal(RenderTargets(), pixelWidth, pixelHeight, isGammaCorrect()); state.renderTargets = RenderTargetsStrongRef(); renderTargetSwitchCount++; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index f318ca78e..be813d0ce 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -982,7 +982,7 @@ protected: virtual bool dispatch(int x, int y, int z) = 0; - virtual void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) = 0; + virtual void setRenderTargetsInternal(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBtexture) = 0; virtual void initCapabilities() = 0; virtual void getAPIStats(int &shaderswitches) const = 0; diff --git a/src/modules/graphics/metal/Graphics.h b/src/modules/graphics/metal/Graphics.h index 104bc9eab..ea1c2d2f9 100644 --- a/src/modules/graphics/metal/Graphics.h +++ b/src/modules/graphics/metal/Graphics.h @@ -201,7 +201,7 @@ private: love::graphics::ShaderStage *newShaderStageInternal(ShaderStageType stage, const std::string &cachekey, const std::string &source, bool gles) override; love::graphics::Shader *newShaderInternal(StrongRef stages[SHADERSTAGE_MAX_ENUM]) override; love::graphics::StreamBuffer *newStreamBuffer(BufferUsage usage, size_t size) override; - void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBcanvas) override; + void setRenderTargetsInternal(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBcanvas) override; void initCapabilities() override; void getAPIStats(int &shaderswitches) const override; @@ -226,6 +226,7 @@ private: uint32 dirtyRenderState; CullMode lastCullMode; VertexAttributes lastVertexAttributes; + PixelFormat activeDepthStencilFormat; bool windowHasStencil; int shaderSwitches; diff --git a/src/modules/graphics/metal/Graphics.mm b/src/modules/graphics/metal/Graphics.mm index 7e9890531..3d260b9a3 100644 --- a/src/modules/graphics/metal/Graphics.mm +++ b/src/modules/graphics/metal/Graphics.mm @@ -270,6 +270,7 @@ Graphics::Graphics() , passDesc(nil) , dirtyRenderState(STATEBIT_ALL) , lastCullMode(CULL_MAX_ENUM) + , activeDepthStencilFormat(PIXELFORMAT_UNKNOWN) , windowHasStencil(false) , shaderSwitches(0) , requestedBackbufferMSAA(0) @@ -920,9 +921,9 @@ void Graphics::applyRenderState(id encoder, const Verte for (size_t i = 0; i < rts.size(); i++) key.colorRenderTargetFormats |= (rts[i].texture->getPixelFormat()) << (8 * i); - // TODO: automatic depth/stencil (state doesn't store it). - if (state.renderTargets.depthStencil.texture.get()) - key.depthStencilFormat = state.renderTargets.depthStencil.texture->getPixelFormat(); + // Don't query the current RTs because they don't include + // automatic depth/stencil. + key.depthStencilFormat = activeDepthStencilFormat; key.msaa = (uint8) firsttarget.texture->getMSAA(); } @@ -1321,7 +1322,7 @@ bool Graphics::dispatch(int x, int y, int z) return true; }} -void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int /*w*/, int /*h*/, int /*pixelw*/, int /*pixelh*/, bool /*hasSRGBtexture*/) +void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int /*pixelw*/, int /*pixelh*/, bool /*hasSRGBtexture*/) { @autoreleasepool { endPass(); @@ -1346,18 +1347,21 @@ void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int /*w*/, int if (isbackbuffer && ds == nullptr) ds = backbufferDepthStencil; + PixelFormat dsformat = PIXELFORMAT_UNKNOWN; if (ds != nullptr) { RenderTarget rt = rts.depthStencil; rt.texture = ds; + dsformat = ds->getPixelFormat(); - if (isPixelFormatDepth(ds->getPixelFormat())) + if (isPixelFormatDepth(dsformat)) setAttachment(rt, passDesc.depthAttachment, attachmentStoreActions.depth); - if (isPixelFormatStencil(ds->getPixelFormat())) + if (isPixelFormatStencil(dsformat)) setAttachment(rt, passDesc.stencilAttachment, attachmentStoreActions.stencil); } + activeDepthStencilFormat = dsformat; dirtyRenderState = STATEBIT_ALL; lastVertexAttributes = VertexAttributes(); }} diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index d10663048..cdde43887 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -742,7 +742,7 @@ void Graphics::setDebug(bool enable) ::printf("OpenGL debug output enabled (LOVE_GRAPHICS_DEBUG=1)\n"); } -void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int /*w*/, int /*h*/, int pixelw, int pixelh, bool hasSRGBtexture) +void Graphics::setRenderTargetsInternal(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBtexture) { const DisplayState &state = states.back(); diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index e364ac51b..70955c325 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -144,7 +144,7 @@ private: love::graphics::ShaderStage *newShaderStageInternal(ShaderStageType stage, const std::string &cachekey, const std::string &source, bool gles) override; love::graphics::Shader *newShaderInternal(StrongRef stages[SHADERSTAGE_MAX_ENUM]) override; love::graphics::StreamBuffer *newStreamBuffer(BufferUsage type, size_t size) override; - void setRenderTargetsInternal(const RenderTargets &rts, int w, int h, int pixelw, int pixelh, bool hasSRGBtexture) override; + void setRenderTargetsInternal(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBtexture) override; void initCapabilities() override; void getAPIStats(int &shaderswitches) const override;