pub struct RenderSurface { /* private fields */ }Expand description
渲染表面
管理窗口表面、交换链配置和帧缓冲,提供渲染目标管理功能。
§设计理念
- 自适应配置: 根据设备能力自动配置表面参数
- 动态调整: 支持窗口大小变化时的动态重配置
- 格式选择: 自动选择最佳的纹理格式和呈现模式
- 错误恢复: 处理表面丢失等异常情况
§示例
use anvilkit_render::renderer::{RenderDevice, RenderSurface};
use std::sync::Arc;
use winit::window::Window;
// 创建设备和表面
// let window = Arc::new(window);
// let device = RenderDevice::new(&window).await?;
// let surface = RenderSurface::new(&device, &window)?;
// 获取当前帧
// let frame = surface.get_current_frame()?;Implementations§
Source§impl RenderSurface
impl RenderSurface
Sourcepub fn new(device: &RenderDevice, window: &Arc<Window>) -> Result<Self>
pub fn new(device: &RenderDevice, window: &Arc<Window>) -> Result<Self>
创建新的渲染表面
§参数
device: 渲染设备window: 窗口实例
§返回
成功时返回 RenderSurface 实例,失败时返回错误
§示例
use anvilkit_render::renderer::{RenderDevice, RenderSurface};
use std::sync::Arc;
use winit::window::Window;
// let window = Arc::new(window);
// let device = RenderDevice::new(&window).await?;
// let surface = RenderSurface::new(&device, &window)?;Sourcepub fn new_with_vsync(
device: &RenderDevice,
window: &Arc<Window>,
vsync: bool,
) -> Result<Self>
pub fn new_with_vsync( device: &RenderDevice, window: &Arc<Window>, vsync: bool, ) -> Result<Self>
创建新的渲染表面(指定 vsync 模式)
vsync = true: 使用PresentMode::Fifo(垂直同步)vsync = false: 优先使用PresentMode::Mailbox(三重缓冲,低延迟)
Sourcepub fn get_current_frame(&self) -> Result<SurfaceTexture>
pub fn get_current_frame(&self) -> Result<SurfaceTexture>
Sourcepub fn reconfigure(&self, device: &RenderDevice)
pub fn reconfigure(&self, device: &RenderDevice)
重新配置表面(用于 Lost/Outdated 恢复)
Sourcepub fn get_current_frame_with_recovery(
&self,
device: &RenderDevice,
) -> Result<SurfaceTexture>
pub fn get_current_frame_with_recovery( &self, device: &RenderDevice, ) -> Result<SurfaceTexture>
获取当前帧,自动恢复 Lost/Outdated 错误
如果首次获取失败(Lost 或 Outdated),自动 reconfigure 后重试一次。
Sourcepub fn config(&self) -> &SurfaceConfiguration
pub fn config(&self) -> &SurfaceConfiguration
Sourcepub fn format(&self) -> TextureFormat
pub fn format(&self) -> TextureFormat
Auto Trait Implementations§
impl !Freeze for RenderSurface
impl !RefUnwindSafe for RenderSurface
impl Send for RenderSurface
impl Sync for RenderSurface
impl Unpin for RenderSurface
impl UnsafeUnpin for RenderSurface
impl !UnwindSafe for RenderSurface
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.