Ofelia
Ofelia copied to clipboard
Passing an array of floats to a shader using setUniform1fv
If I use the function setUniform1fv to pass an array of floats to a shader I get this error:
Error in ofShader::setUniform1fv (arg 3), expected 'float const *' got 'table'
This probably happens because in the Lua script I define the float array as a table:
a = {}
a[1] = 2.0
a[2] = 4.0
Is there a way to pass the right variable type?
I don't think this is possible yet as the Lua bindings don't know how to translate from a table to a float vector. This would need to be handled by a custom typemap ala ofData binary string -> binary data bytes.
I ended up passing my float array as a 3×3 matrix, which is also semantically correct as I was passing a convolution matrix. Actually I'm not aware of many uses of uniform arrays in shaders.
In case someone else needs this:
local matrix = ofMatrix3x3()
matrix:set(1,1,1,0,0,0,1,1,1)
local shader = ofShader()
shader:setUniformMatrix3f("convolution", matrix:mat3())