Class VertexArray

java.lang.Object
rosequartz.gfx.VertexArray

public class VertexArray extends Object
Represents a vertex array, used to upload vertex data and triangles made from 3 of those vertices to the graphics card.
  • Constructor Details

    • VertexArray

      public VertexArray(int... attributeLengths) throws NotOnGraphicsThreadException
      Creates a VertexArray from the lengths of each vertex attribute.
      
       +--------+----------------+
       | Length | GLSL data type |
       +--------+----------------+
       | 1      | float          |
       | 2      | vec2           |
       | 3      | vec3           |
       | 4      | vec4           |
       | other  | [INVALID]      |
       +--------+----------------+
       
      A vertex array with these lengths:
      
       new VertexArray(2, 4)
       
      would be equal to this GLSL vertex shader signature:
      
       #version 330 core
       layout(location=0) in vec2 in_attribute_1;
       layout(location=1) in vec4 in_attribute_2;
       
      Parameters:
      attributeLengths - the lengths for all attributes of every vertex
      Throws:
      NotOnGraphicsThreadException
  • Method Details

    • vertex

      public VertexArray vertex(float... data)
      Adds a vertex at the end of the array.
      Parameters:
      data - the data to add
      Returns:
      this
    • clearVertices

      public VertexArray clearVertices()
      Clears all vertices from the array.
      Returns:
      this
    • uploadVertices

      public VertexArray uploadVertices() throws NotOnGraphicsThreadException
      Uploads all vertex data to the graphics card.
      Returns:
      this
      Throws:
      NotOnGraphicsThreadException
    • addAllVertices

      public VertexArray addAllVertices(VertexArray vertexArray)
      Copies all vertices from a given vertex array onto this one.
      Parameters:
      vertexArray - the buffer to copy from
      Returns:
      this
    • getVertexCount

      public int getVertexCount()
      Gets the amount of vertices in the array.
      Returns:
      vertex count
    • getUploadedVertexCount

      public int getUploadedVertexCount()
      Gets the amount of vertices currently uploaded to the GPU.
      Returns:
      uploaded vertex count
    • fragment

      public VertexArray fragment(int index1, int index2, int index3)
      Adds triangle / fragment at the end of the array. Must be made from three vertices already inside this buffer. For correct rendering, the vertices must be in counter-clockwise order.
      Parameters:
      index1 - vertex 1
      index2 - vertex 2
      index3 - vertex 3
      Returns:
      this
    • clearFragments

      public VertexArray clearFragments()
      Clears all triangles / fragments from the array.
      Returns:
      this
    • uploadFragments

      public VertexArray uploadFragments() throws NotOnGraphicsThreadException
      Upload all triangle / fragment data to the graphics card.
      Returns:
      this
      Throws:
      NotOnGraphicsThreadException
    • addAllFragments

      public VertexArray addAllFragments(VertexArray vertexArray)
      Copies all triangles / fragments from a given vertex array onto this one.
      Parameters:
      vertexArray - the array to copy from
      Returns:
      this
    • getFragmentCount

      public int getFragmentCount()
      Gets the amount of triangles / fragments in the array.
      Returns:
      triangle count
    • getUploadedFragmentCount

      public int getUploadedFragmentCount()
      Gets the amount of triangles / fragments currently uploaded to the GPU.
      Returns:
      uploaded triangle count
    • clear

      public VertexArray clear()
      Clears all vertices and triangles / fragments from the array.
      Returns:
      this
    • upload

      public VertexArray upload() throws NotOnGraphicsThreadException
      Upload all vertex and triangle / fragment data to the graphics card.
      Returns:
      this
      Throws:
      NotOnGraphicsThreadException
    • addAll

      public VertexArray addAll(VertexArray vertexArray)
      Copies all vertices and triangles / fragments from a given vertex array onto this one.
      Parameters:
      vertexArray - the array to copy from
      Returns:
      this
    • addAll

      public VertexArray addAll(Model model, ModelInstance modelInstance)
      Copies all vertices and triangles / fragments from a given vertex array onto this one, transforming the array using a given model instance.
      Parameters:
      model - the model to copy from
      modelInstance - the model instance to apply
      Returns:
      this
    • render

      public VertexArray render() throws NotOnGraphicsThreadException
      Render the array using the current shader program onto the current target frame buffer.
      Returns:
      this
      Throws:
      NotOnGraphicsThreadException
    • toString

      public String toString()
      Overrides:
      toString in class Object