pub struct Context { /* private fields */ }
Expand description
Contains the adapter, device, queue, RenderTarget
and configuration.
A Context
is created to initialize rendering to a window, canvas or
texture.
use renderling::context::Context;
let ctx = futures_lite::future::block_on(Context::headless(100, 100));
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(
target: RenderTarget,
adapter: impl Into<Arc<Adapter>>,
device: impl Into<Arc<Device>>,
queue: impl Into<Arc<Queue>>,
) -> Self
pub fn new( target: RenderTarget, adapter: impl Into<Arc<Adapter>>, device: impl Into<Arc<Device>>, queue: impl Into<Arc<Queue>>, ) -> Self
Creates a new Context
with the specified target, adapter, device, and queue.
Sourcepub async fn try_new_headless(
width: u32,
height: u32,
backends: Option<Backends>,
) -> Result<Self, ContextError>
pub async fn try_new_headless( width: u32, height: u32, backends: Option<Backends>, ) -> Result<Self, ContextError>
Attempts to create a new headless Context
with the specified width, height, and backends.
Sourcepub async fn try_new_with_surface(
width: u32,
height: u32,
backends: Option<Backends>,
window: impl Into<SurfaceTarget<'static>>,
) -> Result<Self, ContextError>
pub async fn try_new_with_surface( width: u32, height: u32, backends: Option<Backends>, window: impl Into<SurfaceTarget<'static>>, ) -> Result<Self, ContextError>
Attempts to create a new Context
with a surface, using the specified width, height, backends, and window.
Sourcepub async fn from_winit_window(
backends: Option<Backends>,
window: Arc<Window>,
) -> Self
pub async fn from_winit_window( backends: Option<Backends>, window: Arc<Window>, ) -> Self
Sourcepub async fn headless(width: u32, height: u32) -> Self
pub async fn headless(width: u32, height: u32) -> Self
Creates a new headless renderer.
Immediately proxies to Context::try_new_headless
and unwraps.
§Panics
This function will panic if an adapter cannot be found. For example, this would happen on machines without a GPU.
pub fn get_size(&self) -> UVec2
Sourcepub fn create_texture<P>(
&self,
label: Option<&str>,
img: &ImageBuffer<P, Vec<u8>>,
) -> Result<Texture, TextureError>
pub fn create_texture<P>( &self, label: Option<&str>, img: &ImageBuffer<P, Vec<u8>>, ) -> Result<Texture, TextureError>
Creates a texture from an image buffer.
Sourcepub fn texture_from_wgpu_tex(
&self,
texture: impl Into<Arc<Texture>>,
sampler: Option<SamplerDescriptor<'_>>,
) -> Texture
pub fn texture_from_wgpu_tex( &self, texture: impl Into<Arc<Texture>>, sampler: Option<SamplerDescriptor<'_>>, ) -> Texture
Creates a Texture
from a wgpu::Texture
and an optional sampler.
Sourcepub fn runtime(&self) -> &WgpuRuntime
pub fn runtime(&self) -> &WgpuRuntime
Returns a reference to the WgpuRuntime
.
Sourcepub fn get_device(&self) -> &Device
pub fn get_device(&self) -> &Device
Returns a reference to the wgpu::Device
.
Sourcepub fn get_adapter(&self) -> &Adapter
pub fn get_adapter(&self) -> &Adapter
Returns a reference to the wgpu::Adapter
.
Sourcepub fn get_adapter_owned(&self) -> Arc<Adapter>
pub fn get_adapter_owned(&self) -> Arc<Adapter>
Returns the adapter in an owned wrapper.
Sourcepub fn get_render_target(&self) -> &RenderTarget
pub fn get_render_target(&self) -> &RenderTarget
Returns a reference to the RenderTarget
.
Sourcepub fn get_next_frame(&self) -> Result<Frame, ContextError>
pub fn get_next_frame(&self) -> Result<Frame, ContextError>
Gets the next frame from the render target.
A surface context (window or canvas) will return the next swapchain texture.
A headless context will return the underlying headless texture.
§Errors
Errs if the render target is a surface and there was an error getting the next swapchain texture. This can happen if the frame has already been acquired.
Sourcepub fn set_default_atlas_texture_size(&self, size: impl Into<UVec3>) -> &Self
pub fn set_default_atlas_texture_size(&self, size: impl Into<UVec3>) -> &Self
Sets the default texture size for the material atlas.
- Width is
size.x
and must be a power of two. - Height is
size.y
, must matchsize.x
and must be a power of two. - Layers is
size.z
and must be two or greater.
Sourcepub fn with_default_atlas_texture_size(self, size: impl Into<UVec3>) -> Self
pub fn with_default_atlas_texture_size(self, size: impl Into<UVec3>) -> Self
Sets the default texture size for the material atlas.
- Width is
size.x
and must be a power of two. - Height is
size.y
, must matchsize.x
and must be a power of two. - Layers is
size.z
and must be greater than zero.
§Panics
Will panic if the above conditions are not met.
Sourcepub fn set_shadow_mapping_atlas_texture_size(
&self,
size: impl Into<UVec3>,
) -> &Self
pub fn set_shadow_mapping_atlas_texture_size( &self, size: impl Into<UVec3>, ) -> &Self
Sets the default texture size for the shadow mapping atlas.
- Width is
size.x
and must be a power of two. - Height is
size.y
, must matchsize.x
and must be a power of two. - Layers is
size.z
and must be two or greater.
Sourcepub fn with_shadow_mapping_atlas_texture_size(
self,
size: impl Into<UVec3>,
) -> Self
pub fn with_shadow_mapping_atlas_texture_size( self, size: impl Into<UVec3>, ) -> Self
Sets the default texture size for the shadow mapping atlas.
- Width is
size.x
and must be a power of two. - Height is
size.y
, must matchsize.x
and must be a power of two. - Layers is
size.z
and must be greater than zero.
§Panics
Will panic if the above conditions are not met.
Sourcepub fn set_use_direct_draw(&self, use_direct_drawing: bool)
pub fn set_use_direct_draw(&self, use_direct_drawing: bool)
Sets the use of direct drawing.
Default is false.
If set to true, all compute culling, including frustum and occlusion culling, will not run.
Sourcepub fn with_use_direct_draw(self, use_direct_drawing: bool) -> Self
pub fn with_use_direct_draw(self, use_direct_drawing: bool) -> Self
Sets the use of direct drawing.
Default is false.
If set to true, all compute culling is turned off. This includes frustum and occlusion culling.
Sourcepub fn get_use_direct_draw(&self) -> bool
pub fn get_use_direct_draw(&self) -> bool
Returns whether direct drawing is used.
Trait Implementations§
Source§impl AsRef<WgpuRuntime> for Context
impl AsRef<WgpuRuntime> for Context
Source§fn as_ref(&self) -> &WgpuRuntime
fn as_ref(&self) -> &WgpuRuntime
Auto Trait Implementations§
impl !Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl !UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);