Lately I had problem with variable in my code. Variable that I send to GLSL don't work. It turned out I forgot uniform instruction before variable type.
Of course my memory is good but short.
Tabel of functions that use uniform instructions.
| uniform types | functions |
|---|---|
| float | gl.uniform1f gl.uniform1fv |
| vec2 | gl.uniform2f gl.uniform2fv |
| vec3 | gl.uniform3f gl.uniform3fv |
| vec4 | gl.uniform4f gl.uniform4fv |
| int | gl.uniform1i gl.uniform1iv |
| ivec2 | gl.uniform2i gl.uniform2iv |
| ivec3 | gl.uniform3i gl.uniform3iv |
| ivec4 | gl.uniform4i gl.uniform4iv |
| sampler2D | gl.uniform1i gl.uniform1iv |
| samplerCube | gl.uniform1i gl.uniform1iv |
| mat2 | gl.uniformMatrix2fv |
| mat3 | gl.uniformMatrix3fv |
| mat4 | gl.uniformMatrix4fv |
| bool | gl.uniform1i gl.uniform1f gl.uniform1iv gl.uniform1fv |
| bvec2 | gl.uniform2i gl.uniform2f gl.uniform2iv gl.uniform2fv |
| bvec3 | gl.uniform3i gl.uniform3f gl.uniform3iv gl.uniform3fv |
| bvec4 | gl.uniform4i gl.uniform4f gl.uniform4iv gl.uniform4fv |
Each functions in table take handle to GLSL variable in first argument
In functions prefix i is int, f float and v is table.
gl.getUniformLocation(glsl_program, variable_name) return handle to variable in GLSL.
In WebGL handle will be represented by WebGLUniformLocation interface.

Top comments (0)