Struct ark_api::render::Render

source ·
pub struct Render { /* private fields */ }
Expand description

Gives access to rendering specific functionality like drawing 2D triangles.

Use the require_render_api macro’s render() function to get an instance of Render. See the module level documentation for an example.

A Render object can be cheaply cloned.

Implementations§

source§

impl Render

source

pub fn draw_triangles( &self, clip_rect: &Rectangle, indices: impl AsRef<[[u32; 3]]>, positions: impl AsRef<[Vec2]>, colors: impl AsRef<[ColorRgba8]> )

Draw colored 2D triangles in screen space (physical pixel coordinates).

  • colors - Assumes premultiplied alpha.
source

pub fn draw_textured_triangles( &self, clip_rect: &Rectangle, texture: TextureHandle, indices: impl AsRef<[[u32; 3]]>, positions: impl AsRef<[Vec2]>, colors: impl AsRef<[ColorRgba8]>, uvs: impl AsRef<[Vec2]> )

Draw colored 2D textured triangles in screen space (physical pixel coordinates).

  • colors - Assumes premultiplied alpha.
source

pub fn draw_debug_lines(&self, lines: &[Line])

Draws 3D debug lines.

These are simple but fast primitive lines that are meant to quickly get something up with little overhead, when you just need to visualize something for debugging. They will never deliver a polished look, so do not use for user-facing things.

source

pub fn create_mesh( &self, mesh: &Mesh, flags: RenderMeshCreateFlags ) -> RenderMesh

Creates a mesh.

NOTE: Normals can be automatically generated by the engine. Simply set normals to None in mesh.data.

source

pub fn create_mesh_with_material( &self, mesh: &Mesh, flags: RenderMeshCreateFlags, material: RenderMaterial ) -> RenderMesh

Creates a mesh with a material.

NOTE: Normals can be automatically generated by the engine. Simply set normals to None in mesh.data.

source

pub fn create_mesh_with_materials_and_sections( &self, mesh: &Mesh, flags: RenderMeshCreateFlags, materials: &[RenderMaterial], sections: &[RenderMeshSection] ) -> RenderMesh

Creates a mesh with multiple materials split by sections.

The mesh can be split into multiple sections with different materials. If no sections are provided the entire mesh will be a single section. NOTE: Normals can be automatically generated by the engine. Simply set normals to None in mesh.data.

source

pub fn create_mesh_from_gltf( &self, debug_name: &str, gltf_data: &[u8], buffer_data: &[u8], flags: GltfFlags ) -> Result<RenderMesh, Error>

Loads a mesh from directly provided GLTF data.

Supports .gltf and .glb, and a single additional buffer file. buffer_name is not used directly, but might be used for validation.

source

pub fn create_mesh_from_gltf_resource( &self, debug_name: &str, gltf_resource: ResourceHandleRepr, buffer_resource: Option<ResourceHandleRepr>, flags: GltfFlags ) -> Result<RenderMesh, Error>

Creates a mesh from a GLTF resource handle and additional buffer resource handle.

source

pub fn draw_mesh( &self, mesh: &RenderMesh, world_transform: &Mat4, style: &RenderMeshStyle, instance_id: Option<InstanceId> )

Draws a single mesh.

It is OK to drop the RenderMesh in the same frame after calling this, it will still be drawn.

When drawing multiple meshes, prefer to use Render::draw_meshes instead for improved performance.

If you are drawing the same mesh over multiple frames, pick a unique-enough instance_id and pass the same one every frame. Pass 0 if you can’t come up with one, but you’ll end up with rendering artifacts on quick movements.

Errors

Under normal safe circumstances, this function cannot error. However, errors through the underlying API can happen - for example, if the raw handle inside mesh has already been destroyed (via unsafe code).

source

pub fn draw_meshes(&self, mesh_instances: &[RenderMeshInstance])

Draws multiple meshes.

Use RenderMeshInstanceBuilder to create a RenderMeshInstance.

It is OK to drop the RenderMesh in the same frame after calling this, it will still be drawn.

Errors

Under normal safe circumstances, this function cannot error. However, errors through the underlying API can happen - for example, if the raw handle inside mesh has already been destroyed (via unsafe code).

If an error occurs drawing one or more of the meshes in the list, no meshes in the list will be drawn, and an error is returned.

source

pub fn draw_meshes_with_materials( &self, mesh_instances: &[RenderMeshInstance], material_overrides: &[RenderMaterial] )

Draws multiple meshes with a list of material overrides.

Use RenderMeshInstanceBuilder to create a RenderMeshInstance.

It is okay to drop the RenderMesh in the same frame after calling this, it will still be drawn.

The material ID inside the meshes will be used to index into the material_overrides list offsetted by RenderMeshInstance::materials_offset. If no override is provided for an index the meshes original material will be used.

source

pub fn draw_meshes_with_materials_and_styles( &self, mesh_instances: &[RenderMeshInstance], material_overrides: &[RenderMaterial], mesh_style_overrides: &[RenderMeshStyle] )

Draws multiple meshes with a list of material and style overrides.

Use RenderMeshInstanceBuilder to create a RenderMeshInstance.

It is okay to drop the RenderMesh in the same frame after calling this, it will still be drawn.

The material ID inside the meshes will be used to index into the material_overrides list offsetted by RenderMeshInstance::materials_offset. If no override is provided for an index the meshes original material will be used.

source

pub fn create_texture(&self) -> TextureBuilder<'_>

Allocate a new texture.

Example
let data = [255, 0, 0, 255,
            0, 255, 0, 255];
let texture = render
    .create_texture()
    .name("my_texture")
    .dimension(2, 1)
    .format(TextureFormat::R8G8B8A8_SRGB) // can be omitted - this is the default
    .data(pixels)
    .build()?;
source

pub fn create_sdf_model( &self, opcodes: &[u32], constants: &[f32], bounding_box: &BoundingBox ) -> Result<SdfModel, Error>

Creates a new SDF function from Saft opcodes and constants.

Trait Implementations§

source§

impl Clone for Render

source§

fn clone(&self) -> Render

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.