Skip to content

Commit

Permalink
update and use unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren committed Mar 9, 2024
1 parent ad0bfe3 commit a0714d5
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion include/threepp/lights/DirectionalLightShadow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace threepp {

protected:
DirectionalLightShadow()
: LightShadow(OrthographicCamera::create(-5, 5, 5, -5, 0.5f, 500)) {}
: LightShadow(std::make_unique<OrthographicCamera>(-5.f, 5.f, 5.f, -5.f, 0.5f, 500.f)) {}
};

}// namespace threepp
Expand Down
4 changes: 2 additions & 2 deletions include/threepp/lights/LightShadow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace threepp {
class LightShadow {

public:
std::shared_ptr<Camera> camera;
std::unique_ptr<Camera> camera;

float bias = 0;
float normalBias = 0;
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace threepp {

std::vector<Vector4> _viewports{Vector4(0, 0, 1, 1)};

explicit LightShadow(std::shared_ptr<Camera> camera);
explicit LightShadow(std::unique_ptr<Camera> camera);
};

}// namespace threepp
Expand Down
2 changes: 1 addition & 1 deletion src/threepp/lights/LightShadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using namespace threepp;


LightShadow::LightShadow(std::shared_ptr<Camera> camera)
LightShadow::LightShadow(std::unique_ptr<Camera> camera)
: camera(std::move(camera)) {}


Expand Down
9 changes: 1 addition & 8 deletions src/threepp/lights/PointLightShadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@

using namespace threepp;

namespace {

Vector3 _lightPositionWorld;
Vector3 _lookTarget;
Matrix4 _projScreenMatrix;

}// namespace

PointLightShadow::PointLightShadow()
: LightShadow(PerspectiveCamera::create(90, 1, 0.5f, 500)),
: LightShadow(std::make_unique<PerspectiveCamera>(90, 1, 0.5f, 500)),
_cubeDirections({Vector3(1, 0, 0), Vector3(-1, 0, 0), Vector3(0, 0, 1),
Vector3(0, 0, -1), Vector3(0, 1, 0), Vector3(0, -1, 0)}),
_cubeUps({Vector3(0, 1, 0), Vector3(0, 1, 0), Vector3(0, 1, 0),
Expand Down
2 changes: 1 addition & 1 deletion src/threepp/lights/SpotLightShadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using namespace threepp;

SpotLightShadow::SpotLightShadow()
: LightShadow(PerspectiveCamera::create(50, 1, 0.5f, 500)) {}
: LightShadow(std::make_unique<PerspectiveCamera>(50, 1, 0.5f, 500)) {}

void SpotLightShadow::updateMatrices(Light* _light) {

Expand Down
4 changes: 4 additions & 0 deletions src/threepp/renderers/gl/GLUniforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ namespace {
glUniform1iv(addr, static_cast<int>(n), units.data());

for (unsigned i = 0; i != n; ++i) {
auto value = data[i];
if (!value) continue;
textures->setTexture2D(*data[i], units[i]);
}
};
Expand Down Expand Up @@ -401,6 +403,8 @@ namespace {
[&](std::vector<std::unordered_map<std::string, NestedUniformValue>*> arg) {
for (auto& u : seq) {
int index = utils::parseInt(u->id);
auto value = arg[index];
if (!value) continue;
u->setValue(*arg[index], textures);
}
}},
Expand Down

0 comments on commit a0714d5

Please sign in to comment.