I am successfully drawing single objects with glDrawElements and I am now trying to render at least one object with glDrawElementsInstanced instead. However the object just flashes for a frame (or more, I can't tell) and then stays invisible. The main problem is I can't see what is happening on the shader side so I can't debug it. I was hoping for some experienced members taking a look before I Keep searching with Trial and error.
All I did was changing the vertex shader to this
#version 310 es
uniform mat4 projectionMatrix;
//uniform mat4 modelMatrix;
in mat4 modelMatrix;
uniform mat4 worldMatrix;
in vec4 in_Position;
in vec2 in_TextureCoord;
out vec2 pass_TextureCoord;
void main(void) {
gl_Position = projectionMatrix * worldMatrix * modelMatrix * in_Position;
pass_TextureCoord = in_TextureCoord;
}
and instead of using this every frame:
GLES31.glUniformMatrix4fv(currentShader.getUniLocations()[1], 1, false, matrix.getArray(), 0);
I am now doing this every frame:
ByteBuffer buffer = createBuffer( matrix.getArray() );
GLES31.glBindVertexArray(vaoID);
int id = attriLocations[index];
if (id != -1) {
for( int i = 0; i < 4; i++ ) {
GLES31.glEnableVertexAttribArray(id+i);
}
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, vboIDs[index]);
GLES31.glBufferData(GLES31.GL_ARRAY_BUFFER, buffer.size(), buffer, GLES31.GL_DYNAMIC_DRAW);
for( int i = 0; i < 4; i++ ) {
GLES31.glVertexAttribPointer(id+i, 4, GLES31.GL_FLOAT, false, 4 * 4 * 4, i * 4 * 4);
}
for( int i = 0; i < 4; i++ ) {
GLES31.glVertexAttribDivisor(id+i, 1);
}
}
GLES31.glBindVertexArray(0);
GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
It draws for a very short period (probably one frame) and then nothing at all, anymore. The other still non-instanced objects keep being drawn correctly and OpenGL throws no Error.