pub struct RenderContext {
pub display: Display,
pub context: Context,
pub surfaces: Vec<WindowSurface>,
pub active_index: Option<usize>,
pub gl_ver: String,
pub glsl_ver: String,
pub device: String,
/* private fields */
}Expand description
EGL + OpenGL 4.6 context with support for multiple window surfaces.
§Initialisation
Create a headless context for off-screen rendering:
let ctx = RenderContext::new_headless()?;Or create a windowed context from a raw window handle:
let ctx = RenderContext::new_windowed(raw_handle, display_handle, size)?;§Multi-window
Additional windows can be attached with attach_window
and made current with make_current.
Fields§
§display: Display§context: Context§surfaces: Vec<WindowSurface>§active_index: Option<usize>§gl_ver: String§glsl_ver: String§device: StringImplementations§
Source§impl RenderContext
impl RenderContext
Sourcepub fn new_headless() -> OpticResult<Self>
pub fn new_headless() -> OpticResult<Self>
Creates a headless EGL context with a 1×1 pbuffer surface.
This is useful for off-screen rendering or when no window is available. Loads OpenGL function pointers via EGL and queries driver info.
Sourcepub fn new_windowed(
raw_handle: RawWindowHandle,
display_handle: RawDisplayHandle,
size: Size2D,
) -> OpticResult<Self>
pub fn new_windowed( raw_handle: RawWindowHandle, display_handle: RawDisplayHandle, size: Size2D, ) -> OpticResult<Self>
Creates a windowed EGL context from raw window and display handles.
Supports X11 (with optional visual ID matching), Wayland, and Win32 platforms. Falls back to the default EGL display if platform-specific display creation fails.
Sourcepub fn attach_window(
&mut self,
raw_handle: RawWindowHandle,
size: Size2D,
) -> OpticResult<usize>
pub fn attach_window( &mut self, raw_handle: RawWindowHandle, size: Size2D, ) -> OpticResult<usize>
Attaches a new window surface to this context.
Returns the index of the new surface, which can be used with
make_current.
Sourcepub fn resize_window(&mut self, index: usize, size: Size2D)
pub fn resize_window(&mut self, index: usize, size: Size2D)
Resizes the tracked size for a window surface.
Does not call EGL surface resize — just updates the stored
dimensions used by make_current
for the viewport call.
Sourcepub fn make_current(&self, index: usize) -> OpticResult<()>
pub fn make_current(&self, index: usize) -> OpticResult<()>
Makes the given surface current and sets the viewport.
Sourcepub fn swap_buffers(&self, index: usize) -> OpticResult<()>
pub fn swap_buffers(&self, index: usize) -> OpticResult<()>
Swaps front and back buffers for the given surface (double-buffering).
Sourcepub fn set_clear_color(&self, color: RGBA)
pub fn set_clear_color(&self, color: RGBA)
Sets the clear colour used by clear.
Trait Implementations§
Source§impl Drop for RenderContext
impl Drop for RenderContext
Auto Trait Implementations§
impl !Send for RenderContext
impl !Sync for RenderContext
impl Freeze for RenderContext
impl RefUnwindSafe for RenderContext
impl Unpin for RenderContext
impl UnsafeUnpin for RenderContext
impl UnwindSafe for RenderContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more