Class: SFML::RenderStates
- Inherits:
-
Object
- Object
- SFML::RenderStates
- Defined in:
- lib/sfml/graphics/render_states.rb
Overview
The state passed alongside a draw call: blend mode, texture, shader, transform, coordinate type. You rarely instantiate this directly —‘window.draw(…)` accepts `blend_mode:`, `texture:`, etc. shortcuts that build a RenderStates internally. Construct one yourself when you need to keep the same combination across many draws:
states = SFML::RenderStates.new(
blend_mode: SFML::BlendMode::ADD,
texture: glow_texture,
)
window.draw(va, render_states: states)
window.draw(other, render_states: states)
All fields default to the CSFML ‘sfRenderStates_default` value.
Constant Summary collapse
- COORDINATE_TYPES =
%i[normalized pixels].freeze
- COORDINATE_INDEX =
COORDINATE_TYPES.each_with_index.to_h.freeze
Instance Attribute Summary collapse
-
#blend_mode ⇒ Object
readonly
Returns the value of attribute blend_mode.
-
#coordinate_type ⇒ Object
readonly
Returns the value of attribute coordinate_type.
-
#shader ⇒ Object
readonly
Returns the value of attribute shader.
-
#stencil_mode ⇒ Object
readonly
Returns the value of attribute stencil_mode.
-
#texture ⇒ Object
readonly
Returns the value of attribute texture.
Class Method Summary collapse
-
.from_draw_opts(opts) ⇒ Object
Convenience: build a RenderStates from the same shortcut kwargs that RenderTarget#draw accepts.
Instance Method Summary collapse
-
#initialize(blend_mode: nil, stencil_mode: nil, texture: nil, shader: nil, coordinate_type: :normalized) ⇒ RenderStates
constructor
A new instance of RenderStates.
Constructor Details
#initialize(blend_mode: nil, stencil_mode: nil, texture: nil, shader: nil, coordinate_type: :normalized) ⇒ RenderStates
Returns a new instance of RenderStates.
22 23 24 25 26 27 28 29 30 |
# File 'lib/sfml/graphics/render_states.rb', line 22 def initialize(blend_mode: nil, stencil_mode: nil, texture: nil, shader: nil, coordinate_type: :normalized) @blend_mode = blend_mode @stencil_mode = stencil_mode @texture = texture @shader = shader @coordinate_type = coordinate_type raise ArgumentError, "unknown coordinate_type: #{coordinate_type.inspect}" unless COORDINATE_INDEX.key?(coordinate_type) freeze end |
Instance Attribute Details
#blend_mode ⇒ Object (readonly)
Returns the value of attribute blend_mode.
20 21 22 |
# File 'lib/sfml/graphics/render_states.rb', line 20 def blend_mode @blend_mode end |
#coordinate_type ⇒ Object (readonly)
Returns the value of attribute coordinate_type.
20 21 22 |
# File 'lib/sfml/graphics/render_states.rb', line 20 def coordinate_type @coordinate_type end |
#shader ⇒ Object (readonly)
Returns the value of attribute shader.
20 21 22 |
# File 'lib/sfml/graphics/render_states.rb', line 20 def shader @shader end |
#stencil_mode ⇒ Object (readonly)
Returns the value of attribute stencil_mode.
20 21 22 |
# File 'lib/sfml/graphics/render_states.rb', line 20 def stencil_mode @stencil_mode end |
#texture ⇒ Object (readonly)
Returns the value of attribute texture.
20 21 22 |
# File 'lib/sfml/graphics/render_states.rb', line 20 def texture @texture end |
Class Method Details
.from_draw_opts(opts) ⇒ Object
Convenience: build a RenderStates from the same shortcut kwargs that RenderTarget#draw accepts. Returns nil if no opts given (so the draw call uses the CSFML default without allocating anything).
53 54 55 56 |
# File 'lib/sfml/graphics/render_states.rb', line 53 def self.from_draw_opts(opts) return nil if opts.empty? new(**opts) end |