Skip to content

graphics

FreeBodyEngine.graphics #

create_compute_buffer(data) #

Creates whatever buffer type the current compute backend's buffer blocks actually need - a real read/write SSBO under GL44, a read-only texture buffer under GL33, a read-only 2D-data-texture-backed buffer under WebGL2 (see graphics/webgl/buffer.py's WebGL2TextureBuffer) - so code calling ComputeShader.bind_buffer() doesn't need to know or care which one it got either.

create_compute_shader(source, injector=None, **kwargs) #

Creates a compute shader using whichever backend this session is (or will be) running under - GL44's real glDispatchCompute if the GPU/ driver support it, GL33's fullscreen-quad-emulated fallback otherwise, or WebGL2's own (also fullscreen-quad-emulated, plus a buffer-texture workaround of its own - see graphics/webgl/compute.py) version under a browser - entirely transparently. Code written against the returned ComputeShader never needs to know or branch on which backend actually produced it. Creates a GPU context automatically (see ensure_gpu_context()) if one doesn't exist yet.

create_raytrace_shader(source, injector=None) #

Creates a raytrace ('@raytrace') kernel using whichever backend this session is (or will be) running under. Unlike create_compute_shader(), there's no GL44 branch yet - raytracing here is always the same software-BVH-over-a-fullscreen-pass emulation (see graphics/gl33/ compute.py's GLRaytraceShader / graphics/webgl/compute.py's WebGL2RaytraceShader), just against a samplerBuffer-backed scene on desktop or a 2D-data-texture-backed one on web.

ensure_gpu_context() #

Makes sure a live GPU context - and the matching Renderer service - exists, transparently creating one if nothing has set one up yet. Write once, run anywhere: a normal windowed game already has both (the window is created, then get_renderer() picks and registers the right backend) by the time anything calls this, so it's a no-op there. It only ever does something for a program that wants GPU compute with no window at all - a benchmark, a command-line tool.

"No window at all" is the operative phrase: this does not register a 'window' service, hidden or otherwise - it uses core.window.glfw.create_raw_offscreen_context(), a bare GL context with no Window/Service wrapper, no input/event pump, nothing. GL33Renderer/ GL44Renderer.on_initialize() both handle 'window' simply not existing.

Not the same thing as fb.HEADLESS - that flag means "no GPU at all" (HeadlessWindow, an SDL dummy-driver window with no GL context, for a dedicated server that never touches graphics). This is the opposite: a real GPU context, with no window service at all standing in for one. Using this while HEADLESS is set is a contradiction and raises rather than guessing which one was actually meant.

get_renderer() #

Get the correct renderer for the platform.

fb.set_flag(fb.FORCE_RENDERER, "gl33") (or "gl44") overrides auto-detection entirely - the main reason to: comparing backends against each other (e.g. ComputeStressTest) needs the ability to pick GL33 deliberately even on hardware that's perfectly capable of GL44, which auto-detection alone could never do (it would always prefer the newer one).