OGRE  2.0
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-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 _ShaderParameter_
28 #define _ShaderParameter_
29 
31 #include "OgreVector2.h"
32 #include "OgreMatrix4.h"
33 #include "OgreGpuProgramParams.h"
34 
35 namespace Ogre {
36 namespace RTShader {
37 
48 {
49 public:
50  // Shader parameter semantic.
51  enum Semantic
52  {
54  SPS_UNKNOWN = 0,
56  SPS_POSITION = 1,
58  SPS_BLEND_WEIGHTS = 2,
60  SPS_BLEND_INDICES = 3,
62  SPS_NORMAL = 4,
64  SPS_COLOR = 5,
66  SPS_TEXTURE_COORDINATES = 7,
68  SPS_BINORMAL = 8,
70  SPS_TANGENT = 9
71  };
72 
73  // Shader parameter content.
74  enum Content
75  {
78 
81 
84 
87 
90 
100 
103 
106 
109 
112 
115 
118 
121 
124 
134 
144 
154 
164 
174 
184 
194 
204 
214 
224 
234 
237 
240 
243 
246 
249 
252 
255 
258 
261 
264 
267 
270 
273 
276 
279 
282 
285 
295 
297  SPC_CUSTOM_CONTENT_BEGIN = 1000,
298  SPC_CUSTOM_CONTENT_END = 2000
299  };
300 
301 // Interface.
302 public:
304  Parameter();
305 
313  Parameter(GpuConstantType type, const String& name,
314  const Semantic& semantic, int index,
315  const Content& content, size_t size = 0);
316 
318  virtual ~Parameter() {};
319 
321  const String& getName() const { return mName; }
322 
324  GpuConstantType getType() const { return mType; }
325 
327  const Semantic& getSemantic() const { return mSemantic; }
328 
330  int getIndex() const { return mIndex; }
331 
333  Content getContent() const { return mContent; }
334 
336  virtual bool isConstParameter() const { return false; }
337 
339  virtual String toString() const { return mName; }
340 
342  bool isArray() const { return mSize > 0; }
343 
345  size_t getSize() const { return mSize; }
346 
348  void setSize(size_t size) { mSize = size; }
349 
350 // Attributes.
351 protected:
352  // Name of this parameter.
354  // Type of this parameter.
356  // Semantic of this parameter.
358  // Index of this parameter.
359  int mIndex;
360  // The content of this parameter.
362  // Number of elements in the parameter (for arrays)
363  size_t mSize;
364 
365 };
366 
367 typedef ShaderParameterList::iterator ShaderParameterIterator;
368 typedef ShaderParameterList::const_iterator ShaderParameterConstIterator;
369 
373 {
374 public:
375 
385  UniformParameter(GpuConstantType type, const String& name,
386  const Semantic& semantic, int index,
387  const Content& content,
388  uint16 variability, size_t size);
389 
395  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size);
396 
403  UniformParameter(GpuProgramParameters::AutoConstantType autoType, Real fAutoConstantData, size_t size, GpuConstantType type);
404 
410  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size);
411 
418  UniformParameter(GpuProgramParameters::AutoConstantType autoType, size_t nAutoConstantData, size_t size, GpuConstantType type);
419 
420 
422  size_t getAutoConstantIntData() const { return mAutoConstantIntData; }
423 
425  Real getAutoConstantRealData() const { return mAutoConstantRealData; }
426 
428  bool isFloat() const;
429 
431  bool isSampler() const;
432 
434  bool isAutoConstantParameter() const { return mIsAutoConstantReal || mIsAutoConstantInt; }
435 
437  bool isAutoConstantIntParameter() const { return mIsAutoConstantInt; }
438 
440  bool isAutoConstantRealParameter() const { return mIsAutoConstantReal; }
441 
443  GpuProgramParameters::AutoConstantType getAutoConstantType () const { return mAutoConstantType; }
444 
446  uint16 getVariability() const { return mVariability; }
447 
449  void bind(GpuProgramParametersSharedPtr paramsPtr);
450 
451 public:
452 
454  void setGpuParameter(int val)
455  {
456  if (mParamsPtr != NULL)
457  {
458  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
459  }
460  }
461 
464  {
465  if (mParamsPtr != NULL)
466  {
467  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
468  }
469  }
470 
472  void setGpuParameter(const ColourValue& val)
473  {
474  if (mParamsPtr != NULL)
475  {
476  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
477  }
478  }
479 
481  void setGpuParameter(const Vector2& val)
482  {
483  if (mParamsPtr != NULL)
484  {
485  mParamsPtr->_writeRawConstants(mPhysicalIndex, val.ptr(), 2);
486  }
487  }
488 
490  void setGpuParameter(const Vector3& val)
491  {
492  if (mParamsPtr != NULL)
493  {
494  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
495  }
496  }
497 
499  void setGpuParameter(const Vector4& val)
500  {
501  if (mParamsPtr != NULL)
502  {
503  mParamsPtr->_writeRawConstant(mPhysicalIndex, val);
504  }
505  }
506 
508  void setGpuParameter(const Matrix4& val)
509  {
510  if (mParamsPtr != NULL)
511  {
512  mParamsPtr->_writeRawConstant(mPhysicalIndex, val, 16);
513  }
514  }
515 
517  void setGpuParameter(const float *val, size_t count, size_t multiple = 4)
518  {
519  if (mParamsPtr != NULL)
520  {
521  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
522  }
523  }
524 
526  void setGpuParameter(const double *val, size_t count, size_t multiple = 4)
527  {
528  if (mParamsPtr != NULL)
529  {
530  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
531  }
532  }
533 
535  void setGpuParameter(const int *val, size_t count, size_t multiple = 4)
536  {
537  if (mParamsPtr != NULL)
538  {
539  mParamsPtr->_writeRawConstants(mPhysicalIndex, val, count * multiple);
540  }
541  }
542 
543 protected:
544  // Is it auto constant real based parameter.
546  // Is it auto constant int based parameter.
548  GpuProgramParameters::AutoConstantType mAutoConstantType; // The auto constant type of this parameter.
549  union
550  {
551  // Auto constant int data.
553  // Auto constant real data.
555  };
556  // How this parameter varies (bitwise combination of GpuProgramVariability).
558  // The actual GPU parameters pointer.
560  // The physical index of this parameter in the GPU program.
562 };
563 
565 typedef UniformParameterList::iterator UniformParameterIterator;
566 typedef UniformParameterList::const_iterator UniformParameterConstIterator;
567 
570 template <class valueType>
571 class ConstParameter : public Parameter
572 {
573 public:
574 
575  ConstParameter( valueType val,
576  GpuConstantType type,
577  const Semantic& semantic,
578  const Content& content)
579  : Parameter(type, "Constant", semantic, 0, content)
580  {
581  mValue = val;
582  }
583 
584  virtual ~ConstParameter () {}
585 
587  const valueType& getValue() const { return mValue; }
588 
592  virtual bool isConstParameter() const { return true; }
593 
597  virtual String toString() const = 0;
598 
599 protected:
600  valueType mValue;
601 };
602 
606 {
607 
608  // Interface.
609 public:
610 
611  static ParameterPtr createInPosition(int index);
612  static ParameterPtr createOutPosition(int index);
613 
614  static ParameterPtr createInNormal(int index);
615  static ParameterPtr createInWeights(int index);
616  static ParameterPtr createInIndices(int index);
617  static ParameterPtr createOutNormal(int index);
618  static ParameterPtr createInBiNormal(int index);
619  static ParameterPtr createOutBiNormal(int index);
620  static ParameterPtr createInTangent(int index);
621  static ParameterPtr createOutTangent(int index);
622  static ParameterPtr createInColor(int index);
623  static ParameterPtr createOutColor(int index);
624 
625  static ParameterPtr createInTexcoord(GpuConstantType type, int index, Parameter::Content content);
626  static ParameterPtr createOutTexcoord(GpuConstantType type, int index, Parameter::Content content);
627  static ParameterPtr createInTexcoord1(int index, Parameter::Content content);
628  static ParameterPtr createOutTexcoord1(int index, Parameter::Content content);
629  static ParameterPtr createInTexcoord2(int index, Parameter::Content content);
630  static ParameterPtr createOutTexcoord2(int index, Parameter::Content content);
631  static ParameterPtr createInTexcoord3(int index, Parameter::Content content);
632  static ParameterPtr createOutTexcoord3(int index, Parameter::Content content);
633  static ParameterPtr createInTexcoord4(int index, Parameter::Content content);
634  static ParameterPtr createOutTexcoord4(int index, Parameter::Content content);
635 
636  static ParameterPtr createConstParamVector2(Vector2 val);
637  static ParameterPtr createConstParamVector3(Vector3 val);
638  static ParameterPtr createConstParamVector4(Vector4 val);
639  static ParameterPtr createConstParamFloat(float val);
640 
641  static UniformParameterPtr createSampler(GpuConstantType type, int index);
642  static UniformParameterPtr createSampler1D(int index);
643  static UniformParameterPtr createSampler2D(int index);
644  static UniformParameterPtr createSampler2DArray(int index);
645  static UniformParameterPtr createSampler3D(int index);
646  static UniformParameterPtr createSamplerCUBE(int index);
647 
648  static UniformParameterPtr createUniform(GpuConstantType type, int index, uint16 variability, const String& suggestedName, size_t size);
649 };
650 
651 
652 
656 }
657 }
658 
659 #endif
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
float Real
Software floating point type.
GpuProgramParameters::AutoConstantType mAutoConstantType
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.
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:50
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.
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.
ShaderParameterList::const_iterator ShaderParameterConstIterator
Content getContent() const
Return the content of this parameter.
_StringBase String
Definition: OgreCommon.h:53
void setGpuParameter(const Vector3 &val)
Update the GPU parameter with the given value.
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:421
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.
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:115
ConstParameter(valueType val, GpuConstantType type, const Semantic &semantic, const Content &content)