Qt 4.8
qglcustomshaderstage.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qglcustomshaderstage_p.h"
45 #include <private/qpainter_p.h>
46 
48 
50 {
51 public:
53  m_manager(0) {}
54 
57 };
58 
59 
60 
61 
63  : d_ptr(new QGLCustomShaderStagePrivate)
64 {
65 }
66 
68 {
70  if (d->m_manager) {
71  d->m_manager->removeCustomStage();
72  d->m_manager->sharedShaders->cleanupCustomStage(this);
73  }
74 }
75 
77 {
79  if (d->m_manager)
80  d->m_manager->setDirty(); // ### Probably a bit overkill!
81 }
82 
84 {
86  if (p->paintEngine()->type() != QPaintEngine::OpenGL2) {
87  qWarning("QGLCustomShaderStage::setOnPainter() - paint engine not OpenGL2");
88  return false;
89  }
90  if (d->m_manager)
91  qWarning("Custom shader is already set on a painter");
92 
93  QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx*>(p->paintEngine());
95  Q_ASSERT(d->m_manager);
96 
97  d->m_manager->setCustomStage(this);
98  return true;
99 }
100 
102 {
104  if (p->paintEngine()->type() != QPaintEngine::OpenGL2)
105  return;
106 
107  QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx*>(p->paintEngine());
109  Q_ASSERT(d->m_manager);
110 
111  // Just set the stage to null, don't call removeCustomStage().
112  // This should leave the program in a compiled/linked state
113  // if the next custom shader stage is this one again.
114  d->m_manager->setCustomStage(0);
115  d->m_manager = 0;
116 }
117 
119 {
120  Q_D(const QGLCustomShaderStage);
121  return d->m_source;
122 }
123 
124 // Called by the shader manager if another custom shader is attached or
125 // the manager is deleted
127 {
129  d->m_manager = 0;
130 }
131 
133 {
135  d->m_source = s;
136 }
137 
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
static QGLEngineShaderManager * shaderManagerForEngine(QGL2PaintEngineEx *engine)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void setSource(const QByteArray &)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
Q_CORE_EXPORT void qWarning(const char *,...)
QPointer< QGLEngineShaderManager > m_manager
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
bool setOnPainter(QPainter *)
void removeFromPainter(QPainter *)