Qt 4.8
Public Types | Public Functions | Public Variables | Properties | List of all members
QGLEngineShaderManager Class Reference

#include <qglengineshadermanager_p.h>

Inheritance diagram for QGLEngineShaderManager:
QObject

Public Types

enum  MaskType {
  NoMask, PixelMask, SubPixelMaskPass1, SubPixelMaskPass2,
  SubPixelWithGammaMask
}
 
enum  OpacityMode { NoOpacity, UniformOpacity, AttributeOpacity }
 
enum  PixelSrcType { ImageSrc = Qt::TexturePattern+1, NonPremultipliedImageSrc = Qt::TexturePattern+2, PatternSrc = Qt::TexturePattern+3, TextureSrcWithPattern = Qt::TexturePattern+4 }
 
enum  Uniform {
  ImageTexture, PatternColor, GlobalOpacity, Depth,
  MaskTexture, FragmentColor, LinearData, Angle,
  HalfViewportSize, Fmp, Fmp2MRadius2, Inverse2Fmp2MRadius2,
  SqrFr, BRadius, InvertedTextureSize, BrushTransform,
  BrushTexture, Matrix, NumUniforms
}
 

Public Functions

QGLShaderProgramblitProgram ()
 
QGLShaderProgramcurrentProgram ()
 
GLuint getUniformLocation (Uniform id)
 
bool hasComplexGeometry () const
 
void optimiseForBrushTransform (QTransform::TransformationType transformType)
 
 QGLEngineShaderManager (QGLContext *context)
 
void removeCustomStage ()
 
void setCompositionMode (QPainter::CompositionMode)
 
void setCustomStage (QGLCustomShaderStage *stage)
 
void setDirty ()
 
void setHasComplexGeometry (bool hasComplexGeometry)
 
void setMaskType (MaskType)
 
void setOpacityMode (OpacityMode)
 
void setSrcPixelType (Qt::BrushStyle)
 
void setSrcPixelType (PixelSrcType)
 
QGLShaderProgramsimpleProgram ()
 
void useBlitProgram ()
 
bool useCorrectShaderProg ()
 
void useSimpleProgram ()
 
 ~QGLEngineShaderManager ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QGLEngineSharedShaderssharedShaders
 

Properties

QTransform brushTransform
 
bool complexGeometry
 
QPainter::CompositionMode compositionMode
 
QGLContextctx
 
QGLEngineShaderProgcurrentShaderProg
 
QGLCustomShaderStagecustomSrcStage
 
MaskType maskType
 
OpacityMode opacityMode
 
bool shaderProgNeedsChanging
 
int srcPixelType
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 417 of file qglengineshadermanager_p.h.

Enumerations

◆ MaskType

◆ OpacityMode

◆ PixelSrcType

◆ Uniform

Enumerator
ImageTexture 
PatternColor 
GlobalOpacity 
Depth 
MaskTexture 
FragmentColor 
LinearData 
Angle 
HalfViewportSize 
Fmp 
Fmp2MRadius2 
Inverse2Fmp2MRadius2 
SqrFr 
BRadius 
InvertedTextureSize 
BrushTransform 
BrushTexture 
Matrix 
NumUniforms 

Definition at line 432 of file qglengineshadermanager_p.h.

432  {
433  ImageTexture,
434  PatternColor,
436  Depth,
437  MaskTexture,
439  LinearData,
440  Angle,
442  Fmp,
443  Fmp2MRadius2,
445  SqrFr,
446  BRadius,
449  BrushTexture,
450  Matrix,
452  };

Constructors and Destructors

◆ QGLEngineShaderManager()

QGLEngineShaderManager::QGLEngineShaderManager ( QGLContext context)

Definition at line 456 of file qglengineshadermanager.cpp.

457  : ctx(context),
459  complexGeometry(false),
462  maskType(NoMask),
464  customSrcStage(0),
466 {
468 }
QGLCustomShaderStage * customSrcStage
static QGLEngineSharedShaders * shadersForContext(const QGLContext *context)
QGLEngineShaderProg * currentShaderProg
QPainter::CompositionMode compositionMode
QGLEngineSharedShaders * sharedShaders

◆ ~QGLEngineShaderManager()

QGLEngineShaderManager::~QGLEngineShaderManager ( )

Definition at line 470 of file qglengineshadermanager.cpp.

471 {
472  //###
474 }

Functions

◆ blitProgram()

QGLShaderProgram * QGLEngineShaderManager::blitProgram ( )

Definition at line 618 of file qglengineshadermanager.cpp.

Referenced by QGLTextureGlyphCache::resizeTextureData().

619 {
620  return sharedShaders->blitProgram();
621 }
QGLShaderProgram * blitProgram()
QGLEngineSharedShaders * sharedShaders

◆ currentProgram()

QGLShaderProgram * QGLEngineShaderManager::currentProgram ( )

◆ getUniformLocation()

GLuint QGLEngineShaderManager::getUniformLocation ( Uniform  id)

Definition at line 476 of file qglengineshadermanager.cpp.

477 {
478  if (!currentShaderProg)
479  return 0;
480 
481  QVector<uint> &uniformLocations = currentShaderProg->uniformLocations;
482  if (uniformLocations.isEmpty())
483  uniformLocations.fill(GLuint(-1), NumUniforms);
484 
485  static const char *uniformNames[] = {
486  "imageTexture",
487  "patternColor",
488  "globalOpacity",
489  "depth",
490  "maskTexture",
491  "fragmentColor",
492  "linearData",
493  "angle",
494  "halfViewportSize",
495  "fmp",
496  "fmp2_m_radius2",
497  "inverse_2_fmp2_m_radius2",
498  "sqrfr",
499  "bradius",
500  "invertedTextureSize",
501  "brushTransform",
502  "brushTexture",
503  "matrix"
504  };
505 
506  if (uniformLocations.at(id) == GLuint(-1))
507  uniformLocations[id] = currentShaderProg->program->uniformLocation(uniformNames[id]);
508 
509  return uniformLocations.at(id);
510 }
QVector< T > & fill(const T &t, int size=-1)
Assigns value to all items in the vector.
Definition: qvector.h:665
int uniformLocation(const char *name) const
Returns the location of the uniform variable name within this shader program&#39;s parameter list...
QGLEngineShaderProg * currentShaderProg
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

◆ hasComplexGeometry()

bool QGLEngineShaderManager::hasComplexGeometry ( ) const
inline

Definition at line 484 of file qglengineshadermanager_p.h.

Referenced by QGL2PaintEngineExPrivate::prepareForDraw().

485  {
486  return complexGeometry;
487  }

◆ optimiseForBrushTransform()

void QGLEngineShaderManager::optimiseForBrushTransform ( QTransform::TransformationType  transformType)

Definition at line 513 of file qglengineshadermanager.cpp.

Referenced by QGL2PaintEngineExPrivate::setBrush().

514 {
515  Q_UNUSED(transformType); // Currently ignored
516 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ removeCustomStage()

void QGLEngineShaderManager::removeCustomStage ( )

Definition at line 577 of file qglengineshadermanager.cpp.

Referenced by setCustomStage(), and ~QGLEngineShaderManager().

◆ setCompositionMode()

void QGLEngineShaderManager::setCompositionMode ( QPainter::CompositionMode  mode)

Definition at line 560 of file qglengineshadermanager.cpp.

561 {
562  if (compositionMode == mode)
563  return;
564 
565  compositionMode = mode;
566  shaderProgNeedsChanging = true; //###
567 }
QPainter::CompositionMode compositionMode

◆ setCustomStage()

void QGLEngineShaderManager::setCustomStage ( QGLCustomShaderStage stage)

Definition at line 569 of file qglengineshadermanager.cpp.

570 {
571  if (customSrcStage)
573  customSrcStage = stage;
575 }
QGLCustomShaderStage * customSrcStage

◆ setDirty()

void QGLEngineShaderManager::setDirty ( )

Definition at line 518 of file qglengineshadermanager.cpp.

519 {
521 }

◆ setHasComplexGeometry()

void QGLEngineShaderManager::setHasComplexGeometry ( bool  hasComplexGeometry)
inline

◆ setMaskType()

void QGLEngineShaderManager::setMaskType ( MaskType  type)

Definition at line 551 of file qglengineshadermanager.cpp.

Referenced by QGL2PaintEngineExPrivate::transferMode().

552 {
553  if (maskType == type)
554  return;
555 
556  maskType = type;
557  shaderProgNeedsChanging = true; //###
558 }
int type
Definition: qmetatype.cpp:239

◆ setOpacityMode()

void QGLEngineShaderManager::setOpacityMode ( OpacityMode  mode)

Definition at line 542 of file qglengineshadermanager.cpp.

Referenced by QGL2PaintEngineExPrivate::prepareForDraw().

543 {
544  if (opacityMode == mode)
545  return;
546 
547  opacityMode = mode;
548  shaderProgNeedsChanging = true; //###
549 }

◆ setSrcPixelType() [1/2]

void QGLEngineShaderManager::setSrcPixelType ( Qt::BrushStyle  style)

Definition at line 523 of file qglengineshadermanager.cpp.

Referenced by QGL2PaintEngineExPrivate::drawTexture(), and QGL2PaintEngineExPrivate::setBrush().

524 {
525  Q_ASSERT(style != Qt::NoBrush);
526  if (srcPixelType == PixelSrcType(style))
527  return;
528 
529  srcPixelType = style;
530  shaderProgNeedsChanging = true; //###
531 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ setSrcPixelType() [2/2]

void QGLEngineShaderManager::setSrcPixelType ( PixelSrcType  type)

Definition at line 533 of file qglengineshadermanager.cpp.

534 {
535  if (srcPixelType == type)
536  return;
537 
538  srcPixelType = type;
539  shaderProgNeedsChanging = true; //###
540 }
int type
Definition: qmetatype.cpp:239

◆ simpleProgram()

QGLShaderProgram * QGLEngineShaderManager::simpleProgram ( )

Definition at line 613 of file qglengineshadermanager.cpp.

614 {
615  return sharedShaders->simpleProgram();
616 }
QGLShaderProgram * simpleProgram()
QGLEngineSharedShaders * sharedShaders

◆ useBlitProgram()

void QGLEngineShaderManager::useBlitProgram ( )

Definition at line 603 of file qglengineshadermanager.cpp.

Referenced by QGLTextureGlyphCache::resizeTextureData().

604 {
606  QGLContextPrivate* ctx_d = ctx->d_func();
611 }
QGLShaderProgram * blitProgram()
void setVertexAttribArrayEnabled(int arrayIndex, bool enabled=true)
Definition: qgl.cpp:2189
static const GLuint QT_OPACITY_ATTR
static const GLuint QT_TEXTURE_COORDS_ATTR
static const GLuint QT_VERTEX_COORDS_ATTR
QGLEngineSharedShaders * sharedShaders
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...

◆ useCorrectShaderProg()

bool QGLEngineShaderManager::useCorrectShaderProg ( )

Definition at line 627 of file qglengineshadermanager.cpp.

Referenced by QGL2PaintEngineExPrivate::prepareForDraw().

628 {
630  return false;
631 
632  bool useCustomSrc = customSrcStage != 0;
634  useCustomSrc = false;
635  qWarning("QGLEngineShaderManager - Ignoring custom shader stage for non image src");
636  }
637 
638  QGLEngineShaderProg requiredProgram;
639 
640  bool texCoords = false;
641 
642  // Choose vertex shader shader position function (which typically also sets
643  // varyings) and the source pixel (srcPixel) fragment shader function:
646  bool isAffine = brushTransform.isAffine();
648  if (isAffine)
650  else
652 
654  }
655  else switch (srcPixelType) {
656  default:
657  case Qt::NoBrush:
658  qFatal("QGLEngineShaderManager::useCorrectShaderProg() - Qt::NoBrush style is set");
659  break;
663  texCoords = true;
664  break;
668  texCoords = true;
669  break;
673  texCoords = true;
674  break;
679  break;
680  case Qt::SolidPattern:
683  break;
688  break;
693  break;
698  break;
699  case Qt::TexturePattern:
703  break;
704  };
705 
706  if (useCustomSrc) {
708  requiredProgram.customStageSource = customSrcStage->source();
709  }
710 
711  const bool hasCompose = compositionMode > QPainter::CompositionMode_Plus;
712  const bool hasMask = maskType != QGLEngineShaderManager::NoMask;
713 
714  // Choose fragment shader main function:
715  if (opacityMode == AttributeOpacity) {
716  Q_ASSERT(!hasCompose && !hasMask);
718  } else {
719  bool useGlobalOpacity = (opacityMode == UniformOpacity);
720  if (hasCompose && hasMask && useGlobalOpacity)
722  if (hasCompose && hasMask && !useGlobalOpacity)
724  if (!hasCompose && hasMask && useGlobalOpacity)
726  if (!hasCompose && hasMask && !useGlobalOpacity)
728  if (hasCompose && !hasMask && useGlobalOpacity)
730  if (hasCompose && !hasMask && !useGlobalOpacity)
732  if (!hasCompose && !hasMask && useGlobalOpacity)
734  if (!hasCompose && !hasMask && !useGlobalOpacity)
736  }
737 
738  if (hasMask) {
739  if (maskType == PixelMask) {
741  texCoords = true;
742  } else if (maskType == SubPixelMaskPass1) {
744  texCoords = true;
745  } else if (maskType == SubPixelMaskPass2) {
747  texCoords = true;
748  } else if (maskType == SubPixelWithGammaMask) {
750  texCoords = true;
751  } else {
752  qCritical("QGLEngineShaderManager::useCorrectShaderProg() - Unknown mask type");
753  }
754  } else {
756  }
757 
758  if (hasCompose) {
759  switch (compositionMode) {
762  break;
765  break;
768  break;
771  break;
774  break;
777  break;
780  break;
783  break;
786  break;
789  break;
792  break;
793  default:
794  qWarning("QGLEngineShaderManager::useCorrectShaderProg() - Unsupported composition mode");
795  }
796  } else {
798  }
799 
800  // Choose vertex shader main function
801  if (opacityMode == AttributeOpacity) {
802  Q_ASSERT(texCoords);
804  } else if (texCoords) {
806  } else {
808  }
809  requiredProgram.useTextureCoords = texCoords;
810  requiredProgram.useOpacityAttribute = (opacityMode == AttributeOpacity);
813  requiredProgram.usePmvMatrixAttribute = false;
814  } else {
815  requiredProgram.usePmvMatrixAttribute = true;
816 
817  // Force complexGeometry off, since we currently don't support that mode for
818  // non-solid brushes
819  complexGeometry = false;
820  }
821 
822  // At this point, requiredProgram is fully populated so try to find the program in the cache
824 
825  if (currentShaderProg && useCustomSrc) {
827  }
828 
829  // Make sure all the vertex attribute arrays the program uses are enabled (and the ones it
830  // doesn't use are disabled)
831  QGLContextPrivate* ctx_d = ctx->d_func();
835 
836  shaderProgNeedsChanging = false;
837  return true;
838 }
QGLEngineSharedShaders::SnippetName mainVertexShader
QGLCustomShaderStage * customSrcStage
QGLEngineSharedShaders::SnippetName mainFragShader
QGLEngineSharedShaders::SnippetName maskFragShader
QGLEngineSharedShaders::SnippetName positionVertexShader
QGLEngineShaderProg * findProgramInCache(const QGLEngineShaderProg &prog)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setVertexAttribArrayEnabled(int arrayIndex, bool enabled=true)
Definition: qgl.cpp:2189
static const GLuint QT_OPACITY_ATTR
QGLEngineShaderProg * currentShaderProg
virtual void setUniforms(QGLShaderProgram *)
QPainter::CompositionMode compositionMode
Q_CORE_EXPORT void qWarning(const char *,...)
QGLEngineSharedShaders::SnippetName compositionFragShader
Q_CORE_EXPORT void qFatal(const char *,...)
bool isAffine() const
Returns true if the matrix represent an affine transformation, otherwise returns false.
Definition: qtransform.h:200
static const GLuint QT_TEXTURE_COORDS_ATTR
QGLEngineSharedShaders::SnippetName srcPixelFragShader
static const GLuint QT_VERTEX_COORDS_ATTR
QGLEngineSharedShaders * sharedShaders
Q_CORE_EXPORT void qCritical(const char *,...)

◆ useSimpleProgram()

void QGLEngineShaderManager::useSimpleProgram ( )

Definition at line 593 of file qglengineshadermanager.cpp.

Referenced by QGL2PaintEngineExPrivate::useSimpleShader().

594 {
596  QGLContextPrivate* ctx_d = ctx->d_func();
601 }
void setVertexAttribArrayEnabled(int arrayIndex, bool enabled=true)
Definition: qgl.cpp:2189
static const GLuint QT_OPACITY_ATTR
QGLShaderProgram * simpleProgram()
static const GLuint QT_TEXTURE_COORDS_ATTR
static const GLuint QT_VERTEX_COORDS_ATTR
QGLEngineSharedShaders * sharedShaders
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...

Properties

◆ brushTransform

QTransform QGLEngineShaderManager::brushTransform
private

Definition at line 501 of file qglengineshadermanager_p.h.

Referenced by useCorrectShaderProg().

◆ complexGeometry

bool QGLEngineShaderManager::complexGeometry
private

Definition at line 498 of file qglengineshadermanager_p.h.

Referenced by useCorrectShaderProg().

◆ compositionMode

QPainter::CompositionMode QGLEngineShaderManager::compositionMode
private

Definition at line 505 of file qglengineshadermanager_p.h.

Referenced by setCompositionMode(), and useCorrectShaderProg().

◆ ctx

QGLContext* QGLEngineShaderManager::ctx
private

◆ currentShaderProg

QGLEngineShaderProg* QGLEngineShaderManager::currentShaderProg
private

◆ customSrcStage

QGLCustomShaderStage* QGLEngineShaderManager::customSrcStage
private

◆ maskType

MaskType QGLEngineShaderManager::maskType
private

Definition at line 504 of file qglengineshadermanager_p.h.

Referenced by setMaskType(), and useCorrectShaderProg().

◆ opacityMode

OpacityMode QGLEngineShaderManager::opacityMode
private

Definition at line 503 of file qglengineshadermanager_p.h.

Referenced by setOpacityMode(), and useCorrectShaderProg().

◆ shaderProgNeedsChanging

bool QGLEngineShaderManager::shaderProgNeedsChanging
private

◆ sharedShaders

QGLEngineSharedShaders* QGLEngineShaderManager::sharedShaders

◆ srcPixelType

int QGLEngineShaderManager::srcPixelType
private

Definition at line 502 of file qglengineshadermanager_p.h.

Referenced by setSrcPixelType(), and useCorrectShaderProg().


The documentation for this class was generated from the following files: