예제 #1
0
// THIS METHOD IS EXECUTED IN THE RENDERING THREAD
QSGNode*    QmlAsTexture::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
    qDebug() << "Updating paint node";
    if (!this->provider && this->sourceItem)
    {
        qDebug() << "Setting provider";
        this->provider = this->sourceItem->textureProvider();
        QObject::connect(this->provider, SIGNAL(textureChanged()), this, SLOT(textureChanged()), Qt::DirectConnection);
    }

    if (this->provider && !this->texture)
    {
        this->texture = this->provider->texture();
        qDebug() << "Texture Id " << this->texture->textureId() << " SIZE " << this->texture->textureSize();
        if (this->texture->textureId() == 0)
        {
            this->texture = NULL;
            this->update();
        }
        else
            emit textureChanged();
    }

    //if (this->texture && this->effectItem)
    //     this->effectItem->triggerDynamicTextureUpdate();

    //    this->update();
    return oldNode;
}
예제 #2
0
int main(int argc, char *argv[])
{    
    QApplication a(argc, argv);

    QImage texture("pics/nana.jpg");
    if (texture.isNull()) {
        qDebug() << "Couldn't read the default texture. Shadow building, but forgot to set the run directory?";
        return 0;
    }
    QPixmap *canvas = new QPixmap(texture.width(), texture.height());

    QGraphicsScene scene;
    scene.setItemIndexMethod(QGraphicsScene::NoIndex);
    Boids boids(&scene, canvas, &texture);


    SettingsPanel settings;
    settings.move(1250, 200);

    BoidsView view(canvas);


    QGLWidget* viewport = new QGLWidget();
    view.setViewport(viewport);
    view.setOptimizationFlag(QGraphicsView::DontSavePainterState);

    view.setAutoFillBackground(false);
    view.setGeometry(50, 100, texture.width(), texture.height());
    view.setScene(&scene);
    view.setSceneRect(-view.width() / 2, -view.height() / 2, view.width(), view.height());
    view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view.setWindowTitle("Boids");

    QObject::connect(&view, SIGNAL(mousePositionChanged(float,float)), &boids, SLOT(setTargetLocation(float,float)));
    QObject::connect(&view, SIGNAL(enableSimulation(bool)), &boids, SLOT(enableSimulation(bool)));
    QObject::connect(&settings, SIGNAL(boidCountChanged(int)), &boids, SLOT(setBoidCount(int)));
    QObject::connect(&settings, SIGNAL(trailOpacityChanged(int)), &boids, SLOT(setTrailOpacity(int)));
    QObject::connect(&settings, SIGNAL(textureChanged(QString)), &boids, SLOT(loadTexture(QString)));
    QObject::connect(&settings, SIGNAL(clearCanvas()), &boids, SLOT(clearCanvas()));
    QObject::connect(&settings, SIGNAL(saveCanvas(QString)), &boids, SLOT(saveCanvas(QString)));
    QObject::connect(&settings, SIGNAL(colorEvolutionRateChanged(int)), &boids, SLOT(setColorEvolutionRate(int)));
    QObject::connect(&settings, SIGNAL(coloringModeChanged(Boids::ColoringMode)), &boids, SLOT(setColoringMode(Boids::ColoringMode)));
    QObject::connect(&boids, SIGNAL(canvasChanged(QPixmap*)), &view, SLOT(canvasChanged(QPixmap*)));
    QObject::connect(&settings, SIGNAL(maximumSpeedChanged(int)), &boids, SLOT(setMaxBoidSpeed(int)));
    QObject::connect(&settings, SIGNAL(minimumDistanceChanged(int)), &boids, SLOT(setMinimumDistance(int)));
    QObject::connect(&settings, SIGNAL(inertiaChanged(int)), &boids, SLOT(setInertia(int)));

    boids.setBoidCount(settings.boidCount());
    boids.setColorEvolutionRate(settings.colorEvolutionRate());
    boids.setColoringMode(settings.coloringMode());
    boids.setTrailOpacity(settings.trailOpacity());
    boids.setMaxBoidSpeed(settings.maximumSpeed());
    boids.setMinimumDistance(settings.minimumDistance());
    boids.setInertia(settings.inertia());

    view.show();
    settings.show();
    return a.exec();
}
예제 #3
0
    void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &buffer)
    {
        Q_ASSERT(QThread::currentThread() == thread());
        m_ref = buffer;
        delete m_sgTex;
        m_sgTex = 0;
        if (m_ref.hasBuffer()) {
            if (buffer.isSharedMemory()) {
                m_sgTex = surfaceItem->window()->createTextureFromImage(buffer.image());
                if (m_sgTex) {
                    m_sgTex->bind();
                }
            } else {
                QQuickWindow::CreateTextureOptions opt = QQuickWindow::TextureOwnsGLTexture;
                QWaylandQuickSurface *surface = qobject_cast<QWaylandQuickSurface *>(surfaceItem->surface());
                if (surface && surface->useTextureAlpha()) {
                    opt |= QQuickWindow::TextureHasAlphaChannel;
                }

                GLuint texture;
                glGenTextures(1, &texture);
                glBindTexture(GL_TEXTURE_2D, texture);
#ifdef QT_WAYLAND_COMPOSITOR_GL
                buffer.bindToTexture();
#endif
                m_sgTex = surfaceItem->window()->createTextureFromId(texture , QSize(surfaceItem->width(), surfaceItem->height()), opt);
            }
        }
        emit textureChanged();
    }
예제 #4
0
void TextureDrop::TextureDropped(const QString& p_textureName)
{
	Render::TextureInterface* texture = m_engineInterface->GetTexture(p_textureName.toStdString());

	SetTexture(texture);

	emit textureChanged(texture);
}
예제 #5
0
void QQuickContext2DTexture::markDirtyTexture()
{
    if (m_onCustomThread)
        m_mutex.lock();
    m_dirtyTexture = true;
    emit textureChanged();
    if (m_onCustomThread)
        m_mutex.unlock();
}
예제 #6
0
파일: QtGLView.cpp 프로젝트: manaze/WMIT
QtGLView::QtGLView(QWidget *parent) :
		QGLViewer(parent),
		drawLightSource(true)
{
	setStateFileName(QString::null);
	connect(&textureUpdater, SIGNAL(fileChanged(QString)), this, SLOT(textureChanged(QString)));

	setShortcut(DISPLAY_FPS, 0); // Disable stuff that won't work.
	setGridIsDrawn(true);
	setAxisIsDrawn(true);
}
예제 #7
0
void TextureManager::onTextureLoaded(QString fileName, QSharedPointer<Texture> texture)
{
	// проверяем, используется ли текстура игровыми объектами
	TextureCache::iterator it = mTextureCache.find(fileName);
	if (it != mTextureCache.end() && !it->mTexture.isNull() && (!it->mTexture.toStrongRef()->isDefault() || !texture.isNull()))
	{
		// добавляем файл на слежение
		if (!texture.isNull())
		{
			QString path = Project::getSingleton().getRootDirectory() + fileName;
			if (!mWatcher->files().contains(path))
				mWatcher->addPath(path);
		}

		// выдаем сигнал об изменении текстуры и заменяем ее в кэше
		mPrimaryGLWidget->makeCurrent();
		QSharedPointer<Texture> newTexture = !texture.isNull() ? texture : QSharedPointer<Texture>(new Texture());
		emit textureChanged(fileName, newTexture);
		Q_ASSERT(it->mTexture.isNull());
		it->mTexture = newTexture;
	}
}
예제 #8
0
void LipstickCompositor::surfaceMapped()
{
    QWaylandSurface *surface = qobject_cast<QWaylandSurface *>(sender());
    //Ignore surface if it's not a window surface
    if (!surface->hasShellSurface())
        return;

    QVariantMap properties = surface->windowProperties();
    QString category = properties.value("CATEGORY").toString();

    if (surface->surfaceItem()) {
        // Always cause a repaint on surface mapped
        maybePostUpdateRequest();
        return;
    }

    // The surface was mapped for the first time
    int id = m_nextWindowId++;
    LipstickCompositorWindow *item = new LipstickCompositorWindow(id, category, surface, contentItem());
    item->setSize(surface->size());
    QObject::connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(windowDestroyed()));

    // Whenever the item is damaged, cause a full repaint
    QObject::connect(item, SIGNAL(textureChanged()), this, SLOT(maybePostUpdateRequest()));
    m_totalWindowCount++;
    m_mappedSurfaces.insert(id, item);

    item->setTouchEventsEnabled(true);

    emit windowCountChanged();
    emit windowAdded(item);

    windowAdded(id);

    emit availableWinIdsChanged();
}
예제 #9
0
 void fireTextureChanged() { emit textureChanged(); }
예제 #10
0
void QQuickShaderEffectCommon::updateMaterial(QQuickShaderEffectNode *node,
                                              QQuickShaderEffectMaterial *material,
                                              bool updateUniforms, bool updateUniformValues,
                                              bool updateTextureProviders)
{
    if (updateUniforms) {
        for (int i = 0; i < material->textureProviders.size(); ++i) {
            QSGTextureProvider *t = material->textureProviders.at(i);
            if (t) {
                QObject::disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()));
                QObject::disconnect(t, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*)));
            }
        }

        // First make room in the textureProviders array. Set to proper value further down.
        int textureProviderCount = 0;
        for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
            for (int i = 0; i < uniformData[shaderType].size(); ++i) {
                if (uniformData[shaderType].at(i).specialType == UniformData::Sampler)
                    ++textureProviderCount;
            }
            material->uniforms[shaderType] = uniformData[shaderType];
        }
        material->textureProviders.fill(0, textureProviderCount);
        updateUniformValues = false;
        updateTextureProviders = true;
    }

    if (updateUniformValues) {
        for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
            Q_ASSERT(uniformData[shaderType].size() == material->uniforms[shaderType].size());
            for (int i = 0; i < uniformData[shaderType].size(); ++i)
                material->uniforms[shaderType][i].value = uniformData[shaderType].at(i).value;
        }
    }

    if (updateTextureProviders) {
        int index = 0;
        for (int shaderType = 0; shaderType < Key::ShaderTypeCount; ++shaderType) {
            for (int i = 0; i < uniformData[shaderType].size(); ++i) {
                const UniformData &d = uniformData[shaderType].at(i);
                if (d.specialType != UniformData::Sampler)
                    continue;
                QSGTextureProvider *oldProvider = material->textureProviders.at(index);
                QSGTextureProvider *newProvider = 0;
                QQuickItem *source = qobject_cast<QQuickItem *>(qvariant_cast<QObject *>(d.value));
                if (source && source->isTextureProvider())
                    newProvider = source->textureProvider();
                if (newProvider != oldProvider) {
                    if (oldProvider) {
                        QObject::disconnect(oldProvider, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()));
                        QObject::disconnect(oldProvider, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*)));
                    }
                    if (newProvider) {
                        Q_ASSERT_X(newProvider->thread() == QThread::currentThread(),
                                   "QQuickShaderEffect::updatePaintNode",
                                   "Texture provider must belong to the rendering thread");
                        QObject::connect(newProvider, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()));
                        QObject::connect(newProvider, SIGNAL(destroyed(QObject*)), node, SLOT(textureProviderDestroyed(QObject*)));
                    } else {
                        const char *typeName = source ? source->metaObject()->className() : d.value.typeName();
                        qWarning("ShaderEffect: Property '%s' is not assigned a valid texture provider (%s).",
                                 d.name.constData(), typeName);
                    }
                    material->textureProviders[index] = newProvider;
                }
                ++index;
            }
        }
        Q_ASSERT(index == material->textureProviders.size());
    }
}
void QQuickContext2DTexture::markDirtyTexture()
{
    m_dirtyTexture = true;
    updateTexture();
    emit textureChanged();
}