diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2016-05-24 13:45:26 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-25 19:51:16 +0000 |
commit | 7793c707b985efc14a5675d344fdca83128059ba (patch) | |
tree | d453b9227d34c37a6509c0a55625e27f705fe657 | |
parent | cc8cc05f873aa64ee3c4e1ea6e7a662b15c57723 (diff) |
Initialize dynamic properties of lights
Forces them to be initialized so they exist when the property reader
is used for later updates.
Also use correct type in default value setting of uniforms.
Task-number: QTBUG-53585
Change-Id: Id594670ea75385c1d54f06d4d7c6241d77403ce6
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/render/backend/renderview.cpp | 4 | ||||
-rw-r--r-- | src/render/lights/qabstractlight.cpp | 2 | ||||
-rw-r--r-- | tests/auto/render/qabstractlight/tst_qabstractlight.cpp | 16 |
3 files changed, 12 insertions, 10 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp index c131ef718..ac4567aa7 100644 --- a/src/render/backend/renderview.cpp +++ b/src/render/backend/renderview.cpp @@ -896,7 +896,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, setUniformValue(command->m_parameterPack, LIGHT_POSITION_NAMES[lightIdx], worldPos); setUniformValue(command->m_parameterPack, LIGHT_TYPE_NAMES[lightIdx], int(QAbstractLight::PointLight)); setUniformValue(command->m_parameterPack, LIGHT_COLOR_NAMES[lightIdx], QVector3D(1.0f, 1.0f, 1.0f)); - setUniformValue(command->m_parameterPack, LIGHT_INTENSITY_NAMES[lightIdx], QVector3D(0.5f, 0.5f, 0.5f)); + setUniformValue(command->m_parameterPack, LIGHT_INTENSITY_NAMES[lightIdx], 0.5f); setDefaultUniformBlockShaderDataValue(command->m_parameterPack, shader, shaderData, LIGHT_STRUCT_NAMES[lightIdx]); ++lightIdx; } @@ -909,7 +909,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, setUniformValue(command->m_parameterPack, LIGHT_POSITION_NAMES[0], QVector3D(10.0f, 10.0f, 0.0f)); setUniformValue(command->m_parameterPack, LIGHT_TYPE_NAMES[0], int(QAbstractLight::PointLight)); setUniformValue(command->m_parameterPack, LIGHT_COLOR_NAMES[0], QVector3D(1.0f, 1.0f, 1.0f)); - setUniformValue(command->m_parameterPack, LIGHT_INTENSITY_NAMES[0], QVector3D(0.5f, 0.5f, 0.5f)); + setUniformValue(command->m_parameterPack, LIGHT_INTENSITY_NAMES[0], 0.5f); } } // Set frag outputs in the shaders if hash not empty diff --git a/src/render/lights/qabstractlight.cpp b/src/render/lights/qabstractlight.cpp index 0f8e5c19f..ea8fd13d6 100644 --- a/src/render/lights/qabstractlight.cpp +++ b/src/render/lights/qabstractlight.cpp @@ -59,6 +59,8 @@ QAbstractLightPrivate::QAbstractLightPrivate(QAbstractLight::Type type) , m_shaderData(new QShaderData) { m_shaderData->setProperty("type", type); + m_shaderData->setProperty("color", QColor(Qt::white)); + m_shaderData->setProperty("intensity", 0.5f); } QAbstractLightPrivate::~QAbstractLightPrivate() diff --git a/tests/auto/render/qabstractlight/tst_qabstractlight.cpp b/tests/auto/render/qabstractlight/tst_qabstractlight.cpp index 9fc6bfa76..68fc2cd30 100644 --- a/tests/auto/render/qabstractlight/tst_qabstractlight.cpp +++ b/tests/auto/render/qabstractlight/tst_qabstractlight.cpp @@ -148,7 +148,7 @@ private Q_SLOTS: arbiter.setArbiterOnNode(light.data()); light->setColor(Qt::red); - light->setIntensity(0.5f); + light->setIntensity(0.8f); // change from the default of 0.5f QCoreApplication::processEvents(); QCOMPARE(arbiter.events.size(), 2 * 2); // Due to contained shader data @@ -162,7 +162,7 @@ private Q_SLOTS: change = arbiter.events[1].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "intensity"); QCOMPARE(change->subjectId(), light->id()); - QCOMPARE(change->value().value<float>(), 0.5f); + QCOMPARE(change->value().value<float>(), 0.8f); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); arbiter.events.clear(); @@ -182,7 +182,7 @@ private Q_SLOTS: arbiter.setArbiterOnNode(pointLight.data()); pointLight->setColor(Qt::green); - pointLight->setIntensity(0.5f); + pointLight->setIntensity(0.8f); pointLight->setConstantAttenuation(0.5f); pointLight->setLinearAttenuation(0.0f); // No actual event triggered as 0.0f is default pointLight->setQuadraticAttenuation(1.0f); @@ -199,7 +199,7 @@ private Q_SLOTS: change = arbiter.events[1].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "intensity"); QCOMPARE(change->subjectId(), pointLight->id()); - QCOMPARE(change->value().value<float>(), 0.5f); + QCOMPARE(change->value().value<float>(), 0.8f); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); change = arbiter.events[2].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "constantAttenuation"); @@ -222,7 +222,7 @@ private Q_SLOTS: arbiter.setArbiterOnNode(dirLight.data()); dirLight->setColor(Qt::blue); - dirLight->setIntensity(0.5f); + dirLight->setIntensity(0.8f); dirLight->setWorldDirection(QVector3D(0.5f, 0.0f, -1.0f)); QCoreApplication::processEvents(); @@ -237,7 +237,7 @@ private Q_SLOTS: change = arbiter.events[1].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "intensity"); QCOMPARE(change->subjectId(), dirLight->id()); - QCOMPARE(change->value().value<float>(), 0.5f); + QCOMPARE(change->value().value<float>(), 0.8f); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); change = arbiter.events[2].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "worldDirection"); @@ -255,7 +255,7 @@ private Q_SLOTS: arbiter.setArbiterOnNode(spotLight.data()); spotLight->setColor(Qt::lightGray); - spotLight->setIntensity(0.5f); + spotLight->setIntensity(0.8f); spotLight->setLocalDirection(QVector3D(0.5f, 0.0f, -1.0f)); spotLight->setCutOffAngle(0.75f); QCoreApplication::processEvents(); @@ -271,7 +271,7 @@ private Q_SLOTS: change = arbiter.events[1].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "intensity"); QCOMPARE(change->subjectId(), spotLight->id()); - QCOMPARE(change->value().value<float>(), 0.5f); + QCOMPARE(change->value().value<float>(), 0.8f); QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); change = arbiter.events[2].staticCast<Qt3DCore::QPropertyUpdatedChange>(); QCOMPARE(change->propertyName(), "localDirection"); |