API Docs for: 1.4.0
Show:

Kiwi.Renderers.GLBlendMode Class

Module: Renderers
Parent Module: Kiwi

The Blend Mode object for recording and applying GL blend functions on a renderer.

Constructor

Kiwi.Renderers.GLBlendMode

(
  • gl
  • params
)
Kiwi.Renderers.GLBlendMode

Parameters:

  • gl WebGLRenderingContext
  • params Object

Methods

apply

(
  • gl
)
public

Sets the blend mode on the video card

Parameters:

  • gl WebGLRenderingContext

isIdentical

(
  • blendMode
)
Boolean public

Compares against another GLBlendMode

Parameters:

Returns:

Boolean:

Is this GLBlendMode identical to the passed GLBlendMode?

makeConstant

(
  • code
)
Number private

Formats a parameter into a GL context-compatible number. This recognises valid constant names, such as "SRC_ALPHA" or "REVERSE_AND_SUBTRACT", with some tolerance for case. It does not check for valid numeric codes.

Parameters:

  • code String

Returns:

Number:

readConfig

(
  • params
)
public

Set a blend mode from a param object.

This is the main method for configuring blend modes on a renderer. It resolves to a pair of calls to blendEquationSeparate and blendFuncSeparate. The params object should specify compatible terms, namely { srcRGB: a, dstRGB: b, srcAlpha: c, dstAlpha: d, modeRGB: e, modeAlpha: f }. You should set abcdef using either direct calls to a gl context (ie. gl.SRC_ALPHA) or by using predefined strings.

The predefined string parameters for blendEquationSeparate are:

FUNC_ADD, FUNC_SUBTRACT, and FUNC_REVERSE_SUBTRACT.

The predefined string parameters for blendFuncSeparate are:

ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, SRC_ALPHA_SATURATE, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR, CONSTANT_ALPHA, and ONE_MINUS_CONSTANT_ALPHA.

Parameters:

  • params Object

setMode

(
  • mode
)
public

Sets a blend mode by name. Name is case-tolerant.

These are shortcuts to setting the blend function parameters manually. A listing of valid modes follows. Each is listed with the parameters modeRGB, modeAlpha, srcRGB, dstRGB, srcAlpha, and dstAlpha, constants used in the gl calls "blendEquationSeparate(modeRGB, modeAlpha)" and "blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha". This is very technical, and will probably only be useful if you are developing your own shaders for Kiwi.js.

"NORMAL" or any non-recognised string will draw as normal, blending colour via alpha. FUNC_ADD, FUNC_ADD, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE.

"ADD" or "ADDITIVE" will add pixels to the background, creating a lightening effect. FUNC_ADD, FUNC_ADD, SRC_ALPHA, ONE, ONE, ONE.

"SUBTRACT" or "SUBTRACTIVE" will subtract pixels from the background, creating an eerie dark effect. FUNC_REVERSE_SUBTRACT, FUNC_ADD, SRC_ALPHA, ONE, ONE, ONE.

"ERASE" or "ERASER" will erase the game canvas itself, allowing the page background to show through. You can later draw over this erased region. FUNC_REVERSE_SUBTRACT, FUNC_REVERSE_SUBTRACT, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ONE, ONE.

"BLACK" or "BLACKEN" will turn all colour black, but preserve alpha. FUNC_ADD, FUNC_ADD, ZERO, ONE_MINUS_SRC_ALPHA, ONE, ONE.

Blend modes as seen in Adobe Photoshop are not reliably available via WebGL blend modes. Such blend modes require shaders to create.

Parameters:

  • mode String

Properties

_dstAlpha

Number private

Destination alpha factor used in WebGL blendfunc.

_dstRGB

Number private

Destination RGB factor used in WebGL blendfunc.

_modeAlpha

Number private

Alpha mode used in WebGL blendfunc.

_modeRGB

Number private

RGB mode used in WebGL blendfunc.

_srcAlpha

Number private

Source alpha factor used in WebGL blendfunc.

_srcRGB

Number private

Source RGB factor used in WebGL blendfunc.

dirty

Boolean public

Dirty flag indicates whether this object has been altered and needs to be processed.

gl

WebGLRenderingContext public

Target WebGL rendering context.