Array transfer to shader

I create my this.kernel array: it has 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); 
Nucleus

defined in my shader:

 uniform vec3 kernel[16]; 

I get an error for insufficient arguments. I already looked at the specification, etc., but did not find my problem -.-

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

thanks for the help

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

€ 2: error in Chrome: not enough arguments

in Firefox: NS_ERROR_XPC_BAD_CONVERT_JS: Failed to convert JavaScript argument

+1
source share
1 answer

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

Also counting is not used in WebGL. Function (from WebGL Specification )

 void uniform3fv(WebGLUniformLocation? location, Float32Array v); 

Usage example:

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

See the full example here: http://jsfiddle.net/mortennobel/URvtx/

+3
source

Source: https://habr.com/ru/post/1493555/


All Articles