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
sourceimpl Render
impl Render
sourcepub fn draw_triangles(
&self,
clip_rect: &Rectangle,
indices: impl AsRef<[[u32; 3]]>,
positions: impl AsRef<[Vec2]>,
colors: impl AsRef<[ColorRgba8]>
)
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.
sourcepub 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]>
)
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.
sourcepub fn draw_debug_lines(&self, lines: &[Line])
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.
sourcepub fn create_mesh(&self, mesh: Mesh, flags: RenderMeshCreateFlags) -> RenderMesh
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
.
sourcepub fn create_mesh_with_material(
&self,
mesh: Mesh,
flags: RenderMeshCreateFlags,
material: RenderMaterial
) -> RenderMesh
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
.
sourcepub fn create_mesh_with_materials_and_sections(
&self,
mesh: Mesh,
flags: RenderMeshCreateFlags,
materials: &[RenderMaterial],
sections: &[RenderMeshSection]
) -> RenderMesh
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
.
sourcepub fn create_mesh_from_gltf(
&self,
debug_name: &str,
gltf_data: &[u8],
buffer_data: &[u8],
flags: GltfFlags
) -> Result<RenderMesh, Error>
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.
sourcepub fn create_mesh_from_gltf_resource(
&self,
debug_name: &str,
gltf_resource: ResourceHandleRepr,
buffer_resource: Option<ResourceHandleRepr>,
flags: GltfFlags
) -> Result<RenderMesh, Error>
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.
sourcepub fn draw_mesh(
&self,
mesh: &RenderMesh,
world_transform: &Mat4,
style: &RenderMeshStyle,
instance_id: Option<InstanceId>
)
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).
sourcepub fn draw_meshes(&self, mesh_instances: &[RenderMeshInstance])
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.
sourcepub fn draw_meshes_with_materials(
&self,
mesh_instances: &[RenderMeshInstance],
material_overrides: &[RenderMaterial]
)
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.
sourcepub fn create_texture(&self) -> TextureBuilder<'_>
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()?;
sourcepub fn create_sdf_model(
&self,
opcodes: &[u32],
constants: &[f32],
bounding_box: &BoundingBox
) -> Result<SdfModel, Error>
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
Auto Trait Implementations
impl RefUnwindSafe for Render
impl Send for Render
impl Sync for Render
impl Unpin for Render
impl UnwindSafe for Render
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more