OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreD3D11HLSLProgram.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __D3D11HLSLProgram_H__
29 #define __D3D11HLSLProgram_H__
30 
31 #include "OgreD3D11Prerequisites.h"
34 
35 
36 namespace Ogre {
38 
48  {
49  public:
51  class CmdEntryPoint : public ParamCommand
52  {
53  public:
54  String doGet(const void* target) const;
55  void doSet(void* target, const String& val);
56  };
58  class CmdTarget : public ParamCommand
59  {
60  public:
61  String doGet(const void* target) const;
62  void doSet(void* target, const String& val);
63  };
66  {
67  public:
68  String doGet(const void* target) const;
69  void doSet(void* target, const String& val);
70  };
73  {
74  public:
75  String doGet(const void* target) const;
76  void doSet(void* target, const String& val);
77  };
80  {
81  public:
82  String doGet(const void* target) const;
83  void doSet(void* target, const String& val);
84  };
85 
86  protected:
87 
93 
94 
97  void createLowLevelImpl(void);
99  void unloadHighLevelImpl(void);
101  //void populateParameterNames(GpuProgramParametersSharedPtr params);
102 
103  // Recursive utility method for populateParameterNames
104  void processParamElement(String prefix, LPCSTR pName, size_t paramIndex, ID3D11ShaderReflectionType* varRefType) const;
105 
106  void populateDef(D3D11_SHADER_TYPE_DESC& d3dDesc, GpuConstantDefinition& def) const;
107 
113 
116  ID3D11Buffer* mConstantBuffer;
117 
119 
120  ID3D11ShaderReflectionConstantBuffer* mShaderReflectionConstantBuffer;
121  D3D11_SHADER_BUFFER_DESC mConstantBufferDesc ;
122  D3D11_SHADER_DESC mShaderDesc;
123 
125 
126  ID3D11ShaderReflection* mIShaderReflection;
127 
128  ID3D11VertexShader* mVertexShader;
129  ID3D11PixelShader* mPixelShader;
130  ID3D11GeometryShader* mGeometryShader;
131 
133  {
134  bool wasInit;
135  bool isFloat;
137  void * src;
139 
140  D3D11_SHADER_VARIABLE_DESC var;
141  };
143  typedef ShaderVars::iterator ShaderVarsIter;
144 
146 
147  void createConstantBuffer(const UINT ByteWidth);
148  void analizeMicrocode();
149  void getMicrocodeFromCache(void);
150  void compileMicrocode(void);
151  public:
152  D3D11HLSLProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
153  const String& group, bool isManual, ManualResourceLoader* loader, D3D11Device & device);
155 
157  void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
159  const String& getEntryPoint(void) const { return mEntryPoint; }
161  void setTarget(const String& target);
163  const String& getTarget(void) const { return mTarget; }
164 
166  void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
168  const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
170  void setColumnMajorMatrices(bool columnMajor) { mColumnMajorMatrices = columnMajor; }
172  bool getColumnMajorMatrices(void) const { return mColumnMajorMatrices; }
174  void setEnableBackwardsCompatibility(bool enableBackwardsCompatibility) { mEnableBackwardsCompatibility = enableBackwardsCompatibility; }
178  bool isSupported(void) const;
182  const String& getLanguage(void) const;
183 
184  virtual void buildConstantDefinitions() const;
185  ID3D11VertexShader* getVertexShader(void) const;
186  ID3D11PixelShader* getPixelShader(void) const;
187  ID3D11GeometryShader* getGeometryShader(void) const;
188  const MicroCode & getMicroCode(void) const;
189 
190  ID3D11Buffer* getConstantBuffer(GpuProgramParametersSharedPtr params, uint16 variabilityMask);
191 
192  void CreateVertexShader();
193  void CreatePixelShader();
194  void CreateGeometryShader();
195 
198  void loadFromSource(void);
199 
201 
202  void reinterpretGSForStreamOut(void);
204 
205  unsigned int getNumInputs(void)const {return mShaderDesc.InputParameters;}
206  unsigned int getNumOutputs(void)const {return mShaderDesc.OutputParameters;}
207 
208  D3D11_SIGNATURE_PARAMETER_DESC getInputParamDesc(unsigned int index) const;
209  D3D11_SIGNATURE_PARAMETER_DESC getOutputParamDesc(unsigned int index) const;
210  };
211 }
212 
213 #endif
D3D11VertexDeclaration mInputVertexDeclaration
String doGet(const void *target) const
Command object for setting backwards compatibility.
void createLowLevelImpl(void)
Internal method for creating an appropriate low-level program from this high-level program...
vector< ShaderVarWithPosInBuf >::type ShaderVars
unsigned int getNumInputs(void) const
void doSet(void *target, const String &val)
ID3D11Buffer * getConstantBuffer(GpuProgramParametersSharedPtr params, uint16 variabilityMask)
D3D11_SHADER_BUFFER_DESC mConstantBufferDesc
void loadFromSource(void)
Internal load implementation, must be implemented by subclasses.
void doSet(void *target, const String &val)
ID3D11ShaderReflectionConstantBuffer * mShaderReflectionConstantBuffer
void compileMicrocode(void)
D3D11VertexDeclaration & getInputVertexDeclaration()
void doSet(void *target, const String &val)
void setEnableBackwardsCompatibility(bool enableBackwardsCompatibility)
Sets whether backwards compatibility is enabled.
D3D11_SIGNATURE_PARAMETER_DESC getInputParamDesc(unsigned int index) const
D3D11HLSLProgram(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual, ManualResourceLoader *loader, D3D11Device &device)
Interface describing a manual resource loader.
Definition: OgreResource.h:513
void setTarget(const String &target)
Sets the shader target to compile down to, e.g.
void doSet(void *target, const String &val)
String doGet(const void *target) const
ID3D11GeometryShader * getGeometryShader(void) const
const String & getLanguage(void) const
Overridden from GpuProgram.
const MicroCode & getMicroCode(void) const
D3D11_SHADER_DESC mShaderDesc
void unloadHighLevelImpl(void)
Internal unload implementation, must be implemented by subclasses.
ID3D11VertexShader * mVertexShader
Command object for setting macro defines.
void createConstantBuffer(const UINT ByteWidth)
Command object for setting entry point.
vector< byte >::type MicroCode
ID3D11VertexShader * getVertexShader(void) const
Command object for setting target assembler.
static CmdEntryPoint msCmdEntryPoint
static CmdTarget msCmdTarget
String doGet(const void *target) const
void processParamElement(String prefix, LPCSTR pName, size_t paramIndex, ID3D11ShaderReflectionType *varRefType) const
Populate the passed parameters with name->index map, must be overridden.
ID3D11PixelShader * mPixelShader
void getMicrocodeFromCache(void)
ID3D11GeometryShader * mGeometryShader
ID3D11PixelShader * getPixelShader(void) const
GpuProgramParametersSharedPtr createParameters(void)
Overridden from GpuProgram.
ID3D11ShaderReflection * mIShaderReflection
String doGet(const void *target) const
void doSet(void *target, const String &val)
unsigned int getNumOutputs(void) const
D3D11_SIGNATURE_PARAMETER_DESC getOutputParamDesc(unsigned int index) const
unsigned long long int ResourceHandle
Definition: OgreResource.h:40
bool isSupported(void) const
Overridden from GpuProgram.
bool getColumnMajorMatrices(void) const
Gets whether matrix packed in column-major order.
void setEntryPoint(const String &entryPoint)
Sets the entry point for this program ie the first method called.
bool getEnableBackwardsCompatibility(void) const
Gets whether backwards compatibility is enabled.
static CmdColumnMajorMatrices msCmdColumnMajorMatrices
void populateDef(D3D11_SHADER_TYPE_DESC &d3dDesc, GpuConstantDefinition &def) const
void setPreprocessorDefines(const String &defines)
Sets the preprocessor defines use to compile the program.
Defines a generic resource handler.
Specialisation of VertexDeclaration for D3D11.
ShaderVars::iterator ShaderVarsIter
Information about predefined program constants.
_StringBase String
void reinterpretGSForStreamOut(void)
Command object for setting matrix packing in column-major order.
unsigned short uint16
Definition: OgrePlatform.h:271
Abstract base class representing a high-level program (a vertex or fragment program).
const String & getTarget(void) const
Gets the shader target to compile down to, e.g.
static CmdEnableBackwardsCompatibility msCmdEnableBackwardsCompatibility
void setColumnMajorMatrices(bool columnMajor)
Sets whether matrix packing in column-major order.
virtual void buildConstantDefinitions() const
Build the constant definition map, must be overridden.
Specialization of HighLevelGpuProgram to provide support for D3D11 High-Level Shader Language (HLSL)...
Abstract class which is command object which gets/sets parameters.
const String & getPreprocessorDefines(void) const
Sets the preprocessor defines use to compile the program.
static CmdPreprocessorDefines msCmdPreprocessorDefines
const String & getEntryPoint(void) const
Gets the entry point defined for this program.