Class: Rugl::StateManager
- Inherits:
-
Object
- Object
- Rugl::StateManager
- Defined in:
- lib/rugl/state_manager.rb
Constant Summary collapse
- HANDLERS =
{ blend: ->(gl, value) { State::Blend.apply(gl: gl, params: value) }, depth: ->(gl, value) { State::Depth.apply(gl: gl, params: value) }, stencil: ->(gl, value) { State::Stencil.apply(gl: gl, params: value) }, scissor: ->(gl, value) { State::Scissor.apply(gl: gl, params: value) }, cull: ->(gl, value) { State::Cull.apply(gl: gl, params: value) }, polygon_offset: ->(gl, value) { State::PolygonOffset.apply(gl: gl, params: value) }, color_mask: ->(gl, value) { State::ColorMask.apply(gl: gl, params: value) } }.freeze
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
- #apply(command_state, context:, props:) ⇒ Object
-
#initialize(gl: nil) ⇒ StateManager
constructor
A new instance of StateManager.
- #restore(previous_state) ⇒ Object
Constructor Details
#initialize(gl: nil) ⇒ StateManager
Returns a new instance of StateManager.
25 26 27 28 |
# File 'lib/rugl/state_manager.rb', line 25 def initialize(gl: nil) @gl = gl @current = default_state end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
23 24 25 |
# File 'lib/rugl/state_manager.rb', line 23 def current @current end |
Instance Method Details
#apply(command_state, context:, props:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rugl/state_manager.rb', line 30 def apply(command_state, context:, props:) return {} unless @gl return {} if command_state.nil? || command_state.empty? previous = {} command_state.each do |key, value| resolved = Dynamic.resolve(value, context: context, props: props) next if @current[key] == resolved previous[key] = @current[key] set_gl_state(key, resolved) @current[key] = deep_copy(resolved) end previous end |
#restore(previous_state) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/rugl/state_manager.rb', line 48 def restore(previous_state) return if !@gl || previous_state.nil? || previous_state.empty? previous_state.each do |key, value| set_gl_state(key, value) @current[key] = deep_copy(value) end nil end |