implement color buffer clear

This commit is contained in:
Samuliak 2024-08-04 15:09:49 +02:00
parent 763d57d921
commit 5030a2e84a
2 changed files with 24 additions and 14 deletions

View File

@ -126,7 +126,10 @@ bool MetalRenderer::GetVRAMInfo(int& usageInMB, int& totalInMB) const
void MetalRenderer::ClearColorbuffer(bool padView) void MetalRenderer::ClearColorbuffer(bool padView)
{ {
debug_printf("MetalRenderer::ClearColorbuffer not implemented\n"); if (!AcquireNextDrawable())
return;
ClearColorTextureInternal(m_drawable->texture(), 0, 0, 0.0f, 0.0f, 0.0f, 0.0f);
} }
void MetalRenderer::DrawEmptyFrame(bool mainWindow) void MetalRenderer::DrawEmptyFrame(bool mainWindow)
@ -283,19 +286,7 @@ void MetalRenderer::texture_clearColorSlice(LatteTexture* hostTexture, sint32 sl
{ {
auto mtlTexture = static_cast<LatteTextureMtl*>(hostTexture)->GetTexture(); auto mtlTexture = static_cast<LatteTextureMtl*>(hostTexture)->GetTexture();
MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init(); ClearColorTextureInternal(mtlTexture, sliceIndex, mipIndex, r, g, b, a);
auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0);
colorAttachment->setTexture(mtlTexture);
colorAttachment->setClearColor(MTL::ClearColor(r, g, b, a));
colorAttachment->setLoadAction(MTL::LoadActionClear);
colorAttachment->setStoreAction(MTL::StoreActionStore);
colorAttachment->setSlice(sliceIndex);
colorAttachment->setLevel(mipIndex);
MTL::Texture* colorRenderTargets[8] = {nullptr};
colorRenderTargets[0] = mtlTexture;
GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, nullptr, true);
renderPassDescriptor->release();
} }
void MetalRenderer::texture_clearDepthSlice(LatteTexture* hostTexture, uint32 sliceIndex, sint32 mipIndex, bool clearDepth, bool clearStencil, float depthValue, uint32 stencilValue) void MetalRenderer::texture_clearDepthSlice(LatteTexture* hostTexture, uint32 sliceIndex, sint32 mipIndex, bool clearDepth, bool clearStencil, float depthValue, uint32 stencilValue)
@ -1162,3 +1153,20 @@ void MetalRenderer::RebindRenderState(MTL::RenderCommandEncoder* renderCommandEn
} }
} }
} }
void MetalRenderer::ClearColorTextureInternal(MTL::Texture* mtlTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a)
{
MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init();
auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0);
colorAttachment->setTexture(mtlTexture);
colorAttachment->setClearColor(MTL::ClearColor(r, g, b, a));
colorAttachment->setLoadAction(MTL::LoadActionClear);
colorAttachment->setStoreAction(MTL::StoreActionStore);
colorAttachment->setSlice(sliceIndex);
colorAttachment->setLevel(mipIndex);
MTL::Texture* colorRenderTargets[8] = {nullptr};
colorRenderTargets[0] = mtlTexture;
GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, nullptr, true);
renderPassDescriptor->release();
}

View File

@ -229,4 +229,6 @@ private:
void BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader); void BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader);
void RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder); void RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder);
void ClearColorTextureInternal(MTL::Texture* mtlTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a);
}; };