Qt 4.8
shadereffectitem.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 QML Shaders plugin 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 "shadereffectitem.h"
43 #include "shadereffect.h"
44 #include "glfunctions.h"
45 
46 #include <QPainter>
47 #include <QtOpenGL>
48 
49 static const char qt_default_vertex_code[] =
50  "uniform highp mat4 qt_ModelViewProjectionMatrix;\n"
51  "attribute highp vec4 qt_Vertex;\n"
52  "attribute highp vec2 qt_MultiTexCoord0;\n"
53  "varying highp vec2 qt_TexCoord0;\n"
54  "void main(void)\n"
55  "{\n"
56  "qt_TexCoord0 = qt_MultiTexCoord0;\n"
57  "gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n"
58  "}\n";
59 
60 static const char qt_default_fragment_code[] =
61  "varying highp vec2 qt_TexCoord0;\n"
62  "uniform lowp sampler2D source;\n"
63  "void main(void)\n"
64  "{\n"
65  "gl_FragColor = texture2D(source, qt_TexCoord0.st);\n"
66  "}\n";
67 
68 static const char qt_postion_attribute_name[] = "qt_Vertex";
69 static const char qt_texcoord_attribute_name[] = "qt_MultiTexCoord0";
70 static const char qt_emptyAttributeName[] = "";
71 
72 
206  : QDeclarativeItem(parent)
207  , m_program(0)
208  , m_meshResolution(1, 1)
209  , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
210  , m_blending(true)
211  , m_program_dirty(true)
212  , m_active(true)
213  , m_respectsMatrix(false)
214  , m_respectsOpacity(false)
215  , m_checkedViewportUpdateMode(false)
216  , m_checkedOpenGL(false)
217  , m_checkedShaderPrograms(false)
218  , m_hasShaderPrograms(false)
219  , m_mirrored(false)
220  , m_defaultVertexShader(true)
221 {
224  m_active = isVisible();
225 }
226 
228 {
229  reset();
230 }
231 
232 
254 {
255  if (m_fragment_code.constData() == code.constData())
256  return;
257 
258  m_fragment_code = code;
259  if (isComponentComplete()) {
260  reset();
262  }
264 }
265 
287 {
288  if (m_vertex_code.constData() == code.constData())
289  return;
290 
291  m_vertex_code = code;
292  m_defaultVertexShader = false;
293  if (isComponentComplete()) {
294  reset();
296  }
298 }
299 
324 {
325  if (m_blending == enable)
326  return;
327 
328  m_blending = enable;
329  m_changed = true;
331 }
332 
333 
349 {
350  if (size == m_meshResolution)
351  return;
352 
353  m_meshResolution = size;
355  updateGeometry();
356 }
357 
359 {
362 }
363 
365 {
367  QGraphicsScene *s = scene();
368  if (s){
369  QList<QGraphicsView*> views = s->views();
370  for (int i = 0; i < views.count(); i++) {
371  if (views[i]->viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
372  qWarning() << "ShaderEffectItem::checkViewportUpdateMode - consider setting QGraphicsView::FullViewportUpdate mode with OpenGL!";
373  }
374  }
375  }
377  }
378 }
379 
381 {
382  if (!m_active) return;
383 
384  const QGLContext *context = QGLContext::currentContext();
385 
386  if (context) {
390 
391  if (!m_hasShaderPrograms)
392  qWarning() << "ShaderEffectItem::paint - Shader programs are not supported";
393  }
394 
395  if ( !m_hasShaderPrograms )
396  return;
397 
399  painter->save();
400  painter->beginNativePainting();
401  QMatrix4x4 combinedMatrix = QMatrix4x4(painter->transform());
402  renderEffect(painter, combinedMatrix);
403  painter->endNativePainting();
404  painter->restore();
405  } else {
406  if (!m_checkedOpenGL) {
407  qWarning() << "ShaderEffectItem::paint - OpenGL not available";
408  m_checkedOpenGL = true;
409  }
410  }
411 }
412 
414 {
415  if (!painter || !painter->device())
416  return;
417 
418  if (!m_program || !m_program->programId()) {
419  // Deleted due to deactivation, to save GPU memory,
420  // or invalidated due to GL context change.
421  delete m_program;
423  m_program = new QGLShaderProgram(this);
424  if (!m_program)
425  qWarning() << "ShaderEffectItem::renderEffect - Creating QGLShaderProgram failed!";
426  }
427 
428  if (!m_program)
429  return;
430 
433 
434  m_program->bind();
435 
436  QMatrix4x4 combinedMatrix;
437  combinedMatrix.scale(2.0 / painter->device()->width(), -2.0 / painter->device()->height(), 1.0);
438  combinedMatrix.translate(-painter->device()->width() / 2.0, -painter->device()->height() / 2.0 );
439  combinedMatrix *= matrix;
440  updateEffectState(combinedMatrix);
441 
442  for (int i = 0; i < m_attributeNames.size(); ++i) {
444  }
445 
446  bindGeometry();
447 
448  // Optimization, disable depth test when we know we don't need it.
449  if (m_defaultVertexShader) {
450  glDepthMask(false);
451  glDisable(GL_DEPTH_TEST);
452  } else {
453  glEnable(GL_DEPTH_TEST);
454  glDepthFunc(GL_GREATER);
455  glDepthMask(true);
456 #if defined(QT_OPENGL_ES)
457  glClearDepthf(0);
458 #else
459  glClearDepth(0);
460 #endif
461  glClearColor(0, 0, 0, 0);
462  glClear(GL_DEPTH_BUFFER_BIT);
463  }
464 
465  if (m_blending){
466  glEnable(GL_BLEND);
467  glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
468  } else {
469  glDisable(GL_BLEND);
470  }
471 
472  if (m_geometry.indexCount())
474  else
475  glDrawArrays(m_geometry.drawingMode(), 0, m_geometry.vertexCount());
476 
477  glDepthMask(false);
478  glDisable(GL_DEPTH_TEST);
479 
480  for (int i = 0; i < m_attributeNames.size(); ++i)
482 }
483 
485 {
486  if (!m_program)
487  return;
488 
489  for (int i = m_sources.size() - 1; i >= 0; --i) {
490  const ShaderEffectItem::SourceData &source = m_sources.at(i);
491  if (!source.source)
492  continue;
493 
495  source.source->bind();
496  }
497 
498  if (m_respectsOpacity)
499  m_program->setUniformValue("qt_Opacity", static_cast<float> (effectiveOpacity()));
500 
501  if (m_respectsMatrix){
502  m_program->setUniformValue("qt_ModelViewProjectionMatrix", matrix);
503  }
504 
506  for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
507  const QByteArray &name = *it;
508  QVariant v = property(name.constData());
509 
510  switch (v.type()) {
511  case QVariant::Color:
513  break;
514  case QVariant::Double:
515  m_program->setUniformValue(name.constData(), (float) qvariant_cast<double>(v));
516  break;
517  case QVariant::Transform:
519  break;
520  case QVariant::Int:
522  break;
523  case QVariant::Bool:
525  break;
526  case QVariant::Size:
527  case QVariant::SizeF:
529  break;
530  case QVariant::Point:
531  case QVariant::PointF:
533  break;
534  case QVariant::Rect:
535  case QVariant::RectF:
536  {
537  QRectF r = v.toRectF();
538  m_program->setUniformValue(name.constData(), r.x(), r.y(), r.width(), r.height());
539  }
540  break;
541  case QVariant::Vector3D:
543  break;
544  default:
545  break;
546  }
547  }
548 }
549 
550 static inline int size_of_type(GLenum type)
551 {
552  static int sizes[] = {
553  sizeof(char),
554  sizeof(unsigned char),
555  sizeof(short),
556  sizeof(unsigned short),
557  sizeof(int),
558  sizeof(unsigned int),
559  sizeof(float),
560  2,
561  3,
562  4,
563  sizeof(double)
564  };
565  return sizes[type - GL_BYTE];
566 }
567 
569 {
570  if (!m_program)
571  return;
572 
573  char const *const *attrNames = m_attributeNames.constData();
574  int offset = 0;
575  for (int j = 0; j < m_attributeNames.size(); ++j) {
576  if (!*attrNames[j])
577  continue;
578  Q_ASSERT_X(j < m_geometry.attributeCount(), "ShaderEffectItem::bindGeometry()", "Geometry lacks attribute required by material");
580  Q_ASSERT_X(j == a.position, "ShaderEffectItem::bindGeometry()", "Geometry does not have continuous attribute positions");
581 #if defined(QT_OPENGL_ES_2)
582  GLboolean normalize = a.type != GL_FLOAT;
583 #else
584  GLboolean normalize = a.type != GL_FLOAT && a.type != GL_DOUBLE;
585 #endif
586  if (normalize)
587  qWarning() << "ShaderEffectItem::bindGeometry() - non supported attribute type!";
588 
589  m_program->setAttributeArray(a.position, (GLfloat*) (((char*) m_geometry.vertexData()) + offset), a.tupleSize, m_geometry.stride());
590  //glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, m_geometry.stride(), (char *) m_geometry.vertexData() + offset);
591  offset += a.tupleSize * size_of_type(a.type);
592  }
593 }
594 
596 {
597  QRectF srcRect(0, 1, 1, -1);
598 
599  if (m_mirrored)
600  srcRect = QRectF(0, 0, 1, 1);
601 
602  QRectF dstRect = QRectF(0,0, width(), height());
603 
604  int vmesh = m_meshResolution.height();
605  int hmesh = m_meshResolution.width();
606 
607  QSGGeometry *g = &m_geometry;
608  if (vmesh == 1 && hmesh == 1) {
609  if (g->vertexCount() != 4)
610  g->allocate(4);
611  QSGGeometry::updateTexturedRectGeometry(g, dstRect, srcRect);
612  return;
613  }
614 
615  g->allocate((vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2));
616 
618 
619  for (int iy = 0; iy <= vmesh; ++iy) {
620  float fy = iy / float(vmesh);
621  float y = float(dstRect.top()) + fy * float(dstRect.height());
622  float ty = float(srcRect.top()) + fy * float(srcRect.height());
623  for (int ix = 0; ix <= hmesh; ++ix) {
624  float fx = ix / float(hmesh);
625  vdata->x = float(dstRect.left()) + fx * float(dstRect.width());
626  vdata->y = y;
627  vdata->tx = float(srcRect.left()) + fx * float(srcRect.width());
628  vdata->ty = ty;
629  ++vdata;
630  }
631  }
632 
633  quint16 *indices = (quint16 *)g->indexDataAsUShort();
634  int i = 0;
635  for (int iy = 0; iy < vmesh; ++iy) {
636  *(indices++) = i + hmesh + 1;
637  for (int ix = 0; ix <= hmesh; ++ix, ++i) {
638  *(indices++) = i + hmesh + 1;
639  *(indices++) = i;
640  }
641  *(indices++) = i - 1;
642  }
643 }
644 
646 {
647  if (m_active == enable)
648  return;
649 
650  if (m_active) {
651  for (int i = 0; i < m_sources.size(); ++i) {
652  ShaderEffectSource *source = m_sources.at(i).source;
653  if (!source)
654  continue;
655  disconnect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
656  source->derefFromEffectItem();
657  }
658  }
659 
660  m_active = enable;
661 
662  if (m_active) {
663  for (int i = 0; i < m_sources.size(); ++i) {
664  ShaderEffectSource *source = m_sources.at(i).source;
665  if (!source)
666  continue;
667  source->refFromEffectItem();
668  connect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
669  }
670  }
671 
672  // QGLShaderProgram is deleted when not active (to minimize GPU memory usage).
673  if (!m_active && m_program) {
674  delete m_program;
675  m_program = 0;
676  }
677 
679  markDirty();
680 }
681 
683 {
684  for (int i = 0; i < m_sources.size(); ++i) {
685  ShaderEffectSource *source = m_sources.at(i).source;
686  if (source)
687  source->updateBackbuffer();
688  }
689 }
690 
691 void ShaderEffectItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
692 {
693  if (newGeometry.size() != oldGeometry.size())
694  updateGeometry();
695  QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
696 }
697 
699 {
700  Q_ASSERT(index >= 0 && index < m_sources.size());
701  QVariant v = property(m_sources.at(index).name.constData());
702  setSource(v, index);
703 }
704 
706  update();
707 }
708 
710 {
711  Q_ASSERT(index >= 0 && index < m_sources.size());
712 
713  SourceData &source = m_sources[index];
714 
715  source.source = 0;
716  source.item = 0;
717  if (var.isNull()) {
718  return;
719  } else if (!qVariantCanConvert<QObject *>(var)) {
720  qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData());
721  return;
722  }
723 
724  QObject *obj = qVariantValue<QObject *>(var);
725 
726  source.source = qobject_cast<ShaderEffectSource *>(obj);
727  source.item = qobject_cast<QDeclarativeItem *>(obj);
728 
729  if (!source.item)
730  qWarning("Could not assign property '%s', did not implement QDeclarativeItem.", source.name.constData());
731 
732  if (!source.source)
733  qWarning("Could not assign property '%s', did not implement ShaderEffectSource.", source.name.constData());
734 
735  // TODO: Find better solution.
736  // 'source.item' needs a canvas to get a scenegraph node.
737  // The easiest way to make sure it gets a canvas is to
738  // make it a part of the same item tree as 'this'.
739  if (source.item && source.item->parentItem() == 0) {
740  source.item->setParentItem(this);
741  // Unlike in scenegraph, we cannot set item invisible here because qgraphicsview would optimize it away.
742  }
743 
744  // Unlike in scenegraph, ref counting is used to optimize memory consumption. Sources themself may free fbos when not referenced.
745  if (m_active && source.source) {
746  source.source->refFromEffectItem();
747  connect(source.source, SIGNAL(repaintRequired()), this, SLOT(markDirty()));
748  }
749 }
750 
752 {
753  disconnect(this, 0, this, SLOT(markDirty()));
754  for (int i = 0; i < m_sources.size(); ++i) {
755  SourceData &source = m_sources[i];
756  disconnect(this, 0, source.mapper, 0);
757  disconnect(source.mapper, 0, this, 0);
758  }
759 }
760 
762 {
764  for (it = m_uniformNames.begin(); it != m_uniformNames.end(); ++it) {
765  int pi = metaObject()->indexOfProperty(it->constData());
766  if (pi >= 0) {
767  QMetaProperty mp = metaObject()->property(pi);
768  if (!mp.hasNotifySignal())
769  qWarning("ShaderEffectItem: property '%s' does not have notification method!", it->constData());
770  QByteArray signalName("2");
771  signalName.append(mp.notifySignal().signature());
772  connect(this, signalName, this, SLOT(markDirty()));
773  } else {
774  qWarning("ShaderEffectItem: '%s' does not have a matching property!", it->constData());
775  }
776  }
777  for (int i = 0; i < m_sources.size(); ++i) {
778  SourceData &source = m_sources[i];
779  int pi = metaObject()->indexOfProperty(source.name.constData());
780  if (pi >= 0) {
781  QMetaProperty mp = metaObject()->property(pi);
782  QByteArray signalName("2");
783  signalName.append(mp.notifySignal().signature());
784  connect(this, signalName, source.mapper, SLOT(map()));
785  source.mapper->setMapping(this, i);
786  connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
787  } else {
788  qWarning("ShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
789  }
790  }
791 }
792 
794 {
796 
797  if (m_program)
799 
802  for (int i = 0; i < m_sources.size(); ++i) {
803  const SourceData &source = m_sources.at(i);
804  if (m_active && source.source)
805  source.source->derefFromEffectItem();
806  delete source.mapper;
807  }
808 
809  m_sources.clear();
810  m_program_dirty = true;
811 }
812 
814 {
815  QString vertexCode = m_vertex_code;
816  QString fragmentCode = m_fragment_code;
817 
818  if (vertexCode.isEmpty())
819  vertexCode = qt_default_vertex_code;
820 
821  if (fragmentCode.isEmpty())
822  fragmentCode = qt_default_fragment_code;
823 
824  lookThroughShaderCode(vertexCode);
825  lookThroughShaderCode(fragmentCode);
826 
828  qWarning("ShaderEffectItem: Missing reference to \'%s\'.", qt_postion_attribute_name);
830  qWarning("ShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
831  if (!m_respectsMatrix)
832  qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
833 
834  for (int i = 0; i < m_sources.size(); ++i) {
835  QVariant v = property(m_sources.at(i).name);
836  setSource(v, i); // Property exists.
837  }
838 
840 }
841 
843 {
844  if (!m_program)
845  return;
846 
847  QString vertexCode = m_vertex_code;
848  QString fragmentCode = m_fragment_code;
849 
850  if (vertexCode.isEmpty())
852 
853  if (fragmentCode.isEmpty())
855 
858 
859  for (int i = 0; i < m_attributeNames.size(); ++i) {
861  }
862 
863  if (!m_program->link()) {
864  qWarning("ShaderEffectItem: Shader compilation failed:");
865  qWarning() << m_program->log();
866  }
867 
869  qWarning("ShaderEffectItem: Missing reference to \'qt_Vertex\'.");
871  qWarning("ShaderEffectItem: Missing reference to \'qt_MultiTexCoord0\'.");
872  if (!m_respectsMatrix)
873  qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
874 
875  if (m_program->isLinked()) {
876  m_program->bind();
877  for (int i = 0; i < m_sources.size(); ++i)
878  m_program->setUniformValue(m_sources.at(i).name.constData(), (GLint) i);
879  }
880 
881  m_program_dirty = false;
882 }
883 
885 {
886  // Regexp for matching attributes and uniforms.
887  // In human readable form: attribute|uniform [lowp|mediump|highp] <type> <name>
888  static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)"));
889  Q_ASSERT(re.isValid());
890 
891  int pos = -1;
892 
893  //QString wideCode = QString::fromLatin1(code.constData(), code.size());
894  QString wideCode = code;
895 
896  while ((pos = re.indexIn(wideCode, pos + 1)) != -1) {
897  QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute
898  QByteArray type = re.cap(2).toLatin1(); // type
899  QByteArray name = re.cap(3).toLatin1(); // variable name
900 
901  if (decl == "attribute") {
902  if (name == qt_postion_attribute_name) {
904  } else if (name == "qt_MultiTexCoord0") {
905  if (m_attributeNames.at(0) == 0) {
907  }
909  } else {
910  // TODO: Support user defined attributes.
911  qWarning("ShaderEffectItem: Attribute \'%s\' not recognized.", name.constData());
912  }
913  } else {
914  Q_ASSERT(decl == "uniform");
915 
916  if (name == "qt_ModelViewProjectionMatrix") {
917  m_respectsMatrix = true;
918  } else if (name == "qt_Opacity") {
919  m_respectsOpacity = true;
920  } else {
921  m_uniformNames.insert(name);
922  if (type == "sampler2D") {
923  SourceData d;
924  d.mapper = new QSignalMapper;
925  d.source = 0;
926  d.name = name;
927  d.item = 0;
928  m_sources.append(d);
929  }
930  }
931  }
932  }
933 }
934 
936 {
937  setActive(isVisible());
938 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void lookThroughShaderCode(const QString &code)
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector...
Definition: qmatrix4x4.cpp:944
#define GL_ONE_MINUS_SRC_ALPHA
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
void setMeshResolution(const QSize &size)
void bindAttributeLocation(const char *name, int location)
Binds the attribute name to the specified location.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void disableAttributeArray(int location)
Disables the vertex array at location in this shader program that was enabled by a previous call to e...
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
The QVector3D class represents a vector or vertex in 3D space.
Definition: qvector3d.h:60
GLenum drawingMode() const
Definition: qsggeometry.h:82
void visibleChanged()
This signal gets emitted whenever the visibility of the item changes.
void * vertexData()
Definition: qsggeometry.h:88
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Definition: qsggeometry.h:168
void meshResolutionChanged()
static int size_of_type(GLenum type)
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
Definition: qregexp.cpp:4310
void removeAllShaders()
Removes all of the shaders that were added to this program previously.
void changeSource(int index)
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
int indexType() const
Definition: qsggeometry.h:98
QDeclarativeParserStatus ** d
void setSource(const QVariant &var, int index)
void setFragmentShader(const QString &code)
QVector< const char * > m_attributeNames
void setAttributeArray(int location, const GLfloat *values, int tupleSize, int stride=0)
Sets an array of vertex values on the attribute at location in this shader program.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item&#39;s changes in geometry from oldGeometry to newGeometry...
GLuint programId() const
Returns the OpenGL identifier associated with this shader program.
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
#define GL_DEPTH_TEST
#define it(className, varName)
QByteArray & append(char c)
Appends the character ch to this byte array.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void * indexData()
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
int height() const
Definition: qpaintdevice.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
QSGGeometry m_geometry
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setVertexShader(const QString &code)
void vertexShaderChanged()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
The QSignalMapper class bundles signals from identifiable senders.
Definition: qsignalmapper.h:56
QPointF pos() const
Returns the position of the item in parent coordinates.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QString log() const
Returns the errors and warnings that occurred during the last link() or addShader() with explicitly s...
virtual void componentComplete()
void setBlending(bool enable)
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
qreal effectiveOpacity() const
Returns this item&#39;s effective opacity, which is between 0.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
int stride() const
Definition: qsggeometry.h:112
iterator begin()
Definition: qset.h:166
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
static const char qt_emptyAttributeName[]
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source)
Compiles source as a shader of the specified type and adds it to this shader program.
bool isValid() const
Returns true if the regular expression is valid; otherwise returns false.
Definition: qregexp.cpp:3943
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
static const char qt_default_vertex_code[]
void setMapping(QObject *sender, int id)
Adds a mapping so that when map() is signalled from the given sender, the signal mapped(id) is emitte...
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QMatrix matrix() const
Returns the item&#39;s affine transformation matrix.
#define GL_TEXTURE0
Definition: glfunctions.h:61
int width() const
Returns the width.
Definition: qsize.h:126
void renderEffect(QPainter *painter, const QMatrix4x4 &matrix)
QFuture< void > map(Sequence &sequence, MapFunction function)
int width() const
Definition: qpaintdevice.h:91
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
#define GL_GREATER
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
Definition: qregexp.cpp:4136
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
The QDeclarativeItem class provides the most basic of all visual items in QML.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
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 rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void beginNativePainting()
Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying g...
Definition: qpainter.cpp:2032
QMetaMethod notifySignal() const
Returns the QMetaMethod instance of the property change notifying signal if one was specified...
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const char * name
#define emit
Definition: qobjectdefs.h:76
void blendingChanged()
virtual int type() const
Returns the type of an item as an int.
iterator end()
Definition: qset.h:169
static const char qt_postion_attribute_name[]
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
const_iterator insert(const T &value)
Definition: qset.h:179
void clear()
Definition: qset.h:87
#define GL_FLOAT
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item&#39;s changes in geometry from oldGeometry to newGeometry...
The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem.
#define glActiveTexture
Definition: glfunctions.h:69
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
#define GL_DEPTH_BUFFER_BIT
QPointer< ShaderEffectSource > source
static const char qt_default_fragment_code[]
#define GL_BLEND
#define GL_BYTE
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
Definition: qvariant.cpp:2447
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
virtual bool link()
Links together the shaders that were added to this program with addShader().
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.
Definition: qobject.cpp:2895
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
static const char qt_texcoord_attribute_name[]
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
quint16 * indexDataAsUShort()
Definition: qsggeometry.h:140
qreal y() const
This convenience function is equivalent to calling pos().
void setUniformValue(int location, GLfloat value)
Sets the uniform variable at location in the current context to value.
unsigned int GLenum
Definition: main.cpp:50
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
ShaderEffectItem(QDeclarativeItem *parent=0)
QGLShaderProgram * m_program
virtual void componentComplete()
int height() const
Returns the height.
Definition: qsize.h:129
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
Definition: qmatrix4x4.cpp:775
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
typedef GLint
Definition: glfunctions.h:67
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
const Attribute * attributes() const
Definition: qsggeometry.h:111
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
void updateEffectState(const QMatrix4x4 &matrix)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
QVector< SourceData > m_sources
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...
bool hasNotifySignal() const
Returns true if this property has a corresponding change notify signal; otherwise returns false...
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
void enableAttributeArray(int location)
Enables the vertex array at location in this shader program so that the value set by setAttributeArra...
int indexCount() const
Definition: qsggeometry.h:100
void endNativePainting()
Restores the painter after manually issuing native painting commands.
Definition: qpainter.cpp:2056
static void normalize(double &x, double &y)
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
QPointer< QDeclarativeItem > item
void allocate(int vertexCount, int indexCount=0)
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
typedef GLboolean
Definition: glfunctions.h:67
static bool hasOpenGLShaderPrograms(const QGLContext *context=0)
Returns true if shader programs written in the OpenGL Shading Language (GLSL) are supported on this s...
void fragmentShaderChanged()
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
void setActive(bool enable)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool isLinked() const
Returns true if this shader program has been linked; false otherwise.
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
#define GL_ONE
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
int attributeCount() const
Definition: qsggeometry.h:110
QSet< QByteArray > m_uniformNames
int vertexCount() const
Definition: qsggeometry.h:86