mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Refactored Shader.set_uniform into multiple methods
This commit is contained in:
@@ -125,7 +125,7 @@ module CyberarmEngine
|
|||||||
puts "Shader Error: Program \"#{@name}\""
|
puts "Shader Error: Program \"#{@name}\""
|
||||||
puts " Fragment Shader InfoLog:", " #{log.strip.split("\n").join("\n ")}\n\n"
|
puts " Fragment Shader InfoLog:", " #{log.strip.split("\n").join("\n ")}\n\n"
|
||||||
puts " Shader Compiled status: #{compiled}"
|
puts " Shader Compiled status: #{compiled}"
|
||||||
puts " NOTE: assignment of uniforms in shader is illegal!"
|
puts " NOTE: assignment of uniforms in shader is not allowed."
|
||||||
puts
|
puts
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -185,25 +185,40 @@ module CyberarmEngine
|
|||||||
glGetUniformLocation(@program, variable)
|
glGetUniformLocation(@program, variable)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_uniform(variable, value, location = nil)
|
def uniform_transform(variable, value, location = nil)
|
||||||
attr_loc = location ? location : attribute_location(variable)
|
attr_loc = location ? location : attribute_location(variable)
|
||||||
|
|
||||||
case value.class.to_s.split("::").last.downcase.to_sym
|
glUniformMatrix4fv(attr_loc, 1, GL_FALSE, value.to_gl.pack("F16"))
|
||||||
when :integer, :falseclass, :trueclass
|
end
|
||||||
value = value ? 1 : 0 if value.is_a?(TrueClass) or value.is_a?(FalseClass)
|
|
||||||
glUniform1i(attr_loc, value)
|
def uniform_boolean(variable, value, location = nil)
|
||||||
when :float
|
attr_loc = location ? location : attribute_location(variable)
|
||||||
glUniform1f(attr_loc, value)
|
|
||||||
when :string
|
glUniform1i(attr_loc, value ? 1 : 0)
|
||||||
when :transform
|
end
|
||||||
glUniformMatrix4fv(attr_loc, 1, GL_FALSE, value.to_gl.pack("F16"))
|
|
||||||
when :vector
|
def uniform_integer(variable, value, location = nil)
|
||||||
# TODO: add support for passing vec4
|
attr_loc = location ? location : attribute_location(variable)
|
||||||
# glUniform4f(attr_loc, *value.to_a[0..3])
|
|
||||||
glUniform3f(attr_loc, *value.to_a[0..2])
|
glUniform1i(attr_loc, value)
|
||||||
else
|
end
|
||||||
raise NotImplementedError, "Shader support for #{value.class.inspect} not implemented."
|
|
||||||
end
|
def uniform_float(variable, value, location = nil)
|
||||||
|
attr_loc = location ? location : attribute_location(variable)
|
||||||
|
|
||||||
|
glUniform1f(attr_loc, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def uniform_vec3(variable, value, location = nil)
|
||||||
|
attr_loc = location ? location : attribute_location(variable)
|
||||||
|
|
||||||
|
glUniform3f(attr_loc, *value.to_a[0..2])
|
||||||
|
end
|
||||||
|
|
||||||
|
def uniform_vec4(variable, value, location = nil)
|
||||||
|
attr_loc = location ? location : attribute_location(variable)
|
||||||
|
|
||||||
|
glUniform4f(attr_loc, *value.to_a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user