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 =
Texture coordinate-type symbols.
%i[normalized pixels].freeze
- COORDINATE_INDEX =
Coordinate-type symbol → integer Hash.
COORDINATE_TYPES.each_with_index.to_h.freeze
Instance Attribute Summary collapse
-
#blend_mode ⇒ Object
readonly
The blend mode, stencil mode, texture, shader, coordinate type components.
-
#coordinate_type ⇒ Object
readonly
The blend mode, stencil mode, texture, shader, coordinate type components.
-
#shader ⇒ Object
readonly
The blend mode, stencil mode, texture, shader, coordinate type components.
-
#stencil_mode ⇒ Object
readonly
The blend mode, stencil mode, texture, shader, coordinate type components.
-
#texture ⇒ Object
readonly
The blend mode, stencil mode, texture, shader, coordinate type components.
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.
25 26 27 28 29 30 31 32 33 |
# File 'lib/sfml/graphics/render_states.rb', line 25 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)
The blend mode, stencil mode, texture, shader, coordinate type components.
23 24 25 |
# File 'lib/sfml/graphics/render_states.rb', line 23 def blend_mode @blend_mode end |
#coordinate_type ⇒ Object (readonly)
The blend mode, stencil mode, texture, shader, coordinate type components.
23 24 25 |
# File 'lib/sfml/graphics/render_states.rb', line 23 def coordinate_type @coordinate_type end |
#shader ⇒ Object (readonly)
The blend mode, stencil mode, texture, shader, coordinate type components.
23 24 25 |
# File 'lib/sfml/graphics/render_states.rb', line 23 def shader @shader end |
#stencil_mode ⇒ Object (readonly)
The blend mode, stencil mode, texture, shader, coordinate type components.
23 24 25 |
# File 'lib/sfml/graphics/render_states.rb', line 23 def stencil_mode @stencil_mode end |
#texture ⇒ Object (readonly)
The blend mode, stencil mode, texture, shader, coordinate type components.
23 24 25 |
# File 'lib/sfml/graphics/render_states.rb', line 23 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).
56 57 58 59 |
# File 'lib/sfml/graphics/render_states.rb', line 56 def self.from_draw_opts(opts) return nil if opts.empty? new(**opts) end |