CC3GLSLVariable Class Reference
Inherits from | NSObject |
Conforms to | NSCopying |
Declared in | CC3GLSLVariable.h |
Overview
Represents a variable used in a GLSL shader program. Different subclasses are used for uniform variables and attribute variables.
A variable may contain an int or float scalar, an int or float vector, a float matrix, or an array of any of those types, as indicated by the type and size properties.
Tasks
-
program
property -
index
property -
location
property -
name
property -
type
property -
size
property -
typeStorageElementCount
property -
storageElementCount
property -
semantic
property -
semanticIndex
property -
scope
property -
isGLStateKnown
property -
– initInProgram:atIndex:
-
+ variableInProgram:atIndex:
-
– normalizeName
-
– copyAsClass:
-
– copyWithZone:asClass:
-
– populateFrom:
-
– fullDescription
Properties
index
The index of this variable within the GL program object. This is distinct from the location property.
@property (nonatomic, readonly) GLuint index
Declared In
CC3GLSLVariable.h
isGLStateKnown
- Indicates whether the value of the variable in the shader program is known. *
- To maintain efficient performance, the value of this variable will be set in the shader
- program only if the value of this variable has been changed since the last time it was
- set in the GL engine.
@property (nonatomic, assign) BOOL isGLStateKnown
Discussion
- Setting the value of this property to NO will cause the value in the GL engine to be set
- the next time the shader program is used, regardless of whether the value of this variable
- has been changed since the last time the shader program was used.
Declared In
CC3GLSLVariable.h
location
The location of this variable within the GL program object. This is distinct from the index property.
@property (nonatomic, readonly) GLint location
Declared In
CC3GLSLVariable.h
name
The name of this variable in the GLSL shader source code.
@property (nonatomic, retain, readonly) NSString *name
Declared In
CC3GLSLVariable.h
program
The GL program object containing this variable.
@property (nonatomic, readonly) CC3ShaderProgram *program
Declared In
CC3GLSLVariable.h
scope
Indicates the scope of a GLSL variable.
@property (nonatomic, assign) CC3GLSLVariableScope scope
Discussion
GLSL variable are automatically populated prior to drawing. This property indicates when and how often the variable needs to be populated.
Most GLSL variables need to be populated anew as each node is drawn. But some variables, such as lighting or camera content only needs to be populated once each time the scene is drawn, and some other variables, such as bone matrices, need to be populated on each draw call.
Declared In
CC3GLSLVariable.h
semantic
A symbolic constant indicating the semantic meaning of this variable.
@property (nonatomic, assign) GLenum semantic
Discussion
The value of this property is typically one of values in the CC3Semantic enumeration, but an application can define and use additional semantics beyond the values defined by CC3Semantic. Additional semantics defined by the application should fall with the range defined by the kCC3SemanticAppBase and kCC3SemanticMax constants, inclusively.
The initial value of this property is kCC3SemanticNone.
Declared In
CC3GLSLVariable.h
semanticIndex
When the semantic refers to an element of a structure that may have multiple instances, this property indicates to which instance this variable refers.
@property (nonatomic, assign) GLuint semanticIndex
Discussion
This property is a zero-based index. For variables that do not appear in multiple structures, this property will always be zero.
As an example, there may be mulitple lights in a scene, each tracked in the GLSL by a structure, one element of which might be the diffuse color property. For the variable associated with the diffuse color of the third light, the value of the semantic property would be kCC3SemanticLightColorDiffuse and the value of this property would be 2.
On the other hand, for variables that represent an array of non-structure values, there will only be one instance of the variable, but the size property of that variable will indicate how many values are being managed by that single variable. For these types of variables, the value of this property will always be zero.
As an example of an array of scalar values. If a single GLSL variable is defined to track the ambient color of multiple lights (ie- defined as an array of vec4), the value of the semantic property would be kCC3SemanticLightColorDiffuse, the value of the size property would be the size of the array as defined in the GLSL, and the value of this property would be zero. In this case, the values of the diffuse colors of all lights will be set as a single array.
The initial value of this property is zero.
Declared In
CC3GLSLVariable.h
size
Returns the size of the variable content, in units of the type indicated by the type property.
@property (nonatomic, readonly) GLint size
Discussion
If the variable is declared as an array in the GLSL program, this property will return the size of that array, otherwise it will return the value 1.
Declared In
CC3GLSLVariable.h
storageElementCount
Returns the number of memory storage elements consumed by this variable.
@property (nonatomic, readonly) GLuint storageElementCount
Discussion
If this variable represents an array (the size property returns a value greater than one), the value returned by this property indicates the number of storage elements required for the entire array.
Returns the result of multipying the typeStorageElementCount property by the size property.
Declared In
CC3GLSLVariable.h
type
Returns a symbolic constant indicating the type of content held by this variable.
@property (nonatomic, readonly) GLenum type
Discussion
The returned value depends on the type of variable being tracked, as determined by the subclass. See the notes for this property in each subclass for more specific information.
Declared In
CC3GLSLVariable.h
typeStorageElementCount
Returns the number of memory storage elements consumed by each instance of this variable.
@property (nonatomic, readonly) GLuint typeStorageElementCount
Discussion
The value returned is dependent on the type property: – scalar types consume 1 storage element per instance – vector types consume 2, 3 or 4 storage elements per instance – matrix types consume 4, 9 or 16 storage elements per instance
If this variable represents an array (the size property returns a value greater than one), the value returned by this property indicates the number of storage elements required for a single component of the array. By contrast, the storageElementCount property returns the total number of storage elements required for the entire array.
Declared In
CC3GLSLVariable.h
Instance Methods
copyAsClass:
Returns a newly allocated (retained) copy of this instance. The new copy will be an instance of the specified class, whose content is copied from this instance.
- (id)copyAsClass:(Class)aClass
Discussion
Care should be taken when choosing the class to be instantiated. If the class is different than that of this instance, the populateFrom: method of that class must be compatible with the contents of this instance.
As with all copy behaviour, the returned instance is retained. It is the responsiblity of the invoker to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3GLSLVariable.h
copyWithZone:asClass:
Returns a newly allocated (retained) copy of this instance. The new copy will be an instance of the specified class, whose content is copied from this instance.
- (id)copyWithZone:(NSZone *)zone asClass:(Class)aClass
Discussion
Care should be taken when choosing the class to be instantiated. If the class is different than that of this instance, the populateFrom: method of that class must be compatible with the contents of this instance.
As with all copy behaviour, the returned instance is retained. It is the responsiblity of the invoker to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3GLSLVariable.h
fullDescription
Returns a detailed description of this instance.
- (NSString *)fullDescription
Declared In
CC3GLSLVariable.h
initInProgram:atIndex:
Initializes this instance at the specified index within the specified program.
- (id)initInProgram:(CC3ShaderProgram *)program atIndex:(GLuint)index
Declared In
CC3GLSLVariable.h
normalizeName
Ensures this variable has a valid name. – Removes the subscript suffix ([0]), if it exists. – Marks this variable as redundant, by setting the semantic to kCC3SemanticRedundant if a subscript other than ([0]) exists.
- (void)normalizeName
Discussion
This method is invoked automatically when the instance is initialized. Normally, you will never need to invoke this method.
Declared In
CC3GLSLVariable.h
populateFrom:
Template method that populates this instance from the specified other instance.
- (void)populateFrom:(CC3GLSLVariable *)another
Discussion
This method is invoked automatically during object copying via the copy or copyWithZone: method. In most situations, the application should use the copy method, and should never need to invoke this method directly.
Subclasses that add additional instance state (instance variables) should extend copying by overriding this method to copy that additional state. Superclass that override this method should be sure to invoke the superclass implementation to ensure that superclass state is copied as well.
Declared In
CC3GLSLVariable.h