-
Notifications
You must be signed in to change notification settings - Fork 1
Tessellator
Alexander Orzechowski edited this page Oct 16, 2015
·
3 revisions
The Tessellator Object is the main class that will create resources and graphics for any <canvas>
element.
###Constructor
-
Tessellator(void)
This will create a new Tessellator object with default properties. The Tessellator.context object is populated with a new<canvas>
element that has its css height and width automatically set to "100%". After creating such an object theTessellator.canvas
object can be extracted and appended to the DOM tree. It can also be extracted and passed to a Tessellator.TextureVideo to behave as a standard texture in an existing Tessellator object.
-
Tessellator(DOMElement)
This will create a new Tessellator object with default properties. The argument passed must be a<canvas>
element or an exception will be thrown.
-
Tessellator(String)
This will create a new Tessellator object with default properties. The argument passed is assumed to be an existing dom element's id and will automatically callgetElementById()
.
-
Tessellator(..., Object)
This will create a new Tessellator object with custom properties defined by the object. The '...' argument is any of the previous specification listed so you can pass a DOMElement or a String as the '...' argument.
###Functions
-
.canvasResize()
This will do a check to see if the size of the canvas element is different from the cached size of the canvas. If so, it will reset thecanvas.width
andcanvas.height
and thewidth
andheight
properties of the Tessellator object.
-
.forceCanvasResize()
Similar to.canvasResize()
function, it will forcefully reset all the properties pertaining the size of the canvas without checks.
-
.width
Returns the cached width of the canvas element attached to the Tessellator. This will respect the scale.
-
.height
Returns the cached height of the canvas element attached to the Tessellator. This will respect the scale.
-
.originWidth
The same as.width
except it will not respect the scale.
-
.originHeight
The same as.height
except it will not respect the scale.
-
.dispose()
This will dispose all the resources created with this context removing them from memory making all resources useless. The Tessellator context itself is still usable although all resources will need to be recreated.
-
.setResolutionScale(x, y)
This will set the resolution scale of the Tessellator. If the size of the canvas is (100, 100) and the resolution scale is set to (0.1, 0.1) the resulting usable and renderable space will be (10, 10). The scale is done by CSS so that the pixels are linearly interpolated so that edjes are fuzzy. If this is not desired see theTessellator.BufferedRenderer
class.
-
.setResolutionScale(vec2)
This will set the resolution of an array passed that is at least two elements large. Calls.setResolutionScale(vec2[0], vec2[1])
. This will respect any tweens attached to the array.
-
.setResolutionScale(scale)
calls.setResolutionScale(scale, scale)
-
.printLowLevelAccess()
This is a debugging feature that should be used with caution. Every time the WebGL context is accessed, it will print a message in the console with the name of the function called and its arguments. The printed message will look something like this with the arguments printed as a list in the square brackets:
GL createBuffer: []
Note: do not call this when the application is running at regular speed: there may be potentially thousands of calls every second and this can make a browser unusable as it needs to display thousands of GL calls.
Note: Once called, there is no way to revert this. Calling.printLowLevelAccess()
again will just print the accesses two times instead of once.
-
.countLowLevelAccess()
Similar to.printLowLevelAccess()
except it counts the amount of times the WebGL context is accessed. This value is saved to.gledits
property as a integer. This can be reset to 0 and the value will simply continue to accumulate.
Note: Once called, there is no way to revert this. Calling.countLowLevelAccess()
again will just accumulate.gledits
at double the speed.
-
.getDataURL()
This is a shortcut function that ends up returning.canvas.toDataURL()
. This will return a url that is a png of the curret graphic on the.canvas
element.
-
.preRender()
This will set up the Tessellator to start rendering a frame. You may override this and call.super_preRender()
-
.postRender()
This will set up the Tessellator to end rendering a frame. You may override this and call.super_postRender()
-
.createRenderLoop()
This will return a newTessellator.RenderLoop()
initializing it with the passed arguments.
-
.create3DTextureModel(texture, width, height, depth)
This is a helper method to attempt to add depth to a texture as if it was putting peices of paper on top of eachother to create a stack with depth. This will return aTessellator.Model
with geometry scaled to match thewidth
,height
, anddepth
parameters.
-
.getPointerLock()
returns the dom element that currenly has locked the pointer
-
.hasPointerLock()
return true if this current Tessellator context has the pointer lock, false otherwise.
-
.aquirePointerLock()
This will request the browser to give the pointer lock to the current Tessellator context.
-
.releasePointerLock()
This will release the pointer lock if one exists.
-
.isFullscreen()
returns true of the current context is fullscreen, false otherwise
-
.exitFullScreen()
if the current context is fullscreen it will exit into windowed mode
-
.requestFullscreen()
this will request the brower to make the current context fullscreen.
Note: some browers will only allow you to enter fullscreen when a event happened like a click or a key on the keyboard.
-
.createModelFromObj(text, <optional>object)
this will read a the text as a .obj file. If the optionalTessellator.Object
argument is supplied, the geometry will be added to it, otherwise it will create its own and return it.
-
.loadObjModel(url, <optional>object)
This will load a .obj file form the specified url and pass the loaded text to.createModelFromObj()
returns aTessellator.Object
-
.createModelFromJSON(text, <optional>object)
This will load a object encoded with json.-
.vertexPositions
attribute is interpreted as the vertex positions -
.vertexTextureCoords
attribute is interpreted as the uv coordinates for textures applied to the model -
.vertexNormals
attribute is interpreted as the vertex normals
Returns aTessellator.Object
with the attributes set with the above attributes. All other attributes are ignored.
-
-
.loadJSONModel(url' <optional>object)
loads the url and returns.createModelFromJSON(loadedURL, object)
-
.loadTexture(url, <optional>filter)
loads a texture with the url and applies the filter. The filter will default toTessellator.TEXTURE_FILTER_DEFAULT
.
-
.createTexture()
calls.loadTexture()
with the supplied arugments
-
.createTextureQueue()
creates aTessellator.TextureQueue
with the supplied arguments.
-
.createVideoTexture()
creates aTessellator.VideoTexture
with the supplied arguments.
-
.loadVideoTexture()
calls.createVideoTexture()
with the supplied arguments.
-
.createTextureCubeMap()
creates aTessellator.TextureCubeMap
with thes supplied arguments.
-
.createTextureSolid()
creates aTessellator.TextureSolid
with the supplied arguments
-
.createTextureDrawable()
creates aTessellator.TextureDrawable
with the supplied arguments.
-
.createTextureBuffered()
creates aTessellator.TextureBuffered
with the supplied arguments.
-
.createTextureAtlas()
creates aTessellator.TextureAtlas
with the supplied arguments.
-
.createTextureAtlasAnimation()
creates aTessellator.TextureAtlasAnimation
with the supplied arguments.
-
.createShaderProgram(vertex, fragement)
creates a shader program with the vertex shader as the first string and the fragment shader the second argument.- If the vertex string ends with ".glsl" then this is interpreted as a url and will be loaded.
- If the vertex is a
Tessellator.Shader
, then it is directly passed to the program. - If the vertex is a dom element, then the code is extracted from it and interpreted.
- If the fragment string ends with ".glsl" then this is interpreted as a url and will be loaded.
- If the fragment is a
Tessellator.Shader
, then it is directly passed to the program. - If the fragment is a dom element, then the code is extracted from it and interpreted.
-
.createPixelShader(shader)
creates a spectial shader with the vertex shader asTessellator.PIXEL_SHADER_VERTEX_SHADER
and calls.createShaderProgram()
-
.createPixelShaderUV()
similar to.createPixelShader()
this usesTessellator.PIXEL_SHADER_VERTEX_UV_SHADER
as the vertex shader.
-
.createShader(source)
creates a single shader form the source passed. ATessellator.Prorgram
will need to be created for this shader to be useful.
-
.createObject()
creates aTessellater.Object
with the supplied arguments.
-
.renderModel(model, <optional>renderer)
renders a single frame of the supplied model with the renderer. If no renderer is usedTessellator.ModelRenderer()
will be used as the shader.
-
.createModel(<optional>renderer)
creates aTessellator.Model
with the optional custom renderer.
-
.createMatrix()
calls and returns.createModel()
-
source
Tessellator-
renderers
RendererAbstract
ModelRenderer
BufferedRenderer FullScreenRenderer -
shaders
Shader
Program
RenderMatrix -
geometry
Object
-