1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the QtOpenGL module of the Qt Toolkit. |
7 ** This file is part of the QtOpenGL module of the Qt Toolkit. |
8 ** |
8 ** |
251 */ |
251 */ |
252 |
252 |
253 static const GLuint QT_VERTEX_COORDS_ATTR = 0; |
253 static const GLuint QT_VERTEX_COORDS_ATTR = 0; |
254 static const GLuint QT_TEXTURE_COORDS_ATTR = 1; |
254 static const GLuint QT_TEXTURE_COORDS_ATTR = 1; |
255 static const GLuint QT_OPACITY_ATTR = 2; |
255 static const GLuint QT_OPACITY_ATTR = 2; |
|
256 static const GLuint QT_PMV_MATRIX_1_ATTR = 3; |
|
257 static const GLuint QT_PMV_MATRIX_2_ATTR = 4; |
|
258 static const GLuint QT_PMV_MATRIX_3_ATTR = 5; |
256 |
259 |
257 class QGLEngineShaderProg; |
260 class QGLEngineShaderProg; |
258 |
261 |
259 class QGLEngineSharedShaders : public QObject |
262 class QGLEngineSharedShaders : public QObject |
260 { |
263 { |
342 const int maskOffset = (1<<14) - NoMaskShader; |
345 const int maskOffset = (1<<14) - NoMaskShader; |
343 const int compositionOffset = (1 << 16) - MultiplyCompositionModeFragmentShader; |
346 const int compositionOffset = (1 << 16) - MultiplyCompositionModeFragmentShader; |
344 */ |
347 */ |
345 |
348 |
346 QGLEngineSharedShaders(const QGLContext *context); |
349 QGLEngineSharedShaders(const QGLContext *context); |
|
350 ~QGLEngineSharedShaders(); |
347 |
351 |
348 QGLShaderProgram *simpleProgram() { return simpleShaderProg; } |
352 QGLShaderProgram *simpleProgram() { return simpleShaderProg; } |
349 QGLShaderProgram *blitProgram() { return blitShaderProg; } |
353 QGLShaderProgram *blitProgram() { return blitShaderProg; } |
350 // Compile the program if it's not already in the cache, return the item in the cache. |
354 // Compile the program if it's not already in the cache, return the item in the cache. |
351 QGLEngineShaderProg *findProgramInCache(const QGLEngineShaderProg &prog); |
355 QGLEngineShaderProg *findProgramInCache(const QGLEngineShaderProg &prog); |
394 |
398 |
395 QVector<uint> uniformLocations; |
399 QVector<uint> uniformLocations; |
396 |
400 |
397 bool useTextureCoords; |
401 bool useTextureCoords; |
398 bool useOpacityAttribute; |
402 bool useOpacityAttribute; |
|
403 bool usePmvMatrix; |
399 |
404 |
400 bool operator==(const QGLEngineShaderProg& other) { |
405 bool operator==(const QGLEngineShaderProg& other) { |
401 // We don't care about the program |
406 // We don't care about the program |
402 return ( mainVertexShader == other.mainVertexShader && |
407 return ( mainVertexShader == other.mainVertexShader && |
403 positionVertexShader == other.positionVertexShader && |
408 positionVertexShader == other.positionVertexShader && |
452 }; |
456 }; |
453 |
457 |
454 // There are optimisations we can do, depending on the brush transform: |
458 // There are optimisations we can do, depending on the brush transform: |
455 // 1) May not have to apply perspective-correction |
459 // 1) May not have to apply perspective-correction |
456 // 2) Can use lower precision for matrix |
460 // 2) Can use lower precision for matrix |
457 void optimiseForBrushTransform(const QTransform &transform); |
461 void optimiseForBrushTransform(QTransform::TransformationType transformType); |
458 void setSrcPixelType(Qt::BrushStyle); |
462 void setSrcPixelType(Qt::BrushStyle); |
459 void setSrcPixelType(PixelSrcType); // For non-brush sources, like pixmaps & images |
463 void setSrcPixelType(PixelSrcType); // For non-brush sources, like pixmaps & images |
460 void setOpacityMode(OpacityMode); |
464 void setOpacityMode(OpacityMode); |
461 void setMaskType(MaskType); |
465 void setMaskType(MaskType); |
462 void setCompositionMode(QPainter::CompositionMode); |
466 void setCompositionMode(QPainter::CompositionMode); |
463 void setCustomStage(QGLCustomShaderStage* stage); |
467 void setCustomStage(QGLCustomShaderStage* stage); |
464 void removeCustomStage(); |
468 void removeCustomStage(); |
465 |
469 |
466 uint getUniformLocation(Uniform id); |
470 GLuint getUniformLocation(Uniform id); |
467 |
471 |
468 void setDirty(); // someone has manually changed the current shader program |
472 void setDirty(); // someone has manually changed the current shader program |
469 bool useCorrectShaderProg(); // returns true if the shader program needed to be changed |
473 bool useCorrectShaderProg(); // returns true if the shader program needed to be changed |
|
474 |
|
475 void useSimpleProgram(); |
|
476 void useBlitProgram(); |
470 |
477 |
471 QGLShaderProgram* currentProgram(); // Returns pointer to the shader the manager has chosen |
478 QGLShaderProgram* currentProgram(); // Returns pointer to the shader the manager has chosen |
472 QGLShaderProgram* simpleProgram(); // Used to draw into e.g. stencil buffers |
479 QGLShaderProgram* simpleProgram(); // Used to draw into e.g. stencil buffers |
473 QGLShaderProgram* blitProgram(); // Used to blit a texture into the framebuffer |
480 QGLShaderProgram* blitProgram(); // Used to blit a texture into the framebuffer |
474 |
481 |