1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
#pragma once
#include <memory>
#include "LuaWrappers.h"
#include "LuaFunctionBinding.h"
#include "RenderDevice.h"
#include "DeviceContext.h"
#include "RefCountedObjectImpl.h"
#include "RefCntAutoPtr.h"
namespace Diligent
{
class ScriptParser : public RefCountedObject<IObject>
{
public:
typedef RefCountedObject<IObject> TBase;
ScriptParser( IReferenceCounters* pRefCounters, IRenderDevice* pRenderDevice );
~ScriptParser();
virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface );
void Parse(const Char *pScript);
template<typename... ArgsType>
void Run(IDeviceContext *pContext, const ArgsType&... Args)
{
lua_pushstring( m_LuaState, DeviceContextRegistryKey ); // -0 | +1 -> +1
lua_pushlightuserdata( m_LuaState, pContext ); // -0 | +1 -> +1
lua_settable( m_LuaState, LUA_REGISTRYINDEX ); // -2 | +0 -> -2
m_RunFunctionCaller(Args...);
}
template<typename... ArgsType>
void Run( RefCntAutoPtr<IDeviceContext> &pContext, const ArgsType&... Args )
{
Run(pContext.RawPtr(), Args... );
}
template<typename... ArgsType>
void Run( const ArgsType&... Args )
{
Run( static_cast<IDeviceContext *>(nullptr), Args... );
}
void GetSamplerByName( const Char *SamplerName, ISampler** ppSampler );
void GetShaderByName( const Char *ShaderName, IShader** ppShader );
void GetBufferByName( const Char *BufferName, IBuffer** ppBuffer );
void GetTextureByName( const Char *TextureName, ITexture** ppTexture );
void GetResourceMappingByName( const Char *ResourceMappingName, IResourceMapping** ppResourceMapping );
void GetTextureViewByName( const Char *TextureViewName, ITextureView** ppTextureView );
void GetBufferViewByName( const Char *BufferViewName, IBufferView** ppTextureView );
void GetPipelineStateByName( const Char *PSOName, IPipelineState** ppPSO );
void GetShaderVariableByName( const Char *ShaderVarName, IShaderResourceVariable** ppShaderVar );
void GetShaderResourceBindingByName( const Char *SRBName, IShaderResourceBinding** ppSRB );
template<typename ValType>
void SetGlobalVariable( const Char *Name, ValType Var )
{
m_RunFunctionCaller.PushFuncStub( m_LuaState, Var );
lua_setglobal( m_LuaState, Name );
}
static const Char* DeviceContextRegistryKey;
private:
class SpecialPushFuncs
{
public:
SpecialPushFuncs() : m_pScriptParser( nullptr ){}
void SetScriptParser( ScriptParser *pScriptParser ){ m_pScriptParser = pScriptParser; }
void PushFuncStub( lua_State *L, const ISampler* pSampler );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<ISampler> &pSampler );
void PushFuncStub( lua_State *L, const IShader* pShader );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShader> &pShader );
void PushFuncStub( lua_State *L, const IBuffer* pBuffer );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBuffer> &pBuffer );
void PushFuncStub( lua_State *L, const ITexture* pTexture );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<ITexture> &pTexture );
void PushFuncStub( lua_State *L, const DrawAttribs &DrawAttribs );
void PushFuncStub( lua_State *L, const IResourceMapping* pResourceMapping );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IResourceMapping> &pResourceMapping );
void PushFuncStub( lua_State *L, const ITextureView* pTextureView );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<ITextureView> &pTextureView );
void PushFuncStub( lua_State *L, const IBufferView* pBufferView );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IBufferView> &pBufferView );
void PushFuncStub( lua_State *L, const IPipelineState* pPSO );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IPipelineState> &pPSO );
void PushFuncStub( lua_State *L, const Viewport &Viewport );
void PushFuncStub( lua_State *L, const Rect &Rect );
void PushFuncStub( lua_State *L, const IShaderResourceVariable* pShaderVar );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShaderResourceVariable> &pShaderVar );
void PushFuncStub( lua_State *L, const IShaderResourceBinding* pShaderVar );
void PushFuncStub( lua_State *L, const RefCntAutoPtr<IShaderResourceBinding> &pShaderVar );
private:
ScriptParser *m_pScriptParser;
};
LuaFunctionCaller<SpecialPushFuncs> m_RunFunctionCaller;
void DefineGlobalConstants( lua_State *L );
Diligent::RefCntAutoPtr<IRenderDevice> m_pRenderDevice;
LuaState m_LuaState;
std::unique_ptr<class SamplerParser> m_pSamplerParser;
std::unique_ptr<class ShaderParser> m_pShaderParser;
std::unique_ptr<class BufferParser> m_pBufferParser;
std::unique_ptr<class TextureParser> m_pTextureParser;
std::unique_ptr<class DrawAttribsParser> m_pDrawAttribsParser;
std::unique_ptr<class ResourceMappingParser> m_pResourceMappingParser;
std::unique_ptr<class TextureViewParser> m_pTextureViewParser;
std::unique_ptr<class BufferViewParser> m_pBufferViewParser;
std::unique_ptr<class PSODescParser> m_pPSOParser;
std::unique_ptr<class DeviceContextFuncBindings> m_pDeviceCtxFuncBindings;
std::unique_ptr<class ViewportParser> m_pViewportParser;
std::unique_ptr<class ScissorRectParser> m_pScissorRectParser;
std::unique_ptr<class ShaderVariableParser> m_pShaderVariableParser;
std::unique_ptr<class ShaderResourceBindingParser> m_pShaderResBindingParser;
};
}
|