var native = native_float_array
if native == null or array.length > native.length then
- if native != null then native.destroy
+ if native != null then native.finalize
native = new GLfloatArray.from(array)
self.native_float_array = native
else
fun uniform(val: Bool) do uniform_1i(location, if val then 1 else 0)
end
+# Shader uniform of GLSL type `int`
+class UniformInt
+ super Uniform
+
+ # Set this uniform value
+ fun uniform(val: Int) do uniform_1i(location, val)
+end
+
# Shader uniform of GLSL type `vec4`
class UniformFloat
super Uniform
class InactiveUniform
super InactiveVariable
super UniformBool
+ super UniformInt
super UniformFloat
super UniformSampler2D
super UniformVec2
var uniform
if typ == gl_BOOL then
uniform = new UniformBool(gl_program, name, location, size)
+ else if typ == gl_INT then
+ uniform = new UniformInt(gl_program, name, location, size)
else if typ == gl_SAMPLER_2D then
uniform = new UniformSampler2D(gl_program, name, location, size)
else if typ == gl_FLOAT then
end
end
+ # Diagnose possible problems with the shaders of the program
+ #
+ # Lists to the console inactive uniforms and attributes.
+ # These may not be problematic but they can help to debug the program.
+ fun diagnose
+ do
+ if gl_program == null then compile_and_link
+
+ print "# Diagnose {class_name}"
+ for k,v in uniforms do
+ if not v.is_active then print "* Uniform {v.name} is inactive"
+ end
+ for k,v in attributes do
+ if not v.is_active then print "* Attribute {v.name} is inactive"
+ end
+ end
+
# Attributes of this program organized by name
#
# Active attributes are gathered at `compile_and_link`.
# Overwrite this matrix with the identity matrix
fun set_identity
do
- for i in 4.times do
- for j in 4.times do
+ for i in [0..4[ do
+ for j in [0..4[ do
matrix_set(i, j, if i == j then 1.0 else 0.0)
end
end
# Copy content of this matrix to a `NativeGLfloatArray`
fun fill_native(native: NativeGLfloatArray)
do
- for i in width.times do
- for j in height.times do
+ for i in [0..width[ do
+ for j in [0..height[ do
native.matrix_set(i, j, self[i, j])
end
end