Skip to main content

WebGlRenderer

Struct WebGlRenderer 

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

Vello GPU’s WebGL2 renderer.

Note that any operation of WebGlRenderer might modify the global state of the underlying WebGL context; state like the active texture unit and texture bindings are therefore not guaranteed to be restored to their original value after each method call.

§Context loss

Methods on WebGlRenderer are not guaranteed to return an error if the WebGL context has been lost; therefore, if not handled properly, rendering or other operations might silently fail. To prevent this, clients should create their own listener for the WebGL context lost event and react to it appropriately.

Implementations§

Source§

impl WebGlRenderer

Source

pub fn probe( &mut self, elements: &[ProbeFeature], ) -> Result<WebGlPendingProbe, WebGlProbeError>

Conduct a probing operation.

The WebGL drivers of certain devices are known to be buggy and might therefore not work correctly with Vello GPU. In the best case, it will simply result in a program crash, but in the worst case it can instead result in a silent failure, meaning that no explicit error is thrown, but the rendered contents of Vello GPU will either be completely empty or look glitchy.

The purpose of this method is to run a sanity check to ensure that running Vello GPU on this device actually results in visible and correct output. How this achieved is by drawing a selection of small elements into a small canvas, and comparing the final output against a reference image.

This method will return a handle that allows inspecting the results of the probe once the results of the probe scene can be copied back from GPU to CPU. For performance reasons, anything in-between mostly happens asynchronously.

Source§

impl WebGlRenderer

Source

pub fn new(canvas: &HtmlCanvasElement) -> Result<(Self, Resources), WebGlError>

Creates a new WebGL2 renderer and its persistent resources.

This blocks until shader compilation and linking finish. Use WebGlRenderer::begin when initialization must not block the browser’s main thread.

Source

pub fn new_with( canvas: &HtmlCanvasElement, settings: RenderSettings, use_depth_buffer: bool, ) -> Result<(Self, Resources), WebGlError>

Creates a new WebGL2 renderer and its persistent resources with specific settings.

When use_depth_buffer is true, the WebGL context allocates a depth buffer and the renderer uses it for opaque-strip occlusion. Disabling it reduces GPU memory usage, but can increase overdraw.

Source

pub fn begin( canvas: &HtmlCanvasElement, ) -> Result<(WebGlRendererInit, Resources), WebGlError>

Begins creating a WebGL2 renderer and its persistent resources.

When KHR_parallel_shader_compile is available, shader compilation and program linking can continue while the caller yields to the browser. Poll the returned initialization with WebGlRendererInit::try_finish on successive animation frames.

If the extension is unavailable, the first poll synchronously finishes shader compilation and linking.

Source

pub fn begin_with( canvas: &HtmlCanvasElement, settings: RenderSettings, use_depth_buffer: bool, ) -> Result<(WebGlRendererInit, Resources), WebGlError>

Begins creating a WebGL2 renderer with specific settings.

See WebGlRenderer::begin for polling and fallback behavior.

Source

pub fn render( &mut self, scene: &Scene, resources: &mut Resources, render_size: &RenderSize, texture_bindings: &WebGlTextureBindings, clear_color: AlphaColor<Srgb>, ) -> Result<(), WebGlError>

Render scene using WebGL2

This method creates GPU resources as needed and schedules potentially multiple draw calls.

Every TextureId referenced by the scene must have a binding; this returns WebGlError::Render containing RenderError::MissingTextureBinding otherwise. See WebGlTextureBindings::insert for the requirements on the bound textures.

To render without any texture bindings, you can pass an empty WebGlTextureBindings.

Source

pub fn gl_context(&self) -> &WebGl2RenderingContext

Get a reference to the underlying WebGL context.

This allows direct access to WebGL operations for advanced use cases like texture creation.

Source

pub fn upload_image<T: WebGlAtlasWriter>( &mut self, resources: &mut Resources, writer: &T, ) -> Result<ImageId, WebGlError>

Upload image to cache and atlas in one step. Returns the ImageId.

This is the WebGL analogue of the wgpu Renderer’s upload_image method. It allocates space in the image cache and uploads the image data to the atlas texture.

Source

pub fn destroy_image( &mut self, resources: &mut Resources, image_id: ImageId, ) -> Result<(), WebGlError>

Destroy an image from the cache and clear the allocated slot in the atlas.

Source

pub fn atlas_texture(&self, atlas_id: AtlasId) -> &WebGlTexture

Returns an individual image atlas texture.

Source

pub fn atlas_info(&self) -> AtlasTextureInfo

Returns the current allocation state of the image/glyph atlas texture.

Trait Implementations§

Source§

impl Debug for WebGlRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,