Skip to content

Commit 765f3c4

Browse files
author
Matt Kleinschafer
committed
More tidy up
1 parent 5174f58 commit 765f3c4

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

modules/graphics/src/rendering/culling.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ impl From<&Material> for MaterialSortingKey {
6767

6868
/// Represents an object that is visible to a camera, along with it's material
6969
/// properties that are used to render it.
70-
pub struct VisibleObject<'a, I> {
71-
/// The identifier of the object.
72-
pub identifier: I,
70+
pub struct VisibleObject<'a> {
71+
/// The object itself.
72+
pub object: &'a dyn RenderObject,
7373
/// The sorting key for the material of the object.
7474
pub material: &'a Material,
7575
}
@@ -79,16 +79,16 @@ pub struct VisibleObject<'a, I> {
7979
/// This is a subset of the objects in a scene that are visible to a specific
8080
/// camera, and can be used to optimize rendering by only rendering the objects
8181
/// that are visible to the camera.
82-
pub struct VisibleObjectSet<'a, I> {
82+
pub struct VisibleObjectSet<'a> {
8383
/// The frustum of the camera that was used to cull the objects.
8484
pub frustum: Frustum,
8585
/// The objects that are visible to the camera.
86-
pub objects: Vec<VisibleObject<'a, I>>,
86+
pub objects: Vec<VisibleObject<'a>>,
8787
}
8888

89-
impl<'a, I> VisibleObjectSet<'a, I> {
89+
impl<'a> VisibleObjectSet<'a> {
9090
/// Gets an iterator over the objects in the set.
91-
pub fn group_by_material(&self) -> impl Iterator<Item = (&'a Material, &[VisibleObject<'a, I>])> {
91+
pub fn group_by_material(&self) -> impl Iterator<Item = (&'a Material, &[VisibleObject<'a>])> {
9292
self
9393
.objects
9494
.chunk_by(|a, b| MaterialSortingKey::from(a.material) == MaterialSortingKey::from(b.material))

modules/graphics/src/rendering/pipelines.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ impl<'a> RenderFrame<'a> {
1919
for (material, group) in visible_object_set.group_by_material() {
2020
self.queue.set_material(material);
2121

22-
for object in group {
23-
let render_object = scene.get_object(object.identifier).unwrap();
24-
25-
render_object.render(self);
22+
for entry in group {
23+
entry.object.render(self)
2624
}
2725
}
2826
}
@@ -33,11 +31,8 @@ pub trait RenderScene {
3331
/// Gets the cameras that should be used to render this scene.
3432
fn cameras(&self) -> Vec<&dyn Camera>;
3533

36-
/// Gets the object with the given identifier.
37-
fn get_object(&self, identifier: u64) -> Option<&dyn RenderObject>;
38-
3934
/// Gets the objects that should be rendered by the given camera.
40-
fn cull_visible_objects(&self, camera: &dyn Camera) -> VisibleObjectSet<u64>;
35+
fn cull_visible_objects(&self, camera: &dyn Camera) -> VisibleObjectSet;
4136
}
4237

4338
/// Represents an object capable of being rendered.

modules/scene/src/graph/rendering.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Rendering support for scene graphs
22
3-
use graphics::{RenderFrame, RenderObject, RenderScene, VisibleObjectSet};
3+
use graphics::{RenderFrame, RenderObject, RenderScene, VisibleObject, VisibleObjectSet};
44

55
use super::*;
66

@@ -10,7 +10,7 @@ impl<'a, T: Transform> RenderScene for SceneGraph<'a, T> {
1010
todo!()
1111
}
1212

13-
fn cull_visible_objects(&self, camera: &dyn Camera) -> VisibleObjectSet<u64> {
13+
fn cull_visible_objects(&self, camera: &dyn Camera) -> VisibleObjectSet<'a> {
1414
let frustum = camera.frustum();
1515
let objects = Vec::new();
1616

@@ -20,24 +20,13 @@ impl<'a, T: Transform> RenderScene for SceneGraph<'a, T> {
2020
return false;
2121
}
2222

23-
// TODO: fix this up
24-
// objects.push(VisibleObject {
25-
// material: todo!(),
26-
// identifier: node.id().into(),
27-
// });
23+
// TODO: push the object to the list
2824

2925
true
3026
});
3127

3228
VisibleObjectSet { frustum, objects }
3329
}
34-
35-
fn get_object(&self, identifier: u64) -> Option<&dyn RenderObject> {
36-
self
37-
.root
38-
.find_by_id(SceneNodeId::from(identifier))
39-
.map(|node| node as &dyn RenderObject)
40-
}
4130
}
4231

4332
impl<'a, T: Transform> Debug for SceneGraph<'a, T> {

0 commit comments

Comments
 (0)