API Docs for:
Show:

LS.ShadersManager Class

Module: LS

ShadersManager is the static class in charge of loading, compiling and storing shaders for reuse.

Constructor

LS.ShadersManager

()

Methods

clearCache

()

Clears all the compiled shaders

compileShader

(
  • vs_code
  • fs_code
  • name
)
GL.Shader

Compiles a shader, the vertex and fragment shader are cached indepently to speed up compilations but a unique name must be provided

Parameters:

  • vs_code String

    the final source code for the vertex shader

  • fs_code String

    the final source code for the fragment shader

  • name String

    an unique name that should be associated with this shader

Returns:

GL.Shader:

shader

createDefaultShaders

(
  • id
)
String

Create some default shaders useful for generic situations (flat, texture and screenspace quad)

Parameters:

  • id String

Returns:

String:

code

get

(
  • id
  • macros
)
GL.Shader

Returns a compiled shader with this id and this macros

Parameters:

  • id String
  • macros String

Returns:

GL.Shader:

the shader, if not found the default shader is returned

getGlobalShaderInfo

(
  • id
)
Object

Returns the info of a global shader

Parameters:

  • id String

Returns:

Object:

shader info (code, macros supported, flags)

getSnippet

(
  • id
)
String

Returns the code of a snipper

Parameters:

  • id String

Returns:

String:

code

init

(
  • url
)

Initializes the shader manager

Parameters:

  • url String

    a url to a shaders.xml can be specified to load the shaders

loadFromXML

(
  • url
  • reset_old
  • ignore_cache
  • on_complete
)

Loads shaders code from an XML file

Parameters:

  • url String

    to the shaders file

  • reset_old Boolean

    to reset all the existing shaders once loaded

  • ignore_cache Boolean

    force to ignore web cache

  • on_complete Function

    callback once the file has been loaded and processed

processShadersXML

(
  • xml
)

extracts all the shaders from the XML doc

Parameters:

  • xml XMLDocument

registerCompiledShader

(
  • shader
  • key
  • id
)
GL.Shader

Stores a compiled shader program, so it can be reused

Parameters:

  • shader GL.Shader

    the compiled shader

  • key String

    unique id

  • id String

    the shader name

Returns:

GL.Shader:

shader

registerGlobalShader

(
  • vs_code
  • fs_code
)

extracts all the shaders from the XML doc

Parameters:

  • vs_code String
  • fs_code String

registerSnippet

(
  • id
  • code
)

Register a code snippet ready to be used by the #import clause in the shader

Parameters:

  • id String
  • code String

reloadShaders

(
  • on_complete
)

Reloads the XML file with the shaders, useful when editing the file

Parameters:

  • on_complete Function

    call when the shaders have been reloaded

resolve

(
  • query
)
GL.Shader

Resolves a shader query, returns the shader

Parameters:

  • query ShaderQuery

Returns:

GL.Shader:

the shader, if not found the default shader is returned