OpenGL ES - instancing - different uv-coord one drawcall

274 views Asked by At

I have the following problem in OpenGL ES3 concerning instancing

I draw 64 shapes in one drawcall - triangles. OK!

Then I want to give the shapes individual eyes and they are "blinking". The blinking means different offsets in the atlas (i.e. differents uv-coords). I could easily make one drawcall for all shapes with the same eye-state but if I want the shapes to be in different blinking-modes - how could I acomplish it with instancing. The method-signature does not allow it

GLES30.glDrawArraysInstanced(GLES30.GL_TRIANGLES, (vertexOffset +  bitmapIndex) * CreateGLContext.N_RECT_VERTS, CreateGLContext.N_RECT_VERTS, nShapes);

the vertexoffset is the position in the buffer and let say the first-eye has position 59. the next 60 and so on. Totally 7 eye-states and uv-coords

So I have 64 shapes and since I want them to have their own blinking-states which means differents offsets .. I do NOT know how I could acomplish it with just ONE draw call.

the draw-method in the class BlinkingEyes

 @Override
public void draw() {

    GLES30.glUseProgram(mProgramHandle);

    GLES30.glEnableVertexAttribArray(mPositionHandle);
    GLES30.glVertexAttribPointer(mPositionHandle, CreateGLContext.POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, CreateGLContext.STRIDE, 0);

    GLES30.glEnableVertexAttribArray(mTextureCoordinateHandle);
    GLES30.glVertexAttribPointer(mTextureCoordinateHandle, CreateGLContext.TEXTURE_COORDINATE_DATA_SIZE, GLES20.GL_FLOAT, false,
            CreateGLContext.STRIDE, CreateGLContext.POSITION_DATA_SIZE * CreateGLContext.BYTES_PER_FLOAT);

    setLargeMVPmatrix();

    GLES30.glUniformMatrix4fv(mMVPMatrixHandle, nShapes, false, mMVPMatrixMajor, 0);
    GLES30.glDrawArraysInstanced(GLES30.GL_TRIANGLES, (vertexOffset + bitmapIndex) * CreateGLContext.N_RECT_VERTS, CreateGLContext.N_RECT_VERTS, nShapes);

}

snippet from vertex-shader

uniform mat4 u_MVPMatrix[64];
in vec4 a_Position;  
v_TexCoordinate = a_TexCoordinate;
gl_Position =  u_MVPMatrix[gl_InstanceID] * a_Position;

snippet from fragment-shader

in vec2 v_TexCoordinate;
uniform sampler2D u_Texture;  
fragmentColor = texture(u_Texture, v_TexCoordinate);

Is there a solution to this problem? Could I possibly send the information to the shader and tell it to use different uv-coords for different shapes?

the eyes (snippet from the atlas)

enter image description here

0

There are 0 answers