Struct speedy2d::GLRenderer

source ·
pub struct GLRenderer { /* private fields */ }
Expand description

A graphics renderer using an OpenGL backend.

Note: There is no need to use this struct if you are letting Speedy2D create a window for you.

Implementations§

source§

impl GLRenderer

source

pub unsafe fn new_for_gl_context<V, F>( viewport_size_pixels: V, loader_function: F ) -> Result<Self, BacktraceError<GLRendererCreationError>>
where V: Into<UVec2>, F: FnMut(&str) -> *const c_void,

Creates a GLRenderer with the specified OpenGL loader function. The loader function takes the name of an OpenGL function, and returns the associated function pointer. viewport_size_pixels should be set to the initial viewport size, however this can be changed later using [GLRenderer:: set_viewport_size_pixels()].

Note: This function must not be called if you are letting Speedy2D create a window for you.

§Safety

While a GLRenderer object is active, you must not make any changes to the active GL context. Doing so may lead to undefined behavior, which is why this function is marked unsafe. It is strongly advised not to use any other OpenGL libraries in the same thread as GLRenderer.

source

pub fn new_for_web_canvas_by_id<V, S>( viewport_size_pixels: V, element_id: S ) -> Result<Self, BacktraceError<GLRendererCreationError>>
where V: Into<UVec2>, S: AsRef<str>,

Creates a GLRenderer for the specified HTML canvas. The canvas will be found based on the specified ID.

The parameter viewport_size_pixels should be set to the initial canvas size, however this can be changed later using [GLRenderer:: set_viewport_size_pixels()].

source

pub fn set_viewport_size_pixels(&mut self, viewport_size_pixels: UVec2)

Sets the renderer viewport to the specified pixel size, in response to a change in the window size.

source

pub fn create_image_from_raw_pixels( &mut self, data_type: ImageDataType, smoothing_mode: ImageSmoothingMode, size: UVec2, data: &[u8] ) -> Result<ImageHandle, BacktraceError<ErrorMessage>>

Creates a new ImageHandle from the specified raw pixel data.

The data provided in the data parameter must be in the format specified by data_type.

The returned ImageHandle is valid only for the current graphics context.

source

pub fn create_image_from_file_path<S: AsRef<Path>>( &mut self, data_type: Option<ImageFileFormat>, smoothing_mode: ImageSmoothingMode, path: S ) -> Result<ImageHandle, BacktraceError<ErrorMessage>>

Loads an image from the specified file path.

If no data_type is provided, an attempt will be made to guess the file format.

For a list of supported image types, see image::ImageFileFormat.

The returned ImageHandle is valid only for the current graphics context.

source

pub fn create_image_from_file_bytes<R: Seek + BufRead>( &mut self, data_type: Option<ImageFileFormat>, smoothing_mode: ImageSmoothingMode, file_bytes: R ) -> Result<ImageHandle, BacktraceError<ErrorMessage>>

Loads an image from the provided encoded image file data.

If no data_type is provided, an attempt will be made to guess the file format.

The data source must implement std::io::BufRead and std::io::Seek. For example, if you have a &[u8], you may wrap it in a std::io::Cursor as follows:

use std::io::Cursor;

let image_bytes : &[u8] = include_bytes!("../assets/screenshots/hello_world.png");

let image_result = renderer.create_image_from_file_bytes(
    None,
    ImageSmoothingMode::Linear,
    Cursor::new(image_bytes));

For a list of supported image types, see image::ImageFileFormat.

The returned ImageHandle is valid only for the current graphics context.

source

pub fn draw_frame<F: FnOnce(&mut Graphics2D) -> R, R>( &mut self, callback: F ) -> R

Starts the process of drawing a frame. A Graphics2D object will be provided to the callback. When the callback returns, the internal render queue will be flushed.

Note: if calling this method, you are responsible for swapping the window context buffers if necessary.

Trait Implementations§

source§

impl Drop for GLRenderer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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.