OGRE  1.9
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 "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:
306  Parameter();
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 
389  UniformParameter(GpuConstantType type, const String& name,
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 
453  void bind(GpuProgramParametersSharedPtr paramsPtr);
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 
630  static ParameterPtr createInTexcoord(GpuConstantType type, int index, Parameter::Content content);
631  static ParameterPtr createOutTexcoord(GpuConstantType type, int index, Parameter::Content content);
632  static ParameterPtr createInTexcoord1(int index, Parameter::Content content);
633  static ParameterPtr createOutTexcoord1(int index, Parameter::Content content);
634  static ParameterPtr createInTexcoord2(int index, Parameter::Content content);
635  static ParameterPtr createOutTexcoord2(int index, Parameter::Content content);
636  static ParameterPtr createInTexcoord3(int index, Parameter::Content content);
637  static ParameterPtr createOutTexcoord3(int index, Parameter::Content content);
638  static ParameterPtr createInTexcoord4(int index, Parameter::Content content);
639  static ParameterPtr createOutTexcoord4(int index, Parameter::Content content);
640 
641  static ParameterPtr createConstParamVector2(Vector2 val);
642  static ParameterPtr createConstParamVector3(Vector3 val);
643  static ParameterPtr createConstParamVector4(Vector4 val);
644  static ParameterPtr createConstParamFloat(float val);
645 
646  static UniformParameterPtr createSampler(GpuConstantType type, int index);
647  static UniformParameterPtr createSampler1D(int index);
648  static UniformParameterPtr createSampler2D(int index);
649  static UniformParameterPtr createSampler2DArray(int index);
650  static UniformParameterPtr createSampler3D(int index);
651  static UniformParameterPtr createSamplerCUBE(int index);
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
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
float Real
Software floating point type.
GpuProgramParameters::AutoConstantType mAutoConstantType
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.
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
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:345
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:115
ConstParameter(valueType val, GpuConstantType type, const Semantic &semantic, const Content &content)