How to use the wgpu.wgpu_ffi.ffi function in wgpu

To help you get started, we’ve selected a few wgpu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github almarklein / wgpu-py / examples / test-wgpu.py View on Github external
def create_window_qt(width, height, name, instance_handle):
    from PyQt5 import QtCore, QtGui, QtWidgets

    app = QtWidgets.QApplication([])

    if BACKEND in ("CTYPES", "FFI"):
        window = QtGui.QWindow(None)
        # Use winId() or effectiveWinId() to get the Windows window handle
        hwnd = wgpu.wgpu_ffi.ffi.cast("void *", int(window.winId()))
        hinstance = wgpu.wgpu_ffi.ffi.NULL
        surface = ctx.create_surface_from_windows_hwnd(hinstance, hwnd)
    else:
        # class MyQt5OpenGLWidget(QtWidgets.QOpenGLWidget):
        #     def paintEvent(self, event):
        #         self.makeCurrent()
        # todo: GL does currently not work on Qt - I'm fighting contexts / swap buffers
        window = QtGui.QWindow(None)
        window.setSurfaceType(QtGui.QWindow.OpenGLSurface)
        window.ctx = QtGui.QOpenGLContext(window)
        window.ctx.setFormat(window.requestedFormat())
        window.ctx.create()
        window.ctx.makeCurrent(window)
        surface = window

    window.resize(width, height)
    window.setTitle(name + " | " + BACKEND)
github almarklein / wgpu-py / examples / test-wgpu.py View on Github external
def create_window_qt(width, height, name, instance_handle):
    from PyQt5 import QtCore, QtGui, QtWidgets

    app = QtWidgets.QApplication([])

    if BACKEND in ("CTYPES", "FFI"):
        window = QtGui.QWindow(None)
        # Use winId() or effectiveWinId() to get the Windows window handle
        hwnd = wgpu.wgpu_ffi.ffi.cast("void *", int(window.winId()))
        hinstance = wgpu.wgpu_ffi.ffi.NULL
        surface = ctx.create_surface_from_windows_hwnd(hinstance, hwnd)
    else:
        # class MyQt5OpenGLWidget(QtWidgets.QOpenGLWidget):
        #     def paintEvent(self, event):
        #         self.makeCurrent()
        # todo: GL does currently not work on Qt - I'm fighting contexts / swap buffers
        window = QtGui.QWindow(None)
        window.setSurfaceType(QtGui.QWindow.OpenGLSurface)
        window.ctx = QtGui.QOpenGLContext(window)
        window.ctx.setFormat(window.requestedFormat())
        window.ctx.create()
        window.ctx.makeCurrent(window)
        surface = window

    window.resize(width, height)
github almarklein / wgpu-py / visvis2 / _renderer.py View on Github external
def compose_pipeline(self, wobject):
        ffi = wgpu.wgpu_ffi.ffi
        ctx = self._ctx
        device_id = self._device_id

        # Get description from world object
        pipelinedescription = wobject.describe_pipeline()

        vshader = pipelinedescription["vertex_shader"]  # an SpirVModule
        vs_module = ctx.device_create_shader_module(
            device_id,
            ctx.create_ShaderModuleDescriptor(code=ffi_code_from_spirv_module(vshader)),
        )

        fshader = pipelinedescription["fragment_shader"]
        fs_module = ctx.device_create_shader_module(
            device_id,
            ctx.create_ShaderModuleDescriptor(code=ffi_code_from_spirv_module(fshader)),
github almarklein / wgpu-py / visvis2 / _renderer.py View on Github external
def __init__(self):
        self._pipelines = []

        ffi = wgpu.wgpu_ffi.ffi

        # todo: this context is not really a context, its just an API, maybe keep it that way, or make it a context by including device_id
        ctx = wgpu.wgpu_ffi.RsWGPU()
        self._ctx = ctx

        self._surface_size = 0, 0
        # backends = 1 | 2 | 4 | 8  # modern, but Dx12 is still buggy
        backends = 2 | 4  # Vulkan or Metal
        # on HP laptop: 2 and 8 are available, but 2 does not work. 8 works, but it wants zero bind groups :/
        # 1 => Backend::Empty,
        # 2 => Backend::Vulkan,
        # 4 => Backend::Metal,
        # 8 => Backend::Dx12,
        # 16 => Backend::Dx11,
        # 32 => Backend::Gl,
github almarklein / wgpu-py / visvis2 / _figure.py View on Github external
def _visvis_get_surface_id(self, ctx):  # called by renderer
        # Memoize
        if self._surface_id is not None:
            return self._surface_id

        if sys.platform.startswith("win"):
            # Use create_surface_from_windows_hwnd
            hwnd = wgpu.wgpu_ffi.ffi.cast("void *", int(self.winId()))
            hinstance = wgpu.wgpu_ffi.ffi.NULL
            surface_id = ctx.create_surface_from_windows_hwnd(hinstance, hwnd)

        elif sys.platform.startswith("linux"):
            # Use create_surface_from_xlib
            raise NotImplementedError("Linux")

        elif sys.platform.startswith("darwin"):
            # Use create_surface_from_metal_layer
            raise NotImplementedError("OS-X")

        else:
            raise RuntimeError("Unsupported platform")

        self._surface_id = surface_id
        return surface_id
github almarklein / wgpu-py / visvis2 / _figure.py View on Github external
def _visvis_get_surface_id(self, ctx):  # called by renderer
        # Memoize
        if self._surface_id is not None:
            return self._surface_id

        if sys.platform.startswith("win"):
            # Use create_surface_from_windows_hwnd
            hwnd = wgpu.wgpu_ffi.ffi.cast("void *", int(self.winId()))
            hinstance = wgpu.wgpu_ffi.ffi.NULL
            surface_id = ctx.create_surface_from_windows_hwnd(hinstance, hwnd)

        elif sys.platform.startswith("linux"):
            # Use create_surface_from_xlib
            raise NotImplementedError("Linux")

        elif sys.platform.startswith("darwin"):
            # Use create_surface_from_metal_layer
            raise NotImplementedError("OS-X")

        else:
            raise RuntimeError("Unsupported platform")

        self._surface_id = surface_id
        return surface_id