update pixels backend api
This commit is contained in:
parent
5f7e7db307
commit
3d57d8f309
3 changed files with 49 additions and 25 deletions
|
@ -1,9 +1,9 @@
|
|||
const SHADER_SRC_DIR: &str = "src/renderer/vulkan/shaders";
|
||||
const SHADER_OUT_DIR: &str = "shaders";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[cfg(feature = "vulkan")]
|
||||
{
|
||||
const SHADER_SRC_DIR: &str = "src/renderer/vulkan/shaders";
|
||||
const SHADER_OUT_DIR: &str = "shaders";
|
||||
|
||||
println!("cargo:rerun-if-changed={}", SHADER_SRC_DIR);
|
||||
std::fs::create_dir_all(SHADER_OUT_DIR)?;
|
||||
|
||||
|
|
|
@ -1,22 +1,38 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use pixels::{Pixels, SurfaceTexture};
|
||||
use winit::window::Window;
|
||||
pub struct Renderer {
|
||||
|
||||
use super::ResolutionData;
|
||||
|
||||
pub struct RendererBackendManager {}
|
||||
|
||||
impl RendererBackendManager {
|
||||
pub(super) fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WindowOptions {}
|
||||
|
||||
pub struct RendererBackend {
|
||||
pub pixels: Pixels,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn new(factor: u32, window: &Window) -> Self {
|
||||
let pixels = {
|
||||
let window_size = window.inner_size();
|
||||
let width = window_size.width / factor;
|
||||
let height = window_size.height / factor;
|
||||
new_pixels(width, height, factor, window)
|
||||
};
|
||||
Self { pixels }
|
||||
impl RendererBackend {
|
||||
pub fn new(
|
||||
resolutions: ResolutionData,
|
||||
window: &Window,
|
||||
_: WindowOptions,
|
||||
_: Arc<RendererBackendManager>,
|
||||
) -> Self {
|
||||
Self {
|
||||
pixels: new_pixels(resolutions, window),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, width: u32, height: u32, factor: u32, window: &Window) {
|
||||
self.pixels = new_pixels(width, height, factor, window);
|
||||
pub fn resize(&mut self, resolutions: ResolutionData, window: &Window) {
|
||||
self.pixels = new_pixels(resolutions, window);
|
||||
}
|
||||
|
||||
pub fn new_frame(&mut self, buffer: &[[u8; 4]]) {
|
||||
|
@ -25,19 +41,23 @@ impl Renderer {
|
|||
.copy_from_slice(bytemuck::cast_slice(buffer));
|
||||
}
|
||||
|
||||
pub fn render(&mut self) {
|
||||
pub fn render(&mut self, _: ResolutionData, _: &RendererBackendManager) {
|
||||
self.pixels.render().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn new_pixels(width: u32, height: u32, scaling: u32, window: &Window) -> Pixels {
|
||||
fn new_pixels(resolutions: ResolutionData, window: &Window) -> Pixels {
|
||||
let surface_texture: SurfaceTexture<'_, Window> =
|
||||
SurfaceTexture::new(width * scaling, height * scaling, window);
|
||||
pixels::PixelsBuilder::new(width, height, surface_texture)
|
||||
.request_adapter_options(pixels::wgpu::RequestAdapterOptionsBase {
|
||||
power_preference: pixels::wgpu::PowerPreference::HighPerformance,
|
||||
..pixels::wgpu::RequestAdapterOptionsBase::default()
|
||||
})
|
||||
.build()
|
||||
.unwrap()
|
||||
SurfaceTexture::new(resolutions.real_width, resolutions.real_height, window);
|
||||
pixels::PixelsBuilder::new(
|
||||
resolutions.scaled_width,
|
||||
resolutions.scaled_height,
|
||||
surface_texture,
|
||||
)
|
||||
.request_adapter_options(pixels::wgpu::RequestAdapterOptionsBase {
|
||||
power_preference: pixels::wgpu::PowerPreference::HighPerformance,
|
||||
..pixels::wgpu::RequestAdapterOptionsBase::default()
|
||||
})
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use gilrs::{
|
|||
ff::{BaseEffect, BaseEffectType, EffectBuilder, Replay, Ticks},
|
||||
Button, Gilrs,
|
||||
};
|
||||
#[cfg(feature = "vulkan")]
|
||||
use raw_window_handle::HasRawDisplayHandle;
|
||||
use winit::{
|
||||
dpi::PhysicalSize,
|
||||
|
@ -157,11 +158,14 @@ impl WindowRenderer {
|
|||
scaled_height: inner_size.height / real_factor,
|
||||
};
|
||||
|
||||
#[cfg(feature = "vulkan")]
|
||||
let options = WindowOptions {
|
||||
shader_path: std::path::PathBuf::from(
|
||||
"./test-roms/shaders/slang-shaders/bilinear.slangp",
|
||||
),
|
||||
};
|
||||
#[cfg(feature = "pixels")]
|
||||
let options = WindowOptions {};
|
||||
|
||||
let renderer = Mutex::new(RendererBackend::new(resolutions, &window, options, manager));
|
||||
let id = window.id();
|
||||
|
|
Loading…
Add table
Reference in a new issue