Skip to content

Commit e19d65f

Browse files
committed
CRenderTarget: Implement OpenGL support, including MSAA.
Still needs support for MSAA render targets though.
1 parent 9d9d8c1 commit e19d65f

25 files changed

+510
-873
lines changed

src/Layers/xrRender/SH_RT.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class CRT : public xr_resource_named {
2020
public:
2121
#ifdef USE_OGL
2222
GLuint pRT;
23+
GLuint pZRT;
24+
GLenum target;
2325
#else
2426
ID3DTexture2D* pSurface;
2527
ID3DRenderTargetView* pRT;

src/Layers/xrRender/light.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class light : public IRender_Light, public SpatialBase
5151
ref_shader s_point;
5252
ref_shader s_volumetric;
5353

54-
#if (RENDER==R_R3) || (RENDER==R_R4)
54+
#if (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
5555
ref_shader s_spot_msaa[8];
5656
ref_shader s_point_msaa[8];
5757
ref_shader s_volumetric_msaa[8];
58-
#endif // (RENDER==R_R3) || (RENDER==R_R4)
58+
#endif // (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
5959

6060
u32 m_xform_frame;
6161
Fmatrix m_xform;

src/Layers/xrRender/r__dsgraph_render.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void D3DXRenderBase::r_dsgraph_render_hud_ui()
542542
const ref_rt rt_null;
543543
RCache.set_RT(0, 1);
544544
RCache.set_RT(0, 2);
545-
#if (RENDER==R_R3) || (RENDER==R_R4)
545+
#if (RENDER==R_R3) || (RENDER==R_R4) || (RENDER==R_GL)
546546
if( !RImplementation.o.dx10_msaa )
547547
{
548548
if (RImplementation.o.albedo_wo) RImplementation.Target->u_setrt (RImplementation.Target->rt_Accumulator, rt_null, rt_null, HW.pBaseZB);

src/Layers/xrRenderGL/glR_Backend_Runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ IC void CBackend::set_RT(GLuint RT, u32 ID)
1818
PGO(Msg("PGO:setRT"));
1919
stat.target_rt++;
2020
pRT[ID] = RT;
21+
// TODO: OGL: Implement support for multi-sampled render targets
2122
CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + ID, GL_TEXTURE_2D, RT, 0));
2223
}
2324
}
@@ -29,6 +30,7 @@ IC void CBackend::set_ZB(GLuint ZB)
2930
PGO(Msg("PGO:setZB"));
3031
stat.target_zb++;
3132
pZB = ZB;
33+
// TODO: OGL: Implement support for multi-sampled render targets
3234
CHK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, ZB, 0));
3335
}
3436
}

src/Layers/xrRenderGL/glSH_RT.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,25 @@ void CRT::create (LPCSTR Name, u32 w, u32 h, D3DFORMAT f, u32 SampleCount )
4343

4444
RImplementation.Resources->Evict();
4545

46+
target = (SampleCount > 1) ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D;
4647
glGenTextures(1, &pRT);
47-
CHK_GL(glBindTexture(GL_TEXTURE_2D, pRT));
48-
CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, glTextureUtils::ConvertTextureFormat(fmt), w, h));
48+
CHK_GL(glBindTexture(target, pRT));
49+
if (SampleCount > 1)
50+
CHK_GL(glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, SampleCount, glTextureUtils::ConvertTextureFormat(fmt), w, h, GL_FALSE));
51+
else
52+
CHK_GL(glTexStorage2D(GL_TEXTURE_2D, 1, glTextureUtils::ConvertTextureFormat(fmt), w, h));
4953

5054
pTexture = RImplementation.Resources->_CreateTexture (Name);
51-
pTexture->surface_set(GL_TEXTURE_2D, pRT);
55+
pTexture->surface_set(target, pRT);
56+
57+
// OpenGL doesn't differentiate between color and depth targets
58+
pZRT = pRT;
5259
}
5360

5461
void CRT::destroy ()
5562
{
5663
if (pTexture._get()) {
57-
pTexture->surface_set(GL_TEXTURE_2D, 0);
64+
pTexture->surface_set(target, 0);
5865
pTexture = NULL;
5966
}
6067
CHK_GL(glDeleteTextures(1, &pRT));

0 commit comments

Comments
 (0)