Skip to content

Commit f4d39e5

Browse files
committed
Merge branch 'underwater' into for_v2.11
2 parents 234ae43 + bc48fbc commit f4d39e5

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

include/luxrays/utils/observer_ptr.h

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ class observer_ptr {
6161
"Template parameter T cannot be void"
6262
);
6363
public:
64-
using element_type = std::remove_extent_t<T>;
64+
using element_type = std::remove_extent_t<T>;
6565

6666
// Default constructor: initialize to nullptr
6767
constexpr observer_ptr() noexcept : ptr(nullptr) {}
6868
constexpr observer_ptr(std::nullptr_t) noexcept : ptr(nullptr) {}
6969

7070
// Constructor from raw pointer (implicit conversions allowed)
71-
constexpr observer_ptr(T* p) noexcept : ptr(p) {}
71+
constexpr explicit observer_ptr(T* p) noexcept : ptr(p) {}
7272

7373
// Copy constructor and assignment
7474
constexpr observer_ptr(const observer_ptr&) noexcept = default;
@@ -160,39 +160,47 @@ class observer_ptr {
160160

161161
// Free function for dynamic casting observer_ptr<B> to observer_ptr<A>
162162
template<class T, class U>
163-
observer_ptr<T> dynamic_observer_cast(const observer_ptr<U>& r) noexcept
163+
inline observer_ptr<T>
164+
dynamic_observer_cast(const observer_ptr<U>& r) noexcept
164165
{
165-
if (auto p = dynamic_cast<typename observer_ptr<T>::element_type*>(r.get()))
166-
return observer_ptr<T>(r);
167-
else
168-
return observer_ptr<T>{nullptr};
166+
auto* p = dynamic_cast<typename observer_ptr<T>::element_type*>(r.get());
167+
168+
if (p) return observer_ptr<T>(p);
169+
170+
return observer_ptr<T>{nullptr};
169171
}
170172

171173
template<class T, class U>
172-
observer_ptr<const T> dynamic_observer_cast(const observer_ptr<const U>& r) noexcept
174+
inline observer_ptr<const T>
175+
dynamic_observer_cast(const observer_ptr<const U>& r) noexcept
173176
{
174-
if (auto p = dynamic_cast<const typename observer_ptr<const T>::element_type*>(r.get()))
175-
return observer_ptr<const T>(p);
176-
else
177-
return observer_ptr<const T>{nullptr};
178-
}
177+
const auto* p = dynamic_cast<const typename observer_ptr<const T>::element_type*>(r.get());
178+
179+
if (p) return observer_ptr<const T>(p);
180+
181+
return observer_ptr<const T>{nullptr};
182+
}
179183

180184
template<class T, class U>
181-
observer_ptr<T> static_observer_cast(const observer_ptr<U>& r) noexcept
185+
inline observer_ptr<T>
186+
static_observer_cast(const observer_ptr<U>& r) noexcept
182187
{
183-
if (auto p = static_cast<typename observer_ptr<T>::element_type*>(r.get()))
184-
return observer_ptr<T>(r);
185-
else
186-
return observer_ptr<T>{nullptr};
188+
auto* p = static_cast<typename observer_ptr<T>::element_type*>(r.get());
189+
190+
if (p) return observer_ptr<T>(p);
191+
192+
return observer_ptr<T>{nullptr};
187193
}
188194

189195
template<class T, class U>
190-
observer_ptr<const T> static_observer_cast(const observer_ptr<const U>& r) noexcept
196+
inline observer_ptr<const T>
197+
static_observer_cast(const observer_ptr<const U>& r) noexcept
191198
{
192-
if (auto p = static_cast<const typename observer_ptr<const T>::element_type*>(r.get()))
193-
return observer_ptr<const T>(p);
194-
else
195-
return observer_ptr<const T>{nullptr};
199+
const auto* p = static_cast<const typename observer_ptr<const T>::element_type*>(r.get());
200+
201+
if (p) return observer_ptr<const T>(p);
202+
203+
return observer_ptr<const T>{nullptr};
196204
}
197205

198206
// Non-member swap

include/slg/bsdf/bsdf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class BSDF {
117117
bool IsShadowCatcherOnlyInfiniteLights() const { return material->IsShadowCatcherOnlyInfiniteLights(); }
118118
bool IsCameraInvisible() const;
119119
bool IsVolume() const {
120-
auto ptr = dynamic_observer_cast<VolumeConstPtr>(material);
120+
auto ptr = dynamic_observer_cast<const Volume>(material);
121121
return bool(ptr);
122122
}
123123
bool IsPhotonGIEnabled() const { return material->IsPhotonGIEnabled(); }

include/slg/lights/lightsourcedefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LightSourceDefinitions {
7575

7676
LightSourceRef GetLightSource(size_t n) const { return lights[n]; }
7777
LightSourcePtr GetLightSourcePtr(size_t n) const {
78-
return std::addressof(lights[n].get());
78+
return LightSourcePtr(std::addressof(lights[n].get()));
7979
}
8080

8181
auto ViewEnvLightSources() {

src/slg/engines/pathocl/pathoclnativethread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ FilmPtr PathOCLNativeRenderThread::GetThreadFilmPtr() {
8989
auto * thread0 = static_cast<PathOCLNativeRenderThread *>(
9090
engine->renderNativeThreads[0]
9191
);
92-
return thread0->threadFilm.get();
92+
return FilmPtr(thread0->threadFilm.get());
9393
}
9494

9595
FilmRef PathOCLNativeRenderThread::GetThreadFilm() {

src/slg/engines/tilepathcpu/tilepathcputhread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void TilePathCPURenderThread::RenderFunc(std::stop_token stop_token) {
108108
// Render the tile
109109
//----------------------------------------------------------------------
110110

111-
sampler.Init(&tileWork, tileFilm.get());
111+
sampler.Init(&tileWork, FilmPtr(tileFilm.get()));
112112

113113
for (u_int y = 0; y < tileWork.GetCoord().height && !interruptionRequested; ++y) {
114114
for (u_int x = 0; x < tileWork.GetCoord().width && !interruptionRequested; ++x) {

src/slg/lights/lightsourcedefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ LightSourceConstPtr LightSourceDefinitions::GetLightSourcePtr(const string &name
101101
if (e == lightsByName.end())
102102
throw runtime_error("Reference to an undefined LightSource in LightSourceDefinitions::GetLightSource(): " + name);
103103

104-
return e->second.get();
104+
return LightSourceConstPtr(e->second.get());
105105
}
106106

107107
LightSourcePtr LightSourceDefinitions::GetLightSourcePtr(const string &name) {
@@ -111,7 +111,7 @@ LightSourcePtr LightSourceDefinitions::GetLightSourcePtr(const string &name) {
111111
if (e == lightsByName.end())
112112
throw runtime_error("Reference to an undefined LightSource in LightSourceDefinitions::GetLightSource(): " + name);
113113

114-
return e->second.get();
114+
return LightSourcePtr(e->second.get());
115115
}
116116

117117
TriangleLightConstRef LightSourceDefinitions::GetLightSourceByMeshAndTriIndex(const u_int meshIndex, const u_int triIndex) const {

src/slg/lights/strategies/distributionlightstrategy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ LightSourcePtr DistributionLightStrategy::SampleLights(
6060
assert ((lightIndex >= 0) && (lightIndex < scene.GetLightSources().GetSize()));
6161

6262
if (*pdf > 0.f)
63-
return &scene.GetLightSources().GetLightSource(lightIndex);
63+
return LightSourcePtr(&scene.GetLightSources().GetLightSource(lightIndex));
6464
else
6565
return nullptr;
6666
} else

0 commit comments

Comments
 (0)