Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.cpp:
- int main(int argc, char *argv[])
- {
- using namespace vl;
- qmlRegisterType<QQuickViewport>("VP", 0, 1, "Viewport");
- QGuiApplication app(argc, argv, 5);
- QQuickView * view = new QQuickView();
- view->setResizeMode(QQuickView::SizeRootObjectToView);
- view->resize(600, 400);
- view->setSource(QUrl("main.qml"));
- view->show();
- return app.exec();
- }
- QQuickViewport.h
- class QQuickViewport : public QQuickItem
- {
- Q_OBJECT
- public:
- QQuickViewport(QQuickItem * parent = 0);
- protected:
- QSGNode *updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * data);
- };
- class QSGFrameBufferTextureNode : public QObject, public QSGSimpleTextureNode
- {
- Q_OBJECT
- public:
- QSGFrameBufferTextureNode(QQuickWindow *window);
- ~QSGFrameBufferTextureNode();
- virtual void preprocess();
- protected:
- virtual void mousePressEvent(QMouseEvent * event);
- virtual void hoverEnterEvent(QHoverEvent * event);
- private:
- std::unique_ptr<QOpenGLFramebufferObject> frame_buffer_object_;
- std::unique_ptr<QSGTexture> texture_;
- QQuickWindow *window_;
- };
- QQuickViewport.cpp
- QQuickViewport::QQuickViewport( QQuickItem * parent /*= 0*/ ) :
- QQuickItem(parent)
- {
- setFlags(ItemHasContents | ItemIsFocusScope);
- setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton);
- setAcceptHoverEvents(true);
- }
- QSGNode * QQuickViewport::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
- {
- QSGFrameBufferTextureNode *node = static_cast<QSGFrameBufferTextureNode *>(oldNode);
- if (!node)
- node = new QSGFrameBufferTextureNode(window());
- node->setRect(boundingRect());
- node->setFlags(QSGNode::UsePreprocess);
- return node;
- }
- QSGFrameBufferTextureNode::QSGFrameBufferTextureNode( QQuickWindow *window ) :
- window_(window)
- {
- }
- QSGFrameBufferTextureNode::~QSGFrameBufferTextureNode()
- {
- }
- void QSGFrameBufferTextureNode::preprocess()
- {
- QSize size = rect().size().toSize();
- QOpenGLFramebufferObjectFormat format;
- format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
- if (!frame_buffer_object_ || frame_buffer_object_->size() != size)
- {
- frame_buffer_object_.reset(new QOpenGLFramebufferObject(size, format));
- texture_.reset(window_->createTextureFromId(frame_buffer_object_->texture(), size));
- setTexture(texture_.get());
- }
- frame_buffer_object_->bind();
- glViewport(0, 0, size.width(), size.height());
- LogoRenderer renderer;
- renderer.initialize();
- renderer.render();
- frame_buffer_object_->bindDefault();
- window_->update();
- }
- void QSGFrameBufferTextureNode::mousePressEvent( QMouseEvent * event )
- {
- qDebug() << event->isAccepted();
- }
- void QSGFrameBufferTextureNode::hoverEnterEvent( QHoverEvent * event )
- {
- qDebug() << event->isAccepted();
- }
- script:
- import QtQuick 2.1
- import VP 0.1
- Item
- {
- id: item
- width: 400
- height: 300
- Viewport
- {
- id: renderer
- anchors.fill : parent
- visible: true
- enabled: true
- opacity: 1.0
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement