Class: Engine::Material
- Inherits:
-
Object
- Object
- Engine::Material
- Defined in:
- lib/engine/material.rb
Instance Attribute Summary collapse
-
#shader ⇒ Object
readonly
Returns the value of attribute shader.
Instance Method Summary collapse
-
#initialize(shader) ⇒ Material
constructor
A new instance of Material.
- #set_float(name, value) ⇒ Object
- #set_mat4(name, value) ⇒ Object
- #set_texture(name, value) ⇒ Object
- #set_vec3(name, value) ⇒ Object
- #set_vec4(name, value) ⇒ Object
- #update_shader ⇒ Object
Constructor Details
#initialize(shader) ⇒ Material
Returns a new instance of Material.
7 8 9 |
# File 'lib/engine/material.rb', line 7 def initialize(shader) @shader = shader end |
Instance Attribute Details
#shader ⇒ Object (readonly)
Returns the value of attribute shader.
5 6 7 |
# File 'lib/engine/material.rb', line 5 def shader @shader end |
Instance Method Details
#set_float(name, value) ⇒ Object
23 24 25 |
# File 'lib/engine/material.rb', line 23 def set_float(name, value) floats[name] = value end |
#set_mat4(name, value) ⇒ Object
11 12 13 |
# File 'lib/engine/material.rb', line 11 def set_mat4(name, value) mat4s[name] = value end |
#set_texture(name, value) ⇒ Object
27 28 29 |
# File 'lib/engine/material.rb', line 27 def set_texture(name, value) textures[name] = value end |
#set_vec3(name, value) ⇒ Object
15 16 17 |
# File 'lib/engine/material.rb', line 15 def set_vec3(name, value) vec3s[name] = value end |
#set_vec4(name, value) ⇒ Object
19 20 21 |
# File 'lib/engine/material.rb', line 19 def set_vec4(name, value) vec4s[name] = value end |
#update_shader ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/engine/material.rb', line 31 def update_shader shader.use mat4s.each do |name, value| shader.set_mat4(name, value) end vec3s.each do |name, value| shader.set_vec3(name, value) end vec4s.each do |name, value| shader.set_vec4(name, value) end floats.each do |name, value| shader.set_float(name, value) end textures.each.with_index do |(name, value), slot| GL.ActiveTexture(Object.const_get("GL::TEXTURE#{slot}")) if value GL.BindTexture(GL::TEXTURE_2D, value) else GL.BindTexture(GL::TEXTURE_2D, 0) end shader.set_int(name, slot) end end |