创建IBO后glDrawArrays段错误

时间:2012-08-29 01:09:29

标签: opengl

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

当我添加IBO时,即使没有任何使用它的渲染代码,我也会在glDrawArrays上崩溃。

我检查了所有glBindBuffer调用10次,问题不存在。但这与国际文凭组织的规模有关。这是触发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与崩溃可能性的相关性,但我无法弄清楚我做错了什么。 / p>

我使用官方的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;
}

0 个答案:

没有答案
相关问题