61 |
61 |
62 class Q_OPENGL_EXPORT QGLShader : public QObject |
62 class Q_OPENGL_EXPORT QGLShader : public QObject |
63 { |
63 { |
64 Q_OBJECT |
64 Q_OBJECT |
65 public: |
65 public: |
66 enum ShaderTypeBits |
66 enum ShaderTypeBit |
67 { |
67 { |
68 VertexShader = 0x0001, |
68 Vertex = 0x0001, |
69 FragmentShader = 0x0002, |
69 Fragment = 0x0002 |
70 |
|
71 PartialShader = 0x1000, |
|
72 |
|
73 PartialVertexShader = PartialShader | VertexShader, |
|
74 PartialFragmentShader = PartialShader | FragmentShader |
|
75 }; |
70 }; |
76 Q_DECLARE_FLAGS(ShaderType, ShaderTypeBits) |
71 Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit) |
77 |
72 |
78 explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0); |
73 explicit QGLShader(QGLShader::ShaderType type, QObject *parent = 0); |
79 QGLShader(const QString& fileName, QGLShader::ShaderType type, QObject *parent = 0); |
|
80 QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0); |
74 QGLShader(QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0); |
81 QGLShader(const QString& fileName, QGLShader::ShaderType type, const QGLContext *context, QObject *parent = 0); |
|
82 virtual ~QGLShader(); |
75 virtual ~QGLShader(); |
83 |
76 |
84 QGLShader::ShaderType shaderType() const; |
77 QGLShader::ShaderType shaderType() const; |
85 |
78 |
86 bool compile(const char *source); |
79 bool compileSourceCode(const char *source); |
87 bool compile(const QByteArray& source); |
80 bool compileSourceCode(const QByteArray& source); |
88 bool compile(const QString& source); |
81 bool compileSourceCode(const QString& source); |
89 bool compileFile(const QString& fileName); |
82 bool compileSourceFile(const QString& fileName); |
90 |
|
91 bool setShaderBinary(GLenum format, const void *binary, int length); |
|
92 bool setShaderBinary(QGLShader& otherShader, GLenum format, const void *binary, int length); |
|
93 |
|
94 static QList<GLenum> shaderBinaryFormats(); |
|
95 |
83 |
96 QByteArray sourceCode() const; |
84 QByteArray sourceCode() const; |
97 |
85 |
98 bool isCompiled() const; |
86 bool isCompiled() const; |
99 QString log() const; |
87 QString log() const; |
100 |
88 |
101 GLuint shaderId() const; |
89 GLuint shaderId() const; |
102 |
90 |
103 private: |
91 private: |
104 QGLShaderPrivate *d; |
|
105 |
|
106 friend class QGLShaderProgram; |
92 friend class QGLShaderProgram; |
107 |
93 |
108 Q_DISABLE_COPY(QGLShader) |
94 Q_DISABLE_COPY(QGLShader) |
|
95 Q_DECLARE_PRIVATE(QGLShader) |
109 }; |
96 }; |
110 |
97 |
111 Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType) |
98 Q_DECLARE_OPERATORS_FOR_FLAGS(QGLShader::ShaderType) |
112 |
99 |
113 |
100 |
123 |
110 |
124 bool addShader(QGLShader *shader); |
111 bool addShader(QGLShader *shader); |
125 void removeShader(QGLShader *shader); |
112 void removeShader(QGLShader *shader); |
126 QList<QGLShader *> shaders() const; |
113 QList<QGLShader *> shaders() const; |
127 |
114 |
128 bool addShader(QGLShader::ShaderType type, const char *source); |
115 bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source); |
129 bool addShader(QGLShader::ShaderType type, const QByteArray& source); |
116 bool addShaderFromSourceCode(QGLShader::ShaderType type, const QByteArray& source); |
130 bool addShader(QGLShader::ShaderType type, const QString& source); |
117 bool addShaderFromSourceCode(QGLShader::ShaderType type, const QString& source); |
131 bool addShaderFromFile(QGLShader::ShaderType type, const QString& fileName); |
118 bool addShaderFromSourceFile(QGLShader::ShaderType type, const QString& fileName); |
132 |
119 |
133 void removeAllShaders(); |
120 void removeAllShaders(); |
134 |
|
135 QByteArray programBinary(int *format) const; |
|
136 bool setProgramBinary(int format, const QByteArray& binary); |
|
137 static QList<int> programBinaryFormats(); |
|
138 |
121 |
139 virtual bool link(); |
122 virtual bool link(); |
140 bool isLinked() const; |
123 bool isLinked() const; |
141 QString log() const; |
124 QString log() const; |
142 |
125 |
143 bool enable(); |
126 bool bind(); |
144 static void disable(); |
127 void release(); |
145 |
128 |
146 GLuint programId() const; |
129 GLuint programId() const; |
147 |
130 |
148 void bindAttributeLocation(const char *name, int location); |
131 void bindAttributeLocation(const char *name, int location); |
149 void bindAttributeLocation(const QByteArray& name, int location); |
132 void bindAttributeLocation(const QByteArray& name, int location); |
172 void setAttributeValue(const char *name, const QVector4D& value); |
155 void setAttributeValue(const char *name, const QVector4D& value); |
173 void setAttributeValue(const char *name, const QColor& value); |
156 void setAttributeValue(const char *name, const QColor& value); |
174 void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows); |
157 void setAttributeValue(const char *name, const GLfloat *values, int columns, int rows); |
175 |
158 |
176 void setAttributeArray |
159 void setAttributeArray |
177 (int location, const GLfloat *values, int size, int stride = 0); |
160 (int location, const GLfloat *values, int tupleSize, int stride = 0); |
178 void setAttributeArray |
161 void setAttributeArray |
179 (int location, const QVector2D *values, int stride = 0); |
162 (int location, const QVector2D *values, int stride = 0); |
180 void setAttributeArray |
163 void setAttributeArray |
181 (int location, const QVector3D *values, int stride = 0); |
164 (int location, const QVector3D *values, int stride = 0); |
182 void setAttributeArray |
165 void setAttributeArray |
183 (int location, const QVector4D *values, int stride = 0); |
166 (int location, const QVector4D *values, int stride = 0); |
184 void setAttributeArray |
167 void setAttributeArray |
185 (const char *name, const GLfloat *values, int size, int stride = 0); |
168 (const char *name, const GLfloat *values, int tupleSize, int stride = 0); |
186 void setAttributeArray |
169 void setAttributeArray |
187 (const char *name, const QVector2D *values, int stride = 0); |
170 (const char *name, const QVector2D *values, int stride = 0); |
188 void setAttributeArray |
171 void setAttributeArray |
189 (const char *name, const QVector3D *values, int stride = 0); |
172 (const char *name, const QVector3D *values, int stride = 0); |
190 void setAttributeArray |
173 void setAttributeArray |
191 (const char *name, const QVector4D *values, int stride = 0); |
174 (const char *name, const QVector4D *values, int stride = 0); |
|
175 |
|
176 void enableAttributeArray(int location); |
|
177 void enableAttributeArray(const char *name); |
192 void disableAttributeArray(int location); |
178 void disableAttributeArray(int location); |
193 void disableAttributeArray(const char *name); |
179 void disableAttributeArray(const char *name); |
194 |
180 |
195 int uniformLocation(const char *name) const; |
181 int uniformLocation(const char *name) const; |
196 int uniformLocation(const QByteArray& name) const; |
182 int uniformLocation(const QByteArray& name) const; |
197 int uniformLocation(const QString& name) const; |
183 int uniformLocation(const QString& name) const; |
|
184 |
|
185 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS |
|
186 void setUniformValue(int location, QMacCompatGLint value); |
|
187 void setUniformValue(int location, QMacCompatGLuint value); |
|
188 void setUniformValue(const char *name, QMacCompatGLint value); |
|
189 void setUniformValue(const char *name, QMacCompatGLuint value); |
|
190 void setUniformValueArray(int location, const QMacCompatGLint *values, int count); |
|
191 void setUniformValueArray(int location, const QMacCompatGLuint *values, int count); |
|
192 void setUniformValueArray(const char *name, const QMacCompatGLint *values, int count); |
|
193 void setUniformValueArray(const char *name, const QMacCompatGLuint *values, int count); |
|
194 #endif |
198 |
195 |
199 void setUniformValue(int location, GLfloat value); |
196 void setUniformValue(int location, GLfloat value); |
200 void setUniformValue(int location, GLint value); |
197 void setUniformValue(int location, GLint value); |
201 void setUniformValue(int location, GLuint value); |
198 void setUniformValue(int location, GLuint value); |
202 void setUniformValue(int location, GLfloat x, GLfloat y); |
199 void setUniformValue(int location, GLfloat x, GLfloat y); |
246 void setUniformValue(const char *name, const QMatrix4x3& value); |
243 void setUniformValue(const char *name, const QMatrix4x3& value); |
247 void setUniformValue(const char *name, const QMatrix4x4& value); |
244 void setUniformValue(const char *name, const QMatrix4x4& value); |
248 void setUniformValue(const char *name, const GLfloat value[4][4]); |
245 void setUniformValue(const char *name, const GLfloat value[4][4]); |
249 void setUniformValue(const char *name, const QTransform& value); |
246 void setUniformValue(const char *name, const QTransform& value); |
250 |
247 |
251 void setUniformValueArray(int location, const GLfloat *values, int count, int size); |
248 void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize); |
252 void setUniformValueArray(int location, const GLint *values, int count); |
249 void setUniformValueArray(int location, const GLint *values, int count); |
253 void setUniformValueArray(int location, const GLuint *values, int count); |
250 void setUniformValueArray(int location, const GLuint *values, int count); |
254 void setUniformValueArray(int location, const QVector2D *values, int count); |
251 void setUniformValueArray(int location, const QVector2D *values, int count); |
255 void setUniformValueArray(int location, const QVector3D *values, int count); |
252 void setUniformValueArray(int location, const QVector3D *values, int count); |
256 void setUniformValueArray(int location, const QVector4D *values, int count); |
253 void setUniformValueArray(int location, const QVector4D *values, int count); |
262 void setUniformValueArray(int location, const QMatrix3x4 *values, int count); |
259 void setUniformValueArray(int location, const QMatrix3x4 *values, int count); |
263 void setUniformValueArray(int location, const QMatrix4x2 *values, int count); |
260 void setUniformValueArray(int location, const QMatrix4x2 *values, int count); |
264 void setUniformValueArray(int location, const QMatrix4x3 *values, int count); |
261 void setUniformValueArray(int location, const QMatrix4x3 *values, int count); |
265 void setUniformValueArray(int location, const QMatrix4x4 *values, int count); |
262 void setUniformValueArray(int location, const QMatrix4x4 *values, int count); |
266 |
263 |
267 void setUniformValueArray(const char *name, const GLfloat *values, int count, int size); |
264 void setUniformValueArray(const char *name, const GLfloat *values, int count, int tupleSize); |
268 void setUniformValueArray(const char *name, const GLint *values, int count); |
265 void setUniformValueArray(const char *name, const GLint *values, int count); |
269 void setUniformValueArray(const char *name, const GLuint *values, int count); |
266 void setUniformValueArray(const char *name, const GLuint *values, int count); |
270 void setUniformValueArray(const char *name, const QVector2D *values, int count); |
267 void setUniformValueArray(const char *name, const QVector2D *values, int count); |
271 void setUniformValueArray(const char *name, const QVector3D *values, int count); |
268 void setUniformValueArray(const char *name, const QVector3D *values, int count); |
272 void setUniformValueArray(const char *name, const QVector4D *values, int count); |
269 void setUniformValueArray(const char *name, const QVector4D *values, int count); |
278 void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count); |
275 void setUniformValueArray(const char *name, const QMatrix3x4 *values, int count); |
279 void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count); |
276 void setUniformValueArray(const char *name, const QMatrix4x2 *values, int count); |
280 void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count); |
277 void setUniformValueArray(const char *name, const QMatrix4x3 *values, int count); |
281 void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count); |
278 void setUniformValueArray(const char *name, const QMatrix4x4 *values, int count); |
282 |
279 |
283 static bool hasShaderPrograms(const QGLContext *context = 0); |
280 static bool hasOpenGLShaderPrograms(const QGLContext *context = 0); |
284 |
281 |
285 private Q_SLOTS: |
282 private Q_SLOTS: |
286 void shaderDestroyed(); |
283 void shaderDestroyed(); |
287 |
284 |
288 private: |
285 private: |
289 QGLShaderProgramPrivate *d; |
|
290 |
|
291 Q_DISABLE_COPY(QGLShaderProgram) |
286 Q_DISABLE_COPY(QGLShaderProgram) |
|
287 Q_DECLARE_PRIVATE(QGLShaderProgram) |
292 |
288 |
293 bool init(); |
289 bool init(); |
294 }; |
290 }; |
295 |
291 |
296 #endif |
292 #endif |