Exemplo n.º 1
0
def get_default_format(*, gles: bool):
    fmt = QSurfaceFormat()
    fmt.setVersion(2, 0)
    fmt.setProfile(QSurfaceFormat.CoreProfile)
    fmt.setRenderableType(
        QSurfaceFormat.OpenGLES if gles else QSurfaceFormat.OpenGL)
    fmt.setDepthBufferSize(24)
    fmt.setStencilBufferSize(8)
    fmt.setOption(QSurfaceFormat.DebugContext)
    return fmt
Exemplo n.º 2
0
    def __init__(self, argv: List[str]):
        super().__init__(argv)
        self.setApplicationName('Qt Offscreen Rendering')

        format = QSurfaceFormat()
        format.setDepthBufferSize(16)
        format.setStencilBufferSize(8)

        self.window = MainWindow(format)
        self.window.addQmlView('View', os.path.join(os.path.dirname(__file__), 'view.qml'))
        self.window.addQmlView('Web', os.path.join(os.path.dirname(__file__), 'web.qml'))
 def defaultFormat(stereo_capable):
     fmt = QSurfaceFormat()
     fmt.setRenderableType(QSurfaceFormat.OpenGL)
     fmt.setVersion(3, 2)
     fmt.setProfile(QSurfaceFormat.CoreProfile)
     fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer)
     fmt.setRedBufferSize(8)
     fmt.setGreenBufferSize(8)
     fmt.setBlueBufferSize(8)
     fmt.setDepthBufferSize(8)
     fmt.setAlphaBufferSize(8)
     fmt.setStencilBufferSize(0)
     fmt.setStereo(stereo_capable)
     fmt.setSamples(0)
     return fmt
Exemplo n.º 4
0
def defaultVtkFormat(stereo_capable):
    """ Po prostu skopiowałem to z https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKRenderWindowAdapter.cxx
     i działa poprawnie bufor głębokości
    """
    fmt = QSurfaceFormat()
    fmt.setRenderableType(QSurfaceFormat.OpenGL)
    fmt.setVersion(3, 2)
    fmt.setProfile(QSurfaceFormat.CoreProfile)
    fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer)
    fmt.setRedBufferSize(8)
    fmt.setGreenBufferSize(8)
    fmt.setBlueBufferSize(8)
    fmt.setDepthBufferSize(8)
    fmt.setAlphaBufferSize(8)
    fmt.setStencilBufferSize(0)
    fmt.setStereo(stereo_capable)
    fmt.setSamples(0)
    return fmt
    def defaultSurfaceFormat(stereo_capable):
        """ Ported from: https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKRenderWindowAdapter.cxx
        """
        fmt = QSurfaceFormat()
        fmt.setRenderableType(QSurfaceFormat.OpenGL)
        fmt.setVersion(3, 2)
        fmt.setProfile(QSurfaceFormat.CoreProfile)
        fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer)
        fmt.setRedBufferSize(8)
        fmt.setGreenBufferSize(8)
        fmt.setBlueBufferSize(8)
        fmt.setDepthBufferSize(8)
        fmt.setAlphaBufferSize(8)
        fmt.setStencilBufferSize(0)
        fmt.setStereo(stereo_capable)
        fmt.setSamples(0)

        return fmt
Exemplo n.º 6
0
        self.__slot_channels()

    def __slot_checkerboard(self):
        self._viewport.set_colors(True, None, None)

    def __slot_solid_color(self):
        color = QColorDialog.getColor(Qt.black, self,
                                      "Choose background color")
        if color.isValid():
            self._viewport.set_colors(False, color, color)


if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)
    # must be called before the OpenGLWidget or its parent window gets shown
    # set default OpenGL surface format
    glformat = QSurfaceFormat()
    glformat.setDepthBufferSize(24)
    glformat.setStencilBufferSize(8)
    glformat.setVersion(3, 1)
    glformat.setProfile(QSurfaceFormat.CoreProfile)
    QSurfaceFormat.setDefaultFormat(glformat)
    # Create and show the form
    form = TViewerWindow()
    form.show()
    sample = join(dirname(realpath(__file__)), "rgba.tga")
    form.view(sample)
    # Run the main Qt loop
    sys.exit(app.exec_())
Exemplo n.º 7
0
import sys

from PySide2.QtCore import QCoreApplication, QPoint, QSize, Qt
from PySide2.QtGui import QSurfaceFormat
from PySide2.QtWidgets import QApplication

from window import Window

if __name__ == '__main__':
    fmt = QSurfaceFormat()
    fmt.setRenderableType(QSurfaceFormat.OpenGL)
    fmt.setVersion(2, 1)
    fmt.setProfile(QSurfaceFormat.CoreProfile)
    fmt.setSwapBehavior(QSurfaceFormat.DoubleBuffer)
    fmt.setSwapInterval(1)
    fmt.setStereo(False)
    fmt.setSamples(0)
    fmt.setRedBufferSize(8)
    fmt.setGreenBufferSize(8)
    fmt.setBlueBufferSize(8)
    fmt.setAlphaBufferSize(8)
    fmt.setDepthBufferSize(24)
    fmt.setStencilBufferSize(1)
    QSurfaceFormat.setDefaultFormat(fmt)

    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
Exemplo n.º 8
0
    def initialize(self, size: QSize, shareContext: QOpenGLContext) -> None:
        """
        Initialize offscreen renderer.

        Args:
            size: The size of the area available for rendering.
            shareContext: OpenGL context used as a share context.

        Raises:
            RuntimeError: If the renderer has already been initialized.
        """
        print(f'QmlOffscreenRenderer.initialize: {size}')
        if self.initialized:
            raise RuntimeError('Already initialized')

        format = QSurfaceFormat()
        format.setDepthBufferSize(16)
        format.setStencilBufferSize(8)
        context = QOpenGLContext()
        context.setFormat(format)
        context.setShareContext(shareContext)
        context.create()

        self.size = size
        self.context = context

        # Create offscreen surface with initialized format
        self._surface = surface = QOffscreenSurface()
        surface.setFormat(context.format())
        surface.create()

        # Set up quick rendering
        self._control = control = QQuickRenderControl()
        self._window = window = QQuickWindow(control)
        self._engine = engine = QQmlEngine()
        if not engine.incubationController():
            engine.setIncubationController(window.incubationController())

        # Don't polish/sync/render immediately for better performance, use a timer
        self._renderTimer = renderTimer = QTimer()
        renderTimer.setSingleShot(True)
        renderTimer.setInterval(5)
        renderTimer.timeout.connect(self._onRenderTimer)
        self._syncTimer = syncTimer = QTimer()
        syncTimer.setSingleShot(True)
        syncTimer.setInterval(5)
        syncTimer.timeout.connect(self._onSyncTimer)
        syncTimer.destroyed.connect(self._onSyncTimerDestroyed)

        # Request to create frame buffer
        window.sceneGraphInitialized.connect(self._onSceneGraphInitialized)
        # Request to release frame buffer
        window.sceneGraphInvalidated.connect(self._onSceneGraphInvalidated)
        # Only render is needed
        control.renderRequested.connect(self._onRenderRequested)
        # Polish, sync & render
        control.sceneChanged.connect(self._onSceneChanged)

        self.initialized = True

        # Load QML component
        self._component = component = QQmlComponent(self._engine, self.qmlUrl)
        if component.isLoading():
            component.statusChanged.connect(self._onComponentStatusChanged)
        else:
            self._attachRootItem()