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
impl RenderEngine
Sourcepub fn new(
canvas: Rc<HtmlCanvasElement>,
window: Rc<Window>,
document: &Document,
) -> Result<RenderEngine, JsValue>
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.
Sourcepub fn add_object(&mut self, object: RenderObject)
pub fn add_object(&mut self, object: RenderObject)
Adds a render object to the scene.
Sourcepub fn render(&mut self) -> Result<(), JsValue>
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
.
Sourcepub fn make_program(
&self,
source: ProgramSource<'_>,
) -> Result<Rc<WebGlProgram>, JsValue>
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.
Sourcepub fn create_vao(&mut self) -> Result<VaoBuilder<'_>, JsValue>
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
.
Sourcepub fn modify_vao(&mut self, vao: Rc<WebGlVertexArrayObject>) -> VaoBuilder<'_>
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
.
Sourcepub fn create_texture(&mut self) -> Result<TextureBuilder<'_>, JsValue>
pub fn create_texture(&mut self) -> Result<TextureBuilder<'_>, JsValue>
Creates a new texture.
The texture is constructed using a TextureBuilder
.
Sourcepub fn canvas_dims(&self) -> CanvasDims
pub fn canvas_dims(&self) -> CanvasDims
Returns the current canvas dimensions.
Sourcepub fn resize_canvas(&mut self) -> Result<(), JsValue>
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.
Sourcepub fn render_texts_to_texture(
&mut self,
texture: &Rc<WebGlTexture>,
texts: &[String],
text_height_px: u32,
) -> Result<TextsDimensions, JsValue>
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.
Sourcepub fn text_renderer_text_width(
&self,
text: &str,
height_px: u32,
) -> Result<f32, JsValue>
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
impl RenderEngine
Sourcepub fn texture_image<F: TextureInternalFormat>(
&mut self,
texture: &Rc<WebGlTexture>,
image: &[F::T],
width: usize,
height: usize,
) -> Result<(), JsValue>
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.
Sourcepub fn texture_subimage<F: TextureInternalFormat>(
&mut self,
texture: &Rc<WebGlTexture>,
image: &[F::T],
xoffset: usize,
yoffset: usize,
width: usize,
height: usize,
) -> Result<(), JsValue>
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.
Sourcepub fn generate_mipmap(&mut self, texture: &Rc<WebGlTexture>)
pub fn generate_mipmap(&mut self, texture: &Rc<WebGlTexture>)
Generate mipmap.
This function generates the mipmap from a given texture.