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
impl GLRenderer
sourcepub unsafe fn new_for_current_context<V: Into<UVec2>>(
viewport_size_pixels: V
) -> Result<Self, BacktraceError<GLRendererCreationError>>
pub unsafe fn new_for_current_context<V: Into<UVec2>>(
viewport_size_pixels: V
) -> Result<Self, BacktraceError<GLRendererCreationError>>
Creates a GLRenderer
for the current OpenGL context.
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.
Deprecation
Note: This function will be removed in a future version of Speedy2D. Please use GLRenderer::new_for_gl_context instead.
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 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,
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
.
sourcepub 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>,
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()].
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.