1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | //
|
---|
43 | // W A R N I N G
|
---|
44 | // -------------
|
---|
45 | //
|
---|
46 | // This file is not part of the Qt API. It exists purely as an
|
---|
47 | // implementation detail. This header file may change from version to
|
---|
48 | // version without notice, or even be removed.
|
---|
49 | //
|
---|
50 | // We mean it.
|
---|
51 | //
|
---|
52 |
|
---|
53 | #include "qglshader_p.h"
|
---|
54 |
|
---|
55 |
|
---|
56 | // Worstcase combo: Brush->Mask->Composition
|
---|
57 |
|
---|
58 | /*
|
---|
59 | Vertex shader source is specified with a single string. This string
|
---|
60 | contains the main function and sets the gl_Position. The choice of
|
---|
61 | which vertex shader to use depends on:
|
---|
62 | - Brush style
|
---|
63 | - Brush transform->isAffine()
|
---|
64 |
|
---|
65 | Fragment shaders are specified as multiple strings, one for the main
|
---|
66 | function, one for the brush calculation and optionally one for the
|
---|
67 | extended composition mode. Brushes are implementations of
|
---|
68 | "mediump vec4 brush()"
|
---|
69 | Composition modes are implemented as a
|
---|
70 | "mediump vec4 compose(mediump vec4 color)"
|
---|
71 | NOTE: Precision may change in future.
|
---|
72 |
|
---|
73 | The choice of which main() fragment shader string to use depends on:
|
---|
74 | - Global opacity
|
---|
75 | - Brush style (some brushes apply opacity themselves)
|
---|
76 | - Use of mask (TODO: Need to support high quality anti-aliasing & text)
|
---|
77 | - Composition mode
|
---|
78 |
|
---|
79 | The choice of which brush() fragment shader to use depends on:
|
---|
80 | - Brush style
|
---|
81 |
|
---|
82 | */
|
---|
83 |
|
---|
84 |
|
---|
85 | struct QGLCachedShaderProg
|
---|
86 | {
|
---|
87 | QGLShader* vertexShader;
|
---|
88 | QGLShader* brushShader;
|
---|
89 | QGLShader* compositionShader;
|
---|
90 | QGLShaderProgram* shader;
|
---|
91 | };
|
---|
92 |
|
---|
93 | class QGLPEXShaderManager
|
---|
94 | {
|
---|
95 | public:
|
---|
96 | QGLPEXShaderManager(const QGLContext* context);
|
---|
97 | ~QGLPEXShaderManager();
|
---|
98 |
|
---|
99 | enum TransformType {IdentityTransform, ScaleTransform, TranslateTransform, FullTransform};
|
---|
100 |
|
---|
101 | void optimiseForBrushTransform(const QTransform& transform);
|
---|
102 | void setBrushStyle(Qt::BrushStyle style);
|
---|
103 | void setUseGlobalOpacity(bool value);
|
---|
104 | void setAffineOnlyBrushTransform(bool value); // I.e. Do we need to apply perspective-correction?
|
---|
105 | // Not doing so saves some vertex shader calculations.
|
---|
106 |
|
---|
107 | bool useCorrectShaderProg(); // returns true if the shader program has changed
|
---|
108 |
|
---|
109 | QGLShaderProgram* brushShader();
|
---|
110 | QGLShaderProgram* simpleShader(); // Used to draw into e.g. stencil buffers
|
---|
111 | QGLShaderProgram* imageShader();
|
---|
112 | QGLShaderProgram* textShader();
|
---|
113 |
|
---|
114 | private:
|
---|
115 | QGLShader* defaultVertexShader;
|
---|
116 |
|
---|
117 | QGLShader* imageVertexShader;
|
---|
118 | QGLShader* imageFragmentShader;
|
---|
119 | QGLShaderProgram* imageShaderProgram;
|
---|
120 |
|
---|
121 | QGLShader* textVertexShader;
|
---|
122 | QGLShader* textFragmentShader;
|
---|
123 | QGLShaderProgram* textShaderProgram;
|
---|
124 |
|
---|
125 | QGLShader* noBrushShader;
|
---|
126 | QGLShader* solidBrushShader;
|
---|
127 |
|
---|
128 | QGLShader* conicalBrushVertexShader;
|
---|
129 | QGLShader* conicalBrushFragmentShader;
|
---|
130 |
|
---|
131 | QGLShader* radialBrushVertexShader;
|
---|
132 | QGLShader* radialBrushFragmentShader;
|
---|
133 |
|
---|
134 | QGLShader* linearBrushVertexShader;
|
---|
135 | QGLShader* linearBrushFragmentShader;
|
---|
136 |
|
---|
137 | QGLShader* patternBrushVertexShader;
|
---|
138 | QGLShader* patternBrushFragmentShader;
|
---|
139 |
|
---|
140 | QGLShader* textureBrushFragmentShader;
|
---|
141 | QGLShader* textureBrushVertexShader;
|
---|
142 |
|
---|
143 | QGLShader* simpleFragmentShader;
|
---|
144 | QGLShaderProgram* simpleShaderProgram;
|
---|
145 |
|
---|
146 | QGLShaderProgram* activeProgram;
|
---|
147 |
|
---|
148 | Qt::BrushStyle currentBrushStyle;
|
---|
149 | bool useGlobalOpacity;
|
---|
150 | TransformType currentTransformType;
|
---|
151 | bool shaderProgNeedsChanging;
|
---|
152 |
|
---|
153 | QList<QGLCachedShaderProg> cachedPrograms;
|
---|
154 |
|
---|
155 | QGLContext* ctx;
|
---|
156 | };
|
---|