How to use the wgpu.request_adapter 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 / tests / test_rs_basics.py View on Github external
def test_adapter_destroy():
    adapter = wgpu.request_adapter(canvas=None, power_preference="high-performance")
    assert adapter._id is not None
    adapter.__del__()
    assert adapter._id is None
github almarklein / wgpu-py / tests / test_api.py View on Github external
def request_adapter():
        pass

    async def request_adapter_async():
        pass

    old_request_adapter = wgpu.request_adapter
    try:
        wgpu.request_adapter = wgpu.base.request_adapter

        with raises(RuntimeError):
            wgpu._register_backend("foo", "foo")
        with raises(RuntimeError):
            wgpu._register_backend(request_adapter, "foo")
        wgpu._register_backend(request_adapter, request_adapter_async)
        assert wgpu.request_adapter is request_adapter
        assert wgpu.request_adapter_async is request_adapter_async

        wgpu.request_adapter = "anything not base.request_adapter"
        with raises(RuntimeError):
            wgpu._register_backend(request_adapter, request_adapter_async)

    finally:
        wgpu.request_adapter = old_request_adapter
github almarklein / wgpu-py / tests / test_api.py View on Github external
wgpu.request_adapter = wgpu.base.request_adapter

        with raises(RuntimeError):
            wgpu._register_backend("foo", "foo")
        with raises(RuntimeError):
            wgpu._register_backend(request_adapter, "foo")
        wgpu._register_backend(request_adapter, request_adapter_async)
        assert wgpu.request_adapter is request_adapter
        assert wgpu.request_adapter_async is request_adapter_async

        wgpu.request_adapter = "anything not base.request_adapter"
        with raises(RuntimeError):
            wgpu._register_backend(request_adapter, request_adapter_async)

    finally:
        wgpu.request_adapter = old_request_adapter
github almarklein / wgpu-py / tests / test_gui_glfw.py View on Github external
def test_glfw_canvas_render():
    """ Render an orange square ... in a glfw window.
    """

    import glfw
    from wgpu.gui.glfw import update_glfw_canvasses, WgpuCanvas

    canvas = WgpuCanvas()

    # wgpu.utils.get_default_device()
    adapter = wgpu.request_adapter(canvas=canvas, power_preference="high-performance")
    device = adapter.request_device()
    draw_frame1 = _get_draw_function(device, canvas)

    frame_counter = 0

    def draw_frame2():
        nonlocal frame_counter
        frame_counter += 1
        draw_frame1()

    canvas.request_draw(draw_frame2)

    # Give it a few rounds to start up
    for i in range(5):
        glfw.poll_events()
        update_glfw_canvasses()
github almarklein / wgpu-py / tests / test_api.py View on Github external
def test_register_backend_fails():
    def request_adapter():
        pass

    async def request_adapter_async():
        pass

    old_request_adapter = wgpu.request_adapter
    try:
        wgpu.request_adapter = wgpu.base.request_adapter

        with raises(RuntimeError):
            wgpu._register_backend("foo", "foo")
        with raises(RuntimeError):
            wgpu._register_backend(request_adapter, "foo")
        wgpu._register_backend(request_adapter, request_adapter_async)
        assert wgpu.request_adapter is request_adapter
        assert wgpu.request_adapter_async is request_adapter_async

        wgpu.request_adapter = "anything not base.request_adapter"
        with raises(RuntimeError):
            wgpu._register_backend(request_adapter, request_adapter_async)

    finally:
github almarklein / wgpu-py / tests / test_gui_glfw.py View on Github external
return int(glfw.get_wayland_window(self.__window))
                else:
                    return int(glfw.get_x11_window(self.__window))
            else:
                raise RuntimeError(f"Cannot get GLFW window id on {sys.platform}.")

        def get_display_id(self):
            return wgpu.WgpuCanvasInterface.get_display_id(self)

        def get_physical_size(self):
            psize = glfw.get_framebuffer_size(self.__window)
            return int(psize[0]), int(psize[1])

    canvas = CustomCanvas()

    adapter = wgpu.request_adapter(canvas=canvas, power_preference="high-performance")
    device = adapter.request_device()
    draw_frame = _get_draw_function(device, canvas)

    for i in range(5):
        time.sleep(0.01)
        glfw.poll_events()
        draw_frame()
github almarklein / wgpu-py / examples / cube_glfw.py View on Github external
import wgpu
from wgpu.gui.glfw import update_glfw_canvasses, WgpuCanvas
import wgpu.backends.rs  # noqa: F401, Select Rust backend
import numpy as np
from pyshader import python2shader, shadertype_as_ctype
from pyshader import Struct, mat4, vec4, vec2


# %% Create canvas and device

# Create a canvas to render to
glfw.init()
canvas = WgpuCanvas(title="wgpu cube with GLFW")

# Create a wgpu device
adapter = wgpu.request_adapter(canvas=canvas, power_preference="high-performance")
device = adapter.request_device(extensions=[], limits={})


# %% Generate data

# pos         texcoord
# x, y, z, w, u, v
vertex_data = np.array(
    [
        # top (0, 0, 1)
        [-1, -1, 1, 1, 0, 0],
        [1, -1, 1, 1, 1, 0],
        [1, 1, 1, 1, 1, 1],
        [-1, 1, 1, 1, 0, 1],
        # bottom (0, 0, -1)
        [-1, 1, -1, 1, 1, 0],
github almarklein / wgpu-py / wgpu / utils / _device.py View on Github external
def get_default_device():
    """ Get a wgpu device object. If this succeeds, it's likely that
    the WGPU lib is usable on this system. If not, this call will
    probably exit (Rust panic). When called multiple times,
    returns the same global device object (useful for e.g. unit tests).
    """
    global _default_device

    if _default_device is None:
        import wgpu.backends.rs  # noqa

        adapter = wgpu.request_adapter(canvas=None, power_preference="high-performance")
        _default_device = adapter.request_device()
    return _default_device