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];
4

1 回答 1

0

没关系,我想我已经找到了(可能在 Martins 的同一时间)。看起来glVertexAttribPointer直到调用glDrawElements. 由于 myglDrawElements在该函数之外,因此堆栈内存正在被释放(但由于某种原因texices2仍然有效)。

我已经稍微重写了代码,以便在texices分配该类时分配一次堆,并且只是一遍又一遍地重用并在应用程序解除分配时释放。

于 2012-11-20T07:24:32.367 回答