Skip to content

Instantly share code, notes, and snippets.

@rostikL
Last active December 18, 2019 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rostikL/7876e4c47fc8dd8ce02f to your computer and use it in GitHub Desktop.
Save rostikL/7876e4c47fc8dd8ce02f to your computer and use it in GitHub Desktop.
QQuickFramebufferObject
import QtQuick 2.3
import Renderer 1.0
Item {
width: 500
height: 600
FBORenderer{
id: fboRenderItem
anchors.fill: parent
}
Text {
anchors.bottom: fboRenderItem.bottom
x: 20
wrapMode: Text.WordWrap
text: "This is an openGl rendering with QQuickFrameBufferObject"
}
}
from PyQt5.QtCore import QUrl, qDebug, QObject
from PyQt5.QtGui import QGuiApplication, QOpenGLFramebufferObjectFormat, QOpenGLFramebufferObject
from PyQt5.QtQml import qmlRegisterType
from PyQt5.QtQuick import QQuickItem, QQuickView, QQuickFramebufferObject
class FbItemRenderer(QQuickFramebufferObject.Renderer):
def __init__(self, parent=None):
super(FbItemRenderer, self).__init__()
qDebug("Creating FbItemRenderer")
def createFrameBufferObject(self, size):
qDebug("Creating FrameBufferObject")
format = QOpenGLFramebufferObjectFormat()
format.setAttachment(QOpenGLFramebufferObject.Depth)
return QOpenGLFramebufferObject(size, format)
def synchronize(self, item):
qDebug("Synchronizing")
def render(self):
qDebug("Render")
# Called with the FBO bound and the viewport set.
# ... Issue OpenGL commands.
class FBORenderItem(QQuickFramebufferObject):
def __init__(self, parent=None):
qDebug("Create fborenderitem")
super(FBORenderItem, self).__init__(parent)
def createRenderer(self):
qDebug("Create renderer")
return FbItemRenderer()
if __name__ == '__main__':
import sys
app = QGuiApplication(sys.argv)
qmlRegisterType(FBORenderItem, "Renderer", 1, 0, "FBORenderer")
view = QQuickView()
view.setSource(QUrl("main.qml"))
view.show()
sys.exit(app.exec_())
@rostikL
Copy link
Author

rostikL commented Sep 14, 2015

Based on the instructions here: Integrating custom OpenGL rendering with Qt Quick via QQuickFramebufferObject

"QQuickFramebufferObject follows the well-known split: subclasses are expected to reimplement a createRenderer() virtual function. This factory function is always called on the scenegraph’s render thread (which is either the main (GUI) thread, or a separate, dedicated one)."

In c++:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment