Open mattdesl opened 9 years ago
will log to console.error
by default unless quiet: true
(for unit tests etc)
though console.warn
looks nice too
looking into this a bit more. the shader wrapper that stackgl uses is quite nice since it allows for a clean way of handling structs and arrays:
shader.uniforms.lights[0] = {
position: ...
}
Compare with string-based access.
The downside is that you end up very easily calling glGetUniform
which can destroy framerate, and also it doesn't behave like you would expect. Generally using getter/setter to perform a complex action can lead to surprises IMHO.
//does not work as expected
vec3.add(shader.uniforms.lightPosition, aVec, bVec)
EDIT:
Alternative syntax where the discrete uniforms are functions:
//query current uniform looks like this
var pos = shader.uniforms.lights[0].position()
//set uniform, no ambiguity here since it's a function
vec3.add(tmp, aVec, bVec)
shader.uniforms.lights[0].position(tmp)
Or more verbose:
shader.uniforms.lights[0].position.set(tmp)
shader.uniforms.lights[0].position.get()
I actually think that maybe it is worth killing gl-shader long term. A more ideal solution would be to have a "draw command" that could take the shader source as a string argument, along with all uniforms that need to be set. Then these could be grouped using some "draw list" that would combine and reorder draw commands so that the number of shader state changes and uniform updates are minimized.
Interesting idea. Definitely going to think about it and how it could all look for the end-user.
shader
see dev branch for progress
gl-shader
, try to share code where possible e.g. gl-shader-extractprogram
handle, no cachingglGetUniform
calls should be more opaque so the dev doesn't accidentally query GL stategl-shader
uniform wrapper approach and whether something else is more suitable