Skip to content

Commit 635f365

Browse files
committed
xrRenderPC_GL: Switch to the GL-specific blender code path.
This merges the texture and sampler uniforms while keeping the DX10-level features.
1 parent 0cbdf6d commit 635f365

31 files changed

+872
-917
lines changed

src/Layers/xrRender/Blender_BmmD.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,60 @@ void CBlender_BmmD::Compile (CBlender_Compile& C)
172172
break;
173173
}
174174
}
175+
#elif RENDER==R_GL
176+
//////////////////////////////////////////////////////////////////////////
177+
// GL
178+
//////////////////////////////////////////////////////////////////////////
179+
#include "uber_deffer.h"
180+
void CBlender_BmmD::Compile (CBlender_Compile& C)
181+
{
182+
IBlender::Compile (C);
183+
// codepath is the same, only the shaders differ
184+
// ***only pixel shaders differ***
185+
string256 mask;
186+
strconcat (sizeof(mask),mask,C.L_textures[0].c_str(),"_mask");
187+
switch(C.iElement)
188+
{
189+
case SE_R2_NORMAL_HQ: // deffer
190+
uber_deffer (C, true, "impl","impl",false,oT2_Name[0]?oT2_Name:0,true);
191+
C.r_Sampler ("s_mask", mask);
192+
C.r_Sampler ("s_lmap", C.L_textures[1]);
193+
194+
C.r_Sampler ("s_dt_r", oR_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
195+
C.r_Sampler ("s_dt_g", oG_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
196+
C.r_Sampler ("s_dt_b", oB_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
197+
C.r_Sampler ("s_dt_a", oA_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
198+
199+
C.r_Sampler ("s_dn_r", strconcat(sizeof(mask),mask,oR_Name,"_bump") );
200+
C.r_Sampler ("s_dn_g", strconcat(sizeof(mask),mask,oG_Name,"_bump") );
201+
C.r_Sampler ("s_dn_b", strconcat(sizeof(mask),mask,oB_Name,"_bump") );
202+
C.r_Sampler ("s_dn_a", strconcat(sizeof(mask),mask,oA_Name,"_bump") );
203+
204+
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
205+
C.r_StencilRef (0x01);
206+
207+
C.r_End ();
208+
break;
209+
case SE_R2_NORMAL_LQ: // deffer
210+
uber_deffer (C, false, "base","impl",false,oT2_Name[0]?oT2_Name:0,true);
211+
212+
C.r_Sampler ("s_lmap", C.L_textures[1]);
213+
214+
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
215+
C.r_StencilRef (0x01);
216+
217+
C.r_End ();
218+
break;
219+
case SE_R2_SHADOW: // smap
220+
//if (RImplementation.o.HW_smap) C.r_Pass ("shadow_direct_base","dumb", FALSE,TRUE,TRUE,FALSE);
221+
//else C.r_Pass ("shadow_direct_base","shadow_direct_base",FALSE);
222+
C.r_Pass ("shadow_direct_base","dumb", FALSE,TRUE,TRUE,FALSE);
223+
C.r_Sampler ("s_base",C.L_textures[0]);
224+
C.r_ColorWriteEnable(false, false, false, false);
225+
C.r_End ();
226+
break;
227+
}
228+
}
175229
#else
176230
//////////////////////////////////////////////////////////////////////////
177231
// R3

src/Layers/xrRender/Blender_Lm(EbB).cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void CBlender_LmEbB::Compile(CBlender_Compile& C)
138138
}
139139
}
140140
}
141-
#elif RENDER==R_R2
141+
#elif RENDER==R_R2 || RENDER==R_GL
142142
//////////////////////////////////////////////////////////////////////////
143143
// R2
144144
//////////////////////////////////////////////////////////////////////////

src/Layers/xrRender/Blender_Model_EbB.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,57 @@ void CBlender_Model_EbB::Compile(CBlender_Compile& C)
171171
}
172172
}
173173
}
174+
#elif RENDER==R_GL
175+
#include "uber_deffer.h"
176+
void CBlender_Model_EbB::Compile(CBlender_Compile& C)
177+
{
178+
IBlender::Compile(C);
179+
180+
if (oBlend.value)
181+
{
182+
// forward
183+
LPCSTR vsname = 0;
184+
LPCSTR psname = 0;
185+
switch (C.iElement)
186+
{
187+
case 0:
188+
case 1:
189+
vsname = psname = "model_env_lq";
190+
C.r_Pass(vsname, psname, TRUE, TRUE, FALSE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, 0);
191+
C.r_Sampler ("s_base", C.L_textures[0]);
192+
C.r_Sampler ("s_env", oT2_Name,false,D3DTADDRESS_CLAMP);
193+
C.r_End();
194+
break;
195+
}
196+
}
197+
else
198+
{
199+
// deferred
200+
switch (C.iElement)
201+
{
202+
case SE_R2_NORMAL_HQ: // deffer
203+
uber_deffer(C, true, "model", "base", false, 0, true);
204+
C.r_Stencil(TRUE, D3DCMP_ALWAYS, 0xff, 0x7f, D3DSTENCILOP_KEEP, D3DSTENCILOP_REPLACE, D3DSTENCILOP_KEEP);
205+
C.r_StencilRef(0x01);
206+
C.r_End();
207+
break;
208+
case SE_R2_NORMAL_LQ: // deffer
209+
uber_deffer(C, false, "model", "base", false, 0, true);
210+
C.r_Stencil(TRUE, D3DCMP_ALWAYS, 0xff, 0x7f, D3DSTENCILOP_KEEP, D3DSTENCILOP_REPLACE, D3DSTENCILOP_KEEP);
211+
C.r_StencilRef(0x01);
212+
C.r_End();
213+
break;
214+
case SE_R2_SHADOW: // smap
215+
//if (RImplementation.o.HW_smap) C.r_Pass ("shadow_direct_model","dumb", FALSE,TRUE,TRUE,FALSE);
216+
//else C.r_Pass ("shadow_direct_model","shadow_direct_base",FALSE);
217+
C.r_Pass("shadow_direct_model", "dumb", FALSE, TRUE, TRUE, FALSE);
218+
C.r_Sampler ("s_base",C.L_textures[0]);
219+
C.r_ColorWriteEnable(false, false, false, false);
220+
C.r_End();
221+
break;
222+
}
223+
}
224+
}
174225
#else
175226
#include "uber_deffer.h"
176227
void CBlender_Model_EbB::Compile( CBlender_Compile& C )

src/Layers/xrRender/Blender_Particle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void CBlender_Particle::Compile (CBlender_Compile& C)
7070
C.r_Sampler ("s_base", C.L_textures[0],false,oClamp.value?D3DTADDRESS_CLAMP:D3DTADDRESS_WRAP);
7171
C.r_End ();
7272
}
73-
#elif RENDER==R_R2
73+
#elif RENDER==R_R2 || RENDER==R_GL
7474
void CBlender_Particle::Compile (CBlender_Compile& C)
7575
{
7676
IBlender::Compile (C);

src/Layers/xrRender/Blender_Screen_SET.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void CBlender_Screen_SET::Load ( IReader& fs, u16 version)
9393
}
9494
}
9595

96-
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
96+
#if defined(USE_DX10) || defined(USE_DX11)
9797

9898
void CBlender_Screen_SET::Compile (CBlender_Compile& C)
9999
{

src/Layers/xrRender/Blender_tree.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,87 @@ void CBlender_Tree::Compile (CBlender_Compile& C)
161161
break;
162162
}
163163
}
164+
#elif RENDER==R_GL
165+
//////////////////////////////////////////////////////////////////////////
166+
// GL
167+
//////////////////////////////////////////////////////////////////////////
168+
#include "uber_deffer.h"
169+
void CBlender_Tree::Compile (CBlender_Compile& C)
170+
{
171+
IBlender::Compile (C);
172+
173+
//*************** codepath is the same, only shaders differ
174+
LPCSTR tvs;
175+
LPCSTR tvs_s;
176+
if (oNotAnTree.value)
177+
{
178+
tvs="tree_s";
179+
if (oBlend.value) tvs_s="shadow_direct_tree_s_aref";
180+
else tvs_s="shadow_direct_tree_s";
181+
}
182+
else
183+
{
184+
tvs = "tree";
185+
if (oBlend.value) tvs_s="shadow_direct_tree_aref";
186+
else tvs_s="shadow_direct_tree";
187+
}
188+
189+
bool bUseATOC = (oBlend.value && (RImplementation.o.dx10_msaa_alphatest==CRender::MSAA_ATEST_DX10_0_ATOC));
190+
191+
switch (C.iElement)
192+
{
193+
case SE_R2_NORMAL_HQ: // deffer
194+
if (bUseATOC)
195+
{
196+
uber_deffer (C,true,tvs,"base_atoc",oBlend.value,0,true);
197+
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
198+
C.r_ColorWriteEnable(false, false, false, false);
199+
C.r_StencilRef (0x01);
200+
// Alpha to coverage.
201+
C.RS.SetRS (XRDX10RS_ALPHATOCOVERAGE, TRUE);
202+
C.r_End ();
203+
}
204+
205+
uber_deffer (C,true,tvs,"base",oBlend.value,0,true);
206+
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
207+
C.r_StencilRef (0x01);
208+
//C.PassSET_ZB (true,false);
209+
// Need only for ATOC to emulate stencil test
210+
if (bUseATOC)
211+
C.RS.SetRS ( D3DRS_ZFUNC, D3DCMP_EQUAL);
212+
C.r_End ();
213+
214+
break;
215+
case SE_R2_NORMAL_LQ: // deffer
216+
if (bUseATOC)
217+
{
218+
uber_deffer (C,false,tvs,"base_atoc",oBlend.value,0,true);
219+
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
220+
C.r_StencilRef (0x01);
221+
C.r_ColorWriteEnable(false, false, false, false);
222+
// Alpha to coverage.
223+
C.RS.SetRS (XRDX10RS_ALPHATOCOVERAGE, TRUE);
224+
C.r_End ();
225+
}
226+
227+
uber_deffer (C,false,tvs,"base",oBlend.value,0,true);
228+
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
229+
C.r_StencilRef (0x01);
230+
// Need only for ATOC to emulate stencil test
231+
if (bUseATOC)
232+
C.RS.SetRS ( D3DRS_ZFUNC, D3DCMP_EQUAL);
233+
C.r_End ();
234+
break;
235+
case SE_R2_SHADOW: // smap-spot
236+
// TODO: DX10: Use dumb shader for shadowmap since shadows are drawn using hardware PCF
237+
if (oBlend.value) C.r_Pass (tvs_s,"shadow_direct_base_aref", FALSE,TRUE,TRUE,TRUE,D3DBLEND_ZERO,D3DBLEND_ONE,TRUE,200);
238+
else C.r_Pass (tvs_s,"shadow_direct_base", FALSE);
239+
C.r_Sampler ("s_base", C.L_textures[0]);
240+
C.r_ColorWriteEnable (false, false, false, false);
241+
C.r_End ();
242+
break;
243+
}
244+
}
164245
#else
165246
//////////////////////////////////////////////////////////////////////////
166247
// R3

src/Layers/xrRender/blenders/Blender_Recorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void CBlender_Compile::StageSET_Alpha (u32 a1, u32 op, u32 a2)
288288
{
289289
RS.SetAlpha (Stage(),a1,op,a2);
290290
}
291-
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
291+
#if !defined(USE_DX10) && !defined(USE_DX11)
292292
void CBlender_Compile::StageSET_TMC (LPCSTR T, LPCSTR M, LPCSTR C, int UVW_channel)
293293
{
294294
Stage_Texture (T);

src/Layers/xrRender/blenders/Blender_Recorder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CBlender_Compile
9292
void StageSET_Color (u32 a1, u32 op, u32 a2);
9393
void StageSET_Color3 (u32 a1, u32 op, u32 a2, u32 a3);
9494
void StageSET_Alpha (u32 a1, u32 op, u32 a2);
95-
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
95+
#if !defined(USE_DX10) && !defined(USE_DX11)
9696
void StageSET_TMC (LPCSTR T, LPCSTR M, LPCSTR C, int UVW_channel);
9797
void Stage_Texture (LPCSTR name, u32 address=D3DTADDRESS_WRAP, u32 fmin=D3DTEXF_LINEAR, u32 fmip=D3DTEXF_LINEAR, u32 fmag=D3DTEXF_LINEAR);
9898
void StageTemplate_LMAP0 ();

src/Layers/xrRender/dxEnvironmentRender.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CBlender_skybox : public IBlender
1515
virtual void Compile (CBlender_Compile& C)
1616
{
1717
C.r_Pass ("sky2", "sky2", FALSE, TRUE, FALSE);
18-
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
18+
#if defined(USE_DX10) || defined(USE_DX11)
1919
//C.r_Sampler_clf ("s_sky0", "$null" );
2020
//C.r_Sampler_clf ("s_sky1", "$null" );
2121
C.r_dx10Texture ("s_sky0", "$null" );

src/Layers/xrRender/uber_deffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void uber_deffer (CBlender_Compile& C, bool hq, LPCSTR _vspec, LPCSTR _pspec, BO
9191
}
9292

9393
// Uber-construct
94-
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
94+
#if defined(USE_DX10) || defined(USE_DX11)
9595
# ifdef USE_DX11
9696
if (bump && hq && RImplementation.o.dx11_enable_tessellation && C.TessMethod!=0)
9797
{

0 commit comments

Comments
 (0)