render: fix "next swap chain texture" bug
This commit is contained in:
parent
946d5d1024
commit
cadbb4c1b0
@ -68,7 +68,7 @@ impl Node for WindowSwapChainNode {
|
||||
render_resource_context.create_swap_chain(window);
|
||||
}
|
||||
|
||||
let swap_chain_texture = render_resource_context.next_swap_chain_texture(window.id);
|
||||
let swap_chain_texture = render_resource_context.next_swap_chain_texture(&window);
|
||||
output.set(
|
||||
WINDOW_TEXTURE,
|
||||
RenderResourceId::Texture(swap_chain_texture),
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_asset::{Assets, Handle, HandleUntyped};
|
||||
use bevy_window::{Window, WindowId};
|
||||
use bevy_window::Window;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::Range,
|
||||
@ -35,7 +35,7 @@ impl HeadlessRenderResourceContext {
|
||||
|
||||
impl RenderResourceContext for HeadlessRenderResourceContext {
|
||||
fn create_swap_chain(&self, _window: &Window) {}
|
||||
fn next_swap_chain_texture(&self, _window_id: WindowId) -> TextureId {
|
||||
fn next_swap_chain_texture(&self, _window: &Window) -> TextureId {
|
||||
TextureId::new()
|
||||
}
|
||||
fn drop_swap_chain_texture(&self, _render_resource: TextureId) {}
|
||||
|
@ -5,13 +5,13 @@ use crate::{
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_asset::{Assets, Handle, HandleUntyped};
|
||||
use bevy_window::{Window, WindowId};
|
||||
use bevy_window::Window;
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
use std::ops::Range;
|
||||
|
||||
pub trait RenderResourceContext: Downcast + Send + Sync + 'static {
|
||||
fn create_swap_chain(&self, window: &Window);
|
||||
fn next_swap_chain_texture(&self, window_id: WindowId) -> TextureId;
|
||||
fn next_swap_chain_texture(&self, window: &Window) -> TextureId;
|
||||
fn drop_swap_chain_texture(&self, resource: TextureId);
|
||||
fn drop_all_swap_chain_textures(&self);
|
||||
fn create_sampler(&self, sampler_descriptor: &SamplerDescriptor) -> SamplerId;
|
||||
|
@ -127,6 +127,17 @@ impl WgpuRenderResourceContext {
|
||||
let bind_group_layout = self.device.create_bind_group_layout(&wgpu_descriptor);
|
||||
bind_group_layouts.insert(descriptor.id, bind_group_layout);
|
||||
}
|
||||
|
||||
fn try_next_swap_chain_texture(&self, window_id: bevy_window::WindowId) -> Option<TextureId> {
|
||||
let mut window_swap_chains = self.resources.window_swap_chains.write().unwrap();
|
||||
let mut swap_chain_outputs = self.resources.swap_chain_frames.write().unwrap();
|
||||
|
||||
let window_swap_chain = window_swap_chains.get_mut(&window_id).unwrap();
|
||||
let next_texture = window_swap_chain.get_next_frame().ok()?;
|
||||
let id = TextureId::new();
|
||||
swap_chain_outputs.insert(id, next_texture);
|
||||
Some(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderResourceContext for WgpuRenderResourceContext {
|
||||
@ -252,16 +263,14 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
||||
window_swap_chains.insert(window.id, swap_chain);
|
||||
}
|
||||
|
||||
fn next_swap_chain_texture(&self, window_id: bevy_window::WindowId) -> TextureId {
|
||||
let mut window_swap_chains = self.resources.window_swap_chains.write().unwrap();
|
||||
let mut swap_chain_outputs = self.resources.swap_chain_frames.write().unwrap();
|
||||
|
||||
let window_swap_chain = window_swap_chains.get_mut(&window_id).unwrap();
|
||||
let next_texture = window_swap_chain.get_next_frame().unwrap();
|
||||
|
||||
let id = TextureId::new();
|
||||
swap_chain_outputs.insert(id, next_texture);
|
||||
id
|
||||
fn next_swap_chain_texture(&self, window: &bevy_window::Window) -> TextureId {
|
||||
if let Some(texture_id) = self.try_next_swap_chain_texture(window.id) {
|
||||
texture_id
|
||||
} else {
|
||||
self.resources.window_swap_chains.write().unwrap().remove(&window.id);
|
||||
self.create_swap_chain(window);
|
||||
self.try_next_swap_chain_texture(window.id).expect("Failed to acquire next swap chain texture!")
|
||||
}
|
||||
}
|
||||
|
||||
fn drop_swap_chain_texture(&self, texture: TextureId) {
|
||||
|
Loading…
Reference in New Issue
Block a user