git.s-ol.nu forks/DiligentTools / d9ff664
Removed RenderScript and lua assiduous 3 years ago
133 changed file(s) with 1 addition(s) and 39966 deletion(s). Raw diff Collapse all Expand all
4040 add_subdirectory(Imgui)
4141 add_subdirectory(NativeApp)
4242
43 if(${DILIGENT_BUILD_RENDER_SCRIPT})
44 add_subdirectory(RenderScript)
45 endif()
46
4743 if(PLATFORM_WIN32 AND GL_SUPPORTED)
4844 add_subdirectory(HLSL2GLSLConverter)
4945 endif()
22 This module implements additional functionality on top of the [Diligent Engine](https://github.com/DiligentGraphics/DiligentEngine)'s core module
33 and contains the following libraries:
44
5 * [Render script](RenderScript): a Lua-based scripting system
65 * [Texture loader](TextureLoader): a texture loading libary. The following formats are currently supported: jpg, png, tiff, dds, ktx.
76 * [Asset Loader](AssetLoader): an asset loading libary. The library currently supports GLTF 2.0.
87 * [Imgui](Imgui): implementation of [dear imgui](https://github.com/ocornut/imgui) with Diligent API.
2726 * [libtiff](http://www.libtiff.org/): TIFF Library and Utilities.
2827 * [libpng](http://www.libpng.org/pub/png/libpng.html): Official PNG reference library.
2928 * [zlib](https://zlib.net/): A compression library.
30 * [lua](https://www.lua.org/): Lua programming language run time.
3129 * [tinygltf](https://github.com/syoyo/tinygltf): A header only C++11 glTF 2.0 library.
3230 * [imgui](https://github.com/ocornut/imgui): Immediate Mode Graphical User interface for C++ with minimal dependencies.
3331
+0
-100
RenderScript/CMakeLists.txt less more
0 cmake_minimum_required (VERSION 3.6)
1
2 project(Diligent-RenderScript CXX)
3
4 set(INCLUDE
5 include/BlendStateDescParser.h
6 include/BufferParser.h
7 include/BufferViewParser.h
8 include/ClassMethodBinding.h
9 include/ConvenienceFunctions.h
10 include/Debug.h
11 include/DepthStencilStateDescParser.h
12 include/DeviceContextFuncBindings.h
13 include/DrawAttribsParser.h
14 include/EngineObjectParserBase.h
15 include/EngineObjectParserCommon.h
16 include/EnumMappings.h
17 include/InputLayoutDescParser.h
18 include/LuaBindings.h
19 include/LuaFunctionBinding.h
20 include/LuaWrappers.h
21 include/ParsingErrors.h
22 include/pch.h
23 include/PSODescParser.h
24 include/RasterizerStateDescParser.h
25 include/ResourceMappingParser.h
26 include/SamplerParser.h
27 include/ScissorRectParser.h
28 include/ScriptParser.h
29 include/ShaderParser.h
30 include/ShaderResourceBindingParser.h
31 include/ShaderVariableParser.h
32 include/TextureParser.h
33 include/TextureViewParser.h
34 include/ViewportParser.h
35 )
36
37 set(SOURCE
38 src/BlendStateDescParser.cpp
39 src/BufferParser.cpp
40 src/BufferViewParser.cpp
41 src/DepthStencilStateDescParser.cpp
42 src/DeviceContextFuncBindings.cpp
43 src/DrawAttribsParser.cpp
44 src/EngineObjectParserBase.cpp
45 src/EnumMappings.cpp
46 src/InputLayoutDescParser.cpp
47 src/LuaBindings.cpp
48 src/LuaFunctionBinding.cpp
49 src/LuaWrappers.cpp
50 src/ParsingErrors.cpp
51 src/PSODescParser.cpp
52 src/RasterizerStateDescParser.cpp
53 src/ResourceMappingParser.cpp
54 src/SamplerParser.cpp
55 src/ScissorRectParser.cpp
56 src/ScriptParser.cpp
57 src/ShaderParser.cpp
58 src/ShaderResourceBindingParser.cpp
59 src/ShaderVariableParser.cpp
60 src/TextureParser.cpp
61 src/TextureViewParser.cpp
62 src/ViewportParser.cpp
63 )
64
65 add_library(Diligent-RenderScript STATIC ${SOURCE} ${INCLUDE})
66 set_common_target_properties(Diligent-RenderScript)
67
68 target_include_directories(Diligent-RenderScript
69 PUBLIC
70 include
71 )
72
73 if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
74 CMAKE_CXX_COMPILER_ID MATCHES "GNU")
75 # Suppress warnings from applying the ‘offsetof’ macro to a non-POD type
76 # warning: offset of on non-standard-layout type [-Winvalid-offsetof]
77 # This is OK because the warning is generated for simple structs (such as TextureDesc)
78 # that fail to be a POD type only by virtue of having a constructor and comparison operator
79 target_compile_options(Diligent-RenderScript PRIVATE -Wno-invalid-offsetof)
80 endif()
81
82 source_group("source" FILES ${SOURCE})
83 source_group("include" FILES ${INCLUDE})
84
85 target_link_libraries(Diligent-RenderScript
86 PUBLIC
87 Lua
88 PRIVATE
89 Diligent-BuildSettings
90 Diligent-GraphicsEngineInterface
91 Diligent-GraphicsAccessories
92 Diligent-Common
93 Diligent-PlatformInterface
94 Diligent-GraphicsTools
95 )
96
97 set_target_properties(Diligent-RenderScript PROPERTIES
98 FOLDER DiligentTools
99 )
+0
-41
RenderScript/include/BlendStateDescParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "PipelineState.h"
26 #include "LuaBindings.h"
27
28 namespace Diligent
29 {
30 template<>
31 class MemberBinder<BlendStateDesc> final : public MemberBinderBase
32 {
33 public:
34 MemberBinder( size_t MemberOffset, size_t Dummy ) ;
35 virtual void GetValue( lua_State *L, const void* pBasePointer )override final;
36 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )override final;
37 private:
38 BindingsMapType m_Bindings;
39 };
40 }
+0
-62
RenderScript/include/BufferParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class BufferParser final : public EngineObjectParserCommon<IBuffer>
33 {
34 public:
35 BufferParser( IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char* BufferLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40
41 private:
42 // BufferDesc structure does not provide storage for the Name field.
43 // We need to use ObjectDescWrapper<> to be able to store the field.
44 typedef ObjectDescWrapper<BufferDesc> SBuffDescWrapper;
45
46 int SetVertexBuffers( lua_State * );
47 ClassMethodCaller<BufferParser> m_SetVertexBuffersBinding;
48 int SetIndexBuffer( lua_State * );
49 ClassMethodCaller<BufferParser> m_SetIndexBufferBinding;
50
51 UsageEnumMapping m_UsageEnumMapping;
52 // Explicit namespace declaraion is necesseary to avoid
53 // name conflicts when building for windows store
54 EnumMapping<Diligent::BIND_FLAGS> m_BindFlagEnumMapping;
55 CpuAccessFlagEnumMapping m_CpuAccessFlagEnumMapping;
56 NumericArrayLoader m_ArrayLoader;
57 EnumMapping<BUFFER_MODE> m_BuffModeEnumMapping;
58 EnumMapping<SET_VERTEX_BUFFERS_FLAGS> m_SetVBFlagEnumMapping;
59 StateTransitionModeEnumMapping m_StateTransitionModeMapping;
60 };
61 }
+0
-58
RenderScript/include/BufferViewParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class BufferViewParser final : public EngineObjectParserCommon<IBufferView>
33 {
34 public:
35 BufferViewParser( class BufferParser *pBufParser, IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char *BufferViewLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40
41 private:
42 // BufferViewDesc structure does not provide storage for the Name field.
43 // We need to use ObjectDescWrapper<> to be able to store the field.
44 typedef ObjectDescWrapper<BufferViewDesc> SBuffViewDescWrapper;
45
46 const String m_BufferLibMetatableName;
47
48 ClassMethodCaller<BufferViewParser> m_CreateViewBinding;
49 int CreateView( lua_State *L );
50
51 ClassMethodCaller<BufferViewParser> m_GetDefaultViewBinding;
52 int GetDefaultView( lua_State * );
53
54 EnumMapping<BUFFER_VIEW_TYPE> m_ViewTypeEnumMapping;
55 EnumMemberBinder<BUFFER_VIEW_TYPE> m_ViewTypeParser;
56 };
57 }
+0
-87
RenderScript/include/ClassMethodBinding.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 namespace Diligent
26 {
27 template<typename OwnerClassType>
28 class ClassMethodCaller
29 {
30 public:
31 typedef int(OwnerClassType::*MemberFunctionType)(lua_State *LuaState);
32
33 ClassMethodCaller( OwnerClassType *pOwner,
34 lua_State *L,
35 const Char *LuaTableName,
36 const Char *LuaFunctionName,
37 MemberFunctionType MemberFunction) :
38 m_MemberFunction( MemberFunction )
39 {
40 INIT_LUA_STACK_TRACKING( L );
41
42 lua_getglobal( L, LuaTableName ); // -0 | +1 -> +1
43 if( lua_type( L, -1 ) == LUA_TNIL )
44 {
45 // Global name is not found, try to find metatable with that name
46 // Pop nil from the stack
47 lua_pop( L, 1 ); // -1 | +0 -> -1
48 luaL_getmetatable( L, LuaTableName ); // -0 | +1 -> +1
49 }
50 CheckType( L, -1, LUA_TTABLE );
51 lua_pushstring( L, LuaFunctionName ); // -0 | +1 -> +1
52 lua_pushlightuserdata( L, pOwner ); // -0 | +1 -> +1
53 lua_pushlightuserdata( L, this ); // -0 | +1 -> +1
54 lua_pushcclosure( L, LuaEntry, 2 ); // -2 | +0 -> -2
55 lua_settable( L, -3 ); // -1 | +0 -> -1
56 // Pop table
57 lua_pop( L, 1 ); // -1 | +0 -> -1
58
59 CHECK_LUA_STACK_HEIGHT();
60 };
61
62 private:
63 MemberFunctionType m_MemberFunction;
64
65 static int LuaEntry( lua_State *L )
66 {
67 auto pOwner = static_cast<OwnerClassType*>(lua_touserdata( L, lua_upvalueindex( 1 ) ));
68 VERIFY( pOwner, "Owner pointer is null" );
69
70 auto pThis = static_cast<ClassMethodCaller*>(lua_touserdata( L, lua_upvalueindex( 2 ) ));
71 VERIFY( pThis, "This pointer is null" );
72
73 if( pOwner && pThis )
74 {
75 auto MemberFunction = pThis->m_MemberFunction;
76
77 // A C function returns an integer with the number of values it is returning in Lua.
78 // Therefore, the function does not need to clear the stack before pushing its results.
79 // After it returns, Lua automatically removes whatever is in the stack below the results.
80 return (pOwner->*MemberFunction)(L);
81 }
82 else
83 return 0;
84 }
85 };
86 }
+0
-88
RenderScript/include/ConvenienceFunctions.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include <string>
26
27 #include "Errors.h"
28 #include "FileWrapper.h"
29 #include "ScriptParser.h"
30 #include "DataBlobImpl.h"
31 #ifdef _WIN32
32 # ifndef NOMINMAX
33 # define NOMINMAX
34 # endif
35 # include <Windows.h>
36 #endif
37
38 inline void SetGlobalVarsStub( Diligent::ScriptParser * ){}
39
40 template<typename TSetGlobalVars>
41 Diligent::RefCntAutoPtr<Diligent::ScriptParser> CreateRenderScriptFromFile( const Diligent::Char *FilePath, Diligent::IRenderDevice *pRenderDevice, Diligent::IDeviceContext *pContext, TSetGlobalVars SetGlobalVars )
42 {
43 bool bSuccess = true;
44 Diligent::RefCntAutoPtr<Diligent::ScriptParser> pScriptParser;
45 #if PLATFORM_WIN32
46 do
47 {
48 #endif
49 std::string ErrorMsg;
50 bSuccess = true;
51 try
52 {
53 Diligent::FileWrapper ScriptFile(FilePath);
54 if( !ScriptFile )
55 LOG_ERROR_AND_THROW( "Failed to open Lua source file" );
56 Diligent::RefCntAutoPtr<Diligent::IDataBlob> pFileData( Diligent::MakeNewRCObj<Diligent::DataBlobImpl>()(0) );
57 ScriptFile->Read( pFileData );
58
59 // Null-terminator is not read from the stream
60 pFileData->Resize(pFileData->GetSize() + 1);
61 auto *ScriptText = reinterpret_cast<char*>(pFileData->GetDataPtr());
62 ScriptText[pFileData->GetSize() - 1] = 0;
63
64 pScriptParser = Diligent::MakeNewRCObj<Diligent::ScriptParser>()( pRenderDevice );
65 pScriptParser->Parse( ScriptText );
66 SetGlobalVars( pScriptParser );
67 pScriptParser->Run( pContext );
68 }
69 catch( const std::runtime_error &err )
70 {
71 bSuccess = false;
72 ErrorMsg = err.what();
73 }
74
75 #if PLATFORM_WIN32
76 if( !bSuccess )
77 {
78 if( IDRETRY != MessageBoxA( NULL, "Failed to parse the script. Retry?", "Lua parser error", MB_ICONERROR | MB_ABORTRETRYIGNORE ) )
79 {
80 abort();
81 }
82 }
83 } while( !bSuccess );
84 #endif
85
86 return pScriptParser;
87 }
+0
-63
RenderScript/include/Debug.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #ifdef _DEBUG
26
27 class LuaStackHeightTracker
28 {
29 public:
30 LuaStackHeightTracker( lua_State *L ) :
31 m_L( L ),
32 m_StackTop(0)
33 {
34 Record();
35 }
36
37 void Record()
38 {
39 m_StackTop = lua_gettop( m_L );
40 }
41
42 void Check(int Adjustment = 0)
43 {
44 auto CurrHeight = lua_gettop( m_L );
45 VERIFY( CurrHeight == m_StackTop + Adjustment, "Unexpected stack height" );
46 }
47 private:
48 lua_State *m_L;
49 int m_StackTop;
50 };
51
52 #define INIT_LUA_STACK_TRACKING(L) LuaStackHeightTracker LuaStackHeightTracker(L)
53 #define RECORD_LUA_STACK_HEIGHT() LuaStackHeightTracker.Record()
54 #define CHECK_LUA_STACK_HEIGHT(...) LuaStackHeightTracker.Check(__VA_ARGS__)
55
56 #else
57
58 #define INIT_LUA_STACK_TRACKING(L)
59 #define RECORD_LUA_STACK_HEIGHT()
60 #define CHECK_LUA_STACK_HEIGHT(...)
61
62 #endif
+0
-43
RenderScript/include/DepthStencilStateDescParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "PipelineState.h"
26 #include "LuaBindings.h"
27 #include "EnumMappings.h"
28
29 namespace Diligent
30 {
31 template<>
32 class MemberBinder<DepthStencilStateDesc> : public MemberBinderBase
33 {
34 public:
35 MemberBinder( size_t MemberOffset, size_t Dummy ) ;
36 virtual void GetValue( lua_State *L, const void* pBasePointer )override;
37 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )override;
38 private:
39 BindingsMapType m_Bindings;
40 ComparisonFuncEnumMapping m_CmpFuncEnumMapping;
41 };
42 }
+0
-67
RenderScript/include/DeviceContextFuncBindings.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "ClassMethodBinding.h"
28 #include "EnumMappings.h"
29
30 namespace Diligent
31 {
32 class DeviceContextFuncBindings
33 {
34 public:
35 DeviceContextFuncBindings( IRenderDevice *pRenderDevice, lua_State *L, class TextureViewParser *pTexViewPasrser, class ShaderResourceBindingParser *pSRBParser, class PSODescParser *pPSOParser );
36
37 private:
38 int SetRenderTargets( lua_State * );
39 ClassMethodCaller<DeviceContextFuncBindings> m_SetRenderTargetsBinding;
40
41 int ClearRenderTarget( lua_State * );
42 ClassMethodCaller<DeviceContextFuncBindings> m_ClearRenderTargetBinding;
43
44 int ClearDepthStencil( lua_State * );
45 ClassMethodCaller<DeviceContextFuncBindings> m_ClearDepthStencilBinding;
46
47 int SetStencilRef( lua_State * );
48 ClassMethodCaller<DeviceContextFuncBindings> m_SetStencilRefBinding;
49
50 int SetBlendFactors( lua_State * );
51 ClassMethodCaller<DeviceContextFuncBindings> m_SetBlendFactorsBinding;
52
53 int CommitShaderResources( lua_State * );
54 ClassMethodCaller<DeviceContextFuncBindings> m_CommitShaderResourcesBinding;
55
56 int TransitionShaderResources( lua_State * );
57 ClassMethodCaller<DeviceContextFuncBindings> m_TransitionShaderResourcesBinding;
58
59 StateTransitionModeEnumMapping m_StateTransitionModeMapping;
60 EnumMapping<CLEAR_DEPTH_STENCIL_FLAGS> m_ClearDepthStencilFlagsEnumMapping;
61
62 String m_TexViewMetatableName;
63 String m_ShaderResBindingMetatableName;
64 String m_PSOMetatableName;
65 };
66 }
+0
-59
RenderScript/include/DrawAttribsParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class DrawAttribsParser final : public EngineObjectParserBase
33 {
34 public:
35 DrawAttribsParser( class BufferParser *pBuffParser, IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char* DrawAttribsLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40 virtual void DestroyObj( void *pData )override final;
41 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
42 virtual void UpdateField( lua_State *L, void *pData, const Char *Field )override final;
43 virtual void PushExistingObject( lua_State *L, const void *pObject )override final;
44
45 private:
46 int Draw( lua_State * );
47 ClassMethodCaller<DrawAttribsParser> m_DrawBinding;
48
49 int DispatchCompute( lua_State * );
50 ClassMethodCaller<DrawAttribsParser> m_DispatchComputeBinding;
51
52 EnumMapping<DRAW_FLAGS> m_DrawFlagsEnumMapping;
53 EnumMapping<VALUE_TYPE> m_ValueTypeEnumMapping;
54 StateTransitionModeEnumMapping m_StateTransitionModeEnumMapping;
55
56 String m_BufferMetatableName;
57 };
58 }
+0
-62
RenderScript/include/EngineObjectParserBase.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27
28 namespace Diligent
29 {
30 class EngineObjectParserBase
31 {
32 public:
33 EngineObjectParserBase( IRenderDevice *pRenderDevice, lua_State *L, const Char *LibName );
34 void PushObject( lua_State *L, const void *pData );
35 const String &GetMetatableName(){ return m_MetatableRegistryName; }
36
37 static IDeviceContext* LoadDeviceContextFromRegistry( lua_State *L );
38
39 protected:
40 void RegisterTable( lua_State *L );
41
42 static int LuaCreate( lua_State *L );
43 virtual void CreateObj( lua_State *L ) = 0;
44
45 static int LuaGC( lua_State *L );
46 virtual void DestroyObj( void *pData ) = 0;
47
48 static int LuaIndex( lua_State *L );
49 virtual void ReadField( lua_State *L, void *pData, const Char *Field ) = 0;
50
51 static int LuaNewIndex( lua_State *L );
52 virtual void UpdateField( lua_State *L, void *pData, const Char *Field );
53
54 virtual void PushExistingObject( lua_State *L, const void *pObject ) = 0;
55
56 Diligent::RefCntAutoPtr<IRenderDevice> m_pRenderDevice;
57 BindingsMapType m_Bindings;
58 const String m_LibName;
59 const String m_MetatableRegistryName;
60 };
61 }
+0
-70
RenderScript/include/EngineObjectParserCommon.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "EngineObjectParserBase.h"
26
27 namespace Diligent
28 {
29 template<typename ObjectType>
30 class EngineObjectParserCommon : public EngineObjectParserBase
31 {
32 public:
33 EngineObjectParserCommon( IRenderDevice *pRenderDevice, lua_State *L, const Char *LibName ) :
34 EngineObjectParserBase( pRenderDevice, L, LibName )
35 {}
36
37 virtual void GetObjectByName( lua_State *L, const Char *ShaderName, ObjectType** ppObject )
38 {
39 auto pObject = *GetGlobalObject<ObjectType**>( L, ShaderName, m_MetatableRegistryName.c_str() );
40 *ppObject = pObject;
41 pObject->AddRef();
42 }
43
44 protected:
45 virtual void PushExistingObject( lua_State *L, const void *pObject )
46 {
47 auto ppObject = reinterpret_cast<ObjectType**>(lua_newuserdata( L, sizeof( ObjectType* ) ));
48 *ppObject = reinterpret_cast<ObjectType*>(const_cast<void*>(pObject));
49 (*ppObject)->AddRef();
50 }
51
52 virtual void DestroyObj( void *pData )
53 {
54 if( pData != nullptr )
55 {
56 auto ppObject = reinterpret_cast<ObjectType**>(pData);
57 if( *ppObject != nullptr )
58 (*ppObject)->Release();
59 }
60 }
61
62 virtual void ReadField( lua_State *L, void *pData, const Char *Field )
63 {
64 auto pObject = *reinterpret_cast<ObjectType**>(pData);
65 const auto &Desc = pObject->GetDesc();
66 PushField( L, &Desc, Field, m_Bindings );
67 }
68 };
69 }
+0
-98
RenderScript/include/EnumMappings.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include <unordered_map>
26 #include "HashUtils.h"
27
28 namespace Diligent
29 {
30 template<typename EnumType>
31 struct EnumMapping
32 {
33 void AddMapping( const Char *Str, EnumType Val )
34 {
35 m_Str2ValMap.insert( std::make_pair( Diligent::HashMapStringKey(Str, true), Val ) );
36 m_Val2StrMap.insert( std::make_pair( Val, Str ) );
37 }
38
39 std::unordered_map<HashMapStringKey, EnumType, HashMapStringKey::Hasher> m_Str2ValMap;
40 std::unordered_map<EnumType, String, std::hash<typename std::underlying_type<EnumType>::type>> m_Val2StrMap;
41 };
42 #define DEFINE_ENUM_ELEMENT_MAPPING(EnumMapping, Elem) EnumMapping.AddMapping(#Elem, Elem)
43
44 class CpuAccessFlagEnumMapping : public EnumMapping < Diligent::CPU_ACCESS_FLAGS >
45 {
46 public:
47 CpuAccessFlagEnumMapping();
48 };
49
50 class UsageEnumMapping : public EnumMapping < Diligent::USAGE >
51 {
52 public:
53 UsageEnumMapping();
54 };
55
56 class TextureFormatEnumMapping : public EnumMapping < Diligent::TEXTURE_FORMAT >
57 {
58 public:
59 TextureFormatEnumMapping();
60 };
61
62 class ResourceDimEnumMapping : public EnumMapping < Diligent::RESOURCE_DIMENSION >
63 {
64 public:
65 ResourceDimEnumMapping();
66 };
67
68 class ValueTypeEnumMapping : public EnumMapping < Diligent::VALUE_TYPE >
69 {
70 public:
71 ValueTypeEnumMapping();
72 };
73
74 class ComparisonFuncEnumMapping : public EnumMapping < Diligent::COMPARISON_FUNCTION >
75 {
76 public:
77 ComparisonFuncEnumMapping();
78 };
79
80 class BindShaderResourcesFlagEnumMapping : public EnumMapping < Diligent::BIND_SHADER_RESOURCES_FLAGS >
81 {
82 public:
83 BindShaderResourcesFlagEnumMapping();
84 };
85
86 class ShaderTypeEnumMapping : public EnumMapping<SHADER_TYPE>
87 {
88 public:
89 ShaderTypeEnumMapping();
90 };
91
92 class StateTransitionModeEnumMapping : public EnumMapping<RESOURCE_STATE_TRANSITION_MODE>
93 {
94 public:
95 StateTransitionModeEnumMapping();
96 };
97 }
+0
-46
RenderScript/include/InputLayoutDescParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27
28 namespace Diligent
29 {
30 template<>
31 class MemberBinder<InputLayoutDesc> : public MemberBinderBase
32 {
33 public:
34 MemberBinder( size_t InputLayoutOffset, size_t ElementsBufferOffset );
35 virtual void GetValue( lua_State *L, const void* pBasePointer )override;
36 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )override;
37
38 private:
39 BindingsMapType m_Bindings;
40 ValueTypeEnumMapping m_ValueTypeEnumMapping;
41 EnumMapping < LayoutElement::FREQUENCY > m_FrequencyEnumMapping;
42 size_t m_LayoutElementsBufferOffset;
43 };
44
45 }
+0
-684
RenderScript/include/LuaBindings.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "lua.h"
26 #include "lualib.h"
27 #include "lauxlib.h"
28 #include "EnumMappings.h"
29
30 namespace Diligent
31 {
32 template< typename ValueType>
33 ValueType ReadValueFromLua( lua_State *L, int Index )
34 {
35 UNSUPPORTED( "Type is not supported" );
36 return static_cast<ValueType>(0);
37 }
38 template<>int ReadValueFromLua<int>( lua_State *L, int Index );
39 template<>double ReadValueFromLua<double>( lua_State *L, int Index );
40 template<>float ReadValueFromLua<float>( lua_State *L, int Index );
41 template<>String ReadValueFromLua<String>( lua_State *L, int Index );
42 template<>const Char* ReadValueFromLua<const Char*>( lua_State *L, int Index );
43 template<>Bool ReadValueFromLua<Bool>( lua_State *L, int Index );
44 template<>Uint32 ReadValueFromLua<Uint32>( lua_State *L, int Index );
45 template<>Uint8 ReadValueFromLua<Uint8>( lua_State *L, int Index );
46
47
48 inline void CheckType( lua_State *L, int Index, int ExpectedType )
49 {
50 auto Type = lua_type( L, Index );
51 if( Type != ExpectedType )
52 {
53 auto TypeName = lua_typename( L, Type );
54 auto ExpectedTypeName = lua_typename( L, ExpectedType );
55 auto Param = lua_tostring( L, Index );
56 SCRIPT_PARSING_ERROR( L, "Incorrect argument: \"", Param ? Param : "<Unknown>", "\". \"", ExpectedTypeName, "\" is expected, while \"", TypeName, "\" is provided." );
57 }
58 }
59
60 // Special version of luaL_testudata() which takes an array of allowed metatables
61 void *luaL_testudata( lua_State *L, int ud, const std::vector<String> &MetatableNames );
62
63 template<typename DataType, typename MetatableNameType>
64 DataType GetUserData( lua_State *L, int Index, MetatableNameType MetatableName )
65 {
66 CheckType( L, Index, LUA_TUSERDATA );
67 auto pUserData = luaL_testudata( L, Index, MetatableName );
68 if( pUserData == nullptr )
69 {
70 auto Type = lua_type( L, Index );
71 auto TypeName = lua_typename( L, Type );
72 SCRIPT_PARSING_ERROR( L, "Bad argument #", Index, ". User data with metatable \"", MetatableName, "\" is expected. \"", TypeName, "\" is provided." );
73 }
74 return reinterpret_cast<DataType>(pUserData);
75 }
76
77 template<typename DataType>
78 DataType GetGlobalObject( lua_State *L, const Char* ObjectName, const Char* MetatableName )
79 {
80 INIT_LUA_STACK_TRACKING( L );
81 // Pushes onto the stack the value of the given global name
82 lua_getglobal( L, ObjectName ); // -0 | +1 -> +1
83 auto pData = GetUserData<DataType>( L, -1, MetatableName ); // -0 | +0 -> 0
84 lua_pop( L, 1 ); // -1 | +0 -> -1
85 CHECK_LUA_STACK_HEIGHT();
86 return pData;
87 }
88
89
90
91 template<typename Type>
92 void PushValue( lua_State *L, Type )
93 {
94 UNSUPPORTED( "Type is not supported" );
95 }
96 // Forward declarations of template specializations
97 template<> void PushValue<double>( lua_State *L, double Val );
98 template<> void PushValue<const float&>( lua_State *L, const float& Val );
99 template<> void PushValue<const Int32&>( lua_State *L, const Int32& Val );
100 template<> void PushValue<const Uint32&>( lua_State *L, const Uint32& Val );
101 template<> void PushValue<const Uint8&>( lua_State *L, const Uint8& Val );
102 template<> void PushValue<const Char*>( lua_State *L, const Char* Val );
103 template<> void PushValue<const Char* const&>( lua_State *L, const Char* const& Val );
104 template<> void PushValue<const String&>( lua_State *L, const String& Val );
105 template<> void PushValue<bool>( lua_State *L, bool Val );
106 template<> void PushValue<const bool &>( lua_State *L, const bool &Val );
107
108
109 class MemberBinderBase
110 {
111 public:
112 MemberBinderBase( size_t MemberOffset ) :
113 m_MemberOffset( MemberOffset )
114 {}
115 virtual ~MemberBinderBase(){}
116 virtual void GetValue( lua_State *L, const void* pBasePointer ) = 0;
117 virtual void SetValue( lua_State *L, int Index, void* pBasePointer ) = 0;
118
119 protected:
120 const size_t m_MemberOffset;
121 };
122 typedef std::unordered_map<HashMapStringKey, std::unique_ptr<MemberBinderBase>, HashMapStringKey::Hasher> BindingsMapType;
123
124 #define DEFINE_BINDER_EX(BindingsMap, Struct, Member, type, ValidationFunc) \
125 do{\
126 auto *pNewBinder = new MemberBinder<type>( offsetof( Struct, Member ), ValidationFunc ); \
127 /* No need to make a copy of #Member since it is constant string. */ \
128 /* HashMapStringKey will simply keep pointer to it */ \
129 BindingsMap.insert( std::make_pair( #Member, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
130 }while(false)
131
132 #define DEFINE_BINDER(BindingsMap, Struct, Member) DEFINE_BINDER_EX(BindingsMap, Struct, Member, decltype(Struct::Member), Validator<decltype(Struct::Member)>() )
133
134 template<typename ValueType>
135 void SkipValidationFunc( const ValueType & )
136 {
137 // Do nothing
138 }
139
140 template<typename ValueType>
141 class Validator
142 {
143 public:
144 typedef void( *ValidationFuncType )(const ValueType &);
145 Validator( const char *pParameterName, ValueType MinValue, ValueType MaxValue ) :
146 m_pParameterName( pParameterName ),
147 m_MinValue( MinValue ),
148 m_MaxValue( MaxValue ),
149 m_ValidationFunc( nullptr )
150 {}
151
152 Validator( ValidationFuncType ValidationFunc = SkipValidationFunc<ValueType> ) :
153 m_pParameterName( nullptr ),
154 m_MinValue( ValueType() ),
155 m_MaxValue( ValueType() ),
156 m_ValidationFunc( ValidationFunc )
157 {}
158
159 void SetParameterName( const char *NewName ){ m_pParameterName = NewName; }
160
161 void operator()( lua_State *L, const ValueType &Value )const
162 {
163 if( m_ValidationFunc )
164 {
165 m_ValidationFunc( Value );
166 }
167 else
168 {
169 if( Value < m_MinValue || Value > m_MaxValue )
170 {
171 SCRIPT_PARSING_ERROR( L, "Parameter '", m_pParameterName, "' (", Value, ") is out of range [", m_MinValue, ",", m_MaxValue, "]\n" );
172 }
173 }
174 }
175
176 private:
177 const char *m_pParameterName;
178 ValueType m_MinValue, m_MaxValue;
179 ValidationFuncType m_ValidationFunc;
180 };
181
182 template<>
183 class Validator < Bool >
184 {
185 public:
186 void operator()( lua_State *L, const Bool & )const
187 {
188 // Do nothing
189 }
190 };
191
192 template<typename MemberType>
193 MemberType& GetMemberByOffest( void* pBasePointer, size_t Offset )
194 {
195 return *(reinterpret_cast<MemberType*>(reinterpret_cast<char*>(pBasePointer)+Offset));
196 }
197
198 template<typename MemberType>
199 const MemberType& GetMemberByOffest( const void* pBasePointer, size_t Offset )
200 {
201 return *(reinterpret_cast<const MemberType*>(reinterpret_cast<const char*>(pBasePointer)+Offset));
202 }
203
204 template<typename MemberType>
205 class MemberBinder : public MemberBinderBase
206 {
207 public:
208 MemberBinder( size_t MemberOffset, Validator<MemberType> Validator ) :
209 MemberBinderBase( MemberOffset ),
210 m_Validator( Validator )
211 {}
212
213 virtual void GetValue( lua_State *L, const void* pBasePointer )
214 {
215 const auto &Value = GetMemberByOffest<MemberType>(pBasePointer, m_MemberOffset);
216 PushValue<const MemberType &>( L, Value );
217 }
218
219 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
220 {
221 auto Value = ReadValueFromLua<MemberType>( L, Index );
222 m_Validator( L, Value );
223 GetMemberByOffest<MemberType>( pBasePointer, m_MemberOffset ) = Value;
224 }
225 protected:
226 Validator<MemberType> m_Validator;
227 };
228
229
230 template<typename TableElementParser>
231 inline void ParseLuaTable( lua_State *L, int Index, void* pBasePointer, TableElementParser ElemParser )
232 {
233 CheckType( L, Index, LUA_TTABLE );
234
235 lua_pushnil( L ); // first key which will be popped out in the first call to lua_next()
236 // lua_next() pops a key from the stack, and pushes a key–value pair from the table at the given index
237 // (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns
238 // 0 (and pushes nothing).
239 if( Index < 0 )
240 --Index;
241 while( lua_next( L, Index ) != 0 )
242 {
243 // Key is now at index -2 and Value is at index -1
244 auto IsString = lua_isstring( L, -2 );
245 if( !IsString )
246 {
247 SCRIPT_PARSING_ERROR( L, "Table key value must be string")
248 }
249 // NOTE: the lua_tostring function returns a pointer to an internal copy of the string.
250 // The string is always zero-terminated and Lua ensures that this pointer is valid as long
251 // as the corresponding value is in the stack.
252 auto Key = lua_tostring( L, -2 );
253 ElemParser(-1, pBasePointer, Key);
254
255 // Pop value from the stack, but KEEP Key for the next iteration
256 lua_pop( L, 1 );
257 }
258 }
259
260 inline void ParseLuaTable( lua_State *L, int Index, void* pBasePointer, BindingsMapType &Bindings )
261 {
262 ParseLuaTable( L, Index, pBasePointer,
263 [&](int Index, void* pBasePointer, const char *Key)
264 {
265 auto Binding = Bindings.find( Key );
266 if( Binding != Bindings.end() )
267 {
268 Binding->second->SetValue( L, Index, pBasePointer );
269 }
270 else
271 {
272 SCRIPT_PARSING_ERROR( L, "Unknown Member \"", Key, '\"' );
273 }
274 }
275 );
276 }
277
278 template<class ArrayElemParser>
279 inline void ParseLuaArray( lua_State *L, int Index, void* pBasePointer, ArrayElemParser ElemParser )
280 {
281 CheckType( L, Index, LUA_TTABLE );
282
283 lua_pushnil( L ); // first key which will be popped out in the first call to lua_next()
284 // lua_next() pops a key from the stack, and pushes a key–value pair from the table at the given index
285 // (the "next" pair after the given key). If there are no more elements in the table, then lua_next returns
286 // 0 (and pushes nothing).
287 if( Index < 0 )
288 --Index;
289 while( lua_next( L, Index ) != 0 )
290 {
291 // Key is now at index -2 and Value is at index -1
292 CheckType( L, -2, LUA_TNUMBER );
293
294 auto NewArrayIndex = static_cast<int>( lua_tointeger( L, -2 ) );
295 ElemParser( pBasePointer, -1, NewArrayIndex );
296
297 // Pop value from the stack, but KEEP Key for the next iteration
298 lua_pop( L, 1 );
299 }
300 }
301
302 inline void PushLuaTable( lua_State *L, const void* pBasePointer, BindingsMapType &Bindings )
303 {
304 lua_newtable( L );
305 for( auto it = Bindings.begin(); it != Bindings.end(); ++it )
306 {
307 const auto &Field = it->first.GetStr();
308 lua_pushstring( L, Field );
309 it->second->GetValue( L, pBasePointer );
310 lua_settable( L, -3 ); // Stack: 0
311 }
312 }
313
314 template<typename ItType, class ElemPushAlg>
315 void PushLuaArray( lua_State *L, ItType Begin, ItType End, ElemPushAlg PushAlg )
316 {
317 lua_newtable( L );
318 int ArrayInd = 1; // Lua arrays are 1-based
319 for( auto it = Begin; it != End; ++it, ++ArrayInd )
320 {
321 lua_pushnumber( L, ArrayInd ); // -0 | +1 -> +1
322 PushAlg( *it ); // -0 | +1 -> +1
323 lua_settable( L, -3 ); // -2 | +0 -> -2
324 }
325 }
326
327 template<typename ArrayType, class ElemPushAlg>
328 void PushLuaArray( lua_State *L, const ArrayType& Arr, ElemPushAlg PushAlg )
329 {
330 PushLuaArray( L, Arr.begin(), Arr.end(), PushAlg );
331 }
332
333 inline void PushField( lua_State *L, const void* pBasePointer, const Char *Field, BindingsMapType &Bindings )
334 {
335 auto It = Bindings.find( Field );
336 if( It != Bindings.end() )
337 {
338 It->second->GetValue( L, pBasePointer );
339 }
340 else
341 {
342 SCRIPT_PARSING_ERROR( L, "Unknown Member \"", Field, '\"' );
343 }
344 }
345
346 inline void UpdateField( lua_State *L, int Index, void* pBasePointer, const Char *Field, BindingsMapType &Bindings )
347 {
348 auto It = Bindings.find( Field );
349 if( It != Bindings.end() )
350 {
351 It->second->SetValue( L, Index, pBasePointer );
352 }
353 else
354 {
355 SCRIPT_PARSING_ERROR( L, "Unknown Member \"", Field, '\"' );
356 }
357 }
358
359 class RGBALoader; // Used only as a template switch
360 template<>
361 class MemberBinder<RGBALoader> : public MemberBinderBase
362 {
363 public:
364 MemberBinder( size_t MemberOffset, size_t Dummy ) :
365 MemberBinderBase( MemberOffset )
366 {
367 const char* Members[] = { "r", "g", "b", "a" };
368 for( int c = 0; c < 4; ++c )
369 {
370 auto *pNewBinder = new MemberBinder<Float32>( MemberOffset + sizeof( Float32 )*c, Validator<float>() );
371 // No need to make a copy of Members[c] since it is constant string.
372 // HashMapStringKey will simply keep pointer to it
373 Bindings.insert( std::make_pair( Members[c], std::unique_ptr<MemberBinderBase>( pNewBinder ) ) );
374 }
375 }
376 virtual void GetValue( lua_State *L, const void* pBasePointer )
377 {
378 PushLuaTable( L, pBasePointer, Bindings );
379 }
380
381 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
382 {
383 ParseLuaTable( L, Index, pBasePointer, Bindings );
384 }
385 private:
386 BindingsMapType Bindings;
387 };
388
389
390 template< typename EnumType >
391 String GetEnumMappingsString( const EnumMapping<EnumType> &EnumMapping )
392 {
393 String Values;
394 bool bFirst = true;
395 for( auto it = EnumMapping.m_Str2ValMap.begin(); it != EnumMapping.m_Str2ValMap.end(); ++it )
396 {
397 if( !bFirst )
398 Values += ", ";
399 Values += '\"';
400 Values.append( it->first.GetStr() );
401 Values += '\"';
402 bFirst = false;
403 }
404 return Values;
405 }
406
407 template<typename EnumType>
408 class EnumMemberBinder : public MemberBinderBase
409 {
410 public:
411 EnumMemberBinder( size_t MemberOffset, const Char* MemberName, const EnumMapping<EnumType> &EnumMapping ) :
412 MemberBinderBase( MemberOffset ),
413 m_MemberName( MemberName ),
414 m_EnumMapping( EnumMapping )
415 {
416 }
417
418 virtual void GetValue( lua_State *L, const void* pBasePointer )
419 {
420 const auto &Val = GetMemberByOffest<EnumType>( pBasePointer, m_MemberOffset );
421 auto It = m_EnumMapping.m_Val2StrMap.find( Val );
422 if( It != m_EnumMapping.m_Val2StrMap.end() )
423 {
424 const String& StrVal = It->second;
425 PushValue<const String&>( L, StrVal );
426 }
427 else
428 {
429 UNEXPECTED( "Enum value (", static_cast<Int32>(Val), ") not found in the map" );
430 SCRIPT_PARSING_ERROR( L, "Enum value (", static_cast<Int32>(Val), ") not found in the map" );
431 }
432 }
433
434 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
435 {
436 auto Str = ReadValueFromLua<String>( L, Index );
437 auto It = m_EnumMapping.m_Str2ValMap.find( Str.c_str() );
438 if( It != m_EnumMapping.m_Str2ValMap.end() )
439 {
440 auto Val = It->second;
441 GetMemberByOffest<EnumType>(pBasePointer, m_MemberOffset) = Val;
442 }
443 else
444 {
445 String AllowableValues = GetEnumMappingsString<EnumType>( m_EnumMapping );
446 SCRIPT_PARSING_ERROR( L, "Unknown value (\"", Str, "\") provided for parameter ", m_MemberName, ". Only the following values are allowed:\n", AllowableValues );
447 }
448 }
449
450 private:
451 const Char *m_MemberName;
452 const EnumMapping<EnumType> &m_EnumMapping;
453 };
454
455 #define DEFINE_ENUM_BINDER(BindingsMap, Struct, Member, EnumMapping ) \
456 do{\
457 auto *pNewBinder = new EnumMemberBinder<decltype(Struct::Member)>( offsetof( Struct, Member ), #Member, EnumMapping ); \
458 /* No need to make a copy of #Member since it is constant string. */ \
459 /* HashMapStringKey will simply keep pointer to it */ \
460 BindingsMap.insert( std::make_pair( #Member, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
461 }while(false)
462
463 template< typename EnumType, typename FlagsType = typename std::underlying_type<EnumType>::type >
464 class FlagsLoader : public MemberBinderBase
465 {
466 public:
467 FlagsLoader( size_t MemberOffset, const Char* MemberName, const EnumMapping<EnumType> &EnumMapping ) :
468 MemberBinderBase( MemberOffset ),
469 m_MemberName( MemberName ),
470 m_EnumMapping( EnumMapping )
471 {
472 }
473 virtual void GetValue( lua_State *L, const void* pBasePointer )
474 {
475 auto Flags = GetMemberByOffest<FlagsType>( pBasePointer, m_MemberOffset );
476 lua_newtable( L );
477 int ArrayInd = 1;
478 for( auto it = m_EnumMapping.m_Val2StrMap.begin(); it != m_EnumMapping.m_Val2StrMap.end(); ++it )
479 {
480 if( (it->first != 0 && static_cast<EnumType>(Flags & it->first) == it->first) ||
481 (Flags == 0 && it->first == 0) )
482 {
483 lua_pushnumber( L, ArrayInd ); // -0 | +1 -> +1
484 PushValue<const String&>( L, it->second ); // -0 | +1 -> +1
485 lua_settable( L, -3 ); // -2 | +0 -> -2
486 ++ArrayInd;
487 }
488 }
489 }
490
491 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
492 {
493 FlagsType Flags = static_cast<FlagsType>(0);
494 if( lua_isnumber( L, Index ) )
495 {
496 Flags = static_cast<FlagsType>( ReadValueFromLua<Uint32>( L, Index ) );
497 }
498 else if( lua_isstring( L, Index ) )
499 {
500 Flags = ReadFlag( L, Index );
501 }
502 else if( lua_istable( L, Index ) )
503 {
504 ParseLuaArray( L, Index, pBasePointer, [ &]( void* _pBasePointer, int StackIndex, int NewArrayIndex )
505 {
506 auto CurrFlag = ReadFlag( L, StackIndex );
507 Flags |= CurrFlag;
508 }
509 );
510 }
511 else
512 {
513 SCRIPT_PARSING_ERROR( L, m_MemberName, "must be specified as a single string or an array of strings." );
514 }
515 GetMemberByOffest<FlagsType>( pBasePointer, m_MemberOffset ) = Flags;
516 }
517
518 private:
519 FlagsType ReadFlag( lua_State *L, int StackIndex )
520 {
521 auto CurrFlagName = ReadValueFromLua<const Char *>( L, StackIndex );
522 auto It = m_EnumMapping.m_Str2ValMap.find( CurrFlagName );
523 if( It != m_EnumMapping.m_Str2ValMap.end() )
524 {
525 return It->second;
526 }
527 else
528 {
529 String AllowableValues = GetEnumMappingsString<EnumType>( m_EnumMapping );
530 SCRIPT_PARSING_ERROR( L, "Unknown flag (\"", CurrFlagName, "\") provided for parameter ", m_MemberName, ". Only the following flags are allowed:\n", AllowableValues );
531 return static_cast<FlagsType>(0);
532 }
533 }
534
535 const Char *m_MemberName;
536 const EnumMapping<EnumType> &m_EnumMapping;
537 };
538 #define DEFINE_FLAGS_BINDER(BindingsMap, Struct, Member, type, EnumMapping ) \
539 do{\
540 auto *pNewBinder = new FlagsLoader<type, decltype(Struct::Member)>( offsetof( Struct, Member ), #Member, EnumMapping ); \
541 /* No need to make a copy of #Member since it is constant string. */ \
542 /* HashMapStringKey will simply keep pointer to it */ \
543 BindingsMap.insert( std::make_pair( #Member, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
544 }while(false)
545
546
547 template<typename FieldType>
548 void SetTableField( lua_State *L, const char *FieldName, int TableStackIndex, FieldType Value )
549 {
550 INIT_LUA_STACK_TRACKING( L );
551
552 lua_pushstring( L, FieldName ); // -0 | +1 -> +1
553 PushValue<FieldType>( L, Value ); // -0 | +1 -> +1
554
555 // lua_settable() does the equivalent to t[k] = v, where t is the value at the given index,
556 // v is the value at the top of the stack (-1), and k is the value just below the top (-2)
557 // The function pops both the key and the value from the stack. As in Lua, this function may
558 // trigger a metamethod for the "newindex" event
559 lua_settable( L, TableStackIndex - 2 ); // -2 | +0 -> -2
560
561 CHECK_LUA_STACK_HEIGHT();
562 }
563
564 class NumericArrayLoader
565 {
566 public:
567 NumericArrayLoader();
568 void LoadArray( lua_State *L, int StackIndex, std::vector< Uint8 >& RawData );
569 private:
570 EnumMapping<VALUE_TYPE> m_ValueTypeEnumMapping;
571 EnumMemberBinder<VALUE_TYPE> m_ValueTypeBinder;
572 typedef void (*ParseNumericArrayFuncType)(lua_State *L, int StackIndex, std::vector< Uint8 >& RawData);
573 std::unordered_map< VALUE_TYPE, ParseNumericArrayFuncType, std::hash<std::underlying_type<VALUE_TYPE>::type> > m_ParseFuncJumpTbl;
574 };
575
576
577 template<typename EngineObjectType>
578 class EngineObjectPtrLoader
579 {
580 public:
581 typedef EngineObjectType ObjectType;
582 };
583
584 template<typename EngineObjectType>
585 class MemberBinder< EngineObjectPtrLoader<EngineObjectType> > : public MemberBinderBase
586 {
587 public:
588 typedef typename EngineObjectPtrLoader<EngineObjectType>::ObjectType ObjectType;
589
590 MemberBinder( size_t MemberOffset, const std::vector<String> &_Metatables ) :
591 MemberBinderBase( MemberOffset ),
592 Metatables( _Metatables )
593 {
594 }
595
596 virtual void GetValue( lua_State *L, const void* pBasePointer )
597 {
598 VERIFY( Metatables.size() == 1, "Ambiguous metatable" );
599 const auto& MetatableName = *Metatables.begin();
600 auto pObject = GetMemberByOffest<ObjectType*>( pBasePointer, m_MemberOffset );
601 if( pObject )
602 {
603 auto ppNewObject = reinterpret_cast<ObjectType**>(lua_newuserdata( L, sizeof( ObjectType* ) ));
604 *ppNewObject = pObject;
605 pObject->AddRef();
606 // Push onto the stack the metatable associated with name given in the registry
607 luaL_getmetatable( L, MetatableName.c_str() ); // -0 | +1 -> +1
608 // Pop a table from the top of the stack and set it as the new metatable
609 // for the value at the given index (which is where the new user datum is)
610 lua_setmetatable( L, -2 ); // -1 | +0 -> -1
611 }
612 else
613 {
614 lua_pushnil(L);
615 }
616 }
617
618 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
619 {
620 ObjectType *pObject = nullptr;
621 pObject = *GetUserData<ObjectType**>( L, -1, Metatables );
622 GetMemberByOffest<ObjectType*>( pBasePointer, m_MemberOffset ) = pObject;
623 }
624 private:
625 BindingsMapType Bindings;
626 std::vector<String> Metatables;
627 };
628
629 // None of the graphics engine structures (such as BufferDesc or TextureDesc)
630 // provide storage for strings, but only contain const Char* pointers.
631 // The script wraps every such structure to provide the storage
632 // This binder handles such strings
633 class BufferedStringBinder : public MemberBinderBase
634 {
635 public:
636 BufferedStringBinder(
637 size_t StringPtrOffset, // This is the offset of the const Char* pointer
638 size_t StringBuffOffset // This is the offset of the buffer that contains string data
639 ) :
640 MemberBinderBase( StringBuffOffset ),
641 m_StringPtrOffset( StringPtrOffset )
642 {
643 }
644
645 virtual void GetValue( lua_State *L, const void* pBasePointer )
646 {
647 // Always use const Char* pointer to push value to Lua as there
648 // might be no valid buffer
649 auto *StringPtr = GetMemberByOffest<const Char*>( pBasePointer, m_StringPtrOffset );
650 PushValue<const Char*>( L, StringPtr );
651 }
652
653 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
654 {
655 // When reading the string from Lua, we need to make
656 // sure that the string pointer contains the right data
657 auto SrcString = ReadValueFromLua<String>( L, Index );
658 // Set the const Char* pointer
659 auto &DstStrBuff = GetMemberByOffest<String>( pBasePointer, m_MemberOffset );
660 auto &DstStringPtr = GetMemberByOffest<const Char*>( pBasePointer, m_StringPtrOffset );
661 DstStrBuff = SrcString;
662 DstStringPtr = DstStrBuff.data();
663 }
664 protected:
665 size_t m_StringPtrOffset;
666 };
667
668 #define DEFINE_BUFFERED_STRING_BINDER(BindingsMap, Struct, StringPtr, StringBuffer) \
669 {\
670 auto *pNewBinder = new BufferedStringBinder( offsetof( Struct, StringPtr ), offsetof( Struct, StringBuffer ) ); \
671 /* No need to make a copy of #Member since it is constant string. */ \
672 /* HashMapStringKey will simply keep pointer to it */ \
673 BindingsMap.insert( std::make_pair( #StringPtr, std::unique_ptr<MemberBinderBase>(pNewBinder) ) ); \
674 }
675
676 // Object description wrapper that provides storage for
677 // the Name field
678 template<typename ObjectDescType>
679 struct ObjectDescWrapper : ObjectDescType
680 {
681 String NameBuffer;
682 };
683 }
+0
-100
RenderScript/include/LuaFunctionBinding.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 namespace Diligent
26 {
27 class LuaFunctionCallerBase
28 {
29 public:
30 LuaFunctionCallerBase( lua_State *LuaState = nullptr ) :
31 m_LuaState( LuaState )
32 {
33 };
34
35 void SetLuaState( lua_State *LuaState )
36 {
37 m_LuaState = LuaState;
38 }
39
40 // We need these stubs to hide implementation details
41 void PushFuncStub( lua_State *L, Bool Arg );
42 void PushFuncStub( lua_State *L, Int32 Arg );
43 void PushFuncStub( lua_State *L, Uint32 Arg );
44 void PushFuncStub( lua_State *L, Int16 Arg );
45 void PushFuncStub( lua_State *L, Uint16 Arg );
46 void PushFuncStub( lua_State *L, Int8 Arg );
47 void PushFuncStub( lua_State *L, Uint8 Arg );
48 void PushFuncStub( lua_State *L, float Arg );
49 void PushFuncStub( lua_State *L, const Char *Arg );
50 void PushFuncStub( lua_State *L, const String &Arg );
51
52 protected:
53 void Run_internal( int NumArgs, const Char *FuncName );
54
55 lua_State *m_LuaState;
56 };
57
58 class DummyPushFuncs
59 {
60 public:
61 void PushFuncStub();
62 };
63
64 template<typename AdditionalPushFuncs = DummyPushFuncs>
65 class LuaFunctionCaller : public LuaFunctionCallerBase, public AdditionalPushFuncs
66 {
67 public:
68 void operator()()
69 {
70 operator()( nullptr );
71 }
72
73 template<typename... ArgsType>
74 void operator()( const Char *FuncName, const ArgsType&... Args )
75 {
76 Run_internal( 0, FuncName, Args... );
77 }
78
79 // We need to make visible these parent-class definitions here
80 using LuaFunctionCallerBase::PushFuncStub;
81 using LuaFunctionCallerBase::Run_internal;
82 using AdditionalPushFuncs::PushFuncStub;
83
84 protected:
85 template<typename ArgType>
86 void Run_internal( int NumArgs, const Char *FuncName, const ArgType &Arg )
87 {
88 PushFuncStub( m_LuaState, Arg );
89 Run_internal( NumArgs + 1, FuncName );
90 }
91
92 template<typename ArgType, typename... RestArgsType>
93 void Run_internal( int NumArgs, const Char *FuncName, const ArgType &Arg, const RestArgsType&... RestArgs )
94 {
95 PushFuncStub( m_LuaState, Arg );
96 Run_internal( NumArgs + 1, FuncName, RestArgs... ); // recursive call using pack expansion syntax
97 }
98 };
99 }
+0
-59
RenderScript/include/LuaWrappers.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "lua.h"
26 #include "lualib.h"
27 #include "lauxlib.h"
28 #include "BasicTypes.h"
29
30 namespace Diligent
31 {
32 class LuaState
33 {
34 public:
35 enum
36 {
37 LUA_LIB_BASE = 0x001,
38 LUA_LIB_PACKAGE = 0x002,
39 LUA_LIB_COROUTINE = 0x004,
40 LUA_LIB_TABLE = 0x008,
41 LUA_LIB_IO = 0x010,
42 LUA_LIB_OS = 0x020,
43 LUA_LIB_STRING = 0x040,
44 LUA_LIB_BIT32 = 0x080,
45 LUA_LIB_MATH = 0x100,
46 LUA_LIB_DEBUG = 0x200
47 };
48 LuaState( Uint32 OpenLibFlags = static_cast<Uint32>(-1) );
49 ~LuaState();
50 void Close();
51
52 operator lua_State *();
53
54 private:
55 lua_State *m_pLuaState;
56 };
57
58 }
+0
-71
RenderScript/include/PSODescParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29 #include "PipelineState.h"
30
31 namespace Diligent
32 {
33 class PSODescParser final : public EngineObjectParserCommon<IPipelineState>
34 {
35 public:
36 PSODescParser( IRenderDevice *pRenderDevice, lua_State *L, const String& ResMappingMetatableName );
37 static const Char* PSODescLibName;
38
39 protected:
40 virtual void CreateObj( lua_State *L )override final;
41
42 private:
43 // PipelineStateDesc structure does not provide storage for the Name field.
44 // We need to use ObjectDescWrapper<> to be able to store the field.
45 struct PSODescWrapper : PipelineStateDesc
46 {
47 String NameBuffer;
48 std::vector<ShaderResourceVariableDesc> m_VarDescBuffer;
49 std::vector<String> m_VarNamesBuffer;
50 std::vector<StaticSamplerDesc> m_StaticSamplersBuffer;
51 std::vector<String> m_StaticSamplerTexNamesBuffer;
52 std::vector<LayoutElement> LayoutElementsBuffer;
53 };
54 friend class MemberBinder<GraphicsPipelineDesc>;
55
56 int SetPSO( lua_State *L );
57 ClassMethodCaller<PSODescParser> m_SetPSOBinding;
58
59 int IsCompatibleWith(lua_State *L);
60 ClassMethodCaller<PSODescParser> m_IsCompatibleWithBinding;
61
62 const String m_ResMappingMetatableName;
63
64 ClassMethodCaller<PSODescParser> m_BindStaticResourcesBinding;
65 int BindStaticResources( lua_State *L );
66
67 BindShaderResourcesFlagEnumMapping m_BindShaderResFlagEnumMapping;
68 ShaderTypeEnumMapping m_ShaderTypeEnumMapping;
69 };
70 }
+0
-53
RenderScript/include/ParsingErrors.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include <vector>
26
27 template<typename SSType>
28 SSType& operator << (SSType &ss, const std::vector<Diligent::String>& Arg )
29 {
30 bool bIsFirst = true;
31 for( auto it = Arg.cbegin(); it != Arg.cend(); ++it )
32 {
33 if( !bIsFirst )
34 ss << ", ";
35 ss << *it;
36 bIsFirst = false;
37 }
38 return ss;
39 }
40
41 void LuaDebugInformation( lua_State *L, std::stringstream &ss );
42
43 #define SCRIPT_PARSING_ERROR(L, ...) \
44 { \
45 std::stringstream ss; \
46 ss << '\n'; \
47 Diligent::FormatStrSS( ss, ##__VA_ARGS__ ); \
48 ss << "\n\n"; \
49 LuaDebugInformation(L, ss); \
50 auto strFullMessage = ss.str(); \
51 luaL_error(L, strFullMessage.c_str());\
52 }
+0
-44
RenderScript/include/RasterizerStateDescParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "PipelineState.h"
26 #include "LuaBindings.h"
27
28 namespace Diligent
29 {
30 template<>
31 class MemberBinder<RasterizerStateDesc> final : public MemberBinderBase
32 {
33 public:
34 MemberBinder( size_t MemberOffset, size_t Dummy ) ;
35 virtual void GetValue( lua_State *L, const void* pBasePointer )override final;
36 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )override final;
37 private:
38 BindingsMapType m_Bindings;
39
40 EnumMapping < FILL_MODE > m_FillModeEnumMapping;
41 EnumMapping < CULL_MODE > m_CullModeEnumMapping;
42 };
43 }
+0
-62
RenderScript/include/ResourceMappingParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserBase.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class ResourceMappingParser final : public EngineObjectParserBase
33 {
34 public:
35 ResourceMappingParser( IRenderDevice *pRenderDevice, lua_State *L,
36 class TextureViewParser *pTexViewParser,
37 class BufferParser *pBuffParser,
38 class BufferViewParser *pBuffViewParser );
39 void GetObjectByName( lua_State *L, const Char *ShaderName, IResourceMapping** ppObject );
40
41 static const Char* ResourceMappingLibName;
42
43 protected:
44 virtual void CreateObj( lua_State *L )override final;
45 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
46 virtual void UpdateField( lua_State *L, void *pData, const Char *Field )override final;
47
48 private:
49 virtual void PushExistingObject( lua_State *L, const void *pObject )override final;
50 virtual void DestroyObj( void *pData )override final;
51
52 BindingsMapType m_Bindings;
53
54 TextureViewParser *m_pTexViewParser;
55 BufferParser *m_pBuffParser;
56 BufferViewParser *m_pBuffViewParser;
57 std::vector<String> m_MappedResourceMetatables;
58
59 BindShaderResourcesFlagEnumMapping m_BindShaderResFlagEnumMapping;
60 };
61 }
+0
-103
RenderScript/include/SamplerParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserBase.h"
28 #include "ClassMethodBinding.h"
29 #include "EngineObjectParserCommon.h"
30
31 namespace Diligent
32 {
33 template<typename StructType>
34 void InitSamplerParserBindings(BindingsMapType &Bindings,
35 EnumMapping<FILTER_TYPE> &FilterTypeEnumMapping,
36 EnumMapping<TEXTURE_ADDRESS_MODE> &TexAddrModeEnumMapping,
37 ComparisonFuncEnumMapping &CmpFuncEnumMapping)
38 {
39 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_POINT );
40 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_LINEAR );
41 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_ANISOTROPIC );
42 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_COMPARISON_POINT );
43 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_COMPARISON_LINEAR );
44 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_COMPARISON_ANISOTROPIC );
45 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_MINIMUM_POINT );
46 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_MINIMUM_LINEAR );
47 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_MINIMUM_ANISOTROPIC );
48 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_MAXIMUM_POINT );
49 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_MAXIMUM_LINEAR );
50 DEFINE_ENUM_ELEMENT_MAPPING( FilterTypeEnumMapping, FILTER_TYPE_MAXIMUM_ANISOTROPIC );
51 VERIFY( FilterTypeEnumMapping.m_Str2ValMap.size() == FILTER_TYPE_NUM_FILTERS - 1, "Unexpected map size. Did you update FILTER_TYPE enum?" );
52 VERIFY( FilterTypeEnumMapping.m_Val2StrMap.size() == FILTER_TYPE_NUM_FILTERS - 1, "Unexpected map size. Did you update FILTER_TYPE enum?" );
53 DEFINE_ENUM_BINDER( Bindings, StructType, MinFilter, FilterTypeEnumMapping );
54 DEFINE_ENUM_BINDER( Bindings, StructType, MagFilter, FilterTypeEnumMapping );
55 DEFINE_ENUM_BINDER( Bindings, StructType, MipFilter, FilterTypeEnumMapping );
56
57
58 DEFINE_ENUM_ELEMENT_MAPPING( TexAddrModeEnumMapping, TEXTURE_ADDRESS_WRAP );
59 DEFINE_ENUM_ELEMENT_MAPPING( TexAddrModeEnumMapping, TEXTURE_ADDRESS_MIRROR );
60 DEFINE_ENUM_ELEMENT_MAPPING( TexAddrModeEnumMapping, TEXTURE_ADDRESS_CLAMP );
61 DEFINE_ENUM_ELEMENT_MAPPING( TexAddrModeEnumMapping, TEXTURE_ADDRESS_BORDER );
62 DEFINE_ENUM_ELEMENT_MAPPING( TexAddrModeEnumMapping, TEXTURE_ADDRESS_MIRROR_ONCE );
63 VERIFY( TexAddrModeEnumMapping.m_Str2ValMap.size() == TEXTURE_ADDRESS_NUM_MODES - 1, "Unexpected map size. Did you update TEXTURE_ADDRESS_MODE enum?" );
64 VERIFY( TexAddrModeEnumMapping.m_Val2StrMap.size() == TEXTURE_ADDRESS_NUM_MODES - 1, "Unexpected map size. Did you update TEXTURE_ADDRESS_MODE enum?" );
65 DEFINE_ENUM_BINDER( Bindings, StructType, AddressU, TexAddrModeEnumMapping );
66 DEFINE_ENUM_BINDER( Bindings, StructType, AddressV, TexAddrModeEnumMapping );
67 DEFINE_ENUM_BINDER( Bindings, StructType, AddressW, TexAddrModeEnumMapping );
68
69
70 DEFINE_BINDER( Bindings, StructType, MipLODBias );
71
72 using MaxAnisotropyType = decltype(StructType::MaxAnisotropy);
73 Validator<MaxAnisotropyType> MaxAnisotropyValidator( "Max Anisotropy", 0, 32 );
74 DEFINE_BINDER_EX( Bindings, StructType, MaxAnisotropy, MaxAnisotropyType, MaxAnisotropyValidator );
75
76 DEFINE_ENUM_BINDER( Bindings, StructType, ComparisonFunc, CmpFuncEnumMapping );
77
78 DEFINE_BINDER_EX( Bindings, StructType, BorderColor, RGBALoader, 0 );
79
80 DEFINE_BINDER( Bindings, StructType, MinLOD );
81 DEFINE_BINDER( Bindings, StructType, MaxLOD );
82 }
83
84 class SamplerParser final : public EngineObjectParserCommon<ISampler>
85 {
86 public:
87 SamplerParser( IRenderDevice *pRenderDevice, lua_State *L );
88 static const Char* SamplerLibName;
89
90 protected:
91 virtual void CreateObj( lua_State *L )override final;
92
93 private:
94 // SamplerDesc structure does not provide storage for the Name field.
95 // We need to use ObjectDescWrapper<> to be able to store the field.
96 typedef ObjectDescWrapper<SamplerDesc> SSamDescWrapper;
97
98 EnumMapping<FILTER_TYPE> m_FilterTypeEnumMapping;
99 EnumMapping<TEXTURE_ADDRESS_MODE> m_TexAddrModeEnumMapping;
100 ComparisonFuncEnumMapping m_CmpFuncEnumMapping;
101 };
102 }
+0
-51
RenderScript/include/ScissorRectParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class ScissorRectParser final : public EngineObjectParserBase
33 {
34 public:
35 ScissorRectParser( IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char* ScissorRectLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40 virtual void DestroyObj( void *pData )override final;
41 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
42 virtual void UpdateField( lua_State *L, void *pData, const Char *Field )override final;
43 virtual void PushExistingObject( lua_State *L, const void *pObject )override final;
44
45 private:
46 int SetScissorRects( lua_State * );
47 ClassMethodCaller<ScissorRectParser> m_SetScissorRectsBinding;
48 std::vector<Rect> m_ScissorRects;
49 };
50 }
+0
-169
RenderScript/include/ScriptParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include <memory>
26 #include "LuaWrappers.h"
27 #include "LuaFunctionBinding.h"
28 #include "RenderDevice.h"
29 #include "DeviceContext.h"
30 #include "RefCountedObjectImpl.h"
31 #include "RefCntAutoPtr.h"
32
33 namespace Diligent
34 {
35 class ScriptParser : public RefCountedObject<IObject>
36 {
37 public:
38 struct CombinedDrawAttribs
39 {
40 union
41 {
42 Uint32 NumVertices = 0;
43 Uint32 NumIndices;
44 };
45 VALUE_TYPE IndexType = VT_UNDEFINED;
46 DRAW_FLAGS Flags = DRAW_FLAG_NONE;
47 RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
48 Uint32 NumInstances = 1;
49 Uint32 BaseVertex = 0;
50 Uint32 IndirectDrawArgsOffset = 0;
51 union
52 {
53 Uint32 StartVertexLocation = 0;
54 Uint32 FirstIndexLocation;
55 };
56 Uint32 FirstInstanceLocation = 0;
57 IBuffer* pIndirectDrawAttribs = nullptr;
58 };
59
60 typedef RefCountedObject<IObject> TBase;
61
62 ScriptParser( IReferenceCounters* pRefCounters, IRenderDevice* pRenderDevice );
63 ~ScriptParser();
64
65 virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface );
66
67 void Parse(const Char *pScript);
68
69 template<typename... ArgsType>
70 void Run(IDeviceContext *pContext, const ArgsType&... Args)
71 {
72 lua_pushstring( m_LuaState, DeviceContextRegistryKey ); // -0 | +1 -> +1
73 lua_pushlightuserdata( m_LuaState, pContext ); // -0 | +1 -> +1
74 lua_settable( m_LuaState, LUA_REGISTRYINDEX ); // -2 | +0 -> -2
75
76 m_RunFunctionCaller(Args...);
77 }
78 template<typename... ArgsType>
79 void Run( RefCntAutoPtr<IDeviceContext> &pContext, const ArgsType&... Args )
80 {
81 Run(pContext.RawPtr(), Args... );
82 }
83
84 template<typename... ArgsType>
85 void Run( const ArgsType&... Args )
86 {
87 Run( static_cast<IDeviceContext *>(nullptr), Args... );
88 }
89
90
91 void GetSamplerByName( const Char *SamplerName, ISampler** ppSampler );
92 void GetShaderByName( const Char *ShaderName, IShader** ppShader );
93 void GetBufferByName( const Char *BufferName, IBuffer** ppBuffer );
94 void GetTextureByName( const Char *TextureName, ITexture** ppTexture );
95 void GetResourceMappingByName( const Char *ResourceMappingName, IResourceMapping** ppResourceMapping );
96 void GetTextureViewByName( const Char *TextureViewName, ITextureView** ppTextureView );
97 void GetBufferViewByName( const Char *BufferViewName, IBufferView** ppTextureView );
98 void GetPipelineStateByName( const Char *PSOName, IPipelineState** ppPSO );
99 void GetShaderVariableByName( const Char *ShaderVarName, IShaderResourceVariable** ppShaderVar );
100 void GetShaderResourceBindingByName( const Char *SRBName, IShaderResourceBinding** ppSRB );
101
102 template<typename ValType>
103 void SetGlobalVariable( const Char *Name, ValType Var )
104 {
105 m_RunFunctionCaller.PushFuncStub( m_LuaState, Var );
106 lua_setglobal( m_LuaState, Name );
107 }
108
109 static const Char* DeviceContextRegistryKey;
110
111 private:
112 class SpecialPushFuncs
113 {
114 public:
115 SpecialPushFuncs() : m_pScriptParser( nullptr ){}
116 void SetScriptParser( ScriptParser *pScriptParser ){ m_pScriptParser = pScriptParser; }
117
118 void PushFuncStub( lua_State *L, const ISampler* pSampler );
119 void PushFuncStub( lua_State *L, const RefCntAutoPtr<ISampler> &pSampler );
120 void PushFuncStub( lua_State *L, const IShader* pShader );
121 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShader> &pShader );
122 void PushFuncStub( lua_State *L, const IBuffer* pBuffer );
123 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBuffer> &pBuffer );
124 void PushFuncStub( lua_State *L, const ITexture* pTexture );
125 void PushFuncStub( lua_State *L, const RefCntAutoPtr<ITexture> &pTexture );
126 void PushFuncStub( lua_State *L, const struct CombinedDrawAttribs &Attribs );
127 void PushFuncStub( lua_State *L, const DrawAttribs &Attribs );
128 void PushFuncStub( lua_State *L, const DrawIndexedAttribs &Attribs );
129 void PushFuncStub( lua_State *L, const IResourceMapping* pResourceMapping );
130 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IResourceMapping> &pResourceMapping );
131 void PushFuncStub( lua_State *L, const ITextureView* pTextureView );
132 void PushFuncStub( lua_State *L, const RefCntAutoPtr<ITextureView> &pTextureView );
133 void PushFuncStub( lua_State *L, const IBufferView* pBufferView );
134 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBufferView> &pBufferView );
135 void PushFuncStub( lua_State *L, const IPipelineState* pPSO );
136 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IPipelineState> &pPSO );
137 void PushFuncStub( lua_State *L, const Viewport &Viewport );
138 void PushFuncStub( lua_State *L, const Rect &Rect );
139 void PushFuncStub( lua_State *L, const IShaderResourceVariable* pShaderVar );
140 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShaderResourceVariable> &pShaderVar );
141 void PushFuncStub( lua_State *L, const IShaderResourceBinding* pShaderVar );
142 void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShaderResourceBinding> &pShaderVar );
143
144 private:
145 ScriptParser *m_pScriptParser;
146 };
147 LuaFunctionCaller<SpecialPushFuncs> m_RunFunctionCaller;
148
149 void DefineGlobalConstants( lua_State *L );
150
151 Diligent::RefCntAutoPtr<IRenderDevice> m_pRenderDevice;
152 LuaState m_LuaState;
153 std::unique_ptr<class SamplerParser> m_pSamplerParser;
154 std::unique_ptr<class ShaderParser> m_pShaderParser;
155 std::unique_ptr<class BufferParser> m_pBufferParser;
156 std::unique_ptr<class TextureParser> m_pTextureParser;
157 std::unique_ptr<class DrawAttribsParser> m_pDrawAttribsParser;
158 std::unique_ptr<class ResourceMappingParser> m_pResourceMappingParser;
159 std::unique_ptr<class TextureViewParser> m_pTextureViewParser;
160 std::unique_ptr<class BufferViewParser> m_pBufferViewParser;
161 std::unique_ptr<class PSODescParser> m_pPSOParser;
162 std::unique_ptr<class DeviceContextFuncBindings> m_pDeviceCtxFuncBindings;
163 std::unique_ptr<class ViewportParser> m_pViewportParser;
164 std::unique_ptr<class ScissorRectParser> m_pScissorRectParser;
165 std::unique_ptr<class ShaderVariableParser> m_pShaderVariableParser;
166 std::unique_ptr<class ShaderResourceBindingParser> m_pShaderResBindingParser;
167 };
168 }
+0
-61
RenderScript/include/ShaderParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserBase.h"
28 #include "ClassMethodBinding.h"
29 #include "EngineObjectParserCommon.h"
30
31 namespace Diligent
32 {
33 class ShaderParser final : public EngineObjectParserCommon<IShader>
34 {
35 public:
36 ShaderParser( IRenderDevice *pRenderDevice, lua_State *L);
37 static const Char* ShaderLibName;
38
39 // ShaderCreateInfo structure does not provide storage for the Name field,
40 // nor does it provide storage for FilePath.
41 // We need to use ShaderCreateInfoWrapper to be able to store the data.
42 struct ShaderCreateInfoWrapper : ShaderCreateInfo
43 {
44 String NameBuffer;
45 String SourceBuffer;
46 String FilePathBuffer;
47 String EntryPointBuffer;
48 String SearchDirectoriesBuffer;
49 String CombinedSamplerSuffixBuffer;
50 const char *SearchDirectories = nullptr;
51 };
52
53 protected:
54 virtual void CreateObj( lua_State *L )override final;
55 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
56
57 private:
58 EnumMapping<SHADER_SOURCE_LANGUAGE> m_ShaderSourceLangEnumMapping;
59 };
60 }
+0
-73
RenderScript/include/ShaderResourceBindingParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserBase.h"
28 #include "ClassMethodBinding.h"
29 #include "EngineObjectParserCommon.h"
30
31 namespace Diligent
32 {
33 class ShaderResourceBindingParser final : public EngineObjectParserBase
34 {
35 public:
36 ShaderResourceBindingParser( IRenderDevice *pRenderDevice, lua_State *L,
37 const String &PSOLibMetatableName,
38 const String &ResMappingMetatableName,
39 const String &ShaderVarMetatableRegistryName);
40 static const Char* ShaderResourceBindingLibName;
41
42 void GetObjectByName( lua_State *L, const Char *ShaderName, IShaderResourceBinding** ppObject );
43
44 protected:
45 virtual void CreateObj( lua_State *L )override final;
46 virtual void DestroyObj( void *pData )override final;
47 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
48 virtual void UpdateField( lua_State *L, void *pData, const Char *Field )override final;
49 virtual void PushExistingObject( lua_State *L, const void *pObject )override final;
50
51 private:
52 String m_PSOLibMetatableName;
53 String m_ResMappingMetatableName;
54 String m_ShaderVarMetatableRegistryName;
55
56 BindShaderResourcesFlagEnumMapping m_BindShaderResFlagEnumMapping;
57 ShaderTypeEnumMapping m_ShaderTypeEnumMapping;
58
59 int BindResources( lua_State *L );
60 ClassMethodCaller < ShaderResourceBindingParser > m_BindResourcesBinding;
61
62 int GetVariable( lua_State *L );
63 ClassMethodCaller < ShaderResourceBindingParser > m_GetVariableByNameBinding;
64 ClassMethodCaller < ShaderResourceBindingParser > m_GetVariableByIndexBinding;
65
66 int CreateShaderResourceBinding( lua_State *L );
67 ClassMethodCaller<ShaderResourceBindingParser> m_CreateShaderResourceBinding;
68
69 int InitializeStaticResources( lua_State *L );
70 ClassMethodCaller < ShaderResourceBindingParser > m_InitializeStaticResourcesBinding;
71 };
72 }
+0
-70
RenderScript/include/ShaderVariableParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserBase.h"
28 #include "ClassMethodBinding.h"
29 #include "EngineObjectParserCommon.h"
30
31 namespace Diligent
32 {
33 class ShaderVariableParser final : public EngineObjectParserBase
34 {
35 public:
36 ShaderVariableParser( IRenderDevice *pRenderDevice, lua_State *L,
37 const String &PSOLibMetatableName,
38 const String &BufferLibMetatableName,
39 const String &BufferViewLibMetatableName,
40 const String &TexViewMetatableName );
41 static const Char* ShaderVariableLibName;
42
43 void GetObjectByName( lua_State *L, const Char *ShaderName, IShaderResourceVariable** ppObject );
44
45 protected:
46 virtual void CreateObj( lua_State *L )override final;
47 virtual void DestroyObj( void *pData )override final;
48 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
49 virtual void UpdateField( lua_State *L, void *pData, const Char *Field )override final;
50 virtual void PushExistingObject( lua_State *L, const void *pObject )override final;
51
52 private:
53 const String m_PSOLibMetatableName;
54 const String m_BufferLibMetatableName;
55 const String m_BufferViewLibMetatableName;
56 const String m_TexViewMetatableName;
57
58 ShaderTypeEnumMapping m_ShaderTypeEnumMapping;
59
60 int Set( lua_State *L );
61 ClassMethodCaller < ShaderVariableParser > m_SetBinding;
62
63 ClassMethodCaller<ShaderVariableParser> m_GetStaticVariableByNameBinding;
64 int GetStaticVariableByName( lua_State *L );
65
66 ClassMethodCaller<ShaderVariableParser> m_GetStaticVariableByIndexBinding;
67 int GetStaticVariableByIndex( lua_State *L );
68 };
69 }
+0
-61
RenderScript/include/TextureParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class TextureParser final : public EngineObjectParserCommon<ITexture>
33 {
34 public:
35 TextureParser( IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char* TextureLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40
41 private:
42 // TextureDesc structure does not provide storage for the Name field.
43 // We need to use ObjectDescWrapper<> to be able to store the field.
44 typedef ObjectDescWrapper<TextureDesc> STexDescWrapper;
45
46 ResourceDimEnumMapping m_TexTypeEnumMapping;
47 TextureFormatEnumMapping m_TexFormatEnumMapping;
48
49 // Note that different bind flags are allowed for different objects,
50 // so we need to populate this enum with values suitable for textures only
51 EnumMapping<Diligent::BIND_FLAGS> m_BindFlagEnumMapping;
52 // Explicit namespace declaraion is necesseary to avoid
53 // name conflicts when building for windows store
54
55 EnumMapping<Diligent::MISC_TEXTURE_FLAGS> m_MiscFlagEnumMapping;
56
57 UsageEnumMapping m_UsageEnumMapping;
58 CpuAccessFlagEnumMapping m_CpuAccessFlagEnumMapping;
59 };
60 }
+0
-65
RenderScript/include/TextureViewParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class TextureViewParser final : public EngineObjectParserCommon<ITextureView>
33 {
34 public:
35 TextureViewParser( class TextureParser *pTexParser, class SamplerParser *pSamplerParser, IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char *TextureViewLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40
41 private:
42 // TextureViewDesc structure does not provide storage for the Name field.
43 // We need to use ObjectDescWrapper<> to be able to store the field.
44 typedef ObjectDescWrapper<TextureViewDesc> STexViewDescWrapper;
45
46 const String m_TextureLibMetatableName;
47 const String m_SamplerLibMetatableName;
48
49 ClassMethodCaller<TextureViewParser> m_CreateViewBinding;
50 int CreateView( lua_State *L );
51
52 ClassMethodCaller<TextureViewParser> m_GetDefaultViewBinding;
53 int GetDefaultView( lua_State * );
54
55 ClassMethodCaller<TextureViewParser> m_SetSamplerBinding;
56 int SetSampler( lua_State * );
57
58 EnumMapping<TEXTURE_VIEW_TYPE> m_ViewTypeEnumMapping;
59 ResourceDimEnumMapping m_TexTypeEnumMapping;
60 TextureFormatEnumMapping m_TexFormatEnumMapping;
61 EnumMemberBinder<TEXTURE_VIEW_TYPE> m_ViewTypeParser;
62 EnumMapping<UAV_ACCESS_FLAG> m_UAVAccessFlagEnumMapping;
63 };
64 }
+0
-51
RenderScript/include/ViewportParser.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #pragma once
24
25 #include "LuaWrappers.h"
26 #include "LuaBindings.h"
27 #include "EngineObjectParserCommon.h"
28 #include "ClassMethodBinding.h"
29
30 namespace Diligent
31 {
32 class ViewportParser final : public EngineObjectParserBase
33 {
34 public:
35 ViewportParser( IRenderDevice *pRenderDevice, lua_State *L );
36 static const Char* ViewportLibName;
37
38 protected:
39 virtual void CreateObj( lua_State *L )override final;
40 virtual void DestroyObj( void *pData )override final;
41 virtual void ReadField( lua_State *L, void *pData, const Char *Field )override final;
42 virtual void UpdateField( lua_State *L, void *pData, const Char *Field )override final;
43 virtual void PushExistingObject( lua_State *L, const void *pObject )override final;
44
45 private:
46 int SetViewports( lua_State * );
47 ClassMethodCaller<ViewportParser> m_SetViewportsBinding;
48 std::vector<Viewport> m_Viewports;
49 };
50 }
+0
-49
RenderScript/include/pch.h less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 // stdafx.h : include file for standard system include files,
24 // or project specific include files that are used frequently, but
25 // are changed infrequently
26 //
27
28 #pragma once
29
30 #include <algorithm>
31 #include <unordered_map>
32 #include <memory>
33
34 #include "lua.h"
35 #include "lualib.h"
36 #include "lauxlib.h"
37
38 #include "BasicTypes.h"
39 #include "ParsingErrors.h"
40 #include "Errors.h"
41
42 #include "RefCntAutoPtr.h"
43 #include "RenderDevice.h"
44 #include "DeviceContext.h"
45
46 #include "LuaWrappers.h"
47 #include "Debug.h"
48 #include "DebugUtilities.h"
+0
-146
RenderScript/src/BlendStateDescParser.cpp less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #include "pch.h"
24 #include "BlendStateDescParser.h"
25 #include "LuaWrappers.h"
26 #include "ClassMethodBinding.h"
27
28 namespace Diligent
29 {
30 class RenderTargetBlendDescArrayParser;
31
32 template<>
33 class MemberBinder<RenderTargetBlendDescArrayParser> : public MemberBinderBase
34 {
35 public:
36 MemberBinder( size_t MemberOffset, size_t Dummy ) :
37 MemberBinderBase( MemberOffset )
38 {
39 DEFINE_BINDER( m_Bindings, RenderTargetBlendDesc, BlendEnable );
40
41 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_ZERO);
42 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_ONE);
43 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_SRC_COLOR);
44 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_SRC_COLOR);
45 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_SRC_ALPHA);
46 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_SRC_ALPHA);
47 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_DEST_ALPHA);
48 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_DEST_ALPHA);
49 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_DEST_COLOR);
50 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_DEST_COLOR);
51 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_SRC_ALPHA_SAT);
52 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_BLEND_FACTOR);
53 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_BLEND_FACTOR);
54 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_SRC1_COLOR);
55 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_SRC1_COLOR);
56 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_SRC1_ALPHA);
57 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendFactorEnumMapping, BLEND_FACTOR_INV_SRC1_ALPHA);
58 VERIFY( m_BlendFactorEnumMapping.m_Str2ValMap.size() == BLEND_FACTOR_NUM_FACTORS - 1,
59 "Unexpected map size. Did you update BLEND_FACTOR enum?" );
60 VERIFY( m_BlendFactorEnumMapping.m_Val2StrMap.size() == BLEND_FACTOR_NUM_FACTORS - 1,
61 "Unexpected map size. Did you update BLEND_FACTOR enum?" );
62
63 DEFINE_ENUM_BINDER( m_Bindings, RenderTargetBlendDesc, SrcBlend, m_BlendFactorEnumMapping );
64 DEFINE_ENUM_BINDER( m_Bindings, RenderTargetBlendDesc, DestBlend, m_BlendFactorEnumMapping );
65 DEFINE_ENUM_BINDER( m_Bindings, RenderTargetBlendDesc, SrcBlendAlpha, m_BlendFactorEnumMapping );
66 DEFINE_ENUM_BINDER( m_Bindings, RenderTargetBlendDesc, DestBlendAlpha, m_BlendFactorEnumMapping );
67
68
69 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendOpEnumMapping, BLEND_OPERATION_ADD );
70 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendOpEnumMapping, BLEND_OPERATION_SUBTRACT );
71 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendOpEnumMapping, BLEND_OPERATION_REV_SUBTRACT );
72 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendOpEnumMapping, BLEND_OPERATION_MIN );
73 DEFINE_ENUM_ELEMENT_MAPPING( m_BlendOpEnumMapping, BLEND_OPERATION_MAX );
74 VERIFY( m_BlendOpEnumMapping.m_Str2ValMap.size() == BLEND_OPERATION_NUM_OPERATIONS - 1,
75 "Unexpected map size. Did you update BLEND_OPERATION enum?" );
76 VERIFY( m_BlendOpEnumMapping.m_Val2StrMap.size() == BLEND_OPERATION_NUM_OPERATIONS - 1,
77 "Unexpected map size. Did you update BLEND_OPERATION enum?" );
78
79 DEFINE_ENUM_BINDER( m_Bindings, RenderTargetBlendDesc, BlendOp, m_BlendOpEnumMapping );
80 DEFINE_ENUM_BINDER( m_Bindings, RenderTargetBlendDesc, BlendOpAlpha, m_BlendOpEnumMapping );
81
82
83 DEFINE_ENUM_ELEMENT_MAPPING( m_ColorMaskEnumMapping, COLOR_MASK_RED );
84 DEFINE_ENUM_ELEMENT_MAPPING( m_ColorMaskEnumMapping, COLOR_MASK_GREEN );
85 DEFINE_ENUM_ELEMENT_MAPPING( m_ColorMaskEnumMapping, COLOR_MASK_BLUE );
86 DEFINE_ENUM_ELEMENT_MAPPING( m_ColorMaskEnumMapping, COLOR_MASK_ALPHA );
87 DEFINE_ENUM_ELEMENT_MAPPING( m_ColorMaskEnumMapping, COLOR_MASK_ALL );
88 DEFINE_FLAGS_BINDER( m_Bindings, RenderTargetBlendDesc, RenderTargetWriteMask, COLOR_MASK, m_ColorMaskEnumMapping );
89 }
90
91 virtual void GetValue( lua_State *L, const void* pBasePointer )
92 {
93 const auto &RTs = GetMemberByOffest< const RenderTargetBlendDesc >(pBasePointer, m_MemberOffset);
94 PushLuaArray( L, &RTs, &RTs+BlendStateDesc::MaxRenderTargets, [&](const RenderTargetBlendDesc &Elem)
95 {
96 PushLuaTable( L, &Elem, m_Bindings );
97 }
98 );
99 }
100
101 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
102 {
103 ParseLuaArray( L, Index, pBasePointer, [&]( void* _pBasePointer, int StackIndex, int NewArrayIndex )
104 {
105 VERIFY( pBasePointer == _pBasePointer, "Sanity check" );
106 auto &RenderTargets = GetMemberByOffest<RenderTargetBlendDesc>( pBasePointer, m_MemberOffset );
107
108 auto MaxRTs = BlendStateDesc::MaxRenderTargets;
109 if( !(NewArrayIndex >= 1 && NewArrayIndex <= MaxRTs) )
110 SCRIPT_PARSING_ERROR( L, "Incorrect render target index ", NewArrayIndex, ". Only 1..", MaxRTs, " are allowed" );
111
112 ParseLuaTable( L, StackIndex, &RenderTargets + (NewArrayIndex-1), m_Bindings );
113 }
114 );
115 }
116 private:
117 BindingsMapType m_Bindings;
118
119 EnumMapping < BLEND_FACTOR > m_BlendFactorEnumMapping;
120 EnumMapping < BLEND_OPERATION > m_BlendOpEnumMapping;
121 EnumMapping < COLOR_MASK > m_ColorMaskEnumMapping;
122 };
123
124
125 MemberBinder<BlendStateDesc> :: MemberBinder( size_t MemberOffset, size_t Dummy ) :
126 MemberBinderBase( MemberOffset )
127 {
128 DEFINE_BINDER( m_Bindings, BlendStateDesc, AlphaToCoverageEnable );
129 DEFINE_BINDER( m_Bindings, BlendStateDesc, IndependentBlendEnable );
130
131 DEFINE_BINDER_EX( m_Bindings, BlendStateDesc, RenderTargets, RenderTargetBlendDescArrayParser, 0 );
132 }
133
134 void MemberBinder<BlendStateDesc> ::GetValue(lua_State *L, const void* pBasePointer)
135 {
136 const auto &BlendDesc = GetMemberByOffest< BlendStateDesc >(pBasePointer, m_MemberOffset);
137 PushLuaTable(L, &BlendDesc, m_Bindings);
138 }
139
140 void MemberBinder<BlendStateDesc> ::SetValue(lua_State *L, int Index, void* pBasePointer)
141 {
142 auto &BlendDesc = GetMemberByOffest< BlendStateDesc>( pBasePointer, m_MemberOffset );
143 ParseLuaTable( L, Index, &BlendDesc, m_Bindings );
144 }
145 }
+0
-226
RenderScript/src/BufferParser.cpp less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #include "pch.h"
24 #include "BufferParser.h"
25
26 namespace Diligent
27 {
28 const Char* BufferParser::BufferLibName = "Buffer";
29
30 BufferParser::BufferParser( IRenderDevice *pRenderDevice, lua_State *L ) :
31 EngineObjectParserCommon<IBuffer>( pRenderDevice, L, BufferLibName ),
32 m_SetVertexBuffersBinding(this, L, "Context", "SetVertexBuffers", &BufferParser::SetVertexBuffers),
33 m_SetIndexBufferBinding( this, L, "Context", "SetIndexBuffer", &BufferParser::SetIndexBuffer )
34 {
35 DEFINE_BUFFERED_STRING_BINDER( m_Bindings, SBuffDescWrapper, Name, NameBuffer );
36
37 DEFINE_BINDER( m_Bindings, SBuffDescWrapper, uiSizeInBytes );
38
39 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_VERTEX_BUFFER );
40 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_INDEX_BUFFER );
41 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_UNIFORM_BUFFER );
42 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_SHADER_RESOURCE );
43 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_STREAM_OUTPUT );
44 //DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_RENDER_TARGET );
45 //DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_DEPTH_STENCIL );
46 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_UNORDERED_ACCESS );
47 DEFINE_ENUM_ELEMENT_MAPPING( m_BindFlagEnumMapping, BIND_INDIRECT_DRAW_ARGS );
48 // Explicit namespace declaraion is necesseary to avoid
49 // name conflicts when building for windows store
50 DEFINE_FLAGS_BINDER( m_Bindings, SBuffDescWrapper, BindFlags, Diligent::BIND_FLAGS, m_BindFlagEnumMapping );
51
52 DEFINE_ENUM_BINDER( m_Bindings, SBuffDescWrapper, Usage, m_UsageEnumMapping );
53 DEFINE_FLAGS_BINDER( m_Bindings, SBuffDescWrapper, CPUAccessFlags, CPU_ACCESS_FLAGS, m_CpuAccessFlagEnumMapping );
54
55 DEFINE_ENUM_ELEMENT_MAPPING( m_BuffModeEnumMapping, BUFFER_MODE_UNDEFINED );
56 DEFINE_ENUM_ELEMENT_MAPPING( m_BuffModeEnumMapping, BUFFER_MODE_FORMATTED );
57 DEFINE_ENUM_ELEMENT_MAPPING( m_BuffModeEnumMapping, BUFFER_MODE_STRUCTURED );
58 DEFINE_ENUM_ELEMENT_MAPPING( m_BuffModeEnumMapping, BUFFER_MODE_RAW );
59 static_assert(BUFFER_MODE_NUM_MODES == BUFFER_MODE_RAW + 1, "Not all buffer modes initialized.");
60 VERIFY( m_BuffModeEnumMapping.m_Str2ValMap.size() == BUFFER_MODE_NUM_MODES,
61 "Unexpected map size. Did you update BUFFER_MODE enum?" );
62 VERIFY( m_BuffModeEnumMapping.m_Val2StrMap.size() == BUFFER_MODE_NUM_MODES,
63 "Unexpected map size. Did you update BUFFER_MODE enum?" );
64 DEFINE_ENUM_BINDER( m_Bindings, SBuffDescWrapper, Mode, m_BuffModeEnumMapping );
65
66 DEFINE_BINDER( m_Bindings, SBuffDescWrapper, ElementByteStride );
67
68 DEFINE_ENUM_ELEMENT_MAPPING( m_SetVBFlagEnumMapping, SET_VERTEX_BUFFERS_FLAG_NONE );
69 DEFINE_ENUM_ELEMENT_MAPPING( m_SetVBFlagEnumMapping, SET_VERTEX_BUFFERS_FLAG_RESET );
70 };
71
72 void BufferParser::CreateObj( lua_State *L )
73 {
74 auto NumArgs = lua_gettop( L );
75 INIT_LUA_STACK_TRACKING(L);
76 SBuffDescWrapper BufferDesc;
77 ParseLuaTable( L, 1, &BufferDesc, m_Bindings );
78 CHECK_LUA_STACK_HEIGHT();
79
80 if( (BufferDesc.Mode == BUFFER_MODE_STRUCTURED || BufferDesc.Mode == BUFFER_MODE_FORMATTED) && BufferDesc.ElementByteStride == 0 )
81 SCRIPT_PARSING_ERROR( L, "Element byte stride of a structured or formatted buffer cannot be zero" );
82
83 if( (BufferDesc.Mode == BUFFER_MODE_FORMATTED || BufferDesc.Mode == BUFFER_MODE_STRUCTURED) &&
84 (BufferDesc.uiSizeInBytes % BufferDesc.ElementByteStride) != 0 )
85 SCRIPT_PARSING_ERROR( L, "Buffer size (", BufferDesc.uiSizeInBytes, ") is not multiple of element byte stride (", BufferDesc.ElementByteStride, ")." );
86
87 std::vector<Uint8> RawData;
88 if( NumArgs > 1 )
89 {
90 if( NumArgs != 3 )
91 {
92 SCRIPT_PARSING_ERROR( L, "To initialize buffer with initial data, provide value type and array of values as the 2nd and 3rd parameters. ", NumArgs, " arguments is provided." );
93 }
94
95 m_ArrayLoader.LoadArray( L, 3, RawData );
96 }
97 BufferData BuffData;
98 auto DataSize = static_cast<Uint32>(RawData.size());
99 if( DataSize )
100 {
101 if( BufferDesc.uiSizeInBytes == 0 )
102 BufferDesc.uiSizeInBytes = DataSize;
103 if( DataSize != BufferDesc.uiSizeInBytes )
104 {
105 SCRIPT_PARSING_ERROR( L, "Initial buffer data size (", DataSize, ") does not match the requested buffer size (", BufferDesc.uiSizeInBytes, "). "
106 "Do not specify uiSizeInBytes to have the buffer size calculated automatically." );
107 }
108 BuffData.pData = RawData.data();
109 BuffData.DataSize = DataSize;
110 }
111
112 if( (BufferDesc.BindFlags & BIND_UNIFORM_BUFFER) && (BufferDesc.uiSizeInBytes % 16) )
113 {
114 SCRIPT_PARSING_ERROR( L, "Uniform buffer size (", DataSize, ") is not multiple of 16." );
115 }
116
117 auto ppBuffer = reinterpret_cast<IBuffer**>(lua_newuserdata( L, sizeof( IBuffer* ) ));
118 *ppBuffer = nullptr;
119 m_pRenderDevice->CreateBuffer( BufferDesc, &BuffData, ppBuffer );
120 if( *ppBuffer == nullptr )
121 SCRIPT_PARSING_ERROR( L, "Failed to create buffer" )
122
123 CHECK_LUA_STACK_HEIGHT( +1 );
124 }
125
126 int BufferParser::SetVertexBuffers( lua_State *L )
127 {
128 auto NumArgs = lua_gettop( L );
129
130 int CurrArgInd = 1;
131
132 Int32 StartSlot = 0;
133 if( lua_type( L, CurrArgInd ) == LUA_TNUMBER )
134 {
135 StartSlot = ReadValueFromLua<Int32>( L, CurrArgInd++ );
136 if( StartSlot < 0 )
137 {
138 SCRIPT_PARSING_ERROR( L, "Start slot (", StartSlot, " provided) must be in range 0..", MaxBufferSlots - 1 );
139 }
140 }
141
142 SET_VERTEX_BUFFERS_FLAGS Flags = SET_VERTEX_BUFFERS_FLAG_NONE;
143 RESOURCE_STATE_TRANSITION_MODE StateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
144 Uint32 NumBuffers = 0;
145 IBuffer *pBuffs[MaxBufferSlots] = {};
146 Uint32 Offsets[MaxBufferSlots] = {};
147 while( CurrArgInd <= NumArgs )
148 {
149 if( StartSlot + (NumBuffers + 1) > MaxBufferSlots )
150 {
151 SCRIPT_PARSING_ERROR( L, "Too many buffer slots (", StartSlot, "..", StartSlot + NumBuffers - 1, ") are being set. Allowed slots are 0..", MaxBufferSlots - 1 );
152 break;
153 }
154
155 if( lua_type( L, CurrArgInd ) != LUA_TNIL )
156 pBuffs[NumBuffers] = *GetUserData<IBuffer**>( L, CurrArgInd++, m_MetatableRegistryName.c_str() );
157 else
158 {
159 ++CurrArgInd;
160 pBuffs[NumBuffers] = nullptr;
161 }
162
163 if( lua_type( L, CurrArgInd ) == LUA_TNUMBER )
164 Offsets[NumBuffers] = ReadValueFromLua<Uint32>( L, CurrArgInd++ );
165 else
166 Offsets[NumBuffers] = 0;
167
168 if( CurrArgInd >= NumArgs-1 && lua_type( L, CurrArgInd ) == LUA_TSTRING)
169 {
170 EnumMemberBinder<RESOURCE_STATE_TRANSITION_MODE> StateTransitionModeLoader(0, "StateTransitionMode", m_StateTransitionModeMapping);
171 StateTransitionModeLoader.SetValue( L, CurrArgInd, &StateTransitionMode );
172 ++CurrArgInd;
173 }
174
175 // The last argument may be flags
176 if( CurrArgInd == NumArgs &&
177 (lua_type( L, CurrArgInd ) == LUA_TSTRING ||
178 lua_type( L, CurrArgInd ) == LUA_TTABLE ) )
179 {
180 VERIFY( Flags == 0, "Flags have already been set!" );
181 FlagsLoader<SET_VERTEX_BUFFERS_FLAGS> SetVBFlagsLoader(0, "SetVBFlags", m_SetVBFlagEnumMapping);
182 SetVBFlagsLoader.SetValue( L, CurrArgInd, &Flags );
183 ++CurrArgInd;
184 }
185
186 ++NumBuffers;
187 }
188
189 auto *pContext = LoadDeviceContextFromRegistry( L );
190 pContext->SetVertexBuffers( StartSlot, NumBuffers, pBuffs, Offsets, StateTransitionMode, Flags );
191
192 // Return no values to Lua
193 return 0;
194 }
195
196 int BufferParser::SetIndexBuffer( lua_State *L )
197 {
198 auto *pIndexBuff = *GetUserData<IBuffer**>( L, 1, m_MetatableRegistryName.c_str() );
199 Uint32 Offset = 0;
200 auto NumArgs = lua_gettop( L );
201 if( NumArgs > 3 )
202 {
203 SCRIPT_PARSING_ERROR( L, "SetIndexBuffer() expects offset and state transition mode as optional 2nd and 3rd parameters. ", NumArgs, " arguments are provided." );
204 }
205 int CurrArg = 2;
206 if( CurrArg <= NumArgs && lua_isnumber( L, CurrArg ) )
207 {
208 Offset = ReadValueFromLua<Uint32>( L, CurrArg );
209 ++CurrArg;
210 }
211
212 RESOURCE_STATE_TRANSITION_MODE StateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
213 if( CurrArg <= NumArgs && lua_type( L, CurrArg ) == LUA_TSTRING)
214 {
215 EnumMemberBinder<RESOURCE_STATE_TRANSITION_MODE> StateTransitionModeLoader(0, "StateTransitionMode", m_StateTransitionModeMapping);
216 StateTransitionModeLoader.SetValue( L, CurrArg, &StateTransitionMode );
217 }
218
219 auto *pContext = LoadDeviceContextFromRegistry( L );
220 pContext->SetIndexBuffer( pIndexBuff, Offset, StateTransitionMode );
221
222 // Return no values to Lua
223 return 0;
224 }
225 }
+0
-153
RenderScript/src/BufferViewParser.cpp less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #include "pch.h"
24 #include "BufferViewParser.h"
25 #include "BufferParser.h"
26 #include "SamplerParser.h"
27 #include "GraphicsAccessories.h"
28
29 namespace Diligent
30 {
31 const Char* BufferViewParser::BufferViewLibName = "BufferView";
32
33 template<>
34 class MemberBinder<BufferFormat> : public MemberBinderBase
35 {
36 public:
37 MemberBinder( size_t MemberOffset, size_t Dummy ) :
38 MemberBinderBase( MemberOffset )
39 {
40 DEFINE_ENUM_BINDER( m_Bindings, BufferFormat, ValueType, m_ValueTypeEnumMapping );
41 using NumComponentsType = decltype(BufferFormat::NumComponents);
42 DEFINE_BINDER_EX( m_Bindings, BufferFormat, NumComponents, NumComponentsType, Validator<NumComponentsType>( "Num Components", 1, 4 ) );
43 DEFINE_BINDER( m_Bindings, BufferFormat, IsNormalized );
44 }
45
46 virtual void GetValue( lua_State *L, const void* pBasePointer )
47 {
48 const auto &BuffFmt = GetMemberByOffest<BufferFormat>( pBasePointer, m_MemberOffset );
49 PushLuaTable( L, &BuffFmt, m_Bindings );
50 }
51
52 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
53 {
54 auto &BuffFmt = GetMemberByOffest<BufferFormat>( pBasePointer, m_MemberOffset );
55 ParseLuaTable( L, Index, &BuffFmt, m_Bindings );
56 }
57 private:
58 BindingsMapType m_Bindings;
59 ValueTypeEnumMapping m_ValueTypeEnumMapping;
60 };
61
62 BufferViewParser::BufferViewParser( BufferParser *pBufParser,
63 IRenderDevice *pRenderDevice,
64 lua_State *L ) :
65 EngineObjectParserCommon<IBufferView>( pRenderDevice, L, BufferViewLibName ),
66 m_BufferLibMetatableName(pBufParser->GetMetatableName()),
67 m_CreateViewBinding( this, L, m_BufferLibMetatableName.c_str(), "CreateView", &BufferViewParser::CreateView ),
68 m_GetDefaultViewBinding( this, L, m_BufferLibMetatableName.c_str(), "GetDefaultView", &BufferViewParser::GetDefaultView ),
69 m_ViewTypeParser( 0, "ViewType", m_ViewTypeEnumMapping )
70 {
71 DEFINE_BUFFERED_STRING_BINDER( m_Bindings, SBuffViewDescWrapper, Name, NameBuffer );
72
73 DEFINE_ENUM_ELEMENT_MAPPING( m_ViewTypeEnumMapping, BUFFER_VIEW_SHADER_RESOURCE );
74 DEFINE_ENUM_ELEMENT_MAPPING( m_ViewTypeEnumMapping, BUFFER_VIEW_UNORDERED_ACCESS );
75 VERIFY( m_ViewTypeEnumMapping.m_Str2ValMap.size() == BUFFER_VIEW_NUM_VIEWS - 1,
76 "Unexpected map size. Did you update BUFFER_VIEW_TYPE enum?" );
77 VERIFY( m_ViewTypeEnumMapping.m_Val2StrMap.size() == BUFFER_VIEW_NUM_VIEWS - 1,
78 "Unexpected map size. Did you update BUFFER_VIEW_TYPE enum?" );
79 DEFINE_ENUM_BINDER( m_Bindings, SBuffViewDescWrapper, ViewType, m_ViewTypeEnumMapping );
80
81 DEFINE_BINDER_EX( m_Bindings, SBuffViewDescWrapper, Format, BufferFormat, 0 );
82
83 DEFINE_BINDER( m_Bindings, SBuffViewDescWrapper, ByteOffset);
84 DEFINE_BINDER( m_Bindings, SBuffViewDescWrapper, ByteWidth);
85 };
86
87 void BufferViewParser::CreateObj( lua_State *L )
88 {
89 INIT_LUA_STACK_TRACKING(L);
90
91 auto *pBuffer = *GetUserData<IBuffer**>( L, 1, m_BufferLibMetatableName.c_str() );
92
93 SBuffViewDescWrapper BufferViewDesc;
94 ParseLuaTable( L, 2, &BufferViewDesc, m_Bindings );
95 CHECK_LUA_STACK_HEIGHT();
96
97 auto ppBufferView = reinterpret_cast<IBufferView**>(lua_newuserdata( L, sizeof( IBufferView* ) ));
98 *ppBufferView = nullptr;
99
100 auto& BuffFmt = BufferViewDesc.Format;
101 const auto& BuffDesc = pBuffer->GetDesc();
102 if (BuffFmt.ValueType != VT_UNDEFINED)
103 {
104 if (BuffFmt.NumComponents == 0)
105 SCRIPT_PARSING_ERROR( L, "Number components cannot be 0" );
106 auto FmtSize = GetValueSize( BuffFmt.ValueType ) * Uint32{BuffFmt.NumComponents};
107 if (BuffDesc.ElementByteStride != FmtSize )
108 {
109 SCRIPT_PARSING_ERROR( L, "Format size (", FmtSize, ") specified by view '", BufferViewDesc.Name,"' does not match the element byte stride (", BuffDesc.ElementByteStride, ") of the buffer '", BuffDesc.Name, "'." );
110 }
111 if (BuffFmt.ValueType == VT_FLOAT32 || BuffFmt.ValueType == VT_FLOAT16)
112 BuffFmt.IsNormalized = false;
113 }
114
115 pBuffer->CreateView( BufferViewDesc, ppBufferView );
116 if( *ppBufferView == nullptr )
117 SCRIPT_PARSING_ERROR(L, "Failed to create buffer view")
118
119 CHECK_LUA_STACK_HEIGHT( +1 );
120 }
121
122 int BufferViewParser::CreateView( lua_State *L )
123 {
124 // Note that LuaCreate is a static function.
125 // However, this pointer to the BufferViewParser object
126 // is stored in the upvalue. So LuaCreate will call
127 // BufferViewParser::CreateObj()
128 return LuaCreate(L);
129 }
130
131 int BufferViewParser::GetDefaultView( lua_State *L )
132 {
133 INIT_LUA_STACK_TRACKING( L );
134
135 // Buffer should be the first argument
136 auto *pBuffer = *GetUserData<IBuffer**>( L, 1, m_BufferLibMetatableName.c_str() );
137
138 // View type should be the second argument
139 BUFFER_VIEW_TYPE ViewType;
140 m_ViewTypeParser.SetValue( L, 2, &ViewType );
141
142 auto pView = pBuffer->GetDefaultView( ViewType );
143
144 // Push existing object
145 PushObject(L, pView);
146
147 CHECK_LUA_STACK_HEIGHT( +1 );
148
149 // Returning one value to Lua
150 return 1;
151 }
152 }
+0
-98
RenderScript/src/DepthStencilStateDescParser.cpp less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #include "pch.h"
24 #include "DepthStencilStateDescParser.h"
25
26 namespace Diligent
27 {
28 template<>
29 class MemberBinder<StencilOpDesc> : public MemberBinderBase
30 {
31 public:
32 MemberBinder( size_t MemberOffset, size_t Dummy ) :
33 MemberBinderBase( MemberOffset )
34 {
35 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_KEEP );
36 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_ZERO );
37 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_REPLACE );
38 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_INCR_SAT );
39 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_DECR_SAT );
40 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_INVERT );
41 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_INCR_WRAP );
42 DEFINE_ENUM_ELEMENT_MAPPING( m_StencilOpEnumMapping, STENCIL_OP_DECR_WRAP );
43 VERIFY( m_StencilOpEnumMapping.m_Str2ValMap.size() == STENCIL_OP_NUM_OPS - 1,
44 "Unexpected map size. Did you update STENCIL_OP enum?" );
45 VERIFY( m_StencilOpEnumMapping.m_Val2StrMap.size() == STENCIL_OP_NUM_OPS - 1,
46 "Unexpected map size. Did you update STENCIL_OP enum?" );
47
48 DEFINE_ENUM_BINDER( m_Bindings, StencilOpDesc, StencilFailOp, m_StencilOpEnumMapping );
49 DEFINE_ENUM_BINDER( m_Bindings, StencilOpDesc, StencilDepthFailOp, m_StencilOpEnumMapping );
50 DEFINE_ENUM_BINDER( m_Bindings, StencilOpDesc, StencilPassOp, m_StencilOpEnumMapping );
51 DEFINE_ENUM_BINDER( m_Bindings, StencilOpDesc, StencilFunc, m_CmpFuncEnumMapping );
52 }
53
54 virtual void GetValue( lua_State *L, const void* pBasePointer )
55 {
56 const auto &StOpDesc = GetMemberByOffest< StencilOpDesc >(pBasePointer, m_MemberOffset);
57 PushLuaTable( L, &StOpDesc, m_Bindings );
58 }
59
60 virtual void SetValue( lua_State *L, int Index, void* pBasePointer )
61 {
62 auto &StOpDesc = GetMemberByOffest< StencilOpDesc >( pBasePointer, m_MemberOffset );
63 ParseLuaTable( L, Index, &StOpDesc, m_Bindings );
64 }
65
66 private:
67 BindingsMapType m_Bindings;
68 ComparisonFuncEnumMapping m_CmpFuncEnumMapping;
69 EnumMapping < STENCIL_OP > m_StencilOpEnumMapping;
70 };
71
72 MemberBinder<DepthStencilStateDesc>::MemberBinder( size_t MemberOffset, size_t Dummy ) :
73 MemberBinderBase( MemberOffset )
74 {
75 DEFINE_BINDER( m_Bindings, DepthStencilStateDesc, DepthEnable );
76 DEFINE_BINDER( m_Bindings, DepthStencilStateDesc, DepthWriteEnable );
77 DEFINE_ENUM_BINDER( m_Bindings, DepthStencilStateDesc, DepthFunc, m_CmpFuncEnumMapping );
78
79 DEFINE_BINDER( m_Bindings, DepthStencilStateDesc, StencilEnable );
80 DEFINE_BINDER( m_Bindings, DepthStencilStateDesc, StencilReadMask );
81 DEFINE_BINDER( m_Bindings, DepthStencilStateDesc, StencilWriteMask );
82 DEFINE_BINDER_EX( m_Bindings, DepthStencilStateDesc, FrontFace, StencilOpDesc, 0 );
83 DEFINE_BINDER_EX( m_Bindings, DepthStencilStateDesc, BackFace, StencilOpDesc, 0 );
84 };
85
86 void MemberBinder<DepthStencilStateDesc> ::GetValue(lua_State *L, const void* pBasePointer)
87 {
88 const auto &DSSDesc = GetMemberByOffest< DepthStencilStateDesc >(pBasePointer, m_MemberOffset);
89 PushLuaTable(L, &DSSDesc, m_Bindings);
90 }
91
92 void MemberBinder<DepthStencilStateDesc> ::SetValue(lua_State *L, int Index, void* pBasePointer)
93 {
94 auto &DSSDesc = GetMemberByOffest< DepthStencilStateDesc>( pBasePointer, m_MemberOffset );
95 ParseLuaTable( L, Index, &DSSDesc, m_Bindings );
96 }
97 }
+0
-290
RenderScript/src/DeviceContextFuncBindings.cpp less more
0 /* Copyright 2019 Diligent Graphics LLC
1 *
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
11 *
12 * In no event and under no legal theory, whether in tort (including negligence),
13 * contract, or otherwise, unless required by applicable law (such as deliberate
14 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
15 * liable for any damages, including any direct, indirect, special, incidental,
16 * or consequential damages of any character arising as a result of this License or
17 * out of the use or inability to use the software (including but not limited to damages
18 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
19 * all other commercial damages or losses), even if such Contributor has been advised
20 * of the possibility of such damages.
21 */
22
23 #include "pch.h"
24 #include "DeviceContextFuncBindings.h"
25 #include "GraphicsUtilities.h"
26 #include "TextureViewParser.h"
27 #include "EngineObjectParserBase.h"
28 #include "ShaderResourceBindingParser.h"
29 #include "PSODescParser.h"
30
31 namespace Diligent
32 {
33 DeviceContextFuncBindings::DeviceContextFuncBindings( IRenderDevice *pRenderDevice, lua_State *L,
34 TextureViewParser *pTexViewPasrser,
35 ShaderResourceBindingParser *pSRBParser,
36 PSODescParser *pPSOParser) :
37 m_SetRenderTargetsBinding(this, L, "Context", "SetRenderTargets", &DeviceContextFuncBindings::SetRenderTargets),
38 m_ClearRenderTargetBinding(this, L, "Context", "ClearRenderTarget", &DeviceContextFuncBindings::ClearRenderTarget),
39 m_ClearDepthStencilBinding(this, L, "Context", "ClearDepthStencil", &DeviceContextFuncBindings::ClearDepthStencil),
40 m_SetStencilRefBinding(this, L, "Context", "SetStencilRef", &DeviceContextFuncBindings::SetStencilRef),
41 m_SetBlendFactorsBinding(this, L, "Context", "SetBlendFactors", &DeviceContextFuncBindings::SetBlendFactors),
42 m_CommitShaderResourcesBinding(this, L, "Context", "CommitShaderResources", &DeviceContextFuncBindings::CommitShaderResources),
43 m_TransitionShaderResourcesBinding(this, L, "Context", "TransitionShaderResources", &DeviceContextFuncBindings::TransitionShaderResources),
44 m_TexViewMetatableName( pTexViewPasrser->GetMetatableName() ),
45 m_ShaderResBindingMetatableName( pSRBParser->GetMetatableName() ),
46 m_PSOMetatableName(pPSOParser->GetMetatableName())
47 {
48 DEFINE_ENUM_ELEMENT_MAPPING( m_ClearDepthStencilFlagsEnumMapping, CLEAR_DEPTH_FLAG_NONE );
49 DEFINE_ENUM_ELEMENT_MAPPING( m_ClearDepthStencilFlagsEnumMapping, CLEAR_DEPTH_FLAG );
50 DEFINE_ENUM_ELEMENT_MAPPING( m_ClearDepthStencilFlagsEnumMapping, CLEAR_STENCIL_FLAG );
51 };
52
53 int DeviceContextFuncBindings::SetRenderTargets( lua_State *L )
54 {
55 auto NumArgs = lua_gettop( L );
56 ITextureView *pRTVs[MaxRenderTargets] = {};
57 ITextureView *pDSV = nullptr;
58 Uint32 NumRTs = 0;
59 RESOURCE_STATE_TRANSITION_MODE TransitionMode = RESOURCE_STATE_TRANSITION_MODE_TRANSITION;
60 for( int CurrArg = 1; CurrArg <= NumArgs; ++CurrArg )
61 {
62 if( lua_type( L, CurrArg ) == LUA_TUSERDATA )
63 {
64 auto *pView = *GetUserData<ITextureView**>( L, CurrArg, m_TexViewMetatableName.c_str() );
65 auto ViewType = pView->GetDesc().ViewType;
66 if( ViewType == TEXTURE_VIEW_RENDER_TARGET )
67 {
68 if( NumRTs < MaxRenderTargets )
69 {
70 pRTVs[NumRTs] = pView;
71 ++NumRTs;
72 }
73 else
74 {
75 SCRIPT_PARSING_ERROR( L, "Too many render targets are being set. ", MaxRenderTargets, " at most are allowed." );
76 }
77 }
78 else if( ViewType == TEXTURE_VIEW_DEPTH_STENCIL )
79 {
80 if( pDSV != nullptr )
81 SCRIPT_PARSING_ERROR( L, "Respecifying depth stencil view. Only one is allowed" );
82 pDSV = pView;
83 }
84 else
85 {
86 SCRIPT_PARSING_ERROR( L, "Unexpected view type. Only render target and depth stencil are allowed" );
87 }
88 }
89 else
90 {
91 EnumMemberBinder<RESOURCE_STATE_TRANSITION_MODE> StateTransitionModeLoader(0, "StateTransitionMode", m_StateTransitionModeMapping);
92 StateTransitionModeLoader.SetValue( L, CurrArg, &TransitionMode );
93 }
94 }