diff options
author | Liang Qi <liang.qi@qt.io> | 2019-07-31 15:40:18 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2019-07-31 15:40:18 +0200 |
commit | f8a85093097cbd1783f19602513631e06c762fd9 (patch) | |
tree | 8109c1a04a578c7a79a25b0a2fe4c1463b0a264c | |
parent | f3b6963f8b873c190cc1033cb8dabaf1d63ee2b6 (diff) | |
parent | 64e10caaa1c261167fd98f91ce87cbefd11782ca (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts:
tests/manual/manual.pro
Change-Id: I15d497da84d3fe684c3a598831171d6aed7534ca
29 files changed, 1022 insertions, 22 deletions
diff --git a/src/extras/defaults/qskyboxentity.cpp b/src/extras/defaults/qskyboxentity.cpp index 7de552b38..e82a30950 100644 --- a/src/extras/defaults/qskyboxentity.cpp +++ b/src/extras/defaults/qskyboxentity.cpp @@ -238,6 +238,30 @@ void QSkyboxEntityPrivate::reloadTexture() */ /*! + * \qmltype SkyboxEntity + * \instantiates Qt3DExtras::QSkyboxEntity + \inqmlmodule Qt3D.Extras + * + * \brief SkyboxEntity is a convenience Entity subclass that can be used to + * insert a skybox in a 3D scene. + * + * By specifying a base name and an extension, SkyboxEntity will take care of + * building a TextureCubeMap to be rendered at runtime. The images in the + * source directory should match the pattern: \b base name + * + * "_posx|_posy|_posz|_negx|_negy|_negz" + extension + * + * By default the extension defaults to .png. + * + * Be sure to disable frustum culling in the FrameGraph through which the + * skybox rendering happens. + * + * \note Please note that you shouldn't try to render a skybox with an + * orthographic projection. + * + * \since 5.5 + */ + +/*! * Constructs a new Qt3DExtras::QSkyboxEntity object with \a parent as parent. */ QSkyboxEntity::QSkyboxEntity(QNode *parent) @@ -269,6 +293,11 @@ void QSkyboxEntity::setBaseName(const QString &baseName) Contains the base name of the Skybox. */ /*! + \qmlproperty string QSkyboxEntity::baseName + + Contains the base name of the Skybox. +*/ +/*! * Returns the base name of the Skybox. */ QString QSkyboxEntity::baseName() const @@ -298,6 +327,15 @@ void QSkyboxEntity::setExtension(const QString &extension) The default value is: .png */ + +/*! + \qmlproperty string QSkyboxEntity::extension + + Contains the extension of the filename for the skybox image, including the + leading '.'. + + The default value is: .png +*/ /*! * Returns the extension */ @@ -336,5 +374,12 @@ bool QSkyboxEntity::isGammaCorrectEnabled() const \property QSkyboxEntity::gammaCorrect A boolean indicating whether gamma correction is enabled. + \since 5.9 +*/ +/*! + \qmlproperty bool QSkyboxEntity::gammaCorrect + + A boolean indicating whether gamma correction is enabled. + \since 5.9 */ QT_END_NAMESPACE diff --git a/src/render/backend/uniform.cpp b/src/render/backend/uniform.cpp index 41ee24967..17c26e6c7 100644 --- a/src/render/backend/uniform.cpp +++ b/src/render/backend/uniform.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "uniform_p.h" +#include "qabstracttexture.h" QT_BEGIN_NAMESPACE @@ -261,6 +262,11 @@ UniformValue UniformValue::fromVariant(const QVariant &variant) memcpy(v.data<float>(), mat33.constData(), 9 * sizeof(float)); break; } + if (variant.userType() == qMetaTypeId<Qt3DRender::QAbstractTexture *>()) { + // silently ignore null texture pointers as they are common while textures are loading + if (variant.value<Qt3DRender::QAbstractTexture *>() == nullptr) + break; + } qWarning() << "Unknown uniform type or value:" << variant << "Please check your QParameters"; } } diff --git a/src/render/lights/qdirectionallight.cpp b/src/render/lights/qdirectionallight.cpp index 14bdb2c38..9b6e580de 100644 --- a/src/render/lights/qdirectionallight.cpp +++ b/src/render/lights/qdirectionallight.cpp @@ -76,6 +76,9 @@ QDirectionalLightPrivate::QDirectionalLightPrivate() \since 5.7 \brief Encapsulate a Directional Light object in a Qt 3D scene. + A directional light is a light source that behaves similar to sunlight. + The light from a directional light hits all objects from the same direction + and with the same intensity, regardless of where they are in the scene. */ /*! @@ -86,6 +89,9 @@ QDirectionalLightPrivate::QDirectionalLightPrivate() \since 5.7 \brief Encapsulate a Directional Light object in a Qt 3D scene. + A directional light is a light source that behaves similar to sunlight. + The light from a directional light hits all objects from the same direction + and with the same intensity, regardless of where they are in the scene. */ /*! diff --git a/src/render/lights/qenvironmentlight.cpp b/src/render/lights/qenvironmentlight.cpp index 866905fb6..b3dac56ff 100644 --- a/src/render/lights/qenvironmentlight.cpp +++ b/src/render/lights/qenvironmentlight.cpp @@ -53,6 +53,9 @@ namespace Qt3DRender * \instantiates Qt3DRender::QEnvironmentLight * \brief Encapsulate an environment light object in a Qt 3D scene. * \since 5.9 + * + * EnvironmentLight uses cubemaps to implement image-based lighting (IBL), a technique + * often used in conjunction with physically-based rendering (PBR). */ QEnvironmentLightPrivate::QEnvironmentLightPrivate() @@ -97,6 +100,9 @@ Qt3DCore::QNodeCreatedChangeBasePtr QEnvironmentLight::createNodeCreationChange( \inmodule Qt3DRender \brief Encapsulate an environment light object in a Qt 3D scene. \since 5.9 + + EnvironmentLight uses cubemaps to implement image-based lighting (IBL), a technique + often used in conjunction with physically-based rendering (PBR). */ QEnvironmentLight::QEnvironmentLight(Qt3DCore::QNode *parent) diff --git a/src/render/lights/qpointlight.cpp b/src/render/lights/qpointlight.cpp index 28dd265b8..2b042c91d 100644 --- a/src/render/lights/qpointlight.cpp +++ b/src/render/lights/qpointlight.cpp @@ -75,6 +75,19 @@ QPointLightPrivate::QPointLightPrivate() \since 5.5 \brief Encapsulate a Point Light object in a Qt 3D scene. + A point light is a light source that emits light in all directions, from a single point. + Conceptually, this is similar to light given off by a standard light bulb. + + A point light uses three attenuation factors to describe how the intensity of the light + decreases over distance. These factors are designed to be used together in calcuating total + attenuation. For the materials in Qt3D Extras the following formula is used, where distance + is the distance from the light to the surface being rendered: + + \code + totalAttenuation = 1.0 / (constantAttenuation + (linearAttenuation * distance) + (quadraticAttenuation * distance * distance)); + \endcode + + Custom materials may choose to interpret these factors differently. */ /*! @@ -84,6 +97,20 @@ QPointLightPrivate::QPointLightPrivate() \inqmlmodule Qt3D.Render \since 5.5 \brief Encapsulate a Point Light object in a Qt 3D scene. + + A point light is a light source that emits light in all directions, from a single point. + Conceptually, this is similar to light given off by a standard light bulb. + + A point light uses three attenuation factors to describe how the intensity of the light + decreases over distance. These factors are designed to be used together in calcuating total + attenuation. For the materials in Qt3D Extras the following formula is used, where distance + is the distance from the light to the surface being rendered: + + \code + totalAttenuation = 1.0 / (constantAttenuation + (linearAttenuation * distance) + (quadraticAttenuation * distance * distance)); + \endcode + + Custom materials may choose to interpret these factors differently. */ /*! diff --git a/src/render/lights/qspotlight.cpp b/src/render/lights/qspotlight.cpp index 81c18387b..c4deaf817 100644 --- a/src/render/lights/qspotlight.cpp +++ b/src/render/lights/qspotlight.cpp @@ -83,6 +83,18 @@ QSpotLightPrivate::QSpotLightPrivate() \since 5.5 \brief Encapsulate a Spot Light object in a Qt 3D scene. + A spotlight is a light source that emits a cone of light in a particular direction. + + A spotlight uses three attenuation factors to describe how the intensity of the light + decreases over distance. These factors are designed to be used together in calcuating total + attenuation. For the materials in Qt3D Extras the following formula is used, where distance + is the distance from the light to the surface being rendered: + + \code + totalAttenuation = 1.0 / (constantAttenuation + (linearAttenuation * distance) + (quadraticAttenuation * distance * distance)); + \endcode + + Custom materials may choose to interpret these factors differently. */ /*! @@ -93,6 +105,18 @@ QSpotLightPrivate::QSpotLightPrivate() \since 5.5 \brief Encapsulate a Spot Light object in a Qt 3D scene. + A spotlight is a light source that emits a cone of light in a particular direction. + + A spotlight uses three attenuation factors to describe how the intensity of the light + decreases over distance. These factors are designed to be used together in calcuating total + attenuation. For the materials in Qt3D Extras the following formula is used, where distance + is the distance from the light to the surface being rendered: + + \code + totalAttenuation = 1.0 / (constantAttenuation + (linearAttenuation * distance) + (quadraticAttenuation * distance * distance)); + \endcode + + Custom materials may choose to interpret these factors differently. */ /*! diff --git a/src/render/renderers/opengl/jobs/renderviewjobutils.cpp b/src/render/renderers/opengl/jobs/renderviewjobutils.cpp index e55497d06..d2babe58a 100644 --- a/src/render/renderers/opengl/jobs/renderviewjobutils.cpp +++ b/src/render/renderers/opengl/jobs/renderviewjobutils.cpp @@ -194,8 +194,10 @@ void setRenderViewConfigFromFrameGraphLeafNode(RenderView *rv, const FrameGraphN rv->setStateSet(stateSet); } + // Add states from new stateSet we might be missing + // but don' t override existing states (lower StateSetNode always has priority) if (rStateSet->hasRenderStates()) - addToRenderStateSet(stateSet, rStateSet->renderStates(), manager->renderStateManager()); + addUniqueStatesToRenderStateSet(stateSet, rStateSet->renderStates(), manager->renderStateManager()); break; } @@ -433,14 +435,16 @@ void parametersFromMaterialEffectTechnique(ParameterInfoList *infoList, parametersFromParametersProvider(infoList, manager, technique); } -void addToRenderStateSet(RenderStateSet *stateSet, - const QVector<Qt3DCore::QNodeId> stateIds, - RenderStateManager *manager) +// Only add states with types we don't already have +void addUniqueStatesToRenderStateSet(RenderStateSet *stateSet, + const QVector<Qt3DCore::QNodeId> stateIds, + RenderStateManager *manager) { for (const Qt3DCore::QNodeId &stateId : stateIds) { RenderStateNode *node = manager->lookupResource(stateId); - if (node->isEnabled()) + if (node->isEnabled() && !stateSet->hasStateOfType(node->type())) { stateSet->addState(node->impl()); + } } } diff --git a/src/render/renderers/opengl/jobs/renderviewjobutils_p.h b/src/render/renderers/opengl/jobs/renderviewjobutils_p.h index 90c4a53cc..bd2e12534 100644 --- a/src/render/renderers/opengl/jobs/renderviewjobutils_p.h +++ b/src/render/renderers/opengl/jobs/renderviewjobutils_p.h @@ -150,9 +150,9 @@ void parametersFromParametersProvider(ParameterInfoList *infoList, Q_AUTOTEST_EXPORT ParameterInfoList::const_iterator findParamInfo(ParameterInfoList *infoList, const int nameId); -Q_AUTOTEST_EXPORT void addToRenderStateSet(RenderStateSet *stateSet, - const QVector<Qt3DCore::QNodeId> stateIds, - RenderStateManager *manager); +Q_AUTOTEST_EXPORT void addUniqueStatesToRenderStateSet(RenderStateSet *stateSet, + const QVector<Qt3DCore::QNodeId> stateIds, + RenderStateManager *manager); typedef QHash<int, QVariant> UniformBlockValueBuilderHash; diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp index 68d31be71..b60eea33d 100644 --- a/src/render/renderers/opengl/renderer/renderer.cpp +++ b/src/render/renderers/opengl/renderer/renderer.cpp @@ -1648,7 +1648,7 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren // Reset state and call doneCurrent if the surface // is valid and was actually activated - if (surface && m_submissionContext->hasValidGLHelper()) { + if (lastUsedSurface && m_submissionContext->hasValidGLHelper()) { // Reset state to the default state if the last stateset is not the // defaultRenderStateSet if (m_submissionContext->currentStateSet() != m_defaultRenderStateSet) diff --git a/src/render/renderers/opengl/renderer/renderview.cpp b/src/render/renderers/opengl/renderer/renderview.cpp index ebb1ee7ab..5845fe147 100644 --- a/src/render/renderers/opengl/renderer/renderview.cpp +++ b/src/render/renderers/opengl/renderer/renderview.cpp @@ -656,10 +656,7 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit RenderPass *pass = passData.pass; if (pass->hasRenderStates()) { command->m_stateSet = new RenderStateSet(); - addToRenderStateSet(command->m_stateSet, pass->renderStates(), m_manager->renderStateManager()); - - // Merge per pass stateset with global stateset - // so that the local stateset only overrides + addUniqueStatesToRenderStateSet(command->m_stateSet, pass->renderStates(), m_manager->renderStateManager()); if (m_stateSet != nullptr) command->m_stateSet->merge(m_stateSet); command->m_changeCost = m_renderer->defaultRenderState()->changeCost(command->m_stateSet); @@ -779,15 +776,26 @@ QVector<RenderCommand *> RenderView::buildComputeRenderCommands(const QVector<En // 1 RenderCommand per RenderPass pass on an Entity with a Mesh for (const RenderPassParameterData &passData : renderPassData) { // Add the RenderPass Parameters - ParameterInfoList globalParameters = passData.parameterInfo; + RenderCommand *command = new RenderCommand(); RenderPass *pass = passData.pass; - parametersFromParametersProvider(&globalParameters, m_manager->parameterManager(), pass); - RenderCommand *command = new RenderCommand(); + if (pass->hasRenderStates()) { + command->m_stateSet = new RenderStateSet(); + addUniqueStatesToRenderStateSet(command->m_stateSet, pass->renderStates(), m_manager->renderStateManager()); + + // Merge per pass stateset with global stateset + // so that the local stateset only overrides + if (m_stateSet != nullptr) + command->m_stateSet->merge(m_stateSet); + command->m_changeCost = m_renderer->defaultRenderState()->changeCost(command->m_stateSet); + } + command->m_type = RenderCommand::Compute; command->m_workGroups[0] = std::max(m_workGroups[0], computeJob->x()); command->m_workGroups[1] = std::max(m_workGroups[1], computeJob->y()); command->m_workGroups[2] = std::max(m_workGroups[2], computeJob->z()); + + ParameterInfoList globalParameters = passData.parameterInfo; setShaderAndUniforms(command, pass, globalParameters, diff --git a/src/render/renderers/opengl/renderstates/renderstateset.cpp b/src/render/renderers/opengl/renderstates/renderstateset.cpp index f7fc279a1..b14695c77 100644 --- a/src/render/renderers/opengl/renderstates/renderstateset.cpp +++ b/src/render/renderers/opengl/renderstates/renderstateset.cpp @@ -103,9 +103,24 @@ StateMaskSet RenderStateSet::stateMask() const return m_stateMask; } +// This modifies our state to add states from others +// if we don't already contain a state with that type set void RenderStateSet::merge(RenderStateSet *other) { m_stateMask |= other->stateMask(); + const QVector<StateVariant> otherStates = other->states(); + + // We only add states which are new (different type) + for (const StateVariant &otherState : otherStates) { + const bool hasFoundStateOfSameType = hasStateOfType(otherState.type); + if (!hasFoundStateOfSameType) + m_states.push_back(otherState); + } +} + +bool RenderStateSet::hasStateOfType(StateMask type) const +{ + return (type & stateMask()); } bool RenderStateSet::contains(const StateVariant &ds) const diff --git a/src/render/renderers/opengl/renderstates/renderstateset_p.h b/src/render/renderers/opengl/renderstates/renderstateset_p.h index 09b58b859..29be4d2f1 100644 --- a/src/render/renderers/opengl/renderstates/renderstateset_p.h +++ b/src/render/renderers/opengl/renderstates/renderstateset_p.h @@ -93,6 +93,9 @@ public: QVector<StateVariant> states() const { return m_states; } + bool hasStateOfType(StateMask type) const; + + /** * @brief contains - check if this set contains a matching piece of state * @param ds diff --git a/src/render/renderstates/genericstate_p.h b/src/render/renderstates/genericstate_p.h index 69c3dee15..b07487d65 100644 --- a/src/render/renderstates/genericstate_p.h +++ b/src/render/renderstates/genericstate_p.h @@ -96,7 +96,7 @@ public: bool equalTo(const RenderStateImpl &renderState) const override { const GenericState *other = static_cast<const GenericState*>(&renderState); - return (other != NULL && other->m_values == m_values); + return (other != nullptr && other->m_values == m_values); } StateMask mask() const override diff --git a/src/render/renderstates/renderstatenode_p.h b/src/render/renderstates/renderstatenode_p.h index 886bb0c95..277b8a7c8 100644 --- a/src/render/renderstates/renderstatenode_p.h +++ b/src/render/renderstates/renderstatenode_p.h @@ -65,7 +65,7 @@ public: void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override; - StateMaskSet mask() const { return m_impl.type; } + StateMask type() const { return m_impl.type; } StateVariant impl() const { return m_impl; } protected: diff --git a/tests/auto/render/qrenderstate/tst_qrenderstate.cpp b/tests/auto/render/qrenderstate/tst_qrenderstate.cpp index 4dc850b25..596aa9553 100644 --- a/tests/auto/render/qrenderstate/tst_qrenderstate.cpp +++ b/tests/auto/render/qrenderstate/tst_qrenderstate.cpp @@ -187,8 +187,8 @@ private Q_SLOTS: // THEN RenderStateNode *backend1 = createBackendNode(frontend1); RenderStateNode *backend2 = createBackendNode(frontend2); - QVERIFY(backend1->mask() == mask); - QVERIFY(backend2->mask() == mask); + QVERIFY(backend1->type() == mask); + QVERIFY(backend2->type() == mask); QVERIFY(backend1->impl() != backend2->impl()); // WHEN @@ -272,8 +272,8 @@ private Q_SLOTS: // THEN RenderStateNode *backend1 = createBackendNode(frontend1); RenderStateNode *backend2 = createBackendNode(frontend2); - QVERIFY(backend1->mask() == mask); - QVERIFY(backend2->mask() == mask); + QVERIFY(backend1->type() == mask); + QVERIFY(backend2->type() == mask); QVERIFY(backend1->impl() != backend2->impl()); // WHEN diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 88e339561..07f7f9132 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -64,6 +64,7 @@ SUBDIRS += \ raster-cpp \ raster-qml \ qtbug-72236 \ + qtbug-76766 \ shader-image-qml qtHaveModule(multimedia): { diff --git a/tests/manual/qtbug-76766/FrameGraph.qml b/tests/manual/qtbug-76766/FrameGraph.qml new file mode 100644 index 000000000..0b096bc19 --- /dev/null +++ b/tests/manual/qtbug-76766/FrameGraph.qml @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.9 +import Qt3D.Render 2.9 + +RenderSurfaceSelector { + id: surfaceSelector + + readonly property Layer layer: Layer { + recursive: true + } + + property alias camera: cameraSelector.camera + property alias clearColor: clearBuffers.clearColor + property alias fbo : renderToFboSelector.target + + Viewport { + normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0) + + // 1st: render scene to texture + RenderTargetSelector { + id : renderToFboSelector + + RenderStateSet { + renderStates: [ + MultiSampleAntiAliasing {}, + DepthTest { + depthFunction: DepthTest.Less + }, + CullFace{ + mode: CullFace.Back + } + ] + + ClearBuffers { + id: clearBuffers + buffers: ClearBuffers.ColorDepthBuffer + NoDraw {} + } + + CameraSelector { + id: cameraSelector + + LayerFilter { + layers: [layer] + filterMode: LayerFilter.DiscardAllMatchingLayers + TechniqueFilter { + RenderPassFilter { + matchAny: FilterKey { name: "pass"; value: 0 } + } + SortPolicy { + sortTypes: [SortPolicy.BackToFront] + RenderPassFilter { + matchAny: FilterKey { name: "pass"; value: 1 } + } + } + } + } + + RenderStateSet { + renderStates: [ + DepthTest { + depthFunction: DepthTest.Always + } + ] + LayerFilter { + layers: [layer] + filterMode: LayerFilter.AcceptAnyMatchingLayers + TechniqueFilter { + RenderPassFilter { + matchAny: FilterKey { name: "pass"; value: 0 } + } + SortPolicy { + sortTypes: [SortPolicy.BackToFront] + RenderPassFilter { + matchAny: FilterKey { name: "pass"; value: 1 } + } + } + } + } + } + } + } + } + + RenderStateSet { + renderStates: [ + DepthTest {depthFunction: DepthTest.Always}, + BlendEquation {}, + BlendEquationArguments { + sourceRgb: BlendEquationArguments.One + sourceAlpha: BlendEquationArguments.One + destinationRgb: BlendEquationArguments.Zero + destinationAlpha: BlendEquationArguments.Zero + } + ] + + RenderPassFilter { + matchAny : FilterKey { name : "pass"; value : "final" } + } + } + } +} diff --git a/tests/manual/qtbug-76766/Material1.qml b/tests/manual/qtbug-76766/Material1.qml new file mode 100644 index 000000000..069d99c74 --- /dev/null +++ b/tests/manual/qtbug-76766/Material1.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +Material { + id: root + + property color color: Qt.rgba(0.15, 0.35, 0.50, 1.0) + + parameters: [ + Parameter { name: "color"; value: Qt.vector3d(root.color.r, root.color.g, root.color.b) } + ] + + + effect: Effect { + property string vertex: "qrc:/shaders/shader.vert" + property string fragment: "qrc:/shaders/shader.frag" + + FilterKey { + id: forward + name: "renderingStyle" + value: "forward" + } + + ShaderProgram { + id: gl3Shader + vertexShaderCode: loadSource(parent.vertex) + fragmentShaderCode: loadSource(parent.fragment) + } + + techniques: [ + // OpenGL 3.1 + Technique { + filterKeys: [ forward ] + graphicsApiFilter { + api: GraphicsApiFilter.OpenGL + profile: GraphicsApiFilter.CoreProfile + majorVersion: 3 + minorVersion: 3 + } + renderPasses: RenderPass { + filterKeys: [ + FilterKey { + name: "pass" + value: 0 + } + ] + shaderProgram: gl3Shader + } + } + ] + } +} + + diff --git a/tests/manual/qtbug-76766/Material2.qml b/tests/manual/qtbug-76766/Material2.qml new file mode 100644 index 000000000..0af0ecb6c --- /dev/null +++ b/tests/manual/qtbug-76766/Material2.qml @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 + +Material { + id: root + + property color color: Qt.rgba(0.15, 0.35, 0.50, 1.0) + + parameters: [ + Parameter { name: "color"; value: Qt.vector3d(root.color.r, root.color.g, root.color.b) } + ] + + + effect: Effect { + property string vertex: "qrc:/shaders/shader.vert" + property string fragment: "qrc:/shaders/shader.frag" + + FilterKey { + id: forward + name: "renderingStyle" + value: "forward" + } + + ShaderProgram { + id: gl3Shader + vertexShaderCode: loadSource(parent.vertex) + fragmentShaderCode: loadSource(parent.fragment) + } + + techniques: [ + // OpenGL 3.1 + Technique { + filterKeys: [ forward ] + graphicsApiFilter { + api: GraphicsApiFilter.OpenGL + profile: GraphicsApiFilter.CoreProfile + majorVersion: 3 + minorVersion: 3 + } + renderPasses: [ + RenderPass { + filterKeys: [ + FilterKey { + name: "pass" + value: 1 + } + ] + shaderProgram: gl3Shader + renderStates: [ + NoDepthMask {}, + BlendEquation {}, + BlendEquationArguments { + sourceRgb: BlendEquationArguments.One + destinationRgb: BlendEquationArguments.One + sourceAlpha: BlendEquationArguments.Zero + destinationAlpha: BlendEquationArguments.One + } + ] + } + ] + } + ] + } +} + + diff --git a/tests/manual/qtbug-76766/PostProcess.qml b/tests/manual/qtbug-76766/PostProcess.qml new file mode 100644 index 000000000..cd4c9c0c6 --- /dev/null +++ b/tests/manual/qtbug-76766/PostProcess.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.9 +import Qt3D.Render 2.9 +import Qt3D.Extras 2.0 + +Entity { + id: root + + property Texture colorTexture + readonly property int samples : colorTexture ? colorTexture.samples : 1 + + Effect { + id: materialEffect + techniques : [ + // OpenGL 3.2 + Technique { + graphicsApiFilter { + api : GraphicsApiFilter.OpenGL + profile : GraphicsApiFilter.CoreProfile + minorVersion : 3 + majorVersion : 2 + } + + renderPasses : RenderPass { + filterKeys : FilterKey { name : "pass"; value : "final" } + + shaderProgram : ShaderProgram { + vertexShaderCode: + "#version 150 core + + in vec3 vertexPosition; + out vec2 texCoords; + + void main() { + texCoords = vec2(0.5) + vec2(0.5) * vertexPosition.xz; + gl_Position = vec4(vertexPosition.x, vertexPosition.z, 0.0, 1.0); + }" + fragmentShaderCode: + "#version 150 core + + uniform sampler2DMS source; + + in vec2 texCoords; + out vec4 fragColor; + + void main() { + vec4 c = vec4(0.0); + c += texelFetch(source, ivec2(gl_FragCoord), 0); + fragColor = vec4(c.rgb / max(c.a, 0.01), c.a); + }" + } + } + } + ] + } + + Material { + id: materialWithoutTexture + + parameters: [ + Parameter { name: "source"; value: colorTexture }, + Parameter { name: "samples"; value: root.samples } + ] + + effect: materialEffect + } + + PlaneMesh { + id: planeMesh + width: 2.0 + height: 2.0 + meshResolution: Qt.size(2, 2) + } + + components : [ + planeMesh, + materialWithoutTexture + ] +} diff --git a/tests/manual/qtbug-76766/SceneRoot.qml b/tests/manual/qtbug-76766/SceneRoot.qml new file mode 100644 index 000000000..6e34633b1 --- /dev/null +++ b/tests/manual/qtbug-76766/SceneRoot.qml @@ -0,0 +1,176 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 +import Qt3D.Input 2.0 +import QtQuick 2.0 as QQ2 +import QtQuick 2.12 + + +Entity { + id: sceneRoot + + Camera { + id: camera + projectionType: CameraLens.OrthographicProjection + left: -2 + right: 2 + top: 2 + bottom: -2 + nearPlane: 0.1 + farPlane: 1000.0 + position: Qt.vector3d(0.0, 0.0, 1.0) + upVector: Qt.vector3d(0.0, 1.0, 0.0) + viewCenter: Qt.vector3d(0.0, 0.0, 0.0) + } + + RenderTarget { + id: renderTargetFBO + attachments : [ + RenderTargetOutput { + attachmentPoint : RenderTargetOutput.Color0 + texture : Texture2DMultisample { + id : colorAttachment + width : scene3d.width + height : scene3d.height + format : Texture.RGBA8_UNorm + generateMipMaps : false + samples: 1 + } + }, + RenderTargetOutput { + attachmentPoint : RenderTargetOutput.Depth + texture : Texture2DMultisample { + width : scene3d.width + height : scene3d.height + format : Texture.D32F + generateMipMaps : false + samples: 1 + } + } + ] + } + + components: [ + RenderSettings { + activeFrameGraph: FrameGraph { + id: framegraph + camera: camera + fbo: renderTargetFBO + } + renderPolicy: RenderSettings.Always + } + ] + + Entity { + id: firstPassEntities + + Entity { + components: [ + Transform { + translation: Qt.vector3d(0,0,-2) + }, + Material1 { + color: "red" + }, + SphereMesh { + } + ] + } + + + Entity { + components: [ + Transform { + translation: Qt.vector3d(1,0,-1) + }, + Material2 { + color: "green" + }, + SphereMesh { + } + ] + } + } + + Entity { + id: secondPassEntities + components: [framegraph.layer] + + Entity { + components: [ + Transform { + translation: Qt.vector3d(0,0,-4) + scale: 0.5 + }, + Material1 { + ColorAnimation on color { + from: "black" + to: "purple" + duration: 2000 + loops: Animation.Infinite + } + }, + SphereMesh { + } + ] + } + + + Entity { + components: [ + Transform { + translation: Qt.vector3d(1,0,-3) + scale: 0.5 + }, + Material2 { + color: "orange" + }, + SphereMesh { + } + ] + } + } + + PostProcess { + colorTexture: colorAttachment + } +} diff --git a/tests/manual/qtbug-76766/expected_output.png b/tests/manual/qtbug-76766/expected_output.png Binary files differnew file mode 100644 index 000000000..8f642e843 --- /dev/null +++ b/tests/manual/qtbug-76766/expected_output.png diff --git a/tests/manual/qtbug-76766/main.cpp b/tests/manual/qtbug-76766/main.cpp new file mode 100644 index 000000000..f9d49846a --- /dev/null +++ b/tests/manual/qtbug-76766/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQuickView> +#include <QOpenGLContext> + +void setSurfaceFormat() +{ + QSurfaceFormat format; +#ifdef QT_OPENGL_ES_2 + format.setRenderableType(QSurfaceFormat::OpenGLES); +#else + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { + format.setVersion(4, 3); + format.setProfile(QSurfaceFormat::CoreProfile); + } +#endif + format.setDepthBufferSize(24); + format.setSamples(4); + format.setStencilBufferSize(8); + QSurfaceFormat::setDefaultFormat(format); +} + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + setSurfaceFormat(); + + QQuickView view; + + view.resize(1920, 1080); + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl("qrc:/main.qml")); + view.show(); + + return app.exec(); +} diff --git a/tests/manual/qtbug-76766/main.qml b/tests/manual/qtbug-76766/main.qml new file mode 100644 index 000000000..9b8f4b691 --- /dev/null +++ b/tests/manual/qtbug-76766/main.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Scene3D 2.12 +import Qt3D.Render 2.12 + +Item { + anchors.fill: parent + + Scene3D { + id: scene3d + anchors.fill: parent + focus: true + cameraAspectRatioMode: Scene3D.AutomaticAspectRatio + + SceneRoot { + id: root + } + } + + Image { + width: 400 + fillMode: Image.PreserveAspectFit + source: "qrc:/expected_output.png" + Text { + anchors.centerIn: parent + color: "white" + text: "This is the expected output" + } + Rectangle { + anchors.fill: parent + color: "transparent" + border { + color: "white" + width: 2 + } + } + } +} diff --git a/tests/manual/qtbug-76766/qml.qrc b/tests/manual/qtbug-76766/qml.qrc new file mode 100644 index 000000000..b1f8c2c21 --- /dev/null +++ b/tests/manual/qtbug-76766/qml.qrc @@ -0,0 +1,11 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>SceneRoot.qml</file> + <file>FrameGraph.qml</file> + <file>PostProcess.qml</file> + <file>Material1.qml</file> + <file>Material2.qml</file> + <file>expected_output.png</file> + </qresource> +</RCC> diff --git a/tests/manual/qtbug-76766/qtbug-76766.pro b/tests/manual/qtbug-76766/qtbug-76766.pro new file mode 100644 index 000000000..f332d7d57 --- /dev/null +++ b/tests/manual/qtbug-76766/qtbug-76766.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +QT += qml quick +CONFIG += c++11 + +SOURCES += main.cpp + +RESOURCES += qml.qrc \ + shaders.qrc + diff --git a/tests/manual/qtbug-76766/shaders.qrc b/tests/manual/qtbug-76766/shaders.qrc new file mode 100644 index 000000000..665814e55 --- /dev/null +++ b/tests/manual/qtbug-76766/shaders.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file>shaders/shader.frag</file> + <file>shaders/shader.vert</file> + </qresource> +</RCC> diff --git a/tests/manual/qtbug-76766/shaders/shader.frag b/tests/manual/qtbug-76766/shaders/shader.frag new file mode 100644 index 000000000..92d304640 --- /dev/null +++ b/tests/manual/qtbug-76766/shaders/shader.frag @@ -0,0 +1,11 @@ +#version 150 core + +uniform vec3 color; + +out vec4 fragColor; + +void main() +{ + fragColor = vec4(color,1.0); +} + diff --git a/tests/manual/qtbug-76766/shaders/shader.vert b/tests/manual/qtbug-76766/shaders/shader.vert new file mode 100644 index 000000000..fa836855d --- /dev/null +++ b/tests/manual/qtbug-76766/shaders/shader.vert @@ -0,0 +1,36 @@ +#version 150 core + +in vec3 vertexPosition; +in vec3 vertexNormal; +in vec2 vertexTexCoord; +in vec4 vertexTangent; + +out vec3 worldPosition; +out vec3 worldNormal; +out vec4 worldTangent; +out vec2 texCoord; + +uniform mat4 modelMatrix; +uniform mat3 modelNormalMatrix; +uniform mat4 mvp; + +void main() +{ + // Scale texture coordinates for for fragment shader + texCoord = vertexTexCoord; + + // Transform position, normal, and tangent to world coords + worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0)); + worldNormal = normalize(modelNormalMatrix * vertexNormal); + worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0))); + worldTangent.w = vertexTangent.w; + + // Calculate animated vertex positions + + float sinPos = (vertexPosition.z)+(vertexPosition.x); + float sinPos2 = (vertexPosition.y/2)+(vertexPosition.z); + vec3 vertMod = vec3(vertexPosition.x,vertexPosition.y,vertexPosition.z); + + // Calculate vertex position in clip coordinates + gl_Position = mvp * vec4(vertexPosition, 1.0); +} |