CC3ShaderMatcher Protocol Reference
Conforms to | CC3Object |
Declared in | CC3ShaderMatcher.h |
Overview
CC3ShaderMatcher describes the behaviour required to match nodes and materials to an appropriate GL program for rendering a particular node.
Under OpenGL ES 2, every drawable mesh node requires a CC3ShaderProgram to be rendered. Typically, the application will deliberately assign a specific GL program to each material, through the shaderProgram or shaderContext properties of the material, and in some cases, this may be defined during model loading from resources.
When a model is created or loaded without a specific CC3ShaderProgram assigned, the material will retrieve an appropriate default shader from the shader cache. The shader cache maintains an instance of an implementation of this protocol and delegates to it to match the model to a suitable GL program.
Tasks
-
– programForMeshNode:
required method -
– pureColorProgramMatching:
required method -
semanticDelegate
property required method
Properties
semanticDelegate
The semantic delegate that will be attached to any program created by this matcher.
@property (nonatomic, retain) id<CC3ShaderSemanticsDelegate> semanticDelegate
Discussion
The initial value of this property is an instance of CC3ShaderSemanticsByVarName that has been populated with default semantics by the populateWithDefaultVariableNameMappings method.
Declared In
CC3ShaderMatcher.h
Instance Methods
programForMeshNode:
Returns the shader program to use to draw the specified mesh node.
- (CC3ShaderProgram *)programForMeshNode:(CC3MeshNode *)aMeshNode
Discussion
Returns a shader program selected from the characteristics of the mesh node and its material.
The returned program will be compiled and linked, and will have a semantics delegate assigned in the semanticDelegate property.
The implementation is responsible for determining how to match the specified mesh node to an appropriate GL program, and each implementation may have a different matching methodology.
Implementations are responsible for compiling, linking, and assigning a semantics delegate to the program.
Declared In
CC3ShaderMatcher.h
pureColorProgramMatching:
Returns a shader program that matches the specified shader program, but renders the mesh in a single, solid color, instead of taking into consideration lighting, textures, etc.
- (CC3ShaderProgram *)pureColorProgramMatching:(CC3ShaderProgram *)shaderProgram
Discussion
The returned shaderProgram will be used for rendering the mesh node during paint-based node picking, or can be used for simply rendering the mesh while ignoring lighting, material and textures.
Implementation should ensure that the vertices will be rendered in the same position as the specified shader program. Typical implementations will return a shader program that uses the same vertex shader as the specified shader program, but has a fragment shader that renders in a single color.
Declared In
CC3ShaderMatcher.h