Skip to content

Commit 13d875c

Browse files
committed
glR_Backend_Runtime: Move framebuffer and program pipeline to HW.
Also provide more modern clear functions.
1 parent b1c35af commit 13d875c

File tree

6 files changed

+81
-38
lines changed

6 files changed

+81
-38
lines changed

src/Layers/xrRender/HW.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class CHW
5858
#if defined(USE_OGL)
5959
public:
6060
CHW* pDevice;
61+
GLuint pBaseRT;
6162
GLuint pBaseZB;
63+
GLuint pFB;
64+
GLuint pPP;
6265

6366
CHWCaps Caps;
6467

@@ -128,6 +131,12 @@ class CHW
128131
virtual void OnAppActivate();
129132
virtual void OnAppDeactivate();
130133
#endif
134+
#ifdef USE_OGL
135+
// TODO: OGL: Implement this into a compatibility layer?
136+
void ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[4]);
137+
void ClearDepthStencilView(GLuint pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil);
138+
#endif // USE_OGL
139+
131140

132141
private:
133142
bool m_move_window;

src/Layers/xrRender/R_Backend.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ void CBackend::OnDeviceCreate ()
161161
#if defined(USE_DX10) || defined(USE_DX11)
162162
//CreateConstantBuffers();
163163
#endif // USE_DX10
164-
#ifdef USE_OGL
165-
// Create the program pipeline used for rendering with shaders
166-
glGenProgramPipelines(1, &pp);
167-
#endif // USE_OGL
168164

169165
CreateQuadIB ();
170166

@@ -193,9 +189,6 @@ void CBackend::OnDeviceDestroy()
193189
#if defined(USE_DX10) || defined(USE_DX11)
194190
//DestroyConstantBuffers();
195191
#endif // USE_DX10
196-
#ifdef USE_OGL
197-
glDeleteProgramPipelines(1, &pp);
198-
#endif // USE_OGL
199192
}
200193

201194
#if defined(USE_DX10) || defined(USE_DX11)

src/Layers/xrRender/R_Backend.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class ECORE_API CBackend
9393
private:
9494
// Render-targets
9595
#ifdef USE_OGL
96-
GLuint pFB;
9796
GLuint pRT[4];
9897
GLuint pZB;
9998
#else
@@ -123,7 +122,6 @@ class ECORE_API CBackend
123122
// Shaders/State
124123
#ifdef USE_OGL
125124
SState* state;
126-
GLuint pp;
127125
GLuint ps;
128126
GLuint vs;
129127
#else
@@ -253,10 +251,8 @@ class ECORE_API CBackend
253251
IC const Fmatrix& get_xform_project ();
254252

255253
#ifdef USE_OGL
256-
IC void set_FB (GLuint FB=0);
257254
IC void set_RT (GLuint RT, u32 ID=0);
258255
IC void set_ZB (GLuint ZB);
259-
IC GLuint get_FB ();
260256
IC GLuint get_RT (u32 ID=0);
261257
IC GLuint get_ZB ();
262258
#else

src/Layers/xrRender/xrD3DDefs.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
#pragma once
44

55
#if defined(USE_OGL)
6-
using namespace gl;
7-
class glState;
6+
87
// TODO: Get rid of D3D types.
98
#include <d3d9types.h>
109

10+
using namespace gl;
11+
class glState;
12+
13+
typedef enum D3D_CLEAR_FLAG {
14+
D3D_CLEAR_DEPTH = 0x1L,
15+
D3D_CLEAR_STENCIL = 0x2L
16+
} D3D_CLEAR_FLAG;
17+
1118
#define DX10_ONLY(expr) do {} while (0)
1219

1320
#elif defined(USE_DX11) || defined(USE_DX10)

src/Layers/xrRenderGL/glHW.cpp

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

323333
void 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

src/Layers/xrRenderGL/glR_Backend_Runtime.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,13 @@
44

55
#include "glStateUtils.h"
66

7-
IC GLuint CBackend::get_FB()
8-
{
9-
return pFB;
10-
}
11-
127
IC void CBackend::set_xform(u32 ID, const Fmatrix& M)
138
{
149
stat.xforms++;
1510
// TODO: OGL: Implement CBackend::set_xform
1611
//VERIFY(!"Implement CBackend::set_xform");
1712
}
1813

19-
IC void CBackend::set_FB(GLuint FB)
20-
{
21-
if (FB != pFB)
22-
{
23-
PGO(Msg("PGO:set_FB"));
24-
pFB = FB;
25-
CHK_GL(glBindFramebuffer(GL_FRAMEBUFFER, pFB));
26-
27-
// Clear cached attachments
28-
pRT[0] = pRT[1] = pRT[2] = pRT[3] = pZB = NULL;
29-
}
30-
}
31-
3214
IC void CBackend::set_RT(GLuint RT, u32 ID)
3315
{
3416
if (RT != pRT[ID])
@@ -76,7 +58,7 @@ ICF void CBackend::set_PS(GLuint _ps, LPCSTR _n)
7658
PGO(Msg("PGO:Pshader:%d,%s", _ps, _n ? _n : name));
7759
stat.ps++;
7860
ps = _ps;
79-
CHK_GL(glUseProgramStages(pp, GL_FRAGMENT_SHADER_BIT, ps));
61+
CHK_GL(glUseProgramStages(HW.pPP, GL_FRAGMENT_SHADER_BIT, ps));
8062
#ifdef DEBUG
8163
ps_name = _n;
8264
#endif
@@ -92,7 +74,7 @@ ICF void CBackend::set_VS(GLuint _vs, LPCSTR _n)
9274
PGO(Msg("PGO:Vshader:%d,%s", _vs, _n ? _n : name));
9375
stat.vs++;
9476
vs = _vs;
95-
CHK_GL(glUseProgramStages(pp, GL_VERTEX_SHADER_BIT, vs));
77+
CHK_GL(glUseProgramStages(HW.pPP, GL_VERTEX_SHADER_BIT, vs));
9678
#ifdef DEBUG
9779
vs_name = _n;
9880
#endif
@@ -179,7 +161,6 @@ ICF void CBackend::Render(D3DPRIMITIVETYPE T, u32 baseV, u32 startV, u32 countV,
179161
stat.verts += countV;
180162
stat.polys += PC;
181163
constants.flush();
182-
CHK_GL(glBindProgramPipeline(pp));
183164
CHK_GL(glDrawElementsBaseVertex(Topology, iIndexCount, GL_UNSIGNED_SHORT, (void*)(startI * sizeof(GLushort)), baseV));
184165
PGO(Msg("PGO:DIP:%dv/%df", countV, PC));
185166
}
@@ -193,7 +174,6 @@ ICF void CBackend::Render(D3DPRIMITIVETYPE T, u32 startV, u32 PC)
193174
stat.verts += iIndexCount;
194175
stat.polys += PC;
195176
constants.flush();
196-
CHK_GL(glBindProgramPipeline(pp));
197177
CHK_GL(glDrawArrays(Topology, startV, iIndexCount));
198178
PGO(Msg("PGO:DIP:%dv/%df", iIndexCount, PC));
199179
}

0 commit comments

Comments
 (0)