Constructor
(abstract) new Renderer(canvas)
Creates a new Renderer instance and initializes the WebGL context.
Parameters:
| Name | Type | Description |
|---|---|---|
canvas |
HTMLCanvasElement | The canvas element to render to. |
- Source:
Members
fragmentShader :WebGLShader|null
Type:
- WebGLShader | null
- Source:
program :WebGLProgram|null
Type:
- WebGLProgram | null
- Source:
vertexShader :WebGLShader|null
Type:
- WebGLShader | null
- Source:
vertexShaderSource :string
Vertex shader source code
Type:
- string
- Source:
Methods
baseDraw()
Base draw operation: sets viewport, clears the canvas, and draws the quad.
Subclasses should call this after uploading their uniforms.
- Source:
compileShader(source, type) → {WebGLShader|null}
Compiles shader code.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
string | Shader source code |
type |
GLenum | Shader type (gl.VERTEX_SHADER or gl.FRAGMENT_SHADER) |
- Source:
Returns:
Compiled shader or null on failure
- Type
- WebGLShader | null
(abstract) createFragmentShaderSource() → {string}
Creates the fragment shader source code.
Must be implemented by subclasses to define their specific shader.
- Source:
Throws:
-
Always throws an error if not implemented.
- Type
- Error
Returns:
Fragment shader source code
- Type
- string
destroy()
Cleans up renderer resources and releases references.
- Source:
(abstract) draw()
Performs the rendering operation. Must be implemented by subclasses.
- Source:
Throws:
-
Always throws an error if not implemented.
- Type
- Error
(abstract) init()
Initializes the renderer. Must be implemented by subclasses.
- Source:
Throws:
-
Always throws an error if not implemented.
- Type
- Error
initGLProgram()
Initializes WebGL program, shaders, and full-screen quad.
Compiles vertex and fragment shaders, links the program,
and sets up the position attribute buffer.
- Source:
onProgramCreated()
Hook called after GL program is created and linked.
Subclasses can override to cache uniform locations.
Default implementation does nothing.
- Source:
onWebGLContextLost(event)
Handles WebGL context lost events and attempts to recover the context.
Parameters:
| Name | Type | Description |
|---|---|---|
event |
WebGLContextEvent | The context lost event. |
- Source:
(abstract) reset()
Resets the renderer to its initial state. Must be implemented by subclasses.
- Source:
Throws:
-
Always throws an error if not implemented.
- Type
- Error