Skip to content

Commit f7524cf

Browse files
committed
work on docs and the manual
1 parent a5f0608 commit f7524cf

56 files changed

Lines changed: 1122 additions & 177 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 13 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[workspace]
22
members = [
3-
"crates/example",
4-
"crates/example-culling",
5-
"crates/example-wasm",
3+
# "crates/example",
4+
"crates/examples",
5+
#"crates/example-culling",
6+
#"crates/example-wasm",
67
"crates/loading-bytes",
78
"crates/renderling",
89
"crates/renderling-build",
@@ -50,8 +51,8 @@ serde_json = "1.0.117"
5051
send_wrapper = "0.6.0"
5152
similarity = "0.2.0"
5253
snafu = "0.8"
53-
spirv-std = { git = "https://github.com/LegNeato/rust-gpu.git", rev = "425328a" }
54-
spirv-std-macros = { git = "https://github.com/LegNeato/rust-gpu.git", rev = "425328a" }
54+
spirv-std = { git = "https://github.com/rust-gpu/rust-gpu.git", rev = "425328a" }
55+
spirv-std-macros = { git = "https://github.com/rust-gpu/rust-gpu.git", rev = "425328a" }
5556
syn = { version = "2.0.49", features = ["full", "extra-traits", "parsing"] }
5657
tokio = "1.47.1"
5758
tracing = "0.1.41"
@@ -74,6 +75,4 @@ opt-level = 3
7475
opt-level = 3
7576

7677
[patch.crates-io]
77-
spirv-std = { git = "https://github.com/LegNeato/rust-gpu.git", rev = "425328a" }
78-
crabslab = { path = "../crabslab/crates/crabslab" }
79-
craballoc = { path = "../crabslab/crates/craballoc" }
78+
spirv-std = { git = "https://github.com/rust-gpu/rust-gpu.git", rev = "425328a" }

crates/example/src/camera.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Camera control.
22
use std::str::FromStr;
33

4-
use renderling::bvol::Aabb;
5-
use renderling::camera::Camera;
6-
use renderling::prelude::glam::{Mat4, Quat, UVec2, Vec2, Vec3};
4+
use renderling::{
5+
bvol::Aabb,
6+
camera::Camera,
7+
glam::{Mat4, Quat, UVec2, Vec2, Vec3},
8+
};
79
use winit::{event::KeyEvent, keyboard::Key};
810

911
const RADIUS_SCROLL_DAMPENING: f32 = 0.001;
@@ -183,12 +185,8 @@ impl CameraController for WasdMouseCameraController {
183185
}
184186

185187
fn update_camera(&self, UVec2 { x: w, y: h }: UVec2, camera: &Camera) {
186-
let camera_rotation = Quat::from_euler(
187-
renderling::prelude::glam::EulerRot::XYZ,
188-
self.phi,
189-
self.theta,
190-
0.0,
191-
);
188+
let camera_rotation =
189+
Quat::from_euler(renderling::glam::EulerRot::XYZ, self.phi, self.theta, 0.0);
192190
let projection =
193191
Mat4::perspective_infinite_rh(std::f32::consts::FRAC_PI_4, w as f32 / h as f32, 0.01);
194192
let view = Mat4::from_quat(camera_rotation) * Mat4::from_translation(-self.position);

crates/example/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ use renderling::{
1010
atlas::AtlasImage,
1111
bvol::{Aabb, BoundingSphere},
1212
camera::Camera,
13+
context::Context,
1314
geometry::Vertex,
15+
glam,
1416
gltf::{Animator, GltfDocument},
1517
light::AnalyticalLight,
16-
prelude::*,
1718
primitive::Primitive,
1819
skybox::Skybox,
1920
stage::Stage,
2021
ui::{FontArc, Section, Text, Ui, UiPath, UiText},
21-
Context,
2222
};
2323

2424
pub mod camera;

crates/example/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::sync::Arc;
44
use clap::Parser;
55
use example::{camera::CameraControl, App};
66
use renderling::{
7-
prelude::glam::{UVec2, Vec2},
8-
Context,
7+
context::Context,
8+
glam::{UVec2, Vec2},
99
};
1010
use winit::{application::ApplicationHandler, event::WindowEvent, window::WindowAttributes};
1111

crates/example/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::sync::Arc;
44

5-
use renderling::Context;
5+
use renderling::context::Context;
66
use winit::monitor::MonitorHandle;
77

88
pub trait TestAppHandler: winit::application::ApplicationHandler {

crates/examples/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "examples"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
doc-comment = "0.3"
8+
futures-lite.workspace = true
9+
renderling = { path = "../renderling" }
10+
tokio = { workspace = true, features = ["full"] }

crates/examples/src/context.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Context manual page.
2+
3+
#[tokio::test]
4+
async fn context_page() {
5+
// ANCHOR: create
6+
use renderling::context::Context;
7+
8+
let ctx = Context::headless(256, 256).await;
9+
// ANCHOR_END: create
10+
11+
// ANCHOR: frame
12+
let frame = ctx.get_next_frame().unwrap();
13+
// ...do some rendering
14+
//
15+
// Then capture the frame into an image, if you like
16+
let _image_capture = frame.read_image().await.unwrap();
17+
frame.present();
18+
// ANCHOR_END: frame
19+
}

crates/examples/src/gltf.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//! GLTF manual page.
2+
3+
use crate::workspace_dir;
4+
5+
#[tokio::test]
6+
async fn manual_gltf() {
7+
// ANCHOR: setup
8+
use renderling::{
9+
camera::Camera,
10+
context::Context,
11+
glam::Vec4,
12+
glam::{Mat4, Vec3},
13+
stage::Stage,
14+
};
15+
16+
let ctx = Context::headless(256, 256).await;
17+
let stage: Stage = ctx
18+
.new_stage()
19+
.with_background_color(Vec4::new(0.5, 0.5, 0.5, 1.0));
20+
21+
let _camera: Camera = {
22+
let aspect = 1.0;
23+
let fovy = core::f32::consts::PI / 4.0;
24+
let znear = 0.1;
25+
let zfar = 1000.0;
26+
let projection = Mat4::perspective_rh(fovy, aspect, znear, zfar);
27+
let y = 50.0;
28+
let eye = Vec3::new(120.0, y, 120.0);
29+
let target = Vec3::new(0.0, y, 0.0);
30+
let up = Vec3::Y;
31+
let view = Mat4::look_at_rh(eye, target, up);
32+
33+
stage
34+
.new_camera()
35+
.with_projection_and_view(projection, view)
36+
};
37+
// ANCHOR_END: setup
38+
39+
// ANCHOR: load
40+
use renderling::{gltf::GltfDocument, types::GpuOnlyArray};
41+
let _model: GltfDocument<GpuOnlyArray> = stage
42+
.load_gltf_document_from_path(workspace_dir().join("gltf/Fox.glb"))
43+
.unwrap()
44+
.into_gpu_only();
45+
// ANCHOR_END: load
46+
47+
super::cwd_to_manual_assets_dir();
48+
49+
// ANCHOR: render_1
50+
let frame = ctx.get_next_frame().unwrap();
51+
stage.render(&frame.view());
52+
let img = frame.read_image().await.unwrap();
53+
img.save("gltf-example-shadow.png").unwrap();
54+
frame.present();
55+
// ANCHOR_END: render_1
56+
57+
// ANCHOR: no_lights
58+
stage.set_has_lighting(false);
59+
// ANCHOR_END: no_lights
60+
61+
let frame = ctx.get_next_frame().unwrap();
62+
stage.render(&frame.view());
63+
let img = frame.read_image().await.unwrap();
64+
img.save("gltf-example-unlit.png").unwrap();
65+
frame.present();
66+
}

crates/examples/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! # Examples for the manual
2+
//!
3+
//! This crate contains examples and snippets that get pulled into the manual
4+
//! via mdbook links. It also contains tests.
5+
6+
#[cfg(test)]
7+
mod context;
8+
9+
#[cfg(test)]
10+
mod stage;
11+
12+
#[cfg(test)]
13+
mod gltf;
14+
15+
#[cfg(test)]
16+
mod skybox;
17+
18+
pub fn cwd_to_manual_assets_dir() -> std::path::PathBuf {
19+
let current_dir =
20+
std::path::PathBuf::from(std::env!("CARGO_WORKSPACE_DIR")).join("manual/src/assets");
21+
let current_dir = current_dir.canonicalize().unwrap();
22+
std::env::set_current_dir(&current_dir).unwrap();
23+
println!("current dir: {:?}", std::env::current_dir());
24+
current_dir
25+
}
26+
27+
pub fn workspace_dir() -> std::path::PathBuf {
28+
let current_dir = std::path::PathBuf::from(std::env!("CARGO_WORKSPACE_DIR"));
29+
current_dir.canonicalize().unwrap()
30+
}
31+
32+
pub fn cwd_to_cargo_workspace() -> std::path::PathBuf {
33+
let current_dir = workspace_dir();
34+
std::env::set_current_dir(&current_dir).unwrap();
35+
println!("current dir: {:?}", std::env::current_dir());
36+
current_dir
37+
}
38+
39+
doc_comment::doctest!("../../../manual/src/stage.md", stage_md);
40+
41+
#[test]
42+
fn can_test() {
43+
assert_eq!(1, 1);
44+
}

0 commit comments

Comments
 (0)