OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreShaderFFPTexturing.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-2014 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 _ShaderFFPTextureStage_
28 #define _ShaderFFPTextureStage_
29 
31 #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS
33 #include "OgreRenderSystem.h"
34 
35 namespace Ogre {
36 namespace RTShader {
37 
38 
53 class _OgreRTSSExport FFPTexturing : public SubRenderState
54 {
55 
56 // Interface.
57 public:
58 
60  FFPTexturing();
61 
65  virtual const String& getType() const;
66 
70  virtual int getExecutionOrder() const;
71 
75  virtual void updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList);
76 
80  virtual void copyFrom(const SubRenderState& rhs);
81 
85  virtual bool preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass);
86 
87  static void AddTextureSampleWrapperInvocation(UniformParameterPtr textureSampler,UniformParameterPtr textureSamplerState,
88  GpuConstantType samplerType, Function* function, int groupOrder, int& internalCounter);
89 
90 
91  static ParameterPtr GetSamplerWrapperParam(GpuConstantType samplerType,Function* function);
92 
93  static String Type;
94 
95 // Protected types:
96 protected:
97 
98  // Per texture unit parameters.
99  struct _OgreRTSSExport TextureUnitParams
100  {
101  // Texture unit state.
102  TextureUnitState* mTextureUnitState;
103  // Texture projector.
104  const Frustum* mTextureProjector;
105  // Texture sampler index.
106  unsigned short mTextureSamplerIndex;
107  // Texture sampler index.
108  GpuConstantType mTextureSamplerType;
109  // Vertex shader input texture coordinate type.
110  GpuConstantType mVSInTextureCoordinateType;
111  // Vertex shader output texture coordinates type.
112  GpuConstantType mVSOutTextureCoordinateType;
113  // Texture coordinates calculation method.
114  TexCoordCalcMethod mTexCoordCalcMethod;
115  // Texture matrix parameter.
116  UniformParameterPtr mTextureMatrix;
117  // Texture View Projection Image space matrix parameter.
118  UniformParameterPtr mTextureViewProjImageMatrix;
119  // Texture sampler parameter.
120  UniformParameterPtr mTextureSampler;
121  // Texture sampler state parameter.
122  UniformParameterPtr mTextureSamplerState;
123  // Vertex shader input texture coordinates parameter.
124  ParameterPtr mVSInputTexCoord;
125  // Vertex shader output texture coordinates parameter.
126  ParameterPtr mVSOutputTexCoord;
127  // Pixel shader input texture coordinates parameter.
128  ParameterPtr mPSInputTexCoord;
129  };
130 
131  typedef vector<TextureUnitParams>::type TextureUnitParamsList;
132  typedef TextureUnitParamsList::iterator TextureUnitParamsIterator;
133  typedef TextureUnitParamsList::const_iterator TextureUnitParamsConstIterator;
134 
135 // Protected methods
136 protected:
137 
142  void setTextureUnitCount(size_t count);
143 
147  size_t getTextureUnitCount() const { return mTextureUnitParamsList.size(); }
148 
154  void setTextureUnit(unsigned short index, TextureUnitState* textureUnitState);
155 
159  virtual bool resolveParameters(ProgramSet* programSet);
160 
164  bool resolveUniformParams(TextureUnitParams* textureUnitParams, ProgramSet* programSet);
165 
169  bool resolveFunctionsParams(TextureUnitParams* textureUnitParams, ProgramSet* programSet);
170 
174  virtual bool resolveDependencies(ProgramSet* programSet);
175 
179  virtual bool addFunctionInvocations(ProgramSet* programSet);
180 
181 
185  bool addVSFunctionInvocations(TextureUnitParams* textureUnitParams, Function* vsMain);
186 
190  bool addPSFunctionInvocations(TextureUnitParams* textureUnitParams, Function* psMain, int& internalCounter);
191 
195  virtual void addPSSampleTexelInvocation(TextureUnitParams* textureUnitParams, Function* psMain,
196  const ParameterPtr& texel, int groupOrder, int& internalCounter);
197 
198  virtual void addPSArgumentInvocations(Function* psMain, ParameterPtr arg, ParameterPtr texel,
199  int samplerIndex, LayerBlendSource blendSrc, const ColourValue& colourValue, Real alphaValue,
200  bool isAlphaArgument, const int groupOrder, int& internalCounter);
201 
202  virtual void addPSBlendInvocations(Function* psMain, ParameterPtr arg1, ParameterPtr arg2,
203  ParameterPtr texel,int samplerIndex, const LayerBlendModeEx& blendMode,
204  const int groupOrder, int& internalCounter, int targetChannels);
205 
209  TexCoordCalcMethod getTexCalcMethod(TextureUnitState* textureUnitState);
210 
214  bool needsTextureMatrix(TextureUnitState* textureUnitState);
215 
219  virtual bool isProcessingNeeded(TextureUnitState* texUnitState);
220 
221 
222 // Attributes.
223 protected:
224  // Texture units list.
225  TextureUnitParamsList mTextureUnitParamsList;
226  // World matrix parameter.
227  UniformParameterPtr mWorldMatrix;
228  // World inverse transpose matrix parameter.
229  UniformParameterPtr mWorldITMatrix;
230  // View matrix parameter.
231  UniformParameterPtr mViewMatrix;
232  // Vertex shader input normal parameter.
233  ParameterPtr mVSInputNormal;
234  // Vertex shader input position parameter.
235  ParameterPtr mVSInputPos;
236  // Pixel shader output colour.
237  ParameterPtr mPSOutDiffuse;
238  // Pixel shader diffuse colour.
239  ParameterPtr mPSDiffuse;
240  // Pixel shader specular colour.
241  ParameterPtr mPSSpecular;
242 };
243 
244 
249 class _OgreRTSSExport FFPTexturingFactory : public SubRenderStateFactory
250 {
251 public:
252 
256  virtual const String& getType() const;
257 
261  virtual SubRenderState* createInstance(ScriptCompiler* compiler, PropertyAbstractNode* prop, Pass* pass, SGScriptTranslator* translator);
262 
266  virtual void writeInstance(MaterialSerializer* ser, SubRenderState* subRenderState, Pass* srcPass, Pass* dstPass);
267 
268 
269 protected:
270 
274  virtual SubRenderState* createInstanceImpl();
275 
276 
277 };
278 
283 }
284 }
285 
286 #endif
287 #endif
288 
float Real
Software floating point type.
TexCoordCalcMethod
Enum describing the ways to generate texture coordinates.
#define _OgreRTSSExport
SharedPtr< Parameter > ParameterPtr
HashedVector< LightClosest > LightList
Definition: OgreCommon.h:569
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
LayerBlendSource
List of valid sources of values for blending operations used in TextureUnitState::setColourOperation ...
SharedPtr< UniformParameter > UniformParameterPtr
_StringBase String
Definition: OgreCommon.h:53