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