0

I'm trying to draw a lot of squares by loading vertex data (position and texture coordinates) into a VBO. My issue is when I try to load all of these vertices, for some reason it skips over some squares, leaving an empty space. if I reduce the number of squares, then this issue does not occur.

Here's how I attempt to set up the 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];

And here's how it's rendered:

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);

A lot of code has been omitted for simplicity, I'm only showing what I think is relevant. Let me know if it's not enough.

Edit: Here's an image of my issue: enter image description here

Update: I've seperated the buffers into smaller chunks and rendered them individually. Here are the results (edited with MS Paint):
2x2 chunks: enter image description here

4x4 chunks: enter image description here

The bottom left corner tiles of the 4x4 are suppose to be empty. The adjacent chunk is suppose to be completely filled. It looks like there is some limit to the number of vertex one buffer can hold/render, 3 for the 2x2, and 9 for the 4x4. (ignore the green stuff, there in a different buffer).
1x1 chunks (every tile is in their own buffer) renders everything completely fine, but performance takes a huge hit.

George
  • 2,820
  • 4
  • 29
  • 56
  • Mah is it considered as a lot os squares? Do you have any idea what is missing, is it random or it just draws till some point? Like firs 65536 vertices? – Matic Oblak Jun 18 '15 at 10:42
  • i'm trying to draw a textured grid, but there are some holes in the grid. – George Jun 18 '15 at 21:08
  • Well the code you posted seems fine. There are still a few possible issues causing this but you may try to eliminate a few. Please try to use the same buffer as you do and try to draw each rectangle separately. Just create a for loop and set the vertex attribute pointers accordingly to draw only that rectangle. This is not a fix, it will produce a bad performance but will give a better understanding on where the issue is. Please report the result then. – Matic Oblak Jun 19 '15 at 06:27
  • How do I draw each rectangle separately when they are in the same buffer? I updated by inserting data into separate buffers instead. – George Jun 19 '15 at 13:50
  • Such as calling GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 20, i*(3*4 + 2*4)); where i is the vertex index in your case. And draw just 3 vertices instead of one. Makes no difference how many buffers you use, just set the correct pointer. – Matic Oblak Jun 19 '15 at 13:56

0 Answers0