2

我正在尝试使用 GLKit 渲染两个对象。最初我试图这样做:

[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;

但是,这似乎会导致内存泄漏。我在某处读到:

“基本”属性(lightingType、lightModelTwoSided、colorMaterialEnabled...)的每次更改都会导致新的着色器程序在下一次“prepareToDraw”调用中加载。

如果我删除 self.effect.light0.enabled 更改并运行以下命令,则不会出现内存泄漏问题:

[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;

我尝试创建 2 个不同的 GLKBaseEffects 但第二个对象无法正确渲染地板。

drawViewController 调用 prepareToDraw 并如下所示:

-(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);
}
4

0 回答 0