OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreShaderProgramProcessor.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-2011 Torus Knot Software Ltd
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 -----------------------------------------------------------------------------
26 */
27 #ifndef _ShaderProgramProcessor_
28 #define _ShaderProgramProcessor_
29 
31 #include "OgreShaderParameter.h"
32 #include "OgreShaderFunctionAtom.h"
33 
34 
35 namespace Ogre {
36 namespace RTShader {
37 
50 {
51 
52 // Interface.
53 public:
54 
59 
61  virtual ~ProgramProcessor ();
62 
64  virtual const String& getTargetLanguage () const = 0;
65 
71  virtual bool preCreateGpuPrograms (ProgramSet* programSet) = 0;
72 
77  virtual bool postCreateGpuPrograms (ProgramSet* programSet) = 0;
78 
79 // Protected types.
80 protected:
81 
82  //-----------------------------------------------------------------------------
83  // Class that holds merge parameter information.
85  {
86  // Interface.
87  public:
90 
91 
93  void clear ();
94 
96  void addSourceParameter (ParameterPtr srcParam, int mask);
97 
99  size_t getSourceParameterCount () const { return mSrcParameterCount; }
100 
102  ParameterPtr getSourceParameter (unsigned int index) { return mSrcParameter[index]; }
103 
105  int getSourceParameterMask (unsigned int index) const { return mSrcParameterMask[index]; }
106 
108  int getDestinationParameterMask (unsigned int index) const { return mDstParameterMask[index]; }
109 
111  int getUsedFloatCount ();
112 
114  ParameterPtr getDestinationParameter (int usage, int index);
115 
116  protected:
117 
119  void createDestinationParameter (int usage, int index);
120 
121 
122  protected:
123  ParameterPtr mDstParameter; // Destination merged parameter.
124  ParameterPtr mSrcParameter[4]; // Source parameters - 4 source at max 1,1,1,1 -> 4.
125  int mSrcParameterMask[4]; // Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
126  int mDstParameterMask[4]; // Destination parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
127  size_t mSrcParameterCount; // The actual source parameters count.
128  size_t mUsedFloatCount; // The number of used floats.
129  };
131 
132 
133  //-----------------------------------------------------------------------------
134  // A struct that defines merge parameters combination.
136  {
137  size_t srcParamterTypeCount[4]; // The count of each source type. I.E (1 FLOAT1, 0 FLOAT2, 1 FLOAT3, 0 FLOAT4).
138  int srcParameterMask[4]; // Source parameters mask. OPM_ALL means all fields used, otherwise it is split source parameter.
139 
141  int float1Count, int float1Mask,
142  int float2Count, int float2Mask,
143  int float3Count, int float3Mask,
144  int float4Count, int float4Mask)
145  {
146  srcParamterTypeCount[0] = float1Count;
147  srcParamterTypeCount[1] = float2Count;
148  srcParamterTypeCount[2] = float3Count;
149  srcParamterTypeCount[3] = float4Count;
150  srcParameterMask[0] = float1Mask;
151  srcParameterMask[1] = float2Mask;
152  srcParameterMask[2] = float3Mask;
153  srcParameterMask[3] = float4Mask;
154 
155  }
156  };
158 
159  //-----------------------------------------------------------------------------
163 
164 protected:
165 
167  void buildMergeCombinations ();
168 
174  virtual bool compactVsOutputs (Function* vsMain, Function* fsMain);
175 
181  void countVsTexcoordOutputs (Function* vsMain, int& outTexCoordSlots, int& outTexCoordFloats);
182 
187  void buildTexcoordTable (const ShaderParameterList& paramList, ShaderParameterList outParamsTable[4]);
188 
189 
194  void mergeParameters (ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
195 
196 
201  void mergeParametersByPredefinedCombinations(ShaderParameterList paramsTable[4], MergeParameterList& mergedParams);
202 
208  bool mergeParametersByCombination (const MergeCombination& combination, ShaderParameterList paramsTable[4],
209  MergeParameter* mergedParameter);
210 
216  void mergeParametersReminders (ShaderParameterList paramsTable[4], MergeParameterList& mergedParams, ShaderParameterList& splitParams);
217 
218 
220  void generateLocalSplitParameters (Function* func, GpuProgramType progType, MergeParameterList& mergedParams, ShaderParameterList& splitParams, LocalParameterMap& localParamsMap);
221 
224  void rebuildParameterList (Function* func, int paramsUsage, MergeParameterList& mergedParams);
225 
227  void rebuildFunctionInvocations (FunctionAtomInstanceList& funcAtomList, MergeParameterList& mergedParams, LocalParameterMap& localParamsMap);
228 
230  void buildParameterReferenceMap (FunctionAtomInstanceList& funcAtomList, ParameterOperandMap& paramsRefMap);
231 
233  void replaceParametersReferences (MergeParameterList& mergedParams, ParameterOperandMap& paramsRefMap);
234 
236  void replaceSplitParametersReferences (LocalParameterMap& localParamsMap, ParameterOperandMap& paramsRefMap);
237 
239  static int getParameterFloatCount (GpuConstantType type);
240 
242  static int getParameterMaskByType (GpuConstantType type);
243 
245  static int getParameterMaskByFloatCount (int floatCount);
246 
248  void bindAutoParameters (Program* pCpuProgram, GpuProgramPtr pGpuProgram);
249 
250 protected:
251  MergeCombinationList mParamMergeCombinations; // Merging combinations defs.
252  int mMaxTexCoordSlots; // Maximum texcoord slots.
253  int mMaxTexCoordFloats; // Maximum texcoord floats count.
254 
255 };
256 
257 
261 }
262 }
263 
264 #endif
265 
map< Parameter *, ParameterPtr >::type LocalParameterMap
std::vector< T, A > type
vector< ParameterPtr >::type ShaderParameterList
Specialisation of SharedPtr to allow SharedPtr to be assigned to GpuProgramPtr.
MergeCombination(int float1Count, int float1Mask, int float2Count, int float2Mask, int float3Count, int float3Mask, int float4Count, int float4Mask)
GpuProgramType
Enumerates the types of programs which can run on the GPU.
A class that provides extra processing services on CPU based programs.
#define _OgreRTSSExport
int getDestinationParameterMask(unsigned int index) const
Return destination parameter mask by index.
int getSourceParameterMask(unsigned int index) const
Return source parameter mask by index.
ParameterPtr getSourceParameter(unsigned int index)
Return source parameter by index.
size_t getSourceParameterCount() const
Return the source parameter count.
vector< MergeParameter >::type MergeParameterList
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
A class that represents a shader based program function.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
std::map< K, V, P, A > type
vector< FunctionAtom * >::type FunctionAtomInstanceList
vector< MergeCombination >::type MergeCombinationList
A class that represents a shader based program.
_StringBase String
Container class for shader based programs.
map< Parameter *, OperandPtrVector >::type ParameterOperandMap