Skip to content

Commit

Permalink
glR_Backend_Runtime: Move framebuffer and program pipeline to HW.
Browse files Browse the repository at this point in the history
Also provide more modern clear functions.
  • Loading branch information
CrossVR committed Nov 23, 2015
1 parent b1c35af commit 13d875c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 38 deletions.
9 changes: 9 additions & 0 deletions src/Layers/xrRender/HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class CHW
#if defined(USE_OGL)
public:
CHW* pDevice;
GLuint pBaseRT;
GLuint pBaseZB;
GLuint pFB;
GLuint pPP;

CHWCaps Caps;

Expand Down Expand Up @@ -128,6 +131,12 @@ class CHW
virtual void OnAppActivate();
virtual void OnAppDeactivate();
#endif
#ifdef USE_OGL
// TODO: OGL: Implement this into a compatibility layer?
void ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[4]);
void ClearDepthStencilView(GLuint pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil);
#endif // USE_OGL


private:
bool m_move_window;
Expand Down
7 changes: 0 additions & 7 deletions src/Layers/xrRender/R_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ void CBackend::OnDeviceCreate ()
#if defined(USE_DX10) || defined(USE_DX11)
//CreateConstantBuffers();
#endif // USE_DX10
#ifdef USE_OGL
// Create the program pipeline used for rendering with shaders
glGenProgramPipelines(1, &pp);
#endif // USE_OGL

CreateQuadIB ();

Expand Down Expand Up @@ -193,9 +189,6 @@ void CBackend::OnDeviceDestroy()
#if defined(USE_DX10) || defined(USE_DX11)
//DestroyConstantBuffers();
#endif // USE_DX10
#ifdef USE_OGL
glDeleteProgramPipelines(1, &pp);
#endif // USE_OGL
}

#if defined(USE_DX10) || defined(USE_DX11)
Expand Down
4 changes: 0 additions & 4 deletions src/Layers/xrRender/R_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class ECORE_API CBackend
private:
// Render-targets
#ifdef USE_OGL
GLuint pFB;
GLuint pRT[4];
GLuint pZB;
#else
Expand Down Expand Up @@ -123,7 +122,6 @@ class ECORE_API CBackend
// Shaders/State
#ifdef USE_OGL
SState* state;
GLuint pp;
GLuint ps;
GLuint vs;
#else
Expand Down Expand Up @@ -253,10 +251,8 @@ class ECORE_API CBackend
IC const Fmatrix& get_xform_project ();

#ifdef USE_OGL
IC void set_FB (GLuint FB=0);
IC void set_RT (GLuint RT, u32 ID=0);
IC void set_ZB (GLuint ZB);
IC GLuint get_FB ();
IC GLuint get_RT (u32 ID=0);
IC GLuint get_ZB ();
#else
Expand Down
11 changes: 9 additions & 2 deletions src/Layers/xrRender/xrD3DDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
#pragma once

#if defined(USE_OGL)
using namespace gl;
class glState;

// TODO: Get rid of D3D types.
#include <d3d9types.h>

using namespace gl;
class glState;

typedef enum D3D_CLEAR_FLAG {
D3D_CLEAR_DEPTH = 0x1L,
D3D_CLEAR_STENCIL = 0x2L
} D3D_CLEAR_FLAG;

#define DX10_ONLY(expr) do {} while (0)

#elif defined(USE_DX11) || defined(USE_DX10)
Expand Down
64 changes: 61 additions & 3 deletions src/Layers/xrRenderGL/glHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ CHW::CHW() :
m_hRC(NULL),
pDevice(this),
m_move_window(true),
pBaseZB(0)
pBaseRT(0),
pBaseZB(0),
pPP(0),
pFB(0)
{
}

Expand Down Expand Up @@ -129,6 +132,9 @@ void CHW::CreateDevice( HWND hWnd, bool move_window )
// TODO: Fix these differences in the blenders/shaders.
CHK_GL(glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE));

// Create render target and depth-stencil views here
UpdateViews();

#ifndef _EDITOR
updateWindowProps (m_hWnd);
fill_vid_mode_list (this);
Expand Down Expand Up @@ -168,7 +174,11 @@ void CHW::Reset (HWND hwnd)
{
BOOL bWindowed = !psDeviceFlags.is (rsFullscreen);

CHK_GL(glDeleteTextures(1, &HW.pBaseZB));
CHK_GL(glDeleteProgramPipelines(1, &pPP));
CHK_GL(glDeleteFramebuffers(1, &pFB));

CHK_GL(glDeleteTextures(1, &pBaseRT));
CHK_GL(glDeleteTextures(1, &pBaseZB));

UpdateViews();

Expand Down Expand Up @@ -322,9 +332,57 @@ void fill_vid_mode_list()

void CHW::UpdateViews()
{
// Create an staging depth buffer used for post-processing
// Create the program pipeline used for rendering with shaders
glGenProgramPipelines(1, &pPP);
CHK_GL(glBindProgramPipeline(pPP));

// Create the framebuffer
glGenFramebuffers(1, &pFB);
CHK_GL(glBindFramebuffer(GL_FRAMEBUFFER, pFB));

// Create a render target view
// We reserve a texture name to represent GL_BACK
glGenTextures(1, &HW.pBaseRT);

// Create Depth/stencil buffer
glGenTextures(1, &HW.pBaseZB);
CHK_GL(glBindTexture(GL_TEXTURE_2D, HW.pBaseZB));
CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH24_STENCIL8, Device.dwWidth, Device.dwHeight));
}


void CHW::ClearRenderTargetView(GLuint pRenderTargetView, const FLOAT ColorRGBA[4])
{
// TODO: OGL: Bind the RT to a clear frame buffer.
glPushAttrib(GL_COLOR_BUFFER_BIT);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClearColor(ColorRGBA[0], ColorRGBA[1], ColorRGBA[2], ColorRGBA[3]);
CHK_GL(glClear(GL_COLOR_BUFFER_BIT));
glPopAttrib();
}

void CHW::ClearDepthStencilView(GLuint pDepthStencilView, UINT ClearFlags, FLOAT Depth, UINT8 Stencil)
{
// TODO: OGL: Bind the DS to a clear frame buffer.
u32 mask = 0;
if (ClearFlags & D3D_CLEAR_DEPTH)
mask |= (u32)GL_DEPTH_BUFFER_BIT;
if (ClearFlags & D3D_CLEAR_STENCIL)
mask |= (u32)GL_STENCIL_BUFFER_BIT;


glPushAttrib((AttribMask)mask);
if (ClearFlags & D3DCLEAR_ZBUFFER)
{
glDepthMask(GL_TRUE);
glClearDepthf(Depth);
}
if (ClearFlags & D3DCLEAR_STENCIL)
{
glStencilMask(~0);
glClearStencil(Stencil);
}
CHK_GL(glClear((ClearBufferMask)mask));
glPopAttrib();
}
#endif
24 changes: 2 additions & 22 deletions src/Layers/xrRenderGL/glR_Backend_Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,13 @@

#include "glStateUtils.h"

IC GLuint CBackend::get_FB()
{
return pFB;
}

IC void CBackend::set_xform(u32 ID, const Fmatrix& M)
{
stat.xforms++;
// TODO: OGL: Implement CBackend::set_xform
//VERIFY(!"Implement CBackend::set_xform");
}

IC void CBackend::set_FB(GLuint FB)
{
if (FB != pFB)
{
PGO(Msg("PGO:set_FB"));
pFB = FB;
CHK_GL(glBindFramebuffer(GL_FRAMEBUFFER, pFB));

// Clear cached attachments
pRT[0] = pRT[1] = pRT[2] = pRT[3] = pZB = NULL;
}
}

IC void CBackend::set_RT(GLuint RT, u32 ID)
{
if (RT != pRT[ID])
Expand Down Expand Up @@ -76,7 +58,7 @@ ICF void CBackend::set_PS(GLuint _ps, LPCSTR _n)
PGO(Msg("PGO:Pshader:%d,%s", _ps, _n ? _n : name));
stat.ps++;
ps = _ps;
CHK_GL(glUseProgramStages(pp, GL_FRAGMENT_SHADER_BIT, ps));
CHK_GL(glUseProgramStages(HW.pPP, GL_FRAGMENT_SHADER_BIT, ps));
#ifdef DEBUG
ps_name = _n;
#endif
Expand All @@ -92,7 +74,7 @@ ICF void CBackend::set_VS(GLuint _vs, LPCSTR _n)
PGO(Msg("PGO:Vshader:%d,%s", _vs, _n ? _n : name));
stat.vs++;
vs = _vs;
CHK_GL(glUseProgramStages(pp, GL_VERTEX_SHADER_BIT, vs));
CHK_GL(glUseProgramStages(HW.pPP, GL_VERTEX_SHADER_BIT, vs));
#ifdef DEBUG
vs_name = _n;
#endif
Expand Down Expand Up @@ -179,7 +161,6 @@ ICF void CBackend::Render(D3DPRIMITIVETYPE T, u32 baseV, u32 startV, u32 countV,
stat.verts += countV;
stat.polys += PC;
constants.flush();
CHK_GL(glBindProgramPipeline(pp));
CHK_GL(glDrawElementsBaseVertex(Topology, iIndexCount, GL_UNSIGNED_SHORT, (void*)(startI * sizeof(GLushort)), baseV));
PGO(Msg("PGO:DIP:%dv/%df", countV, PC));
}
Expand All @@ -193,7 +174,6 @@ ICF void CBackend::Render(D3DPRIMITIVETYPE T, u32 startV, u32 PC)
stat.verts += iIndexCount;
stat.polys += PC;
constants.flush();
CHK_GL(glBindProgramPipeline(pp));
CHK_GL(glDrawArrays(Topology, startV, iIndexCount));
PGO(Msg("PGO:DIP:%dv/%df", iIndexCount, PC));
}
Expand Down

0 comments on commit 13d875c

Please sign in to comment.