v2.0.2
Instance Methods | Class Methods | Properties | List of all members
CC3ShaderProgram Class Reference

#import <CC3Shaders.h>

Inheritance diagram for CC3ShaderProgram:
Inheritance graph
[legend]

Instance Methods

(CC3GLSLAttribute *) - attributeAtLocation:
 
(CC3GLSLAttribute *) - attributeForSemantic:
 
(CC3GLSLAttribute *) - attributeForSemantic:at:
 
(CC3GLSLAttribute *) - attributeNamed:
 
(void) - bindWithVisitor:
 
(NSString *) - constructorDescription
 
(NSString *) - fullDescription
 
(id) - initFromVertexShaderFile:andFragmentShaderFile:
 
(id) - initWithSemanticDelegate:fromVertexShaderFile:andFragmentShaderFile:
 
(id) - initWithSemanticDelegate:withVertexShader:andFragmentShader:
 
(id) - initWithVertexShader:andFragmentShader:
 
(void) - link
 
(void) - markSceneScopeDirty
 
(void) - populateDrawScopeUniformsWithVisitor:
 
(void) - populateNodeScopeUniformsWithVisitor:
 
(void) - populateSceneScopeUniformsWithVisitor:
 
(void) - populateVertexAttributesWithVisitor:
 
(void) - prewarm
 
(void) - remove
 
(void) - resetGLState
 
(CC3GLSLUniform *) - uniformAtLocation:
 
(CC3GLSLUniform *) - uniformForSemantic:
 
(CC3GLSLUniform *) - uniformForSemantic:at:
 
(CC3GLSLUniform *) - uniformNamed:
 
(void) - willBeginDrawingScene
 
- Instance Methods inherited from CC3Identifiable
(id) - copy
 
(id) - copyAsClass:
 
(void) - copyUserDataFrom:
 
(id) - copyWithName:
 
(id) - copyWithName:asClass:
 
(id) - copyWithZone:withName:
 
(id) - copyWithZone:withName:asClass:
 
(BOOL) - deriveNameFrom:
 
(BOOL) - deriveNameFrom:usingSuffix:
 
(id) - init
 
(id) - initAtIndex:fromPODResource:
 
(void) - initUserData
 
(id) - initWithName:
 
(id) - initWithTag:
 
(id) - initWithTag:withName:
 
(GLuint) - nextTag
 
(void) - populateFrom:
 

Class Methods

(id< CC3ShaderMatcher >) + __deprecated
 
(void) + addProgram:
 
(BOOL) + defaultShouldAllowDefaultVariableValues
 
(CC3ShaderProgram *) + getProgramNamed:
 
(BOOL) + isPreloading
 
(NSString *) + loadedProgramsDescription
 
(id) + programFromVertexShaderFile:andFragmentShaderFile:
 
(NSString *) + programNameFromVertexShaderName:andFragmentShaderName:
 
(id) + programWithSemanticDelegate:fromVertexShaderFile:andFragmentShaderFile:
 
(id) + programWithSemanticDelegate:withVertexShader:andFragmentShader:
 
(id) + programWithVertexShader:andFragmentShader:
 
(void) + removeAllPrograms
 
(void) + removeProgram:
 
(void) + removeProgramNamed:
 
(void) + setDefaultShouldAllowDefaultVariableValues:
 
(void) + setIsPreloading:
 
(void) + setProgramMatcher:
 
(void) + setShaderMatcher:
 
(void) + setShouldAutomaticallyPreloadMatchingPureColorPrograms:
 
(id< CC3ShaderMatcher >) + shaderMatcher
 
(BOOL) + shouldAutomaticallyPreloadMatchingPureColorPrograms
 
(void) + willBeginDrawingScene
 
- Class Methods inherited from CC3Identifiable
(GLint) + instanceCount
 
(void) + resetTagAllocation
 

Properties

GLuint attributeCount
 
NSArray * attributes
 
CC3FragmentShaderfragmentShader
 
GLint maxAttributeNameLength
 
GLint maxUniformNameLength
 
GLuint programID
 
id< CC3ShaderSemanticsDelegatesemanticDelegate
 
BOOL shouldAllowDefaultVariableValues
 
GLuint texture2DCount
 
GLuint texture2DStart
 
GLuint textureCubeCount
 
GLuint textureCubeStart
 
GLuint textureLightProbeCount
 
GLuint textureLightProbeStart
 
GLuint uniformCount
 
NSArray * uniforms
 
GLuint uniformStorageElementCount
 
CC3VertexShadervertexShader
 
BOOL wasLoadedFromFile
 
- Properties inherited from CC3Identifiable
NSObject *sharedUserData __deprecated
 
NSString * name
 
NSString * nameSuffix
 
GLint podIndex
 
BOOL shouldIncludeInDeepCopy
 
GLuint tag
 
NSObject * userData
 
- Properties inherited from <CC3Cacheable>
NSString * name
 

Detailed Description

CC3ShaderProgram represents an OpenGL shader program, containing one vertex shader and one fragment shader, each compiled from GLSL source code.

CC3ShaderProgram manages the automatic population of the attributes and uniforms from the scene content by using semantic definitions for each attribute and uniform. This semantic mapping is handled by a delegate held in the semanticDelegate property.

Since a single shader program can be used by many nodes and materials, shader programs are cached. The most common, and recommended way to create shader programs is to use the programFromVertexShaderFile:andFragmentShaderFile: method, which automatically manages the cache, and only loads, compiles and links the shader program if it is not already cached.

Method Documentation

Deprecated:
Renamed to shaderMatcher.

Implements CC3Identifiable.

+ (void) addProgram: (CC3ShaderProgram *)  program

Adds the specified program to the collection of loaded programs.

The specified program should be compiled and linked prior to being added here.

Programs are accessible via their names through the getProgramNamed: method, and each program name should be unique. If a program with the same name as the specified program already exists in this cache, an assertion error is raised.

Depending on the value of the isPreloading property, the shader program may be held within this cache as a weak reference. As a result, the specified shader program may automatically be deallocated and removed from this cache once all external strong references to it have been released.

If the value of both the shouldAutomaticallyPreloadMatchingPureColorPrograms and isPreloading properties are set to YES, this method will ensure that a matching pure-color program is added to the cache for each regular program that is added. The pureColorProgramMatching: method, of the program matcher found in the class-side shaderMatcher property, is used to create the matching pure-color program.

- (CC3GLSLAttribute*) attributeAtLocation: (GLint)  attrLocation

Returns the vertex attribute at the specified location, or nil if no attribute is defined at the specified location.

- (CC3GLSLAttribute*) attributeForSemantic: (GLenum)  semantic

Returns the vertex attribute with the specified semantic at index zero, or nil if no attribute is defined for the specified semantic.

- (CC3GLSLAttribute*) attributeForSemantic: (GLenum)  semantic
at: (GLuint)  semanticIndex 

Returns the vertex attribute with the specified semantic and index, or nil if no attribute is defined for the specified semantic.

- (CC3GLSLAttribute*) attributeNamed: (NSString *)  name

Returns the vertex attribute with the specified name, or nil if no attribute is defined for the specified name.

- (void) bindWithVisitor: (CC3NodeDrawingVisitor *)  visitor

Sets the currentShaderProgram property of the specified visitor to this program, binds this program to the GL engine, and populates the program attributes and uniforms.

- (NSString*) constructorDescription

Returns a description formatted as a source-code line for loading this program from shader source code files.

During development time, you can log this string, then copy and paste it into a pre-loading function within your app code.

+ (BOOL) defaultShouldAllowDefaultVariableValues

Indicates the initial value of the shouldAllowDefaultVariableValues for each instance.

See the notes for the shouldAllowDefaultVariableValues property for a full discussion.

The initial value of this property is NO.

- (NSString*) fullDescription

Returns a detailed description of this instance, including a description of each uniform and attribute.

Implements CC3Identifiable.

+ (CC3ShaderProgram*) getProgramNamed: (NSString *)  name

Returns the program with the specified name, or nil if a program with that name has not been added.

- (id) initFromVertexShaderFile: (NSString *)  vshFilePath
andFragmentShaderFile: (NSString *)  fshFilePath 

Initializes this instance by setting the vertexShader and programShader properties to shaders compiled from the GLSL source code loaded from the specified files, and invoking the link and prewarm methods to prepare this instance for use.

Initializes this instance by compiling and linking the GLSL source code loaded from the specified vertex and fragment shader files.

If a shader has already been loaded, compiled, and cached, the cached shader will be reused, and will not be reloaded and recompiled from the file.

The specified file paths may be either absolute paths, or relative to the application resource directory. If the files are located directly in the application resources directory, the specified file paths can simply be the names of the files.

The semanticDelegate property is set to the default semantic delegate returned from the semanticDelegate property of the program matcher in the class-side shaderMatcher property.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of this instance from the names of the vertex and fragment shaders.

Since a single shader program can be used by many nodes and materials, shaders are cached. Typically, this method is not invoked directly, and the programFromVertexShaderFile:andFragmentShaderFile: method is used instead.

If you do use this method directly, before invoking this method, you can invoke the class-side getProgramNamed: method to detemine whether a shader program with with a name derived from the programNameFromVertexShaderName:andFragmentShaderName: method already exists, and after invoking this method, you should use the class-side addProgram: method to add the new shader program instance to the program cache.

- (id) initWithSemanticDelegate: (id< CC3ShaderSemanticsDelegate >)  semanticDelegate
fromVertexShaderFile: (NSString *)  vshFilePath
andFragmentShaderFile: (NSString *)  fshFilePath 

Initializes this instance by setting the semanticDelegate property to the specified semantic delgate, setting the vertexShader and programShader properties to shaders compiled from the GLSL source code loaded from the specified files, and invoking the link and prewarm methods to prepare this instance for use.

If a shader has already been loaded, compiled, and cached, the cached shader will be reused, and will not be reloaded and recompiled from the file.

The specified file paths may be either absolute paths, or relative to the application resource directory. If the files are located directly in the application resources directory, the specified file paths can simply be the names of the files.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of this instance from the names of the vertex and fragment shaders.

Since a single shader program can be used by many nodes and materials, shaders are cached. Typically, this method is not invoked directly, and the programFromVertexShaderFile:andFragmentShaderFile: method is used instead.

If you do use this method directly, before invoking this method, you can invoke the class-side getProgramNamed: method to detemine whether a shader program with with a name derived from the programNameFromVertexShaderName:andFragmentShaderName: method already exists, and after invoking this method, you should use the class-side addProgram: method to add the new shader program instance to the program cache.

- (id) initWithSemanticDelegate: (id< CC3ShaderSemanticsDelegate >)  semanticDelegate
withVertexShader: (CC3VertexShader *)  vertexShader
andFragmentShader: (CC3FragmentShader *)  fragmentShader 

Initializes this instance by setting the semanticDelegate property to the specified semantic delgate, setting the vertexShader and programShader properties to the specified shaders, and invoking the link and prewarm methods to prepare this instance for use.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of this instance from the names of the vertex and fragment shaders.

Since a single shader program can be used by many nodes and materials, shader programs are cached. Typically, this method is not invoked directly, and the programWithVertexShader:andFragmentShader: method is used instead.

If you do use this method directly, before invoking this method, you can invoke the class-side getProgramNamed: method, to detemine whether a shader program with a name derived from the programNameFromVertexShaderName:andFragmentShaderName: method already exists, and after invoking this method, you should use the class-side addProgram: method to add the new shader program instance to the program cache.

- (id) initWithVertexShader: (CC3VertexShader *)  vertexShader
andFragmentShader: (CC3FragmentShader *)  fragmentShader 

Initializes this instance by setting the vertexShader and programShader properties to the specified shaders, and invoking the link and prewarm methods to prepare this instance for use.

The semanticDelegate property is set to the default semantic delegate returned from the semanticDelegate property of the program matcher in the class-side shaderMatcher property.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of this instance from the names of the vertex and fragment shaders.

Since a single shader program can be used by many nodes and materials, shader programs are cached. Typically, this method is not invoked directly, and the programWithVertexShader:andFragmentShader: method is used instead.

If you do use this method directly, before invoking this method, you can invoke the class-side getProgramNamed: method, to detemine whether a shader program with a name derived from the programNameFromVertexShaderName:andFragmentShaderName: method already exists, and after invoking this method, you should use the class-side addProgram: method to add the new shader program instance to the program cache.

+ (BOOL) isPreloading

Returns whether shader programs are being pre-loaded.

See the setIsPreloading setter method for a description of how and when to use this property.

- (void) link

Links the vertex and fragment shaders into this shader program.

The vertexShader, fragmentShader, and semanticDelegate properties must be set prior to invoking this method.

This method is automatically invoked during instance initialization if the vertex and fragment shaders are provided. If you create this instance without shaders and add them later, you can invoke this method once the vertexShader and fragmentShader properties have been set.

+ (NSString*) loadedProgramsDescription

Returns a description of the shader programs in this cache that were loaded from files, with each entry formatted as a source-code line to load the shader program from a file.

During development time, you can log this string, then copy and paste it into a pre-loading function within your app code to pre-load the shader programs for later use.

- (void) markSceneScopeDirty

Marks the scene scope variables as dirty and in need of re-populating.

Invoked automatically at the beginning of scene rendering.

- (void) populateDrawScopeUniformsWithVisitor: (CC3NodeDrawingVisitor *)  visitor

Populates the uniform variables that have draw scope.

- (void) populateNodeScopeUniformsWithVisitor: (CC3NodeDrawingVisitor *)  visitor

Populates the uniform variables that have node scope.

- (void) populateSceneScopeUniformsWithVisitor: (CC3NodeDrawingVisitor *)  visitor

If the scene scope was previously marked dirty by an invocation of the markSceneScopeDirty method, this method populates all uniform variables that have scene scope, and marks the scene scope as no longer dirty.

Further invocations of this method will not re-populate the scene scope variables until markSceneScopeDirty is invoked.

This method is lazily invoked by the populateNodeScopeUniformsWithVisitor method. Therefore, scene scope will be populated on each render pass when the first node that uses this program is rendered. Under normal operations, this method need never be explicitly invoked.

- (void) populateVertexAttributesWithVisitor: (CC3NodeDrawingVisitor *)  visitor

Populates the vertex attribute variables.

- (void) prewarm

Pre-warms this shader program by using it to render a small mesh node to an off-screen surface.

The GL engine may choose to defer some final shader program compilation steps until the first time the shader program is used to render a mesh. This can cause the first frame of the first mesh drawn with the shader program to take significantly longer than subsequent renderings with that shader program, which can often result in a transient, but noticable, "freezing" of the scene. This is particularly apparent for new meshes that are added to the scene at any point other than during scene initialization.

To avoid this, this method can be invoked to cause this shader program to render a small mesh to an off-screen rendering surface, in order to force this shader program to perform its final compilation and linking steps at a controlled, and predicatble, time.

This method is automatically invoked during instance initialization if the vertex and fragment shaders are provided. If you create this instance without shaders and add them later, you can invoke this method once the vertexShader and fragmentShader properties have been set, and the link method has been invoked.

Prewarming is always performed on shader programs loaded on the background thread, but is only performed on shader programs loaded on the foreground thread during the preloading phase. This is to avoid prewarming activity during lazy loading of shader programs during rendering.

+ (id) programFromVertexShaderFile: (NSString *)  vshFilePath
andFragmentShaderFile: (NSString *)  fshFilePath 

Returns an instance by setting the vertexShader and programShader properties to shaders compiled from the GLSL source code loaded from the specified files, and invoking the link and prewarm methods to prepare the instance for use.

If either shader has already been loaded, compiled, and cached, the cached shader will be reused, and will not be reloaded and recompiled from the file.

The specified file paths may be either absolute paths, or relative to the application resource directory. If the files are located directly in the application resources directory, the specified file paths can simply be the names of the files.

The semanticDelegate property is set to the default semantic delegate returned from the semanticDelegate property of the program matcher in the class-side shaderMatcher property.

Programs loaded through this method are cached. If the program was already loaded and is in the cache, it is retrieved and returned. If the program has not in the cache, it is loaded, compiled, and linked, placed into the cache, and returned. It is therefore safe to invoke this method any time the program is needed, without having to worry that the program will be repeatedly loaded and compiled from the files.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of the instance from the names of the vertex and fragment shaders, and to attempt to retrieve the program from the cache, prior to creating a new program.

To clear a program instance from the cache, use the removeProgram: method.

To create the program directly, bypassing the cache, use the alloc and initWithSemanticDelegate:fromVertexShaderFile:andFragmentShaderFile: methods. This technique can be used to create the same program twice, if needed for some reason. Each distinct instance can then be given its own name, and added to the cache separately.

+ (NSString*) programNameFromVertexShaderName: (NSString *)  vertexShaderName
andFragmentShaderName: (NSString *)  fragmentShaderName 

Returns a program name created as a simple hyphenated concatenation of the specified vertex and shader names.

This method is used to standardize the naming of programs, to ease in adding and retrieving programs to and from the cache.

+ (id) programWithSemanticDelegate: (id< CC3ShaderSemanticsDelegate >)  semanticDelegate
fromVertexShaderFile: (NSString *)  vshFilePath
andFragmentShaderFile: (NSString *)  fshFilePath 

Returns an instance by setting the semanticDelegate property to the specified semantic delgate, setting the vertexShader and programShader properties to shaders compiled from the GLSL source code loaded from the specified files, and invoking the link and prewarm methods to prepare this instance for use.

If either shader has already been loaded, compiled, and cached, the cached shader will be reused, and will not be reloaded and recompiled from the file.

The specified file paths may be either absolute paths, or relative to the application resource directory. If the files are located directly in the application resources directory, the specified file paths can simply be the names of the files.

Programs loaded through this method are cached. If the program was already loaded and is in the cache, it is retrieved and returned. If the program has not in the cache, it is loaded, compiled, and linked, placed into the cache, and returned. It is therefore safe to invoke this method any time the program is needed, without having to worry that the program will be repeatedly loaded and compiled from the files.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of the instance from the names of the vertex and fragment shaders, and to attempt to retrieve the program from the cache, prior to creating a new program.

To clear a program instance from the cache, use the removeProgram: method.

To create the program directly, bypassing the cache, use the alloc and initWithSemanticDelegate:fromVertexShaderFile:andFragmentShaderFile: methods. This technique can be used to create the same program twice, if needed for some reason. Each distinct instance can then be given its own name, and added to the cache separately.

+ (id) programWithSemanticDelegate: (id< CC3ShaderSemanticsDelegate >)  semanticDelegate
withVertexShader: (CC3VertexShader *)  vertexShader
andFragmentShader: (CC3FragmentShader *)  fragmentShader 

Returns an instance by setting the semanticDelegate property to the specified semantic delgate, setting the vertexShader and programShader properties to the specified shaders, and invoking the link and prewarm methods to prepare the instance for use.

Programs loaded through this method are cached. If the program was already loaded and is in the cache, it is retrieved and returned. If the program has not in the cache, it is loaded, compiled, and linked, placed into the cache, and returned. It is therefore safe to invoke this method any time the program is needed, without having to worry that the program will be repeatedly loaded and compiled from the files.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of the instance from the names of the vertex and fragment shaders, and to attempt to retrieve the program from the cache, prior to creating a new program.

To clear a program instance from the cache, use the removeProgram: method.

To create the program directly, bypassing the cache, use the alloc and initWithSemanticDelegate:withVertexShader:withFragmentShader: methods. This technique can be used to create the same program twice, if needed for some reason. Each distinct instance can then be given its own name, and added to the cache separately.

+ (id) programWithVertexShader: (CC3VertexShader *)  vertexShader
andFragmentShader: (CC3FragmentShader *)  fragmentShader 

Returns an instance by setting the vertexShader and programShader properties to the specified shaders, and invoking the link and prewarm methods to prepare the instance for use.

The semanticDelegate property is set to the default semantic delegate returned from the semanticDelegate property of the program matcher in the class-side shaderMatcher property.

Programs loaded through this method are cached. If the program was already loaded and is in the cache, it is retrieved and returned. If the program has not in the cache, it is loaded, compiled, and linked, placed into the cache, and returned. It is therefore safe to invoke this method any time the program is needed, without having to worry that the program will be repeatedly loaded and compiled from the files.

This method uses the programNameFromVertexShaderName:andFragmentShaderName: method to set the name of the instance from the names of the vertex and fragment shaders, and to attempt to retrieve the program from the cache, prior to creating a new program.

To clear a program instance from the cache, use the removeProgram: method.

To create the program directly, bypassing the cache, use the alloc and initWithSemanticDelegate:withVertexShader:withFragmentShader: methods. This technique can be used to create the same program twice, if needed for some reason. Each distinct instance can then be given its own name, and added to the cache separately.

- (void) remove

Removes this program instance from the cache.

+ (void) removeAllPrograms

Removes from the cache all shader programs that are instances of any subclass of the receiver.

You can use this method to selectively remove specific types of shader programs, based on the shader program class, by invoking this method on that class. If you invoke this method on the CC3ShaderProgram class, this cache will be compltely cleared. However, if you invoke this method on one of its subclasses, only those shader programs that are instances of that subclass (or one of its subclasses in turn) will be removed, leaving the remaining shader programs in the cache.

+ (void) removeProgram: (CC3ShaderProgram *)  program

Removes the specified program from the program cache.

+ (void) removeProgramNamed: (NSString *)  name

Removes the program with the specified name from the program cache.

- (void) resetGLState

Resets the GL state management used by this shader program, including the values of all variables.

+ (void) setDefaultShouldAllowDefaultVariableValues: (BOOL)  shouldAllow

Indicates the initial value of the shouldAllowDefaultVariableValues for each instance.

See the notes for the shouldAllowDefaultVariableValues property for a full discussion.

The initial value of this property is NO.

+ (void) setIsPreloading: (BOOL)  isPreloading

Sets whether shader programs are being pre-loaded.

Shader programs that are added to this cache while the value of this property is YES will be strongly cached and cannot be deallocated until specifically removed from this cache. You must manually remove any shader programs added to this cache while the value of this property is YES.

Shader programs that are added to this cache while the value of this property is NO will be weakly cached, and will automatically be deallocated and removed from this cache once all references to the shader program outside this cache are released.

If you will be loading resources such as models and textures on a background thread while the scene is running, you will find that any shader programs that are loaded while the scene is running will often create a brief, but noticable, pause in the scene while the final stages of the shader program are conmpiled and configured.

You can avoid this pause by pre-loading all of the shader programs that your scene will need during scene initialization. They will then automatically be recalled from this cache when needed by the models that you load mid-scene. In order for them to be available in this cache at that time, the value of this property must be set to YES for the duration of the pre-loading stage during scene initialization.

You can set the value of this property at any time, and can vary it between YES and NO to accomodate your specific loading patterns.

The initial value of this property is NO, meaning that shader programs will be weakly cached in this cache, and will automatically be removed if not used by a model. You can set this property to YES in order to pre-load shader programs that will not be immediately used in the scene, but which you wish to keep in the cache for later use.

+ (void) setProgramMatcher: (id< CC3ShaderMatcher >)  __deprecated
Deprecated:
Renamed to setShaderMatcher:.
+ (void) setShaderMatcher: (id< CC3ShaderMatcher >)  shaderMatcher

This property contains a helper delegate object that determines which shaders to use when rendering a particular CC3MeshNode.

Rendering a mesh node requires a shader program. Typically, the shader program is assigned to the mesh node when the node is created or loaded from a model resource. This is either done by the resource loader, based on configuration information, or by the application directly, via the shaderProgram or shaderContext properties on the mesh node.

As a convenience, once a mesh node has been constructed and configured, the application can use the shader matcher in this property to retrieve a shader program suitable for rendering that node.

If the application does not assign a specific shader program to a mesh node, the shader matcher in this property will be accessed automatically to assign a shader program when the node is first rendered.

If desired, the application can set a custom shader matcher into this property. If the value of this property is not explicitly set by the application, it is lazily initialized to an instance of CC3ShaderMatcherBase, the first time it is accessed.

+ (void) setShouldAutomaticallyPreloadMatchingPureColorPrograms: (BOOL)  shouldAdd

Sets whether this shader program cache should automatically add a matching pure-color shader program for each normal shader program that is added to this cache during shader program preloading.

If both this property and the isPreloading property are set to YES, the addProgram method will ensure that a matching pure-color shader program is added for each normal shader program that is added using that method.

If pre-loading is not active, each shader program is loaded dynamically the first time it is needed, and is added to the cache at that time. For such dynamically-loaded shader programs, the corresponding pure-color shader program will be dynamically loaded when it is needed, in turn. Typically this will be the first time node is involved in node picking as a result of a touch event.

The initial value of this property is YES, ensuring that a matching pure-color program will be added for each normal shader program that is added during pre-loading. Pure-color shader programs are used when rendering a node for picking from a touch-event. You should therefore leave the value of this property at its default value, unless your app does not use touch events to pick nodes.

+ (id<CC3ShaderMatcher>) shaderMatcher

This property contains a helper delegate object that determines which shaders to use when rendering a particular CC3MeshNode.

Rendering a mesh node requires a shader program. Typically, the shader program is assigned to the mesh node when the node is created or loaded from a model resource. This is either done by the resource loader, based on configuration information, or by the application directly, via the shaderProgram or shaderContext properties on the mesh node.

As a convenience, once a mesh node has been constructed and configured, the application can use the shader matcher in this property to retrieve a shader program suitable for rendering that node.

If the application does not assign a specific shader program to a mesh node, the shader matcher in this property will be accessed automatically to assign a shader program when the node is first rendered.

If desired, the application can set a custom shader matcher into this property. If the value of this property is not explicitly set by the application, it is lazily initialized to an instance of CC3ShaderMatcherBase, the first time it is accessed.

+ (BOOL) shouldAutomaticallyPreloadMatchingPureColorPrograms

Returns whether this shader program cache should automatically add a matching pure-color shader program for each normal shader program that is added to this cache during shader program preloading.

If both this property and the isPreloading property are set to YES, the addProgram method will ensure that a matching pure-color shader program is added for each normal shader program that is added using that method.

If pre-loading is not active, each shader program is loaded dynamically the first time it is needed, and is added to the cache at that time. For such dynamically-loaded shader programs, the corresponding pure-color shader program will be dynamically loaded when it is needed, in turn. Typically this will be the first time node is involved in node picking as a result of a touch event.

The initial value of this property is YES, ensuring that a matching pure-color program will be added for each normal shader program that is added during pre-loading. Pure-color shader programs are used when rendering a node for picking from a touch-event. You should therefore leave the value of this property at its default value, unless your app does not use touch events to pick nodes.

- (CC3GLSLUniform*) uniformAtLocation: (GLint)  uniformLocation

Returns the uniform at the specified location, or nil if no uniform is defined at the specified location.

- (CC3GLSLUniform*) uniformForSemantic: (GLenum)  semantic

Returns the uniform with the specified semantic at index zero, or nil if no uniform is defined for the specified semantic.

- (CC3GLSLUniform*) uniformForSemantic: (GLenum)  semantic
at: (GLuint)  semanticIndex 

Returns the uniform with the specified semantic and index, or nil if no uniform is defined for the specified semantic.

- (CC3GLSLUniform*) uniformNamed: (NSString *)  name

Returns the uniform with the specified name, or nil if no uniform is defined for the specified name.

- (void) willBeginDrawingScene

Invoked automatically at the beginning of scene rendering.

Invokes the markSceneScopeDirty method to mark the scene scope variables as dirty and in need of re-populating.

+ (void) willBeginDrawingScene

Invoked to indicate that scene drawing is about to begin.

This method invokes the same method on each instance in the cache.

Property Documentation

- (GLuint) attributeCount
readnonatomicassign

Returns the number of vertex attributes declared and in use by this program.

- (NSArray*) attributes
readnonatomicassign

Returns a read-only array of the GLSL attributes declared and used by this shader program.

- (CC3FragmentShader*) fragmentShader
readwritenonatomicretain

The fragment shader used by this program.

Normally this property is set during initialization. If you set this property directly, you must invoke the link method, and optionally, the prewarm method, once both shaders have been set via this property and the vertexShader property.

- (GLint) maxAttributeNameLength
readnonatomicassign

Returns the length of the largest attribute name in this program.

- (GLint) maxUniformNameLength
readnonatomicassign

Returns the length of the largest uniform name in this program.

- (GLuint) programID
readnonatomicassign

Returns the GL program ID.

- (id<CC3ShaderSemanticsDelegate>) semanticDelegate
readwritenonatomicretain

On each render loop, this CC3ShaderProgram delegates to this object to populate the current value of each uniform variable from content within the 3D scene.

This property must be set prior to the program being compiled.

- (BOOL) shouldAllowDefaultVariableValues
readwritenonatomicassign

Each uniform used by this shader program must have a valid value.

This property can be used to indicate whether a uniform, whose value cannot be determined, will use its standard default value.

If the value of this property is YES, and the value of a uniform has not been set via either a semantic mapping, or a uniform override in the shader context in a mesh node, a default value will be used for the variable. The default value depends on the variable type. It will be zero for scalars, (0,0,0,1) for vectors, or an identity matrix for matrices.

If the value of this property is NO, and the value of a uniform has not been set via either a semantic mapping, or a uniform override in the shader context in a mesh node, an assertion error will be raised. This ensures that unexpected missing uniform variables are detected directly and early in the development cycle.

The initial value of this property is determined by the value of the class-side defaultShouldAllowDefaultVariableValues property. By default, this will be NO, indicating that an assertion error will be raised if the value of a uniform cannot be determined.

- (GLuint) texture2DCount
readnonatomicassign

Returns the number of 2D textures supported by this shader program.

- (GLuint) texture2DStart
readnonatomicassign

Returns the texture unit index of the first 2D texture supported by this shader program.

The 2D textures are allocated consecutive texture units beginning at the returned texture unit.

- (GLuint) textureCubeCount
readnonatomicassign

Returns the number of cube-map textures supported by this shader program.

- (GLuint) textureCubeStart
readnonatomicassign

Returns the texture unit index of the first cube texture supported by this shader program.

The cube textures are allocated consecutive texture units beginning at the returned texture unit.

- (GLuint) textureLightProbeCount
readnonatomicassign

Returns the number of light probe textures supported by this shader program.

- (GLuint) textureLightProbeStart
readnonatomicassign

Returns the texture unit index of the first light probe texture supported by this shader program.

The light probe textures are allocated consecutive texture units beginning at the returned texture unit.

- (GLuint) uniformCount
readnonatomicassign

Returns the number of uniforms declared and in use by this program.

- (NSArray*) uniforms
readnonatomicretain

Returns a read-only array of the GLSL uniforms declared and used by this shader program.

- (GLuint) uniformStorageElementCount
readnonatomicassign

Returns the number of memory storage elements consumed by the uniform variables used by this program.

- (CC3VertexShader*) vertexShader
readwritenonatomicretain

The vertex shader used by this program.

Normally this property is set during initialization. If you set this property directly, you must invoke the link method, and optionally, the prewarm method, once both shaders have been set via this property and the fragmentShader property.

- (BOOL) wasLoadedFromFile
readnonatomicassign

Indicates whether this shader program was loaded from files.

Returns YES if both the vertex and fragment shaders were loaded from files, otherwise returns NO.


The documentation for this class was generated from the following file: