feat(editor): add ViewportTexture offscreen render target

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 10:31:28 +09:00
parent d93253dfb1
commit ae20590f6e
2 changed files with 74 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ pub mod renderer;
pub mod ui_context;
pub mod widgets;
pub mod dock;
pub mod orbit_camera;
pub use font::FontAtlas;
pub use draw_list::{DrawVertex, DrawCommand, DrawList};
@@ -12,3 +13,7 @@ pub use layout::LayoutState;
pub use renderer::UiRenderer;
pub use ui_context::UiContext;
pub use dock::{DockTree, DockNode, Axis, Rect, LeafLayout};
pub use orbit_camera::OrbitCamera;
pub mod viewport_texture;
pub use viewport_texture::{ViewportTexture, VIEWPORT_COLOR_FORMAT, VIEWPORT_DEPTH_FORMAT};

View File

@@ -0,0 +1,69 @@
pub const VIEWPORT_COLOR_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
pub const VIEWPORT_DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
pub struct ViewportTexture {
pub color_texture: wgpu::Texture,
pub color_view: wgpu::TextureView,
pub depth_texture: wgpu::Texture,
pub depth_view: wgpu::TextureView,
pub width: u32,
pub height: u32,
}
impl ViewportTexture {
pub fn new(device: &wgpu::Device, width: u32, height: u32) -> Self {
let w = width.max(1);
let h = height.max(1);
let color_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("Viewport Color"),
size: wgpu::Extent3d {
width: w,
height: h,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: VIEWPORT_COLOR_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
});
let color_view = color_texture.create_view(&wgpu::TextureViewDescriptor::default());
let depth_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("Viewport Depth"),
size: wgpu::Extent3d {
width: w,
height: h,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: VIEWPORT_DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
});
let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
ViewportTexture {
color_texture,
color_view,
depth_texture,
depth_view,
width: w,
height: h,
}
}
pub fn ensure_size(&mut self, device: &wgpu::Device, width: u32, height: u32) -> bool {
let w = width.max(1);
let h = height.max(1);
if w == self.width && h == self.height {
return false;
}
*self = Self::new(device, w, h);
true
}
}