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-2013 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 
176 
186 
196 
206 
216 
226 
236 
239 
242 
245 
248 
251 
254 
257 
260 
263 
266 
269 
272 
275 
278 
281 
284 
287 
297 
299  SPC_CUSTOM_CONTENT_BEGIN = 1000,
300  SPC_CUSTOM_CONTENT_END = 2000
301  };
302 
303 // Interface.
304 public:
307 
315  Parameter(GpuConstantType type, const String& name,
316  const Semantic& semantic, int index,
317  const Content& content, size_t size = 0);
318 
320  virtual ~Parameter() {};
321 
323  const String& getName() const { return mName; }
324 
326  GpuConstantType getType() const { return mType; }
327 
329  const Semantic& getSemantic() const { return mSemantic; }
330 
332  int getIndex() const { return mIndex; }
333 
335  Content getContent() const { return mContent; }
336 
338  virtual bool isConstParameter() const { return false; }
339 
341  virtual String toString() const { return mName; }
342 
344  bool isArray() const { return mSize > 0; }
345 
347  size_t getSize() const { return mSize; }
348 
350  void setSize(size_t size) { mSize = size; }
351 
352 // Attributes.
353 protected:
354  // Name of this parameter.
356  // Type of this parameter.
358  // Semantic of this parameter.
360  // Index of this parameter.
361  int mIndex;
362  // The content of this parameter.
364  // Number of elements in the parameter (for arrays)
365  size_t mSize;
366 
367 };
368 
371 typedef ShaderParameterList::iterator ShaderParameterIterator;
372 typedef ShaderParameterList::const_iterator ShaderParameterConstIterator;
373 
377 {
378 public:
379 
390  const Semantic& semantic, int index,
391  const Content& content,
392  uint16 variability, size_t size);
393 
399  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size);
400 
407  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size, GpuConstantType type);
408 
414  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size);
415 
422  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size, GpuConstantType type);
423 
424 
426  size_t getAutoConstantIntData() const { return mAutoConstantIntData; }
427 
429  Real getAutoConstantRealData() const { return mAutoConstantRealData; }
430 
432  bool isFloat() const;
433 
435  bool isSampler() const;
436 
438  bool isAutoConstantParameter() const { return mIsAutoConstantReal || mIsAutoConstantInt; }
439 
441  bool isAutoConstantIntParameter() const { return mIsAutoConstantInt; }
442 
444  bool isAutoConstantRealParameter() const { return mIsAutoConstantReal; }
445 
447  GpuProgramParameters::AutoConstantType getAutoConstantType () const { return mAutoConstantType; }
448 
450  uint16 getVariability() const { return mVariability; }
451 
454 
455 public:
456 
458  void setGpuParameter(int val)
459  {
460  if (mParamsPtr != NULL)
461  {
462  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
463  }
464  }
465 
468  {
469  if (mParamsPtr != NULL)
470  {
471  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
472  }
473  }
474 
476  void setGpuParameter(const ColourValue& val)
477  {
478  if (mParamsPtr != NULL)
479  {
480  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
481  }
482  }
483 
485  void setGpuParameter(const Vector2& val)
486  {
487  if (mParamsPtr != NULL)
488  {
489  mParamsPtr->_writeRawConstants(mPhysicalIndex, val.ptr(), 2);
490  }
491  }
492 
494  void setGpuParameter(const Vector3& val)
495  {
496  if (mParamsPtr != NULL)
497  {
498  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
499  }
500  }
501 
503  void setGpuParameter(const Vector4& val)
504  {
505  if (mParamsPtr != NULL)
506  {
507  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
508  }
509  }
510 
512  void setGpuParameter(const Matrix4& val)
513  {
514  if (mParamsPtr != NULL)
515  {
516  mParamsPtr->_writeRawConstant(mPhysicalIndex, val, 16);
517  }
518  }
519 
521  void setGpuParameter(const float *val, size_t count, size_t multiple = 4)
522  {
523  if (mParamsPtr != NULL)
524  {
525  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
526  }
527  }
528 
530  void setGpuParameter(const double *val, size_t count, size_t multiple = 4)
531  {
532  if (mParamsPtr != NULL)
533  {
534  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
535  }
536  }
537 
539  void setGpuParameter(const int *val, size_t count, size_t multiple = 4)
540  {
541  if (mParamsPtr != NULL)
542  {
543  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
544  }
545  }
546 
547 protected:
548  // Is it auto constant real based parameter.
550  // Is it auto constant int based parameter.
552  GpuProgramParameters::AutoConstantType mAutoConstantType; // The auto constant type of this parameter.
553  union
554  {
555  // Auto constant int data.
557  // Auto constant real data.
559  };
560  // How this parameter varies (bitwise combination of GpuProgramVariability).
562  // The actual GPU parameters pointer.
564  // The physical index of this parameter in the GPU program.
566 };
567 
570 typedef UniformParameterList::iterator UniformParameterIterator;
571 typedef UniformParameterList::const_iterator UniformParameterConstIterator;
572 
575 template <class valueType>
576 class ConstParameter : public Parameter
577 {
578 public:
579 
580  ConstParameter( valueType val,
581  GpuConstantType type,
582  const Semantic& semantic,
583  const Content& content)
584  : Parameter(type, "Constant", semantic, 0, content)
585  {
586  mValue = val;
587  }
588 
589  virtual ~ConstParameter () {}
590 
592  const valueType& getValue() const { return mValue; }
593 
597  virtual bool isConstParameter() const { return true; }
598 
602  virtual String toString() const = 0;
603 
604 protected:
605  valueType mValue;
606 };
607 
611 {
612 
613  // Interface.
614 public:
615 
616  static ParameterPtr createInPosition(int index);
617  static ParameterPtr createOutPosition(int index);
618 
619  static ParameterPtr createInNormal(int index);
620  static ParameterPtr createInWeights(int index);
621  static ParameterPtr createInIndices(int index);
622  static ParameterPtr createOutNormal(int index);
623  static ParameterPtr createInBiNormal(int index);
624  static ParameterPtr createOutBiNormal(int index);
625  static ParameterPtr createInTangent(int index);
626  static ParameterPtr createOutTangent(int index);
627  static ParameterPtr createInColor(int index);
628  static ParameterPtr createOutColor(int index);
629 
638  static ParameterPtr createInTexcoord4(int index, Parameter::Content content);
640 
645 
652 
653  static UniformParameterPtr createUniform(GpuConstantType type, int index, uint16 variability, const String& suggestedName, size_t size);
654 };
655 
656 
657 
661 }
662 }
663 
664 #endif
#define _OgreRTSSExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Class representing colour.
Collects together the program parameters used for a GpuProgram.
AutoConstantType
Defines the types of automatically updated values that may be bound to GpuProgram parameters,...
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Helper template which is the base for our ConstParameters.
const valueType & getValue() const
Returns the native value of this parameter.
virtual String toString() const =0
ConstParameter(valueType val, GpuConstantType type, const Semantic &semantic, const Content &content)
virtual bool isConstParameter() const
Helper utility class that creates common parameters.
static UniformParameterPtr createSampler(GpuConstantType type, int index)
static ParameterPtr createInColor(int index)
static ParameterPtr createConstParamVector2(Vector2 val)
static ParameterPtr createOutNormal(int index)
static UniformParameterPtr createSampler2DArray(int index)
static ParameterPtr createInWeights(int index)
static ParameterPtr createOutTexcoord2(int index, Parameter::Content content)
static UniformParameterPtr createUniform(GpuConstantType type, int index, uint16 variability, const String &suggestedName, size_t size)
static ParameterPtr createInTangent(int index)
static UniformParameterPtr createSampler2D(int index)
static ParameterPtr createInNormal(int index)
static UniformParameterPtr createSampler1D(int index)
static ParameterPtr createInTexcoord1(int index, Parameter::Content content)
static ParameterPtr createInTexcoord3(int index, Parameter::Content content)
static UniformParameterPtr createSampler3D(int index)
static ParameterPtr createInBiNormal(int index)
static ParameterPtr createInTexcoord4(int index, Parameter::Content content)
static ParameterPtr createConstParamVector4(Vector4 val)
static ParameterPtr createOutTexcoord3(int index, Parameter::Content content)
static ParameterPtr createInIndices(int index)
static ParameterPtr createInTexcoord2(int index, Parameter::Content content)
static ParameterPtr createOutTexcoord4(int index, Parameter::Content content)
static ParameterPtr createOutPosition(int index)
static ParameterPtr createInPosition(int index)
static UniformParameterPtr createSamplerCUBE(int index)
static ParameterPtr createOutTangent(int index)
static ParameterPtr createOutTexcoord(GpuConstantType type, int index, Parameter::Content content)
static ParameterPtr createOutBiNormal(int index)
static ParameterPtr createConstParamVector3(Vector3 val)
static ParameterPtr createOutColor(int index)
static ParameterPtr createInTexcoord(GpuConstantType type, int index, Parameter::Content content)
static ParameterPtr createOutTexcoord1(int index, Parameter::Content content)
static ParameterPtr createConstParamFloat(float val)
A class that represents a shader based program parameter.
virtual ~Parameter()
Class destructor.
void setSize(size_t size)
Sets the number of elements in the parameter (for arrays).
virtual String toString() const
Returns the string representation of this parameter.
bool isArray() const
Returns Whether this parameter is an array.
const String & getName() const
Get the name of this parameter.
@ SPC_DEPTH_WORLD_SPACE
Depth in world space.
@ SPC_NORMAL_VIEW_SPACE
Normal in view space.
@ SPC_POSTOLIGHT_TANGENT_SPACE0
Light vector in tangent space index 0-7.
@ SPC_POSTOLIGHT_VIEW_SPACE0
Light vector in view space index 0-7.
@ SPC_BLEND_INDICES
Blending indices.
@ SPC_POSTOCAMERA_VIEW_SPACE
View vector in view space.
@ SPC_BINORMAL_WORLD_SPACE
Binormal in world space.
@ SPC_POSTOLIGHT_OBJECT_SPACE0
Light vector in object space index 0-7.
@ SPC_POSTOCAMERA_WORLD_SPACE
View vector in world space.
@ SPC_POSITION_WORLD_SPACE
Position in world space.
@ SPC_NORMAL_OBJECT_SPACE
Normal in object space.
@ SPC_TANGENT_WORLD_SPACE
Tangent in world space.
@ SPC_BINORMAL_OBJECT_SPACE
Binormal in object space.
@ SPC_POSTOLIGHT_WORLD_SPACE0
Light vector in world space index 0-7.
@ SPC_POSITION_VIEW_SPACE
Position in view space.
@ SPC_NORMAL_TANGENT_SPACE
Normal in tangent space.
@ SPC_LIGHTPOSITIONVIEW_SPACE0
Light position in view space index 0-7.
@ SPC_BLEND_WEIGHTS
Blending weights.
@ SPC_DEPTH_PROJECTIVE_SPACE
Depth in projective space.
@ SPC_LIGHTPOSITION_OBJECT_SPACE0
Light position in object space index 0-7.
@ SPC_DEPTH_VIEW_SPACE
Depth in view space.
@ SPC_POSTOCAMERA_OBJECT_SPACE
View vector in object space.
@ SPC_LIGHTPOSITION_WORLD_SPACE0
Light position in world space index 0-7.
@ SPC_POSTOCAMERA_TANGENT_SPACE
View vector in tangent space.
@ SPC_TANGENT_TANGENT_SPACE
Tangent in tangent space.
@ SPC_POSITION_PROJECTIVE_SPACE
Position in projective space.
@ SPC_LIGHTPOSITION_TANGENT_SPACE
Light position in tangent space index 0-7.
@ SPC_TEXTURE_COORDINATE0
Texture coordinate set index 0-7.
@ SPC_LIGHTDIRECTION_TANGENT_SPACE0
Light direction in tangent space index 0-7.
@ SPC_POSITION_OBJECT_SPACE
Position in object space.
@ SPC_TANGENT_OBJECT_SPACE
Tangent in object space.
@ SPC_LIGHTDIRECTION_WORLD_SPACE0
Light direction in world space index 0-7.
@ SPC_TANGENT_VIEW_SPACE
Tangent in view space.
@ SPC_NORMAL_WORLD_SPACE
Normal in world space.
@ SPC_LIGHTDIRECTION_OBJECT_SPACE0
Light direction in object space index 0-7.
@ SPC_COLOR_SPECULAR
Specular color.
@ SPC_LIGHTDIRECTION_VIEW_SPACE0
Light direction in view space index 0-7.
@ SPC_BINORMAL_TANGENT_SPACE
Binormal in tangent space.
@ SPC_DEPTH_OBJECT_SPACE
Depth in object space.
@ SPC_BINORMAL_VIEW_SPACE
Binormal in view space.
@ SPC_POSITION_LIGHT_SPACE0
Position in light space index 0-7.
const Semantic & getSemantic() const
Get the semantic of this parameter.
int getIndex() const
Get the index of this parameter.
virtual bool isConstParameter() const
Returns true if this instance is a ConstParameter otherwise false.
GpuConstantType getType() const
Get the type of this parameter.
Parameter(GpuConstantType type, const String &name, const Semantic &semantic, int index, const Content &content, size_t size=0)
Class constructor.
Content getContent() const
Return the content of this parameter.
size_t getSize() const
Returns the number of elements in the parameter (for arrays).
void setGpuParameter(const Vector2 &val)
Update the GPU parameter with the given value.
void setGpuParameter(const Vector4 &val)
Update the GPU parameter with the given value.
void setGpuParameter(int val)
Update the GPU parameter with the given value.
GpuProgramParameters::AutoConstantType mAutoConstantType
void setGpuParameter(const Matrix4 &val)
Update the GPU parameter with the given value.
UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size, GpuConstantType type)
Class constructor.
void setGpuParameter(const float *val, size_t count, size_t multiple=4)
Update the GPU parameter with the given value.
UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size)
Class constructor.
UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size)
Class constructor.
UniformParameter(GpuConstantType type, const String &name, const Semantic &semantic, int index, const Content &content, uint16 variability, size_t size)
Class constructor.
size_t getAutoConstantIntData() const
Get auto constant int data of this parameter, in case it is auto constant parameter.
uint16 getVariability() const
Return the variability of this parameter.
bool isFloat() const
Return true if this parameter is a floating point type, false otherwise.
void setGpuParameter(const double *val, size_t count, size_t multiple=4)
Update the GPU parameter with the given value.
bool isSampler() const
Return true if this parameter is a texture sampler type, false otherwise.
bool isAutoConstantIntParameter() const
Return true if this parameter an auto constant with int data type, false otherwise.
bool isAutoConstantParameter() const
Return true if this parameter is an auto constant parameter, false otherwise.
Real getAutoConstantRealData() const
Get auto constant real data of this parameter, in case it is auto constant parameter.
UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size, GpuConstantType type)
Class constructor.
void setGpuParameter(const Vector3 &val)
Update the GPU parameter with the given value.
GpuProgramParameters::AutoConstantType getAutoConstantType() const
Return the auto constant type of this parameter.
void setGpuParameter(Real val)
Update the GPU parameter with the given value.
void bind(GpuProgramParametersSharedPtr paramsPtr)
Bind this parameter to the corresponding GPU parameter.
void setGpuParameter(const int *val, size_t count, size_t multiple=4)
Update the GPU parameter with the given value.
bool isAutoConstantRealParameter() const
Return true if this parameter an auto constant with real data type, false otherwise.
void setGpuParameter(const ColourValue &val)
Update the GPU parameter with the given value.
Standard 2-dimensional vector.
Definition: OgreVector2.h:52
Real * ptr()
Pointer accessor for direct copying.
Definition: OgreVector2.h:115
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
4-dimensional homogeneous vector.
Definition: OgreVector4.h:46
GpuConstantType
Enumeration of the types of constant we may encounter in programs.
ShaderParameterList::iterator ShaderParameterIterator
UniformParameterList::const_iterator UniformParameterConstIterator
UniformParameterList::iterator UniformParameterIterator
vector< ParameterPtr >::type ShaderParameterList
vector< UniformParameterPtr >::type UniformParameterList
SharedPtr< Parameter > ParameterPtr
ShaderParameterList::const_iterator ShaderParameterConstIterator
SharedPtr< UniformParameter > UniformParameterPtr
float Real
Software floating point type.
unsigned short uint16
Definition: OgrePlatform.h:360
_StringBase String

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.