renderer
FreeBodyEngine.graphics.webgl.renderer
#
WebGL2Renderer: the web backend's Renderer implementation - see this package's other modules for the pieces it ties together (shader.py, mesh.py, framebuffer.py, texture.py). Mirrors GL33Renderer's shape and method set exactly (including which Renderer methods it does not override - load_image/load_image_from_atlas/load_material are abstract on the base class but GL33Renderer never implements them either, so nothing in the engine actually calls them; this backend matches that instead of inventing new behavior GL33 itself doesn't have).
The one structural difference from every desktop backend: OpenGL is a
global, thread-bound state machine (glFoo(...) always acts on "whatever
context is current"), so GL33Renderer never needs to pass a context object
around. WebGL2 is a JS object (WebGL2RenderingContext) - there's no
implicit "current context" - so this renderer resolves and caches it once,
as self.gl, and every other webgl/*.py module fetches it back via
get_service('renderer').gl.
WebGL2Renderer()
#
Bases: Renderer
The WebGL2 renderer - see this module's own docstring.
Sets the backend's Mesh subclass; the actual gl context is
resolved in on_initialize() from the window (which must already
exist and own a canvas/context by then - see WebWindow).
create_framebuffer
property
#
Returns WebGL2Framebuffer.
mesh_class = WebGL2Mesh
instance-attribute
#
clear(color)
#
Clears the currently bound framebuffer's color and depth
buffers to color.
clear_scissor()
#
create_buffer(data)
#
Not supported yet - see WebGL2Shader.set_buffer()'s own note;
nothing reaches this without a project shader declaring an FBUSL
@buffer block, which WebGL2Generator's empty CAPABILITIES
already rejects at compile time before this could ever run.
destroy()
#
No explicit GPU resource teardown - the WebGL2 context (and everything on it) is released the moment the browser tab itself goes away; there is no separate "close the context" call the way a native GL context has wglDeleteContext/etc.
disable_depth_testing()
#
draw_circle(radius, position, color)
#
Not implemented on GL33Renderer either - see its own stub.
draw_line(start, end, width, color)
#
Not yet implemented - GLES/WebGL2 also don't support
gl.lineWidth() beyond 1px on most implementations (unlike
GL33Renderer's glLineWidth), so this needs a real quad-based
thick-line mesh rather than a straight port; deferred rather than
silently drawing a 1px line no width argument actually
controls.
draw_mesh(mesh, material)
#
Binds material and draws mesh's indexed triangles. Unlike
GL33Renderer, there's no wireframe polygon-mode path -
gl.POLYGON_MODE/glPolygonMode don't exist in WebGL2/GLES at
all (wireframe rendering there needs a real line-topology mesh or
a shader-based edge trick instead), so a material with
render_mode == "wireframe" just draws filled on this backend.
draw_mesh_instanced(mesh, material, model_matrices, camera)
#
enable_depth_testing()
#
get_image_class()
#
get_max_buffer_size()
#
get_mesh_class()
#
load_shader(vertex, fragment, injector=Injector(), geometry=None)
#
Compiles vertex/fragment FBUSL source into a WebGL2Shader.
geometry is accepted only for interface parity - see
WebGL2Shader.init()'s own note on why a non-None value here
would already have failed before reaching this point.
on_initialize()
#
Resolves this session's WebGL2 context from the (required - unlike GL33Renderer, there's no true headless-compute path for web yet) 'window' service, enables standard alpha blending (matching GL33Renderer's own BlendMode.TRANSPARENT default - see its comment on why UI/sprite transparency depends on this being on), and sets the initial viewport.
resize(size)
#
Updates the WebGL2 viewport to size - the canvas's own
drawing-buffer resolution is already updated by WebWindow.update()
before this fires (it's what triggers the FRAMEBUFFER_RESIZE event
this is subscribed to - see Renderer.on_initialize()).
set_blend_mode(mode)
#
See GL33Renderer.set_blend_mode() - identical logic against
self.gl instead of PyOpenGL's global functions.
set_scissor(x, y, width, height)
#
See Renderer.set_scissor() - y flipped against the
framebuffer height, matching GL33Renderer.set_scissor()'s own
top-left-to-bottom-left conversion.