void ShaderEffectItem::setActive(bool enable) { if (m_active == enable) return; if (m_active) { for (int i = 0; i < m_sources.size(); ++i) { ShaderEffectSource *source = m_sources.at(i).source; if (!source) continue; disconnect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty())); source->derefFromEffectItem(); } } m_active = enable; if (m_active) { for (int i = 0; i < m_sources.size(); ++i) { ShaderEffectSource *source = m_sources.at(i).source; if (!source) continue; source->refFromEffectItem(); connect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty())); } } emit activeChanged(); markDirty(); }
void ShaderEffectSource::setSourceItem(QDeclarativeItem *item) { if (item == m_sourceItem) return; if (m_sourceItem) { disconnect(m_sourceItem, SIGNAL(widthChanged()), this, SLOT(markSourceSizeDirty())); disconnect(m_sourceItem, SIGNAL(heightChanged()), this, SLOT(markSourceSizeDirty())); if (m_refs) detachSourceItem(); } m_sourceItem = item; if (m_sourceItem) { // Must have some item as parent if (m_sourceItem->parentItem() == 0) m_sourceItem->setParentItem(this); if (m_refs) attachSourceItem(); connect(m_sourceItem, SIGNAL(widthChanged()), this, SLOT(markSourceSizeDirty())); connect(m_sourceItem, SIGNAL(heightChanged()), this, SLOT(markSourceSizeDirty())); } updateSizeAndTexture(); emit sourceItemChanged(); emit repaintRequired(); }
void ShaderEffectSource::bind() { GLint filtering = smooth() ? GL_LINEAR : GL_NEAREST; GLuint hwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatHorizontally) ? GL_REPEAT : GL_CLAMP_TO_EDGE; GLuint vwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatVertically) ? GL_REPEAT : GL_CLAMP_TO_EDGE; QOpenGLContext *context = QOpenGLContext::currentContext(); QOpenGLFunctions *f = context->functions(); if (!context->isOpenGLES()) f->glEnable(GL_TEXTURE_2D); if (m_fbo && m_fbo->isValid()) { f->glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); } else { m_dirtyTexture = true; emit repaintRequired(); markSourceItemDirty(); f->glBindTexture(GL_TEXTURE_2D, 0); } f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, smooth() ? GL_LINEAR : GL_NEAREST); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, hwrap); f->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, vwrap); }
void ShaderEffectSource::markSourceSizeDirty() { Q_ASSERT(m_sourceItem); if (m_textureSize.isEmpty()) updateSizeAndTexture(); if (m_refs) emit repaintRequired(); }
void ShaderEffectSource::setHideSource(bool hide) { if (hide == m_hideSource) return; m_hideSource = hide; emit hideSourceChanged(); emit repaintRequired(); }
void ShaderEffectSource::setLive(bool s) { if (s == m_live) return; m_live = s; emit liveChanged(); emit repaintRequired(); }
void ShaderEffectSource::setSourceRect(const QRectF &rect) { if (rect == m_sourceRect) return; m_sourceRect = rect; updateSizeAndTexture(); emit sourceRectChanged(); emit repaintRequired(); m_dirtyTexture = true; markSourceItemDirty(); }
void ShaderEffectSource::setTextureSize(const QSize &size) { if (size == m_textureSize) return; m_textureSize = size; updateSizeAndTexture(); emit textureSizeChanged(); emit repaintRequired(); m_dirtyTexture = true; markSourceItemDirty(); }
void ShaderEffectItem::setActive(bool enable) { if (m_active == enable) return; if (m_active) { for (int i = 0; i < m_sources.size(); ++i) { ShaderEffectSource *source = m_sources.at(i).source; if (!source) continue; disconnect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty())); source->derefFromEffectItem(); } } m_active = enable; if (m_active) { for (int i = 0; i < m_sources.size(); ++i) { ShaderEffectSource *source = m_sources.at(i).source; if (!source) continue; source->refFromEffectItem(); connect(source, SIGNAL(repaintRequired()), this, SLOT(markDirty())); } } // QGLShaderProgram is deleted when not active (to minimize GPU memory usage). if (!m_active && m_program) { delete m_program; m_program = 0; } emit activeChanged(); markDirty(); }
void ShaderEffectItem::setSource(const QVariant &var, int index) { Q_ASSERT(index >= 0 && index < m_sources.size()); SourceData &source = m_sources[index]; source.source = 0; source.item = 0; if (var.isNull()) { return; } else if (!qVariantCanConvert<QObject *>(var)) { qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData()); return; } QObject *obj = qVariantValue<QObject *>(var); source.source = qobject_cast<ShaderEffectSource *>(obj); source.item = qobject_cast<QDeclarativeItem *>(obj); if (!source.item) qWarning("Could not assign property '%s', did not implement QDeclarativeItem.", source.name.constData()); if (!source.source) qWarning("Could not assign property '%s', did not implement ShaderEffectSource.", source.name.constData()); // TODO: Find better solution. // 'source.item' needs a canvas to get a scenegraph node. // The easiest way to make sure it gets a canvas is to // make it a part of the same item tree as 'this'. if (source.item && source.item->parentItem() == 0) { source.item->setParentItem(this); // Unlike in scenegraph, we cannot set item invisible here because qgraphicsview would optimize it away. } // Unlike in scenegraph, ref counting is used to optimize memory consumption. Sources themself may free fbos when not referenced. if (m_active && source.source) { source.source->refFromEffectItem(); connect(source.source, SIGNAL(repaintRequired()), this, SLOT(markDirty())); } }
void ShaderEffectSource::markSceneGraphDirty() { m_dirtySceneGraph = true; emit repaintRequired(); }
void ShaderEffectSource::grab() { m_dirtyTexture = true; emit repaintRequired(); }