Skip to content
bg2 engine

PolyListRenderer

Wraps a PolyList for rendering. One PolyListRenderer instance per PolyList instance manages the vertex and index buffers that represent the geometry data.

import PolyListRenderer from "bg2e-js/ts/render/PolyListRenderer.js";
const polyList = createSphere(0.5);
const renderer = myRenderer.factory.polyList(polyList);
PropertyTypeDescription
polyListPolyListThe wrapped geometry data.
rendererRendererThe base renderer (WebGLRenderer) managing this PolyListRenderer.

Initializes the internal buffers (vertexBuffer, indexBuffer). Called once on creation. No action needed by default — called automatically by the WebGL implementation.

Updates internal buffers when the PolyList data changes (e.g., vertices, normals are added). Call after the polylist is modified.

polyList.addVertexPositions([...]);
renderer.refresh(); // Re-upload updated vertex data to GPU

Binds the PolyList’s vertex and index buffers to the current WebGL context, setting up all attribute pointers (positions, normals, texture coords). Called by RenderState.draw() before drawing.

Issues the WebGL draw call (drawElements for indexed, or drawArrays). Called by RenderState.draw().

Releases all GPU resources (vertex and index buffers). Call when removing objects from the scene.

renderer.destroy(); // Destroys the PolyListRenderer
polyList._renderer = null; // Clear the reference to allow disposal of the PolyList too