Support Forum       G3D Web Page     
Classes | Public Types | Public Member Functions | Protected Types | Static Protected Member Functions | Protected Attributes | Friends | List of all members
G3D::UniformTable Class Reference

Uniform and macro arguments for a G3D::Shader. More...

Inherits G3D::ReferenceCountedObject.

Inherited by G3D::Args.

Classes

class  Arg
 This contains the value of a uniform or macro argument passed to shader and its type Macro variables can only be a subset of the possible values. More...
 
class  GPUAttribute
 https://www.opengl.org/sdk/docs/man3/xhtml/glVertexAttribDivisor.xml More...
 
class  MacroArgPair
 
union  Scalar
 8-byte storage used for all argument types More...
 
class  UnboundArgument
 Thrown when an argument is not bound. More...
 

Public Types

typedef Table< String, Arg > ArgTable
 

Public Member Functions

 UniformTable ()
 
 UniformTable (const Any &any)
 
Supports matrix, color, vector, float, string (as macro), boolean, int, and double arguments. More...
 
 UniformTable (const UniformTable &other)
 
virtual ~UniformTable ()
 
void append (const UniformTable &other, const String &prefix="")
 
Sets all arguments from other on this. More...
 
void append (const shared_ptr< UniformTable > &other, const String &prefix="")
 
void appendToPreamble (const String &extra)
 
void clearUniform (const String &s)
 
void clearUniformBindings ()
 
bool getMacro (const String &name, String &value) const
 Get the value of the macro arg name, and return its value in value, returns true if the macro arg exists. More...
 
const GPUAttributeTable & gpuAttributeTable () const
 
bool hasPreambleOrMacros () const
 
bool hasUniform (const String &s) const
 
String macro (const String &name) const
 Returns the empty string if the macro is not bound. More...
 
String preamble () const
 
String preambleAndMacroString () const
 The preamble with macro arg definitions appended. More...
 
void setArrayUniform (const String &name, int index, const shared_ptr< BindlessTextureHandle > &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, int val, bool optional=false)
 
void setArrayUniform (const String &name, int index, float val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Vector2 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Vector3 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Vector4 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Color1 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Color3 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Color4 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Matrix2 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Matrix3 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Matrix4 &val, bool optional=false)
 
void setArrayUniform (const String &name, int index, const Matrix2x3 &val, bool optional=false)
 Becomes a GLSL mat3x2. More...
 
void setArrayUniform (const String &name, int index, const CoordinateFrame &val, bool optional=false)
 Becomes a GLSL mat4x3. More...
 
void setAttributeArray (const String &name, const AttributeArray &val, int instanceDivisor=0)
 
void setImageUniform (const String &name, const shared_ptr< Texture > &val, Access access=Access::READ_WRITE, int mipLevel=0, bool optional=false)
 Uses the texture as the corresponding image type in the shader. More...
 
void setImageUniform (const String &name, const shared_ptr< BufferTexture > &val, Access access=Access::READ_WRITE, bool optional=false)
 Uses the texture as the corresponding *imageBuffer type in the shader. More...
 
void setMacro (const String &name, const String &value)
 
void setMacro (const String &name, const char *value)
 
void setMacro (const String &name, bool val)
 false becomes 0 and true becomes 1 More...
 
void setMacro (const String &name, int val)
 
void setMacro (const String &name, uint32 val)
 
void setMacro (const String &name, double val)
 
void setMacro (const String &name, float val)
 
void setMacro (const String &name, const Vector2 &val)
 
void setMacro (const String &name, const Vector3 &val)
 
void setMacro (const String &name, const Vector4 &val)
 
void setMacro (const String &name, const Color1 &val)
 Becomes float in GLSL. More...
 
void setMacro (const String &name, const Color3 &val)
 
void setMacro (const String &name, const Color4 &val)
 
void setMacro (const String &name, const Vector2int32 &val)
 
void setMacro (const String &name, const Vector2uint32 &val)
 
void setMacro (const String &name, const Vector3int32 &val)
 
void setMacro (const String &name, const Vector2int16 &val)
 
void setMacro (const String &name, const Vector3int16 &val)
 
void setMacro (const String &name, const Vector4int16 &val)
 
void setMacro (const String &name, const Vector4uint16 &val)
 
void setMacro (const String &name, const Matrix2 &val)
 
void setMacro (const String &name, const Matrix3 &val)
 
void setMacro (const String &name, const Matrix4 &val)
 
void setMacro (const String &name, const CoordinateFrame &val)
 Becomes mat3x4 in GLSL. More...
 
void setMacro (const String &name, const Matrix &val)
 
void setPreamble (const String &preamble)
 Arbitrary string to append to beginning of the shader. More...
 
void setUniform (const String &name, bool val, bool optional)
 
void setUniform (const String &name, bool val)
 
void setUniform (const String &name, int val, bool optional=false)
 
void setUniform (const String &name, float val, bool optional=false)
 
void setUniform (const String &name, uint32 val, bool optional=false)
 
void setUniform (const String &name, double val, bool optional=false)
 
void setUniform (const String &name, uint64 val, bool optional=false)
 
void setUniform (const String &name, const Vector2 &val, bool optional=false)
 
void setUniform (const String &name, const Vector3 &val, bool optional=false)
 
void setUniform (const String &name, const Vector4 &val, bool optional=false)
 
void setUniform (const String &name, const Color1 &val, bool optional=false)
 Becomes float in GLSL. More...
 
void setUniform (const String &name, const Color3 &val, bool optional=false)
 
void setUniform (const String &name, const Color4 &val, bool optional=false)
 
void setUniform (const String &name, const Vector2int32 &val, bool optional=false)
 
void setUniform (const String &name, const Vector2uint32 &val, bool optional=false)
 
void setUniform (const String &name, const Vector3int32 &val, bool optional=false)
 
void setUniform (const String &name, const Vector2int16 &val, bool optional=false)
 
void setUniform (const String &name, const Vector3int16 &val, bool optional=false)
 
void setUniform (const String &name, const Vector4int16 &val, bool optional=false)
 
void setUniform (const String &name, const Vector4uint16 &val, bool optional=false)
 
void setUniform (const String &name, const Matrix2 &val, bool optional=false)
 
void setUniform (const String &name, const Matrix3 &val, bool optional=false)
 
void setUniform (const String &name, const Matrix4 &val, bool optional=false)
 
void setUniform (const String &name, const Matrix2x3 &val, bool optional=false)
 Becomes a GLSL mat3x2. More...
 
void setUniform (const String &name, const Matrix &val, bool optional=false)
 
void setUniform (const String &name, const CoordinateFrame &val, bool optional=false)
 Becomes a GLSL mat4x3. More...
 
void setUniform (const String &name, const shared_ptr< Texture > &val, const Sampler &settings, bool optional=false)
 
void setUniform (const String &name, const shared_ptr< BufferTexture > &val, bool optional)
 
void setUniform (const String &name, const shared_ptr< BufferTexture > &val)
 
void setUniform (const String &name, const shared_ptr< BindlessTextureHandle > &val, bool optional=false)
 
const Arg & uniform (const String &name) const
 Returns the uniform value bound to this name or throws UnboundArgument. More...
 
const UniformTable::ArgTable & uniformTable () const
 

Protected Types

typedef Table< String, GPUAttribute > GPUAttributeTable
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

SmallArray< MacroArgPair, 12 > m_macroArgs
 We use a SmallArray to avoid heap allocation for every arg instance. More...
 
String m_preamble
 
GPUAttributeTable m_streamArgs
 Must be empty if m_immediateModeArgs is non-empty. More...
 
ArgTable m_uniformArgs
 

Friends

class Shader
 

Detailed Description

Uniform and macro arguments for a G3D::Shader.

This provides a mechanism for support classes like UniversalMaterial to provide additional arguments to a Shader. AttributeArrays are usually set on Args and not UniformTable, however per-instance attributes may need to be specified for an ArticulatedModel::Pose or related support class.

See also
Args

Member Typedef Documentation

◆ ArgTable

◆ GPUAttributeTable

Constructor & Destructor Documentation

◆ UniformTable() [1/3]

G3D::UniformTable::UniformTable ( )

◆ UniformTable() [2/3]

G3D::UniformTable::UniformTable ( const Any &  any)


Supports matrix, color, vector, float, string (as macro), boolean, int, and double arguments.

Example:

{
height = float(3.1);
numIterations = int(7);
// Macro
USE_BUMP = "1";
position = Point3(2, 1, -4.5);
}

◆ ~UniformTable()

virtual G3D::UniformTable::~UniformTable ( )
virtual

◆ UniformTable() [3/3]

G3D::UniformTable::UniformTable ( const UniformTable &  other)
inline

Member Function Documentation

◆ append() [1/2]

void G3D::UniformTable::append ( const UniformTable &  other,
const String &  prefix = "" 
)


Sets all arguments from other on this.

Parameters
prefixIf specified, prefix each uniform and macro name with this prefix.

Referenced by append(), and UniformTable().

◆ append() [2/2]

void G3D::UniformTable::append ( const shared_ptr< UniformTable > &  other,
const String &  prefix = "" 
)
inline

◆ appendToPreamble()

void G3D::UniformTable::appendToPreamble ( const String &  extra)
inline

◆ clearUniform()

void G3D::UniformTable::clearUniform ( const String &  s)
inline

◆ clearUniformBindings()

void G3D::UniformTable::clearUniformBindings ( )
inline

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ getMacro()

bool G3D::UniformTable::getMacro ( const String &  name,
String &  value 
) const

Get the value of the macro arg name, and return its value in value, returns true if the macro arg exists.

Referenced by macro().

◆ gpuAttributeTable()

const GPUAttributeTable& G3D::UniformTable::gpuAttributeTable ( ) const
inline

◆ hasPreambleOrMacros()

bool G3D::UniformTable::hasPreambleOrMacros ( ) const
inline

◆ hasUniform()

bool G3D::UniformTable::hasUniform ( const String &  s) const
inline

◆ macro()

String G3D::UniformTable::macro ( const String &  name) const
inline

Returns the empty string if the macro is not bound.

See also
getMacro

◆ preamble()

String G3D::UniformTable::preamble ( ) const
inline

◆ preambleAndMacroString()

String G3D::UniformTable::preambleAndMacroString ( ) const

The preamble with macro arg definitions appended.

◆ setArrayUniform() [1/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const shared_ptr< BindlessTextureHandle > &  val,
bool  optional = false 
)

◆ setArrayUniform() [2/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
int  val,
bool  optional = false 
)

◆ setArrayUniform() [3/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
float  val,
bool  optional = false 
)

◆ setArrayUniform() [4/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Vector2 &  val,
bool  optional = false 
)

◆ setArrayUniform() [5/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Vector3 &  val,
bool  optional = false 
)

◆ setArrayUniform() [6/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Vector4 &  val,
bool  optional = false 
)

◆ setArrayUniform() [7/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Color1 &  val,
bool  optional = false 
)

◆ setArrayUniform() [8/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Color3 &  val,
bool  optional = false 
)

◆ setArrayUniform() [9/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Color4 &  val,
bool  optional = false 
)

◆ setArrayUniform() [10/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Matrix2 &  val,
bool  optional = false 
)

◆ setArrayUniform() [11/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Matrix3 &  val,
bool  optional = false 
)

◆ setArrayUniform() [12/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Matrix4 &  val,
bool  optional = false 
)

◆ setArrayUniform() [13/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const Matrix2x3 &  val,
bool  optional = false 
)

Becomes a GLSL mat3x2.

◆ setArrayUniform() [14/14]

void G3D::UniformTable::setArrayUniform ( const String &  name,
int  index,
const CoordinateFrame &  val,
bool  optional = false 
)

Becomes a GLSL mat4x3.

◆ setAttributeArray()

void G3D::UniformTable::setAttributeArray ( const String &  name,
const AttributeArray &  val,
int  instanceDivisor = 0 
)
Parameters
instanceDivisorSet to 0 for regular indexed rendering and 1 to increment once per instance. https://www.opengl.org/sdk/docs/man3/xhtml/glVertexAttribDivisor.xml

◆ setImageUniform() [1/2]

void G3D::UniformTable::setImageUniform ( const String &  name,
const shared_ptr< Texture > &  val,
Access  access = Access::READ_WRITE,
int  mipLevel = 0,
bool  optional = false 
)

Uses the texture as the corresponding image type in the shader.

◆ setImageUniform() [2/2]

void G3D::UniformTable::setImageUniform ( const String &  name,
const shared_ptr< BufferTexture > &  val,
Access  access = Access::READ_WRITE,
bool  optional = false 
)

Uses the texture as the corresponding *imageBuffer type in the shader.

◆ setMacro() [1/25]

void G3D::UniformTable::setMacro ( const String &  name,
const String &  value 
)

Referenced by setMacro().

◆ setMacro() [2/25]

void G3D::UniformTable::setMacro ( const String &  name,
const char *  value 
)
inline

◆ setMacro() [3/25]

void G3D::UniformTable::setMacro ( const String &  name,
bool  val 
)

false becomes 0 and true becomes 1

◆ setMacro() [4/25]

void G3D::UniformTable::setMacro ( const String &  name,
int  val 
)

◆ setMacro() [5/25]

void G3D::UniformTable::setMacro ( const String &  name,
uint32  val 
)

◆ setMacro() [6/25]

void G3D::UniformTable::setMacro ( const String &  name,
double  val 
)

◆ setMacro() [7/25]

void G3D::UniformTable::setMacro ( const String &  name,
float  val 
)

◆ setMacro() [8/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector2 &  val 
)

◆ setMacro() [9/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector3 &  val 
)

◆ setMacro() [10/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector4 &  val 
)

◆ setMacro() [11/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Color1 &  val 
)

Becomes float in GLSL.

◆ setMacro() [12/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Color3 &  val 
)

◆ setMacro() [13/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Color4 &  val 
)

◆ setMacro() [14/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector2int32 &  val 
)

◆ setMacro() [15/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector2uint32 &  val 
)

◆ setMacro() [16/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector3int32 &  val 
)

◆ setMacro() [17/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector2int16 &  val 
)

◆ setMacro() [18/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector3int16 &  val 
)

◆ setMacro() [19/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector4int16 &  val 
)

◆ setMacro() [20/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Vector4uint16 &  val 
)

◆ setMacro() [21/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Matrix2 &  val 
)

◆ setMacro() [22/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Matrix3 &  val 
)

◆ setMacro() [23/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Matrix4 &  val 
)

◆ setMacro() [24/25]

void G3D::UniformTable::setMacro ( const String &  name,
const CoordinateFrame &  val 
)

Becomes mat3x4 in GLSL.

◆ setMacro() [25/25]

void G3D::UniformTable::setMacro ( const String &  name,
const Matrix &  val 
)

◆ setPreamble()

void G3D::UniformTable::setPreamble ( const String &  preamble)

Arbitrary string to append to beginning of the shader.

◆ setUniform() [1/30]

void G3D::UniformTable::setUniform ( const String &  name,
bool  val,
bool  optional 
)

Referenced by setUniform().

◆ setUniform() [2/30]

void G3D::UniformTable::setUniform ( const String &  name,
bool  val 
)
inline

◆ setUniform() [3/30]

void G3D::UniformTable::setUniform ( const String &  name,
int  val,
bool  optional = false 
)

◆ setUniform() [4/30]

void G3D::UniformTable::setUniform ( const String &  name,
float  val,
bool  optional = false 
)

◆ setUniform() [5/30]

void G3D::UniformTable::setUniform ( const String &  name,
uint32  val,
bool  optional = false 
)

◆ setUniform() [6/30]

void G3D::UniformTable::setUniform ( const String &  name,
double  val,
bool  optional = false 
)

◆ setUniform() [7/30]

void G3D::UniformTable::setUniform ( const String &  name,
uint64  val,
bool  optional = false 
)

◆ setUniform() [8/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector2 &  val,
bool  optional = false 
)

◆ setUniform() [9/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector3 &  val,
bool  optional = false 
)

◆ setUniform() [10/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector4 &  val,
bool  optional = false 
)

◆ setUniform() [11/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Color1 &  val,
bool  optional = false 
)

Becomes float in GLSL.

◆ setUniform() [12/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Color3 &  val,
bool  optional = false 
)

◆ setUniform() [13/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Color4 &  val,
bool  optional = false 
)

◆ setUniform() [14/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector2int32 &  val,
bool  optional = false 
)

◆ setUniform() [15/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector2uint32 &  val,
bool  optional = false 
)

◆ setUniform() [16/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector3int32 &  val,
bool  optional = false 
)

◆ setUniform() [17/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector2int16 &  val,
bool  optional = false 
)

◆ setUniform() [18/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector3int16 &  val,
bool  optional = false 
)

◆ setUniform() [19/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector4int16 &  val,
bool  optional = false 
)

◆ setUniform() [20/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Vector4uint16 &  val,
bool  optional = false 
)

◆ setUniform() [21/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Matrix2 &  val,
bool  optional = false 
)

◆ setUniform() [22/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Matrix3 &  val,
bool  optional = false 
)

◆ setUniform() [23/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Matrix4 &  val,
bool  optional = false 
)

◆ setUniform() [24/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Matrix2x3 &  val,
bool  optional = false 
)

Becomes a GLSL mat3x2.

◆ setUniform() [25/30]

void G3D::UniformTable::setUniform ( const String &  name,
const Matrix &  val,
bool  optional = false 
)

◆ setUniform() [26/30]

void G3D::UniformTable::setUniform ( const String &  name,
const CoordinateFrame &  val,
bool  optional = false 
)

Becomes a GLSL mat4x3.

◆ setUniform() [27/30]

void G3D::UniformTable::setUniform ( const String &  name,
const shared_ptr< Texture > &  val,
const Sampler &  settings,
bool  optional = false 
)

◆ setUniform() [28/30]

void G3D::UniformTable::setUniform ( const String &  name,
const shared_ptr< BufferTexture > &  val,
bool  optional 
)

◆ setUniform() [29/30]

void G3D::UniformTable::setUniform ( const String &  name,
const shared_ptr< BufferTexture > &  val 
)
inline

◆ setUniform() [30/30]

void G3D::UniformTable::setUniform ( const String &  name,
const shared_ptr< BindlessTextureHandle > &  val,
bool  optional = false 
)

◆ uniform()

const Arg& G3D::UniformTable::uniform ( const String &  name) const

Returns the uniform value bound to this name or throws UnboundArgument.

◆ uniformTable()

const UniformTable::ArgTable& G3D::UniformTable::uniformTable ( ) const
inline

Friends And Related Function Documentation

◆ Shader

friend class Shader
friend

Member Data Documentation

◆ m_macroArgs

SmallArray<MacroArgPair, 12> G3D::UniformTable::m_macroArgs
protected

We use a SmallArray to avoid heap allocation for every arg instance.

Referenced by hasPreambleOrMacros().

◆ m_preamble

String G3D::UniformTable::m_preamble
protected

◆ m_streamArgs

GPUAttributeTable G3D::UniformTable::m_streamArgs
protected

Must be empty if m_immediateModeArgs is non-empty.

Referenced by gpuAttributeTable(), and G3D::Args::hasStreamArgs().

◆ m_uniformArgs

ArgTable G3D::UniformTable::m_uniformArgs
protected

documentation generated on Wed Nov 24 2021 08:02:01 using doxygen 1.8.15