Skip to content

Latest commit

 

History

History
585 lines (435 loc) · 17 KB

Drawer.md

File metadata and controls

585 lines (435 loc) · 17 KB

Drawer

Members

vertexShaderSource

Vertex Shader

fragmentShaderSource

Fragment Shader

Functions

Drawer(id, webglErrorFunction)Object

Manages the drawing procedure

getMaximumTextureUnits()integer
setActiveTextureUnit(value)boolean

Get a texture unit and activate it

setTexture(image, unit, internalFormat, format)

Set image to specific texture unit

setUseTexture(unit)

Set fragment shader to read texture from specific texture unit.

setColorEnable()

Set fragment shader to read from active texture unit

setTextureEnable()

Set fragment shader to read from color uniform

setColor(r, g, b, a)

Set color to fragment shader and submit in the history

setColorVanilla(r, g, b, a)

Set color to fragment shader but don't submit in the history

setPositions(positions)

Submit vertices to the Array Buffer and submited in the history

setPositionsVanilla(positions)

Submit vertices to the Array Buffer

justDraw(positions)

Draw triangles that are passed.

draw(positions, r, g, b, a)

Draw triangles are passed with a specific color.

drawFromBuffer(count)

Draw triangles in the Array Buffer

clear(r, g, b, a)

Clear screen with passed color and reset the history.

setScale(scale)

Change scale value.

updateScale(scale)

Change scale value and redraw every shape

setTranslation(tx, ty)

Change translation value.

updateTextureScale(scale)

Update texture scale value and redraw every shape.

setTextureScale(scale)

Update texture scale value and calculate required settings.

updateTextureValues()

Reset some values calculated for texture by program. For example reset Base Translation of texture.

setTextureResolution(w, h)

Updates shader uniform that keeps textures resolution and submit that in history.

setTextureResolutionVanilla(w, h)

Updates shader uniform that keeps textures resolution and doesn't submit that in history.

setShaderTextureResolution(w, h)

Updates shader uniform that keeps textures resolution.

setTextureTranslationFromValuesToShader()

Set texture translation value from local variables to shader's uniform

setBaseTextureTranslation(tx, ty)

Change texture's base translation and set it's value to shader's uniform.

setTextureUserTranslation(tx, ty)

Set user-defined translation

setTextureTranslation(tx, ty)

Change texture translation and set it's value to shader's uniform. Calls Drawer.setTextureTranslationVanilla(tx, ty)

setTextureTranslationVanilla(tx, ty)

Change texture translation and set it's value to shader's uniform.

updateTranslation(tx, ty)

Update vertex translation value and redraw every shape.

repeatTheHistory()

Redraw any shape in history.

redraw()

Redraw any shape in history. (Call Drawer.repeatTheHistory() )

updateScaleIntoPoint(newScale, x, y)

Change scale centered on point P

createShader(type, source)WebGLShader

Create WebGL shader object from given data.

createProgram(vertexShader, fragmentShader)WebGLProgram

Create WebGL program object from given data.

enableBlending(sfactor, dfactor, equationA)

Enable blending pixels

disableTextureBlending()

Disable blending pixels

refitWebglToCanvas()

Refit WebGL's clip space to new size of the canvas

setup()

Initialize variables and uniforms

constructor(id, webglErrorFunction)

Construction Function

vertexShaderSource

Vertex Shader

Kind: global variable

fragmentShaderSource

Fragment Shader

Kind: global variable

Drawer(id, webglErrorFunction) ⇒ Object

Manages the drawing procedure

Kind: global function
Returns: Object - Drawer object

Param Type Description
id string id of canvas element
webglErrorFunction function callback function for when user cannot use webgl

getMaximumTextureUnits() ⇒ integer

Kind: global function
Returns: integer - Maximum Texture Units Number

setActiveTextureUnit(value) ⇒ boolean

Get a texture unit and activate it

Kind: global function
Returns: boolean - if texture unit number is not in valid range return true otherwise return false

Param Type Description
value integer texture unit

setTexture(image, unit, internalFormat, format)

Set image to specific texture unit

Kind: global function

Param Type Description
image Image texture
unit integer texture unit
internalFormat GLenum a GLenum specifying the color components in the texture
format GLenum a GLenum specifying the format of the texel data

setUseTexture(unit)

Set fragment shader to read texture from specific texture unit.

Kind: global function

Param Type Description
unit integer texture unit

setColorEnable()

Set fragment shader to read from active texture unit

Kind: global function

setTextureEnable()

Set fragment shader to read from color uniform

Kind: global function

setColor(r, g, b, a)

Set color to fragment shader and submit in the history

Kind: global function

Param Type Description
r integer red color in range 0-1
g integer green color in range 0-1
b integer blue color in range 0-1
a integer alpha color in range 0-1

setColorVanilla(r, g, b, a)

Set color to fragment shader but don't submit in the history

Kind: global function

Param Type Description
r integer red color in range 0-1
g integer green color in range 0-1
b integer blue color in range 0-1
a integer alpha color in range 0-1

setPositions(positions)

Submit vertices to the Array Buffer and submited in the history

Kind: global function

Param Type
positions *

setPositionsVanilla(positions)

Submit vertices to the Array Buffer

Kind: global function

Param Type Description
positions Array.<number> array of vertices [x1, y1, x2, y2, ...]

justDraw(positions)

Draw triangles that are passed.

Kind: global function

Param Type Description
positions Array.<number> array of vertices [x1, y1, x2, y2, ...]

draw(positions, r, g, b, a)

Draw triangles are passed with a specific color.

Kind: global function

Param Type Description
positions * array of vertices [x1, y1, x2, y2, ...]
r integer red color in range 0-1
g integer green color in range 0-1
b integer blue color in range 0-1
a integer alpha color in range 0-1

drawFromBuffer(count)

Draw triangles in the Array Buffer

Kind: global function

Param Type Description
count integer number of vertices

clear(r, g, b, a)

Clear screen with passed color and reset the history.

Kind: global function

Param Type Description
r integer red color in range 0-1
g integer green color in range 0-1
b integer blue color in range 0-1
a integer alpha color in range 0-1

setScale(scale)

Change scale value.

Kind: global function

Param Type Description
scale number new scale

updateScale(scale)

Change scale value and redraw every shape

Kind: global function

Param Type Description
scale number new scale

setTranslation(tx, ty)

Change translation value.

Kind: global function

Param Type Description
tx number X value of translation
ty number Y value of translation

updateTextureScale(scale)

Update texture scale value and redraw every shape.

Kind: global function

Param Type Description
scale number new scale value

setTextureScale(scale)

Update texture scale value and calculate required settings.

Kind: global function

Param Type Description
scale number new scale value

updateTextureValues()

Reset some values calculated for texture by program. For example reset Base Translation of texture.

Kind: global function

setTextureResolution(w, h)

Updates shader uniform that keeps textures resolution and submit that in history.

Kind: global function

Param Type Description
w number width of texture
h number heigt of texture

setTextureResolutionVanilla(w, h)

Updates shader uniform that keeps textures resolution and doesn't submit that in history.

Kind: global function

Param Type Description
w number width of texture
h number heigt of texture

setShaderTextureResolution(w, h)

Updates shader uniform that keeps textures resolution.

Kind: global function

Param Type Description
w number width of texture
h number heigt of texture

setTextureTranslationFromValuesToShader()

Set texture translation value from local variables to shader's uniform

Kind: global function

setBaseTextureTranslation(tx, ty)

Change texture's base translation and set it's value to shader's uniform.

Kind: global function

Param Type Description
tx number X value of translation
ty number Y value of translation

setTextureUserTranslation(tx, ty)

Set user-defined translation

Kind: global function

Param Type Description
tx number X value of translation
ty number Y value of translation

setTextureTranslation(tx, ty)

Change texture translation and set it's value to shader's uniform. Calls Drawer.setTextureTranslationVanilla(tx, ty)

Kind: global function

Param Type Description
tx number X value of translation
ty number Y value of translation

setTextureTranslationVanilla(tx, ty)

Change texture translation and set it's value to shader's uniform.

Kind: global function

Param Type Description
tx number X value of translation
ty number Y value of translation

updateTranslation(tx, ty)

Update vertex translation value and redraw every shape.

Kind: global function

Param Type Description
tx number X value of translation
ty number Y value of translation

repeatTheHistory()

Redraw any shape in history.

Kind: global function

redraw()

Redraw any shape in history. (Call Drawer.repeatTheHistory() )

Kind: global function

updateScaleIntoPoint(newScale, x, y)

Change scale centered on point P

Kind: global function

Param Type Description
newScale number
x number x value of P
y number y value of P

createShader(type, source) ⇒ WebGLShader

Create WebGL shader object from given data.

Kind: global function
Returns: WebGLShader - webgl shader object

Param Type Description
type number gl.VERTEX_SHADER or gl.FRAGMENT_SHADER
source string GLSL source code of shader

createProgram(vertexShader, fragmentShader) ⇒ WebGLProgram

Create WebGL program object from given data.

Kind: global function
Returns: WebGLProgram - webgl program object

Param Type Description
vertexShader WebGLShader vertex shader
fragmentShader WebGLShader fragment shader

enableBlending(sfactor, dfactor, equationA)

Enable blending pixels

Kind: global function

Param Type Description
sfactor GLenum a GLenum specifying a multiplier for the source blending factors
dfactor GLenum a GLenum specifying a multiplier for the destination blending factors
equationA GLenum a GLenum specifying how source and destination colors are combined

disableTextureBlending()

Disable blending pixels

Kind: global function

refitWebglToCanvas()

Refit WebGL's clip space to new size of the canvas

Kind: global function

setup()

Initialize variables and uniforms

Kind: global function

constructor(id, webglErrorFunction)

Construction Function

Kind: global function

Param Type Description
id string id of canvas element
webglErrorFunction function callback function for when user cannot use webgl