Skip to content

Commit 2ed4336

Browse files
committed
CHW: Bind the render target when clearing color/depth.
1 parent 4a9de05 commit 2ed4336

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/Layers/xrRender/HW.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class CHW
6161
CHW* pContext;
6262
GLuint pBaseRT;
6363
GLuint pBaseZB;
64-
GLuint pFB;
6564
GLuint pPP;
65+
GLuint pFB;
66+
GLuint pCFB;
6667

6768
CHWCaps Caps;
6869

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ void CHW::Reset (HWND hwnd)
177177

178178
CHK_GL(glDeleteProgramPipelines(1, &pPP));
179179
CHK_GL(glDeleteFramebuffers(1, &pFB));
180+
CHK_GL(glDeleteFramebuffers(1, &pCFB));
180181

181182
CHK_GL(glDeleteTextures(1, &pBaseRT));
182183
CHK_GL(glDeleteTextures(1, &pBaseZB));
@@ -337,10 +338,13 @@ void CHW::UpdateViews()
337338
glGenProgramPipelines(1, &pPP);
338339
CHK_GL(glBindProgramPipeline(pPP));
339340

340-
// Create the framebuffer
341+
// Create the default framebuffer
341342
glGenFramebuffers(1, &pFB);
342343
CHK_GL(glBindFramebuffer(GL_FRAMEBUFFER, pFB));
343344

345+
// Create the clear framebuffer
346+
glGenFramebuffers(1, &pCFB);
347+
344348
// Create a render target view
345349
// We reserve a texture name to represent GL_BACK
346350
glGenTextures(1, &HW.pBaseRT);
@@ -354,7 +358,14 @@ void CHW::UpdateViews()
354358

355359
void CHW::ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[4])
356360
{
357-
// TODO: OGL: Bind the RT to a clear frame buffer.
361+
if (pRenderTargetView == 0)
362+
return;
363+
364+
// Bind the clear framebuffer and attach the render target
365+
RCache.set_FB(pCFB);
366+
CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pRenderTargetView, 0));
367+
368+
// Clear the color buffer without affecting the global state
358369
glPushAttrib(GL_COLOR_BUFFER_BIT);
359370
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
360371
glClearColor(ColorRGBA[0], ColorRGBA[1], ColorRGBA[2], ColorRGBA[3]);
@@ -364,7 +375,13 @@ void CHW::ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[
364375

365376
void CHW::ClearDepthStencilView(GLuint pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil)
366377
{
367-
// TODO: OGL: Bind the DS to a clear frame buffer.
378+
if (pDepthStencilView == 0)
379+
return;
380+
381+
// Bind the clear framebuffer and attach the render target
382+
RCache.set_FB(pCFB);
383+
CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, pDepthStencilView, 0));
384+
368385
u32 mask = 0;
369386
if (ClearFlags & D3D_CLEAR_DEPTH)
370387
mask |= (u32)GL_DEPTH_BUFFER_BIT;

0 commit comments

Comments
 (0)