Skip to content

Commit

Permalink
xrRenderPC_GL: Switch to the GL-specific blender code path.
Browse files Browse the repository at this point in the history
This merges the texture and sampler uniforms while keeping the DX10-level features.
  • Loading branch information
CrossVR committed Dec 2, 2015
1 parent 0cbdf6d commit 635f365
Show file tree
Hide file tree
Showing 31 changed files with 872 additions and 917 deletions.
54 changes: 54 additions & 0 deletions src/Layers/xrRender/Blender_BmmD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,60 @@ void CBlender_BmmD::Compile (CBlender_Compile& C)
break;
}
}
#elif RENDER==R_GL
//////////////////////////////////////////////////////////////////////////
// GL
//////////////////////////////////////////////////////////////////////////
#include "uber_deffer.h"
void CBlender_BmmD::Compile (CBlender_Compile& C)
{
IBlender::Compile (C);
// codepath is the same, only the shaders differ
// ***only pixel shaders differ***
string256 mask;
strconcat (sizeof(mask),mask,C.L_textures[0].c_str(),"_mask");
switch(C.iElement)
{
case SE_R2_NORMAL_HQ: // deffer
uber_deffer (C, true, "impl","impl",false,oT2_Name[0]?oT2_Name:0,true);
C.r_Sampler ("s_mask", mask);
C.r_Sampler ("s_lmap", C.L_textures[1]);

C.r_Sampler ("s_dt_r", oR_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
C.r_Sampler ("s_dt_g", oG_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
C.r_Sampler ("s_dt_b", oB_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);
C.r_Sampler ("s_dt_a", oA_Name, false, D3DTADDRESS_WRAP, D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR, D3DTEXF_ANISOTROPIC);

C.r_Sampler ("s_dn_r", strconcat(sizeof(mask),mask,oR_Name,"_bump") );
C.r_Sampler ("s_dn_g", strconcat(sizeof(mask),mask,oG_Name,"_bump") );
C.r_Sampler ("s_dn_b", strconcat(sizeof(mask),mask,oB_Name,"_bump") );
C.r_Sampler ("s_dn_a", strconcat(sizeof(mask),mask,oA_Name,"_bump") );

C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
C.r_StencilRef (0x01);

C.r_End ();
break;
case SE_R2_NORMAL_LQ: // deffer
uber_deffer (C, false, "base","impl",false,oT2_Name[0]?oT2_Name:0,true);

C.r_Sampler ("s_lmap", C.L_textures[1]);

C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
C.r_StencilRef (0x01);

C.r_End ();
break;
case SE_R2_SHADOW: // smap
//if (RImplementation.o.HW_smap) C.r_Pass ("shadow_direct_base","dumb", FALSE,TRUE,TRUE,FALSE);
//else C.r_Pass ("shadow_direct_base","shadow_direct_base",FALSE);
C.r_Pass ("shadow_direct_base","dumb", FALSE,TRUE,TRUE,FALSE);
C.r_Sampler ("s_base",C.L_textures[0]);
C.r_ColorWriteEnable(false, false, false, false);
C.r_End ();
break;
}
}
#else
//////////////////////////////////////////////////////////////////////////
// R3
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/Blender_Lm(EbB).cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void CBlender_LmEbB::Compile(CBlender_Compile& C)
}
}
}
#elif RENDER==R_R2
#elif RENDER==R_R2 || RENDER==R_GL
//////////////////////////////////////////////////////////////////////////
// R2
//////////////////////////////////////////////////////////////////////////
Expand Down
51 changes: 51 additions & 0 deletions src/Layers/xrRender/Blender_Model_EbB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,57 @@ void CBlender_Model_EbB::Compile(CBlender_Compile& C)
}
}
}
#elif RENDER==R_GL
#include "uber_deffer.h"
void CBlender_Model_EbB::Compile(CBlender_Compile& C)
{
IBlender::Compile(C);

if (oBlend.value)
{
// forward
LPCSTR vsname = 0;
LPCSTR psname = 0;
switch (C.iElement)
{
case 0:
case 1:
vsname = psname = "model_env_lq";
C.r_Pass(vsname, psname, TRUE, TRUE, FALSE, TRUE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, TRUE, 0);
C.r_Sampler ("s_base", C.L_textures[0]);
C.r_Sampler ("s_env", oT2_Name,false,D3DTADDRESS_CLAMP);
C.r_End();
break;
}
}
else
{
// deferred
switch (C.iElement)
{
case SE_R2_NORMAL_HQ: // deffer
uber_deffer(C, true, "model", "base", false, 0, true);
C.r_Stencil(TRUE, D3DCMP_ALWAYS, 0xff, 0x7f, D3DSTENCILOP_KEEP, D3DSTENCILOP_REPLACE, D3DSTENCILOP_KEEP);
C.r_StencilRef(0x01);
C.r_End();
break;
case SE_R2_NORMAL_LQ: // deffer
uber_deffer(C, false, "model", "base", false, 0, true);
C.r_Stencil(TRUE, D3DCMP_ALWAYS, 0xff, 0x7f, D3DSTENCILOP_KEEP, D3DSTENCILOP_REPLACE, D3DSTENCILOP_KEEP);
C.r_StencilRef(0x01);
C.r_End();
break;
case SE_R2_SHADOW: // smap
//if (RImplementation.o.HW_smap) C.r_Pass ("shadow_direct_model","dumb", FALSE,TRUE,TRUE,FALSE);
//else C.r_Pass ("shadow_direct_model","shadow_direct_base",FALSE);
C.r_Pass("shadow_direct_model", "dumb", FALSE, TRUE, TRUE, FALSE);
C.r_Sampler ("s_base",C.L_textures[0]);
C.r_ColorWriteEnable(false, false, false, false);
C.r_End();
break;
}
}
}
#else
#include "uber_deffer.h"
void CBlender_Model_EbB::Compile( CBlender_Compile& C )
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/Blender_Particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void CBlender_Particle::Compile (CBlender_Compile& C)
C.r_Sampler ("s_base", C.L_textures[0],false,oClamp.value?D3DTADDRESS_CLAMP:D3DTADDRESS_WRAP);
C.r_End ();
}
#elif RENDER==R_R2
#elif RENDER==R_R2 || RENDER==R_GL
void CBlender_Particle::Compile (CBlender_Compile& C)
{
IBlender::Compile (C);
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/Blender_Screen_SET.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void CBlender_Screen_SET::Load ( IReader& fs, u16 version)
}
}

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

void CBlender_Screen_SET::Compile (CBlender_Compile& C)
{
Expand Down
81 changes: 81 additions & 0 deletions src/Layers/xrRender/Blender_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,87 @@ void CBlender_Tree::Compile (CBlender_Compile& C)
break;
}
}
#elif RENDER==R_GL
//////////////////////////////////////////////////////////////////////////
// GL
//////////////////////////////////////////////////////////////////////////
#include "uber_deffer.h"
void CBlender_Tree::Compile (CBlender_Compile& C)
{
IBlender::Compile (C);

//*************** codepath is the same, only shaders differ
LPCSTR tvs;
LPCSTR tvs_s;
if (oNotAnTree.value)
{
tvs="tree_s";
if (oBlend.value) tvs_s="shadow_direct_tree_s_aref";
else tvs_s="shadow_direct_tree_s";
}
else
{
tvs = "tree";
if (oBlend.value) tvs_s="shadow_direct_tree_aref";
else tvs_s="shadow_direct_tree";
}

bool bUseATOC = (oBlend.value && (RImplementation.o.dx10_msaa_alphatest==CRender::MSAA_ATEST_DX10_0_ATOC));

switch (C.iElement)
{
case SE_R2_NORMAL_HQ: // deffer
if (bUseATOC)
{
uber_deffer (C,true,tvs,"base_atoc",oBlend.value,0,true);
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
C.r_ColorWriteEnable(false, false, false, false);
C.r_StencilRef (0x01);
// Alpha to coverage.
C.RS.SetRS (XRDX10RS_ALPHATOCOVERAGE, TRUE);
C.r_End ();
}

uber_deffer (C,true,tvs,"base",oBlend.value,0,true);
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
C.r_StencilRef (0x01);
//C.PassSET_ZB (true,false);
// Need only for ATOC to emulate stencil test
if (bUseATOC)
C.RS.SetRS ( D3DRS_ZFUNC, D3DCMP_EQUAL);
C.r_End ();

break;
case SE_R2_NORMAL_LQ: // deffer
if (bUseATOC)
{
uber_deffer (C,false,tvs,"base_atoc",oBlend.value,0,true);
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
C.r_StencilRef (0x01);
C.r_ColorWriteEnable(false, false, false, false);
// Alpha to coverage.
C.RS.SetRS (XRDX10RS_ALPHATOCOVERAGE, TRUE);
C.r_End ();
}

uber_deffer (C,false,tvs,"base",oBlend.value,0,true);
C.r_Stencil ( TRUE,D3DCMP_ALWAYS,0xff,0x7f,D3DSTENCILOP_KEEP,D3DSTENCILOP_REPLACE,D3DSTENCILOP_KEEP);
C.r_StencilRef (0x01);
// Need only for ATOC to emulate stencil test
if (bUseATOC)
C.RS.SetRS ( D3DRS_ZFUNC, D3DCMP_EQUAL);
C.r_End ();
break;
case SE_R2_SHADOW: // smap-spot
// TODO: DX10: Use dumb shader for shadowmap since shadows are drawn using hardware PCF
if (oBlend.value) C.r_Pass (tvs_s,"shadow_direct_base_aref", FALSE,TRUE,TRUE,TRUE,D3DBLEND_ZERO,D3DBLEND_ONE,TRUE,200);
else C.r_Pass (tvs_s,"shadow_direct_base", FALSE);
C.r_Sampler ("s_base", C.L_textures[0]);
C.r_ColorWriteEnable (false, false, false, false);
C.r_End ();
break;
}
}
#else
//////////////////////////////////////////////////////////////////////////
// R3
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/blenders/Blender_Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void CBlender_Compile::StageSET_Alpha (u32 a1, u32 op, u32 a2)
{
RS.SetAlpha (Stage(),a1,op,a2);
}
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
#if !defined(USE_DX10) && !defined(USE_DX11)
void CBlender_Compile::StageSET_TMC (LPCSTR T, LPCSTR M, LPCSTR C, int UVW_channel)
{
Stage_Texture (T);
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/blenders/Blender_Recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CBlender_Compile
void StageSET_Color (u32 a1, u32 op, u32 a2);
void StageSET_Color3 (u32 a1, u32 op, u32 a2, u32 a3);
void StageSET_Alpha (u32 a1, u32 op, u32 a2);
#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL)
#if !defined(USE_DX10) && !defined(USE_DX11)
void StageSET_TMC (LPCSTR T, LPCSTR M, LPCSTR C, int UVW_channel);
void Stage_Texture (LPCSTR name, u32 address=D3DTADDRESS_WRAP, u32 fmin=D3DTEXF_LINEAR, u32 fmip=D3DTEXF_LINEAR, u32 fmag=D3DTEXF_LINEAR);
void StageTemplate_LMAP0 ();
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/dxEnvironmentRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CBlender_skybox : public IBlender
virtual void Compile (CBlender_Compile& C)
{
C.r_Pass ("sky2", "sky2", FALSE, TRUE, FALSE);
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
#if defined(USE_DX10) || defined(USE_DX11)
//C.r_Sampler_clf ("s_sky0", "$null" );
//C.r_Sampler_clf ("s_sky1", "$null" );
C.r_dx10Texture ("s_sky0", "$null" );
Expand Down
2 changes: 1 addition & 1 deletion src/Layers/xrRender/uber_deffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void uber_deffer (CBlender_Compile& C, bool hq, LPCSTR _vspec, LPCSTR _pspec, BO
}

// Uber-construct
#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL)
#if defined(USE_DX10) || defined(USE_DX11)
# ifdef USE_DX11
if (bump && hq && RImplementation.o.dx11_enable_tessellation && C.TessMethod!=0)
{
Expand Down
Loading

0 comments on commit 635f365

Please sign in to comment.