Mac Developer Library

Developer

GLKit Framework Reference GLKBaseEffect Class Reference

Options
Deployment Target:

On This Page
Language:

GLKBaseEffect

Inheritance


Conforms To


Import Statement


Swift

import GLKit

Objective-C

@import GLKit;

Availability


Available in OS X v10.8 and later.

The GLKBaseEffect class provides shaders that mimic many of the behaviors provided by the OpenGL ES 1.1 lighting and shading model, including materials, lighting and texturing. The base effect allows up to three lights and two textures to be applied to a scene.

At initialization time, your application first creates a compatible OpenGL or OpenGL ES context and makes it current. Then, it allocates and initializes a new effect object, configures its properties, and calls its prepareToDraw method. Binding an effect causes a shader to be compiled and bound to the current context. The base effect also requires vertex data to be supplied by your application. To supply vertex data, create one or more vertex array objects. For each attribute required by the shader, the vertex array object should enable the attribute and point to data stored in a vertex buffer object.

At rendering time, your application calls the effect’s prepareToDraw method to prepare the effect. Then, it binds a vertex array object and submits one or more drawing commands.

Lighting calculations for the base effect are done in eye-space coordinates.  The light0, light1 and light2 properties hold the position and spot direction of the base effect’s lights. The transform property contains the model view matrix assigned to the scene. When a light is assigned a new position or spot direction, those values are immediately modified by the current model view matrix. Thus, it is important to sequence changes to the model view matrix and changes to the lights to achieve the desired light positioning.  Light positions that need to be transformed in a manner similar to scene geometry should be set after the model view matrix is updated.

Subclassing Notes

Although this class can be subclassed, there are no methods your subclass can use to directly override the underlying shader generation. Instead, your subclass should implement its functionality by changing the values of existing properties declared by the base class.

  • label label Property

    A string used to name your effect.

    Declaration

    Swift

    var label: String!

    Objective-C

    @property(nonatomic, copy) NSString *label

    Discussion

    The name of the effect isn’t used directly by GLKit, but is printed when, for example, you log the object to the console via the NSLog function.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • transform transform Property

    The modelview, projection and texture transformations applied to the vertex data when the effect is bound. (read-only)

    Declaration

    Swift

    var transform: GLKEffectPropertyTransform! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyTransform *transform

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • The strategy the effect uses to calculate light values at each fragment. See Determining How Lighting is Calculated.

    Declaration

    Swift

    var lightingType: GLKLightingType

    Objective-C

    @property(nonatomic, assign) GLKLightingType lightingType

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • A Boolean value that indicates whether lighting is calculated for both sides of a primitive.

    Declaration

    Swift

    var lightModelTwoSided: GLboolean

    Objective-C

    @property(nonatomic, assign) GLboolean lightModelTwoSided

    Discussion

    If the value is GL_TRUE and the back face of a primitive is being rendered, the lighting values are calculated by negating the surface normals for the primitive. If the value is GL_FALSE, then the facing of the primitive is ignored when performing the lighting calculation. The default value is GL_FALSE.

    Setting the value of this property to GL_TRUE may impact performance. Only use two-sided lighting when either side of a primitive could theoretically be visible to the camera.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • material material Property

    The material properties used when calculating the light values for a rendered primitive. (read-only)

    Declaration

    Swift

    var material: GLKEffectPropertyMaterial! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyMaterial *material

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • The ambient color applied to all primitives rendered by the effect.

    Declaration

    Swift

    var lightModelAmbientColor: GLKVector4

    Objective-C

    @property(nonatomic, assign) GLKVector4 lightModelAmbientColor

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • light0 light0 Property

    The lighting properties for the first light in the scene. (read-only)

    Declaration

    Swift

    var light0: GLKEffectPropertyLight! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyLight *light0

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • light1 light1 Property

    The lighting properties for the second light in the scene. (read-only)

    Declaration

    Swift

    var light1: GLKEffectPropertyLight! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyLight *light1

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • light2 light2 Property

    The lighting properties for the third light in the scene. (read-only)

    Declaration

    Swift

    var light2: GLKEffectPropertyLight! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyLight *light2

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • The properties for the first texture. (read-only)

    Declaration

    Swift

    var texture2d0: GLKEffectPropertyTexture! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyTexture *texture2d0

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • The properties for the second texture. (read-only)

    Declaration

    Swift

    var texture2d1: GLKEffectPropertyTexture! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyTexture *texture2d1

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • The order in which textures are applied to rendered primitives.

    Declaration

    Swift

    var textureOrder: [AnyObject]!

    Objective-C

    @property(nonatomic, copy) NSArray *textureOrder

    Discussion

    The value of this property should be an array whose contents are all GLKEffectPropertyTexture objects provided by the effect. The order of these objects in the array determines the order in which the textures are applied in the shader. For example, to reverse the order that the textures are applied to a scene, your application would use the following code:

    • baseEffect.textureOrder = [NSArray arrayWithObjects: baseEffect.texture2d1, baseEffect.texture2d0, nil];

    The default value is an array that executes the texture stages in increasing order, skipping any texture stages that are not enabled.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • fog fog Property

    The fog properties to apply to the scene. (read-only)

    Declaration

    Swift

    var fog: GLKEffectPropertyFog! { get }

    Objective-C

    @property(nonatomic, readonly) GLKEffectPropertyFog *fog

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • A Boolean value that indicates whether or not to use the color vertex attribute when calculating the light’s interaction with the material.

    Declaration

    Swift

    var colorMaterialEnabled: GLboolean

    Objective-C

    @property(nonatomic, assign) GLboolean colorMaterialEnabled

    Discussion

    If the value is set to GL_TRUE, then the color attribute provided in the vertex data is used as the material’s color when performing any lighting calculations. If the value is set to GL_FALSE then the colors stored in the material property are used to light the primitive. The default value is GL_FALSE.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • A Boolean value that indicates whether or not to use the constant color.

    Declaration

    Swift

    var useConstantColor: GLboolean

    Objective-C

    @property(nonatomic, assign) GLboolean useConstantColor

    Discussion

    If the value is set to GL_TRUE, then the value stored in the constantColor property is used as the color value for each vertex. If the value is set to GL_FALSE, then your application is expected to enable the GLKVertexAttribColor attribute and provide per-vertex color data. The default value is GL_FALSE.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • A constant color, used when per-vertex color data is not provided.

    Declaration

    Swift

    var constantColor: GLKVector4

    Objective-C

    @property(nonatomic, assign) GLKVector4 constantColor

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.

  • Prepares an effect for rendering.

    Declaration

    Swift

    func prepareToDraw()

    Objective-C

    - (void)prepareToDraw

    Discussion

    An effect must be prepared after it is configured and again when your application wants to use the effect to render any primitives. When your application prepares an effect, some OpenGL state is altered to allow the effect to operate:

    • The GL_CURRENT_PROGRAM state is always changed to point to the shader provided by the effect object.

    • When texturing is enabled, the GL_TEXTURE_BINDING_2D state may also change.

    If your application requires the previous state to be saved before the effect alters them, it must explicitly save and restore the values.

    Import Statement

    Objective-C

    @import GLKit;

    Swift

    import GLKit

    Availability

    Available in OS X v10.8 and later.