Skip to content

Commit 5030a2e

Browse files
committed
implement color buffer clear
1 parent 763d57d commit 5030a2e

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ bool MetalRenderer::GetVRAMInfo(int& usageInMB, int& totalInMB) const
126126

127127
void MetalRenderer::ClearColorbuffer(bool padView)
128128
{
129-
debug_printf("MetalRenderer::ClearColorbuffer not implemented\n");
129+
if (!AcquireNextDrawable())
130+
return;
131+
132+
ClearColorTextureInternal(m_drawable->texture(), 0, 0, 0.0f, 0.0f, 0.0f, 0.0f);
130133
}
131134

132135
void MetalRenderer::DrawEmptyFrame(bool mainWindow)
@@ -283,19 +286,7 @@ void MetalRenderer::texture_clearColorSlice(LatteTexture* hostTexture, sint32 sl
283286
{
284287
auto mtlTexture = static_cast<LatteTextureMtl*>(hostTexture)->GetTexture();
285288

286-
MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init();
287-
auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0);
288-
colorAttachment->setTexture(mtlTexture);
289-
colorAttachment->setClearColor(MTL::ClearColor(r, g, b, a));
290-
colorAttachment->setLoadAction(MTL::LoadActionClear);
291-
colorAttachment->setStoreAction(MTL::StoreActionStore);
292-
colorAttachment->setSlice(sliceIndex);
293-
colorAttachment->setLevel(mipIndex);
294-
295-
MTL::Texture* colorRenderTargets[8] = {nullptr};
296-
colorRenderTargets[0] = mtlTexture;
297-
GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, nullptr, true);
298-
renderPassDescriptor->release();
289+
ClearColorTextureInternal(mtlTexture, sliceIndex, mipIndex, r, g, b, a);
299290
}
300291

301292
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
11621153
}
11631154
}
11641155
}
1156+
1157+
void MetalRenderer::ClearColorTextureInternal(MTL::Texture* mtlTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a)
1158+
{
1159+
MTL::RenderPassDescriptor* renderPassDescriptor = MTL::RenderPassDescriptor::alloc()->init();
1160+
auto colorAttachment = renderPassDescriptor->colorAttachments()->object(0);
1161+
colorAttachment->setTexture(mtlTexture);
1162+
colorAttachment->setClearColor(MTL::ClearColor(r, g, b, a));
1163+
colorAttachment->setLoadAction(MTL::LoadActionClear);
1164+
colorAttachment->setStoreAction(MTL::StoreActionStore);
1165+
colorAttachment->setSlice(sliceIndex);
1166+
colorAttachment->setLevel(mipIndex);
1167+
1168+
MTL::Texture* colorRenderTargets[8] = {nullptr};
1169+
colorRenderTargets[0] = mtlTexture;
1170+
GetRenderCommandEncoder(renderPassDescriptor, colorRenderTargets, nullptr, true);
1171+
renderPassDescriptor->release();
1172+
}

src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,6 @@ class MetalRenderer : public Renderer
229229

230230
void BindStageResources(MTL::RenderCommandEncoder* renderCommandEncoder, LatteDecompilerShader* shader);
231231
void RebindRenderState(MTL::RenderCommandEncoder* renderCommandEncoder);
232+
233+
void ClearColorTextureInternal(MTL::Texture* mtlTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a);
232234
};

0 commit comments

Comments
 (0)