-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* work on manual glfw closed loop * working glfw example * lint with newer versions of flake8 and black * restore test file * add comments * convert some comments to docstrings * rename file
- Loading branch information
Showing
3 changed files
with
122 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
Direct integration of glfw and wgpu-py without using the | ||
wgpu.gui Canvas abstraction/class hierarchy. | ||
Demonstration for hardcore users that need total low-level | ||
control. | ||
# run_example = false | ||
""" | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import glfw | ||
|
||
from wgpu.backends.wgpu_native import GPUCanvasContext | ||
from wgpu.gui.glfw import get_surface_info, get_physical_size | ||
from wgpu.utils.device import get_default_device | ||
|
||
|
||
sys.path.insert(0, str(Path(__file__).parent)) | ||
|
||
from triangle import setup_draw # noqa: E402 | ||
|
||
|
||
class GlfwCanvas: | ||
"""Minimal canvas interface implementation to support GPUCanvasContext""" | ||
|
||
def __init__(self, window): | ||
self._window = window | ||
|
||
def get_surface_info(self): | ||
"""get window and display id, includes some triage to deal with OS differences""" | ||
return get_surface_info(self._window) | ||
|
||
def get_physical_size(self): | ||
"""get framebuffer size in integer pixels""" | ||
return get_physical_size(self._window) | ||
|
||
|
||
def main(): | ||
# get the gpu device/adapter combo | ||
device = get_default_device() | ||
|
||
# create a window with glfw | ||
glfw.init() | ||
# disable automatic API selection, we are not using opengl | ||
glfw.window_hint(glfw.CLIENT_API, glfw.NO_API) | ||
glfw.window_hint(glfw.RESIZABLE, True) | ||
window = glfw.create_window(640, 480, "glfw window", None, None) | ||
|
||
# create a WGPU context | ||
canvas = GlfwCanvas(window) | ||
context = GPUCanvasContext(canvas) | ||
|
||
# drawing logic | ||
draw_frame = setup_draw(context, device) | ||
|
||
# render loop | ||
while True: | ||
# draw a frame | ||
draw_frame() | ||
# present the frame to the screen | ||
context.present() | ||
# process inputs | ||
glfw.poll_events() | ||
|
||
# break on close | ||
if glfw.window_should_close(window): | ||
break | ||
|
||
# dispose all resources and quit | ||
glfw.terminate() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters