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
impl GLRenderer
Sourcepub unsafe fn new_for_gl_context<V, F>(
viewport_size_pixels: V,
loader_function: F,
) -> Result<Self, BacktraceError<GLRendererCreationError>>
pub unsafe fn new_for_gl_context<V, F>( viewport_size_pixels: V, loader_function: F, ) -> Result<Self, BacktraceError<GLRendererCreationError>>
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.
Sourcepub fn new_for_web_canvas_by_id<V, S>(
viewport_size_pixels: V,
element_id: S,
) -> Result<Self, BacktraceError<GLRendererCreationError>>
pub fn new_for_web_canvas_by_id<V, S>( viewport_size_pixels: V, element_id: S, ) -> Result<Self, BacktraceError<GLRendererCreationError>>
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()].
Sourcepub fn set_viewport_size_pixels(&mut self, viewport_size_pixels: UVec2)
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.
Sourcepub fn create_image_from_raw_pixels(
&mut self,
data_type: ImageDataType,
smoothing_mode: ImageSmoothingMode,
size: UVec2,
data: &[u8],
) -> Result<ImageHandle, BacktraceError<ErrorMessage>>
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.
Sourcepub fn create_image_from_file_path<S: AsRef<Path>>(
&mut self,
data_type: Option<ImageFileFormat>,
smoothing_mode: ImageSmoothingMode,
path: S,
) -> Result<ImageHandle, BacktraceError<ErrorMessage>>
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.
Sourcepub 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>>
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.
Sourcepub fn draw_frame<F: FnOnce(&mut Graphics2D) -> R, R>(
&mut self,
callback: F,
) -> R
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§
Auto Trait Implementations§
impl Freeze for GLRenderer
impl !RefUnwindSafe for GLRenderer
impl !Send for GLRenderer
impl !Sync for GLRenderer
impl Unpin for GLRenderer
impl !UnwindSafe for GLRenderer
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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