From c40ff3e324b5cd55767acbd191f232c6a8aa8277 Mon Sep 17 00:00:00 2001 From: numzero Date: Mon, 24 Nov 2025 17:54:42 +0300 Subject: [PATCH] fix output format --- src/lib.rs | 11 ++++++----- src/render/faces.rs | 6 ++++-- src/render/lines.rs | 6 ++++-- src/render/mod.rs | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f2122d3..79e027d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,10 @@ use rand_distr::Distribution as _; use crate::{ camera::OrbitalCamera, ray::Ray, - render::lines::{LookParams, Mesh, Pipeline, Vertex}, + render::{ + OUTPUT_FORMAT, + lines::{LookParams, Mesh, Pipeline, Vertex}, + }, trace::{Hit, Lambertian, Reflector, Scene, Source, Sphere}, }; @@ -18,8 +21,6 @@ mod render; mod shape; mod trace; -const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb; - #[derive(Debug, Clone, Copy, PartialEq)] #[repr(C)] pub struct SphericalPosition { @@ -130,8 +131,8 @@ impl Core { surface, } = gpu; - let pipeline = Pipeline::new(&device, OUTPUT_FORMAT); - let mesh_pipe = render::faces::Pipeline::new(&device, OUTPUT_FORMAT); + let pipeline = Pipeline::new(&device); + let mesh_pipe = render::faces::Pipeline::new(&device); let tripod = new_tripod(&device); queue.submit([]); // flush buffer updates diff --git a/src/render/faces.rs b/src/render/faces.rs index 1776a39..e52e3e7 100644 --- a/src/render/faces.rs +++ b/src/render/faces.rs @@ -4,6 +4,8 @@ use bytemuck::{Pod, Zeroable, bytes_of, cast_slice}; use glam::{Mat4, Vec3}; use wgpu::util::DeviceExt as _; +use crate::render::OUTPUT_FORMAT; + #[derive(Debug, Clone, Copy, Pod, Zeroable)] #[repr(C)] pub struct LookParams { @@ -67,7 +69,7 @@ pub struct Pipeline { } impl Pipeline { - pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self { + pub fn new(device: &wgpu::Device) -> Self { let look_buf = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: size_of::() as u64, @@ -118,7 +120,7 @@ impl Pipeline { entry_point: None, compilation_options: wgpu::PipelineCompilationOptions::default(), targets: &[Some(wgpu::ColorTargetState { - format, + format: OUTPUT_FORMAT, blend: Some(wgpu::BlendState::REPLACE), write_mask: wgpu::ColorWrites::ALL, })], diff --git a/src/render/lines.rs b/src/render/lines.rs index 493023e..8a7ef94 100644 --- a/src/render/lines.rs +++ b/src/render/lines.rs @@ -4,6 +4,8 @@ use bytemuck::{Pod, Zeroable, bytes_of, cast_slice}; use glam::{Mat4, Vec3}; use wgpu::util::DeviceExt as _; +use crate::render::OUTPUT_FORMAT; + #[derive(Debug, Clone, Copy, Pod, Zeroable)] #[repr(C)] pub struct LookParams { @@ -49,7 +51,7 @@ pub struct Pipeline { } impl Pipeline { - pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self { + pub fn new(device: &wgpu::Device) -> Self { let look_buf = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: size_of::() as u64, @@ -100,7 +102,7 @@ impl Pipeline { entry_point: None, compilation_options: wgpu::PipelineCompilationOptions::default(), targets: &[Some(wgpu::ColorTargetState { - format, + format: OUTPUT_FORMAT, blend: Some(wgpu::BlendState::REPLACE), write_mask: wgpu::ColorWrites::ALL, })], diff --git a/src/render/mod.rs b/src/render/mod.rs index 291e015..435dc0d 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -2,3 +2,5 @@ pub mod faces; pub mod lines; static SIMPLE_SHADER: &str = include_str!("simple.wgsl"); + +pub const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;