Class: GlProgram

GlProgram

A wrapper for a WebGL Program. You can create one and then pass it to a shader. This will manage the WebGL program that is compiled and uploaded to the GPU.

To get the most out of this class, you should be familiar with glsl shaders and how they work.

There are a few key things that pixi shader will do for you automatically:

  • If no precision is provided in the shader, it will be injected into the program source for you. This precision will be taken form the options provided, if none is provided, then the program will default to the defaultOptions.
  • It will inject the program name into the shader source if none is provided.
  • It will set the program version to 300 es.

For optimal usage and best performance, its best to reuse programs as much as possible. You should use the GlProgram.from helper function to create programs.

new GlProgram (options)

Creates a shiny new GlProgram. Used by WebGL renderer.

Name Type Description
options GlProgramOptions

The options for the program.

See:

Example

// Create a new program
const program = new GlProgram({
  vertex: '...',
  fragment: '...',
});

Members

defaultOptions Partial<GlProgramOptions> static

The default options used by the program.

fragment string readonly

the fragment glsl shader source.

transformFeedbackVaryings {
   names: string[],
   bufferMode: "separate" | "interleaved"
}

details on how to use this program with transform feedback

vertex string readonly

the vertex glsl shader source

Methods

from (options) GlProgram static

Helper function that creates a program for a given source. It will check the program cache if the program has already been created. If it has that one will be returned, if not a new one will be created and cached.

Name Type Description
options GlProgramOptions

The options for the program.

Returns:
Type Description
GlProgram A program using the same source

destroy () void

destroys the program