Skip to content
Alexander Orzechowski edited this page Oct 17, 2015 · 1 revision

This class manages draw calls and any buffers associated with rendering a model with select Tessellator.Shader.

  • NOTE: This is a resource so it includes a .dispose() function. This program is added to the global list of resources located in the main Tessellator context. This class is a little different then most because it will not recover from being disposed. You will need to create another Tessellator.Object.

###Constructor

  • Tessellator.Object(Tessellator tessellator, <optional>Constant type)
    Constructs a new Tessellator.Object.
  • ARGUMENT tessellator: the Tessellator context object that all resources be made on.
  • ARGUMENT type: the type of the geometry being passed. This argumnt may be emmited and it that case the .setType() function will need to be called. This will commonly be Tessellator.TRIANGLES

###Functions

  • .setType(Constant type)
    will set the current type declaration.
  • NOTE: if the type was not set by the constructor, this function will need to be called.

  • .resetIndices(<optional>type)
    this will reset the indices defined by the object to be encoded in the type variable provided.
  • ARGUMENT type: the encoding of the indices. Example Uint16Array, Uint8Array.

  • .getValue(String name)
  • ARGUMENT name: The name of the attribute you want to acquire.
  • RETURN: the array passed when creating setting a attribute
  • NOTE: if there is no attribute under the passed name, null will be returned
  • SEE: .setAttribute()

  • .setAttribute(String name, Constant dataSize, Tessellator.Object.Buffer buffer, <optional>boolean normalize, <optional>int stride, <optional>int offest)
    This will define a new attribute that will be sent to the shader when the object is to be rendered. If one already exists, it will overwrite it.
  • ARGUMENT name: The name of the attribute being set.
  • ARGUMENT dataSize: The size of each element in the buffer. Example Tessellator.VEC3
  • ARGUMENT buffer: The buffer of data to send to the shader when rendering
  • ARGUMENT normalize: whether or not the data passed to the shaders be normalized. Example: Uint8Array range is 0-255. That will be seen as 0-1 inside the shader. Defaults to false.
  • ARGUMENT stirde: the sum of the elements in the buffer. Defaults to sizeOf(buffer.dataSize)
  • ARGUMENT offset: the position of the first element in the buffer. Defaults to 0.

  • .setAttribute(String name, Constant dataSize, Tessellator.Array value, <optional>Array arrayType, <optional>boolean normalize, <optional>Constant type, <optional>int stride, <optional>int offest)
    This will define a new attribute that will be sent to the shader when the object is to be rendered. If one already exists, it will overwrite it.
  • ARGUMENT name: The name of the attribute being set.
  • ARGUMENT dataSize: The size of each element in the buffer. Example Tessellator.VEC3
  • ARGUMENT value: an array of values.
  • ARGUMENT arrayType: the way the passed value should be packed into memory. Defaults to Float32Array.
  • ARGUMENT normalize: whether or not the data passed to the shaders be normalized. Example: Uint8Array range is 0-255. That will be seen as 0-1 inside the shader. Defaults to false.
  • ARGUMENT type: a hint on how the graphics drivers shall optimize the passed buffer. Defaults to Tessellator.STATIC_DRAW
  • ARGUMENT stirde: the sum of the elements in the buffer. Defaults to sizeOf(buffer.dataSize)
  • ARGUMENT offset: the position of the first element in the buffer. Defaults to 0.

  • .setUniform(String name, Object value)
    if this object were to be rendered with a Tessellator.RenderMatrix then it will set the specified uniforms.
  • ARGUMENT name: the name of the attribute
  • ARGUMENT value: the value of the attribute
  • NOTE: .uniformCount property will be incremented by one if the uniform is not already previously set.
  • SEE: Tessellator.RenderMatrix

  • .getBuffer(String name)
  • RETURN: return a Tessellator.Object.Buffer associated with the attribute of the name.
  • ARGUMENT: the name of the attribute with the buffer in question
  • NOTE

  • .setAttributeData(String name, Tessellator.Array buffer, int off)
    This will set the data of an already existing attribute. The buffer passed does not have to be the size of the original buffer although it cannot be larger.
  • ARGUMENT name: the name of the attribute to set the buffer of.
  • ARGUMENT buffer: the data set. This does not need to be as long as the original buffer passed in .setAttruibute(). It will set all it can.
  • ARGUMENT offset: the position of the element in the original array that the buffer argument starts to write from.
  • SEE: .setAttribute()

  • .upload()
    This will upload all the attributes to the graphics processor that have not been uploaded yet.
  • NOTE: doing an action like .setAttribute() will leave the data on the graphics card not updated and will need to be re uploaded with this function.

  • .useOES()
    this will take use of the OES_vertex_array_object extension available on most WebGL implementations. The graphics processor will cache all the draw commands and the CPU will be relived of doing this instead. Performance is improved with this.

  • .useInstancing(String ... instancedArrays)
    This will take advantage of the ANGLE_instanced_arrays extension available on most WebGL implementations. Instancing is used to consolidate all draw calls that render similar object into one draw call.
  • ARGUMENT intancedArrays: All attributes that want to use instancing.
  • RETURN a function:
    • function (String name, int divisor)
      • ARGUMENT name: the name of the attribute that will be instanced
      • ARGUMENT divisor: the amount of times the current element in used before switching to the next one.
  • SEE: https://en.wikipedia.org/wiki/Geometry_instancing

  • .render(Tessellator.RenderMatrix matrix) Will render this object with the matrix passed.
  • ARGUMENT matrix: the matrix to use the properties from to render things.
  • NOTE: if this object has custom unifroms set by the .setUnfiorm() function, then they will be set to a copy of the matrix.

  • .render(Tessellator.Shader shader) Will render this object with the shader passed.
  • ARGUMENT shader: the shader that will render this object on the GPU.

  • .apply()
    calls .render() with the supplied arguments.
  • NOTE: this is implemented to support models.

  • .dispose()
    this will release all resources associated with this object. When done using this object, call this function or else the object will never be removed from graphics memory. If you call .link() then the program will be recreated as if the object was not disposed. Any attributes will get their .dispose() called if their .disposable flag is set to true

  • .disposable
    This variable dictates whether this program can be disposed by inheritance. It does not matter what this variable is set to if you call this function yourself.
  • SEE: .disposed
  • DEFAULT: true

  • .disposed
    This is a flag set to true if this resource is disposed. Calling .dispose() this flag will be set to true.
  • DEFAULT: false
  • SEE: .dispose()

###Internal

  • .bindAttributes(Tessellator.Shader shader)
    This will enable and bind any attributes and their associated buffers so that rendering can begin.
  • ARGUMENT shader: The shader that is going to be used to render the object.
  • NOTE: Any attributes that are set but do not exist in the shader and ignored and do net effect the shader.

  • .disableAttributes(Tessellator.Shader shader)
    This is called when the object is finished rendering and will disable all the attributes that the shader used.
  • ARGUMENT shader: the shader that was used by the .bindAttributes() function.
  • SEE: .bindAttributes()

###Static Members NOTE: these members are only used internally. The user of the api should not need to worry about this stuff.

  • .dataTypes
    An lookup table to convert all the different function types into types that WebGL understands. Example: this table will convert a Float32Array into a Tessellator.FLOAT.

  • .dataTypeSizes
    Similar to .dataTypes, this will lookup the size of the different data types. Example: Float32Array would lookup to be 4 bytes in length.

  • .dataSize This will convert the dataSize argument into a integer that WebGL understands. Example: Tessellator.VEC2 would turn into 2 as that is how many spaces a vec2 occupies.

##Tessellator.Object.Buffer This is a nested class that keeps track of the buffers on the CPU side and the GPU side.

###Constructor

###Functions

  • .getLength()
  • RETURN: the length of the buffer

  • .subData(Tessellator tessellator, value, off) Updates the data of the buffer.
  • ARGUMENT tessellator: The Tessellator that owns this buffer.
  • ARGUMENT value: the value of the buffer that is going to update the current buffer. Must be smaller or as large as the original buffer.
  • ARGUMENT: the start possition where the value starts to get written to the original buffer.
  • THROWS: if the value is larger then the buffer.
  • THROWS: if the offset is under 0.

  • .upload()
    This will upload the buffer onto the GPU if it hasn't already.

  • .dispose()
    Releases all the resources of the buffer and sets the .disposed flag.
Clone this wiki locally