Enum surfman::platform::generic::multi::device::Device

source ·
pub enum Device<Def, Alt>{
    Default(Def),
    Alternate(Alt),
}
Expand description

A thread-local handle to a device.

Devices contain most of the relevant surface management methods.

Variants§

§

Default(Def)

The default device type.

§

Alternate(Alt)

The alternate device type.

Implementations§

source§

impl<Def, Alt> Device<Def, Alt>

source

pub fn create_context_descriptor( &self, attributes: &ContextAttributes, ) -> Result<ContextDescriptor<Def, Alt>, Error>

Creates a context descriptor with the given attributes.

Context descriptors are local to this device.

source

pub fn create_context( &mut self, descriptor: &ContextDescriptor<Def, Alt>, share_with: Option<&Context<Def, Alt>>, ) -> Result<Context<Def, Alt>, Error>

Creates a new OpenGL context.

The context initially has no surface attached. Until a surface is bound to it, rendering commands will fail or have no effect.

source

pub unsafe fn create_context_from_native_context( &self, native_context: NativeContext<Def, Alt>, ) -> Result<Context<Def, Alt>, Error>

Wraps an existing native context in a Context object.

source

pub fn destroy_context( &self, context: &mut Context<Def, Alt>, ) -> Result<(), Error>

Destroys a context.

The context must have been created on this device.

source

pub fn native_context( &self, context: &Context<Def, Alt>, ) -> NativeContext<Def, Alt>

Returns the native context underlying this context.

source

pub fn context_descriptor( &self, context: &Context<Def, Alt>, ) -> ContextDescriptor<Def, Alt>

Returns the descriptor that this context was created with.

source

pub fn make_context_current( &self, context: &Context<Def, Alt>, ) -> Result<(), Error>

Makes the context the current OpenGL context for this thread.

After calling this function, it is valid to use OpenGL rendering commands.

source

pub fn make_no_context_current(&self) -> Result<(), Error>

Removes the current OpenGL context from this thread.

After calling this function, OpenGL rendering commands will fail until a new context is made current.

source

pub fn bind_surface_to_context( &self, context: &mut Context<Def, Alt>, surface: Surface<Def, Alt>, ) -> Result<(), (Error, Surface<Def, Alt>)>

Attaches a surface to a context for rendering.

This function takes ownership of the surface. The surface must have been created with this context, or an IncompatibleSurface error is returned.

If this function is called with a surface already bound, a SurfaceAlreadyBound error is returned. To avoid this error, first unbind the existing surface with unbind_surface_from_context.

If an error is returned, the surface is returned alongside it.

source

pub fn unbind_surface_from_context( &self, context: &mut Context<Def, Alt>, ) -> Result<Option<Surface<Def, Alt>>, Error>

Removes and returns any attached surface from this context.

Any pending OpenGL commands targeting this surface will be automatically flushed, so the surface is safe to read from immediately when this function returns.

source

pub fn context_descriptor_attributes( &self, context_descriptor: &ContextDescriptor<Def, Alt>, ) -> ContextAttributes

Returns the attributes that the context descriptor was created with.

source

pub fn get_proc_address( &self, context: &Context<Def, Alt>, symbol_name: &str, ) -> *const c_void

Fetches the address of an OpenGL function associated with this context.

OpenGL functions are local to a context. You should not use OpenGL functions on one context with any other context.

This method is typically used with a function like gl::load_with() from the gl crate to load OpenGL function pointers.

source

pub fn context_id(&self, context: &Context<Def, Alt>) -> ContextID

Returns a unique ID representing a context.

This ID is unique to all currently-allocated contexts. If you destroy a context and create a new one, the new context might have the same ID as the destroyed one.

source

pub fn context_surface_info( &self, context: &Context<Def, Alt>, ) -> Result<Option<SurfaceInfo>, Error>

Returns various information about the surface attached to a context.

This includes, most notably, the OpenGL framebuffer object needed to render to the surface.

source§

impl<Def, Alt> Device<Def, Alt>

source

pub fn native_device(&self) -> NativeDevice<Def, Alt>

Returns the native device underlying this device.

source

pub fn connection(&self) -> Connection<Def, Alt>

Returns the display server connection that this device was created with.

source

pub fn adapter(&self) -> Adapter<Def, Alt>

Returns the adapter that this device was created with.

source

pub fn gl_api(&self) -> GLApi

Returns the OpenGL API flavor that this device supports (OpenGL or OpenGL ES).

source§

impl<Def, Alt> Device<Def, Alt>

source

pub fn create_surface( &mut self, context: &Context<Def, Alt>, surface_access: SurfaceAccess, surface_type: SurfaceType<NativeWidget<Def, Alt>>, ) -> Result<Surface<Def, Alt>, Error>

Creates either a generic or a widget surface, depending on the supplied surface type.

Only the given context may ever render to the surface, but generic surfaces can be wrapped up in a SurfaceTexture for reading by other contexts.

source

pub fn create_surface_texture( &self, context: &mut Context<Def, Alt>, surface: Surface<Def, Alt>, ) -> Result<SurfaceTexture<Def, Alt>, (Error, Surface<Def, Alt>)>

Creates a surface texture from an existing generic surface for use with the given context.

The surface texture is local to the supplied context and takes ownership of the surface. Destroying the surface texture allows you to retrieve the surface again.

The supplied context does not have to be the same context that the surface is associated with. This allows you to render to a surface in one context and sample from that surface in another context.

Calling this method on a widget surface returns a WidgetAttached error.

source

pub fn destroy_surface( &self, context: &mut Context<Def, Alt>, surface: &mut Surface<Def, Alt>, ) -> Result<(), Error>

Destroys a surface.

The supplied context must be the context the surface is associated with, or this returns an IncompatibleSurface error.

You must explicitly call this method to dispose of a surface. Otherwise, a panic occurs in the drop method.

source

pub fn destroy_surface_texture( &self, context: &mut Context<Def, Alt>, surface_texture: SurfaceTexture<Def, Alt>, ) -> Result<Surface<Def, Alt>, (Error, SurfaceTexture<Def, Alt>)>

Destroys a surface texture and returns the underlying surface.

The supplied context must be the same context the surface texture was created with, or an IncompatibleSurfaceTexture error is returned.

All surface textures must be explicitly destroyed with this function, or a panic will occur.

source

pub fn present_surface( &self, context: &Context<Def, Alt>, surface: &mut Surface<Def, Alt>, ) -> Result<(), Error>

Displays the contents of a widget surface on screen.

Widget surfaces are internally double-buffered, so changes to them don’t show up in their associated widgets until this method is called.

The supplied context must match the context the surface was created with, or an IncompatibleSurface error is returned.

source

pub fn resize_surface( &self, context: &Context<Def, Alt>, surface: &mut Surface<Def, Alt>, size: Size2D<i32>, ) -> Result<(), Error>

Resizes a widget surface.

source

pub fn surface_gl_texture_target(&self) -> c_uint

Returns the OpenGL texture target needed to read from this surface texture.

This will be GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE, depending on platform.

source

pub fn surface_info(&self, surface: &Surface<Def, Alt>) -> SurfaceInfo

Returns various information about the surface, including the framebuffer object needed to render to this surface.

Before rendering to a surface attached to a context, you must call glBindFramebuffer() on the framebuffer object returned by this function. This framebuffer object may or not be 0, the default framebuffer, depending on platform.

source

pub fn surface_texture_object( &self, surface_texture: &SurfaceTexture<Def, Alt>, ) -> c_uint

Returns the OpenGL texture object containing the contents of this surface.

It is only legal to read from, not write to, this texture object.

Trait Implementations§

source§

impl<Def, Alt> Device for Device<Def, Alt>
where Def: DeviceInterface, Alt: DeviceInterface, Def::Connection: ConnectionInterface<Device = Def>, Alt::Connection: ConnectionInterface<Device = Alt>,

source§

type Connection = Connection<Def, Alt>

The connection type associated with this device.
source§

type Context = Context<Def, Alt>

The context type associated with this device.
source§

type ContextDescriptor = ContextDescriptor<Def, Alt>

The context descriptor type associated with this device.
source§

type NativeContext = NativeContext<Def, Alt>

The native context type associated with this device.
source§

type Surface = Surface<Def, Alt>

The surface type associated with this device.
source§

type SurfaceTexture = SurfaceTexture<Def, Alt>

The surface texture type associated with this device.
source§

fn native_device(&self) -> NativeDevice<Def, Alt>

Returns the native device associated with this device.
source§

fn connection(&self) -> Connection<Def, Alt>

Returns the display server connection that this device was created with.
source§

fn adapter(&self) -> Adapter<Def, Alt>

Returns the adapter that this device was created with.
source§

fn gl_api(&self) -> GLApi

Returns the OpenGL API flavor that this device supports (OpenGL or OpenGL ES).
source§

fn create_context_descriptor( &self, attributes: &ContextAttributes, ) -> Result<Self::ContextDescriptor, Error>

Creates a context descriptor with the given attributes. Read more
source§

fn create_context( &mut self, descriptor: &ContextDescriptor<Def, Alt>, share_with: Option<&Context<Def, Alt>>, ) -> Result<Context<Def, Alt>, Error>

Creates a new OpenGL context. Read more
source§

unsafe fn create_context_from_native_context( &self, native_context: Self::NativeContext, ) -> Result<Context<Def, Alt>, Error>

Wraps a native context object in an OpenGL context.
source§

fn destroy_context(&self, context: &mut Context<Def, Alt>) -> Result<(), Error>

Destroys a context. Read more
source§

fn native_context(&self, context: &Context<Def, Alt>) -> Self::NativeContext

Returns the native context associated with the given context.
source§

fn context_descriptor( &self, context: &Context<Def, Alt>, ) -> Self::ContextDescriptor

Returns the descriptor that this context was created with.
source§

fn make_context_current(&self, context: &Context<Def, Alt>) -> Result<(), Error>

Makes the context the current OpenGL context for this thread. Read more
source§

fn make_no_context_current(&self) -> Result<(), Error>

Removes the current OpenGL context from this thread. Read more
source§

fn context_descriptor_attributes( &self, context_descriptor: &ContextDescriptor<Def, Alt>, ) -> ContextAttributes

Returns the attributes that the context descriptor was created with.
source§

fn get_proc_address( &self, context: &Context<Def, Alt>, symbol_name: &str, ) -> *const c_void

Fetches the address of an OpenGL function associated with this context. Read more
source§

fn bind_surface_to_context( &self, context: &mut Context<Def, Alt>, surface: Surface<Def, Alt>, ) -> Result<(), (Error, Surface<Def, Alt>)>

Attaches a surface to a context for rendering. Read more
source§

fn unbind_surface_from_context( &self, context: &mut Context<Def, Alt>, ) -> Result<Option<Surface<Def, Alt>>, Error>

Removes and returns any attached surface from this context. Read more
source§

fn context_id(&self, context: &Context<Def, Alt>) -> ContextID

Returns a unique ID representing a context. Read more
source§

fn context_surface_info( &self, context: &Context<Def, Alt>, ) -> Result<Option<SurfaceInfo>, Error>

Returns various information about the surface attached to a context. Read more
source§

fn create_surface( &mut self, context: &Context<Def, Alt>, surface_access: SurfaceAccess, surface_type: SurfaceType<NativeWidget<Def, Alt>>, ) -> Result<Surface<Def, Alt>, Error>

Creates either a generic or a widget surface, depending on the supplied surface type. Read more
source§

fn create_surface_texture( &self, context: &mut Context<Def, Alt>, surface: Surface<Def, Alt>, ) -> Result<SurfaceTexture<Def, Alt>, (Error, Surface<Def, Alt>)>

Creates a surface texture from an existing generic surface for use with the given context. Read more
source§

fn destroy_surface( &self, context: &mut Context<Def, Alt>, surface: &mut Surface<Def, Alt>, ) -> Result<(), Error>

Destroys a surface. Read more
source§

fn destroy_surface_texture( &self, context: &mut Context<Def, Alt>, surface_texture: SurfaceTexture<Def, Alt>, ) -> Result<Surface<Def, Alt>, (Error, SurfaceTexture<Def, Alt>)>

Destroys a surface texture and returns the underlying surface. Read more
source§

fn surface_gl_texture_target(&self) -> c_uint

Returns the OpenGL texture target needed to read from this surface texture. Read more
source§

fn present_surface( &self, context: &Context<Def, Alt>, surface: &mut Surface<Def, Alt>, ) -> Result<(), Error>

Displays the contents of a widget surface on screen. Read more
source§

fn resize_surface( &self, context: &Context<Def, Alt>, surface: &mut Surface<Def, Alt>, size: Size2D<i32>, ) -> Result<(), Error>

Resizes a widget surface.
source§

fn surface_info(&self, surface: &Surface<Def, Alt>) -> SurfaceInfo

Returns various information about the surface, including the framebuffer object needed to render to this surface. Read more
source§

fn surface_texture_object( &self, surface_texture: &SurfaceTexture<Def, Alt>, ) -> c_uint

Returns the OpenGL texture object containing the contents of this surface. Read more

Auto Trait Implementations§

§

impl<Def, Alt> Freeze for Device<Def, Alt>
where Def: Freeze, Alt: Freeze,

§

impl<Def, Alt> RefUnwindSafe for Device<Def, Alt>
where Def: RefUnwindSafe, Alt: RefUnwindSafe,

§

impl<Def, Alt> Send for Device<Def, Alt>
where Def: Send, Alt: Send,

§

impl<Def, Alt> Sync for Device<Def, Alt>
where Def: Sync, Alt: Sync,

§

impl<Def, Alt> Unpin for Device<Def, Alt>
where Def: Unpin, Alt: Unpin,

§

impl<Def, Alt> UnwindSafe for Device<Def, Alt>
where Def: UnwindSafe, Alt: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.