我正在尝试使用以下代码渲染一些索引的VBO三角形:
letterFrameSP.useProgram();
glBindBuffer(GL_ARRAY_BUFFER, letterFrame.getBufferVertex());
glVertexAttribPointer(
letterFrameSP.getaPositionLocation(),
3,
GL_FLOAT,
false,
letterFrame.getStride(),
0);
glEnableVertexAttribArray(letterFrameSP.getaPositionLocation());
glVertexAttribPointer(
letterFrameSP.getaNormalLocation(),
3,
GL_FLOAT,
false,
letterFrame.getStride(),
3*Math3dUtil.BYTES_PER_FLOAT);
glEnableVertexAttribArray(letterFrameSP.getaNormalLocation());
glVertexAttribPointer(
letterFrameSP.getaCubeIndex(),
1,
GL_FLOAT,
false,
letterFrame.getStride(),
(3+3)*Math3dUtil.BYTES_PER_FLOAT);
glEnableVertexAttribArray(letterFrameSP.getaCubeIndex());
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,letterFrame.getBufferIndex());
glDrawElements(
GLES20.GL_TRIANGLES,
letterFrame.getTriangleIndexCount(),
GL_UNSIGNED_SHORT,
0);
屏幕为黑色,呈现任何三角形。我使用Tracer For Opengl ES,这就是结果:
glClear(mask = 16640)
glUseProgram(program = 3)
glBindBuffer(target = GL_ARRAY_BUFFER, buffer = 2)
glVertexAttribPointer(indx = 1101, size = 3, type = GL_FLOAT, normalized = false, stride = 28, ptr = 0x0)
glEnableVertexAttribArray(index = 1101)
glVertexAttribPointer(indx = -1, size = 3, type = GL_FLOAT, normalized = false, stride = 28, ptr = 0xc)
glEnableVertexAttribArray(index = -1)
glVertexAttribPointer(indx = 0, size = 1, type = GL_FLOAT, normalized = false, stride = 28, ptr = 0x18)
glEnableVertexAttribArray(index = 0)
glBindBuffer(target = GL_ELEMENT_ARRAY_BUFFER, buffer = 1)
glUniformMatrix4fv(location = 0, count = 1, transpose = false, value = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -20.0, 1.0])
glUniformMatrix4fv(location = 0, count = 1, transpose = false, value = [3.2629604, 0.0, 0.0, 0.0, 0.0, 2.4142134, 0.0, 0.0, 0.0, 0.0, -1.020202, -1.0, 0.0, 0.0, 18.383839, 20.0])
glUniform3f(location = 1229, x = 0,000000, y = 10,000000, z = -10,000000)
glUniform1fv(location = 1230, count = 128, v = [0.0])
glUniform4f(location = 1231, x = 1,000000, y = 0,500000, z = 0,500000, w = 1,000000)
glDrawElements(mode = GL_MAP_INVALIDATE_RANGE_BIT, count = 3840, type = GL_UNSIGNED_SHORT, indices = 0x0)
glBindBuffer(target = GL_ARRAY_BUFFER, buffer = 0)
glBindBuffer(target = GL_ELEMENT_ARRAY_BUFFER, buffer = 0)
glDisableVertexAttribArray(index = 1101)
glDisableVertexAttribArray(index = -1)
glDisableVertexAttribArray(index = 0)
eglSwapBuffers
后续行是什么意思?
glDrawElements(mode = GL_MAP_INVALIDATE_RANGE_BIT, count = 3840, type = GL_UNSIGNED_SHORT, indices = 0x0)
我在glDrawElements函数中使用模式GLES20.GL_TRIANGLES,但在跟踪器中出现GL_MAP_INVALIDATE_RANGE_BIT。为什么呢?
答案 0 :(得分:4)
使用protobuf编码的捕获的跟踪仅包含参数的数值。
GL_TRIANGLES
和GL_MAP_INVALIDATE_RANGE_BIT
具有相同的值。从官方OpenGL头文件:
#define GL_TRIANGLES 0x0004
...
#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004
跟踪显示工具不是很聪明,并且选择了错误的数值枚举表示。
这两个具有相同值的“枚举”在常规OpenGL使用中不是问题,因为它们从未被用作相同API调用的可能参数:
GL_MAP_INVALIDATE_RANGE_BIT
是位掩码的可能值,只能传递给期望相应位掩码值的glMapBufferRange()
等特定API调用。GL_TRIANGLES
是常规枚举,并作为参数传递给glDraw*()
次调用。它恰好具有非常低的值,因为它是原始版本的OpenGL中定义的第一个值之一。所以这是无害的。如果跟踪显示工具知道哪些参数对哪些API调用有效,则可以轻松显示正确的值。