1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 The Qt Company Ltd. |
4 | ** Contact: http://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #include <Qt3DRender/QParameter> |
38 | #include <Qt3DRender/QEffect> |
39 | #include <Qt3DRender/QTechnique> |
40 | #include <Qt3DRender/QAbstractTexture> |
41 | #include <Qt3DRender/QShaderProgram> |
42 | #include <Qt3DRender/QRenderPass> |
43 | #include <Qt3DRender/QBlendEquation> |
44 | #include <Qt3DRender/QBlendEquationArguments> |
45 | #include <Qt3DRender/QFilterKey> |
46 | #include <Qt3DRender/QGraphicsApiFilter> |
47 | #include <QColor> |
48 | #include <QVector2D> |
49 | #include <QUrl> |
50 | |
51 | #include "planematerial.h" |
52 | |
53 | PlaneMaterial::PlaneMaterial(Qt3DRender::QAbstractTexture *texture, Qt3DCore::QNode *parent) |
54 | : QMaterial(parent) |
55 | , m_effect(new Qt3DRender::QEffect(this)) |
56 | , m_texture(texture) |
57 | { |
58 | setEffect(m_effect); |
59 | |
60 | m_texCoordScaleParam = new Qt3DRender::QParameter(QStringLiteral("texCoordScale" ), QVector2D(1.0f, -1.0f)); |
61 | m_texCoordBiasParam = new Qt3DRender::QParameter(QStringLiteral("texCoordBias" ), QVector2D(0.0f, 1.0f)); |
62 | m_textureParam = new Qt3DRender::QParameter(QStringLiteral("surfaceTexture" ), m_texture); |
63 | |
64 | m_effect->addParameter(parameter: m_texCoordScaleParam); |
65 | m_effect->addParameter(parameter: m_texCoordBiasParam); |
66 | m_effect->addParameter(parameter: m_textureParam); |
67 | |
68 | m_filter = new Qt3DRender::QFilterKey(this); |
69 | m_filter->setName(QStringLiteral("renderingStyle" )); |
70 | m_filter->setValue(QStringLiteral("forward" )); |
71 | |
72 | m_techniqueGLES = new Qt3DRender::QTechnique(m_effect); |
73 | m_techniqueGL3 = new Qt3DRender::QTechnique(m_effect); |
74 | m_techniqueGL2 = new Qt3DRender::QTechnique(m_effect); |
75 | |
76 | m_techniqueGLES->addFilterKey(filterKey: m_filter); |
77 | m_techniqueGL3->addFilterKey(filterKey: m_filter); |
78 | m_techniqueGL2->addFilterKey(filterKey: m_filter); |
79 | |
80 | m_effect->addTechnique(t: m_techniqueGLES); |
81 | m_effect->addTechnique(t: m_techniqueGL3); |
82 | m_effect->addTechnique(t: m_techniqueGL2); |
83 | |
84 | m_programGLES = new Qt3DRender::QShaderProgram(m_effect); |
85 | m_programGLES->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/es2/texturing.vert" )))); |
86 | m_programGLES->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/es2/texturing.frag" )))); |
87 | |
88 | m_programGL3 = new Qt3DRender::QShaderProgram(m_effect); |
89 | m_programGL3->setVertexShaderCode(Qt3DRender::QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/gl3/texturing.vert" )))); |
90 | m_programGL3->setFragmentShaderCode(Qt3DRender::QShaderProgram::loadSource(sourceUrl: QUrl(QStringLiteral("qrc:/shaders/gl3/texturing.frag" )))); |
91 | |
92 | m_renderPassGLES = new Qt3DRender::QRenderPass(m_effect); |
93 | m_renderPassGL3 = new Qt3DRender::QRenderPass(m_effect); |
94 | m_renderPassGL2 = new Qt3DRender::QRenderPass(m_effect); |
95 | |
96 | m_renderPassGLES->setShaderProgram(m_programGLES); |
97 | m_renderPassGL3->setShaderProgram(m_programGL3); |
98 | m_renderPassGL2->setShaderProgram(m_programGL3); |
99 | |
100 | m_techniqueGL2->addRenderPass(pass: m_renderPassGL2); |
101 | m_techniqueGLES->addRenderPass(pass: m_renderPassGLES); |
102 | m_techniqueGL3->addRenderPass(pass: m_renderPassGL3); |
103 | |
104 | m_techniqueGLES->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGLES); |
105 | m_techniqueGLES->graphicsApiFilter()->setMajorVersion(2); |
106 | m_techniqueGLES->graphicsApiFilter()->setMinorVersion(0); |
107 | m_techniqueGLES->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile); |
108 | |
109 | m_techniqueGL2->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); |
110 | m_techniqueGL2->graphicsApiFilter()->setMajorVersion(2); |
111 | m_techniqueGL2->graphicsApiFilter()->setMinorVersion(0); |
112 | m_techniqueGL2->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::NoProfile); |
113 | |
114 | m_techniqueGL3->graphicsApiFilter()->setApi(Qt3DRender::QGraphicsApiFilter::OpenGL); |
115 | m_techniqueGL3->graphicsApiFilter()->setMajorVersion(3); |
116 | m_techniqueGL3->graphicsApiFilter()->setMinorVersion(1); |
117 | m_techniqueGL3->graphicsApiFilter()->setProfile(Qt3DRender::QGraphicsApiFilter::CoreProfile); |
118 | } |
119 | |
120 | |