Skip to content

Commit

Permalink
GLTF documents on the slab (#61)
Browse files Browse the repository at this point in the history
* beginning of gltf on the slab

* A whole GLTF document (and buffers and images) on the GPU

* fmt
  • Loading branch information
schell authored Dec 1, 2023
1 parent fb63d72 commit 5e61512
Show file tree
Hide file tree
Showing 48 changed files with 2,302 additions and 791 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ members = [
"crates/renderling-shader",
"crates/renderling-gpui",
"crates/renderling-derive",
"crates/sandbox",
]

exclude = ["./shaders"]
Expand Down
2 changes: 1 addition & 1 deletion crates/example-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn main() {
.apply()
.unwrap();

let event_loop = winit::event_loop::EventLoop::new();
let event_loop = winit::event_loop::EventLoop::new();
let window_size = winit::dpi::LogicalSize {
width: 800,
height: 600,
Expand Down
8 changes: 5 additions & 3 deletions crates/example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Main entry point for the gltf viewer.
use renderling::Renderling;
use clap::Parser;
use example::gltf;
use renderling::Renderling;

#[derive(Parser)]
#[command(author, version, about)]
Expand All @@ -12,7 +12,7 @@ struct Cli {

/// Optional HDR image to use as skybox at startup
#[arg(short, long)]
skybox: Option<String>
skybox: Option<String>,
}

fn run() -> Result<(), anyhow::Error> {
Expand All @@ -38,7 +38,9 @@ fn run() -> Result<(), anyhow::Error> {
// Set up a new renderling
let mut r = Renderling::try_from_window(&window).unwrap();
let mut run_current_frame: Box<dyn FnMut(&mut Renderling, Option<&winit::event::WindowEvent>)> =
Box::new(futures_lite::future::block_on(gltf::demo(&mut r, cli.model, cli.skybox)));
Box::new(futures_lite::future::block_on(gltf::demo(
&mut r, cli.model, cli.skybox,
)));
event_loop.run(move |event, _target, control_flow| {
*control_flow = winit::event_loop::ControlFlow::Poll;

Expand Down
12 changes: 5 additions & 7 deletions crates/renderling-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ pub fn derive_from_slab(input: proc_macro::TokenStream) -> proc_macro::TokenStre
FieldName::Index(i) => Ident::new(&format!("offset_of_{}", i.index), i.span),
FieldName::Ident(field) => Ident::new(&format!("offset_of_{}", field), field.span()),
};
offsets.push(
quote!{
pub fn #ident() -> usize {
#(<#offset_tys as renderling_shader::slab::Slabbed>::slab_size()+)*
0
}
offsets.push(quote! {
pub fn #ident() -> usize {
#(<#offset_tys as renderling_shader::slab::Slabbed>::slab_size()+)*
0
}
);
});
offset_tys.push(ty.clone());
}

Expand Down
12 changes: 8 additions & 4 deletions crates/renderling-gpui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use snafu::prelude::*;
use std::sync::Arc;

use renderling::frame::FrameTextureView;
use renderling::{Device, View, RenderTarget};
use renderling::{Device, RenderTarget, View};
use renderling::{
FontArc, Frame, GlyphCache, Id, OwnedSection, OwnedText, Queue, Renderling, UiDrawObject,
UiDrawObjectBuilder, UiMode, UiScene, UiVertex, WgpuStateError, ViewMut,
UiDrawObjectBuilder, UiMode, UiScene, UiVertex, ViewMut, WgpuStateError,
};
use renderling::{UiRenderPipeline, UiSceneError};

Expand Down Expand Up @@ -330,8 +330,12 @@ impl Gpui {
Ok(())
}

use renderling::{Graph, graph, frame::{create_frame, clear_frame_and_depth}};
r.graph.add_subgraph(graph!(create_frame, clear_frame_and_depth, update_scene));
use renderling::{
frame::{clear_frame_and_depth, create_frame},
graph, Graph,
};
r.graph
.add_subgraph(graph!(create_frame, clear_frame_and_depth, update_scene));
r.graph.add_barrier();
r.graph.add_local::<RenderParams, ()>("render");
Self(r)
Expand Down
23 changes: 19 additions & 4 deletions crates/renderling-shader/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ use crate::id::Id;
use crate::slab::Slabbed;

#[repr(C)]
#[derive(Clone, Copy)]
pub struct Array<T: Slabbed> {
pub struct Array<T> {
index: u32,
len: u32,
_phantom: PhantomData<T>,
}

impl<T: Slabbed> core::fmt::Debug for Array<T> {
impl<T> Clone for Array<T> {
fn clone(&self) -> Self {
Self {
index: self.index,
len: self.len,
_phantom: PhantomData,
}
}
}

impl<T> Copy for Array<T> {}

impl<T> core::fmt::Debug for Array<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Array")
.field("index", &self.index)
Expand All @@ -22,7 +33,7 @@ impl<T: Slabbed> core::fmt::Debug for Array<T> {
}
}

impl<T: Slabbed> PartialEq for Array<T> {
impl<T> PartialEq for Array<T> {
fn eq(&self, other: &Self) -> bool {
self.index == other.index && self.len == other.len
}
Expand Down Expand Up @@ -92,4 +103,8 @@ impl<T: Slabbed> Array<T> {
Id::new(self.index + (T::slab_size() * index) as u32)
}
}

pub fn starting_index(&self) -> usize {
self.index as usize
}
}
Loading

0 comments on commit 5e61512

Please sign in to comment.