Skip to content

Commit

Permalink
refactor: offscreen renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
strasdat committed Jun 29, 2024
1 parent e2b4608 commit 2a7d36a
Show file tree
Hide file tree
Showing 33 changed files with 638 additions and 714 deletions.
22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ include = [
]
keywords = ["robotics", "optimization"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/farm-ng/sophus-rs/"
version = "0.7.0"
repository = "https://github.com/sophus-vision/sophus-rs/"
version = "0.8.0"

[workspace.dependencies]
sophus = {path = "crates/sophus", version = "0.7.0"}
sophus_core = {path = "crates/sophus_core", version = "0.7.0"}
sophus_image = {path = "crates/sophus_image", version = "0.7.0"}
sophus_lie = {path = "crates/sophus_lie", version = "0.7.0"}
sophus_opt = {path = "crates/sophus_opt", version = "0.7.0"}
sophus_pyo3 = {path = "crates/sophus_pyo3", version = "0.7.0"}
sophus_sensor = {path = "crates/sophus_sensor", version = "0.7.0"}
sophus_viewer = {path = "crates/sophus_viewer", version = "0.7.0"}
sophus = {path = "crates/sophus", version = "0.8.0"}
sophus_core = {path = "crates/sophus_core", version = "0.8.0"}
sophus_image = {path = "crates/sophus_image", version = "0.8.0"}
sophus_lie = {path = "crates/sophus_lie", version = "0.8.0"}
sophus_opt = {path = "crates/sophus_opt", version = "0.8.0"}
sophus_pyo3 = {path = "crates/sophus_pyo3", version = "0.8.0"}
sophus_sensor = {path = "crates/sophus_sensor", version = "0.8.0"}
sophus_viewer = {path = "crates/sophus_viewer", version = "0.8.0"}

approx = "0.5"
as-any = "0.3"
Expand All @@ -45,7 +45,7 @@ eframe = {version = "0.27", features = ["wgpu"]}
egui_extras = "0.27"
env_logger = "0.11"
faer = "0.19"
hollywood = {version = "0.7.0"}
hollywood = {version = "0.8.0"}
image = {version = "0.25", features = [
"jpeg",
"png",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sophus-rs builds on stable.

```toml
[dependencies]
sophus = "0.7.0"
sophus = "0.8.0"
```

To allow for batch types, such as BatchScalarF64, the 'simd' feature is required. This feature
Expand All @@ -38,5 +38,5 @@ are no plans to rely on any other nightly features.

```toml
[dependencies]
sophus = { version = "0.7.0", features = ["simd"] }
sophus = { version = "0.8.0", features = ["simd"] }
```
2 changes: 1 addition & 1 deletion crates/sophus/examples/pose_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sophus_lie::Isometry3;
use sophus_sensor::camera_enum::perspective_camera::PerspectiveCameraEnum;
use sophus_sensor::dyn_camera::DynCamera;
use sophus_sensor::KannalaBrandtCamera;
use sophus_viewer::interactions::WgpuClippingPlanes;
use sophus_viewer::views::interactions::WgpuClippingPlanes;
use sophus_viewer::simple_viewer::SimpleViewer;

use crate::color::Color;
Expand Down
2 changes: 1 addition & 1 deletion crates/sophus/examples/viewer_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use sophus_image::mut_image_view::IsMutImageView;
use sophus_lie::traits::IsTranslationProductGroup;
use sophus_lie::Isometry3;
use sophus_sensor::DynCamera;
use sophus_viewer::interactions::WgpuClippingPlanes;
use sophus_viewer::views::interactions::WgpuClippingPlanes;
use sophus_viewer::renderables::color::Color;
use sophus_viewer::renderables::renderable2d::Points2;
use sophus_viewer::renderables::renderable2d::Renderable2d;
Expand Down
2 changes: 1 addition & 1 deletion crates/sophus_viewer/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use sophus_lie::traits::IsTranslationProductGroup;
use sophus_lie::Isometry3;
use sophus_sensor::dyn_camera::DynCamera;

use crate::interactions::WgpuClippingPlanes;
use crate::renderables::Packets;
use crate::views::interactions::WgpuClippingPlanes;
use crate::ViewerRenderState;

/// Viewer camera configuration.
Expand Down
8 changes: 1 addition & 7 deletions crates/sophus_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
/// The actor for the viewer.
pub mod actor;
/// Interactions
pub mod interactions;
/// The offscreen texture for rendering.
pub mod offscreen;
/// The pixel renderer for 2D rendering.
pub mod pixel_renderer;
pub mod offscreen_renderer;
/// The renderable structs.
pub mod renderables;
/// The scene renderer for 3D rendering.
pub mod scene_renderer;
/// The simple viewer.
pub mod simple_viewer;
/// The view struct.
Expand Down
11 changes: 11 additions & 0 deletions crates/sophus_viewer/src/offscreen_renderer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/// offscreen texture for rendering
pub mod textures;

/// Renderer for offscreen rendering
pub mod renderer;

/// The pixel renderer for 2D rendering.
pub mod pixel_renderer;

/// The scene renderer for 3D rendering.
pub mod scene_renderer;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use std::num::NonZeroU64;
use wgpu::util::DeviceExt;
use wgpu::DepthStencilState;

use crate::interactions::InteractionEnum;
use crate::offscreen::ZBufferTexture;
use crate::pixel_renderer::line::PixelLineRenderer;
use crate::pixel_renderer::pixel_point::PixelPointRenderer;
use crate::offscreen_renderer::pixel_renderer::line::PixelLineRenderer;
use crate::offscreen_renderer::pixel_renderer::pixel_point::PixelPointRenderer;
use crate::offscreen_renderer::textures::ZBufferTexture;
use crate::views::interactions::inplane_interaction::InplaneInteraction;
use crate::views::interactions::orbit_interaction::OrbitalInteraction;
use crate::ViewerRenderState;

/// Renderer for pixel data
Expand Down Expand Up @@ -120,72 +121,73 @@ impl PixelRenderer {
}
}

pub(crate) fn show_interaction_marker(
pub(crate) fn show_interaction_marker0(
&self,
state: &ViewerRenderState,
interaction_state: &InteractionEnum,
orbital_interaction: &OrbitalInteraction,
) {
match interaction_state {
InteractionEnum::OrbitalInteraction(orbital_interaction) => {
if let Some(scene_focus) = orbital_interaction.maybe_scene_focus {
*self.point_renderer.show_interaction_marker.lock().unwrap() =
if orbital_interaction.maybe_pointer_state.is_some()
|| orbital_interaction.maybe_scroll_state.is_some()
{
let mut vertex_data = vec![];

for _i in 0..6 {
vertex_data.push(PointVertex2 {
_pos: [
scene_focus.uv_in_virtual_camera[0] as f32,
scene_focus.uv_in_virtual_camera[1] as f32,
],
_color: [0.5, 0.5, 0.5, 1.0],
_point_size: 5.0,
});
}
state.queue.write_buffer(
&self.point_renderer.interaction_vertex_buffer,
0,
bytemuck::cast_slice(&vertex_data),
);

true
} else {
false
};
}
}
InteractionEnum::InplaneInteraction(inplane_interaction) => {
if let Some(scene_focus) = inplane_interaction.maybe_scene_focus {
*self.point_renderer.show_interaction_marker.lock().unwrap() =
if inplane_interaction.maybe_pointer_state.is_some()
|| inplane_interaction.maybe_scroll_state.is_some()
{
let mut vertex_data = vec![];

for _i in 0..6 {
vertex_data.push(PointVertex2 {
_pos: [
scene_focus.uv_in_virtual_camera[0] as f32,
scene_focus.uv_in_virtual_camera[1] as f32,
],
_color: [0.5, 0.5, 0.5, 1.0],
_point_size: 5.0,
});
}
state.queue.write_buffer(
&self.point_renderer.interaction_vertex_buffer,
0,
bytemuck::cast_slice(&vertex_data),
);

true
} else {
false
};
}
}
if let Some(scene_focus) = orbital_interaction.maybe_scene_focus {
*self.point_renderer.show_interaction_marker.lock().unwrap() =
if orbital_interaction.maybe_pointer_state.is_some()
|| orbital_interaction.maybe_scroll_state.is_some()
{
let mut vertex_data = vec![];

for _i in 0..6 {
vertex_data.push(PointVertex2 {
_pos: [
scene_focus.uv_in_virtual_camera[0] as f32,
scene_focus.uv_in_virtual_camera[1] as f32,
],
_color: [0.5, 0.5, 0.5, 1.0],
_point_size: 5.0,
});
}
state.queue.write_buffer(
&self.point_renderer.interaction_vertex_buffer,
0,
bytemuck::cast_slice(&vertex_data),
);

true
} else {
false
};
}
}

pub(crate) fn show_interaction_marker1(
&self,
state: &ViewerRenderState,
inplane_interaction: &InplaneInteraction,
) {
if let Some(scene_focus) = inplane_interaction.maybe_scene_focus {
*self.point_renderer.show_interaction_marker.lock().unwrap() =
if inplane_interaction.maybe_pointer_state.is_some()
|| inplane_interaction.maybe_scroll_state.is_some()
{
let mut vertex_data = vec![];

for _i in 0..6 {
vertex_data.push(PointVertex2 {
_pos: [
scene_focus.uv_in_virtual_camera[0] as f32,
scene_focus.uv_in_virtual_camera[1] as f32,
],
_color: [0.5, 0.5, 0.5, 1.0],
_point_size: 5.0,
});
}
state.queue.write_buffer(
&self.point_renderer.interaction_vertex_buffer,
0,
bytemuck::cast_slice(&vertex_data),
);

true
} else {
false
};
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use eframe::egui_wgpu::wgpu::util::DeviceExt;
use nalgebra::SVector;
use wgpu::DepthStencilState;

use crate::pixel_renderer::LineVertex2;
use crate::offscreen_renderer::pixel_renderer::LineVertex2;
use crate::renderables::renderable2d::Line2;
use crate::ViewerRenderState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Mutex;
use eframe::egui_wgpu::wgpu::util::DeviceExt;
use wgpu::DepthStencilState;

use crate::pixel_renderer::PointVertex2;
use crate::offscreen_renderer::pixel_renderer::PointVertex2;
use crate::renderables::renderable2d::Point2;
use crate::ViewerRenderState;

Expand Down
Loading

0 comments on commit 2a7d36a

Please sign in to comment.