From f2e065dee10fb110e9d51175ee6381333319ef56 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 20 Oct 2015 21:05:29 -0700 Subject: Release v1.0.0 --- RenderScript/include/BlendStateParser.h | 51 ++ RenderScript/include/BufferParser.h | 67 +++ RenderScript/include/BufferViewParser.h | 63 +++ RenderScript/include/ClassMethodBinding.h | 87 +++ RenderScript/include/ConvenienceFunctions.h | 84 +++ RenderScript/include/Debug.h | 63 +++ RenderScript/include/DepthStencilStateParser.h | 52 ++ RenderScript/include/DeviceContextFuncBindings.h | 49 ++ RenderScript/include/DrawAttribsParser.h | 63 +++ RenderScript/include/EngineObjectParserBase.h | 62 +++ RenderScript/include/EngineObjectParserCommon.h | 70 +++ RenderScript/include/EnumMappings.h | 108 ++++ RenderScript/include/LayoutDescParser.h | 55 ++ RenderScript/include/LuaBindings.h | 662 +++++++++++++++++++++++ RenderScript/include/LuaFunctionBinding.h | 100 ++++ RenderScript/include/LuaWrappers.h | 59 ++ RenderScript/include/ParsingErrors.h | 51 ++ RenderScript/include/RasterizerStateParser.h | 60 ++ RenderScript/include/ResourceMappingParser.h | 65 +++ RenderScript/include/SamplerParser.h | 58 ++ RenderScript/include/ScissorRectParser.h | 51 ++ RenderScript/include/ScriptParser.h | 151 ++++++ RenderScript/include/ShaderParser.h | 74 +++ RenderScript/include/ShaderVariableParser.h | 65 +++ RenderScript/include/TextureParser.h | 66 +++ RenderScript/include/TextureViewParser.h | 71 +++ RenderScript/include/ViewportParser.h | 51 ++ RenderScript/include/pch.h | 49 ++ 28 files changed, 2507 insertions(+) create mode 100644 RenderScript/include/BlendStateParser.h create mode 100644 RenderScript/include/BufferParser.h create mode 100644 RenderScript/include/BufferViewParser.h create mode 100644 RenderScript/include/ClassMethodBinding.h create mode 100644 RenderScript/include/ConvenienceFunctions.h create mode 100644 RenderScript/include/Debug.h create mode 100644 RenderScript/include/DepthStencilStateParser.h create mode 100644 RenderScript/include/DeviceContextFuncBindings.h create mode 100644 RenderScript/include/DrawAttribsParser.h create mode 100644 RenderScript/include/EngineObjectParserBase.h create mode 100644 RenderScript/include/EngineObjectParserCommon.h create mode 100644 RenderScript/include/EnumMappings.h create mode 100644 RenderScript/include/LayoutDescParser.h create mode 100644 RenderScript/include/LuaBindings.h create mode 100644 RenderScript/include/LuaFunctionBinding.h create mode 100644 RenderScript/include/LuaWrappers.h create mode 100644 RenderScript/include/ParsingErrors.h create mode 100644 RenderScript/include/RasterizerStateParser.h create mode 100644 RenderScript/include/ResourceMappingParser.h create mode 100644 RenderScript/include/SamplerParser.h create mode 100644 RenderScript/include/ScissorRectParser.h create mode 100644 RenderScript/include/ScriptParser.h create mode 100644 RenderScript/include/ShaderParser.h create mode 100644 RenderScript/include/ShaderVariableParser.h create mode 100644 RenderScript/include/TextureParser.h create mode 100644 RenderScript/include/TextureViewParser.h create mode 100644 RenderScript/include/ViewportParser.h create mode 100644 RenderScript/include/pch.h (limited to 'RenderScript/include') 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 + { + 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 SBSDescWrapper; + + int SetBlendState( lua_State *L ); + ClassMethodCaller 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 + { + 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 SBuffDescWrapper; + + int SetVertexBuffers( lua_State * ); + ClassMethodCaller m_SetVertexBuffersBinding; + int SetIndexBuffer( lua_State * ); + ClassMethodCaller m_SetIndexBufferBinding; + + UsageEnumMapping m_UsageEnumMapping; + // Explicit namespace declaraion is necesseary to avoid + // name conflicts when building for windows store + EnumMapping m_BindFlagEnumMapping; + CpuAccessFlagEnumMapping m_CpuAccessFlagEnumMapping; + NumericArrayLoader m_ArrayLoader; + EnumMapping m_BuffModeEnumMapping; + EnumMapping 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 + { + 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 SBuffViewDescWrapper; + + const String m_BufferLibMetatableName; + + ClassMethodCaller m_CreateViewBinding; + int CreateView( lua_State *L ); + + ClassMethodCaller m_GetDefaultViewBinding; + int GetDefaultView( lua_State * ); + + EnumMapping m_ViewTypeEnumMapping; + EnumMemberBinder 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 + 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(lua_touserdata( L, lua_upvalueindex( 1 ) )); + VERIFY( pOwner, "Owner pointer is null" ); + + auto pThis = static_cast(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 +#endif + +inline void SetGlobalVarsStub( Diligent::ScriptParser * ){} + +template +Diligent::RefCntAutoPtr CreateRenderScriptFromFile( const Diligent::Char *FilePath, Diligent::IRenderDevice *pRenderDevice, Diligent::IDeviceContext *pContext, TSetGlobalVars SetGlobalVars ) +{ + bool bSuccess = true; + Diligent::RefCntAutoPtr 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 pFileData( new Diligent::DataBlobImpl ); + ScriptFile->Read( pFileData ); + + // Null-terminator is not read from the stream + pFileData->Resize(pFileData->GetSize() + 1); + auto *ScriptText = reinterpret_cast(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 + { + 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 SDSSDescWrapper; + + int SetDepthStencilState( lua_State *L ); + ClassMethodCaller 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 m_SetRenderTargetsBinding; + + int ClearRenderTarget( lua_State * ); + ClassMethodCaller m_ClearRenderTargetBinding; + + int ClearDepthStencil( lua_State * ); + ClassMethodCaller 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 m_DrawBinding; + + int DispatchCompute( lua_State * ); + ClassMethodCaller m_DispatchComputeBinding; + + EnumMapping m_PrimTopologyEnumMapping; + EnumMapping 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 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 + 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( L, ShaderName, m_MetatableRegistryName.c_str() ); + *ppObject = pObject; + pObject->AddRef(); + } + + protected: + virtual void PushExistingObject( lua_State *L, const void *pObject ) + { + auto ppObject = reinterpret_cast(lua_newuserdata( L, sizeof( ObjectType* ) )); + *ppObject = reinterpret_cast(const_cast(pObject)); + (*ppObject)->AddRef(); + } + + virtual void DestroyObj( void *pData ) + { + if( pData != nullptr ) + { + auto ppObject = reinterpret_cast(pData); + if( *ppObject != nullptr ) + (*ppObject)->Release(); + } + } + + virtual void ReadField( lua_State *L, void *pData, const Char *Field ) + { + auto pObject = *reinterpret_cast(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 \ +{ \ + size_t operator()( const Type &x ) const \ + { \ + return hash()(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 + 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 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 + { + 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 ElementsBuffer; + }; + + + int SetInputLayout( lua_State *L ); + ClassMethodCaller 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(0); + } + template<>int ReadValueFromLua( lua_State *L, int Index ); + template<>double ReadValueFromLua( lua_State *L, int Index ); + template<>float ReadValueFromLua( lua_State *L, int Index ); + template<>String ReadValueFromLua( lua_State *L, int Index ); + template<>const Char* ReadValueFromLua( lua_State *L, int Index ); + template<>Bool ReadValueFromLua( lua_State *L, int Index ); + template<>Uint32 ReadValueFromLua( lua_State *L, int Index ); + template<>Uint8 ReadValueFromLua( 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 : "", "\". \"", 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 &MetatableNames ); + + template + 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(pUserData); + } + + template + 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( L, -1, MetatableName ); // -0 | +0 -> 0 + lua_pop( L, 1 ); // -1 | +0 -> -1 + CHECK_LUA_STACK_HEIGHT(); + return pData; + } + + + + template + void PushValue( lua_State *L, Type ) + { + UNSUPPORTED( "Type is not supported" ); + } + // Forward declarations of template specializations + template<> void PushValue( lua_State *L, double Val ); + template<> void PushValue( lua_State *L, const float& Val ); + template<> void PushValue( lua_State *L, const Int32& Val ); + template<> void PushValue( lua_State *L, const Uint32& Val ); + template<> void PushValue( lua_State *L, const Uint8& Val ); + template<> void PushValue( lua_State *L, const Char* Val ); + template<> void PushValue( lua_State *L, const Char* const& Val ); + template<> void PushValue( lua_State *L, const String& Val ); + template<> void PushValue( lua_State *L, bool Val ); + template<> void PushValue( 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 > BindingsMapType; + +#define DEFINE_BINDER(BindingsMap, Struct, Member, type, ValidationFunc) \ + {\ + auto *pNewBinder = new MemberBinder( 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(pNewBinder) ) ); \ + } + + template + void SkipValidationFunc( const ValueType & ) + { + // Do nothing + } + + template + 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 ) : + 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 + MemberType& GetMemberByOffest( void* pBasePointer, size_t Offset ) + { + return *(reinterpret_cast(reinterpret_cast(pBasePointer)+Offset)); + } + + template + const MemberType& GetMemberByOffest( const void* pBasePointer, size_t Offset ) + { + return *(reinterpret_cast(reinterpret_cast(pBasePointer)+Offset)); + } + + template + class MemberBinder : public MemberBinderBase + { + public: + MemberBinder( size_t MemberOffset, Validator Validator ) : + MemberBinderBase( MemberOffset ), + m_Validator( Validator ) + {} + + virtual void GetValue( lua_State *L, const void* pBasePointer ) + { + const auto &Value = GetMemberByOffest(pBasePointer, m_MemberOffset); + PushValue( L, Value ); + } + + virtual void SetValue( lua_State *L, int Index, void* pBasePointer ) + { + auto Value = ReadValueFromLua( L, Index ); + m_Validator( L, Value ); + GetMemberByOffest( pBasePointer, m_MemberOffset ) = Value; + } + protected: + Validator 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 + 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( 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 + 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 + 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 : 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( MemberOffset + sizeof( Float32 )*c, Validator() ); + // 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( 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 &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 + class EnumMemberBinder : public MemberBinderBase + { + public: + EnumMemberBinder( size_t MemberOffset, const Char* MemberName, const EnumMapping &EnumMapping ) : + MemberBinderBase( MemberOffset ), + m_MemberName( MemberName ), + m_EnumMapping( EnumMapping ) + { + } + + virtual void GetValue( lua_State *L, const void* pBasePointer ) + { + const auto &Val = GetMemberByOffest( pBasePointer, m_MemberOffset ); + auto It = m_EnumMapping.m_Val2StrMap.find( Val ); + if( It != m_EnumMapping.m_Val2StrMap.end() ) + { + const String& StrVal = It->second; + PushValue( 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( L, Index ); + auto It = m_EnumMapping.m_Str2ValMap.find( Str.c_str() ); + if( It != m_EnumMapping.m_Str2ValMap.end() ) + { + auto Val = It->second; + GetMemberByOffest(pBasePointer, m_MemberOffset) = Val; + } + else + { + String AllowableValues = GetEnumMappingsString( 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 &m_EnumMapping; + }; + +#define DEFINE_ENUM_BINDER(BindingsMap, Struct, Member, type, EnumMapping ) \ + {\ + auto *pNewBinder = new EnumMemberBinder( 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(pNewBinder) ) ); \ + } + + template< typename EnumType, typename FlagsType = Uint32 > + class FlagsLoader : public MemberBinderBase + { + public: + FlagsLoader( size_t MemberOffset, const Char* MemberName, const EnumMapping &EnumMapping ) : + MemberBinderBase( MemberOffset ), + m_MemberName( MemberName ), + m_EnumMapping( EnumMapping ) + { + } + virtual void GetValue( lua_State *L, const void* pBasePointer ) + { + auto Flags = GetMemberByOffest( 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( 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( ReadValueFromLua( 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( pBasePointer, m_MemberOffset ) = Flags; + } + + private: + FlagsType ReadFlag( lua_State *L, int StackIndex ) + { + auto CurrFlagName = ReadValueFromLua( L, StackIndex ); + auto It = m_EnumMapping.m_Str2ValMap.find( CurrFlagName ); + if( It != m_EnumMapping.m_Str2ValMap.end() ) + { + return It->second; + } + else + { + String AllowableValues = GetEnumMappingsString( 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 &m_EnumMapping; + }; +#define DEFINE_FLAGS_BINDER(BindingsMap, Struct, Member, type, EnumMapping ) \ + {\ + auto *pNewBinder = new FlagsLoader( 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(pNewBinder) ) ); \ + } + + + template + 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( 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 m_ValueTypeEnumMapping; + EnumMemberBinder m_ValueTypeBinder; + typedef void (*ParseNumericArrayFuncType)(lua_State *L, int StackIndex, std::vector< Uint8 >& RawData); + std::unordered_map< VALUE_TYPE, ParseNumericArrayFuncType > m_ParseFuncJumpTbl; + }; + + + template + class EngineObjectPtrLoader + { + public: + typedef EngineObjectType ObjectType; + }; + + template + class MemberBinder< EngineObjectPtrLoader > : public MemberBinderBase + { + public: + typedef typename EngineObjectPtrLoader::ObjectType ObjectType; + + MemberBinder( size_t MemberOffset, const std::vector &_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( pBasePointer, m_MemberOffset ); + auto ppNewObject = reinterpret_cast(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( L, -1, Metatables ); + GetMemberByOffest( pBasePointer, m_MemberOffset ) = pObject; + } + private: + BindingsMapType Bindings; + std::vector 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( pBasePointer, m_StringPtrOffset ); + PushValue( 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( L, Index ); + // Set the const Char* pointer + auto &DstStrBuff = GetMemberByOffest( pBasePointer, m_MemberOffset ); + auto &DstStringPtr = GetMemberByOffest( 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(pNewBinder) ) ); \ + } + + // Object description wrapper that provides storage for + // the Name field + template + 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 + class LuaFunctionCaller : public LuaFunctionCallerBase, public AdditionalPushFuncs + { + public: + void operator()() + { + operator()( nullptr ); + } + + template + 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 + void Run_internal( int NumArgs, const Char *FuncName, const ArgType &Arg ) + { + PushFuncStub( m_LuaState, Arg ); + Run_internal( NumArgs + 1, FuncName ); + } + + template + 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(-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 +SSType& operator << (SSType &ss, const std::vector& 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 + { + 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 SRSDescWrapper; + + int SetRasterizerState( lua_State *L ); + ClassMethodCaller 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 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 + { + 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 SSamDescWrapper; + + EnumMapping m_FilterTypeEnumMapping; + EnumMapping 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 m_SetScissorRectsBinding; + std::vector 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 +#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 + { + public: + ScriptParser( IRenderDevice *pRenderDevice ); + ~ScriptParser(); + + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ); + + void Parse(const Char *pScript); + + template + 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 + void Run( RefCntAutoPtr &pContext, const ArgsType&... Args ) + { + Run(pContext.RawPtr(), Args... ); + } + + template + void Run( const ArgsType&... Args ) + { + Run( static_cast(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 + 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 &pSampler ); + void PushFuncStub( lua_State *L, const IVertexDescription* pVertDesc ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pVertDesc ); + void PushFuncStub( lua_State *L, const IShader* pShader ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pShader ); + void PushFuncStub( lua_State *L, const IBuffer* pBuffer ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pBuffer ); + void PushFuncStub( lua_State *L, const ITexture* pTexture ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pTexture ); + void PushFuncStub( lua_State *L, const DrawAttribs &DrawAttribs ); + void PushFuncStub( lua_State *L, const IResourceMapping* pResourceMapping ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pResourceMapping ); + void PushFuncStub( lua_State *L, const ITextureView* pTextureView ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pTextureView ); + void PushFuncStub( lua_State *L, const IBufferView* pBufferView ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pBufferView ); + void PushFuncStub( lua_State *L, const IDepthStencilState* pDSState ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pDSState ); + void PushFuncStub( lua_State *L, const IRasterizerState* pRS ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &pRS ); + void PushFuncStub( lua_State *L, const IBlendState* pBS ); + void PushFuncStub( lua_State *L, const RefCntAutoPtr &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 &pShaderVar ); + + private: + ScriptParser *m_pScriptParser; + }; + LuaFunctionCaller m_RunFunctionCaller; + + void DefineGlobalConstants( lua_State *L ); + + Diligent::RefCntAutoPtr m_pRenderDevice; + LuaState m_LuaState; + std::unique_ptr m_pSamplerParser; + std::unique_ptr m_pLayoutDescParser; + std::unique_ptr m_pShaderParser; + std::unique_ptr m_pBufferParser; + std::unique_ptr m_pTextureParser; + std::unique_ptr m_pDrawAttribsParser; + std::unique_ptr m_pResourceMappingParser; + std::unique_ptr m_pTextureViewParser; + std::unique_ptr m_pBufferViewParser; + std::unique_ptr m_pDSStateParser; + std::unique_ptr m_pRSParser; + std::unique_ptr m_pBSParser; + std::unique_ptr m_pDeviceCtxFuncBindings; + std::unique_ptr m_pViewportParser; + std::unique_ptr m_pScissorRectParser; + std::unique_ptr 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 + { + 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 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 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 + { + 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 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 m_BindFlagEnumMapping; + // Explicit namespace declaraion is necesseary to avoid + // name conflicts when building for windows store + + EnumMapping 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 + { + 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 STexViewDescWrapper; + + const String m_TextureLibMetatableName; + const String m_SamplerLibMetatableName; + + ClassMethodCaller m_CreateViewBinding; + int CreateView( lua_State *L ); + + ClassMethodCaller m_GetDefaultViewBinding; + int GetDefaultView( lua_State * ); + + ClassMethodCaller m_SetSamplerBinding; + int SetSampler( lua_State * ); + + EnumMapping m_ViewTypeEnumMapping; + TextureTypeEnumMapping m_TexTypeEnumMapping; + TextureFormatEnumMapping m_TexFormatEnumMapping; + EnumMemberBinder m_ViewTypeParser; + EnumMapping 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 m_SetViewportsBinding; + std::vector 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 +#include +#include + +#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" -- cgit v1.2.3