大型顶点数据缓冲区

时间:2015-06-18 02:24:45

标签: android opengl-es-2.0 vertex-buffer-objects

我试图通过将顶点数据(位置和纹理坐标)加载到VBO中来绘制大量正方形。我的问题是当我尝试加载所有这些顶点时,由于某种原因它跳过一些正方形,留下一个空的空间。如果我减少平方数,那么这个问题就不会发生。

以下是我尝试设置VBO的方法:

float[] vertexData = new float[<large number>];
//fill vertexData with 5 floats per square
FloatBuffer vertexBuffer = ByteBuffer.allocateDirect(vertexData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
vertexBufferBackground.put(vertexData).position(0);

int[] buffers = new int[1];
GLES20.glGenBuffers(1, buffers, 0);

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexBuffer.capacity() * 4, vertexBuffer, GLES20.GL_STATIC_DRAW);
bufferIDBackground = buffers[0];

以下是它的呈现方式:

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferID);
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 20, 0);

GLES20.glEnableVertexAttribArray(mTexCoordLoc);
GLES20.glVertexAttribPointer(mTexCoordLoc, 2, GLES20.GL_FLOAT, false, 20, 12);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

为简单起见,省略了很多代码,我只是展示了我认为相关的内容。如果这还不够,请告诉我。

编辑:这是我的问题的图片: enter image description here

更新:我已将缓冲区分成较小的块并单独渲染它们。以下是结果(使用MS Paint编辑):
2x2块: enter image description here

4x4块: enter image description here

4x4的左下角瓷砖假设是空的。相邻的块被认为是完全填充的。看起来一个缓冲区可以容纳/渲染的顶点数量有一些限制,2x2有3个,4x4有9个。 (忽略绿色的东西,在不同的缓冲区) 1x1块(每个块都在它们自己的缓冲区中)使一切都完全正常,但性能受到巨大冲击。

0 个答案:

没有答案