Failure to use matrices as vertex shader attributes

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?

+4
1

:

int handle = GLES20.glGetAttribLocation( programId, "vertexTransformation" );
GLES20.glEnableVertexAttribArray( handle );
GLES20.glVertexAttribPointer( handle, 16, GLES20.GL_FLOAT, false, 92, 28 );

OpenGL 4-, mat4 vertex 4 4- .

mat4:

int handle = GLES20.glGetAttribLocation( programId, "vertexTransformation" );

GLES20.glEnableVertexAttribArray( handle );
GLES20.glVertexAttribPointer( handle, 4, GLES20.GL_FLOAT, false, 92, 28 );

GLES20.glEnableVertexAttribArray( handle + 1 );
GLES20.glVertexAttribPointer( handle + 1, 4, GLES20.GL_FLOAT, false, 92, 28+16 );

GLES20.glEnableVertexAttribArray( handle + 2 );
GLES20.glVertexAttribPointer( handle + 2, 4, GLES20.GL_FLOAT, false, 92, 28+32 );

GLES20.glEnableVertexAttribArray( handle + 3 );
GLES20.glVertexAttribPointer( handle + 3, 4, GLES20.GL_FLOAT, false, 92, 28+48 );

, 4 ? "vertexTransformation" handle handle+3.

+5

All Articles