Class: SFML::Context
- Inherits:
-
Object
- Object
- SFML::Context
- Defined in:
- lib/sfml/window/context.rb
Overview
Headless OpenGL context — for compiling shaders, generating textures, or doing GL work without a window. SFML attaches the context to whichever thread constructed it.
ctx = SFML::Context.new
ctx.active = true
# … raw GL work / shader compile …
ctx.active = false
CSFML always returns a non-NULL context on creation (it falls back to a pbuffer / EGL surface if no display is available), so the constructor doesn’t raise.
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.active_context_id ⇒ Object
ID of the context currently active on this thread, or 0 if none.
-
.extension_available?(extension_name) ⇒ Boolean
Is ‘extension_name` (e.g. “GL_ARB_compute_shader”) supported by the active context?.
-
.gl_function(name) ⇒ Object
Look up a raw GL function pointer by name.
Instance Method Summary collapse
-
#active=(value) ⇒ Object
Activate / deactivate this context on the current thread.
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#settings ⇒ Object
The settings the GL driver actually granted (might differ from what you asked for if the driver couldn’t meet every constraint).
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
15 16 17 18 19 |
# File 'lib/sfml/window/context.rb', line 15 def initialize ptr = C::Window.sfContext_create raise Error, "sfContext_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Window.method(:sfContext_destroy)) end |
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
54 55 56 |
# File 'lib/sfml/window/context.rb', line 54 def handle @handle end |
Class Method Details
.active_context_id ⇒ Object
ID of the context currently active on this thread, or 0 if none. Useful for “am I in the GL context I expect?” assertions.
37 38 39 |
# File 'lib/sfml/window/context.rb', line 37 def self.active_context_id C::Window.sfContext_getActiveContextId end |
.extension_available?(extension_name) ⇒ Boolean
Is ‘extension_name` (e.g. “GL_ARB_compute_shader”) supported by the active context?
43 44 45 |
# File 'lib/sfml/window/context.rb', line 43 def self.extension_available?(extension_name) C::Window.sfContext_isExtensionAvailable(extension_name.to_s) end |
.gl_function(name) ⇒ Object
Look up a raw GL function pointer by name. Useful when interoping with a GL extension that SFML doesn’t wrap. Returns an FFI::Pointer (nil pointer if the function isn’t loaded).
50 51 52 |
# File 'lib/sfml/window/context.rb', line 50 def self.gl_function(name) C::Window.sfContext_getFunction(name.to_s) end |
Instance Method Details
#active=(value) ⇒ Object
Activate / deactivate this context on the current thread. Only one context can be current per thread; setting another active implicitly deactivates this one.
24 25 26 |
# File 'lib/sfml/window/context.rb', line 24 def active=(value) C::Window.sfContext_setActive(@handle, !!value) end |
#settings ⇒ Object
The settings the GL driver actually granted (might differ from what you asked for if the driver couldn’t meet every constraint).
31 32 33 |
# File 'lib/sfml/window/context.rb', line 31 def settings ContextSettings.from_native(C::Window.sfContext_getSettings(@handle)) end |