0

我有一堆元素当前从 VBO 渲染使用glDrawArrays没有问题。

但是,当我添加一个 IBO 时,即使没有任何使用它的渲染代码,我也会在glDrawArrays.

我检查了所有 glBindBuffer 调用 10 次,问题不存在。但这与IBO的规模有关。这是触发 glDrawArrays 崩溃的附加代码:

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, NULL, GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

如果size超过 5kb,我开始崩溃。崩溃是一致的,但取决于我正在渲染的元素。例如,在 6kb 时我不会立即崩溃,但如果我拉下另一个最初隐藏的 UI 元素,它会在渲染时崩溃。如果我将它设置在 8kb 以上,我总是会立即在第一个元素上使用glDrawArrays.

我的直觉是glBufferData,考虑到与崩溃可能性的相关性,该调用以某种方式破坏了某处的内存size,但我无法弄清楚我做错了什么。

我正在使用官方 nVidia 驱动程序在 x64 Linux 上运行。

编辑:这是 glDrawArrays 代码:

cgGLBindProgram(program);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
cgGLEnableClientState(verts);
cgGLSetParameterPointer(verts, vertSize, GL_FLOAT, stride, reinterpret_cast<void*>(vertoffset);
gGLEnableClientState(texcoords);
cgGLSetParameterPointer(texcoords, tcSize, GL_FLOAT, tcstride, reinterpret_cast<void*>(tcoffset);
cgSetMatrixParameterfc(matrix, (*m)[0]);   // ortho matrix
cgGLSetParameter4f(color, f1, f2, f3, f4);
cgGLBindProgram(fragmentProgram);
cgGLSetTextureParameter(texture, tex->getID());
cgGLEnableTextureParameter(texture);
glDrawArrays(GL_QUADS, first, vertCount);

使用的着色器:

output ortho(float2 position : POSITION, float2 texCoord : TEXCOORD0, uniform float4 color : COLOR, uniform float4x4 ortho_proj) {
    output OUT;

    OUT.position = mul(float4(position, 0, 1), ortho_proj);
    OUT.color = color;
    OUT.texCoord = texCoord;

    return OUT;
}

void textured(float4 color : COLOR, float2 texCoord : TEXCOORD0, out float4 outColor, uniform sampler2D texture) {
    outColor = tex2D(texture, texCoord) * color;
}
4

0 回答 0