B.Render.Device() -> B.Std.Listenable

Represent a rendering pipeline as stage-material grid. Makes and stores all entities within a rendering context.

To create the object use B.Render.makeDevice().

TYPES:

FrameInfo

Describes a frame information.

{number} fps

frames per second

{number} vertexDrawn

drawn vertex count

{number} vertexTotal

total vertex count

{number} primitiveDrawn

drawn primitive count

{number} primitiveTotal

total primitive count

{number} instanceDrawn

drawn instance count

{number} instanceTotal

total instance count

Caps

Represents capabilities of the hardware.

{boolean} indexUInt

32-bit unsigned integer mesh indices

{number} textureMaxSize

highest possible texture width/height

{number} cubemapMaxSize

highest possible cubemap width/height

{number} depthMaxSize

highest possible depth-stencil buffer width/height

{boolean} textureDXT

compressed texture formats

{boolean} textureFloat16

16-bit floating point texture formats

{boolean} textureFloat32

32-bit floating point texture formats

{boolean} textureFloat16Filter

16-bit floating point texture filtering

{boolean} textureFloat32Filter

32-bit floating point texture filtering

{boolean} colorTargetFloat16

rendering to 16-bit floating point texture

{boolean} colorTargetFloat32

rendering to 32-bit floating point texture

{number} colorTargetCount

highest possible multiple color targets count

{boolean} samplerAnisotropy

anisotropic filtering

{number} samplerMaxAnisotropy

highest possible level of anisotropic filtering

{boolean} readableDepth

reading from the depth buffer through a 2D-texture uniform

{boolean} writableDepth

writing to the depth buffer from the fragment shader

{boolean} derivatives

shader derivatives

{number} attributeCount

highest possible count of vertex shader attributes

{number} varyingCount

highest possible count of shader varyings

{number} vertexUniformCount

highest possible count of vertex shader uniforms

{number} vertexTextureCount

highest possible count of vertex shader textures

{number} fragmentUniformCount

highest possible count of fragment shader uniforms

{number} fragmentTextureCount

highest possible count of fragment shader textures

CONSTANTS:

{Object} TIME

Device time uniform placeholder. It allows to set the time value (wrapped by 1 ms) to a uniform value automatically.

device.uniform("time", B.Render.Device.TIME);

{Object} DELTA_TIME

Device delta time uniform placeholder. It allows to set the delta time value to a uniform value automatically.

device.uniform("deltaTime", B.Render.Device.DELTA_TIME);

METHODS:

makeMesh()

Makes a mesh.

RETURNS:

makeTexture(format, width, height, mipCount, faceCount)

Makes a 2D-texture/cubemap from parameters.

To check maximum 2D-texture/cubemap size use device.caps().textureMaxSize/cubemapMaxSize.

var
    // creating 2D-texture from parameters
    textureA = device.makeTexture(Format.RGBA, 128, 128, 1),

    // creating cubemap from parameters
    textureB = device.makeTexture(Format.RGBA, 128, 128, 1, CubeFace.COUNT);

PARAMETERS:

{B.Render.Format} format

{number} [width]

must be power of 2

{number} [height]

must be power of 2

{number} [mipCount] = 0

omit if you want to build full mip levels chain

{number} [faceCount] = 1

omit for 2D-textures or set to CubeFace.COUNT for cubemaps

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeTexture(object)

Makes a 2D-texture from a source object.

To check maximum 2D-texture size use device.caps().textureMaxSize.

var textureA = device.makeTexture(image);

PARAMETERS:

{ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement} object

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeTexture(array)

Makes a cubemap from array of six source objects.

To check maximum cubemap texture size use device.caps().cubemapMaxSize.

var textureA = device.makeTexture([imgPX, imgNX, imgPY, imgNY, imgPZ, imgNZ]);

PARAMETERS:

{Array.<(ImageData|HTMLImageElement|HTMLCanvasElement|HTMLVideoElement)>} array

array of objects

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeDepth(format, width, height, readable)

Makes a depth.

To check maximum depth-stencil buffer width/height use device.caps().depthMaxSize.

PARAMETERS:

{B.Render.Format} format

{number} width

must be power of 2

{number} height

must be power of 2

{boolean} [readable] = false

true if you want read from the depth buffer through a 2D-texture uniform (to check hardware support use device.caps().readableDepth flag)

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeTarget(color, depth)

Makes a target from objects.

var targetA = device.makeTarget(texture.mip(0), depth),
    targetB = device.makeTarget(texture, depth); // equivalent to above
    targetC = device.makeTarget(texture); // no depth

PARAMETERS:

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeTarget(color, depth, width, height)

Makes a target from parameters.

var targetA = device.makeTarget(Format.RGBA, Format.DEPTH, 512, 512),
    targetB = device.makeTarget(Format.RGBA, false, 512, 512); // no depth

PARAMETERS:

{B.Render.Format} color

{B.Render.Format | false} [depth]

{number} [width]

{number} [height]

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeTarget(color, depth)

Makes a target from objects (multiple color output).

To check maximum color outputs count use device.caps().colorTargetCount.

var targetA = device.makeTarget([mip0, mip1], depth),
    targetB = device.makeTarget([texture1, texture2], depth); // equivalent to above
    targetC = device.makeTarget([texture1, texture2]); // no depth

PARAMETERS:

{Array.<(B.Render.Mip|B.Render.Texture)>} color

{B.Render.Depth} [depth]

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makeTarget(color, depth, width, height)

Makes a target from parameters (multiple color output).

To check maximum color outputs count use device.caps().colorTargetCount.

var targetA = device.makeTarget([Format.RGBA, Format.RGB], Format.DEPTH, 512, 512),
    targetB = device.makeTarget([Format.RGBA, Format.RGB], false, 512, 512); // no depth

PARAMETERS:

{Array.<B.Render.Format>} color

{B.Render.Format | false} [depth]

{number} [width]

{number} [height]

RETURNS:

THROWS:

{B.Render.Error}

if parameters configuration is invalid

makePass(vs, fs, macros)

Makes a pass.

PARAMETERS:

{string} vs

vertex shader source

{string} fs

fragment shader source

{Object.<string, string>} [macros]

shader macro defines

RETURNS:

THROWS:

{B.Render.Error}

if internal or linking error is occurred or shader source is invalid

{B.Render.Pass.CompileError}

if shader compilation error is occurred

stage(name, before)

Adds a new stage to the grid.

// adds new stage to the end of grid
device.stage("new-name");

// adds new stage before existing stage
device.stage("new-name", "existing-name");

PARAMETERS:

{string} name

{string} [before]

RETURNS:

stage(name)

Returns existing stage from the grid.

PARAMETERS:

{string} name

RETURNS:

stages()

Returns ordered array of all stage names.

RETURNS:

{Array.<string>}

material(name, before)

Adds a new material to the grid.

// adds new material to the end of grid
device.material("new-name");

// adds new material before existing material
device.material("new-name", "existing-name");

PARAMETERS:

{string} name

{string} [before]

RETURNS:

material(name)

Returns existing material from the grid.

PARAMETERS:

{string} name

RETURNS:

materials()

Returns ordered array of all material names.

RETURNS:

{Array.<string>}

instance(material, mesh, transform, culling)

Adds a new instance to the rendering.

PARAMETERS:

{string | B.Render.Material} material

string name or object

{B.Render.Mesh} mesh

{B.Math.Matrix4} [transform] = B.Math.Matrix4.IDENTITY

{boolean} [culling] = true

enable/disable frustum culling

RETURNS:

THROWS:

{B.Render.Error}

if the material is not found in the grid

uniforms()

Returns array of uniforms names.

RETURNS:

{Array.<string>}

uniform(name, value)

Sets uniform value.

device.
    uniform("someNumber", 1.5).
    uniform("someVector2", B.Math.makeVector2(1, 2)).
    uniform("someVector3", B.Math.makeVector3(1, 2, 3)).
    uniform("someVector4", B.Math.makeVector4(1, 2, 3, 4)).
    uniform("someColor", B.Math.makeColor(1, 0, 0, 0.5)).
    uniform("someMatrix3", B.Math.makeMatrix3().setRotationX(Math.PI)).
    uniform("someMatrix4", B.Math.makeMatrix4().setTranslation(1, 2, 3)).
    uniform("someTexture", dev.makeTexture(image)).
    uniform("someTexture", dev.stage("someStage").output().color()).
    uniform("someDepth", dev.stage("someStage").output().depth());

device.uniform("someTexture", null); // removing

PARAMETERS:

RETURNS:

uniform(name)

Gets uniform value.

PARAMETERS:

{string} name

RETURNS:

frame()

Performs a frame.

RETURNS:

FIRES:

target()

Returns device target.

canvas()

Returns linked canvas.

RETURNS:

{HTMLCanvasElement}

caps()

Returns hardware capabilities.

free()

Frees all internal data and objects.

EVENTS:

{B.Std.Event} lose

Reporting that the device has been lost.

{B.Std.Event} restore

Reporting that the device has been restored.

{B.Std.Event} resize

Reporting that the linked canvas element size has been changed.

{number} data.width

a new width

{number} data.height

a new height

CLASSES:

TYPES:

CONSTANTS:

METHODS:

EVENTS: