I am trying to create an OpenGL vertex shader that has an extra transformation matrix for each vertex. My shader code is as follows:
uniform mat4 mvpMatrix;
attribute vec3 coordinates;
attribute mat4 vertexTransformation;
attribute vec4 vertexColor;
varying vec4 v_color;
void main()
{
vec4 pos = vec4( coordinates, 1 );
pos = vertexTransformation * pos;
pos = mvpMatrix * pos;
gl_Position = pos;
v_color = color;
}
Whenever I do this in an Android emulator, the emulator crashes.
I tried to isolate the problem and found that this happens when I access the attribute vertexTransformation. The following code also crashes, even if there are no additional matrix operations.
uniform mat4 mvpMatrix;
attribute vec3 coordinates;
attribute mat4 vertexTransformation;
attribute vec4 vertexColor;
varying vec4 v_color;
void main()
{
vec4 pos = vec4( coordinates, 1 );
pos = mvpMatrix * pos;
gl_Position = pos;
vec4 col = vec4( 0,0,0,1 );
if ( vertexTransformation[0][0] == 0.5 )
v_color = color;
else
v_color = vec4( 1, 1, 1, 1 );
}
I use glBufferDatafor data transfer:
ByteBuffer vertexData = ...;
vertexData.position( 0 );
GLES20.glBufferData( GLES20.GL_ARRAY_BUFFER, vertexData.remaining(), vertexData, GLES20.GL_STATIC_DRAW );
and then bind attributes with
int handle = GLES20.glGetAttribLocation( programId, "vertexTransformation" );
GLES20.glEnableVertexAttribArray( handle );
GLES20.glVertexAttribPointer( handle, 16, GLES20.GL_FLOAT, false, 92, 28 );
What am I doing wrong? Is there a way to provide matrix attributes to the vertex and use them in the vertex shader?