can't get glUniform3fv calls to work?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

can't get glUniform3fv calls to work?

Robert
Hi

I have been trying to pass an array of 3-float tuples to my shader using glUniform3fv, but I get a GL_INVALID_OPERATION error. I have no problem using glUniform1fv with a float array. I can post some code, but I'd first like to know if there is some known issue. I've googled the problem and there is next to no information anywhere about glUniformXfv where X is anything other than 1. It seems like nobody is using... is that because it doesn't work?
Reply | Threaded
Open this post in threaded view
|

Re: can't get glUniform3fv calls to work?

Robert
here's a bit of the code (there are many more cases of type checking, but the TupleXX[] and variants (Vector3f etc.) don't work and give the same error)
public static void sendUniform(SPShaderUniformData udata)
{
        if(udata!=null)
        {
                Object data = udata.data;
                               
                int uniformNum = ((Integer)(udata.nativeObject)).intValue();
                                                       
                if(data instanceof Tuple2f)  // works OK
                {
                        Tuple2f c = (Tuple2f)data;
                        gl.glUniform2f(uniformNum, c.x,c.y);
                }
                else if(data instanceof Integer) // works OK
                {
                        Integer fd = (Integer)data;
                        gl.glUniform1i(uniformNum, fd.intValue());
                }
                else if(data instanceof Tuple4f) // works OK
                {
                        Tuple4f fd = (Tuple4f)data;
                        gl.glUniform4f(uniformNum, fd.x, fd.y, fd.z, fd.w);
                }
                if(data instanceof float[]) // works OK
                {
                        float[] array = (float[])data;
                        gl.glUniform1fv(uniformNum, array.length, array, 0);
                }
                else if(data instanceof Float[]) // works OK
                {
                        Float[] fd = (Float[])data;
                       
                        float[] array = new float[fd.length];
                        for(int f=0;f<array.length;f++)
                        {
                                array[f] = fd[f].floatValue();
                        }
                               
                        gl.glUniform1fv(uniformNum, array.length, array, 0);
                }
                else if(data instanceof Vector3f[]) // fails!
                {
                        Vector3f[] fd = (Vector3f[])data;
                        float[] array = new float[fd.length*3];
                        for(int n=0;n<fd.length;n++)
                        {
                                array[n*3] = fd[n].x;
                                array[n*3+1] = fd[n].y;
                                array[n*3+2] = fd[n].z;
                        }
                        gl.glUniform3fv(uniformNum, fd.length, array, 0);
                }
Reply | Threaded
Open this post in threaded view
|

Re: can't get glUniform3fv calls to work?

gouessej
Administrator
Hi

I use it successfully in Ardor3D:
gl.getGL2ES2().glUniform3fv(shaderUniform.variableID, shaderUniform.value.remaining(),
                        shaderUniform.value);

I don't know what is wrong in your code. I use a FloatBuffer.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: can't get glUniform3fv calls to work?

Robert
thanks gouessej, using FloatBuffer fixed it!
Reply | Threaded
Open this post in threaded view
|

Re: can't get glUniform3fv calls to work?

gouessej
Administrator
You're welcome. I hope that your trouble wasn't caused by a bug in JOGL.
Julien Gouesse | Personal blog | Website