diff options
Diffstat (limited to 'RenderScript/src/DeviceContextFuncBindings.cpp')
| -rw-r--r-- | RenderScript/src/DeviceContextFuncBindings.cpp | 115 |
1 files changed, 112 insertions, 3 deletions
diff --git a/RenderScript/src/DeviceContextFuncBindings.cpp b/RenderScript/src/DeviceContextFuncBindings.cpp index 9525cf2..bf7e402 100644 --- a/RenderScript/src/DeviceContextFuncBindings.cpp +++ b/RenderScript/src/DeviceContextFuncBindings.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015 Egor Yusov +/* Copyright 2015-2016 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,15 +26,27 @@ #include "GraphicsUtilities.h" #include "TextureViewParser.h" #include "EngineObjectParserBase.h" +#include "ShaderResourceBindingParser.h" +#include "PSODescParser.h" namespace Diligent { - DeviceContextFuncBindings::DeviceContextFuncBindings( IRenderDevice *pRenderDevice, lua_State *L, TextureViewParser *pTexViewPasrser ) : + DeviceContextFuncBindings::DeviceContextFuncBindings( IRenderDevice *pRenderDevice, lua_State *L, + TextureViewParser *pTexViewPasrser, + ShaderResourceBindingParser *pSRBParser, + PSODescParser *pPSOParser) : m_SetRenderTargetsBinding(this, L, "Context", "SetRenderTargets", &DeviceContextFuncBindings::SetRenderTargets), m_ClearRenderTargetBinding(this, L, "Context", "ClearRenderTarget", &DeviceContextFuncBindings::ClearRenderTarget), m_ClearDepthStencilBinding(this, L, "Context", "ClearDepthStencil", &DeviceContextFuncBindings::ClearDepthStencil), - m_TexViewMetatableName( pTexViewPasrser->GetMetatableName() ) + m_SetStencilRefBinding(this, L, "Context", "SetStencilRef", &DeviceContextFuncBindings::SetStencilRef), + m_SetBlendFactorsBinding(this, L, "Context", "SetBlendFactors", &DeviceContextFuncBindings::SetBlendFactors), + m_CommitShaderResourcesBinding(this, L, "Context", "CommitShaderResources", &DeviceContextFuncBindings::CommitShaderResources), + m_TransitionShaderResourcesBinding(this, L, "Context", "TransitionShaderResources", &DeviceContextFuncBindings::TransitionShaderResources), + m_TexViewMetatableName( pTexViewPasrser->GetMetatableName() ), + m_ShaderResBindingMetatableName( pSRBParser->GetMetatableName() ), + m_PSOMetatableName(pPSOParser->GetMetatableName()) { + DEFINE_ENUM_ELEMENT_MAPPING( m_CommitShaderResFlagsEnumMapping, COMMIT_SHADER_RESOURCES_FLAG_TRANSITION_RESOURCES ); }; int DeviceContextFuncBindings::SetRenderTargets( lua_State *L ) @@ -142,4 +154,101 @@ namespace Diligent return 0; } + + int DeviceContextFuncBindings::SetStencilRef( lua_State *L ) + { + auto NumArgs = lua_gettop( L ); + + Uint32 StencilRef = 0; + if(NumArgs >= 1 ) + StencilRef = ReadValueFromLua<Uint32>( L, 1 ); + + auto *pContext = EngineObjectParserBase::LoadDeviceContextFromRegistry( L ); + pContext->SetStencilRef( StencilRef ); + + // Return no values to Lua + return 0; + } + + int DeviceContextFuncBindings::SetBlendFactors( lua_State *L ) + { + float BlendFactors[4] = {}; + auto NumArgs = lua_gettop( L ); + + for(int bf=0; bf < std::min(NumArgs, 4); ++bf) + BlendFactors[bf] = ReadValueFromLua<Float32>( L, bf+1 ); + + auto *pContext = EngineObjectParserBase::LoadDeviceContextFromRegistry( L ); + pContext->SetBlendFactors( BlendFactors ); + + // Return no values to Lua + return 0; + } + + int DeviceContextFuncBindings::CommitShaderResources( lua_State *L ) + { + auto NumArgs = lua_gettop( L ); + IShaderResourceBinding *pShaderResBinding = nullptr; + int CurrArg = 1; + if(NumArgs >= CurrArg ) + { + if( lua_type( L, CurrArg ) == LUA_TUSERDATA ) + { + pShaderResBinding = *GetUserData<IShaderResourceBinding**>( L, CurrArg, m_ShaderResBindingMetatableName.c_str() ); + ++CurrArg; + } + } + + Uint32 Flags = 0; + if(NumArgs >= CurrArg && + (lua_type( L, CurrArg ) == LUA_TSTRING || + lua_type( L, CurrArg ) == LUA_TTABLE ) ) + { + FlagsLoader<COMMIT_SHADER_RESOURCES_FLAG> CommitShaderResFlagsLoader(0, "CommitShaderResourcesFlag", m_CommitShaderResFlagsEnumMapping); + CommitShaderResFlagsLoader.SetValue( L, CurrArg, &Flags ); + ++CurrArg; + } + + auto *pContext = EngineObjectParserBase::LoadDeviceContextFromRegistry( L ); + pContext->CommitShaderResources( pShaderResBinding, Flags ); + + return 0; + } + + int DeviceContextFuncBindings::TransitionShaderResources( lua_State *L ) + { + auto NumArgs = lua_gettop( L ); + IPipelineState *pPSO = nullptr; + int CurrArg = 1; + + if(NumArgs >= CurrArg ) + { + if( lua_type( L, CurrArg ) == LUA_TUSERDATA ) + { + pPSO = *GetUserData<IPipelineState**>( L, CurrArg, m_PSOMetatableName.c_str() ); + ++CurrArg; + } + } + + if( !pPSO ) + { + SCRIPT_PARSING_ERROR( L, "PSO is expected as the first argument" ); + } + + IShaderResourceBinding *pShaderResBinding = nullptr; + if(NumArgs >= CurrArg ) + { + if( lua_type( L, CurrArg ) == LUA_TUSERDATA ) + { + pShaderResBinding = *GetUserData<IShaderResourceBinding**>( L, CurrArg, m_ShaderResBindingMetatableName.c_str() ); + ++CurrArg; + } + } + + auto *pContext = EngineObjectParserBase::LoadDeviceContextFromRegistry( L ); + pContext->TransitionShaderResources( pPSO, pShaderResBinding ); + + return 0; + } + } |
