OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-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 
316  Parameter(GpuConstantType type, const String& name,
317  const Semantic& semantic, int index,
318  const Content& content, size_t size = 0);
319 
321  virtual ~Parameter() {};
322 
324  const String& getName() const { return mName; }
325 
327  GpuConstantType getType() const { return mType; }
328 
330  const Semantic& getSemantic() const { return mSemantic; }
331 
333  int getIndex() const { return mIndex; }
334 
336  Content getContent() const { return mContent; }
337 
339  virtual bool isConstParameter() const { return false; }
340 
342  virtual String toString() const { return mName; }
343 
345  bool isArray() const { return mSize > 0; }
346 
348  size_t getSize() const { return mSize; }
349 
351  void setSize(size_t size) { mSize = size; }
352 
353 // Attributes.
354 protected:
355  // Name of this parameter.
357  // Type of this parameter.
359  // Semantic of this parameter.
361  // Index of this parameter.
362  int mIndex;
363  // The content of this parameter.
365  // Number of elements in the parameter (for arrays)
366  size_t mSize;
367 
368 };
369 
372 typedef ShaderParameterList::iterator ShaderParameterIterator;
373 typedef ShaderParameterList::const_iterator ShaderParameterConstIterator;
374 
378 {
379 public:
380 
390  UniformParameter(GpuConstantType type, const String& name,
391  const Semantic& semantic, int index,
392  const Content& content,
393  uint16 variability, size_t size);
394 
400  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size);
401 
408  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size, GpuConstantType type);
409 
415  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size);
416 
423  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size, GpuConstantType type);
424 
425 
427  size_t getAutoConstantIntData() const { return mAutoConstantIntData; }
428 
431 
433  bool isFloat() const;
434 
436  bool isSampler() const;
437 
440 
443 
446 
449 
451  uint16 getVariability() const { return mVariability; }
452 
454  void bind(GpuProgramParametersSharedPtr paramsPtr);
455 
456 public:
457 
459  void setGpuParameter(int val)
460  {
461  if (mParamsPtr != NULL)
462  {
464  }
465  }
466 
469  {
470  if (mParamsPtr != NULL)
471  {
473  }
474  }
475 
477  void setGpuParameter(const ColourValue& val)
478  {
479  if (mParamsPtr != NULL)
480  {
482  }
483  }
484 
486  void setGpuParameter(const Vector2& val)
487  {
488  if (mParamsPtr != NULL)
489  {
491  }
492  }
493 
495  void setGpuParameter(const Vector3& val)
496  {
497  if (mParamsPtr != NULL)
498  {
500  }
501  }
502 
504  void setGpuParameter(const Vector4& val)
505  {
506  if (mParamsPtr != NULL)
507  {
509  }
510  }
511 
513  void setGpuParameter(const Matrix4& val)
514  {
515  if (mParamsPtr != NULL)
516  {
518  }
519  }
520 
522  void setGpuParameter(const float *val, size_t count, size_t multiple = 4)
523  {
524  if (mParamsPtr != NULL)
525  {
526  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
527  }
528  }
529 
531  void setGpuParameter(const double *val, size_t count, size_t multiple = 4)
532  {
533  if (mParamsPtr != NULL)
534  {
535  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
536  }
537  }
538 
540  void setGpuParameter(const int *val, size_t count, size_t multiple = 4)
541  {
542  if (mParamsPtr != NULL)
543  {
544  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
545  }
546  }
547 
548 protected:
549  // Is it auto constant real based parameter.
551  // Is it auto constant int based parameter.
553  GpuProgramParameters::AutoConstantType mAutoConstantType; // The auto constant type of this parameter.
554  union
555  {
556  // Auto constant int data.
558  // Auto constant real data.
560  };
561  // How this parameter varies (bitwise combination of GpuProgramVariability).
563  // The actual GPU parameters pointer.
565  // The physical index of this parameter in the GPU program.
567 };
568 
571 typedef UniformParameterList::iterator UniformParameterIterator;
572 typedef UniformParameterList::const_iterator UniformParameterConstIterator;
573 
576 template <class valueType>
577 class ConstParameter : public Parameter
578 {
579 public:
580 
581  ConstParameter( valueType val,
582  GpuConstantType type,
583  const Semantic& semantic,
584  const Content& content)
585  : Parameter(type, "Constant", semantic, 0, content)
586  {
587  mValue = val;
588  }
589 
590  virtual ~ConstParameter () {}
591 
593  const valueType& getValue() const { return mValue; }
594 
598  virtual bool isConstParameter() const { return true; }
599 
603  virtual String toString() const = 0;
604 
605 protected:
606  valueType mValue;
607 };
608 
612 {
613 
614  // Interface.
615 public:
616 
617  static ParameterPtr createInPosition(int index);
618  static ParameterPtr createOutPosition(int index);
619 
620  static ParameterPtr createInNormal(int index);
621  static ParameterPtr createInWeights(int index);
622  static ParameterPtr createInIndices(int index);
623  static ParameterPtr createOutNormal(int index);
624  static ParameterPtr createInBiNormal(int index);
625  static ParameterPtr createOutBiNormal(int index);
626  static ParameterPtr createInTangent(int index);
627  static ParameterPtr createOutTangent(int index);
628  static ParameterPtr createInColor(int index);
629  static ParameterPtr createOutColor(int index);
630 
631  static ParameterPtr createInTexcoord(GpuConstantType type, int index, Parameter::Content content);
632  static ParameterPtr createOutTexcoord(GpuConstantType type, int index, Parameter::Content content);
633  static ParameterPtr createInTexcoord1(int index, Parameter::Content content);
634  static ParameterPtr createOutTexcoord1(int index, Parameter::Content content);
635  static ParameterPtr createInTexcoord2(int index, Parameter::Content content);
636  static ParameterPtr createOutTexcoord2(int index, Parameter::Content content);
637  static ParameterPtr createInTexcoord3(int index, Parameter::Content content);
638  static ParameterPtr createOutTexcoord3(int index, Parameter::Content content);
639  static ParameterPtr createInTexcoord4(int index, Parameter::Content content);
640  static ParameterPtr createOutTexcoord4(int index, Parameter::Content content);
641 
642  static ParameterPtr createConstParamVector2(Vector2 val);
643  static ParameterPtr createConstParamVector3(Vector3 val);
644  static ParameterPtr createConstParamVector4(Vector4 val);
645  static ParameterPtr createConstParamFloat(float val);
646 
647  static UniformParameterPtr createSampler(GpuConstantType type, int index);
648  static UniformParameterPtr createSampler1D(int index);
649  static UniformParameterPtr createSampler2D(int index);
650  static UniformParameterPtr createSampler2DArray(int index);
651  static UniformParameterPtr createSampler3D(int index);
652  static UniformParameterPtr createSamplerCUBE(int index);
653 
654  static UniformParameterPtr createUniform(GpuConstantType type, int index, uint16 variability, const String& suggestedName, size_t size);
655 };
656 
657 
658 
662 }
663 }
664 
665 #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
size_t getSize() const
Returns the number of elements in the parameter (for arrays).
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 double *val, size_t count, size_t multiple=4)
Update the GPU parameter with the given value.
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
void setSize(size_t size)
Sets the number of elements in the parameter (for arrays).
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.
void setGpuParameter(const float *val, size_t count, size_t multiple=4)
Update the GPU parameter with the given value.
virtual String toString() const
Returns the string representation of this parameter.
bool isArray() const
Returns Whether this parameter is an array.
void setGpuParameter(const int *val, size_t count, size_t multiple=4)
Update the GPU parameter with the given value.
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...
UniformParameter(GpuConstantType type, const String &name, const Semantic &semantic, int index, const Content &content, uint16 variability, size_t size)
Class constructor.
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:271
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)