Skip to content

Commit cab9faf

Browse files
committed
faster add objects
1 parent cb26909 commit cab9faf

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

RadeonRays/include/radeon_rays.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,14 @@ namespace RadeonRays
225225
// Create an instance of a shape with its own transform (set via Shape interface).
226226
// The call is blocking, so the returned value is ready upon return.
227227
virtual Shape* CreateInstance(Shape const* shape) const = 0;
228+
// *EDIT* Preallocate shape container
229+
virtual void AllocShapes(size_t const size) {}
228230
// Delete the shape (to simplify DLL boundary crossing
229231
virtual void DeleteShape(Shape const* shape) = 0;
230232
// Attach shape to participate in intersection process
231233
virtual void AttachShape(Shape const* shape) = 0;
234+
// *EDIT* Attach shape without error checking
235+
virtual void AttachShapeUnchecked(Shape const* shape) { AttachShape(shape); }
232236
// Detach shape, i.e. it is not going to be considered part of the scene anymore
233237
virtual void DetachShape(Shape const* shape) = 0;
234238
// Detach all objects

RadeonRays/src/api/radeon_rays_impl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ namespace RadeonRays
8787
return instance;
8888
}
8989

90+
void IntersectionApiImpl::AllocShapes(size_t const size)
91+
{
92+
world_.ReserveShapes(size);
93+
}
94+
9095
void IntersectionApiImpl::DeleteShape(Shape const* shape)
9196
{
9297
delete shape;
@@ -97,6 +102,11 @@ namespace RadeonRays
97102
world_.AttachShape(shape);
98103
}
99104

105+
void IntersectionApiImpl::AttachShapeUnchecked(Shape const* shape)
106+
{
107+
world_.AttachShapeUnchecked(shape);
108+
}
109+
100110
void IntersectionApiImpl::DetachShape(Shape const* shape)
101111
{
102112
world_.DetachShape(shape);

RadeonRays/src/api/radeon_rays_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ namespace RadeonRays
6565
// Create an instance of a shape with its own transform (set via Shape interface).
6666
// The call is blocking, so the returned value is ready upon return.
6767
Shape* CreateInstance(Shape const* shape) const override;
68+
// *EDIT* Preallocate shape container
69+
void AllocShapes(size_t const size) override;
6870
// Delete the shape (to simplify DLL boundary crossing
6971
void DeleteShape(Shape const* shape) override;
7072
// Attach shape to participate in intersection process
7173
void AttachShape(Shape const* shape) override;
74+
// *EDIT* Attach shape without error checking
75+
void AttachShapeUnchecked(Shape const* shape) override;
7276
// Detach shape, i.e. it is not going to be considered part of the scene anymore
7377
void DetachShape(Shape const* shape) override;
7478
// Detach all objects

RadeonRays/src/world/world.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ THE SOFTWARE.
2525

2626
namespace RadeonRays
2727
{
28+
void World::ReserveShapes(size_t const size)
29+
{
30+
shapes_.reserve(size);
31+
}
32+
2833
void World::AttachShape(Shape const* shape)
2934
{
3035
if (std::find(shapes_.cbegin(), shapes_.cend(), shape) == shapes_.cend())
@@ -34,6 +39,12 @@ namespace RadeonRays
3439
}
3540
}
3641

42+
void World::AttachShapeUnchecked(Shape const* shape)
43+
{
44+
shapes_.push_back(shape);
45+
has_changed_ = true;
46+
}
47+
3748
void World::DetachShape(Shape const* shape)
3849
{
3950
auto iter = std::find(shapes_.begin(), shapes_.end(), shape);

RadeonRays/src/world/world.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ namespace RadeonRays
4242
World() = default;
4343
//
4444
virtual ~World() = default;
45+
// *EDIT* Preallocate the shapes container
46+
void ReserveShapes(size_t const size);
4547
// Attach the shape updating all the flags
4648
void AttachShape(Shape const* shape);
49+
// *EDIT* Attach the shape updating all the flags, without checking if shape already exists.
50+
void AttachShapeUnchecked(Shape const* shape);
4751
// Detach the shape
4852
void DetachShape(Shape const* shape);
4953
// Detach all

0 commit comments

Comments
 (0)