Pass array to shader

六月ゝ 毕业季﹏ 提交于 2019-12-24 06:31:04

问题


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


回答1:


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/



来源:https://stackoverflow.com/questions/17002487/pass-array-to-shader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!