class SFML::StencilMode
How a draw call interacts with the stencil buffer. The classic use is masking β first you draw a βmaskβ shape that writes a value into the stencil buffer, then you draw the masked content with a comparison that only lets pixels through where the stencil matches.
target.clear(SFML::Color.black, stencil: 0)
# Phase 1 β write the mask shape into the stencil buffer. write = SFML::StencilMode.new( comparison: :always, update_operation: :replace, reference: 1, only_write_mask: true, # donβt actually paint colour ) target.draw(mask_circle, stencil_mode: write)
# Phase 2 β draw the content; only pixels where stencil == 1 # survive. read = SFML::StencilMode.new( comparison: :equal, update_operation: :keep, reference: 1, ) target.draw(scene, stencil_mode: read)
stencilOnly (only_write_mask:) is a niche flag β set it to true on the mask-write pass if you donβt want the mask shape itself to be visible in the colour buffer.
Constants
- COMPARISONS
-
Order matches sfStencilComparison in CSFML 3.
- COMPARISON_INDEX
-
Comparison symbol β integer Hash.
- OPERATIONS
-
Order matches sfStencilUpdateOperation in CSFML 3.
- OPERATION_INDEX
-
Update-op symbol β integer Hash.
Attributes
The comparison, update operation, reference, mask, only write mask components.
The comparison, update operation, reference, mask, only write mask components.
The comparison, update operation, reference, mask, only write mask components.
The comparison, update operation, reference, mask, only write mask components.
The comparison, update operation, reference, mask, only write mask components.
Public Class Methods
Source
# File lib/sfml/graphics/stencil_mode.rb, line 88 def self.from_native(struct) new( comparison: COMPARISONS[struct[:comparison]], update_operation: OPERATIONS[struct[:update_operation]], reference: struct[:reference][:value], mask: struct[:mask][:value], only_write_mask: struct[:only_write_mask], ) end
@!visibility private
Source
# File lib/sfml/graphics/stencil_mode.rb, line 41 def initialize(comparison: :always, update_operation: :keep, reference: 0, mask: 0xFFFFFFFF, only_write_mask: false) raise ArgumentError, "Unknown stencil comparison: #{comparison.inspect}" \ unless COMPARISON_INDEX.key?(comparison) raise ArgumentError, "Unknown stencil update_operation: #{update_operation.inspect}" \ unless OPERATION_INDEX.key?(update_operation) @comparison = comparison @update_operation = update_operation @reference = Integer(reference) @mask = Integer(mask) @only_write_mask = !!only_write_mask freeze end
Public Instance Methods
Source
# File lib/sfml/graphics/stencil_mode.rb, line 56 def ==(other) other.is_a?(StencilMode) && comparison == other.comparison && update_operation == other.update_operation && reference == other.reference && mask == other.mask && only_write_mask == other.only_write_mask end
Source
# File lib/sfml/graphics/stencil_mode.rb, line 66 def hash = [comparison, update_operation, reference, mask, only_write_mask].hash # Returns the to s. def to_s "StencilMode(#{comparison}, #{update_operation}, ref=#{reference}, " \ "mask=#{format('0x%08X', mask)}, only_write=#{only_write_mask})" end alias inspect to_s # @!visibility private # Write our fields into a CSFML StencilMode struct (typically a # sub-struct of an existing RenderStates buffer). def populate(struct) struct[:comparison] = COMPARISON_INDEX[@comparison] struct[:update_operation] = OPERATION_INDEX[@update_operation] struct[:reference][:value] = @reference struct[:mask][:value] = @mask struct[:only_write_mask] = @only_write_mask struct end # @!visibility private def self.from_native(struct) new( comparison: COMPARISONS[struct[:comparison]], update_operation: OPERATIONS[struct[:update_operation]], reference: struct[:reference][:value], mask: struct[:mask][:value], only_write_mask: struct[:only_write_mask], ) end end
Returns the hash.
Source
# File lib/sfml/graphics/stencil_mode.rb, line 78 def populate(struct) struct[:comparison] = COMPARISON_INDEX[@comparison] struct[:update_operation] = OPERATION_INDEX[@update_operation] struct[:reference][:value] = @reference struct[:mask][:value] = @mask struct[:only_write_mask] = @only_write_mask struct end
@!visibility private Write our fields into a CSFML StencilMode struct (typically a sub-struct of an existing RenderStates buffer).
Source
# File lib/sfml/graphics/stencil_mode.rb, line 69 def to_s "StencilMode(#{comparison}, #{update_operation}, ref=#{reference}, " \ "mask=#{format('0x%08X', mask)}, only_write=#{only_write_mask})" end
Returns the to s.