Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoqsh committed Jan 12, 2024
1 parent a9aecc9 commit fa551f2
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 100 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings
RUST_BACKTRACE: full
MSRV: 1.71
MSRV: 1.75
RUSTDOCFLAGS: -Dwarnings
CACHE_SUFFIX: c
jobs:
Expand All @@ -18,9 +18,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --profile ci --verbose
run: cargo build --all-features --profile ci --verbose
- name: Clippy
run: cargo clippy --profile ci
run: cargo clippy --all-features --profile ci
- name: Install vulkan
run: |
set -e
Expand Down
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@ members = [
"helpers",
]

[workspace.package]
version = "0.3.0-alpha"
edition = "2021"
license = "MIT"
authors = ["nanoqsh"]
keywords = ["graphics", "wgpu"]
documentation = "https://docs.rs/dunge"
readme = "../README.md"
repository = "https://github.com/nanoqsh/dunge"
rust-version = "1.75"

[workspace.dependencies]
dunge = { version = "=0.3.0-alpha", path = "dunge" }
dunge_macros = { version = "=0.3.0-alpha", path = "dunge_macros" }
dunge_shader = { version = "=0.3.0-alpha", path = "dunge_shader" }
dunge_tools = { version = "=0.3.0-alpha", path = "dunge_tools" }
bytemuck = "1.13"
glam = "0.25"
log = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Shader code described as a single rust function
* High degree of typesafety with minimal runtime checks
* Desktop, WASM and Android support
* Built-in and optional window and event loop creation
* Optional built-in window and event loop

## Application area
Currently the library is for personal use only. Although, over time I plan to stabilize API so that someone could use it for their tasks.
Expand All @@ -29,7 +29,7 @@ Currently the library is for personal use only. Although, over time I plan to st
For more examples using the window, see the [examples](https://github.com/nanoqsh/dunge/tree/main/examples) directory.
To build and run an example do:
```sh
cargo r -p <example_name>
cargo run -p <example_name>
```

Also see the [test](https://github.com/nanoqsh/dunge/tree/main/dunge/tests) directory for small examples of creation a single image.
29 changes: 19 additions & 10 deletions dunge/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
[package]
name = "dunge"
version = "0.3.0-alpha"
edition = "2021"
description = "Simple and portable 3d render library"
license = "MIT"
keywords = ["graphics", "wgpu"]
documentation = "https://docs.rs/dunge"
readme = "../README.md"
repository = "https://github.com/nanoqsh/dunge"
rust-version = "1.71"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
keywords = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }

[dependencies]
dunge_macros = { version = "=0.3.0-alpha", path = "../dunge_macros" }
dunge_shader = { version = "=0.3.0-alpha", path = "../dunge_shader" }
dunge_macros = { workspace = true }
dunge_shader = { workspace = true }
bytemuck = { workspace = true }
glam = { workspace = true }
instant = { version = "0.1", optional = true }
Expand Down Expand Up @@ -47,3 +48,11 @@ winit = ["dep:instant", "dep:winit"]

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
"wasm32-unknown-unknown",
]
6 changes: 3 additions & 3 deletions dunge/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'s, 'p, V> BoundLayer<'s, 'p, V> {
}

pub fn draw(&mut self, mesh: &'p Mesh<V>) {
mesh.draw(self.pass);
mesh.draw(self.pass, 1);
}
}

Expand All @@ -65,7 +65,7 @@ pub struct Layer<V> {
no_bindings: bool,
format: Format,
render: RenderPipeline,
vertex: PhantomData<V>,
vert: PhantomData<V>,
}

impl<V> Layer<V> {
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<V> Layer<V> {
no_bindings: shader.groups().is_empty(),
format,
render,
vertex: PhantomData,
vert: PhantomData,
}
}

Expand Down
6 changes: 3 additions & 3 deletions dunge/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ impl<V> Mesh<V> {
}
}

pub(crate) fn draw<'a>(&'a self, pass: &mut RenderPass<'a>) {
pub(crate) fn draw<'a>(&'a self, pass: &mut RenderPass<'a>, n: u32) {
use wgpu::IndexFormat;

pass.set_vertex_buffer(0, self.verts.slice(..));
match &self.indxs {
Some(indxs) => {
pass.set_index_buffer(indxs.slice(..), IndexFormat::Uint16);
let len = indxs.size() as u32 / mem::size_of::<u16>() as u32;
pass.draw_indexed(0..len, 0, 0..1);
pass.draw_indexed(0..len, 0, 0..n);
}
None => {
let len = self.verts.size() as u32 / mem::size_of::<V>() as u32;
pass.draw(0..len, 0..1);
pass.draw(0..len, 0..n);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions dunge/tests/triangle_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
format::Format,
group::BoundTexture,
mesh,
sl::{self, Groups, Input, Out},
sl::{self, Groups, InVertex, Out},
state::{Options, Render},
texture::{self, Filter, Sampler},
Group, Vertex,
Expand Down Expand Up @@ -36,7 +36,7 @@ fn render() -> Result<(), Error> {
sam: &'a Sampler,
}

let triangle = |vert: Input<Vert>, Groups(map): Groups<Map>| Out {
let triangle = |vert: InVertex<Vert>, Groups(map): Groups<Map>| Out {
place: sl::concat(vert.pos, Vec2::new(0., 1.)),
color: sl::texture_sample(map.tex, map.sam, sl::fragment(vert.tex)),
};
Expand Down
4 changes: 2 additions & 2 deletions dunge/tests/triangle_vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
draw,
format::Format,
mesh,
sl::{self, Input, Out},
sl::{self, InVertex, Out},
state::{Options, Render},
texture, Vertex,
},
Expand All @@ -28,7 +28,7 @@ fn render() -> Result<(), Error> {
col: Vec3,
}

let triangle = |vert: Input<Vert>| Out {
let triangle = |vert: InVertex<Vert>| Out {
place: sl::concat(vert.pos, Vec2::new(0., 1.)),
color: sl::vec4_with(sl::fragment(vert.col), 1.),
};
Expand Down
14 changes: 9 additions & 5 deletions dunge_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[package]
name = "dunge_macros"
version = "0.3.0-alpha"
edition = "2021"
description = "Procmacro for the dunge library"
license = "MIT"
documentation = "https://docs.rs/dunge"
repository = "https://github.com/nanoqsh/dunge"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
keywords = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }

[lib]
proc-macro = true
Expand Down
14 changes: 9 additions & 5 deletions dunge_shader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[package]
name = "dunge_shader"
version = "0.3.0-alpha"
edition = "2021"
description = "Shader generator for the dunge library"
license = "MIT"
documentation = "https://docs.rs/dunge"
repository = "https://github.com/nanoqsh/dunge"
version = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
keywords = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }

[dependencies]
glam = { workspace = true }
Expand Down
25 changes: 17 additions & 8 deletions dunge_shader/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Context {
(id, out)
}

#[doc(hidden)]
pub fn groups(&self) -> impl Iterator<Item = GroupInfo> + '_ {
self.groups.iter().map(|entry| GroupInfo {
tyid: entry.tyid,
Expand All @@ -132,6 +133,7 @@ impl Context {
})
}

#[doc(hidden)]
pub fn inputs(&self) -> impl Iterator<Item = InputInfo> + '_ {
self.inputs
.iter()
Expand All @@ -140,27 +142,33 @@ impl Context {
}
}

pub trait FromContextTyped {
pub trait FromContextInput {
type Vertex;
fn from_context_typed(cx: &mut Context) -> Self;
type Instance;
fn from_context_input(cx: &mut Context) -> Self;
}

impl<V> FromContextTyped for V
impl<V> FromContextInput for V
where
V: FromContext,
{
type Vertex = ();
type Instance = ();

fn from_context_typed(cx: &mut Context) -> Self {
fn from_context_input(cx: &mut Context) -> Self {
V::from_context(cx)
}
}

pub struct Input<V>(V::Projection)
pub struct In<V, I>(pub V::Projection, pub I)
where
V: Vertex;

impl<V> ops::Deref for Input<V>
pub struct InVertex<V>(V::Projection)
where
V: Vertex;

impl<V> ops::Deref for InVertex<V>
where
V: Vertex,
{
Expand All @@ -171,13 +179,14 @@ where
}
}

impl<V> FromContextTyped for Input<V>
impl<V> FromContextInput for InVertex<V>
where
V: Vertex,
{
type Vertex = V;
type Instance = ();

fn from_context_typed(cx: &mut Context) -> Self {
fn from_context_input(cx: &mut Context) -> Self {
let id = cx.declare_input(V::DECL, mem::size_of::<V>());
Self(vertex::Projection::projection(id))
}
Expand Down
76 changes: 28 additions & 48 deletions dunge_shader/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
context::{Context, FromContext, FromContextTyped},
context::{Context, FromContext, FromContextInput},
eval::{self, Eval, Fs, Vs},
types,
};
Expand All @@ -22,56 +22,36 @@ where
}
}

impl<M, O, A> IntoModule<(A,)> for M
where
M: FnOnce(A) -> O,
O: Output,
A: FromContextTyped,
{
type Vertex = A::Vertex;

fn into_module(self) -> Module {
let mut cx = Context::new();
let a = A::from_context_typed(&mut cx);
eval::make(cx, self(a))
}
}

impl<M, O, A, B> IntoModule<(A, B)> for M
where
M: FnOnce(A, B) -> O,
O: Output,
A: FromContextTyped,
B: FromContext,
{
type Vertex = A::Vertex;
macro_rules! impl_into_module {
(A $(,)? $($t:ident),*) => {
impl<M, O, A, $($t),*> IntoModule<(A, $($t),*)> for M
where
M: FnOnce(A, $($t),*) -> O,
O: Output,
A: FromContextInput,
$(
$t: FromContext,
)*
{
type Vertex = A::Vertex;

fn into_module(self) -> Module {
let mut cx = Context::new();
let a = A::from_context_typed(&mut cx);
let b = B::from_context(&mut cx);
eval::make(cx, self(a, b))
}
#[allow(non_snake_case)]
fn into_module(self) -> Module {
let mut cx = Context::new();
let a = A::from_context_input(&mut cx);
$(
let $t = $t::from_context(&mut cx);
)*
eval::make(cx, self(a, $($t),*))
}
}
};
}

impl<M, O, A, B, C> IntoModule<(A, B, C)> for M
where
M: FnOnce(A, B, C) -> O,
O: Output,
A: FromContextTyped,
B: FromContext,
C: FromContext,
{
type Vertex = A::Vertex;

fn into_module(self) -> Module {
let mut cx = Context::new();
let a = A::from_context_typed(&mut cx);
let b = B::from_context(&mut cx);
let c = C::from_context(&mut cx);
eval::make(cx, self(a, b, c))
}
}
impl_into_module!(A);
impl_into_module!(A, B);
impl_into_module!(A, B, C);
impl_into_module!(A, B, C, D);

pub struct Out<P, C>
where
Expand Down
Loading

0 comments on commit fa551f2

Please sign in to comment.