2
votes

Hi this is my first post here :) I working on Android 2.3 OpenGL ES 2 2D game engine. I try to improve performance by building one big VBO instead of drawing sprite one by one. I using batching to draw 32 sprites at once.

This is my vertex shader definition:

uniform mat4 mvpMatrix[32];

When I use client side memory

for (int k = 0; k < m; k++)
    mvpBuffor.put(models[k], 0, models[k].length);
mvpBuffor.position(0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, m, false, mvpBuffor);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, m * VERTEX_PER_SPRITE);

and this works very good but when I try to use VBO

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, batch.mvpBufferIndex);
GLES20.glEnableVertexAttribArray(mMVPMatrixHandle);
GLES20.glVertexAttribPointer(mMVPMatrixHandle, MVP_SIZE * BATCHSIZE, GLES20.GL_FLOAT, false, 0, 0);

I get error code 1281

Any one knows how to pass array of mat4 uniform to vertex shader ?

3
Which line gives you the error?Tim

3 Answers

0
votes

If you read this page, it should be something like:

GLES20.glUniformMatrix4fv(<handle>, <number of matrices>, <transposed?>, <array of matrices>);
0
votes

It looks as though your shader's still declaring the mvpMatrix as uniform

uniform mat4 mvpMatrix[32];

yet you're trying to pass it in as an attribute:

GLES20.glEnableVertexAttribArray(mMVPMatrixHandle); GLES20.glVertexAttribPointer(mMVPMatrixHandle, MVP_SIZE * BATCHSIZE, GLES20.GL_FLOAT, false, 0, 0);