View Full Version : problem with glUniformMatrix4fv
srinivasareddyp
03-04-2009, 12:27 AM
Hi,
I am using glUniformMatrix4fv to pass 3 matrices from my main program to vertex shader and geometry shader. When I pass 3 matrices independently its working fine but when trying to pass as array of matrices its giving invalid operation.
main program..
loc1 = glGetUniformLocation(shader,"gx1");
.....
....
float mat[48];
for(int i=0;i<16;i++)
{
mat[i]=gx[m][i];
mat[i+16]=gy[m][i];
mat[i+32]=gz[m][i];
}
glUniformMatrix4fv(loc1,3,0,mat);
in vertex and geometry shaders my declaration is
uniform mat4 gx1[3];
So what am I doing wrong? help me....
kruseborn
03-04-2009, 05:21 AM
I dont know exactly what you are doing wrong but try something more ease,
vector<Matrix> vecM;
vecM.push_back(gx);
vecM.push .....
glUniformMatrix4fv(loc1, size(vecM), 0, &vecMat[0])
srinivasareddyp
03-12-2009, 08:20 AM
Hi kruseborn,
I have tried what u suggested .Here is the code
//global
#include<vector>
typedef vector<double> Vec;
typedef vector<Vec> Matrix;
func displaypatch()
{
799 vector<Matrix> vecM;
800 vecM.push_back(gx[m]);
801 vecM.push_back(gy[m]);
802 vecM.push_back(gz[m]);
804 glUniformMatrix4fv(loc1, size(vecM), 0, &vecM[0]);
}
but I ended up with the following errors.As I have never used vectors i couldnt rectify them.
spline_patch.cpp: In function ‘void displaypatch(int)’:
spline_patch.cpp:800: error: no matching function for call to ‘std::vector<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > > >::push_back(float*&)’
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:602: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, _Alloc = std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > >]
there are same errors on 801 & 802 too.
Plz help me
Reedbeta
03-12-2009, 08:35 AM
For this to work you need to implement Matrix as a vector<float> with 16 elements in the correct order expected by glUniformMatrix4fv, not vector<vector<float> >. Also note that if you use doubles you need to switch to glUniformMatrix4dv ('d' for double, 'f' for float).
srinivasareddyp
03-12-2009, 10:02 AM
Hi kruseborn,
The method you suggested,did it work for you?. I dont think it works.Because in glUnoformMatrix4fv the 4th arg should be of type GLfloat* and you were passing kinda float***.
If it worked for you plz let me know.
srinivasareddyp
03-12-2009, 10:10 AM
Hi Reedbeta,
How do I know the order that is expected by glUniformMatrix4fv?Is there any standard format?. The method I did initially
loc1 = glGetUniformLocation(shader,"gx1");
.....
....
float mat[48];
for(int i=0;i<16;i++)
{
mat[i]=gx[m][i];
mat[i+16]=gy[m][i];
mat[i+32]=gz[m][i];
}
glUniformMatrix4fv(loc1,3,0,mat);
works fine when passing to geometry shader but goes wrong for vertex shader.
Reedbeta
03-12-2009, 12:42 PM
The order is the same as for other GL matrix commands like glLoadMatrix - that is, column major order, using the column vector convention.
Also, for questions about the behavior of a function like this, you should consult the docs (http://www.opengl.org/sdk/docs/man/) first.
kruseborn
03-13-2009, 01:39 AM
I have not tested it, what I wrote was how I pass multiple matrices in DX10, in DX10 there is an entity D3DXMATRIX, then you can just do a vector<D3DXMATRIX> matrices.
I just thought you can do the same thing in opengl, I have not tested it.
srinivasareddyp
03-13-2009, 03:58 AM
Hi,
Its woriking with a single dimensional vector with floats.
vector<float> vec;
for(int i=0;i<16;i++)
vec.push_back(gx[m][i]);
for(int i=0;i<16;i++)
vec.push_back(gy[m][i]);
for(int i=0;i<16;i++)
vec.push_back(gz[m][i]);
glUniformMatrix4fv(loc4,3,0,&vec[0]);
Thank You all Guys.
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.