Example #1
0
 def __init__(self, project, filename, parent):
   self.mutex = QMutex()
   self.project = project
   self.filename = filename
   self.parent = parent
   self.surface = QOffscreenSurface()
   self.surface.setFormat(QSurfaceFormat.defaultFormat())
   self.surface.create()
Example #2
0
    def __init__(self, id: str, app: QGuiApplication):
        assert self._initialized
        self.id = id
        self.app = app
        self.qml_view = QUrl(os.fspath(get_data_path("webview.qml")))

        gl_context = QOpenGLContext()
        gl_context.setFormat(QSurfaceFormat.defaultFormat())
        gl_context.create()

        self.client = Client(id, self.qml_view, gl_context)
        self.client.disconnected.connect(self.on_disconnected)
        self.client.start()
Example #3
0
 def create_gl_widget():
     # QGLWidget Not currently available in pyside2.
     # It has actually been deprecated and we should use
     # QtGui.QGLFormat and other related classes instead.
     from PyQt5.QtWidgets import QOpenGLWidget
     from PyQt5.QtGui import QSurfaceFormat
     from PyQt5 import QtOpenGL
     QGLFormat = QtOpenGL.QGLFormat
     QGL = QtOpenGL.QGL
     open_gl_widget = QOpenGLWidget()
     fmt = QSurfaceFormat.defaultFormat()
     fmt.setSamples(8)
     open_gl_widget.setFormat(fmt)
     return open_gl_widget
Example #4
0
 def is_good_opengl_version():
     from PyQt5.QtGui import QSurfaceFormat
     default_format = QSurfaceFormat.defaultFormat()
     return default_format.majorVersion() >= 2
Example #5
0
    def __init__(self, window):

        self.window = window

        self.offscreenSurface = QOffscreenSurface()
        sformat = QSurfaceFormat.defaultFormat()
        sformat.setDepthBufferSize(32)
        self.offscreenSurface.setFormat( sformat )
        self.offscreenSurface.create()

        self.overlayCamera = Qt3DRender.QCamera()
        self.overlayCamera.setViewCenter( vec3d() )
        self.overlayCamera.setPosition( vec3d( 0, 0, -1 ) )
        self.overlayCamera.setUpVector( vec3d( 0, 1, 0 ) )
        self.overlayCamera.lens().setOrthographicProjection( -1, 1, -1, 1, -1, 1 )

        # Framegraph root #1 -- onscreen rendering
        self.surfaceSelector = Qt3DRender.QRenderSurfaceSelector()
        self.surfaceSelector.setSurface(window)
        self.root = self.surfaceSelector


        # Framgraph root #2 -- Used for offscreen renders, not in the graph by default
        # During screenshots, offscreenSurfaceSelector becomes the root
        # and the branch roots will become a child of renderTargetSelector
        self.offscreenSurfaceSelector = Qt3DRender.QRenderSurfaceSelector()
        self.offscreenSurfaceSelector.setSurface(self.offscreenSurface)
        self.renderTargetSelector = Qt3DRender.QRenderTargetSelector(self.offscreenSurfaceSelector)
        self.targetTexture = OffscreenRenderTarget(self.renderTargetSelector)
        self.renderTargetSelector.setTarget(self.targetTexture)
        self.noDraw2 = Qt3DRender.QNoDraw(self.renderTargetSelector)

        # Branch 1: clear buffers
        self.clearBuffers = Qt3DRender.QClearBuffers(self.surfaceSelector)
        self.clearBuffers.setBuffers(Qt3DRender.QClearBuffers.ColorDepthBuffer)
        self.clearBuffers.setClearColor(Qt.white)
        self.noDraw = Qt3DRender.QNoDraw(self.clearBuffers)

        # Branch 2: main drawing branches using the Athena camera
        self.cameraSelector = Qt3DRender.QCameraSelector(self.surfaceSelector)
        self.cameraSelector.setCamera(window.camera())

        # Branch 2A: solid objects
        self.viewport = Qt3DRender.QViewport(self.cameraSelector)
        self.viewport.setNormalizedRect(QRectF(0, 0, 1.0, 1.0))
        self.qfilt = Qt3DRender.QTechniqueFilter(self.viewport)
        self.solidPassFilter = Qt3DRender.QFilterKey(self.qfilt)
        self.solidPassFilter.setName('pass')
        self.solidPassFilter.setValue('solid')
        self.qfilt.addMatch(self.solidPassFilter)

        # Branch 2B: transparent objects
        self.viewport2 = Qt3DRender.QViewport(self.cameraSelector)
        self.viewport2.setNormalizedRect(QRectF(0, 0, 1.0, 1.0))
        self.qfilt2 = Qt3DRender.QTechniqueFilter(self.viewport2)
        self.transPassFilter = Qt3DRender.QFilterKey(self.qfilt2)
        self.transPassFilter.setName('pass')
        self.transPassFilter.setValue('transp')
        self.qfilt2.addMatch(self.transPassFilter)

        # Branch 3: 2D screen overlays
        self.cameraSelector2 = Qt3DRender.QCameraSelector(self.surfaceSelector)
        self.cameraSelector2.setCamera(self.overlayCamera)
        self.viewport3 = Qt3DRender.QViewport(self.cameraSelector2)
        self.viewport3.setNormalizedRect(QRectF(0, 0, 1.0, 1.0))
        self.qfilt3 = Qt3DRender.QTechniqueFilter(self.viewport3)
        self.overlayPassFilter = Qt3DRender.QFilterKey(self.viewport3)
        self.overlayPassFilter.setName('pass')
        self.overlayPassFilter.setValue('overlay')
        self.qfilt3.addMatch(self.overlayPassFilter)

        # Branch 4: render capture branch for taking screenshots
        self.renderCapture = Qt3DRender.QRenderCapture(self.surfaceSelector)
        self.noDraw3 = Qt3DRender.QNoDraw(self.renderCapture)

        # Branch roots are the bits that need reparenting when switching between
        # offscreen and onscreen rendering
        self.branchRoots = [ self.clearBuffers, self.cameraSelector, self.cameraSelector2, self.renderCapture ]