Skip to content

Commit

Permalink
Move re_renderer examples to its own crate in order to make workspace…
Browse files Browse the repository at this point in the history
… level examples less confusing (#4472)

### What

This way we don't show renderer examples like "the examples". Also, due
to some dependency issues with the optional re_renderer arrow dependency
(details somewhat unclear..), we were previously no longer able to run
examples on the web. This works nicely now again:

<img width="1953" alt="image"
src="https://github.com/rerun-io/rerun/assets/1220815/87b4c2be-2080-44f2-b319-a222c49315b7">

depicted:
* `cargo run -p re_renderer_examples --bin multiview` (native)
* `cargo run-wasm -p re_renderer_examples --bin multiview --features
"webgl"` (webgl, using firefox here)
* `cargo run-wasm -p re_renderer_examples --bin multiview` (webgpu,
using chrome here)


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
  * Full build: [app.rerun.io](https://app.rerun.io/pr/4472/index.html)
* Partial build:
[app.rerun.io](https://app.rerun.io/pr/4472/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
- Useful for quick testing when changes do not affect examples in any
way
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4472)
- [Docs
preview](https://rerun.io/preview/504ce9714e120af91374751e7ae86e70b195044c/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/504ce9714e120af91374751e7ae86e70b195044c/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
Wumpf authored Dec 12, 2023
1 parent a066b4d commit 11ebbef
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 79 deletions.
1 change: 1 addition & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Update instructions:
| rerun_c | Rerun C SDK |
| rerun_py | Rerun Python SDK |
| re_sdk | Rerun logging SDK |
<!-- | re_renderer_examples | Examples for re_renderer | -->


### Viewer crates
Expand Down
29 changes: 21 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 0 additions & 28 deletions crates/re_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,8 @@ wgpu-core.workspace = true

# For examples:
[dev-dependencies]
image = { workspace = true, default-features = false, features = ["png"] }
log.workspace = true
pollster.workspace = true
rand = { workspace = true, features = ["std", "std_rng"] }
web-time.workspace = true
winit.workspace = true
zip = { workspace = true, default-features = false, features = ["deflate"] }

# For tests:
unindent.workspace = true


[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] # native
async-executor.workspace = true

[target.'cfg(target_arch = "wasm32")'.dev-dependencies] # wasm
console_error_panic_hook.workspace = true
# required to make rand work on wasm, see https://github.com/rust-random/rand#wasm-support
getrandom = { workspace = true, features = ["js"] }
wasm-bindgen-futures.workspace = true
web-sys = { workspace = true, features = [
"Location",
"Blob",
"RequestInit",
"RequestMode",
"Request",
"Response",
] }


# For build.rs:
[build-dependencies]

Expand Down
11 changes: 0 additions & 11 deletions crates/re_renderer/examples/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion crates/re_renderer/src/file_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl<Fs: FileSystem> FileResolver<Fs> {
// TODO(cmc): might want an actual test using `RERUN_SHADER_PATH`
#[cfg(test)]
mod tests_file_resolver {
use crate::{FileSystem as _, MemFileSystem};
use crate::MemFileSystem;
use unindent::unindent;

use super::*;
Expand Down
35 changes: 18 additions & 17 deletions crates/re_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,30 @@ mod colormap;
mod context;
mod debug_label;
mod depth_offset;
mod draw_phases;
mod file_resolver;
mod file_server;
mod file_system;
mod global_bindings;
mod line_strip_builder;
mod point_cloud_builder;
mod queuable_draw_data;
mod rect;
mod size;
mod transform;
mod wgpu_buffer_types;
mod wgpu_resources;

#[cfg(not(all(not(target_arch = "wasm32"), debug_assertions)))] // wasm or release builds
#[rustfmt::skip] // it's auto-generated
mod workspace_shaders;

#[cfg(all(not(target_arch = "wasm32"), debug_assertions))] // native debug build
mod error_tracker;

// ---------------------------------------------------------------------------
// Exports

use allocator::GpuReadbackBuffer;
pub use allocator::GpuReadbackIdentifier;

Expand All @@ -50,38 +65,24 @@ pub use transform::RectTransform;
pub use view_builder::{AutoSizeConfig, ViewBuilder};
pub use wgpu_resources::WgpuResourcePoolStatistics;

mod draw_phases;
pub(crate) use draw_phases::DrawPhase;
use draw_phases::DrawPhase;
pub use draw_phases::{
OutlineConfig, OutlineMaskPreference, PickingLayerId, PickingLayerInstanceId,
PickingLayerObjectId, PickingLayerProcessor, ScreenshotProcessor,
};

mod file_system;
pub use self::file_system::{get_filesystem, FileSystem};
#[allow(unused_imports)] // they can be handy from time to time
pub(crate) use self::file_system::{MemFileSystem, OsFileSystem};
use self::file_system::{MemFileSystem, OsFileSystem};

mod file_resolver;
pub use self::file_resolver::{
new_recommended as new_recommended_file_resolver, FileResolver, ImportClause,
RecommendedFileResolver, SearchPath,
};

mod file_server;
pub use self::file_server::FileServer;

mod rect;

#[cfg(not(all(not(target_arch = "wasm32"), debug_assertions)))] // wasm or release builds
#[rustfmt::skip] // it's auto-generated
mod workspace_shaders;

#[cfg(all(not(target_arch = "wasm32"), debug_assertions))] // native debug build
mod error_tracker;

// Re-export used color types.
pub use ecolor::{Color32, Rgba};
pub use ecolor::{Color32, Hsva, Rgba};

// ---------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use ecolor::Hsva;
//! Examples for using 2D rendering.
//!
//! On the left is a 2D view, on the right a 3D view of the same scene.
use itertools::Itertools as _;
use re_renderer::Hsva;

use re_renderer::{
renderer::{
Expand All @@ -26,7 +30,7 @@ impl framework::Example for Render2D {

fn new(re_ctx: &re_renderer::RenderContext) -> Self {
let rerun_logo =
image::load_from_memory(include_bytes!("../../re_ui/data/logo_dark_mode.png")).unwrap();
image::load_from_memory(include_bytes!("../re_ui/data/logo_dark_mode.png")).unwrap();

let image_data = rerun_logo.as_rgba8().unwrap().to_vec();

Expand Down Expand Up @@ -303,7 +307,7 @@ impl framework::Example for Render2D {
view_builder.queue_draw(point_draw_data.clone());
view_builder.queue_draw(rectangle_draw_data.clone());
let command_buffer = view_builder
.draw(re_ctx, ecolor::Rgba::TRANSPARENT)
.draw(re_ctx, re_renderer::Rgba::TRANSPARENT)
.unwrap();
framework::ViewDrawResult {
view_builder,
Expand Down Expand Up @@ -345,7 +349,7 @@ impl framework::Example for Render2D {
.queue_draw(line_strip_draw_data)
.queue_draw(point_draw_data)
.queue_draw(rectangle_draw_data)
.draw(re_ctx, ecolor::Rgba::TRANSPARENT)
.draw(re_ctx, re_renderer::Rgba::TRANSPARENT)
.unwrap();
framework::ViewDrawResult {
view_builder,
Expand Down
68 changes: 68 additions & 0 deletions crates/re_renderer_examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = "re_renderer_examples"
description = "Examples for the re_renderer crate."
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish = false

[features]
webgl = ["re_renderer/webgl"]


[[bin]]
name = "2d"
path = "2d.rs"

[[bin]]
name = "depth_cloud"
path = "depth_cloud.rs"

[[bin]]
name = "depth_offset"
path = "depth_offset.rs"

[[bin]]
name = "multiview"
path = "multiview.rs"

[[bin]]
name = "outlines"
path = "outlines.rs"

[[bin]]
name = "picking"
path = "picking.rs"


[dependencies]
re_log.workspace = true
re_renderer = { workspace = true, features = ["import-obj", "import-gltf"] }

ahash.workspace = true
anyhow.workspace = true
bytemuck.workspace = true
glam.workspace = true
image = { workspace = true, default-features = false, features = ["png"] }
itertools.workspace = true
log.workspace = true
macaw.workspace = true
pollster.workspace = true
rand = { workspace = true, features = ["std", "std_rng"] }
web-time.workspace = true
wgpu.workspace = true
winit.workspace = true
zip = { workspace = true, default-features = false, features = ["deflate"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook.workspace = true
wasm-bindgen-futures.workspace = true
web-sys = { workspace = true, features = [
"Location",
"Blob",
"RequestInit",
"RequestMode",
"Request",
"Response",
] }
20 changes: 20 additions & 0 deletions crates/re_renderer_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Standalone examples for `re_renderer`
-----------------------------------------------

To get a list of all examples run:
```
cargo run -p re_renderer_examples --bin
```

E.g. to run the `multiview`` example run
```
cargo run -p re_renderer_examples --bin multiview
```
To run the same example on the web using WebGPU:
```
cargo run-wasm -p re_renderer_examples --bin multiview
```
To run the same example on the web using WebGL:
```
cargo run-wasm -p re_renderer_examples --bin multiview --features "webgl"
```
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl RenderDepthClouds {
.queue_draw(point_cloud_draw_data)
.queue_draw(frame_draw_data)
.queue_draw(image_draw_data)
.draw(re_ctx, ecolor::Rgba::TRANSPARENT)
.draw(re_ctx, re_renderer::Rgba::TRANSPARENT)
.unwrap();

framework::ViewDrawResult {
Expand Down Expand Up @@ -210,7 +210,7 @@ impl RenderDepthClouds {
.queue_draw(depth_cloud_draw_data)
.queue_draw(frame_draw_data)
.queue_draw(image_draw_data)
.draw(re_ctx, ecolor::Rgba::TRANSPARENT)
.draw(re_ctx, re_renderer::Rgba::TRANSPARENT)
.unwrap();

framework::ViewDrawResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! Press arrow up/down to increase/decrease the distance of the camera to the z==0 plane in tandem with the scale of the rectangles.
//! Press arrow left/right to increase/decrease the near plane distance.
use ecolor::Hsva;
use re_renderer::Hsva;
use re_renderer::{
renderer::{ColormappedTexture, RectangleDrawData, RectangleOptions, TexturedRect},
view_builder::{self, Projection, ViewBuilder},
Expand Down Expand Up @@ -115,7 +115,7 @@ impl framework::Example for Render2D {
);
let command_buffer = view_builder
.queue_draw(RectangleDrawData::new(re_ctx, &rectangles).unwrap())
.draw(re_ctx, ecolor::Rgba::TRANSPARENT)
.draw(re_ctx, re_renderer::Rgba::TRANSPARENT)
.unwrap();

vec![{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Example with several independent views, using various primitives.
use std::f32::consts::TAU;

use ecolor::Hsva;
use framework::Example;
use glam::Vec3;
use itertools::Itertools;
Expand All @@ -13,8 +14,8 @@ use re_renderer::{
TestTriangleDrawData,
},
view_builder::{OrthographicCameraMode, Projection, TargetConfiguration, ViewBuilder},
Color32, GpuReadbackIdentifier, LineStripSeriesBuilder, PointCloudBuilder, RenderContext, Rgba,
ScreenshotProcessor, Size,
Color32, GpuReadbackIdentifier, Hsva, LineStripSeriesBuilder, PointCloudBuilder, RenderContext,
Rgba, ScreenshotProcessor, Size,
};
use winit::event::{ElementState, VirtualKeyCode};

Expand Down
Loading

0 comments on commit 11ebbef

Please sign in to comment.