Class: SFML::ContextSettings
- Inherits:
-
Object
- Object
- SFML::ContextSettings
- Defined in:
- lib/sfml/window/context_settings.rb
Overview
Configuration for the underlying OpenGL context that backs a
Window / RenderWindow. Passed at window-creation time to
request anti-aliasing, depth/stencil buffers, or a specific
OpenGL version.
settings = SFML::ContextSettings.new(antialiasing: 4)
window = SFML::RenderWindow.new(800, 600, "Smooth", context: settings)
Or use the RenderWindow.new shortcut directly:
window = SFML::RenderWindow.new(800, 600, "Smooth", antialiasing: 4)
Anti-aliasing is the most common knob — typical values are 0
(off), 2, 4, or 8. The driver picks the closest level it
actually supports; query window.context_settings after
creation to see what you got.
Constant Summary collapse
- DEFAULT_DEPTH_BITS =
0- DEFAULT_STENCIL_BITS =
0- DEFAULT_AA_LEVEL =
0- DEFAULT_MAJOR_VERSION =
1- DEFAULT_MINOR_VERSION =
1- ATTRIBUTE_FLAGS =
{ default: C::Window::ContextAttribute::DEFAULT, core: C::Window::ContextAttribute::CORE, debug: C::Window::ContextAttribute::DEBUG, }.freeze
Instance Attribute Summary collapse
-
#antialiasing ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
-
#attribute_flags ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
-
#depth_bits ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
-
#major_version ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
-
#minor_version ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
-
#srgb_capable ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
-
#stencil_bits ⇒ Object
readonly
The depth bits, stencil bits, antialiasing components.
Class Method Summary collapse
-
.from_native(struct) ⇒ Object
Returns the self.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#hash ⇒ Object
Returns the hash.
-
#initialize(depth_bits: DEFAULT_DEPTH_BITS, stencil_bits: DEFAULT_STENCIL_BITS, antialiasing: DEFAULT_AA_LEVEL, major_version: DEFAULT_MAJOR_VERSION, minor_version: DEFAULT_MINOR_VERSION, attributes: :default, srgb_capable: false) ⇒ ContextSettings
constructor
A new instance of ContextSettings.
-
#to_native ⇒ Object
Build the matching CSFML struct on the heap.
-
#to_s ⇒ Object
(also: #inspect)
Returns the to s.
Constructor Details
#initialize(depth_bits: DEFAULT_DEPTH_BITS, stencil_bits: DEFAULT_STENCIL_BITS, antialiasing: DEFAULT_AA_LEVEL, major_version: DEFAULT_MAJOR_VERSION, minor_version: DEFAULT_MINOR_VERSION, attributes: :default, srgb_capable: false) ⇒ ContextSettings
Returns a new instance of ContextSettings.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sfml/window/context_settings.rb', line 36 def initialize(depth_bits: DEFAULT_DEPTH_BITS, stencil_bits: DEFAULT_STENCIL_BITS, antialiasing: DEFAULT_AA_LEVEL, major_version: DEFAULT_MAJOR_VERSION, minor_version: DEFAULT_MINOR_VERSION, attributes: :default, srgb_capable: false) @depth_bits = Integer(depth_bits) @stencil_bits = Integer(stencil_bits) @antialiasing = Integer(antialiasing) @major_version = Integer(major_version) @minor_version = Integer(minor_version) @attribute_flags = _attribute_mask(attributes) @srgb_capable = !!srgb_capable freeze end |
Instance Attribute Details
#antialiasing ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def antialiasing @antialiasing end |
#attribute_flags ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def attribute_flags @attribute_flags end |
#depth_bits ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def depth_bits @depth_bits end |
#major_version ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def major_version @major_version end |
#minor_version ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def minor_version @minor_version end |
#srgb_capable ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def srgb_capable @srgb_capable end |
#stencil_bits ⇒ Object (readonly)
The depth bits, stencil bits, antialiasing components.
32 33 34 |
# File 'lib/sfml/window/context_settings.rb', line 32 def stencil_bits @stencil_bits end |
Class Method Details
.from_native(struct) ⇒ Object
Returns the self.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sfml/window/context_settings.rb', line 69 def self.from_native(struct) attrs = ATTRIBUTE_FLAGS.find { |_, v| v == struct[:attribute_flags] }&.first || :default new( depth_bits: struct[:depth_bits], stencil_bits: struct[:stencil_bits], antialiasing: struct[:anti_aliasing_level], major_version: struct[:major_version], minor_version: struct[:minor_version], attributes: attrs, srgb_capable: struct[:s_rgb_capable], ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sfml/window/context_settings.rb', line 82 def ==(other) other.is_a?(ContextSettings) && depth_bits == other.depth_bits && stencil_bits == other.stencil_bits && antialiasing == other.antialiasing && major_version == other.major_version && minor_version == other.minor_version && attribute_flags == other.attribute_flags && srgb_capable == other.srgb_capable end |
#hash ⇒ Object
Returns the hash.
95 96 97 |
# File 'lib/sfml/window/context_settings.rb', line 95 def hash = [@depth_bits, @stencil_bits, @antialiasing, @major_version, @minor_version, @attribute_flags, @srgb_capable].hash |
#to_native ⇒ Object
Build the matching CSFML struct on the heap. Returned struct is owned by the caller (FFI::AutoPointer is not set — pass by reference into a window-creation call and let it copy).
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sfml/window/context_settings.rb', line 56 def to_native s = C::Window::ContextSettings.new s[:depth_bits] = @depth_bits s[:stencil_bits] = @stencil_bits s[:anti_aliasing_level] = @antialiasing s[:major_version] = @major_version s[:minor_version] = @minor_version s[:attribute_flags] = @attribute_flags s[:s_rgb_capable] = @srgb_capable s end |
#to_s ⇒ Object Also known as: inspect
Returns the to s.
100 101 102 103 |
# File 'lib/sfml/window/context_settings.rb', line 100 def to_s "ContextSettings(aa=#{@antialiasing}, depth=#{@depth_bits}, " \ "stencil=#{@stencil_bits}, gl=#{@major_version}.#{@minor_version})" end |