Getting computed matrix data

My fragment shader program performs a 4 x 4 matrix multiplication using the mat4 type. How do I read the matrix result in OpenGL?

void main(void)
mat4 MatA = mat4(0.0, 1.0, 2.0, 3.0,
4.0, 5.0, 6.0, 7.0,
8.0, 9.0, 10.0, 11.0,
12.0, 13.0, 14.0, 15.0);

mat4 MatB = mat4(1.0, 2.0, 3.0, 4.0,
5.0, 6.0, 7.0, 8.0,
9.0, 10.0, 11.0, 12.0,
13.0, 14.0, 15.0, 16.0);

mat4 MatR;

MatR = MatA * MatB;


i believe thats not possible. premultiply on CPU instead.

You can do it by using MRTs and reading back the pixel data, but what would be the point? Doing it on CPU would be much faster anyway.

Maybe you are looking for the matrixCompMult() function ?

From the GLSL spec :
mat matrixCompMult (mat x, mat y)

Multiply matrix x by matrix y component-wise, i.e.,
result[i][j] is the scalar product of x[i][j] and y[i][j].

Note: to get linear algebraic matrix multiplication, use
the multiply operator (*).

I think OpenCL is more appropriated for this issue.

Thanks for the suggestions.

I tried to equate gl_FragData[0] to MatR and it does not work because they are of data different types (vec4 and mat4). Also, it does not make sense to use 4 framebuffers to store the matrix data.

I could not use OpenCL cos my platform supports OpenGL and OpenGL SL

Again, why do you do it on GPU in the first place? It does not make sense to perform matrix multiplication on the GPU just to read it backā€¦ and if want to do it, you MUST use 4 color buffers, just to pack the data!