update to graphics v0.0.7

This commit is contained in:
2026-03-10 07:51:02 -07:00
parent 0b5a8453dc
commit 673142c493
8 changed files with 10 additions and 73 deletions

4
Cargo.lock generated
View File

@@ -1720,9 +1720,9 @@ dependencies = [
[[package]]
name = "strafesnet_graphics"
version = "0.0.6"
version = "0.0.7"
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
checksum = "0956371782403270db1788d0af2977d3d30632e5bdb9e514cd1550db0999c82a"
checksum = "5b0afe15871f8205f3387dd5816e797c0576429d3013a33a3daed293bcaeedef"
dependencies = [
"bytemuck",
"ddsfile",

View File

@@ -16,7 +16,7 @@ codegen-units = 1
glam = "0.32.0"
strafesnet_common = { version = "0.8.6", registry = "strafesnet" }
strafesnet_graphics = { version = "0.0.6", registry = "strafesnet" }
strafesnet_graphics = { version = "0.0.7", registry = "strafesnet" }
strafesnet_roblox_bot_file = { version = "0.9.3", registry = "strafesnet" }
strafesnet_snf = { version = "0.3.2", registry = "strafesnet" }

View File

@@ -2,5 +2,4 @@ pub mod bot;
pub mod head;
pub mod time;
pub mod state;
pub mod surface;
pub mod graphics;

View File

@@ -1,60 +0,0 @@
/// A texture view which can be targetted by draw calls in the command buffer, and then presented to the surface texture.
pub struct Frame{
surface_texture:wgpu::SurfaceTexture,
view:wgpu::TextureView,
}
impl Frame{
pub const fn view(&self)->&wgpu::TextureView{
&self.view
}
pub fn present(self){
self.surface_texture.present();
}
}
/// A render surface configuration, containing information such as resolution and pixel format
pub struct Surface<'window>{
surface:wgpu::Surface<'window>,
config:wgpu::SurfaceConfiguration,
}
impl<'window> Surface<'window>{
// TODO: move Surface to strafesnet_graphics
pub fn new(
surface:wgpu::Surface<'window>,
config:wgpu::SurfaceConfiguration,
)->Self{
Self{surface,config}
}
#[must_use]
pub fn new_frame(&self,device:&wgpu::Device)->Frame{
let frame=match self.surface.get_current_texture(){
Ok(frame)=>frame,
Err(_)=>{
self.surface.configure(device,&self.config);
self.surface
.get_current_texture()
.expect("Failed to acquire next surface texture!")
}
};
let view=frame.texture.create_view(&wgpu::TextureViewDescriptor{
format:Some(self.config.view_formats[0]),
..wgpu::TextureViewDescriptor::default()
});
Frame{
surface_texture:frame,
view,
}
}
pub const fn size(&self)->glam::UVec2{
glam::uvec2(self.config.width,self.config.height)
}
pub fn view_format(&self)->wgpu::TextureFormat{
self.config.view_formats[0]
}
pub fn configure(&mut self,device:&wgpu::Device,size:glam::UVec2){
self.config.width=size.x.max(1);
self.config.height=size.y.max(1);
self.surface.configure(device,&self.config);
}
}

View File

@@ -1,7 +1,8 @@
use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::Time as SessionTime;
use strafesnet_common::timer::TimerState;
use strafesnet_roblox_bot_player::{bot::CompleteBot,graphics::Graphics,head::{PlaybackHead,Time as PlaybackTime},surface::Surface};
use strafesnet_roblox_bot_player::{bot::CompleteBot,graphics::Graphics,head::{PlaybackHead,Time as PlaybackTime}};
use strafesnet_graphics::surface::Surface;
pub enum SessionControlInstruction{
SetPaused(bool),

View File

@@ -22,9 +22,7 @@ pub async fn setup_and_start(title:&str){
let (device,queue)=setup::step4::request_device(&adapter).await.unwrap();
let size=window.inner_size();
let config=setup::step5::configure_surface(&adapter,&device,&surface,(size.width,size.height)).unwrap();
let surface=strafesnet_roblox_bot_player::surface::Surface::new(surface,config);
let surface=setup::step5::configure_surface(&adapter,&device,surface,(size.width,size.height)).unwrap();
//dedicated thread to ping request redraw back and resize the window doesn't seem logical

View File

@@ -126,7 +126,7 @@ impl WindowContext<'_>{
window:&'a winit::window::Window,
device:wgpu::Device,
queue:wgpu::Queue,
surface:strafesnet_roblox_bot_player::surface::Surface<'a>,
surface:strafesnet_graphics::surface::Surface<'a>,
)->WindowContext<'a>{
let size=surface.size();
let graphics=strafesnet_roblox_bot_player::graphics::Graphics::new(&device,&queue,size,surface.view_format());

View File

@@ -1,8 +1,8 @@
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsError;
use strafesnet_roblox_bot_file::v0;
use strafesnet_roblox_bot_player::{bot,head,time,graphics,surface};
use strafesnet_graphics::setup;
use strafesnet_roblox_bot_player::{bot,head,time,graphics};
use strafesnet_graphics::{setup,surface};
// Hack to keep the code compiling,
// SurfaceTarget::Canvas is not available in IDE for whatever reason.
@@ -39,8 +39,7 @@ pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Result<Graphics,
compatible_surface:Some(&surface),
}).await.map_err(|e|JsError::new(&e.to_string()))?;
let (device,queue)=setup::step4::request_device(&adapter).await.map_err(|e|JsError::new(&e.to_string()))?;
let config=setup::step5::configure_surface(&adapter,&device,&surface,(size.x,size.y)).map_err(|e|JsError::new(&e.to_string()))?;
let surface=surface::Surface::new(surface,config);
let surface=setup::step5::configure_surface(&adapter,&device,surface,(size.x,size.y)).map_err(|e|JsError::new(&e.to_string()))?;
Ok(Graphics{
graphics:graphics::Graphics::new(&device,&queue,size,surface.view_format()),
surface,