summaryrefslogtreecommitdiffstats
path: root/RenderScript/include
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2015-10-21 04:05:29 +0000
committerEgor Yusov <egor.yusov@gmail.com>2015-10-21 04:05:29 +0000
commitf2e065dee10fb110e9d51175ee6381333319ef56 (patch)
treeda85ca78fe050280d7592bf6bf1071410846031f /RenderScript/include
downloadDiligentTools-f2e065dee10fb110e9d51175ee6381333319ef56.tar.gz
DiligentTools-f2e065dee10fb110e9d51175ee6381333319ef56.zip
Release v1.0.0
Diffstat (limited to 'RenderScript/include')
-rw-r--r--RenderScript/include/BlendStateParser.h51
-rw-r--r--RenderScript/include/BufferParser.h67
-rw-r--r--RenderScript/include/BufferViewParser.h63
-rw-r--r--RenderScript/include/ClassMethodBinding.h87
-rw-r--r--RenderScript/include/ConvenienceFunctions.h84
-rw-r--r--RenderScript/include/Debug.h63
-rw-r--r--RenderScript/include/DepthStencilStateParser.h52
-rw-r--r--RenderScript/include/DeviceContextFuncBindings.h49
-rw-r--r--RenderScript/include/DrawAttribsParser.h63
-rw-r--r--RenderScript/include/EngineObjectParserBase.h62
-rw-r--r--RenderScript/include/EngineObjectParserCommon.h70
-rw-r--r--RenderScript/include/EnumMappings.h108
-rw-r--r--RenderScript/include/LayoutDescParser.h55
-rw-r--r--RenderScript/include/LuaBindings.h662
-rw-r--r--RenderScript/include/LuaFunctionBinding.h100
-rw-r--r--RenderScript/include/LuaWrappers.h59
-rw-r--r--RenderScript/include/ParsingErrors.h51
-rw-r--r--RenderScript/include/RasterizerStateParser.h60
-rw-r--r--RenderScript/include/ResourceMappingParser.h65
-rw-r--r--RenderScript/include/SamplerParser.h58
-rw-r--r--RenderScript/include/ScissorRectParser.h51
-rw-r--r--RenderScript/include/ScriptParser.h151
-rw-r--r--RenderScript/include/ShaderParser.h74
-rw-r--r--RenderScript/include/ShaderVariableParser.h65
-rw-r--r--RenderScript/include/TextureParser.h66
-rw-r--r--RenderScript/include/TextureViewParser.h71
-rw-r--r--RenderScript/include/ViewportParser.h51
-rw-r--r--RenderScript/include/pch.h49
28 files changed, 2507 insertions, 0 deletions
diff --git a/RenderScript/include/BlendStateParser.h b/RenderScript/include/BlendStateParser.h
new file mode 100644
index 0000000..9589488
--- /dev/null
+++ b/RenderScript/include/BlendStateParser.h
@@ -0,0 +1,51 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+
+namespace Diligent
+{
+ class BlendStateParser : public EngineObjectParserCommon<IBlendState>
+ {
+ public:
+ BlendStateParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* BlendStateLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // BlendStateDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<BlendStateDesc> SBSDescWrapper;
+
+ int SetBlendState( lua_State *L );
+ ClassMethodCaller<BlendStateParser> m_SetBlendBinding;
+ };
+}
diff --git a/RenderScript/include/BufferParser.h b/RenderScript/include/BufferParser.h
new file mode 100644
index 0000000..e9a6053
--- /dev/null
+++ b/RenderScript/include/BufferParser.h
@@ -0,0 +1,67 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::BUFFER_MODE )
+ DEFINE_ENUM_HASH( Diligent::SET_VERTEX_BUFFERS_FLAGS )
+}
+
+namespace Diligent
+{
+ class BufferParser : public EngineObjectParserCommon<IBuffer>
+ {
+ public:
+ BufferParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* BufferLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // BufferDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<BufferDesc> SBuffDescWrapper;
+
+ int SetVertexBuffers( lua_State * );
+ ClassMethodCaller<BufferParser> m_SetVertexBuffersBinding;
+ int SetIndexBuffer( lua_State * );
+ ClassMethodCaller<BufferParser> m_SetIndexBufferBinding;
+
+ UsageEnumMapping m_UsageEnumMapping;
+ // Explicit namespace declaraion is necesseary to avoid
+ // name conflicts when building for windows store
+ EnumMapping<Diligent::BIND_FLAGS> m_BindFlagEnumMapping;
+ CpuAccessFlagEnumMapping m_CpuAccessFlagEnumMapping;
+ NumericArrayLoader m_ArrayLoader;
+ EnumMapping<BUFFER_MODE> m_BuffModeEnumMapping;
+ EnumMapping<SET_VERTEX_BUFFERS_FLAGS> m_SetVBFlagEnumMapping;
+ };
+}
diff --git a/RenderScript/include/BufferViewParser.h b/RenderScript/include/BufferViewParser.h
new file mode 100644
index 0000000..a1b003d
--- /dev/null
+++ b/RenderScript/include/BufferViewParser.h
@@ -0,0 +1,63 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::BUFFER_VIEW_TYPE )
+}
+
+namespace Diligent
+{
+ class BufferViewParser : public EngineObjectParserCommon<IBufferView>
+ {
+ public:
+ BufferViewParser( class BufferParser *pBufParser, IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char *BufferViewLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // BufferViewDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<BufferViewDesc> SBuffViewDescWrapper;
+
+ const String m_BufferLibMetatableName;
+
+ ClassMethodCaller<BufferViewParser> m_CreateViewBinding;
+ int CreateView( lua_State *L );
+
+ ClassMethodCaller<BufferViewParser> m_GetDefaultViewBinding;
+ int GetDefaultView( lua_State * );
+
+ EnumMapping<BUFFER_VIEW_TYPE> m_ViewTypeEnumMapping;
+ EnumMemberBinder<BUFFER_VIEW_TYPE> m_ViewTypeParser;
+ };
+}
diff --git a/RenderScript/include/ClassMethodBinding.h b/RenderScript/include/ClassMethodBinding.h
new file mode 100644
index 0000000..90c4259
--- /dev/null
+++ b/RenderScript/include/ClassMethodBinding.h
@@ -0,0 +1,87 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+namespace Diligent
+{
+ template<typename OwnerClassType>
+ class ClassMethodCaller
+ {
+ public:
+ typedef int(OwnerClassType::*MemberFunctionType)(lua_State *LuaState);
+
+ ClassMethodCaller( OwnerClassType *pOwner,
+ lua_State *L,
+ const Char *LuaTableName,
+ const Char *LuaFunctionName,
+ MemberFunctionType MemberFunction) :
+ m_MemberFunction( MemberFunction )
+ {
+ INIT_LUA_STACK_TRACKING( L );
+
+ lua_getglobal( L, LuaTableName ); // -0 | +1 -> +1
+ if( lua_type( L, -1 ) == LUA_TNIL )
+ {
+ // Global name is not found, try to find metatable with that name
+ // Pop nil from the stack
+ lua_pop( L, 1 ); // -1 | +0 -> -1
+ luaL_getmetatable( L, LuaTableName ); // -0 | +1 -> +1
+ }
+ CheckType( L, -1, LUA_TTABLE );
+ lua_pushstring( L, LuaFunctionName ); // -0 | +1 -> +1
+ lua_pushlightuserdata( L, pOwner ); // -0 | +1 -> +1
+ lua_pushlightuserdata( L, this ); // -0 | +1 -> +1
+ lua_pushcclosure( L, LuaEntry, 2 ); // -2 | +0 -> -2
+ lua_settable( L, -3 ); // -1 | +0 -> -1
+ // Pop table
+ lua_pop( L, 1 ); // -1 | +0 -> -1
+
+ CHECK_LUA_STACK_HEIGHT();
+ };
+
+ private:
+ MemberFunctionType m_MemberFunction;
+
+ static int LuaEntry( lua_State *L )
+ {
+ auto pOwner = static_cast<OwnerClassType*>(lua_touserdata( L, lua_upvalueindex( 1 ) ));
+ VERIFY( pOwner, "Owner pointer is null" );
+
+ auto pThis = static_cast<ClassMethodCaller*>(lua_touserdata( L, lua_upvalueindex( 2 ) ));
+ VERIFY( pThis, "This pointer is null" );
+
+ if( pOwner && pThis )
+ {
+ auto MemberFunction = pThis->m_MemberFunction;
+
+ // A C function returns an integer with the number of values it is returning in Lua.
+ // Therefore, the function does not need to clear the stack before pushing its results.
+ // After it returns, Lua automatically removes whatever is in the stack below the results.
+ return (pOwner->*MemberFunction)(L);
+ }
+ else
+ return 0;
+ }
+ };
+}
diff --git a/RenderScript/include/ConvenienceFunctions.h b/RenderScript/include/ConvenienceFunctions.h
new file mode 100644
index 0000000..2a4df13
--- /dev/null
+++ b/RenderScript/include/ConvenienceFunctions.h
@@ -0,0 +1,84 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "Errors.h"
+#include "FileWrapper.h"
+#include "ScriptParser.h"
+#include "DataBlobImpl.h"
+#ifdef _WIN32
+# define NOMINMAX
+# include <Windows.h>
+#endif
+
+inline void SetGlobalVarsStub( Diligent::ScriptParser * ){}
+
+template<typename TSetGlobalVars>
+Diligent::RefCntAutoPtr<Diligent::ScriptParser> CreateRenderScriptFromFile( const Diligent::Char *FilePath, Diligent::IRenderDevice *pRenderDevice, Diligent::IDeviceContext *pContext, TSetGlobalVars SetGlobalVars )
+{
+ bool bSuccess = true;
+ Diligent::RefCntAutoPtr<Diligent::ScriptParser> pScriptParser;
+#ifdef PLATFORM_WINDOWS
+ do
+ {
+#endif
+ std::string ErrorMsg;
+ bSuccess = true;
+ try
+ {
+ Diligent::FileWrapper ScriptFile(FilePath);
+ if( !ScriptFile )
+ LOG_ERROR_AND_THROW( "Failed to open Lua source file" );
+ Diligent::RefCntAutoPtr<Diligent::IDataBlob> pFileData( new Diligent::DataBlobImpl );
+ ScriptFile->Read( pFileData );
+
+ // Null-terminator is not read from the stream
+ pFileData->Resize(pFileData->GetSize() + 1);
+ auto *ScriptText = reinterpret_cast<char*>(pFileData->GetDataPtr());
+ ScriptText[pFileData->GetSize() - 1] = 0;
+
+ pScriptParser = new Diligent::ScriptParser( pRenderDevice );
+ pScriptParser->Parse( ScriptText );
+ SetGlobalVars( pScriptParser );
+ pScriptParser->Run( pContext );
+ }
+ catch( const std::runtime_error &err )
+ {
+ bSuccess = false;
+ ErrorMsg = err.what();
+ }
+
+#ifdef PLATFORM_WINDOWS
+ if( !bSuccess )
+ {
+ if( IDRETRY != MessageBoxA( NULL, "Failed to parse the script. Retry?", "Lua parser error", MB_ICONERROR | MB_ABORTRETRYIGNORE ) )
+ {
+ abort();
+ }
+ }
+ } while( !bSuccess );
+#endif
+
+ return pScriptParser;
+}
diff --git a/RenderScript/include/Debug.h b/RenderScript/include/Debug.h
new file mode 100644
index 0000000..bd22bfb
--- /dev/null
+++ b/RenderScript/include/Debug.h
@@ -0,0 +1,63 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#ifdef _DEBUG
+
+class LuaStackHeightTracker
+{
+public:
+ LuaStackHeightTracker( lua_State *L ) :
+ m_L( L ),
+ m_StackTop(0)
+ {
+ Record();
+ }
+
+ void Record()
+ {
+ m_StackTop = lua_gettop( m_L );
+ }
+
+ void Check(int Adjustment = 0)
+ {
+ auto CurrHeight = lua_gettop( m_L );
+ VERIFY( CurrHeight == m_StackTop + Adjustment, "Unexpected stack height" );
+ }
+private:
+ lua_State *m_L;
+ int m_StackTop;
+};
+
+#define INIT_LUA_STACK_TRACKING(L) LuaStackHeightTracker LuaStackHeightTracker(L)
+#define RECORD_LUA_STACK_HEIGHT() LuaStackHeightTracker.Record()
+#define CHECK_LUA_STACK_HEIGHT(...) LuaStackHeightTracker.Check(__VA_ARGS__)
+
+#else
+
+#define INIT_LUA_STACK_TRACKING(L)
+#define RECORD_LUA_STACK_HEIGHT()
+#define CHECK_LUA_STACK_HEIGHT(...)
+
+#endif
diff --git a/RenderScript/include/DepthStencilStateParser.h b/RenderScript/include/DepthStencilStateParser.h
new file mode 100644
index 0000000..fb0f2cb
--- /dev/null
+++ b/RenderScript/include/DepthStencilStateParser.h
@@ -0,0 +1,52 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace Diligent
+{
+ class DepthStencilStateParser : public EngineObjectParserCommon<IDepthStencilState>
+ {
+ public:
+ DepthStencilStateParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* DepthStencilStateLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // DepthStencilStateDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<DepthStencilStateDesc> SDSSDescWrapper;
+
+ int SetDepthStencilState( lua_State *L );
+ ClassMethodCaller<DepthStencilStateParser> m_SetDepthStencilBinding;
+
+ ComparisonFuncEnumMapping m_CmpFuncEnumMapping;
+ };
+}
diff --git a/RenderScript/include/DeviceContextFuncBindings.h b/RenderScript/include/DeviceContextFuncBindings.h
new file mode 100644
index 0000000..bb2f880
--- /dev/null
+++ b/RenderScript/include/DeviceContextFuncBindings.h
@@ -0,0 +1,49 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "ClassMethodBinding.h"
+
+namespace Diligent
+{
+ class DeviceContextFuncBindings
+ {
+ public:
+ DeviceContextFuncBindings( IRenderDevice *pRenderDevice, lua_State *L, class TextureViewParser *pTexViewPasrser );
+
+ private:
+ int SetRenderTargets( lua_State * );
+ ClassMethodCaller<DeviceContextFuncBindings> m_SetRenderTargetsBinding;
+
+ int ClearRenderTarget( lua_State * );
+ ClassMethodCaller<DeviceContextFuncBindings> m_ClearRenderTargetBinding;
+
+ int ClearDepthStencil( lua_State * );
+ ClassMethodCaller<DeviceContextFuncBindings> m_ClearDepthStencilBinding;
+
+ String m_TexViewMetatableName;
+ };
+}
diff --git a/RenderScript/include/DrawAttribsParser.h b/RenderScript/include/DrawAttribsParser.h
new file mode 100644
index 0000000..0b855ac
--- /dev/null
+++ b/RenderScript/include/DrawAttribsParser.h
@@ -0,0 +1,63 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::PRIMITIVE_TOPOLOGY )
+}
+
+namespace Diligent
+{
+ class DrawAttribsParser : public EngineObjectParserBase
+ {
+ public:
+ DrawAttribsParser( class BufferParser *pBuffParser, IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* DrawAttribsLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+ virtual void DestroyObj( void *pData );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field );
+ virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
+ virtual void PushExistingObject( lua_State *L, const void *pObject );
+
+ private:
+ int Draw( lua_State * );
+ ClassMethodCaller<DrawAttribsParser> m_DrawBinding;
+
+ int DispatchCompute( lua_State * );
+ ClassMethodCaller<DrawAttribsParser> m_DispatchComputeBinding;
+
+ EnumMapping<PRIMITIVE_TOPOLOGY> m_PrimTopologyEnumMapping;
+ EnumMapping<VALUE_TYPE> m_ValueTypeEnumMapping;
+
+ String m_BufferMetatableName;
+ };
+}
diff --git a/RenderScript/include/EngineObjectParserBase.h b/RenderScript/include/EngineObjectParserBase.h
new file mode 100644
index 0000000..55c0baa
--- /dev/null
+++ b/RenderScript/include/EngineObjectParserBase.h
@@ -0,0 +1,62 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+
+namespace Diligent
+{
+ class EngineObjectParserBase
+ {
+ public:
+ EngineObjectParserBase( IRenderDevice *pRenderDevice, lua_State *L, const Char *LibName );
+ void PushObject( lua_State *L, const void *pData );
+ const String &GetMetatableName(){ return m_MetatableRegistryName; }
+
+ static IDeviceContext* LoadDeviceContextFromRegistry( lua_State *L );
+
+ protected:
+ void RegisterTable( lua_State *L );
+
+ static int LuaCreate( lua_State *L );
+ virtual void CreateObj( lua_State *L ) = 0;
+
+ static int LuaGC( lua_State *L );
+ virtual void DestroyObj( void *pData ) = 0;
+
+ static int LuaIndex( lua_State *L );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field ) = 0;
+
+ static int LuaNewIndex( lua_State *L );
+ virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
+
+ virtual void PushExistingObject( lua_State *L, const void *pObject ) = 0;
+
+ Diligent::RefCntAutoPtr<IRenderDevice> m_pRenderDevice;
+ BindingsMapType m_Bindings;
+ const String m_LibName;
+ const String m_MetatableRegistryName;
+ };
+}
diff --git a/RenderScript/include/EngineObjectParserCommon.h b/RenderScript/include/EngineObjectParserCommon.h
new file mode 100644
index 0000000..ba55e21
--- /dev/null
+++ b/RenderScript/include/EngineObjectParserCommon.h
@@ -0,0 +1,70 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "EngineObjectParserBase.h"
+
+namespace Diligent
+{
+ template<typename ObjectType>
+ class EngineObjectParserCommon : public EngineObjectParserBase
+ {
+ public:
+ EngineObjectParserCommon( IRenderDevice *pRenderDevice, lua_State *L, const Char *LibName ) :
+ EngineObjectParserBase( pRenderDevice, L, LibName )
+ {}
+
+ virtual void GetObjectByName( lua_State *L, const Char *ShaderName, ObjectType** ppObject )
+ {
+ auto pObject = *GetGlobalObject<ObjectType**>( L, ShaderName, m_MetatableRegistryName.c_str() );
+ *ppObject = pObject;
+ pObject->AddRef();
+ }
+
+ protected:
+ virtual void PushExistingObject( lua_State *L, const void *pObject )
+ {
+ auto ppObject = reinterpret_cast<ObjectType**>(lua_newuserdata( L, sizeof( ObjectType* ) ));
+ *ppObject = reinterpret_cast<ObjectType*>(const_cast<void*>(pObject));
+ (*ppObject)->AddRef();
+ }
+
+ virtual void DestroyObj( void *pData )
+ {
+ if( pData != nullptr )
+ {
+ auto ppObject = reinterpret_cast<ObjectType**>(pData);
+ if( *ppObject != nullptr )
+ (*ppObject)->Release();
+ }
+ }
+
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field )
+ {
+ auto pObject = *reinterpret_cast<ObjectType**>(pData);
+ const auto &Desc = pObject->GetDesc();
+ PushField( L, &Desc, Field, m_Bindings );
+ }
+ };
+}
diff --git a/RenderScript/include/EnumMappings.h b/RenderScript/include/EnumMappings.h
new file mode 100644
index 0000000..6b61161
--- /dev/null
+++ b/RenderScript/include/EnumMappings.h
@@ -0,0 +1,108 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "HashUtils.h"
+
+#define DEFINE_ENUM_HASH(Type)\
+template<>struct hash<Type> \
+{ \
+ size_t operator()( const Type &x ) const \
+ { \
+ return hash<int>()(x); \
+ } \
+};
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::TEXTURE_TYPE )
+ DEFINE_ENUM_HASH( Diligent::TEXTURE_FORMAT )
+ DEFINE_ENUM_HASH( Diligent::VALUE_TYPE )
+ DEFINE_ENUM_HASH( Diligent::USAGE )
+ // Explicit namespace declaraion is necesseary to avoid
+ // name conflicts when building for windows store
+ DEFINE_ENUM_HASH( Diligent::BIND_FLAGS )
+ DEFINE_ENUM_HASH( Diligent::CPU_ACCESS_FLAG )
+ DEFINE_ENUM_HASH( Diligent::COMPARISON_FUNCTION )
+ DEFINE_ENUM_HASH( Diligent::BIND_SHADER_RESOURCES_FLAGS )
+}
+
+namespace Diligent
+{
+ template<typename EnumType>
+ struct EnumMapping
+ {
+ void AddMapping( const Char *Str, EnumType Val )
+ {
+ m_Str2ValMap.insert( std::make_pair( Diligent::HashMapStringKey(Str, true), Val ) );
+ m_Val2StrMap.insert( std::make_pair( Val, Str ) );
+ }
+
+ std::unordered_map< Diligent::HashMapStringKey, EnumType> m_Str2ValMap;
+ std::unordered_map<EnumType, String> m_Val2StrMap;
+ };
+#define DEFINE_ENUM_ELEMENT_MAPPING(EnumMapping, Elem) EnumMapping.AddMapping(#Elem, Elem)
+
+ class CpuAccessFlagEnumMapping : public EnumMapping < Diligent::CPU_ACCESS_FLAG >
+ {
+ public:
+ CpuAccessFlagEnumMapping();
+ };
+
+ class UsageEnumMapping : public EnumMapping < Diligent::USAGE >
+ {
+ public:
+ UsageEnumMapping();
+ };
+
+ class TextureFormatEnumMapping : public EnumMapping < Diligent::TEXTURE_FORMAT >
+ {
+ public:
+ TextureFormatEnumMapping();
+ };
+
+ class TextureTypeEnumMapping : public EnumMapping < Diligent::TEXTURE_TYPE >
+ {
+ public:
+ TextureTypeEnumMapping();
+ };
+
+ class ValueTypeEnumMapping : public EnumMapping < Diligent::VALUE_TYPE >
+ {
+ public:
+ ValueTypeEnumMapping();
+ };
+
+ class ComparisonFuncEnumMapping : public EnumMapping < Diligent::COMPARISON_FUNCTION >
+ {
+ public:
+ ComparisonFuncEnumMapping();
+ };
+
+ class BindShaderResourcesFlagEnumMapping : public EnumMapping < Diligent::BIND_SHADER_RESOURCES_FLAGS >
+ {
+ public:
+ BindShaderResourcesFlagEnumMapping();
+ };
+}
diff --git a/RenderScript/include/LayoutDescParser.h b/RenderScript/include/LayoutDescParser.h
new file mode 100644
index 0000000..62d32dd
--- /dev/null
+++ b/RenderScript/include/LayoutDescParser.h
@@ -0,0 +1,55 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace Diligent
+{
+ class LayoutDescParser : public EngineObjectParserCommon<IVertexDescription>
+ {
+ public:
+ LayoutDescParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* LayoutDescLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // LayoutDesc structure does not provide storage for the Name field,
+ // nor does it provide storage for layout elements.
+ // We need to use LayoutDescWrapper to be able to store the data.
+ struct LayoutDescWrapper : ObjectDescWrapper < LayoutDesc >
+ {
+ std::vector<LayoutElement> ElementsBuffer;
+ };
+
+
+ int SetInputLayout( lua_State *L );
+ ClassMethodCaller<LayoutDescParser> m_SetInputLayoutBinding;
+ };
+}
diff --git a/RenderScript/include/LuaBindings.h b/RenderScript/include/LuaBindings.h
new file mode 100644
index 0000000..b9dcace
--- /dev/null
+++ b/RenderScript/include/LuaBindings.h
@@ -0,0 +1,662 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+#include "EnumMappings.h"
+
+namespace Diligent
+{
+ template< typename ValueType>
+ ValueType ReadValueFromLua( lua_State *L, int Index )
+ {
+ UNSUPPORTED( "Type is not supported" );
+ return static_cast<ValueType>(0);
+ }
+ template<>int ReadValueFromLua<int>( lua_State *L, int Index );
+ template<>double ReadValueFromLua<double>( lua_State *L, int Index );
+ template<>float ReadValueFromLua<float>( lua_State *L, int Index );
+ template<>String ReadValueFromLua<String>( lua_State *L, int Index );
+ template<>const Char* ReadValueFromLua<const Char*>( lua_State *L, int Index );
+ template<>Bool ReadValueFromLua<Bool>( lua_State *L, int Index );
+ template<>Uint32 ReadValueFromLua<Uint32>( lua_State *L, int Index );
+ template<>Uint8 ReadValueFromLua<Uint8>( lua_State *L, int Index );
+
+
+ inline void CheckType( lua_State *L, int Index, int ExpectedType )
+ {
+ auto Type = lua_type( L, Index );
+ if( Type != ExpectedType )
+ {
+ auto TypeName = lua_typename( L, Type );
+ auto ExpectedTypeName = lua_typename( L, ExpectedType );
+ auto Param = lua_tostring( L, Index );
+ SCRIPT_PARSING_ERROR( L, "Incorrect argument: \"", Param ? Param : "<Unknown>", "\". \"", ExpectedTypeName, "\" is expected, while \"", TypeName, "\" is provided." );
+ }
+ }
+
+ // Special version of luaL_testudata() which takes an array of allowed metatables
+ void *luaL_testudata( lua_State *L, int ud, const std::vector<String> &MetatableNames );
+
+ template<typename DataType, typename MetatableNameType>
+ DataType GetUserData( lua_State *L, int Index, MetatableNameType MetatableName )
+ {
+ CheckType( L, Index, LUA_TUSERDATA );
+ auto pUserData = luaL_testudata( L, Index, MetatableName );
+ if( pUserData == nullptr )
+ {
+ auto Type = lua_type( L, Index );
+ auto TypeName = lua_typename( L, Type );
+ SCRIPT_PARSING_ERROR( L, "Bad argument #", Index, ". User data with metatable \"", MetatableName, "\" is expected. \"", TypeName, "\" is provided." );
+ }
+ return reinterpret_cast<DataType>(pUserData);
+ }
+
+ template<typename DataType>
+ DataType GetGlobalObject( lua_State *L, const Char* ObjectName, const Char* MetatableName )
+ {
+ INIT_LUA_STACK_TRACKING( L );
+ // Pushes onto the stack the value of the given global name
+ lua_getglobal( L, ObjectName ); // -0 | +1 -> +1
+ auto pData = GetUserData<DataType>( L, -1, MetatableName ); // -0 | +0 -> 0
+ lua_pop( L, 1 ); // -1 | +0 -> -1
+ CHECK_LUA_STACK_HEIGHT();
+ return pData;
+ }
+
+
+
+ template<typename Type>
+ void PushValue( lua_State *L, Type )
+ {
+ UNSUPPORTED( "Type is not supported" );
+ }
+ // Forward declarations of template specializations
+ template<> void PushValue<double>( lua_State *L, double Val );
+ template<> void PushValue<const float&>( lua_State *L, const float& Val );
+ template<> void PushValue<const Int32&>( lua_State *L, const Int32& Val );
+ template<> void PushValue<const Uint32&>( lua_State *L, const Uint32& Val );
+ template<> void PushValue<const Uint8&>( lua_State *L, const Uint8& Val );
+ template<> void PushValue<const Char*>( lua_State *L, const Char* Val );
+ template<> void PushValue<const Char* const&>( lua_State *L, const Char* const& Val );
+ template<> void PushValue<const String&>( lua_State *L, const String& Val );
+ template<> void PushValue<bool>( lua_State *L, bool Val );
+ template<> void PushValue<const bool &>( lua_State *L, const bool &Val );
+
+
+ class MemberBinderBase
+ {
+ public:
+ MemberBinderBase( size_t MemberOffset ) :
+ m_MemberOffset( MemberOffset )
+ {}
+ virtual ~MemberBinderBase(){}
+ virtual void GetValue( lua_State *L, const void* pBasePointer ) = 0;
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer ) = 0;
+
+ protected:
+ const size_t m_MemberOffset;
+ };
+ typedef std::unordered_map<Diligent::HashMapStringKey, std::unique_ptr<MemberBinderBase> > BindingsMapType;
+
+#define DEFINE_BINDER(BindingsMap, Struct, Member, type, ValidationFunc) \
+ {\
+ auto *pNewBinder = new MemberBinder<type>( offsetof( Struct, Member ), ValidationFunc ); \
+ /* No need to make a copy of #Member since it is constant string. */ \
+ /* HashMapStringKey will simply keep pointer to it */ \
+ BindingsMap.insert( std::make_pair( #Member, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
+ }
+
+ template<typename ValueType>
+ void SkipValidationFunc( const ValueType & )
+ {
+ // Do nothing
+ }
+
+ template<typename ValueType>
+ class Validator
+ {
+ public:
+ typedef void( *ValidationFuncType )(const ValueType &);
+ Validator( const char *pParameterName, ValueType MinValue, ValueType MaxValue ) :
+ m_pParameterName( pParameterName ),
+ m_MinValue( MinValue ),
+ m_MaxValue( MaxValue ),
+ m_ValidationFunc( nullptr )
+ {}
+
+ Validator( ValidationFuncType ValidationFunc = SkipValidationFunc<ValueType> ) :
+ m_pParameterName( nullptr ),
+ m_MinValue( ValueType() ),
+ m_MaxValue( ValueType() ),
+ m_ValidationFunc( ValidationFunc )
+ {}
+
+ void SetParameterName( const char *NewName ){ m_pParameterName = NewName; }
+
+ void operator()( lua_State *L, const ValueType &Value )const
+ {
+ if( m_ValidationFunc )
+ {
+ m_ValidationFunc( Value );
+ }
+ else
+ {
+ if( Value < m_MinValue || Value > m_MaxValue )
+ {
+ SCRIPT_PARSING_ERROR( L, "Parameter '", m_pParameterName, "' (", Value, ") is out of range [", m_MinValue, ",", m_MaxValue, "]\n" );
+ }
+ }
+ }
+
+ private:
+ const char *m_pParameterName;
+ ValueType m_MinValue, m_MaxValue;
+ ValidationFuncType m_ValidationFunc;
+ };
+
+ template<>
+ class Validator < Bool >
+ {
+ public:
+ void operator()( lua_State *L, const Bool & )const
+ {
+ // Do nothing
+ }
+ };
+
+ template<typename MemberType>
+ MemberType& GetMemberByOffest( void* pBasePointer, size_t Offset )
+ {
+ return *(reinterpret_cast<MemberType*>(reinterpret_cast<char*>(pBasePointer)+Offset));
+ }
+
+ template<typename MemberType>
+ const MemberType& GetMemberByOffest( const void* pBasePointer, size_t Offset )
+ {
+ return *(reinterpret_cast<const MemberType*>(reinterpret_cast<const char*>(pBasePointer)+Offset));
+ }
+
+ template<typename MemberType>
+ class MemberBinder : public MemberBinderBase
+ {
+ public:
+ MemberBinder( size_t MemberOffset, Validator<MemberType> Validator ) :
+ MemberBinderBase( MemberOffset ),
+ m_Validator( Validator )
+ {}
+
+ virtual void GetValue( lua_State *L, const void* pBasePointer )
+ {
+ const auto &Value = GetMemberByOffest<MemberType>(pBasePointer, m_MemberOffset);
+ PushValue<const MemberType &>( L, Value );
+ }
+
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
+ {
+ auto Value = ReadValueFromLua<MemberType>( L, Index );
+ m_Validator( L, Value );
+ GetMemberByOffest<MemberType>( pBasePointer, m_MemberOffset ) = Value;
+ }
+ protected:
+ Validator<MemberType> m_Validator;
+ };
+
+
+ inline void ParseLuaTable( lua_State *L, int Index, void* pBasePointer, BindingsMapType &Bindings )
+ {
+ CheckType( L, Index, LUA_TTABLE );
+
+ lua_pushnil( L ); // first key which will be popped out in the first call to lua_next()
+ // lua_next() pops a key from the stack, and pushes a key–value pair from the table at the given index
+ // (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns
+ // 0 (and pushes nothing).
+ if( Index < 0 )
+ --Index;
+ while( lua_next( L, Index ) != 0 )
+ {
+ // Key is now at index -2 and Value is at index -1
+ auto IsString = lua_isstring( L, -2 );
+ if( !IsString )
+ {
+ SCRIPT_PARSING_ERROR( L, "Table key value must be string")
+ }
+ // NOTE: the lua_tostring function returns a pointer to an internal copy of the string.
+ // The string is always zero-terminated and Lua ensures that this pointer is valid as long
+ // as the corresponding value is in the stack.
+ auto Key = lua_tostring( L, -2 );
+ auto Binding = Bindings.find( Key );
+ if( Binding != Bindings.end() )
+ {
+ Binding->second->SetValue( L, -1, pBasePointer );
+ }
+ else
+ {
+ SCRIPT_PARSING_ERROR( L, "Unknown Member ", Key );
+ }
+ // Pop value from the stack, but KEEP Key for the next iteration
+ lua_pop( L, 1 );
+ }
+ }
+
+ template<class ArrayElemParser>
+ inline void ParseLuaArray( lua_State *L, int Index, void* pBasePointer, ArrayElemParser ElemParser )
+ {
+ CheckType( L, Index, LUA_TTABLE );
+
+ lua_pushnil( L ); // first key which will be popped out in the first call to lua_next()
+ // lua_next() pops a key from the stack, and pushes a key–value pair from the table at the given index
+ // (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns
+ // 0 (and pushes nothing).
+ if( Index < 0 )
+ --Index;
+ while( lua_next( L, Index ) != 0 )
+ {
+ // Key is now at index -2 and Value is at index -1
+ CheckType( L, -2, LUA_TNUMBER );
+
+ auto NewArrayIndex = static_cast<int>( lua_tointeger( L, -2 ) );
+ ElemParser( pBasePointer, -1, NewArrayIndex );
+
+ // Pop value from the stack, but KEEP Key for the next iteration
+ lua_pop( L, 1 );
+ }
+ }
+
+ inline void PushLuaTable( lua_State *L, const void* pBasePointer, BindingsMapType &Bindings )
+ {
+ lua_newtable( L );
+ for( auto it = Bindings.begin(); it != Bindings.end(); ++it )
+ {
+ const auto &Field = it->first.GetStr();
+ lua_pushstring( L, Field );
+ it->second->GetValue( L, pBasePointer );
+ lua_settable( L, -3 ); // Stack: 0
+ }
+ }
+
+ template<typename ItType, class ElemPushAlg>
+ void PushLuaArray( lua_State *L, ItType Begin, ItType End, ElemPushAlg PushAlg )
+ {
+ lua_newtable( L );
+ int ArrayInd = 1; // Lua arrays are 1-based
+ for( auto it = Begin; it != End; ++it, ++ArrayInd )
+ {
+ lua_pushnumber( L, ArrayInd ); // -0 | +1 -> +1
+ PushAlg( *it ); // -0 | +1 -> +1
+ lua_settable( L, -3 ); // -2 | +0 -> -2
+ }
+ }
+
+ template<typename ArrayType, class ElemPushAlg>
+ void PushLuaArray( lua_State *L, const ArrayType& Arr, ElemPushAlg PushAlg )
+ {
+ PushLuaArray( L, Arr.begin(), Arr.end(), PushAlg );
+ }
+
+ inline void PushField( lua_State *L, const void* pBasePointer, const Char *Field, BindingsMapType &Bindings )
+ {
+ auto It = Bindings.find( Field );
+ if( It != Bindings.end() )
+ {
+ It->second->GetValue( L, pBasePointer );
+ }
+ else
+ {
+ SCRIPT_PARSING_ERROR( L, "Unknown Member ", Field );
+ }
+ }
+
+ inline void UpdateField( lua_State *L, int Index, void* pBasePointer, const Char *Field, BindingsMapType &Bindings )
+ {
+ auto It = Bindings.find( Field );
+ if( It != Bindings.end() )
+ {
+ It->second->SetValue( L, Index, pBasePointer );
+ }
+ else
+ {
+ SCRIPT_PARSING_ERROR( L, "Unknown Member ", Field );
+ }
+ }
+
+ class RGBALoader; // Used only as a template switch
+ template<>
+ class MemberBinder<RGBALoader> : public MemberBinderBase
+ {
+ public:
+ MemberBinder( size_t MemberOffset, size_t Dummy ) :
+ MemberBinderBase( MemberOffset )
+ {
+ const char* Members[] = { "r", "g", "b", "a" };
+ for( int c = 0; c < 4; ++c )
+ {
+ auto *pNewBinder = new MemberBinder<Float32>( MemberOffset + sizeof( Float32 )*c, Validator<float>() );
+ // No need to make a copy of Members[c] since it is constant string.
+ // HashMapStringKey will simply keep pointer to it
+ Bindings.insert( std::make_pair( Members[c], std::unique_ptr<MemberBinderBase>( pNewBinder ) ) );
+ }
+ }
+ virtual void GetValue( lua_State *L, const void* pBasePointer )
+ {
+ PushLuaTable( L, pBasePointer, Bindings );
+ }
+
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
+ {
+ ParseLuaTable( L, Index, pBasePointer, Bindings );
+ }
+ private:
+ BindingsMapType Bindings;
+ };
+
+
+ template< typename EnumType >
+ String GetEnumMappingsString( const EnumMapping<EnumType> &EnumMapping )
+ {
+ String Values;
+ bool bFirst = true;
+ for( auto it = EnumMapping.m_Str2ValMap.begin(); it != EnumMapping.m_Str2ValMap.end(); ++it )
+ {
+ if( !bFirst )
+ Values += ", ";
+ Values += '\"';
+ Values.append( it->first.GetStr() );
+ Values += '\"';
+ bFirst = false;
+ }
+ return Values;
+ }
+
+ template<typename EnumType>
+ class EnumMemberBinder : public MemberBinderBase
+ {
+ public:
+ EnumMemberBinder( size_t MemberOffset, const Char* MemberName, const EnumMapping<EnumType> &EnumMapping ) :
+ MemberBinderBase( MemberOffset ),
+ m_MemberName( MemberName ),
+ m_EnumMapping( EnumMapping )
+ {
+ }
+
+ virtual void GetValue( lua_State *L, const void* pBasePointer )
+ {
+ const auto &Val = GetMemberByOffest<EnumType>( pBasePointer, m_MemberOffset );
+ auto It = m_EnumMapping.m_Val2StrMap.find( Val );
+ if( It != m_EnumMapping.m_Val2StrMap.end() )
+ {
+ const String& StrVal = It->second;
+ PushValue<const String&>( L, StrVal );
+ }
+ else
+ {
+ UNEXPECTED( "Enum value not found in the map" );
+ SCRIPT_PARSING_ERROR( L, "Enum value (", Val, ") not found in the map" );
+ }
+ }
+
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
+ {
+ auto Str = ReadValueFromLua<String>( L, Index );
+ auto It = m_EnumMapping.m_Str2ValMap.find( Str.c_str() );
+ if( It != m_EnumMapping.m_Str2ValMap.end() )
+ {
+ auto Val = It->second;
+ GetMemberByOffest<EnumType>(pBasePointer, m_MemberOffset) = Val;
+ }
+ else
+ {
+ String AllowableValues = GetEnumMappingsString<EnumType>( m_EnumMapping );
+ SCRIPT_PARSING_ERROR( L, "Unknown value (\"", Str, "\") provided for parameter ", m_MemberName, ". Only the following values are allowed:\n", AllowableValues );
+ }
+ }
+
+ private:
+ const Char *m_MemberName;
+ const EnumMapping<EnumType> &m_EnumMapping;
+ };
+
+#define DEFINE_ENUM_BINDER(BindingsMap, Struct, Member, type, EnumMapping ) \
+ {\
+ auto *pNewBinder = new EnumMemberBinder<type>( offsetof( Struct, Member ), #Member, EnumMapping ); \
+ /* No need to make a copy of #Member since it is constant string. */ \
+ /* HashMapStringKey will simply keep pointer to it */ \
+ BindingsMap.insert( std::make_pair( #Member, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
+ }
+
+ template< typename EnumType, typename FlagsType = Uint32 >
+ class FlagsLoader : public MemberBinderBase
+ {
+ public:
+ FlagsLoader( size_t MemberOffset, const Char* MemberName, const EnumMapping<EnumType> &EnumMapping ) :
+ MemberBinderBase( MemberOffset ),
+ m_MemberName( MemberName ),
+ m_EnumMapping( EnumMapping )
+ {
+ }
+ virtual void GetValue( lua_State *L, const void* pBasePointer )
+ {
+ auto Flags = GetMemberByOffest<FlagsType>( pBasePointer, m_MemberOffset );
+ lua_newtable( L );
+ int ArrayInd = 1;
+ for( auto it = m_EnumMapping.m_Val2StrMap.begin(); it != m_EnumMapping.m_Val2StrMap.end(); ++it )
+ {
+ if( (Flags & it->first) == it->first )
+ {
+ lua_pushnumber( L, ArrayInd ); // -0 | +1 -> +1
+ PushValue<const String&>( L, it->second ); // -0 | +1 -> +1
+ lua_settable( L, -3 ); // -2 | +0 -> -2
+ ++ArrayInd;
+ }
+ }
+ }
+
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
+ {
+ FlagsType Flags = 0;
+ if( lua_isnumber( L, Index ) )
+ {
+ Flags = static_cast<FlagsType>( ReadValueFromLua<Uint32>( L, Index ) );
+ }
+ else if( lua_isstring( L, Index ) )
+ {
+ Flags = ReadFlag( L, Index );
+ }
+ else if( lua_istable( L, Index ) )
+ {
+ ParseLuaArray( L, Index, pBasePointer, [ &]( void* _pBasePointer, int StackIndex, int NewArrayIndex )
+ {
+ auto CurrFlag = ReadFlag( L, StackIndex );
+ Flags |= CurrFlag;
+ }
+ );
+ }
+ else
+ {
+ SCRIPT_PARSING_ERROR( L, m_MemberName, "must be specified as a single string or an array of strings." );
+ }
+ GetMemberByOffest<FlagsType>( pBasePointer, m_MemberOffset ) = Flags;
+ }
+
+ private:
+ FlagsType ReadFlag( lua_State *L, int StackIndex )
+ {
+ auto CurrFlagName = ReadValueFromLua<const Char *>( L, StackIndex );
+ auto It = m_EnumMapping.m_Str2ValMap.find( CurrFlagName );
+ if( It != m_EnumMapping.m_Str2ValMap.end() )
+ {
+ return It->second;
+ }
+ else
+ {
+ String AllowableValues = GetEnumMappingsString<EnumType>( m_EnumMapping );
+ SCRIPT_PARSING_ERROR( L, "Unknown flag (\"", CurrFlagName, "\") provided for parameter ", m_MemberName, ". Only the following flags are allowed:\n", AllowableValues );
+ return 0;
+ }
+ }
+
+ const Char *m_MemberName;
+ const EnumMapping<EnumType> &m_EnumMapping;
+ };
+#define DEFINE_FLAGS_BINDER(BindingsMap, Struct, Member, type, EnumMapping ) \
+ {\
+ auto *pNewBinder = new FlagsLoader<type>( offsetof( Struct, Member ), #Member, EnumMapping ); \
+ /* No need to make a copy of #Member since it is constant string. */ \
+ /* HashMapStringKey will simply keep pointer to it */ \
+ BindingsMap.insert( std::make_pair( #Member, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
+ }
+
+
+ template<typename FieldType>
+ void SetTableField( lua_State *L, const char *FieldName, int TableStackIndex, FieldType Value )
+ {
+ INIT_LUA_STACK_TRACKING( L );
+
+ lua_pushstring( L, FieldName ); // -0 | +1 -> +1
+ PushValue<FieldType>( L, Value ); // -0 | +1 -> +1
+
+ // lua_settable() does the equivalent to t[k] = v, where t is the value at the given index,
+ // v is the value at the top of the stack (-1), and k is the value just below the top (-2)
+ // The function pops both the key and the value from the stack. As in Lua, this function may
+ // trigger a metamethod for the "newindex" event
+ lua_settable( L, TableStackIndex - 2 ); // -2 | +0 -> -2
+
+ CHECK_LUA_STACK_HEIGHT();
+ }
+
+ class NumericArrayLoader
+ {
+ public:
+ NumericArrayLoader();
+ void LoadArray( lua_State *L, int StackIndex, std::vector< Uint8 >& RawData );
+ private:
+ EnumMapping<VALUE_TYPE> m_ValueTypeEnumMapping;
+ EnumMemberBinder<VALUE_TYPE> m_ValueTypeBinder;
+ typedef void (*ParseNumericArrayFuncType)(lua_State *L, int StackIndex, std::vector< Uint8 >& RawData);
+ std::unordered_map< VALUE_TYPE, ParseNumericArrayFuncType > m_ParseFuncJumpTbl;
+ };
+
+
+ template<typename EngineObjectType>
+ class EngineObjectPtrLoader
+ {
+ public:
+ typedef EngineObjectType ObjectType;
+ };
+
+ template<typename EngineObjectType>
+ class MemberBinder< EngineObjectPtrLoader<EngineObjectType> > : public MemberBinderBase
+ {
+ public:
+ typedef typename EngineObjectPtrLoader<EngineObjectType>::ObjectType ObjectType;
+
+ MemberBinder( size_t MemberOffset, const std::vector<String> &_Metatables ) :
+ MemberBinderBase( MemberOffset ),
+ Metatables( _Metatables )
+ {
+ }
+
+ virtual void GetValue( lua_State *L, const void* pBasePointer )
+ {
+ VERIFY( Metatables.size() == 1, "Ambiguous metatable" );
+ const auto& MetatableName = *Metatables.begin();
+ auto pObject = GetMemberByOffest<ObjectType*>( pBasePointer, m_MemberOffset );
+ auto ppNewObject = reinterpret_cast<ObjectType**>(lua_newuserdata( L, sizeof( ObjectType* ) ));
+ *ppNewObject = pObject;
+ pObject->AddRef();
+ // Push onto the stack the metatable associated with name given in the registry
+ luaL_getmetatable( L, MetatableName.c_str() ); // -0 | +1 -> +1
+ // Pop a table from the top of the stack and set it as the new metatable
+ // for the value at the given index (which is where the new user datum is)
+ lua_setmetatable( L, -2 ); // -1 | +0 -> -1
+ }
+
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
+ {
+ ObjectType *pObject = nullptr;
+ pObject = *GetUserData<ObjectType**>( L, -1, Metatables );
+ GetMemberByOffest<ObjectType*>( pBasePointer, m_MemberOffset ) = pObject;
+ }
+ private:
+ BindingsMapType Bindings;
+ std::vector<String> Metatables;
+ };
+
+ // None of the graphics engine structures (such as BufferDesc or TextureDesc)
+ // provide storage for strings, but only contain const Char* pointers.
+ // The script wraps every such structure to provide the storage
+ // This binder handles such strings
+ class BufferedStringBinder : public MemberBinderBase
+ {
+ public:
+ BufferedStringBinder(
+ size_t StringPtrOffset, // This is the offset of the const Char* pointer
+ size_t StringBuffOffset // This is the offset of the buffer that contains string data
+ ) :
+ MemberBinderBase( StringBuffOffset ),
+ m_StringPtrOffset( StringPtrOffset )
+ {
+ }
+
+ virtual void GetValue( lua_State *L, const void* pBasePointer )
+ {
+ // Always use const Char* pointer to push value to Lua as there
+ // might be no valid buffer
+ auto *StringPtr = GetMemberByOffest<const Char*>( pBasePointer, m_StringPtrOffset );
+ PushValue<const Char*>( L, StringPtr );
+ }
+
+ virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
+ {
+ // When reading the string from Lua, we need to make
+ // sure that the string pointer contains the right data
+ auto SrcString = ReadValueFromLua<String>( L, Index );
+ // Set the const Char* pointer
+ auto &DstStrBuff = GetMemberByOffest<String>( pBasePointer, m_MemberOffset );
+ auto &DstStringPtr = GetMemberByOffest<const Char*>( pBasePointer, m_StringPtrOffset );
+ DstStrBuff = SrcString;
+ DstStringPtr = DstStrBuff.data();
+ }
+ protected:
+ size_t m_StringPtrOffset;
+ };
+
+#define DEFINE_BUFFERED_STRING_BINDER(BindingsMap, Struct, StringPtr, StringBuffer) \
+ {\
+ auto *pNewBinder = new BufferedStringBinder( offsetof( Struct, StringPtr ), offsetof( Struct, StringBuffer ) ); \
+ /* No need to make a copy of #Member since it is constant string. */ \
+ /* HashMapStringKey will simply keep pointer to it */ \
+ BindingsMap.insert( std::make_pair( #StringPtr, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
+ }
+
+ // Object description wrapper that provides storage for
+ // the Name field
+ template<typename ObjectDescType>
+ struct ObjectDescWrapper : ObjectDescType
+ {
+ String NameBuffer;
+ };
+}
diff --git a/RenderScript/include/LuaFunctionBinding.h b/RenderScript/include/LuaFunctionBinding.h
new file mode 100644
index 0000000..a51a7b9
--- /dev/null
+++ b/RenderScript/include/LuaFunctionBinding.h
@@ -0,0 +1,100 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+namespace Diligent
+{
+ class LuaFunctionCallerBase
+ {
+ public:
+ LuaFunctionCallerBase( lua_State *LuaState = nullptr ) :
+ m_LuaState( LuaState )
+ {
+ };
+
+ void SetLuaState( lua_State *LuaState )
+ {
+ m_LuaState = LuaState;
+ }
+
+ // We need these stubs to hide implementation details
+ void PushFuncStub( lua_State *L, Bool Arg );
+ void PushFuncStub( lua_State *L, Int32 Arg );
+ void PushFuncStub( lua_State *L, Uint32 Arg );
+ void PushFuncStub( lua_State *L, Int16 Arg );
+ void PushFuncStub( lua_State *L, Uint16 Arg );
+ void PushFuncStub( lua_State *L, Int8 Arg );
+ void PushFuncStub( lua_State *L, Uint8 Arg );
+ void PushFuncStub( lua_State *L, float Arg );
+ void PushFuncStub( lua_State *L, const Char *Arg );
+ void PushFuncStub( lua_State *L, const String &Arg );
+
+ protected:
+ void Run_internal( int NumArgs, const Char *FuncName );
+
+ lua_State *m_LuaState;
+ };
+
+ class DummyPushFuncs
+ {
+ public:
+ void PushFuncStub();
+ };
+
+ template<typename AdditionalPushFuncs = DummyPushFuncs>
+ class LuaFunctionCaller : public LuaFunctionCallerBase, public AdditionalPushFuncs
+ {
+ public:
+ void operator()()
+ {
+ operator()( nullptr );
+ }
+
+ template<typename... ArgsType>
+ void operator()( const Char *FuncName, const ArgsType&... Args )
+ {
+ Run_internal( 0, FuncName, Args... );
+ }
+
+ // We need to make visible these parent-class definitions here
+ using LuaFunctionCallerBase::PushFuncStub;
+ using LuaFunctionCallerBase::Run_internal;
+ using AdditionalPushFuncs::PushFuncStub;
+
+ protected:
+ template<typename ArgType>
+ void Run_internal( int NumArgs, const Char *FuncName, const ArgType &Arg )
+ {
+ PushFuncStub( m_LuaState, Arg );
+ Run_internal( NumArgs + 1, FuncName );
+ }
+
+ template<typename ArgType, typename... RestArgsType>
+ void Run_internal( int NumArgs, const Char *FuncName, const ArgType &Arg, const RestArgsType&... RestArgs )
+ {
+ PushFuncStub( m_LuaState, Arg );
+ Run_internal( NumArgs + 1, FuncName, RestArgs... ); // recursive call using pack expansion syntax
+ }
+ };
+}
diff --git a/RenderScript/include/LuaWrappers.h b/RenderScript/include/LuaWrappers.h
new file mode 100644
index 0000000..6e17a65
--- /dev/null
+++ b/RenderScript/include/LuaWrappers.h
@@ -0,0 +1,59 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+#include "BasicTypes.h"
+
+namespace Diligent
+{
+ class LuaState
+ {
+ public:
+ enum
+ {
+ LUA_LIB_BASE = 0x001,
+ LUA_LIB_PACKAGE = 0x002,
+ LUA_LIB_COROUTINE = 0x004,
+ LUA_LIB_TABLE = 0x008,
+ LUA_LIB_IO = 0x010,
+ LUA_LIB_OS = 0x020,
+ LUA_LIB_STRING = 0x040,
+ LUA_LIB_BIT32 = 0x080,
+ LUA_LIB_MATH = 0x100,
+ LUA_LIB_DEBUG = 0x200
+ };
+ LuaState( Uint32 OpenLibFlags = static_cast<Uint32>(-1) );
+ ~LuaState();
+ void Close();
+
+ operator lua_State *();
+
+ private:
+ lua_State *m_pLuaState;
+ };
+
+} \ No newline at end of file
diff --git a/RenderScript/include/ParsingErrors.h b/RenderScript/include/ParsingErrors.h
new file mode 100644
index 0000000..5b7f860
--- /dev/null
+++ b/RenderScript/include/ParsingErrors.h
@@ -0,0 +1,51 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+template<typename SSType>
+SSType& operator << (SSType &ss, const std::vector<Diligent::String>& Arg )
+{
+ bool bIsFirst = true;
+ for( auto it = Arg.cbegin(); it != Arg.cend(); ++it )
+ {
+ if( !bIsFirst )
+ ss << ", ";
+ ss << *it;
+ bIsFirst = false;
+ }
+ return ss;
+}
+
+void LuaDebugInformation( lua_State *L, std::stringstream &ss );
+
+#define SCRIPT_PARSING_ERROR(L, ...) \
+{ \
+ std::stringstream ss; \
+ ss << '\n'; \
+ Diligent::FormatMsg( ss, ##__VA_ARGS__ ); \
+ ss << "\n\n"; \
+ LuaDebugInformation(L, ss); \
+ auto strFullMessage = ss.str(); \
+ luaL_error(L, strFullMessage.c_str());\
+}
diff --git a/RenderScript/include/RasterizerStateParser.h b/RenderScript/include/RasterizerStateParser.h
new file mode 100644
index 0000000..22ab5e9
--- /dev/null
+++ b/RenderScript/include/RasterizerStateParser.h
@@ -0,0 +1,60 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::FILL_MODE )
+ DEFINE_ENUM_HASH( Diligent::CULL_MODE )
+}
+
+namespace Diligent
+{
+ class RasterizerStateParser : public EngineObjectParserCommon<IRasterizerState>
+ {
+ public:
+ RasterizerStateParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* RasterizerStateLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // RasterizerStateDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<RasterizerStateDesc> SRSDescWrapper;
+
+ int SetRasterizerState( lua_State *L );
+ ClassMethodCaller<RasterizerStateParser> m_SetRasterizerBinding;
+
+ EnumMapping < FILL_MODE > m_FillModeEnumMapping;
+ EnumMapping < CULL_MODE > m_CullModeEnumMapping;
+ };
+}
diff --git a/RenderScript/include/ResourceMappingParser.h b/RenderScript/include/ResourceMappingParser.h
new file mode 100644
index 0000000..d191647
--- /dev/null
+++ b/RenderScript/include/ResourceMappingParser.h
@@ -0,0 +1,65 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserBase.h"
+#include "ClassMethodBinding.h"
+
+namespace Diligent
+{
+ class ResourceMappingParser : public EngineObjectParserBase
+ {
+ public:
+ ResourceMappingParser( IRenderDevice *pRenderDevice, lua_State *L,
+ class TextureViewParser *pTexViewParser,
+ class BufferParser *pBuffParser,
+ class BufferViewParser *pBuffViewParser );
+ virtual void GetObjectByName( lua_State *L, const Char *ShaderName, IResourceMapping** ppObject );
+
+ static const Char* ResourceMappingLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field );
+ virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
+
+ private:
+ virtual void PushExistingObject( lua_State *L, const void *pObject );
+ virtual void DestroyObj( void *pData );
+
+ int BindShaderResources( lua_State *L );
+ ClassMethodCaller < ResourceMappingParser > m_BindShaderResourcesBinding;
+
+ BindingsMapType m_Bindings;
+
+ TextureViewParser *m_pTexViewParser;
+ BufferParser *m_pBuffParser;
+ BufferViewParser *m_pBuffViewParser;
+ std::vector<String> m_MappedResourceMetatables;
+
+ BindShaderResourcesFlagEnumMapping m_BindShaderResFlagEnumMapping;
+ };
+}
diff --git a/RenderScript/include/SamplerParser.h b/RenderScript/include/SamplerParser.h
new file mode 100644
index 0000000..5829067
--- /dev/null
+++ b/RenderScript/include/SamplerParser.h
@@ -0,0 +1,58 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserBase.h"
+#include "ClassMethodBinding.h"
+#include "EngineObjectParserCommon.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::FILTER_TYPE )
+ DEFINE_ENUM_HASH( Diligent::TEXTURE_ADDRESS_MODE )
+}
+
+namespace Diligent
+{
+ class SamplerParser : public EngineObjectParserCommon<ISampler>
+ {
+ public:
+ SamplerParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* SamplerLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // SamplerDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<SamplerDesc> SSamDescWrapper;
+
+ EnumMapping<FILTER_TYPE> m_FilterTypeEnumMapping;
+ EnumMapping<TEXTURE_ADDRESS_MODE> m_TexAddrModeEnumMapping;
+ ComparisonFuncEnumMapping m_CmpFuncEnumMapping;
+ };
+}
diff --git a/RenderScript/include/ScissorRectParser.h b/RenderScript/include/ScissorRectParser.h
new file mode 100644
index 0000000..b887afc
--- /dev/null
+++ b/RenderScript/include/ScissorRectParser.h
@@ -0,0 +1,51 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace Diligent
+{
+ class ScissorRectParser : public EngineObjectParserBase
+ {
+ public:
+ ScissorRectParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* ScissorRectLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+ virtual void DestroyObj( void *pData );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field );
+ virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
+ virtual void PushExistingObject( lua_State *L, const void *pObject );
+
+ private:
+ int SetScissorRects( lua_State * );
+ ClassMethodCaller<ScissorRectParser> m_SetScissorRectsBinding;
+ std::vector<Rect> m_ScissorRects;
+ };
+}
diff --git a/RenderScript/include/ScriptParser.h b/RenderScript/include/ScriptParser.h
new file mode 100644
index 0000000..8c960d8
--- /dev/null
+++ b/RenderScript/include/ScriptParser.h
@@ -0,0 +1,151 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include <memory>
+#include "LuaWrappers.h"
+#include "LuaFunctionBinding.h"
+#include "RenderDevice.h"
+#include "DeviceContext.h"
+#include "RefCountedObjectImpl.h"
+#include "RefCntAutoPtr.h"
+
+namespace Diligent
+{
+ class ScriptParser : public Diligent::RefCountedObject<Diligent::IObject>
+ {
+ public:
+ ScriptParser( IRenderDevice *pRenderDevice );
+ ~ScriptParser();
+
+ virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
+
+ void Parse(const Char *pScript);
+
+ template<typename... ArgsType>
+ void Run(IDeviceContext *pContext, const ArgsType&... Args)
+ {
+ lua_pushstring( m_LuaState, DeviceContextRegistryKey ); // -0 | +1 -> +1
+ lua_pushlightuserdata( m_LuaState, pContext ); // -0 | +1 -> +1
+ lua_settable( m_LuaState, LUA_REGISTRYINDEX ); // -2 | +0 -> -2
+
+ m_RunFunctionCaller(Args...);
+ }
+ template<typename... ArgsType>
+ void Run( RefCntAutoPtr<IDeviceContext> &pContext, const ArgsType&... Args )
+ {
+ Run(pContext.RawPtr(), Args... );
+ }
+
+ template<typename... ArgsType>
+ void Run( const ArgsType&... Args )
+ {
+ Run( static_cast<IDeviceContext *>(nullptr), Args... );
+ }
+
+
+ void GetSamplerByName( const Char *SamplerName, ISampler** ppSampler );
+ void GetVertexDescriptionByName( const Char *VertDescName, IVertexDescription** ppVertDesc );
+ void GetShaderByName( const Char *ShaderName, IShader** ppShader );
+ void GetBufferByName( const Char *BufferName, IBuffer** ppBuffer );
+ void GetTextureByName( const Char *TextureName, ITexture** ppTexture );
+ void GetResourceMappingByName( const Char *ResourceMappingName, IResourceMapping** ppResourceMapping );
+ void GetTextureViewByName( const Char *TextureViewName, ITextureView** ppTextureView );
+ void GetBufferViewByName( const Char *BufferViewName, IBufferView** ppTextureView );
+ void GetDepthStencilStateByName( const Char *DSStateName, IDepthStencilState** ppDSState );
+ void GetRasterizerStateByName( const Char *RSName, IRasterizerState** ppRS );
+ void GetBlendStateByName( const Char *BSName, IBlendState** ppRS );
+ void GetShaderVariableByName( const Char *ShaderVarName, IShaderVariable** ppShaderVar );
+
+ template<typename ValType>
+ void SetGlobalVariable( const Char *Name, ValType Var )
+ {
+ m_RunFunctionCaller.PushFuncStub( m_LuaState, Var );
+ lua_setglobal( m_LuaState, Name );
+ }
+
+ static const Char* DeviceContextRegistryKey;
+
+ private:
+ class SpecialPushFuncs
+ {
+ public:
+ SpecialPushFuncs() : m_pScriptParser( nullptr ){}
+ void SetScriptParser( ScriptParser *pScriptParser ){ m_pScriptParser = pScriptParser; }
+
+ void PushFuncStub( lua_State *L, const ISampler* pSampler );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<ISampler> &pSampler );
+ void PushFuncStub( lua_State *L, const IVertexDescription* pVertDesc );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IVertexDescription> &pVertDesc );
+ void PushFuncStub( lua_State *L, const IShader* pShader );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShader> &pShader );
+ void PushFuncStub( lua_State *L, const IBuffer* pBuffer );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBuffer> &pBuffer );
+ void PushFuncStub( lua_State *L, const ITexture* pTexture );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<ITexture> &pTexture );
+ void PushFuncStub( lua_State *L, const DrawAttribs &DrawAttribs );
+ void PushFuncStub( lua_State *L, const IResourceMapping* pResourceMapping );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IResourceMapping> &pResourceMapping );
+ void PushFuncStub( lua_State *L, const ITextureView* pTextureView );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<ITextureView> &pTextureView );
+ void PushFuncStub( lua_State *L, const IBufferView* pBufferView );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBufferView> &pBufferView );
+ void PushFuncStub( lua_State *L, const IDepthStencilState* pDSState );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IDepthStencilState> &pDSState );
+ void PushFuncStub( lua_State *L, const IRasterizerState* pRS );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IRasterizerState> &pRS );
+ void PushFuncStub( lua_State *L, const IBlendState* pBS );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBlendState> &pBS );
+ void PushFuncStub( lua_State *L, const Viewport &Viewport );
+ void PushFuncStub( lua_State *L, const Rect &Rect );
+ void PushFuncStub( lua_State *L, const IShaderVariable* pShaderVar );
+ void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShaderVariable> &pShaderVar );
+
+ private:
+ ScriptParser *m_pScriptParser;
+ };
+ LuaFunctionCaller<SpecialPushFuncs> m_RunFunctionCaller;
+
+ void DefineGlobalConstants( lua_State *L );
+
+ Diligent::RefCntAutoPtr<IRenderDevice> m_pRenderDevice;
+ LuaState m_LuaState;
+ std::unique_ptr<class SamplerParser> m_pSamplerParser;
+ std::unique_ptr<class LayoutDescParser> m_pLayoutDescParser;
+ std::unique_ptr<class ShaderParser> m_pShaderParser;
+ std::unique_ptr<class BufferParser> m_pBufferParser;
+ std::unique_ptr<class TextureParser> m_pTextureParser;
+ std::unique_ptr<class DrawAttribsParser> m_pDrawAttribsParser;
+ std::unique_ptr<class ResourceMappingParser> m_pResourceMappingParser;
+ std::unique_ptr<class TextureViewParser> m_pTextureViewParser;
+ std::unique_ptr<class BufferViewParser> m_pBufferViewParser;
+ std::unique_ptr<class DepthStencilStateParser> m_pDSStateParser;
+ std::unique_ptr<class RasterizerStateParser> m_pRSParser;
+ std::unique_ptr<class BlendStateParser> m_pBSParser;
+ std::unique_ptr<class DeviceContextFuncBindings> m_pDeviceCtxFuncBindings;
+ std::unique_ptr<class ViewportParser> m_pViewportParser;
+ std::unique_ptr<class ScissorRectParser> m_pScissorRectParser;
+ std::unique_ptr<class ShaderVariableParser> m_pShaderVariableParser;
+ };
+}
diff --git a/RenderScript/include/ShaderParser.h b/RenderScript/include/ShaderParser.h
new file mode 100644
index 0000000..2967dd5
--- /dev/null
+++ b/RenderScript/include/ShaderParser.h
@@ -0,0 +1,74 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserBase.h"
+#include "ClassMethodBinding.h"
+#include "EngineObjectParserCommon.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::SHADER_SOURCE_LANGUAGE )
+}
+
+namespace Diligent
+{
+ class ShaderParser : public EngineObjectParserCommon<IShader>
+ {
+ public:
+ ShaderParser( IRenderDevice *pRenderDevice, lua_State *L, const String& ResMappingMetatableName);
+ static const Char* ShaderLibName;
+
+ // ShaderCreationAttribs structure does not provide storage for the Name field,
+ // nor does it provide storage for FilePath.
+ // We need to use ShaderCreationAttribsWrapper to be able to store the data.
+ struct ShaderCreationAttribsWrapper : ShaderCreationAttribs
+ {
+ String NameBuffer;
+ String FilePathBuffer;
+ String EntryPointBuffer;
+ String SearchDirectoriesBuffer;
+ };
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field );
+
+ private:
+
+ int SetShaders( lua_State *L );
+ ClassMethodCaller < ShaderParser > m_SetShadersBinding;
+
+ ClassMethodCaller< ShaderParser > m_BindResourcesBinding;
+ int BindResources( lua_State *L );
+
+ const String m_ResMappingMetatableName;
+
+ EnumMapping<SHADER_SOURCE_LANGUAGE> m_ShaderSourceLangEnumMapping;
+
+ BindShaderResourcesFlagEnumMapping m_BindShaderResFlagEnumMapping;
+ };
+}
diff --git a/RenderScript/include/ShaderVariableParser.h b/RenderScript/include/ShaderVariableParser.h
new file mode 100644
index 0000000..5263e16
--- /dev/null
+++ b/RenderScript/include/ShaderVariableParser.h
@@ -0,0 +1,65 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserBase.h"
+#include "ClassMethodBinding.h"
+#include "EngineObjectParserCommon.h"
+
+namespace Diligent
+{
+ class ShaderVariableParser : public EngineObjectParserBase
+ {
+ public:
+ ShaderVariableParser( IRenderDevice *pRenderDevice, lua_State *L,
+ const String &ShaderLibMetatableName,
+ const String &BufferLibMetatableName,
+ const String &BufferViewLibMetatableName,
+ const String &TexViewMetatableName );
+ static const Char* ShaderVariableLibName;
+
+ virtual void GetObjectByName( lua_State *L, const Char *ShaderName, IShaderVariable** ppObject );
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+ virtual void DestroyObj( void *pData );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field );
+ virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
+ virtual void PushExistingObject( lua_State *L, const void *pObject );
+
+ private:
+ const String m_ShaderLibMetatableName;
+ const String m_BufferLibMetatableName;
+ const String m_BufferViewLibMetatableName;
+ const String m_TexViewMetatableName;
+
+ int Set( lua_State *L );
+ ClassMethodCaller < ShaderVariableParser > m_SetBinding;
+
+ ClassMethodCaller<ShaderVariableParser> m_GetShaderVariableBinding;
+ int GetShaderVariable( lua_State *L );
+ };
+}
diff --git a/RenderScript/include/TextureParser.h b/RenderScript/include/TextureParser.h
new file mode 100644
index 0000000..d6eb6a0
--- /dev/null
+++ b/RenderScript/include/TextureParser.h
@@ -0,0 +1,66 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::MISC_TEXTURE_FLAG )
+}
+
+namespace Diligent
+{
+ class TextureParser : public EngineObjectParserCommon<ITexture>
+ {
+ public:
+ TextureParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* TextureLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // TextureDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<TextureDesc> STexDescWrapper;
+
+ TextureTypeEnumMapping m_TexTypeEnumMapping;
+ TextureFormatEnumMapping m_TexFormatEnumMapping;
+
+ // Note that different bind flags are allowed for different objects,
+ // so we need to populate this enum with values suitable for textures only
+ EnumMapping<Diligent::BIND_FLAGS> m_BindFlagEnumMapping;
+ // Explicit namespace declaraion is necesseary to avoid
+ // name conflicts when building for windows store
+
+ EnumMapping<Diligent::MISC_TEXTURE_FLAG> m_MiscFlagEnumMapping;
+
+ UsageEnumMapping m_UsageEnumMapping;
+ CpuAccessFlagEnumMapping m_CpuAccessFlagEnumMapping;
+ };
+}
diff --git a/RenderScript/include/TextureViewParser.h b/RenderScript/include/TextureViewParser.h
new file mode 100644
index 0000000..c97f28a
--- /dev/null
+++ b/RenderScript/include/TextureViewParser.h
@@ -0,0 +1,71 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace std
+{
+ DEFINE_ENUM_HASH( Diligent::TEXTURE_VIEW_TYPE )
+ DEFINE_ENUM_HASH( Diligent::UAV_ACCESS_FLAG )
+}
+
+namespace Diligent
+{
+ class TextureViewParser : public EngineObjectParserCommon<ITextureView>
+ {
+ public:
+ TextureViewParser( class TextureParser *pTexParser, class SamplerParser *pSamplerParser, IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char *TextureViewLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+
+ private:
+ // TextureViewDesc structure does not provide storage for the Name field.
+ // We need to use ObjectDescWrapper<> to be able to store the field.
+ typedef ObjectDescWrapper<TextureViewDesc> STexViewDescWrapper;
+
+ const String m_TextureLibMetatableName;
+ const String m_SamplerLibMetatableName;
+
+ ClassMethodCaller<TextureViewParser> m_CreateViewBinding;
+ int CreateView( lua_State *L );
+
+ ClassMethodCaller<TextureViewParser> m_GetDefaultViewBinding;
+ int GetDefaultView( lua_State * );
+
+ ClassMethodCaller<TextureViewParser> m_SetSamplerBinding;
+ int SetSampler( lua_State * );
+
+ EnumMapping<TEXTURE_VIEW_TYPE> m_ViewTypeEnumMapping;
+ TextureTypeEnumMapping m_TexTypeEnumMapping;
+ TextureFormatEnumMapping m_TexFormatEnumMapping;
+ EnumMemberBinder<TEXTURE_VIEW_TYPE> m_ViewTypeParser;
+ EnumMapping<UAV_ACCESS_FLAG> m_UAVAccessFlagEnumMapping;
+ };
+}
diff --git a/RenderScript/include/ViewportParser.h b/RenderScript/include/ViewportParser.h
new file mode 100644
index 0000000..86cfaa0
--- /dev/null
+++ b/RenderScript/include/ViewportParser.h
@@ -0,0 +1,51 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "LuaWrappers.h"
+#include "LuaBindings.h"
+#include "EngineObjectParserCommon.h"
+#include "ClassMethodBinding.h"
+
+namespace Diligent
+{
+ class ViewportParser : public EngineObjectParserBase
+ {
+ public:
+ ViewportParser( IRenderDevice *pRenderDevice, lua_State *L );
+ static const Char* ViewportLibName;
+
+ protected:
+ virtual void CreateObj( lua_State *L );
+ virtual void DestroyObj( void *pData );
+ virtual void ReadField( lua_State *L, void *pData, const Char *Field );
+ virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
+ virtual void PushExistingObject( lua_State *L, const void *pObject );
+
+ private:
+ int SetViewports( lua_State * );
+ ClassMethodCaller<ViewportParser> m_SetViewportsBinding;
+ std::vector<Viewport> m_Viewports;
+ };
+}
diff --git a/RenderScript/include/pch.h b/RenderScript/include/pch.h
new file mode 100644
index 0000000..9bb451f
--- /dev/null
+++ b/RenderScript/include/pch.h
@@ -0,0 +1,49 @@
+/* Copyright 2015 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include <algorithm>
+#include <unordered_map>
+#include <memory>
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+
+#include "BasicTypes.h"
+#include "Errors.h"
+#include "ParsingErrors.h"
+
+#include "RefCntAutoPtr.h"
+#include "RenderDevice.h"
+#include "DeviceContext.h"
+
+#include "LuaWrappers.h"
+#include "Debug.h"
+#include "DebugUtilities.h"