1

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

java
  • 1,165
  • 1
  • 25
  • 50
  • @Rabbid76 - but I can only send the second argument in the signature of glDrawArraysInstanced one time - correct? the count parameter tells which uv-coords and vertices i want from the atlas - right? So how could I use gl_InstanceID to get different offsets? I added a snippet of the vertexshader above – java Sep 24 '17 at 07:33
  • @Rabbid76 - THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!! – java Oct 08 '17 at 17:37

0 Answers0