RenderEngine

Struct RenderEngine 

Source
pub struct RenderEngine { /* private fields */ }
Expand description

Render engine.

The render engine is the main object used for rendering. RenderObject’s are added to the engine using RenderEngine::add_object. A call to RenderEngine::render renders the scene.

The render engine also gives additional functionality, such as creation and modification of textures and VAOs, and rendering of text to a texture.

Implementations§

Source§

impl RenderEngine

Source

pub fn new( canvas: Rc<HtmlCanvasElement>, window: Rc<Window>, document: &Document, ) -> Result<RenderEngine, JsValue>

Creates a new render engine.

The canvas is the HTML canvas element that will be used for the render output.

Source

pub fn add_object(&mut self, object: RenderObject)

Adds a render object to the scene.

Source

pub fn render(&mut self) -> Result<(), JsValue>

Renders the scene to the canvas.

The scene is formed by the objects that have been previously added with RenderEngine::add_object.

Source

pub fn make_program( &self, source: ProgramSource<'_>, ) -> Result<Rc<WebGlProgram>, JsValue>

Compiles a WebGL2 program.

This function compiles the vertex and fragment shaders given in source and links them as a program.

Source

pub fn create_vao(&mut self) -> Result<VaoBuilder<'_>, JsValue>

Creates a new VAO.

This function creates a new Vertex Array Object. The VAO is constructed using a VaoBuilder.

Source

pub fn modify_vao(&mut self, vao: Rc<WebGlVertexArrayObject>) -> VaoBuilder<'_>

Modifies an existing VAO.

This function returns a VaoBuilder that can modify the existing Vertex Array Object vao.

Source

pub fn create_texture(&mut self) -> Result<TextureBuilder<'_>, JsValue>

Creates a new texture.

The texture is constructed using a TextureBuilder.

Source

pub fn canvas_dims(&self) -> CanvasDims

Returns the current canvas dimensions.

Source

pub fn resize_canvas(&mut self) -> Result<(), JsValue>

Resizes the canvas.

Resizes the canvas according to the current dimensions of the HTML canvas element and the device pixel ratio. This function should be called whenever any of these parameters change, in order to update the render engine accordingly.

Source

pub fn render_texts_to_texture( &mut self, texture: &Rc<WebGlTexture>, texts: &[String], text_height_px: u32, ) -> Result<TextsDimensions, JsValue>

Renders a series of texts into a texture.

Given a slice of text strings, this function uses an auxiliarly HTML canvas element (which does not form part of the document) to render all of these strings into the canvas and load the resulting image into a texture. The information about the coordinates of the bounding boxes of each text is return, allowing parts of the texture to be used to display each text.

A fixed text height in pixels, text_height_px, is used to set the size of the font and of the image loaded in the texture.

Source

pub fn text_renderer_text_width( &self, text: &str, height_px: u32, ) -> Result<f32, JsValue>

Returns the corresponding text width for a given string of text.

The string of text is measured with a text height of height_px pixels, and the width in screen coordinates is returned.

This function can be used to find out how much screen space a given text will occupy before the text is even rendered.

Source§

impl RenderEngine

Source

pub fn texture_image<F: TextureInternalFormat>( &mut self, texture: &Rc<WebGlTexture>, image: &[F::T], width: usize, height: usize, ) -> Result<(), JsValue>

Loads a texture with an image.

The image is described by a slice of elements whose type is the native Rust type corresponding to the WebGL2 texture internal format F. Such internal format, and its corresponding format are used to load the image into the texture.

The width and height parameters indicate the dimensions of the image in pixels.

Source

pub fn texture_subimage<F: TextureInternalFormat>( &mut self, texture: &Rc<WebGlTexture>, image: &[F::T], xoffset: usize, yoffset: usize, width: usize, height: usize, ) -> Result<(), JsValue>

Loads a portion of a texture with an image.

The image is described in the same way as in texture_image, together with its corresponding width and height dimensions.

The xoffset and yoffset give the offsets in pixels that indicate in which portion of the texture the image data should be loaded.

Source

pub fn generate_mipmap(&mut self, texture: &Rc<WebGlTexture>)

Generate mipmap.

This function generates the mipmap from a given texture.

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