OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreShaderParameter.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 _ShaderParameter_
28 #define _ShaderParameter_
29 
31 #include "OgreGpuProgram.h"
32 #include "OgreVector2.h"
33 #include "OgreVector3.h"
34 #include "OgreVector4.h"
35 #include "OgreMatrix4.h"
36 
37 namespace Ogre {
38 namespace RTShader {
39 
50 {
51 public:
52  // Shader parameter semantic.
53  enum Semantic
54  {
56  SPS_UNKNOWN = 0,
58  SPS_POSITION = 1,
60  SPS_BLEND_WEIGHTS = 2,
62  SPS_BLEND_INDICES = 3,
64  SPS_NORMAL = 4,
66  SPS_COLOR = 5,
68  SPS_TEXTURE_COORDINATES = 7,
70  SPS_BINORMAL = 8,
72  SPS_TANGENT = 9
73  };
74 
75  // Shader parameter content.
76  enum Content
77  {
80 
83 
86 
89 
92 
102 
105 
108 
111 
114 
117 
120 
123 
126 
136 
146 
156 
166 
167 
168 
178 
188 
198 
208 
218 
228 
238 
241 
244 
247 
250 
253 
256 
259 
262 
265 
275 
277  SPC_CUSTOM_CONTENT_BEGIN = 1000,
278  SPC_CUSTOM_CONTENT_END = 2000
279  };
280 
281 // Interface.
282 public:
285 
294  Parameter(GpuConstantType type, const String& name,
295  const Semantic& semantic, int index,
296  const Content& content);
297 
299  virtual ~Parameter() {};
300 
302  const String& getName () const { return mName; }
303 
305  GpuConstantType getType () const { return mType; }
306 
308  const Semantic& getSemantic () const { return mSemantic; }
309 
311  int getIndex () const { return mIndex; }
312 
314  Content getContent () const { return mContent; }
315 
317  virtual bool isConstParameter () const { return false; }
318 
320  virtual String toString () const { return mName; }
321 
322 // Attributes.
323 protected:
324  String mName; // Name of this parameter.
325  GpuConstantType mType; // Type of this parameter.
326  Semantic mSemantic; // Semantic of this parameter.
327  int mIndex; // Index of this parameter.
328  Content mContent; // The content of this parameter.
329 
330 };
331 
334 typedef ShaderParameterList::iterator ShaderParameterIterator;
335 typedef ShaderParameterList::const_iterator ShaderParameterConstIterator;
336 
340 {
341 public:
342 
351  UniformParameter(GpuConstantType type, const String& name,
352  const Semantic& semantic, int index,
353  const Content& content,
354  uint16 variability);
355 
360  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData);
361 
366  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData);
367 
368 
370  size_t getAutoConstantIntData () const { return mAutoConstantIntData; }
371 
374 
376  bool isFloat () const;
377 
379  bool isSampler () const;
380 
383 
386 
389 
392 
394  uint16 getVariability () const { return mVariability; }
395 
396 
398  void bind (GpuProgramParametersSharedPtr paramsPtr);
399 
400 public:
401 
403  void setGpuParameter(int val)
404  {
405  if (mParamsPtr != NULL)
406  {
408  }
409  }
410 
413  {
414  if (mParamsPtr != NULL)
415  {
417  }
418  }
419 
421  void setGpuParameter(const ColourValue& val)
422  {
423  if (mParamsPtr != NULL)
424  {
426  }
427  }
428 
430  void setGpuParameter(const Vector2& val)
431  {
432  if (mParamsPtr != NULL)
433  {
435  }
436  }
437 
439  void setGpuParameter(const Vector3& val)
440  {
441  if (mParamsPtr != NULL)
442  {
444  }
445  }
446 
448  void setGpuParameter(const Vector4& val)
449  {
450  if (mParamsPtr != NULL)
451  {
453  }
454  }
455 
457  void setGpuParameter(const Matrix4& val)
458  {
459  if (mParamsPtr != NULL)
460  {
462  }
463  }
464 
465 protected:
466  bool mIsAutoConstantReal; // Is it auto constant real based parameter.
467  bool mIsAutoConstantInt; // Is it auto constant int based parameter.
468  GpuProgramParameters::AutoConstantType mAutoConstantType; // The auto constant type of this parameter.
469  union
470  {
471  size_t mAutoConstantIntData; // Auto constant int data.
472  Real mAutoConstantRealData; // Auto constant real data.
473  };
474  uint16 mVariability; // How this parameter varies (bitwise combination of GpuProgramVariability).
475  GpuProgramParameters* mParamsPtr; // The actual GPU parameters pointer.
476  size_t mPhysicalIndex; // The physical index of this parameter in the GPU program.
477 
478 };
479 
482 typedef UniformParameterList::iterator UniformParameterIterator;
483 typedef UniformParameterList::const_iterator UniformParameterConstIterator;
484 
487 template <class valueType>
488 class ConstParameter : public Parameter
489 {
490 public:
491 
492  ConstParameter( valueType val,
493  GpuConstantType type,
494  const Semantic& semantic,
495  const Content& content)
496  : Parameter(type, "Constant", semantic, 0, content)
497  {
498  mValue = val;
499  }
500 
501  virtual ~ConstParameter () {}
502 
504  const valueType& getValue () const { return mValue; }
505 
509  virtual bool isConstParameter () const { return true; }
510 
514  virtual String toString () const = 0;
515 
516 protected:
517  valueType mValue;
518 };
519 
523 {
524 
525  // Interface.
526 public:
527 
528  static ParameterPtr createInPosition (int index);
529  static ParameterPtr createOutPosition (int index);
530 
531  static ParameterPtr createInNormal (int index);
532  static ParameterPtr createOutNormal (int index);
533  static ParameterPtr createInBiNormal (int index);
534  static ParameterPtr createOutBiNormal (int index);
535  static ParameterPtr createInTangent (int index);
536  static ParameterPtr createOutTangent (int index);
537  static ParameterPtr createInColor (int index);
538  static ParameterPtr createOutColor (int index);
539 
540  static ParameterPtr createInTexcoord (GpuConstantType type, int index, Parameter::Content content);
541  static ParameterPtr createOutTexcoord (GpuConstantType type, int index, Parameter::Content content);
542  static ParameterPtr createInTexcoord1 (int index, Parameter::Content content);
543  static ParameterPtr createOutTexcoord1 (int index, Parameter::Content content);
544  static ParameterPtr createInTexcoord2 (int index, Parameter::Content content);
545  static ParameterPtr createOutTexcoord2 (int index, Parameter::Content content);
546  static ParameterPtr createInTexcoord3 (int index, Parameter::Content content);
547  static ParameterPtr createOutTexcoord3 (int index, Parameter::Content content);
548  static ParameterPtr createInTexcoord4 (int index, Parameter::Content content);
549  static ParameterPtr createOutTexcoord4 (int index, Parameter::Content content);
550 
551  static ParameterPtr createConstParamVector2 (Vector2 val);
552  static ParameterPtr createConstParamVector3 (Vector3 val);
553  static ParameterPtr createConstParamVector4 (Vector4 val);
554  static ParameterPtr createConstParamFloat (float val);
555 
556  static UniformParameterPtr createSampler (GpuConstantType type, int index);
557  static UniformParameterPtr createSampler1D (int index);
558  static UniformParameterPtr createSampler2D (int index);
559  static UniformParameterPtr createSampler3D (int index);
560  static UniformParameterPtr createSamplerCUBE (int index);
561 
562  static UniformParameterPtr createUniform (GpuConstantType type, int index, uint16 variability, const String& suggestedName);
563 };
564 
565 
566 
570 }
571 }
572 
573 #endif
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
bool isFloat() const
Return true if this parameter is a floating point type, false otherwise.
GpuProgramParameters::AutoConstantType mAutoConstantType
bool isSampler() const
Return true if this parameter is a texture sampler type, false otherwise.
vector< ParameterPtr >::type ShaderParameterList
size_t getAutoConstantIntData() const
Get auto constant int data of this parameter, in case it is auto constant parameter.
virtual String toString() const =0
virtual bool isConstParameter() const
Class representing colour.
void setGpuParameter(const Matrix4 &val)
Update the GPU parameter with the given value.
void setGpuParameter(const Vector2 &val)
Update the GPU parameter with the given value.
SharedPtr< Parameter > ParameterPtr
void setGpuParameter(Real val)
Update the GPU parameter with the given value.
uint16 getVariability() const
Return the variability of this parameter.
bool isAutoConstantParameter() const
Return true if this parameter is an auto constant parameter, false otherwise.
#define _OgreRTSSExport
bool isAutoConstantRealParameter() const
Return true if this parameter an auto constant with real data type, false otherwise.
virtual bool isConstParameter() const
Returns true if this instance is a ConstParameter otherwise false.
void setGpuParameter(const Vector4 &val)
Update the GPU parameter with the given value.
AutoConstantType
Defines the types of automatically updated values that may be bound to GpuProgram parameters...
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
Real getAutoConstantRealData() const
Get auto constant real data of this parameter, in case it is auto constant parameter.
A class that represents a shader based program parameter.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
vector< UniformParameterPtr >::type UniformParameterList
Collects together the program parameters used for a GpuProgram.
Standard 2-dimensional vector.
Definition: OgreVector2.h:51
int getIndex() const
Get the index of this parameter.
ShaderParameterList::iterator ShaderParameterIterator
const Semantic & getSemantic() const
Get the semantic of this parameter.
Helper utility class that creates common parameters.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
UniformParameterList::const_iterator UniformParameterConstIterator
virtual ~Parameter()
Class destructor.
void setGpuParameter(const ColourValue &val)
Update the GPU parameter with the given value.
void _writeRawConstants(size_t physicalIndex, const float *val, size_t count)
Write a series of floating point values into the underlying float constant buffer at the given physic...
const String & getName() const
Get the name of this parameter.
GpuProgramParameters::AutoConstantType getAutoConstantType() const
Return the auto constant type of this parameter.
GpuConstantType getType() const
Get the type of this parameter.
virtual String toString() const
Returns the string representation of this parameter.
UniformParameter(GpuConstantType type, const String &name, const Semantic &semantic, int index, const Content &content, uint16 variability)
Class constructor.
void _writeRawConstant(size_t physicalIndex, const Vector4 &vec, size_t count=4)
Write a 4-element floating-point parameter to the program directly to the underlying constants buffer...
ShaderParameterList::const_iterator ShaderParameterConstIterator
Content getContent() const
Return the content of this parameter.
_StringBase String
void setGpuParameter(const Vector3 &val)
Update the GPU parameter with the given value.
void bind(GpuProgramParametersSharedPtr paramsPtr)
Bind this parameter to the corresponding GPU parameter.
Helper template which is the base for our ConstParameters.
const valueType & getValue() const
Returns the native value of this parameter.
unsigned short uint16
Definition: OgrePlatform.h:247
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
bool isAutoConstantIntParameter() const
Return true if this parameter an auto constant with int data type, false otherwise.
SharedPtr< UniformParameter > UniformParameterPtr
void setGpuParameter(int val)
Update the GPU parameter with the given value.
UniformParameterList::iterator UniformParameterIterator
Real * ptr()
Pointer accessor for direct copying.
Definition: OgreVector2.h:111
ConstParameter(valueType val, GpuConstantType type, const Semantic &semantic, const Content &content)