I am trying to render two objects with GLKit. Initially I was trying to do this:
[Cube drawViewController:self.effect CameraMatrix:&lookatmatrix];
//turn off lighting for floor
self.effect.light0.enabled = GL_FALSE;
[Floor drawViewController:self.effect CameraMatrix:&lookatmatrix];
self.effect.light0.enabled = GL_TRUE;
However this seems to cause a memory leak. I read somewhere that:
Each change of the "fundamental" properties (lightingType, lightModelTwoSided, colorMaterialEnabled, ...) will cause a new shader program to be loaded with the next "prepareToDraw" call.
If I remove the self.effect.light0.enabled changes and run the following I do not have a memory leak issue:
[Cube drawViewController:self.effect CameraMatrix:&lookatmatrix];
//turn off lighting for floor
//self.effect.light0.enabled = GL_FALSE;
[Floor drawViewController:self.effect CameraMatrix:&lookatmatrix];
//self.effect.light0.enabled = GL_TRUE;
I tried creating 2 different GLKBaseEffects but the second object will not render the floor correctly.
drawViewController calls prepareToDraw and looks like the following:
-(void) drawViewController:(GLKBaseEffect *)effect CameraMatrix:(GLKMatrix4 *)cameramatrix
{
GLKMatrix4 modelViewMatrix = GLKMatrix4Multiply(*cameramatrix, modelMatrix);
effect.transform.modelviewMatrix = modelViewMatrix;
[effect prepareToDraw];
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *TextureID);
glBindVertexArrayOES(modelvertdata.vertexArray);
glDrawArrays(GL_TRIANGLES, 0, modelvertdata.NumVerts);
}