@@ -38,7 +38,10 @@ CHW::CHW() :
3838 m_hRC(NULL ),
3939 pDevice(this ),
4040 m_move_window(true ),
41- pBaseZB(0 )
41+ pBaseRT(0 ),
42+ pBaseZB(0 ),
43+ pPP(0 ),
44+ pFB(0 )
4245{
4346}
4447
@@ -129,6 +132,9 @@ void CHW::CreateDevice( HWND hWnd, bool move_window )
129132 // TODO: Fix these differences in the blenders/shaders.
130133 CHK_GL (glClipControl (GL_UPPER_LEFT, GL_ZERO_TO_ONE));
131134
135+ // Create render target and depth-stencil views here
136+ UpdateViews ();
137+
132138#ifndef _EDITOR
133139 updateWindowProps (m_hWnd);
134140 fill_vid_mode_list (this );
@@ -168,7 +174,11 @@ void CHW::Reset (HWND hwnd)
168174{
169175 BOOL bWindowed = !psDeviceFlags.is (rsFullscreen);
170176
171- CHK_GL (glDeleteTextures (1 , &HW.pBaseZB ));
177+ CHK_GL (glDeleteProgramPipelines (1 , &pPP));
178+ CHK_GL (glDeleteFramebuffers (1 , &pFB));
179+
180+ CHK_GL (glDeleteTextures (1 , &pBaseRT));
181+ CHK_GL (glDeleteTextures (1 , &pBaseZB));
172182
173183 UpdateViews ();
174184
@@ -322,9 +332,57 @@ void fill_vid_mode_list()
322332
323333void CHW::UpdateViews ()
324334{
325- // Create an staging depth buffer used for post-processing
335+ // Create the program pipeline used for rendering with shaders
336+ glGenProgramPipelines (1 , &pPP);
337+ CHK_GL (glBindProgramPipeline (pPP));
338+
339+ // Create the framebuffer
340+ glGenFramebuffers (1 , &pFB);
341+ CHK_GL (glBindFramebuffer (GL_FRAMEBUFFER, pFB));
342+
343+ // Create a render target view
344+ // We reserve a texture name to represent GL_BACK
345+ glGenTextures (1 , &HW.pBaseRT );
346+
347+ // Create Depth/stencil buffer
326348 glGenTextures (1 , &HW.pBaseZB );
327349 CHK_GL (glBindTexture (GL_TEXTURE_2D, HW.pBaseZB ));
328350 CHK_GL (glTexStorage2D (GL_TEXTURE_2D, 1 , GL_DEPTH24_STENCIL8, Device.dwWidth , Device.dwHeight ));
329351}
352+
353+
354+ void CHW::ClearRenderTargetView (GLuint pRenderTargetView, const FLOAT ColorRGBA[4 ])
355+ {
356+ // TODO: OGL: Bind the RT to a clear frame buffer.
357+ glPushAttrib (GL_COLOR_BUFFER_BIT);
358+ glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
359+ glClearColor (ColorRGBA[0 ], ColorRGBA[1 ], ColorRGBA[2 ], ColorRGBA[3 ]);
360+ CHK_GL (glClear (GL_COLOR_BUFFER_BIT));
361+ glPopAttrib ();
362+ }
363+
364+ void CHW::ClearDepthStencilView (GLuint pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil)
365+ {
366+ // TODO: OGL: Bind the DS to a clear frame buffer.
367+ u32 mask = 0 ;
368+ if (ClearFlags & D3D_CLEAR_DEPTH)
369+ mask |= (u32 )GL_DEPTH_BUFFER_BIT;
370+ if (ClearFlags & D3D_CLEAR_STENCIL)
371+ mask |= (u32 )GL_STENCIL_BUFFER_BIT;
372+
373+
374+ glPushAttrib ((AttribMask)mask);
375+ if (ClearFlags & D3DCLEAR_ZBUFFER)
376+ {
377+ glDepthMask (GL_TRUE);
378+ glClearDepthf (Depth);
379+ }
380+ if (ClearFlags & D3DCLEAR_STENCIL)
381+ {
382+ glStencilMask (~0 );
383+ glClearStencil (Stencil);
384+ }
385+ CHK_GL (glClear ((ClearBufferMask)mask));
386+ glPopAttrib ();
387+ }
330388#endif
0 commit comments