Public Member Functions | Static Public Member Functions | Properties

CC3Material Class Reference

CC3Material manages information about the material that is used to cover one or more meshes, including:

More...

#import <CC3Material.h>

Inheritance diagram for CC3Material:
CC3Identifiable CC3PODMaterial

List of all members.

Public Member Functions

(void) - draw
(void) - unbind

Static Public Member Functions

(GLenum) + defaultDestinationBlend
(GLenum) + defaultSourceBlend
(void) + initializeSwitching
(id) + material
(id) + materialWithName:
(id) + materialWithTag:
(id) + materialWithTag:withName:
(void) + setDefaultDestinationBlend:
(void) + setDefaultSourceBlend:
(id) + shiny
(id) + shinyWhite
(void) + unbind

Properties

ccColor4F ambientColor
ccColor3B color
GLenum destinationBlend
ccColor4F diffuseColor
ccColor4F emissionColor
BOOL isOpaque
GLubyte opacity
GLfloat shininess
GLenum sourceBlend
ccColor4F specularColor
CC3Texturetexture

Detailed Description

Each CC3MeshNode instance references an instance of CC3Material. Many CC3MeshNode instances may reference the same instance of CC3Material, allowing many objects to be covered by the same material.

When being drawn, the CC3MeshNode invokes the draw method on the CC3Material instance prior to drawing the associated mesh.

When drawing the material to the GL engine, this class remembers which material was last drawn, and only binds the material data to the GL engine when a different material is drawn. This allows the application to organize the CC3MeshNodes within the CC3World so that nodes using the same material are drawn together, before moving on to other materials. This strategy can minimize the number of mesh switches in the GL engine, which improves performance.


Member Function Documentation

+ (GLenum) defaultDestinationBlend

Returns the default GL material destination blend used for new instances.

The initial value is GL_ZERO.

+ (GLenum) defaultSourceBlend

Returns the default GL material source blend used for new instances.

The initial value is GL_ONE.

- (void) draw

If needed, applies this material to the GL engine.

This implementation first determine if this material is different than the material that was last bound to the GL engine. If this material is indeed different, this method applies the material to the GL engine, otherwise it does nothing.

This method is invoked from the draw method of any CC3Node instance referencing this CC3Material intance. Usually, the application never needs to invoke this method directly.

+ (void) initializeSwitching

Initializes the tracking of the material switching functionality.

This is invoked automatically by the CC3World at the beginning of each frame drawing cycle. Usually, the application never needs to invoke this method directly.

+ (id) material

Allocates and initializes an autoreleased unnamed instance with an automatically generated unique tag value.

The tag value is generated using a call to nextTag.

+ (id) materialWithName: (NSString *)  aName

Allocates and initializes an autoreleased instance with the specified name and an automatically generated unique tag value.

The tag value is generated using a call to nextTag.

+ (id) materialWithTag: (GLuint)  aTag

Allocates and initializes an unnamed autoreleased instance with the specified tag.

+ (id) materialWithTag: (GLuint)  aTag
withName: (NSString *)  aName 

Allocates and initializes an autoreleased instance with the specified tag and name.

+ (void) setDefaultDestinationBlend: (GLenum)  destBlend

Sets the default GL material destination blend used for new instances.

+ (void) setDefaultSourceBlend: (GLenum)  srcBlend

Sets the default GL material source blend used for new instances.

+ (id) shiny

Allocates and initializes an autoreleased unnamed instance with an automatically generated unique tag value.

The tag value is generated using a call to nextTag.

The returned instance will have a specularColor of { 1.0, 1.0, 1.0, 1.0 } and a shininess of 75.0.

+ (id) shinyWhite

Allocates and initializes an autoreleased unnamed instance with an automatically generated unique tag value.

The tag value is generated using a call to nextTag.

The returned instance will have both diffuseColor and specularColor set to { 1.0, 1.0, 1.0, 1.0 } and a shininess of 75.0.

- (void) unbind

Unbinds the GL engine from any materials.

This implementation simply delegates to the unbind class method. Usually, the application never needs to invoke this method directly.

+ (void) unbind

Unbinds the GL engine from any materials.

Disables material blending in the GL engine, and invokes the unbind class method of CC3Texture to disable texturing.

This method is invoked automatically from the CC3VertexArrayMeshModel instance. Usually, the application never needs to invoke this method directly.


Property Documentation

- (ccColor4F) ambientColor [read, write, assign]

The color of this material under ambient lighting.

Initially set to kCC3DefaultMaterialColorAmbient.

- (ccColor3B) color [read, write, assign]

Implementation of the CCRGBAProtocol color property.

When setting this property, the RGB values are each converted to a floating point number between 0 and 1, and are set into both the ambientColor and diffuseColor properties. The alpha of each of those properties remains the same.

Querying this property returns the RGB components of the material's diffuseColor property, converted from the floating point range (0 to 1), to the byte range (0 to 255).

- (GLenum) destinationBlend [read, write, assign]

The blending function for the destination material.

This property must be set to one of the valid GL blending functions.

The value in this property combines with the value in the sourceBlend property to determine the way that materials are combined when one (the source) is drawn over another (the destination). Features such as transparency can cause the two to blend together in various ways.

The initial value is determined by the value of the class-side property defaultDestinationBlend, which can be modified by the setDefaultDestinationBlend: method.

- (ccColor4F) diffuseColor [read, write, assign]

The color of this material under ambient lighting.

Initially set to kCC3DefaultMaterialColorDiffuse.

- (ccColor4F) emissionColor [read, write, assign]

The emission color of this material.

Initially set to kCC3DefaultMaterialColorEmission.

- (BOOL) isOpaque [read, assign]

Indicates whether this material is opaque.

This method returns YES if the value of the sourceBlend property is GL_ONE, and the value of the destinationBlend property is GL_ZERO, indicating that this material will completely block out any materials behind it. Otherwise it returns NO.

- (GLubyte) opacity [read, write, assign]

Implementation of the CCRGBAProtocol opacity property.

When setting this property, the value is converted to a floating point number between 0 and 1, and is set into all of the ambientColor, diffuseColor, specularColor, and emissionColor properties. The RGB components of each of those properties remains unchanged.

Querying this property returns the alpha component of the material's diffuseColor property, converted from the floating point range (0 to 1), to the byte range (0 to 255).

- (GLfloat) shininess [read, write, assign]

The shininess of this material.

Initially set to kCC3DefaultMaterialShininess.

- (GLenum) sourceBlend [read, write, assign]

The blending function for the source material (this material).

This property must be set to one of the valid GL blending functions.

The value in this property combines with the value in the destinationBlend property to determine the way that materials are combined when one (the source) is drawn over another (the destination). Features such as transparency can cause the two to blend together in various ways.

The initial value is determined by the value of the class-side property defaultSourceBlend, which can be modified by the setDefaultSourceBlend: method.

- (ccColor4F) specularColor [read, write, assign]

The color of this material under ambient lighting.

Initially set to kCC3DefaultMaterialColorSpecular.

- (CC3Texture *) texture [read, write, retain]

The texture covering this material.

This may be left nil if not texture is needed.


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