1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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.
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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 //#include <GL/glew.h>
46 #include "glextensions.h"
51 #include "roundedbox.h"
52 #include "gltrianglemesh.h"
53 #include "trackball.h"
54 #include "glbuffers.h"
57 #define PI 3.14159265358979
63 class ParameterEdit : public QWidget
66 virtual void emitChange() = 0;
69 class ColorEdit : public ParameterEdit
73 ColorEdit(QRgb initialColor, int id);
74 QRgb color() const {return m_color;}
75 virtual void emitChange() {emit colorChanged(m_color, m_id);}
79 void colorChanged(QRgb color, int id);
81 virtual void mousePressEvent(QMouseEvent *event);
82 void setColor(QRgb color); // also emits colorChanged()
84 QGraphicsScene *m_dialogParentScene;
85 QLineEdit *m_lineEdit;
91 class FloatEdit : public ParameterEdit
95 FloatEdit(float initialValue, int id);
96 float value() const {return m_value;}
97 virtual void emitChange() {emit valueChanged(m_value, m_id);}
101 void valueChanged(float value, int id);
103 QGraphicsScene *m_dialogParentScene;
104 QLineEdit *m_lineEdit;
109 class GraphicsWidget : public QGraphicsProxyWidget
112 GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
114 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
115 virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
116 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
119 class TwoSidedGraphicsWidget : public QObject
123 TwoSidedGraphicsWidget(QGraphicsScene *scene);
124 void setWidget(int index, QWidget *widget);
125 QWidget *widget(int index);
131 GraphicsWidget *m_proxyWidgets[2];
133 int m_angle; // angle in degrees
137 class RenderOptionsDialog : public QDialog
141 RenderOptionsDialog();
142 int addTexture(const QString &name);
143 int addShader(const QString &name);
144 void emitParameterChanged();
146 void setColorParameter(QRgb color, int id);
147 void setFloatParameter(float value, int id);
149 void dynamicCubemapToggled(int);
150 void colorParameterChanged(const QString &, QRgb);
151 void floatParameterChanged(const QString &, float);
152 void textureChanged(int);
153 void shaderChanged(int);
154 void doubleClicked();
156 virtual void mouseDoubleClickEvent(QMouseEvent *event);
158 QVector<QByteArray> m_parameterNames;
159 QComboBox *m_textureCombo;
160 QComboBox *m_shaderCombo;
161 QVector<ParameterEdit *> m_parameterEdits;
164 class ItemDialog : public QDialog
176 void triggerNewQtBox();
177 void triggerNewCircleItem();
178 void triggerNewSquareItem();
180 void doubleClicked();
181 void newItemTriggered(ItemDialog::ItemType type);
183 virtual void mouseDoubleClickEvent(QMouseEvent *event);
186 class Scene : public QGraphicsScene
190 Scene(int width, int height, int maxTextureSize);
192 virtual void drawBackground(QPainter *painter, const QRectF &rect);
195 void setShader(int index);
196 void setTexture(int index);
197 void toggleDynamicCubemap(int state);
198 void setColorParameter(const QString &name, QRgb color);
199 void setFloatParameter(const QString &name, float value);
200 void newItem(ItemDialog::ItemType type);
202 void renderBoxes(const QMatrix4x4 &view, int excludeBox = -2);
205 void defaultStates();
206 void renderCubemaps();
208 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
209 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
210 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
211 virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
214 QPointF pixelPosToViewPos(const QPointF& p);
218 int m_mouseEventTime;
221 int m_maxTextureSize;
224 int m_currentTexture;
225 bool m_dynamicCubemap;
226 bool m_updateAllCubemaps;
228 RenderOptionsDialog *m_renderOptions;
229 ItemDialog *m_itemDialog;
232 TrackBall m_trackBalls[3];
233 QVector<GLTexture *> m_textures;
234 GLTextureCube *m_environment;
235 GLTexture3D *m_noise;
236 GLRenderTargetCube *m_mainCubemap;
237 QVector<GLRenderTargetCube *> m_cubemaps;
238 QVector<QGLShaderProgram *> m_programs;
239 QGLShader *m_vertexShader;
240 QVector<QGLShader *> m_fragmentShaders;
241 QGLShader *m_environmentShader;
242 QGLShaderProgram *m_environmentProgram;