From c82207d54c76d8b66be010bfa63e45f9507891fa Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 4 Mar 2015 16:05:02 +0100 Subject: Move the examples under a qt3d subdir Modules cannot have their examples in the top-level examples directory because in the pre-built packages all modules' examples are merged together. Change-Id: I80fdbb8f1ec6f3d8fd793e4d856e705000237127 Reviewed-by: Paul Lemire --- .../deferred-renderer-cpp.pro | 33 ++++ .../deferred-renderer-cpp.qrc | 12 ++ .../deferred-renderer-cpp/deferredrenderer.cpp | 85 +++++++++ .../qt3d/deferred-renderer-cpp/deferredrenderer.h | 71 +++++++ examples/qt3d/deferred-renderer-cpp/final_gl2.frag | 36 ++++ examples/qt3d/deferred-renderer-cpp/final_gl2.vert | 9 + examples/qt3d/deferred-renderer-cpp/final_gl3.frag | 37 ++++ examples/qt3d/deferred-renderer-cpp/final_gl3.vert | 9 + .../qt3d/deferred-renderer-cpp/finaleffect.cpp | 87 +++++++++ examples/qt3d/deferred-renderer-cpp/finaleffect.h | 60 ++++++ examples/qt3d/deferred-renderer-cpp/gbuffer.cpp | 101 ++++++++++ examples/qt3d/deferred-renderer-cpp/gbuffer.h | 67 +++++++ .../qt3d/deferred-renderer-cpp/geometry_gl2.frag | 12 ++ .../qt3d/deferred-renderer-cpp/geometry_gl2.vert | 21 +++ .../qt3d/deferred-renderer-cpp/geometry_gl3.frag | 16 ++ .../qt3d/deferred-renderer-cpp/geometry_gl3.vert | 21 +++ examples/qt3d/deferred-renderer-cpp/main.cpp | 208 +++++++++++++++++++++ .../qt3d/deferred-renderer-cpp/pointlightblock.cpp | 59 ++++++ .../qt3d/deferred-renderer-cpp/pointlightblock.h | 60 ++++++ .../qt3d/deferred-renderer-cpp/sceneeffect.cpp | 89 +++++++++ examples/qt3d/deferred-renderer-cpp/sceneeffect.h | 58 ++++++ 21 files changed, 1151 insertions(+) create mode 100644 examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.pro create mode 100644 examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.qrc create mode 100644 examples/qt3d/deferred-renderer-cpp/deferredrenderer.cpp create mode 100644 examples/qt3d/deferred-renderer-cpp/deferredrenderer.h create mode 100644 examples/qt3d/deferred-renderer-cpp/final_gl2.frag create mode 100644 examples/qt3d/deferred-renderer-cpp/final_gl2.vert create mode 100644 examples/qt3d/deferred-renderer-cpp/final_gl3.frag create mode 100644 examples/qt3d/deferred-renderer-cpp/final_gl3.vert create mode 100644 examples/qt3d/deferred-renderer-cpp/finaleffect.cpp create mode 100644 examples/qt3d/deferred-renderer-cpp/finaleffect.h create mode 100644 examples/qt3d/deferred-renderer-cpp/gbuffer.cpp create mode 100644 examples/qt3d/deferred-renderer-cpp/gbuffer.h create mode 100644 examples/qt3d/deferred-renderer-cpp/geometry_gl2.frag create mode 100644 examples/qt3d/deferred-renderer-cpp/geometry_gl2.vert create mode 100644 examples/qt3d/deferred-renderer-cpp/geometry_gl3.frag create mode 100644 examples/qt3d/deferred-renderer-cpp/geometry_gl3.vert create mode 100644 examples/qt3d/deferred-renderer-cpp/main.cpp create mode 100644 examples/qt3d/deferred-renderer-cpp/pointlightblock.cpp create mode 100644 examples/qt3d/deferred-renderer-cpp/pointlightblock.h create mode 100644 examples/qt3d/deferred-renderer-cpp/sceneeffect.cpp create mode 100644 examples/qt3d/deferred-renderer-cpp/sceneeffect.h (limited to 'examples/qt3d/deferred-renderer-cpp') diff --git a/examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.pro b/examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.pro new file mode 100644 index 000000000..eaebea4ed --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.pro @@ -0,0 +1,33 @@ +TEMPLATE = app + +QT += 3dcore 3drenderer 3dinput + +include("../exampleresources/exampleresources.pri") + +HEADERS += \ + gbuffer.h \ + deferredrenderer.h \ + finaleffect.h \ + sceneeffect.h \ + pointlightblock.h + +SOURCES += \ + main.cpp \ + gbuffer.cpp \ + deferredrenderer.cpp \ + finaleffect.cpp \ + sceneeffect.cpp \ + pointlightblock.cpp + +RESOURCES += \ + deferred-renderer-cpp.qrc + +OTHER_FILES += \ + geometry_gl2.vert \ + geometry_gl2.frag \ + geometry_gl3.frag \ + geometry_gl3.vert \ + final_gl2.vert \ + final_gl2.frag \ + final_gl3.frag \ + final_gl3.vert diff --git a/examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.qrc b/examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.qrc new file mode 100644 index 000000000..0e38e39ca --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/deferred-renderer-cpp.qrc @@ -0,0 +1,12 @@ + + + geometry_gl2.frag + geometry_gl2.vert + geometry_gl3.frag + geometry_gl3.vert + final_gl2.frag + final_gl2.vert + final_gl3.frag + final_gl3.vert + + diff --git a/examples/qt3d/deferred-renderer-cpp/deferredrenderer.cpp b/examples/qt3d/deferred-renderer-cpp/deferredrenderer.cpp new file mode 100644 index 000000000..dc04e0398 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/deferredrenderer.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "deferredrenderer.h" + + +DeferredRenderer::DeferredRenderer(Qt3D::QNode *parent) + : Qt3D::QViewport(parent) + , m_sceneFilter(new Qt3D::QLayerFilter(this)) + , m_screenQuadFilter(new Qt3D::QLayerFilter(this)) + , m_clearScreenQuad(new Qt3D::QClearBuffer(m_screenQuadFilter)) + , m_gBufferTargetSelector(new Qt3D::QRenderTargetSelector(m_sceneFilter)) + , m_clearGBuffer(new Qt3D::QClearBuffer(m_gBufferTargetSelector)) + , m_geometryPassFilter(new Qt3D::QRenderPassFilter(m_clearGBuffer)) + , m_finalPassFilter(new Qt3D::QRenderPassFilter(m_clearScreenQuad)) + , m_sceneCameraSelector(new Qt3D::QCameraSelector(m_geometryPassFilter)) +{ + m_clearGBuffer->setBuffers(Qt3D::QClearBuffer::ColorDepthBuffer); + m_clearScreenQuad->setBuffers(Qt3D::QClearBuffer::ColorDepthBuffer); +} + +void DeferredRenderer::setSceneCamera(Qt3D::QEntity *camera) +{ + m_sceneCameraSelector->setCamera(camera); +} + +void DeferredRenderer::setGBuffer(Qt3D::QRenderTarget *gBuffer) +{ + m_gBufferTargetSelector->setTarget(gBuffer); +} + +void DeferredRenderer::setGeometryPassCriteria(QList criteria) +{ + Q_FOREACH (Qt3D::QAnnotation *c, criteria) + m_geometryPassFilter->addInclude(c); +} + +void DeferredRenderer::setFinalPassCriteria(QList criteria) +{ + Q_FOREACH (Qt3D::QAnnotation *c, criteria) + c->setParent(m_finalPassFilter); +} + +void DeferredRenderer::setGBufferLayers(const QStringList &layerNames) +{ + m_sceneFilter->setLayers(layerNames); +} + +void DeferredRenderer::setScreenQuadLayers(const QStringList &layerNames) +{ + m_screenQuadFilter->setLayers(layerNames); +} diff --git a/examples/qt3d/deferred-renderer-cpp/deferredrenderer.h b/examples/qt3d/deferred-renderer-cpp/deferredrenderer.h new file mode 100644 index 000000000..34c09175c --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/deferredrenderer.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DEFERREDRENDERER_H +#define DEFERREDRENDERER_H + +#include +#include +#include +#include +#include +#include +#include + +class DeferredRenderer : public Qt3D::QViewport +{ +public: + explicit DeferredRenderer(Qt3D::QNode *parent = 0); + + void setSceneCamera(Qt3D::QEntity *camera); + void setGBuffer(Qt3D::QRenderTarget *gBuffer); + void setGeometryPassCriteria(QList criteria); + void setFinalPassCriteria(QList criteria); + void setGBufferLayers(const QStringList &layerName); + void setScreenQuadLayers(const QStringList &layerName); + +private: + Qt3D::QLayerFilter *m_sceneFilter; + Qt3D::QLayerFilter *m_screenQuadFilter; + Qt3D::QClearBuffer *m_clearScreenQuad; + Qt3D::QRenderTargetSelector *m_gBufferTargetSelector; + Qt3D::QClearBuffer *m_clearGBuffer; + Qt3D::QRenderPassFilter *m_geometryPassFilter; + Qt3D::QRenderPassFilter *m_finalPassFilter; + Qt3D::QCameraSelector *m_sceneCameraSelector; +}; + +#endif // DEFERREDRENDERER_H diff --git a/examples/qt3d/deferred-renderer-cpp/final_gl2.frag b/examples/qt3d/deferred-renderer-cpp/final_gl2.frag new file mode 100644 index 000000000..f384a2df4 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/final_gl2.frag @@ -0,0 +1,36 @@ +#version 110 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform vec2 winSize; + +struct PointLight +{ + vec3 position; + vec3 direction; + vec4 color; + float intensity; +}; + +const int lightCount = 3; +uniform struct +{ + PointLight lights[lightCount]; +} pointLights; + +void main() +{ + vec2 texCoord = gl_FragCoord.xy / winSize; + vec4 col = texture2D(color, texCoord); + vec3 pos = texture2D(position, texCoord).xyz; + vec3 norm = texture2D(normal, texCoord).xyz; + + vec4 lightColor; + for (int i = 0; i < 3; i++) { + vec3 s = normalize(pointLights.lights[i].position - pos); + lightColor += pointLights.lights[i].color * (pointLights.lights[i].intensity * max(dot(s, norm), 0.0)); + } + lightColor /= float(lightCount); + gl_FragColor = col * lightColor; +} diff --git a/examples/qt3d/deferred-renderer-cpp/final_gl2.vert b/examples/qt3d/deferred-renderer-cpp/final_gl2.vert new file mode 100644 index 000000000..a907e10ca --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/final_gl2.vert @@ -0,0 +1,9 @@ +#version 110 + +attribute vec4 vertexPosition; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = modelMatrix * vertexPosition; +} diff --git a/examples/qt3d/deferred-renderer-cpp/final_gl3.frag b/examples/qt3d/deferred-renderer-cpp/final_gl3.frag new file mode 100644 index 000000000..88abd5cb1 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/final_gl3.frag @@ -0,0 +1,37 @@ +#version 140 + +uniform sampler2D color; +uniform sampler2D position; +uniform sampler2D normal; +uniform vec2 winSize; + +out vec4 fragColor; + +struct PointLight +{ + vec3 position; + vec3 direction; + vec4 color; + float intensity; +}; + +const int lightCount = 3; +uniform PointLightBlock { + PointLight lights[lightCount]; +}; + +void main() +{ + vec2 texCoord = gl_FragCoord.xy / winSize; + vec4 col = texture(color, texCoord); + vec3 pos = texture(position, texCoord).xyz; + vec3 norm = texture(normal, texCoord).xyz; + + vec4 lightColor; + for (int i = 0; i < 3; i++) { + vec3 s = normalize(lights[i].position - pos); + lightColor += lights[i].color * (lights[i].intensity * max(dot(s, norm), 0.0)); + } + lightColor /= float(lightCount); + fragColor = col * lightColor; +} diff --git a/examples/qt3d/deferred-renderer-cpp/final_gl3.vert b/examples/qt3d/deferred-renderer-cpp/final_gl3.vert new file mode 100644 index 000000000..60410d34d --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/final_gl3.vert @@ -0,0 +1,9 @@ +#version 140 + +in vec4 vertexPosition; +uniform mat4 modelMatrix; + +void main() +{ + gl_Position = modelMatrix * vertexPosition; +} diff --git a/examples/qt3d/deferred-renderer-cpp/finaleffect.cpp b/examples/qt3d/deferred-renderer-cpp/finaleffect.cpp new file mode 100644 index 000000000..96134c297 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/finaleffect.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "finaleffect.h" + +#include +#include +#include + +FinalEffect::FinalEffect(Qt3D::QNode *parent) + : Qt3D::QEffect(parent) + , m_gl3Technique(new Qt3D::QTechnique()) + , m_gl2Technique(new Qt3D::QTechnique()) + , m_gl2Pass(new Qt3D::QRenderPass()) + , m_gl3Pass(new Qt3D::QRenderPass()) + , m_passCriterion(new Qt3D::QAnnotation(this)) +{ + m_gl3Technique->openGLFilter()->setApi(Qt3D::QOpenGLFilter::Desktop); + m_gl3Technique->openGLFilter()->setMajorVersion(3); + m_gl3Technique->openGLFilter()->setMinorVersion(1); + m_gl3Technique->openGLFilter()->setProfile(Qt3D::QOpenGLFilter::Core); + + m_gl2Technique->openGLFilter()->setApi(Qt3D::QOpenGLFilter::Desktop); + m_gl2Technique->openGLFilter()->setMajorVersion(2); + m_gl2Technique->openGLFilter()->setMinorVersion(0); + m_gl2Technique->openGLFilter()->setProfile(Qt3D::QOpenGLFilter::None); + + m_passCriterion->setName(QStringLiteral("pass")); + m_passCriterion->setValue(QStringLiteral("final")); + + Qt3D::QShaderProgram *gl3Shader = new Qt3D::QShaderProgram(); + gl3Shader->setVertexShaderCode(gl3Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl3.vert")))); + gl3Shader->setFragmentShaderCode(gl3Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl3.frag")))); + + m_gl3Pass->addAnnotation(m_passCriterion); + m_gl3Pass->setShaderProgram(gl3Shader); + m_gl3Technique->addPass(m_gl3Pass); + + Qt3D::QShaderProgram *gl2Shader = new Qt3D::QShaderProgram(); + gl2Shader->setVertexShaderCode(gl2Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl2.vert")))); + gl2Shader->setFragmentShaderCode(gl2Shader->loadSource(QUrl(QStringLiteral("qrc:/final_gl2.frag")))); + + m_gl2Pass->addAnnotation(m_passCriterion); + m_gl2Pass->setShaderProgram(gl2Shader); + m_gl2Technique->addPass(m_gl2Pass); + + addTechnique(m_gl3Technique); + addTechnique(m_gl2Technique); +} + +QList FinalEffect::passCriteria() const +{ + return QList() << m_passCriterion; +} diff --git a/examples/qt3d/deferred-renderer-cpp/finaleffect.h b/examples/qt3d/deferred-renderer-cpp/finaleffect.h new file mode 100644 index 000000000..11fb4c6f3 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/finaleffect.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FINALEFFECT_H +#define FINALEFFECT_H + +#include +#include + +class FinalEffect : public Qt3D::QEffect +{ +public: + explicit FinalEffect(Qt3D::QNode *parent = 0); + + QList passCriteria() const; + inline Qt3D::QTechnique *gl3Technique() const { return m_gl3Technique; } + inline Qt3D::QTechnique *gl2Technique() const { return m_gl2Technique; } + +private : + Qt3D::QTechnique *m_gl3Technique; + Qt3D::QTechnique *m_gl2Technique; + Qt3D::QRenderPass *m_gl2Pass; + Qt3D::QRenderPass *m_gl3Pass; + Qt3D::QAnnotation *m_passCriterion; +}; + +#endif // FINALEFFECT_H diff --git a/examples/qt3d/deferred-renderer-cpp/gbuffer.cpp b/examples/qt3d/deferred-renderer-cpp/gbuffer.cpp new file mode 100644 index 000000000..a05adfc72 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/gbuffer.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "gbuffer.h" + +GBuffer::GBuffer(Qt3D::QNode *parent) + : Qt3D::QRenderTarget(parent) +{ + const Qt3D::QAbstractTextureProvider::TextureFormat formats[AttachmentsCount] = { + Qt3D::QAbstractTextureProvider::RGBA32F, + Qt3D::QAbstractTextureProvider::RGB32F, + Qt3D::QAbstractTextureProvider::RGB16F, + Qt3D::QAbstractTextureProvider::D32F + }; + + const Qt3D::QRenderAttachment::RenderAttachmentType attachmentTypes[AttachmentsCount] = { + Qt3D::QRenderAttachment::ColorAttachment0, + Qt3D::QRenderAttachment::ColorAttachment1, + Qt3D::QRenderAttachment::ColorAttachment2, + Qt3D::QRenderAttachment::DepthAttachment + }; + + const QString attachmentNames[AttachmentsCount] = { + QString::fromLatin1("color"), + QString::fromLatin1("position"), + QString::fromLatin1("normal"), + QString::fromLatin1("depth") + }; + + for (int i = 0; i < AttachmentsCount; i++) { + Qt3D::QRenderAttachment *attachment = new Qt3D::QRenderAttachment(this); + + m_textures[i] = new Qt3D::QTexture2D(); + m_textures[i]->setFormat(formats[i]); + m_textures[i]->setWidth(1024); + m_textures[i]->setHeight(1024); + m_textures[i]->setGenerateMipMaps(false); + m_textures[i]->setWrapMode(Qt3D::QTextureWrapMode(Qt3D::QTextureWrapMode::ClampToEdge)); + m_textures[i]->setMinificationFilter(Qt3D::QAbstractTextureProvider::Linear); + m_textures[i]->setMagnificationFilter(Qt3D::QAbstractTextureProvider::Linear); + + attachment->setTexture(m_textures[i]); + attachment->setType(attachmentTypes[i]); + attachment->setName(attachmentNames[i]); + + addAttachment(attachment); + } +} + +Qt3D::QAbstractTextureProvider *GBuffer::colorTexture() const +{ + return m_textures[Color]; +} + +Qt3D::QAbstractTextureProvider *GBuffer::positionTexture() const +{ + return m_textures[Position]; +} + +Qt3D::QAbstractTextureProvider *GBuffer::normalTexture() const +{ + return m_textures[Normal]; +} + +Qt3D::QAbstractTextureProvider *GBuffer::depthTexture() const +{ + return m_textures[Depth]; +} diff --git a/examples/qt3d/deferred-renderer-cpp/gbuffer.h b/examples/qt3d/deferred-renderer-cpp/gbuffer.h new file mode 100644 index 000000000..1302fbb66 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/gbuffer.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GBUFFER_H +#define GBUFFER_H + +#include +#include +#include + +class GBuffer : public Qt3D::QRenderTarget +{ +public: + explicit GBuffer(Qt3D::QNode *parent = 0); + + enum Attachments { + Color = 0, + Position, + Normal, + Depth, + AttachmentsCount + }; + + Qt3D::QAbstractTextureProvider *colorTexture() const; + Qt3D::QAbstractTextureProvider *positionTexture() const; + Qt3D::QAbstractTextureProvider *normalTexture() const; + Qt3D::QAbstractTextureProvider *depthTexture() const; + +private: + Qt3D::QAbstractTextureProvider *m_textures[AttachmentsCount]; + Qt3D::QRenderAttachment *m_attachments[AttachmentsCount]; +}; + +#endif // GBUFFER_H diff --git a/examples/qt3d/deferred-renderer-cpp/geometry_gl2.frag b/examples/qt3d/deferred-renderer-cpp/geometry_gl2.frag new file mode 100644 index 000000000..0e7776f15 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/geometry_gl2.frag @@ -0,0 +1,12 @@ +#version 110 + +varying vec4 color0; +varying vec3 position0; +varying vec3 normal0; + +void main() +{ + gl_FragData[0] = color0; + gl_FragData[1] = vec4(position0, 0); + gl_FragData[2] = vec4(normal0, 0); +} diff --git a/examples/qt3d/deferred-renderer-cpp/geometry_gl2.vert b/examples/qt3d/deferred-renderer-cpp/geometry_gl2.vert new file mode 100644 index 000000000..72d5345f1 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/geometry_gl2.vert @@ -0,0 +1,21 @@ +#version 110 + +attribute vec4 vertexPosition; +attribute vec3 vertexNormal; + +varying vec4 color0; +varying vec3 position0; +varying vec3 normal0; + +uniform mat4 mvp; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform vec4 meshColor; + +void main() +{ + color0 = meshColor; + position0 = vec3(modelView * vertexPosition); + normal0 = normalize(modelViewNormal * vertexNormal); + gl_Position = mvp * vertexPosition; +} diff --git a/examples/qt3d/deferred-renderer-cpp/geometry_gl3.frag b/examples/qt3d/deferred-renderer-cpp/geometry_gl3.frag new file mode 100644 index 000000000..7d9c7d64e --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/geometry_gl3.frag @@ -0,0 +1,16 @@ +#version 140 + +in vec4 color0; +in vec3 position0; +in vec3 normal0; + +out vec4 color; +out vec3 position; +out vec3 normal; + +void main() +{ + color = color0; + position = position0; + normal = normal0; +} diff --git a/examples/qt3d/deferred-renderer-cpp/geometry_gl3.vert b/examples/qt3d/deferred-renderer-cpp/geometry_gl3.vert new file mode 100644 index 000000000..d3e302d16 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/geometry_gl3.vert @@ -0,0 +1,21 @@ +#version 140 + +in vec4 vertexPosition; +in vec3 vertexNormal; + +out vec4 color0; +out vec3 position0; +out vec3 normal0; + +uniform mat4 mvp; +uniform mat4 modelView; +uniform mat3 modelViewNormal; +uniform vec4 meshColor; + +void main() +{ + color0 = meshColor; + position0 = vec3(modelView * vertexPosition); + normal0 = normalize(modelViewNormal * vertexNormal); + gl_Position = mvp * vertexPosition; +} diff --git a/examples/qt3d/deferred-renderer-cpp/main.cpp b/examples/qt3d/deferred-renderer-cpp/main.cpp new file mode 100644 index 000000000..24814585f --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/main.cpp @@ -0,0 +1,208 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "gbuffer.h" +#include "deferredrenderer.h" +#include "finaleffect.h" +#include "sceneeffect.h" +#include "pointlightblock.h" + +int main(int ac, char **av) +{ + QGuiApplication app(ac, av); + + Qt3D::Window view; + Qt3D::QAspectEngine engine; + engine.registerAspect(new Qt3D::QRenderAspect()); + Qt3D::QInputAspect *input = new Qt3D::QInputAspect; + engine.registerAspect(input); + engine.initialize(); + QVariantMap data; + data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast(&view))); + data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view)); + engine.setData(data); + + // Root entity + Qt3D::QEntity *rootEntity = new Qt3D::QEntity(); + rootEntity->setObjectName(QStringLiteral("rootEntity")); + + // Shared Components + GBuffer *gBuffer = new GBuffer(); + FinalEffect *finalEffect = new FinalEffect(); + SceneEffect *sceneEffect = new SceneEffect(); + + Qt3D::QSphereMesh *sphereMesh = new Qt3D::QSphereMesh(); + sphereMesh->setRings(50); + sphereMesh->setSlices(100); + + Qt3D::QLayer *sceneLayer = new Qt3D::QLayer(); + sceneLayer->setNames(QStringList("scene")); + + Qt3D::QLayer *quadLayer = new Qt3D::QLayer(); + quadLayer->setNames(QStringList("screenQuad")); + + Qt3D::QPlaneMesh *planeMesh = new Qt3D::QPlaneMesh(); + planeMesh->setMeshResolution(QSize(2, 2)); + planeMesh->setWidth(2.0f); + planeMesh->setHeight(2.0f); + + Qt3D::QPointLight *light1 = new Qt3D::QPointLight(); + light1->setColor(Qt::white); + light1->setIntensity(1.5f); + + rootEntity->addComponent(light1); + + // Scene Camera + Qt3D::QCamera *camera = new Qt3D::QCamera(); + + camera->setAspectRatio(16.0f/9.0f); + camera->setFieldOfView(45.0f); + camera->setNearPlane(0.01f); + camera->setFarPlane(1000.0f); + camera->setProjectionType(Qt3D::QCameraLens::PerspectiveProjection); + + camera->setPosition(QVector3D(10.0f, 10.0f, -25.0f)); + camera->setUpVector(QVector3D(0.0f, 1.0f, 0.0f)); + camera->setViewCenter(QVector3D(0.0f, 0.0f, 10.0f)); + + input->setCamera(camera); + + // FrameGraph + Qt3D::QFrameGraph *frameGraph = new Qt3D::QFrameGraph(); + DeferredRenderer *deferredRenderer = new DeferredRenderer(); + deferredRenderer->setClearColor(Qt::black); + deferredRenderer->setRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f)); + deferredRenderer->setFinalPassCriteria(finalEffect->passCriteria()); + deferredRenderer->setGeometryPassCriteria(sceneEffect->passCriteria()); + deferredRenderer->setGBuffer(gBuffer); + deferredRenderer->setSceneCamera(camera); + deferredRenderer->setGBufferLayers(sceneLayer->names()); + deferredRenderer->setScreenQuadLayers(quadLayer->names()); + + frameGraph->setActiveFrameGraph(deferredRenderer); + rootEntity->addComponent(frameGraph); + + // Scene Content + Qt3D::QEntity *sphereOne = new Qt3D::QEntity(rootEntity); + Qt3D::QMaterial *sphereOneMaterial = new Qt3D::QMaterial(); + + sphereOneMaterial->setEffect(sceneEffect); + sphereOneMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("meshColor"), QColor(Qt::blue))); + + Qt3D::QTranslateTransform *sphereOneTranslate = new Qt3D::QTranslateTransform(); + sphereOneTranslate->setDx(-10.0f); + sphereOneTranslate->setDy(0.0f); + sphereOneTranslate->setDz(25.0f); + + Qt3D::QPointLight *light2 = new Qt3D::QPointLight(); + light2->setColor(Qt::white); + light2->setIntensity(1.5f); + + sphereOne->addComponent(new Qt3D::QTransform(sphereOneTranslate)); + sphereOne->addComponent(sphereOneMaterial); + sphereOne->addComponent(sphereMesh); + sphereOne->addComponent(sceneLayer); + sphereOne->addComponent(light2); + + Qt3D::QEntity *sphereTwo = new Qt3D::QEntity(rootEntity); + Qt3D::QMaterial *sphereTwoMaterial = new Qt3D::QMaterial(); + sphereTwoMaterial->setEffect(sceneEffect); + sphereTwoMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("meshColor"), QColor(Qt::yellow))); + + Qt3D::QPointLight *light3 = new Qt3D::QPointLight(); + light3->setColor(Qt::blue); + light3->setIntensity(0.5f); + + sphereTwo->addComponent(sphereMesh); + sphereTwo->addComponent(sceneLayer); + sphereTwo->addComponent(sphereTwoMaterial); + sphereTwo->addComponent(light3); + + // Screen Quad + Qt3D::QEntity *screenQuad = new Qt3D::QEntity(rootEntity); + Qt3D::QMaterial *screenQuadMaterial = new Qt3D::QMaterial(); + screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("position"), gBuffer->positionTexture())); + screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("normal"), gBuffer->normalTexture())); + screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("color"), gBuffer->colorTexture())); + screenQuadMaterial->addParameter(new Qt3D::QParameter(QStringLiteral("winSize"), QSize(1024, 1024))); + PointLightBlock *lightsData = new PointLightBlock(screenQuadMaterial); + lightsData->addLight(light1); + lightsData->addLight(light2); + lightsData->addLight(light3); + + finalEffect->gl3Technique()->addParameter(new Qt3D::QParameter(QStringLiteral("PointLightBlock"), QVariant::fromValue(lightsData))); + finalEffect->gl2Technique()->addParameter(new Qt3D::QParameter(QStringLiteral("pointLights"), QVariant::fromValue(lightsData))); + screenQuadMaterial->setEffect(finalEffect); + + Qt3D::QRotateTransform *screenPlaneRotation = new Qt3D::QRotateTransform(); + screenPlaneRotation->setAngleDeg(90); + screenPlaneRotation->setAxis(QVector3D(1.0f, 0.0f, 0.0f)); + + screenQuad->addComponent(quadLayer); + screenQuad->addComponent(new Qt3D::QTransform(screenPlaneRotation)); + screenQuad->addComponent(screenQuadMaterial); + screenQuad->addComponent(planeMesh); + + // Set root object of the scene + engine.setRootEntity(rootEntity); + // Show window + view.show(); + + return app.exec(); +} diff --git a/examples/qt3d/deferred-renderer-cpp/pointlightblock.cpp b/examples/qt3d/deferred-renderer-cpp/pointlightblock.cpp new file mode 100644 index 000000000..07d77fd7a --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/pointlightblock.cpp @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "pointlightblock.h" + +PointLightBlock::PointLightBlock(Qt3D::QNode *parent) + : Qt3D::QShaderData(parent) +{ + +} + +PointLightBlock::~PointLightBlock() +{ +} + +QList PointLightBlock::lights() const +{ + return m_lights; +} + +void PointLightBlock::addLight(Qt3D::QShaderData *light) +{ + m_lights.append(light); + emit lightsChanged(); +} + diff --git a/examples/qt3d/deferred-renderer-cpp/pointlightblock.h b/examples/qt3d/deferred-renderer-cpp/pointlightblock.h new file mode 100644 index 000000000..8fb470504 --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/pointlightblock.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef POINTLIGHTBLOCK_H +#define POINTLIGHTBLOCK_H + +#include + +class PointLightBlock : public Qt3D::QShaderData +{ + Q_OBJECT + Q_PROPERTY(QList lights READ lights NOTIFY lightsChanged) +public: + explicit PointLightBlock(Qt3D::QNode *parent = 0); + ~PointLightBlock(); + + QList lights() const; + void addLight(QShaderData *light); + +Q_SIGNALS: + void lightsChanged(); + +private: + QList m_lights; +}; + +#endif // POINTLIGHTBLOCK_H diff --git a/examples/qt3d/deferred-renderer-cpp/sceneeffect.cpp b/examples/qt3d/deferred-renderer-cpp/sceneeffect.cpp new file mode 100644 index 000000000..98eb677ed --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/sceneeffect.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sceneeffect.h" + +#include +#include +#include + +SceneEffect::SceneEffect(Qt3D::QNode *parent) + : Qt3D::QEffect(parent) + , m_gl3Technique(new Qt3D::QTechnique()) + , m_gl2Technique(new Qt3D::QTechnique()) + , m_gl2Pass(new Qt3D::QRenderPass()) + , m_gl3Pass(new Qt3D::QRenderPass()) + , m_passCriterion(new Qt3D::QAnnotation(this)) +{ + + m_gl3Technique->openGLFilter()->setProfile(Qt3D::QOpenGLFilter::None); + m_gl3Technique->openGLFilter()->setApi(Qt3D::QOpenGLFilter::Desktop); + m_gl3Technique->openGLFilter()->setMajorVersion(3); + m_gl3Technique->openGLFilter()->setMinorVersion(3); + + m_gl2Technique->openGLFilter()->setApi(Qt3D::QOpenGLFilter::Desktop); + m_gl2Technique->openGLFilter()->setMajorVersion(2); + m_gl2Technique->openGLFilter()->setMinorVersion(0); + m_gl2Technique->openGLFilter()->setProfile(Qt3D::QOpenGLFilter::None); + + + m_passCriterion->setName(QStringLiteral("pass")); + m_passCriterion->setValue(QStringLiteral("geometry")); + + Qt3D::QShaderProgram *gl3Shader = new Qt3D::QShaderProgram(); + gl3Shader->setVertexShaderCode(Qt3D::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl3.vert")))); + gl3Shader->setFragmentShaderCode(Qt3D::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl3.frag")))); + + m_gl3Pass->addAnnotation(m_passCriterion); + m_gl3Pass->setShaderProgram(gl3Shader); + m_gl3Technique->addPass(m_gl3Pass); + + Qt3D::QShaderProgram *gl2Shader = new Qt3D::QShaderProgram(); + gl2Shader->setVertexShaderCode(Qt3D::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl2.vert")))); + gl2Shader->setFragmentShaderCode(Qt3D::QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/geometry_gl2.frag")))); + + m_gl2Pass->addAnnotation(m_passCriterion); + m_gl2Pass->setShaderProgram(gl2Shader); + m_gl2Technique->addPass(m_gl2Pass); + + addTechnique(m_gl3Technique); + addTechnique(m_gl2Technique); +} + +QList SceneEffect::passCriteria() const +{ + return QList() << m_passCriterion; +} diff --git a/examples/qt3d/deferred-renderer-cpp/sceneeffect.h b/examples/qt3d/deferred-renderer-cpp/sceneeffect.h new file mode 100644 index 000000000..18a869bfe --- /dev/null +++ b/examples/qt3d/deferred-renderer-cpp/sceneeffect.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SCENEEFFECT_H +#define SCENEEFFECT_H + +#include +#include + +class SceneEffect : public Qt3D::QEffect +{ +public: + explicit SceneEffect(Qt3D::QNode *parent = 0); + + QList passCriteria() const; + +private: + Qt3D::QTechnique *m_gl3Technique; + Qt3D::QTechnique *m_gl2Technique; + Qt3D::QRenderPass *m_gl2Pass; + Qt3D::QRenderPass *m_gl3Pass; + Qt3D::QAnnotation *m_passCriterion; +}; + +#endif // SCENEEFFECT_H -- cgit v1.2.3