From 2641b74443c1cf64a4fe8d343c7278b453bd0469 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Tue, 24 Nov 2015 21:33:20 +0100 Subject: [PATCH] Blender_Recorder: Implement R3 recorder for OpenGL. --- .../xrRender/blenders/Blender_Recorder.h | 8 +- src/Layers/xrRender/dxEnvironmentRender.h | 2 +- src/Layers/xrRender/tss.h | 2 +- src/Layers/xrRender/xrD3DDefs.h | 9 + .../xrRenderDX10/Blender_Recorder_R3.cpp | 2 +- .../glResourceManager_Scripting.cpp | 411 +++++++++--------- src/Layers/xrRenderPC_GL/stdafx.h | 16 +- src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj | 3 + .../xrRenderPC_GL/xrRender_GL.vcxproj.filters | 12 + 9 files changed, 249 insertions(+), 216 deletions(-) diff --git a/src/Layers/xrRender/blenders/Blender_Recorder.h b/src/Layers/xrRender/blenders/Blender_Recorder.h index cd562029b27..efd1996fcb1 100644 --- a/src/Layers/xrRender/blenders/Blender_Recorder.h +++ b/src/Layers/xrRender/blenders/Blender_Recorder.h @@ -52,7 +52,7 @@ class CBlender_Compile string128 pass_vs; string128 pass_ps; -#if defined(USE_DX10) || defined(USE_DX11) +#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL) string128 pass_gs; # ifdef USE_DX11 string128 pass_hs; @@ -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) +#if !defined(USE_DX10) && !defined(USE_DX11) && !defined(USE_OGL) 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 (); @@ -102,7 +102,7 @@ class CBlender_Compile void StageEnd (); // R1/R2-compiler [programmable] -#if defined(USE_DX10) || defined(USE_DX11) +#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL) void i_dx10Address (u32 s, u32 address); void i_dx10Filter_Min (u32 s, u32 f); void i_dx10Filter_Mip (u32 s, u32 f); @@ -125,7 +125,7 @@ class CBlender_Compile // R1/R2-compiler [programmable] - templates void r_Pass (LPCSTR vs, LPCSTR ps, bool bFog, BOOL bZtest=TRUE, BOOL bZwrite=TRUE, BOOL bABlend=FALSE, D3DBLEND abSRC=D3DBLEND_ONE, D3DBLEND abDST=D3DBLEND_ZERO, BOOL aTest=FALSE, u32 aRef=0); void r_Constant (LPCSTR name, R_constant_setup* s); -#if defined(USE_DX10) || defined(USE_DX11) +#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL) void r_Pass (LPCSTR vs, LPCSTR gs, LPCSTR ps, bool bFog, BOOL bZtest=TRUE, BOOL bZwrite=TRUE, BOOL bABlend=FALSE, D3DBLEND abSRC=D3DBLEND_ONE, D3DBLEND abDST=D3DBLEND_ZERO, BOOL aTest=FALSE, u32 aRef=0); # ifdef USE_DX11 void r_TessPass (LPCSTR vs, LPCSTR hs, LPCSTR ds, LPCSTR gs, LPCSTR ps, bool bFog, BOOL bZtest=TRUE, BOOL bZwrite=TRUE, BOOL bABlend=FALSE, D3DBLEND abSRC=D3DBLEND_ONE, D3DBLEND abDST=D3DBLEND_ZERO, BOOL aTest=FALSE, u32 aRef=0); diff --git a/src/Layers/xrRender/dxEnvironmentRender.h b/src/Layers/xrRender/dxEnvironmentRender.h index 3d25374bc56..c70aab1e960 100644 --- a/src/Layers/xrRender/dxEnvironmentRender.h +++ b/src/Layers/xrRender/dxEnvironmentRender.h @@ -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) +#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL) //C.r_Sampler_clf ("s_sky0", "$null" ); //C.r_Sampler_clf ("s_sky1", "$null" ); C.r_dx10Texture ("s_sky0", "$null" ); diff --git a/src/Layers/xrRender/tss.h b/src/Layers/xrRender/tss.h index 0708477222b..8372a5a06f5 100644 --- a/src/Layers/xrRender/tss.h +++ b/src/Layers/xrRender/tss.h @@ -4,7 +4,7 @@ #include "tss_def.h" -#if defined(USE_DX10) || defined(USE_DX11) +#if defined(USE_DX10) || defined(USE_DX11) || defined(USE_OGL) enum XRDX10SAMPLERSTATETYPE { XRDX10SAMP_ANISOTROPICFILTER = 256, diff --git a/src/Layers/xrRender/xrD3DDefs.h b/src/Layers/xrRender/xrD3DDefs.h index 593c7793a62..bcefab01de1 100644 --- a/src/Layers/xrRender/xrD3DDefs.h +++ b/src/Layers/xrRender/xrD3DDefs.h @@ -15,6 +15,15 @@ typedef enum D3D_CLEAR_FLAG { D3D_CLEAR_STENCIL = 0x2L } D3D_CLEAR_FLAG; +#define D3D_COMPARISON_NEVER GL_NEVER +#define D3D_COMPARISON_LESS GL_LESS +#define D3D_COMPARISON_EQUAL GL_EQUAL +#define D3D_COMPARISON_LESS_EQUAL GL_LEQUAL +#define D3D_COMPARISON_GREATER GL_GREATER +#define D3D_COMPARISON_NOT_EQUAL GL_NEQUAL +#define D3D_COMPARISON_GREATER_EQUAL GL_GEQUAL +#define D3D_COMPARISON_ALWAYS GL_ALWAYS + #define DX10_ONLY(expr) do {} while (0) #elif defined(USE_DX11) || defined(USE_DX10) diff --git a/src/Layers/xrRenderDX10/Blender_Recorder_R3.cpp b/src/Layers/xrRenderDX10/Blender_Recorder_R3.cpp index 51c694ebebd..1676500512e 100644 --- a/src/Layers/xrRenderDX10/Blender_Recorder_R3.cpp +++ b/src/Layers/xrRenderDX10/Blender_Recorder_R3.cpp @@ -167,7 +167,7 @@ u32 CBlender_Compile::r_dx10Sampler(LPCSTR ResourceName) i_dx10Address( stage, D3DTADDRESS_CLAMP); i_dx10Filter(stage, D3DTEXF_LINEAR, D3DTEXF_NONE, D3DTEXF_LINEAR); RS.SetSAMP(stage, XRDX10SAMP_COMPARISONFILTER, TRUE); - RS.SetSAMP(stage, XRDX10SAMP_COMPARISONFUNC, D3D_COMPARISON_LESS_EQUAL); + RS.SetSAMP(stage, XRDX10SAMP_COMPARISONFUNC, (u32)D3D_COMPARISON_LESS_EQUAL); } if (0==xr_strcmp(ResourceName,"smp_jitter")) diff --git a/src/Layers/xrRenderPC_GL/glResourceManager_Scripting.cpp b/src/Layers/xrRenderPC_GL/glResourceManager_Scripting.cpp index 9623482c3cf..522fe687013 100644 --- a/src/Layers/xrRenderPC_GL/glResourceManager_Scripting.cpp +++ b/src/Layers/xrRenderPC_GL/glResourceManager_Scripting.cpp @@ -1,19 +1,15 @@ #include "stdafx.h" #pragma hdrstop -#include - -#include "../../xrEngine/Render.h" -#include "../xrRender/ResourceManager.h" -#include "../xrRender/tss.h" -#include "../xrRender/blenders\blender.h" -#include "../xrRender/blenders\blender_recorder.h" -#include "../../xrEngine/ai_script_space.h" -#include "../../xrEngine/ai_script_lua_extension.h" +#include "xrEngine/Render.h" +#include "Layers/xrRender/ResourceManager.h" +#include "Layers/xrRender/tss.h" +#include "Layers/xrRender/blenders/blender.h" +#include "Layers/xrRender/blenders/blender_recorder.h" +// adopt_compiler don't have = operator And it can't have = operator +#include "xrScriptEngine/script_engine.hpp" #include "luabind/return_reference_to_policy.hpp" -#include "glRenderDeviceRender.h" - using namespace luabind; #ifdef DEBUG @@ -22,215 +18,229 @@ using namespace luabind; #define MDB #endif +class adopt_dx10options +{ +public: + bool _dx10_msaa_alphatest_atoc() { return (RImplementation.o.dx10_msaa_alphatest==CRender::MSAA_ATEST_DX10_0_ATOC); } +}; + // wrapper -class adopt_sampler +class adopt_dx10sampler { - CBlender_Compile* C; - u32 stage; + CBlender_Compile* m_pC; + u32 m_SI; // Sampler index public: - adopt_sampler (CBlender_Compile* _C, u32 _stage) : C(_C), stage(_stage) { if (u32(-1)==stage) C=0; } - adopt_sampler (const adopt_sampler& _C) : C(_C.C), stage(_C.stage) { if (u32(-1)==stage) C=0; } - - adopt_sampler& _texture (LPCSTR texture) { if (C) C->i_Texture (stage,texture); return *this; } - adopt_sampler& _projective (bool _b) { if (C) C->i_Projective(stage,_b); return *this; } - adopt_sampler& _clamp () { if (C) C->i_Address (stage,D3DTADDRESS_CLAMP); return *this; } - adopt_sampler& _wrap () { if (C) C->i_Address (stage,D3DTADDRESS_WRAP); return *this; } - adopt_sampler& _mirror () { if (C) C->i_Address (stage,D3DTADDRESS_MIRROR); return *this; } - adopt_sampler& _f_anisotropic () { if (C) C->i_Filter (stage,D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR,D3DTEXF_ANISOTROPIC); return *this; } - adopt_sampler& _f_trilinear () { if (C) C->i_Filter (stage,D3DTEXF_LINEAR,D3DTEXF_LINEAR,D3DTEXF_LINEAR); return *this; } - adopt_sampler& _f_bilinear () { if (C) C->i_Filter (stage,D3DTEXF_LINEAR,D3DTEXF_POINT, D3DTEXF_LINEAR); return *this; } - adopt_sampler& _f_linear () { if (C) C->i_Filter (stage,D3DTEXF_LINEAR,D3DTEXF_NONE, D3DTEXF_LINEAR); return *this; } - adopt_sampler& _f_none () { if (C) C->i_Filter (stage,D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); return *this; } - adopt_sampler& _fmin_none () { if (C) C->i_Filter_Min(stage,D3DTEXF_NONE); return *this; } - adopt_sampler& _fmin_point () { if (C) C->i_Filter_Min(stage,D3DTEXF_POINT); return *this; } - adopt_sampler& _fmin_linear () { if (C) C->i_Filter_Min(stage,D3DTEXF_LINEAR); return *this; } - adopt_sampler& _fmin_aniso () { if (C) C->i_Filter_Min(stage,D3DTEXF_ANISOTROPIC); return *this; } - adopt_sampler& _fmip_none () { if (C) C->i_Filter_Mip(stage,D3DTEXF_NONE); return *this; } - adopt_sampler& _fmip_point () { if (C) C->i_Filter_Mip(stage,D3DTEXF_POINT); return *this; } - adopt_sampler& _fmip_linear () { if (C) C->i_Filter_Mip(stage,D3DTEXF_LINEAR); return *this; } - adopt_sampler& _fmag_none () { if (C) C->i_Filter_Mag(stage,D3DTEXF_NONE); return *this; } - adopt_sampler& _fmag_point () { if (C) C->i_Filter_Mag(stage,D3DTEXF_POINT); return *this; } - adopt_sampler& _fmag_linear () { if (C) C->i_Filter_Mag(stage,D3DTEXF_LINEAR); return *this; } - adopt_sampler& _comp_less () { if (C) C->i_Comparison(stage,GL_LESS); return *this; } -}; - + adopt_dx10sampler (CBlender_Compile* C, u32 SamplerIndex) : m_pC(C), m_SI(SamplerIndex) { if (u32(-1)==m_SI) m_pC=0;} + adopt_dx10sampler (const adopt_dx10sampler& _C) : m_pC(_C.m_pC), m_SI(_C.m_SI) { if (u32(-1)==m_SI) m_pC=0;} + +// adopt_sampler& _texture (LPCSTR texture) { if (C) C->i_Texture (stage,texture); return *this; } +// adopt_sampler& _projective (bool _b) { if (C) C->i_Projective(stage,_b); return *this; } +// adopt_sampler& _clamp () { if (C) C->i_Address (stage,D3DTADDRESS_CLAMP); return *this; } +// adopt_sampler& _wrap () { if (C) C->i_Address (stage,D3DTADDRESS_WRAP); return *this; } +// adopt_sampler& _mirror () { if (C) C->i_Address (stage,D3DTADDRESS_MIRROR); return *this; } +// adopt_sampler& _f_anisotropic () { if (C) C->i_Filter (stage,D3DTEXF_ANISOTROPIC,D3DTEXF_LINEAR,D3DTEXF_ANISOTROPIC); return *this; } +// adopt_sampler& _f_trilinear () { if (C) C->i_Filter (stage,D3DTEXF_LINEAR,D3DTEXF_LINEAR,D3DTEXF_LINEAR); return *this; } +// adopt_sampler& _f_bilinear () { if (C) C->i_Filter (stage,D3DTEXF_LINEAR,D3DTEXF_POINT, D3DTEXF_LINEAR); return *this; } +// adopt_sampler& _f_linear () { if (C) C->i_Filter (stage,D3DTEXF_LINEAR,D3DTEXF_NONE, D3DTEXF_LINEAR); return *this; } +// adopt_sampler& _f_none () { if (C) C->i_Filter (stage,D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); return *this; } +// adopt_sampler& _fmin_none () { if (C) C->i_Filter_Min(stage,D3DTEXF_NONE); return *this; } +// adopt_sampler& _fmin_point () { if (C) C->i_Filter_Min(stage,D3DTEXF_POINT); return *this; } +// adopt_sampler& _fmin_linear () { if (C) C->i_Filter_Min(stage,D3DTEXF_LINEAR); return *this; } +// adopt_sampler& _fmin_aniso () { if (C) C->i_Filter_Min(stage,D3DTEXF_ANISOTROPIC); return *this; } +// adopt_sampler& _fmip_none () { if (C) C->i_Filter_Mip(stage,D3DTEXF_NONE); return *this; } +// adopt_sampler& _fmip_point () { if (C) C->i_Filter_Mip(stage,D3DTEXF_POINT); return *this; } +// adopt_sampler& _fmip_linear () { if (C) C->i_Filter_Mip(stage,D3DTEXF_LINEAR); return *this; } +// adopt_sampler& _fmag_none () { if (C) C->i_Filter_Mag(stage,D3DTEXF_NONE); return *this; } +// adopt_sampler& _fmag_point () { if (C) C->i_Filter_Mag(stage,D3DTEXF_POINT); return *this; } +// adopt_sampler& _fmag_linear () { if (C) C->i_Filter_Mag(stage,D3DTEXF_LINEAR); return *this; } +}; +/* +class adopt_dx10texture +{ + CBlender_Compile* m_pC; + u32 m_TI; // Sampler index +public: + adopt_dx10texture (CBlender_Compile* C, u32 TextureIndex) : m_pC(C), m_TI(TextureIndex) { if (u32(-1)==m_TI) m_pC=0;} + adopt_dx10texture (const adopt_dx10texture& _C) : m_pC(_C.m_pC), m_TI(_C.m_TI) { if (u32(-1)==m_TI) m_pC=0;} +}; +*/ + +#pragma warning( push ) +#pragma warning( disable : 4512) // wrapper class adopt_compiler { CBlender_Compile* C; + bool &m_bFirstPass; + + void TryEndPass() { if (!m_bFirstPass) C->r_End(); m_bFirstPass = false;} public: - adopt_compiler (CBlender_Compile* _C) : C(_C) { } - adopt_compiler (const adopt_compiler& _C) : C(_C.C) { } + adopt_compiler (CBlender_Compile* _C, bool& bFirstPass) : C(_C), m_bFirstPass(bFirstPass) { m_bFirstPass = true;} + adopt_compiler (const adopt_compiler& _C) : C(_C.C), m_bFirstPass(_C.m_bFirstPass){ } adopt_compiler& _options (int P, bool S) { C->SetParams (P,S); return *this; } adopt_compiler& _o_emissive (bool E) { C->SH->flags.bEmissive=E; return *this; } adopt_compiler& _o_distort (bool E) { C->SH->flags.bDistort=E; return *this; } adopt_compiler& _o_wmark (bool E) { C->SH->flags.bWmark=E; return *this; } - adopt_compiler& _pass (LPCSTR vs, LPCSTR ps) { C->r_Pass (vs,ps,true); return *this; } + adopt_compiler& _pass (LPCSTR vs, LPCSTR ps) { TryEndPass(); C->r_Pass(vs,ps,true); return *this; } + adopt_compiler& _passgs (LPCSTR vs, LPCSTR gs, LPCSTR ps){ TryEndPass(); C->r_Pass(vs,gs,ps,true); return *this; } adopt_compiler& _fog (bool _fog) { C->PassSET_LightFog (FALSE,_fog); return *this; } adopt_compiler& _ZB (bool _test, bool _write) { C->PassSET_ZB (_test,_write); return *this; } adopt_compiler& _blend (bool _blend, u32 abSRC, u32 abDST) { C->PassSET_ablend_mode(_blend,abSRC,abDST); return *this; } adopt_compiler& _aref (bool _aref, u32 aref) { C->PassSET_ablend_aref(_aref,aref); return *this; } - adopt_compiler& _color_write_enable (bool cR, bool cG, bool cB, bool cA) { C->r_ColorWriteEnable(cR, cG, cB, cA); return *this; } - adopt_sampler _sampler (LPCSTR _name) { u32 s = C->r_Sampler(_name,0); return adopt_sampler(C,s); } + adopt_compiler& _dx10texture (LPCSTR _resname, LPCSTR _texname) { C->r_dx10Texture(_resname, _texname); return *this; } + adopt_dx10sampler _dx10sampler (LPCSTR _name) { u32 s = C->r_dx10Sampler(_name); return adopt_dx10sampler(C,s); } + + // DX10 specific + adopt_compiler& _dx10color_write_enable (bool cR, bool cG, bool cB, bool cA) { C->r_ColorWriteEnable(cR, cG, cB, cA); return *this; } + adopt_compiler& _dx10Stencil (bool Enable, u32 Func, u32 Mask, u32 WriteMask, u32 Fail, u32 Pass, u32 ZFail) {C->r_Stencil(Enable, Func, Mask, WriteMask, Fail, Pass, ZFail); return *this; } + adopt_compiler& _dx10StencilRef (u32 Ref) {C->r_StencilRef(Ref); return *this; } + adopt_compiler& _dx10ATOC (bool Enable) { C->RS.SetRS( XRDX10RS_ALPHATOCOVERAGE, Enable); return *this; } + adopt_compiler& _dx10ZFunc (u32 Func) { C->RS.SetRS ( D3DRS_ZFUNC, Func); return *this; } + //adopt_dx10texture _dx10texture (LPCSTR _name) { u32 s = C->r_dx10Texture(_name,0); return adopt_dx10sampler(C,s); } + + adopt_dx10options _dx10Options () { return adopt_dx10options(); }; }; +#pragma warning( pop ) class adopt_blend { public: }; -void LuaLog(LPCSTR caMessage) +class adopt_cmp_func { - MDB; - Lua::LuaOut (Lua::eLuaMessageTypeMessage,"%s",caMessage); -} -void LuaError(lua_State* L) -{ - xrDebug::Fatal(DEBUG_INFO,"LUA error: %s",lua_tostring(L,-1)); -} - -#ifndef PURE_ALLOC -# ifndef USE_MEMORY_MONITOR -# define USE_DL_ALLOCATOR -# endif // USE_MEMORY_MONITOR -#endif // PURE_ALLOC - -#ifndef USE_DL_ALLOCATOR - static void *lua_alloc (void *ud, void *ptr, size_t osize, size_t nsize) - { - (void)ud; - (void)osize; - if (nsize == 0) { - xr_free (ptr); - return NULL; - } - -# ifdef DEBUG_MEMORY_NAME - return Memory.mem_realloc (ptr, nsize, "LUA:Render"); -# else // DEBUG_MEMORY_MANAGER - return Memory.mem_realloc (ptr, nsize); -# endif // DEBUG_MEMORY_MANAGER - } -#else // USE_DL_ALLOCATOR -# include "../xrRender/doug_lea_memory_allocator.h" +public: +}; - static void *lua_alloc (void *ud, void *ptr, size_t osize, size_t nsize) - { - (void)ud; - (void)osize; - if (nsize == 0) { dlfree (ptr); return NULL; } - else return dlrealloc (ptr, nsize); - } -#endif // USE_DL_ALLOCATOR +class adopt_stencil_op +{ +public: +}; // export void CResourceManager::LS_Load () { - LSVM = lua_newstate(lua_alloc, NULL); - if (!LSVM) { - Msg ("! ERROR : Cannot initialize LUA VM!"); - return; - } - - // initialize lua standard library functions - luaopen_base (LSVM); - luaopen_table (LSVM); - luaopen_string (LSVM); - luaopen_math (LSVM); - luaopen_jit (LSVM); - - luabind::open (LSVM); -#if !XRAY_EXCEPTIONS - if (0==luabind::get_error_callback()) - luabind::set_error_callback (LuaError); -#endif - - function (LSVM, "log", LuaLog); - - module (LSVM) - [ - class_("_sampler") - .def( constructor()) - .def("texture", &adopt_sampler::_texture ,return_reference_to(_1)) - .def("project", &adopt_sampler::_projective ,return_reference_to(_1)) - .def("clamp", &adopt_sampler::_clamp ,return_reference_to(_1)) - .def("wrap", &adopt_sampler::_wrap ,return_reference_to(_1)) - .def("mirror", &adopt_sampler::_mirror ,return_reference_to(_1)) - .def("f_anisotropic", &adopt_sampler::_f_anisotropic ,return_reference_to(_1)) - .def("f_trilinear", &adopt_sampler::_f_trilinear ,return_reference_to(_1)) - .def("f_bilinear", &adopt_sampler::_f_bilinear ,return_reference_to(_1)) - .def("f_linear", &adopt_sampler::_f_linear ,return_reference_to(_1)) - .def("f_none", &adopt_sampler::_f_none ,return_reference_to(_1)) - .def("fmin_none", &adopt_sampler::_fmin_none ,return_reference_to(_1)) - .def("fmin_point", &adopt_sampler::_fmin_point ,return_reference_to(_1)) - .def("fmin_linear", &adopt_sampler::_fmin_linear ,return_reference_to(_1)) - .def("fmin_aniso", &adopt_sampler::_fmin_aniso ,return_reference_to(_1)) - .def("fmip_none", &adopt_sampler::_fmip_none ,return_reference_to(_1)) - .def("fmip_point", &adopt_sampler::_fmip_point ,return_reference_to(_1)) - .def("fmip_linear", &adopt_sampler::_fmip_linear ,return_reference_to(_1)) - .def("fmag_none", &adopt_sampler::_fmag_none ,return_reference_to(_1)) - .def("fmag_point", &adopt_sampler::_fmag_point ,return_reference_to(_1)) - .def("fmag_linear", &adopt_sampler::_fmag_linear ,return_reference_to(_1)) - .def("comp_less", &adopt_sampler::_comp_less ,return_reference_to(_1)), - - class_("_compiler") - .def( constructor()) - .def("begin", &adopt_compiler::_pass ,return_reference_to(_1)) - .def("sorting", &adopt_compiler::_options ,return_reference_to(_1)) - .def("emissive", &adopt_compiler::_o_emissive ,return_reference_to(_1)) - .def("distort", &adopt_compiler::_o_distort ,return_reference_to(_1)) - .def("wmark", &adopt_compiler::_o_wmark ,return_reference_to(_1)) - .def("fog", &adopt_compiler::_fog ,return_reference_to(_1)) - .def("zb", &adopt_compiler::_ZB ,return_reference_to(_1)) - .def("blend", &adopt_compiler::_blend ,return_reference_to(_1)) - .def("aref", &adopt_compiler::_aref ,return_reference_to(_1)) - .def("color_write_enable", &adopt_compiler::_color_write_enable,return_reference_to(_1)) - .def("sampler", &adopt_compiler::_sampler ), // returns sampler-object - - class_("blend") - .enum_("blend") - [ - value("zero", int(D3DBLEND_ZERO)), - value("one", int(D3DBLEND_ONE)), - value("srccolor", int(D3DBLEND_SRCCOLOR)), - value("invsrccolor", int(D3DBLEND_INVSRCCOLOR)), - value("srcalpha", int(D3DBLEND_SRCALPHA)), - value("invsrcalpha", int(D3DBLEND_INVSRCALPHA)), - value("destalpha", int(D3DBLEND_DESTALPHA)), - value("invdestalpha", int(D3DBLEND_INVDESTALPHA)), - value("destcolor", int(D3DBLEND_DESTCOLOR)), - value("invdestcolor", int(D3DBLEND_INVDESTCOLOR)), - value("srcalphasat", int(D3DBLEND_SRCALPHASAT)) - ] - ]; - + auto exporterFunc = [](lua_State *luaState) + { + module(luaState) + [ + class_("_dx10options") + .def("dx10_msaa_alphatest_atoc", &adopt_dx10options::_dx10_msaa_alphatest_atoc ) + //.def("", &adopt_dx10options::_dx10Options ), // returns options-object + , + + + class_("_dx10sampler") + //.def("texture", &adopt_sampler::_texture ,return_reference_to(_1)) + //.def("project", &adopt_sampler::_projective ,return_reference_to(_1)) + //.def("clamp", &adopt_sampler::_clamp ,return_reference_to(_1)) + //.def("wrap", &adopt_sampler::_wrap ,return_reference_to(_1)) + //.def("mirror", &adopt_sampler::_mirror ,return_reference_to(_1)) + //.def("f_anisotropic", &adopt_sampler::_f_anisotropic ,return_reference_to(_1)) + //.def("f_trilinear", &adopt_sampler::_f_trilinear ,return_reference_to(_1)) + //.def("f_bilinear", &adopt_sampler::_f_bilinear ,return_reference_to(_1)) + //.def("f_linear", &adopt_sampler::_f_linear ,return_reference_to(_1)) + //.def("f_none", &adopt_sampler::_f_none ,return_reference_to(_1)) + //.def("fmin_none", &adopt_sampler::_fmin_none ,return_reference_to(_1)) + //.def("fmin_point", &adopt_sampler::_fmin_point ,return_reference_to(_1)) + //.def("fmin_linear", &adopt_sampler::_fmin_linear ,return_reference_to(_1)) + //.def("fmin_aniso", &adopt_sampler::_fmin_aniso ,return_reference_to(_1)) + //.def("fmip_none", &adopt_sampler::_fmip_none ,return_reference_to(_1)) + //.def("fmip_point", &adopt_sampler::_fmip_point ,return_reference_to(_1)) + //.def("fmip_linear", &adopt_sampler::_fmip_linear ,return_reference_to(_1)) + //.def("fmag_none", &adopt_sampler::_fmag_none ,return_reference_to(_1)) + //.def("fmag_point", &adopt_sampler::_fmag_point ,return_reference_to(_1)) + //.def("fmag_linear", &adopt_sampler::_fmag_linear ,return_reference_to(_1)) + , + + class_("_compiler") + .def( constructor()) + .def("begin", &adopt_compiler::_pass ,return_reference_to(_1)) + .def("begin", &adopt_compiler::_passgs ,return_reference_to(_1)) + .def("sorting", &adopt_compiler::_options ,return_reference_to(_1)) + .def("emissive", &adopt_compiler::_o_emissive ,return_reference_to(_1)) + .def("distort", &adopt_compiler::_o_distort ,return_reference_to(_1)) + .def("wmark", &adopt_compiler::_o_wmark ,return_reference_to(_1)) + .def("fog", &adopt_compiler::_fog ,return_reference_to(_1)) + .def("zb", &adopt_compiler::_ZB ,return_reference_to(_1)) + .def("blend", &adopt_compiler::_blend ,return_reference_to(_1)) + .def("aref", &adopt_compiler::_aref ,return_reference_to(_1)) + // For compatibility only + .def("dx10color_write_enable", &adopt_compiler::_dx10color_write_enable,return_reference_to(_1)) + .def("color_write_enable", &adopt_compiler::_dx10color_write_enable,return_reference_to(_1)) + .def("dx10texture", &adopt_compiler::_dx10texture ,return_reference_to(_1)) + .def("dx10stencil", &adopt_compiler::_dx10Stencil ,return_reference_to(_1)) + .def("dx10stencil_ref", &adopt_compiler::_dx10StencilRef,return_reference_to(_1)) + .def("dx10atoc", &adopt_compiler::_dx10ATOC ,return_reference_to(_1)) + .def("dx10zfunc", &adopt_compiler::_dx10ZFunc ,return_reference_to(_1)) + + .def("dx10sampler", &adopt_compiler::_dx10sampler ) // returns sampler-object + .def("dx10Options", &adopt_compiler::_dx10Options ), // returns options-object + + + class_("blend") + .enum_("blend") + [ + value("zero", int(D3DBLEND_ZERO)), + value("one", int(D3DBLEND_ONE)), + value("srccolor", int(D3DBLEND_SRCCOLOR)), + value("invsrccolor", int(D3DBLEND_INVSRCCOLOR)), + value("srcalpha", int(D3DBLEND_SRCALPHA)), + value("invsrcalpha", int(D3DBLEND_INVSRCALPHA)), + value("destalpha", int(D3DBLEND_DESTALPHA)), + value("invdestalpha", int(D3DBLEND_INVDESTALPHA)), + value("destcolor", int(D3DBLEND_DESTCOLOR)), + value("invdestcolor", int(D3DBLEND_INVDESTCOLOR)), + value("srcalphasat", int(D3DBLEND_SRCALPHASAT)) + ], + + class_("cmp_func") + .enum_("cmp_func") + [ + value("never", int(D3DCMP_NEVER)), + value("less", int(D3DCMP_LESS)), + value("equal", int(D3DCMP_EQUAL)), + value("lessequal", int(D3DCMP_LESSEQUAL)), + value("greater", int(D3DCMP_GREATER)), + value("notequal", int(D3DCMP_NOTEQUAL)), + value("greaterequal", int(D3DCMP_GREATEREQUAL)), + value("always", int(D3DCMP_ALWAYS)) + ], + + class_("stencil_op") + .enum_("stencil_op") + [ + value("keep", int(D3DSTENCILOP_KEEP)), + value("zero", int(D3DSTENCILOP_ZERO)), + value("replace", int(D3DSTENCILOP_REPLACE)), + value("incrsat", int(D3DSTENCILOP_INCRSAT)), + value("decrsat", int(D3DSTENCILOP_DECRSAT)), + value("invert", int(D3DSTENCILOP_INVERT)), + value("incr", int(D3DSTENCILOP_INCR)), + value("decr", int(D3DSTENCILOP_DECR)) + ] + ]; + }; + ScriptEngine.init(exporterFunc, false); // load shaders - xr_vector* folder = FS.file_list_open ("$game_shaders$",::Render->getShaderPath(),FS_ListFiles|FS_RootOnly); + const char *shaderPath = RImplementation.getShaderPath(); + xr_vector* folder = FS.file_list_open ("$game_shaders$", shaderPath, FS_ListFiles|FS_RootOnly); VERIFY (folder); for (u32 it=0; itsize(); it++) { string_path namesp,fn; - strcpy_s (namesp,(*folder)[it]); + xr_strcpy (namesp,(*folder)[it]); if (0==strext(namesp) || 0!=xr_strcmp(strext(namesp),".s")) continue; *strext (namesp)=0; - if (0==namesp[0]) strcpy_s (namesp,"_G"); - strconcat (sizeof(fn),fn,::Render->getShaderPath(),(*folder)[it]); + if (0==namesp[0]) xr_strcpy (namesp, ScriptEngine.GlobalNamespace); + strconcat (sizeof(fn), fn, shaderPath, (*folder)[it]); FS.update_path (fn,"$game_shaders$",fn); - try { - Script::bfLoadFileIntoNamespace (LSVM,fn,namesp,true); - } catch (...) - { - Log(lua_tostring(LSVM,-1)); - } + ScriptEngine.load_file_into_namespace(fn, namesp); } FS.file_list_close (folder); } -void CResourceManager::LS_Unload () -{ - lua_close (LSVM); - LSVM = NULL; -} +void CResourceManager::LS_Unload() { ScriptEngine.unload(); } BOOL CResourceManager::_lua_HasShader (LPCSTR s_shader) { @@ -239,11 +249,10 @@ BOOL CResourceManager::_lua_HasShader (LPCSTR s_shader) undercorated[i]=('\\'==s_shader[i])?'_':s_shader[i]; #ifdef _EDITOR - return Script::bfIsObjectPresent(LSVM,undercorated,"editor",LUA_TFUNCTION); + return ScriptEngine.object(undercorated,"editor",LUA_TFUNCTION); #else - return Script::bfIsObjectPresent(LSVM,undercorated,"normal",LUA_TFUNCTION) || - Script::bfIsObjectPresent(LSVM,undercorated,"l_special",LUA_TFUNCTION) - ; + return ScriptEngine.object(undercorated,"normal",LUA_TFUNCTION) || + ScriptEngine.object(undercorated,"l_special",LUA_TFUNCTION); #endif } @@ -269,39 +278,33 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures) C.detail_scaler = NULL; // Compile element (LOD0 - HQ) - if (Script::bfIsObjectPresent(LSVM,s_shader,"normal_hq",LUA_TFUNCTION)) + if (ScriptEngine.object(s_shader,"normal_hq",LUA_TFUNCTION)) { // Analyze possibility to detail this shader C.iElement = 0; -//. C.bDetail = glRenderDeviceRender::Instance().Resources->_GetDetailTexture(*C.L_textures[0],C.detail_texture,C.detail_scaler); - //C.bDetail = glRenderDeviceRender::Instance().Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler); - C.bDetail = glRenderDeviceRender::Instance().Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler); + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); if (C.bDetail) S.E[0] = C._lua_Compile(s_shader,"normal_hq"); else S.E[0] = C._lua_Compile(s_shader,"normal"); } else { - if (Script::bfIsObjectPresent(LSVM,s_shader,"normal",LUA_TFUNCTION)) + if (ScriptEngine.object(s_shader,"normal",LUA_TFUNCTION)) { C.iElement = 0; -//. C.bDetail = glRenderDeviceRender::Instance().Resources->_GetDetailTexture(*C.L_textures[0],C.detail_texture,C.detail_scaler); - //C.bDetail = glRenderDeviceRender::Instance().Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler); - C.bDetail = glRenderDeviceRender::Instance().Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler); + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); S.E[0] = C._lua_Compile(s_shader,"normal"); } } // Compile element (LOD1) - if (Script::bfIsObjectPresent(LSVM,s_shader,"normal",LUA_TFUNCTION)) + if (ScriptEngine.object(s_shader,"normal",LUA_TFUNCTION)) { C.iElement = 1; -//. C.bDetail = glRenderDeviceRender::Instance().Resources->_GetDetailTexture(*C.L_textures[0],C.detail_texture,C.detail_scaler); - //C.bDetail = glRenderDeviceRender::Instance().Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler); - C.bDetail = glRenderDeviceRender::Instance().Resources->m_textures_description.GetDetailTexture(C.L_textures[0],C.detail_texture,C.detail_scaler); + C.bDetail = m_textures_description.GetDetailTexture(C.L_textures[0], C.detail_texture, C.detail_scaler); S.E[1] = C._lua_Compile(s_shader,"normal"); } // Compile element - if (Script::bfIsObjectPresent(LSVM,s_shader,"l_point",LUA_TFUNCTION)) + if (ScriptEngine.object(s_shader,"l_point",LUA_TFUNCTION)) { C.iElement = 2; C.bDetail = FALSE; @@ -309,7 +312,7 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures) } // Compile element - if (Script::bfIsObjectPresent(LSVM,s_shader,"l_spot",LUA_TFUNCTION)) + if (ScriptEngine.object(s_shader,"l_spot",LUA_TFUNCTION)) { C.iElement = 3; C.bDetail = FALSE; @@ -317,7 +320,7 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures) } // Compile element - if (Script::bfIsObjectPresent(LSVM,s_shader,"l_special",LUA_TFUNCTION)) + if (ScriptEngine.object(s_shader,"l_special",LUA_TFUNCTION)) { C.iElement = 4; C.bDetail = FALSE; @@ -329,7 +332,7 @@ Shader* CResourceManager::_lua_Create (LPCSTR d_shader, LPCSTR s_textures) if (S.equal(v_shaders[it])) return v_shaders[it]; // Create _new_ entry - Shader* N = new Shader(S); + Shader* N = xr_new(S); N->dwFlags |= xr_resource_flagged::RF_REGISTERED; v_shaders.push_back (N); return N; @@ -345,12 +348,12 @@ ShaderElement* CBlender_Compile::_lua_Compile (LPCSTR namesp, LPCSTR name) LPCSTR t_0 = *L_textures[0] ? *L_textures[0] : "null"; LPCSTR t_1 = (L_textures.size() > 1) ? *L_textures[1] : "null"; LPCSTR t_d = detail_texture ? detail_texture : "null" ; - lua_State* LSVM = glRenderDeviceRender::Instance().Resources->LSVM; - object shader = get_globals(LSVM)[namesp]; + object shader = RImplementation.Resources->ScriptEngine.name_space(namesp); functor element = object_cast >(shader[name]); - adopt_compiler ac = adopt_compiler(this); + bool bFirstPass = false; + adopt_compiler ac = adopt_compiler(this, bFirstPass); element (ac,t_0,t_1,t_d); r_End (); - ShaderElement* _r = glRenderDeviceRender::Instance().Resources->_CreateElement(E); + ShaderElement* _r = RImplementation.Resources->_CreateElement(E); return _r; -} +} \ No newline at end of file diff --git a/src/Layers/xrRenderPC_GL/stdafx.h b/src/Layers/xrRenderPC_GL/stdafx.h index a0d152fe1be..84bd7ef3522 100644 --- a/src/Layers/xrRenderPC_GL/stdafx.h +++ b/src/Layers/xrRenderPC_GL/stdafx.h @@ -43,9 +43,15 @@ IC void jitter(CBlender_Compile& C) { - C.r_Sampler("jitter0", JITTER(0), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); - C.r_Sampler("jitter1", JITTER(1), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); - C.r_Sampler("jitter2", JITTER(2), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); - C.r_Sampler("jitter3", JITTER(3), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); - C.r_Sampler("jitter4", JITTER(4), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); +// C.r_Sampler ("jitter0", JITTER(0), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); +// C.r_Sampler ("jitter1", JITTER(1), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); +// C.r_Sampler ("jitter2", JITTER(2), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); +// C.r_Sampler ("jitter3", JITTER(3), true, D3DTADDRESS_WRAP, D3DTEXF_POINT, D3DTEXF_NONE, D3DTEXF_POINT); + C.r_dx10Texture ("jitter0", JITTER(0)); + C.r_dx10Texture ("jitter1", JITTER(1)); + C.r_dx10Texture ("jitter2", JITTER(2)); + C.r_dx10Texture ("jitter3", JITTER(3)); + C.r_dx10Texture ("jitter4", JITTER(4)); + C.r_dx10Texture ("jitterMipped", r2_jitter_mipped); + C.r_dx10Sampler ("smp_jitter"); } diff --git a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj index d799c4a658d..21c5917c1e8 100644 --- a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj +++ b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj @@ -203,6 +203,7 @@ + @@ -211,6 +212,7 @@ + @@ -402,6 +404,7 @@ + diff --git a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters index 522722d8cc7..c71b30e71f6 100644 --- a/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters +++ b/src/Layers/xrRenderPC_GL/xrRender_GL.vcxproj.filters @@ -166,6 +166,9 @@ {b5644c37-6f04-44e4-8343-56fec645ad53} + + {7fdc926e-8c7d-4cba-a662-332feb1aada8} + @@ -633,6 +636,12 @@ Core + + Core_Target\ColorMap + + + Refactored\Execution & 3D\Shaders\Blender + Refactored\Execution & 3D\DebugDraw @@ -1064,6 +1073,9 @@ Core + + Core_Target\ColorMap + Refactored\Execution & 3D\DebugDraw