diff --git a/dunge/src/bind.rs b/dunge/src/bind.rs index eb33fb2..549f940 100644 --- a/dunge/src/bind.rs +++ b/dunge/src/bind.rs @@ -170,6 +170,9 @@ impl TypedGroup { } } +/// The group binder type. +/// +/// Can be created using the context's [`make_binder`](crate::Context::make_binder) function. pub struct Binder<'a> { shader_id: usize, device: &'a Device, @@ -188,7 +191,17 @@ impl<'a> Binder<'a> { } } - pub fn bind(&mut self, group: &G) -> GroupHandler + /// Adds a group to the associated shader's binding. + /// + /// It returns a [group handler](GroupHandler) that can be used to update + /// the data in this binding. If you don't need to update the data, then + /// discard this handler. + /// + /// # Panic + /// It checks the group type matches to an associated shader's group at runtime. + /// If it's violated or there are more bindings than in the shader, + /// then this function will panic. + pub fn add(&mut self, group: &G) -> GroupHandler where G: Visit, { @@ -221,6 +234,11 @@ impl<'a> Binder<'a> { } } + /// Constructs an object that can be [used](crate::layer::SetLayer::bind) + /// in the draw stage. + /// + /// # Panic + /// It will panic if some group bindings is not set. pub fn into_binding(self) -> UniqueBinding { assert!( self.groups.len() == self.layout.len(), diff --git a/dunge/src/context.rs b/dunge/src/context.rs index d59bee2..170bbed 100644 --- a/dunge/src/context.rs +++ b/dunge/src/context.rs @@ -17,8 +17,6 @@ use { /// Creates the context instance. /// -/// If you need a window call the [`window`] function. -/// /// # Errors /// Returns an error when the context could not be created. /// See [`FailedMakeContext`] for details. diff --git a/dunge/src/shader.rs b/dunge/src/shader.rs index 2b785a6..297c9b4 100644 --- a/dunge/src/shader.rs +++ b/dunge/src/shader.rs @@ -12,6 +12,9 @@ use { }, }; +/// The shader type. +/// +/// Can be created using the context's [`make_shader`](crate::Context::make_shader) function. pub struct Shader { inner: Inner, wgsl: String, diff --git a/dunge/tests/triangle_discard.rs b/dunge/tests/triangle_discard.rs index 42da6ce..8a1ffbc 100644 --- a/dunge/tests/triangle_discard.rs +++ b/dunge/tests/triangle_discard.rs @@ -60,7 +60,7 @@ fn render() -> Result<(), Error> { }; let mut binder = cx.make_binder(&shader); - binder.bind(&map); + binder.add(&map); binder.into_binding() }; diff --git a/dunge/tests/triangle_group.rs b/dunge/tests/triangle_group.rs index 17c7a9b..de1bfe6 100644 --- a/dunge/tests/triangle_group.rs +++ b/dunge/tests/triangle_group.rs @@ -56,7 +56,7 @@ fn render() -> Result<(), Error> { }; let mut binder = cx.make_binder(&shader); - binder.bind(&map); + binder.add(&map); binder.into_binding() }; diff --git a/examples/cube/src/lib.rs b/examples/cube/src/lib.rs index f298a48..d92ed19 100644 --- a/examples/cube/src/lib.rs +++ b/examples/cube/src/lib.rs @@ -48,7 +48,7 @@ pub async fn run(ws: dunge::window::WindowState) -> Result<(), Error> { let bind_transform = { let tr = Transform(&uniform); let mut binder = cx.make_binder(&cube_shader); - binder.bind(&tr); + binder.add(&tr); binder.into_binding() }; diff --git a/examples/ssaa/src/lib.rs b/examples/ssaa/src/lib.rs index 96feb00..93884ab 100644 --- a/examples/ssaa/src/lib.rs +++ b/examples/ssaa/src/lib.rs @@ -69,7 +69,7 @@ pub async fn run(ws: dunge::window::WindowState) -> Result<(), Error> { let bind = { let offset = Offset(&uniform); let mut binder = cx.make_binder(&triangle_shader); - binder.bind(&offset); + binder.add(&offset); binder.into_binding() }; @@ -105,7 +105,7 @@ pub async fn run(ws: dunge::window::WindowState) -> Result<(), Error> { }; let mut binder = cx.make_binder(&screen_shader); - let handler = binder.bind(&map); + let handler = binder.add(&map); (binder.into_binding(), handler) }; diff --git a/examples/triangle/src/lib.rs b/examples/triangle/src/lib.rs index bde4351..449ca2a 100644 --- a/examples/triangle/src/lib.rs +++ b/examples/triangle/src/lib.rs @@ -32,7 +32,7 @@ pub async fn run(ws: dunge::window::WindowState) -> Result<(), Error> { let bind = { let offset = Offset(&uniform); let mut binder = cx.make_binder(&shader); - binder.bind(&offset); + binder.add(&offset); binder.into_binding() }; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4d08638..147a4db 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -179,10 +179,10 @@ fn serve(Opts { module, .. }: Opts) -> Result<(), Error> { let html = index.render()?.leak(); let prefix = "xtask/web"; let strip = |s: &'static str| -> &'static str { s.strip_prefix(prefix).expect("strip") }; - let js_path = format!("{prefix}/{module}/wasm.js").leak(); - let wasm_path = format!("{prefix}/{module}/wasm_bg.wasm").leak(); - let js = fs::read_to_string(&js_path)?.leak(); - let wasm = fs::read(&wasm_path)?.leak(); + let js_path: &str = format!("{prefix}/{module}/wasm.js").leak(); + let wasm_path: &str = format!("{prefix}/{module}/wasm_bg.wasm").leak(); + let js = fs::read_to_string(js_path)?.leak(); + let wasm = fs::read(wasm_path)?.leak(); let routes = &[ ("/", Page::html(html)), ("/favicon.ico", Page::html("")),