带堆栈内存的glDrawElements

时间:2012-11-20 06:55:06

标签: objective-c opengl-es opengl-es-2.0

我在函数堆栈中声明了两个数组,并验证它们都包含完全相同的数据:

/// Rasters the textured quad using the specified parameters.
- (void)privateConfigureRasterWithTexture:(GLuint)theTexture
                          bottomLeftX:(GLfloat)bottomLeftX
                          bottomLeftY:(GLfloat)bottomLeftY
                            topRightX:(GLfloat)topRightX
                            topRightY:(GLfloat)topRightY
{

    const GLfloat texices[] =
      { bottomLeftX, bottomLeftY,   // bottom left corner
        bottomLeftX,   topRightY,   // top left corner
          topRightX,   topRightY,   // top right corner
          topRightX, bottomLeftY }; // bottom right corner

    const GLfloat texices2[] =
      { 0.0f, 0.0f,
        0.0f, 1.0f,
        1.0f, 1.0f,
        1.0f, 0.0f };

    for(int x=0;x<8;x++)
        if(texices[x] != texices2[x])
        {
            NSLog(@"Mismatch!");
            abort();
        }

当我在该函数

的(底部)执行以下代码行时
glVertexAttribPointer(_attributeTexturedTexCoords, 2, GL_FLOAT, GL_FALSE,
                      2*sizeof(GLfloat), texices2);

我得到了预期的结果,但是如果我改为执行

glVertexAttribPointer(_attributeTexturedTexCoords, 2, GL_FLOAT, GL_FALSE,
                      2*sizeof(GLfloat), texices);

我得到了糟糕的结果。我不知道有什么区别。

编辑:以下是我调用此功能的方法。

[self privateConfigureRasterWithTexture:_atlasTexture1
                            bottomLeftX:0.0f
                            bottomLeftY:0.0f
                              topRightX:1.0f
                              topRightY:1.0f];

1 个答案:

答案 0 :(得分:0)

没关系,我想我已经找到了(可能是在Martins做的同一时间)。看起来glVertexAttribPointer在调用glDrawElements之前不会复制数据。由于我的glDrawElements超出了该函数,因此堆栈内存被释放(但由于某种原因,texices2仍然有效)。

我已经重写了一些代码,以便texices在分配该类时分配一次堆,并且在应用程序deallocs时反复重复使用并释放。