Pris0n
Pris0n

Reputation: 350

Pass array to shader

I create my array this.kernel: it hast 48 elements and I want to pass it to my fragment shader.

When i call

 gl.uniform3fv(gl.getUniformLocation(this.program, "kernel"), 16, this.kernel);

kernel is defined in my shader:

uniform vec3 kernel[16]; 

I get an error for not enough arguments. I already looked up the specification etc, but don't find my problem -.-

void glUniform3fv(  GLint  location, GLsizei  count, const GLfloat * value);

Thanks for help

€: I converted this.kernel to a float32array but I still have this error.

€2: error in Chrome: not enough arguments

in Firefox: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument

Upvotes: 2

Views: 5956

Answers (1)

Mortennobel
Mortennobel

Reputation: 3471

Your this.kernel needs to be a Float32Array of length 48 (=3*16). You cannot use an array of vec3s.

Also the count is not used in WebGL. The function is (from WebGL Specification)

void uniform3fv(WebGLUniformLocation? location, Float32Array v);

Example usage:

gl.uniform3fv(gl.getUniformLocation(shaderProgram, "colors"), new Float32Array([0,1,2,3,4,5]));

See a complete example here: http://jsfiddle.net/mortennobel/URvtx/

Upvotes: 3

Related Questions