Class InstanceBufferObjectSubData

    • Constructor Detail

      • InstanceBufferObjectSubData

        public InstanceBufferObjectSubData​(boolean isStatic,
                                           int numInstances,
                                           VertexAttribute... instanceAttributes)
        Constructs a new interleaved InstanceBufferObject.
        Parameters:
        isStatic - whether the vertex data is static.
        numInstances - the maximum number of vertices
        instanceAttributes - the VertexAttributes.
      • InstanceBufferObjectSubData

        public InstanceBufferObjectSubData​(boolean isStatic,
                                           int numInstances,
                                           VertexAttributes instanceAttributes)
        Constructs a new interleaved InstanceBufferObject.
        Parameters:
        isStatic - whether the vertex data is static.
        numInstances - the maximum number of vertices
        instanceAttributes - the VertexAttributes.
    • Method Detail

      • getBuffer

        @Deprecated
        public java.nio.FloatBuffer getBuffer()
        Deprecated.
        use getBuffer(boolean) instead
        Description copied from interface: InstanceData
        Returns the underlying FloatBuffer and marks it as dirty, causing the buffer contents to be uploaded on the next call to bind. If you need immediate uploading use InstanceData.setInstanceData(float[], int, int); Any modifications made to the Buffer *after* the call to bind will not automatically be uploaded.
        Specified by:
        getBuffer in interface InstanceData
        Returns:
        the underlying FloatBuffer holding the vertex data.
      • getBuffer

        public java.nio.FloatBuffer getBuffer​(boolean forWriting)
        Description copied from interface: InstanceData
        Returns the underlying FloatBuffer for reading or writing.
        Specified by:
        getBuffer in interface InstanceData
        Parameters:
        forWriting - when true, the underlying buffer will be uploaded on the next call to bind. If you need immediate uploading use InstanceData.setInstanceData(float[], int, int).
        Returns:
        the underlying FloatBuffer holding the vertex data.
      • setInstanceData

        public void setInstanceData​(float[] data,
                                    int offset,
                                    int count)
        Description copied from interface: InstanceData
        Sets the vertices of this InstanceData, discarding the old vertex data. The count must equal the number of floats per vertex times the number of vertices to be copied to this VertexData. The order of the vertex attributes must be the same as specified at construction time via VertexAttributes.

        This can be called in between calls to bind and unbind. The vertex data will be updated instantly.

        Specified by:
        setInstanceData in interface InstanceData
        Parameters:
        data - the instance data
        offset - the offset to start copying the data from
        count - the number of floats to copy
      • setInstanceData

        public void setInstanceData​(java.nio.FloatBuffer data,
                                    int count)
        Description copied from interface: InstanceData
        Sets the vertices of this InstanceData, discarding the old vertex data. The count must equal the number of floats per vertex times the number of vertices to be copied to this InstanceData. The order of the vertex attributes must be the same as specified at construction time via VertexAttributes.

        This can be called in between calls to bind and unbind. The vertex data will be updated instantly.

        Specified by:
        setInstanceData in interface InstanceData
        Parameters:
        data - the instance data
        count - the number of floats to copy
      • updateInstanceData

        public void updateInstanceData​(int targetOffset,
                                       float[] data,
                                       int sourceOffset,
                                       int count)
        Description copied from interface: InstanceData
        Update (a portion of) the vertices. Does not resize the backing buffer.
        Specified by:
        updateInstanceData in interface InstanceData
        data - the instance data
        sourceOffset - the offset to start copying the data from
        count - the number of floats to copy
      • updateInstanceData

        public void updateInstanceData​(int targetOffset,
                                       java.nio.FloatBuffer data,
                                       int sourceOffset,
                                       int count)
        Description copied from interface: InstanceData
        Update (a portion of) the vertices. Does not resize the backing buffer.
        Specified by:
        updateInstanceData in interface InstanceData
        data - the vertex data
        sourceOffset - the offset to start copying the data from
        count - the number of floats to copy
      • bind

        public void bind​(ShaderProgram shader)
        Binds this InstanceBufferObject for rendering via glDrawArraysInstanced or glDrawElementsInstanced
        Specified by:
        bind in interface InstanceData
        Parameters:
        shader - the shader
      • bind

        public void bind​(ShaderProgram shader,
                         int[] locations)
        Description copied from interface: InstanceData
        Binds this InstanceData for rendering via glDrawArraysInstanced or glDrawElementsInstanced.
        Specified by:
        bind in interface InstanceData
        locations - array containing the attribute locations.
      • unbind

        public void unbind​(ShaderProgram shader)
        Unbinds this InstanceBufferObject.
        Specified by:
        unbind in interface InstanceData
        Parameters:
        shader - the shader
      • unbind

        public void unbind​(ShaderProgram shader,
                           int[] locations)
        Description copied from interface: InstanceData
        Unbinds this InstanceData.
        Specified by:
        unbind in interface InstanceData
        locations - array containing the attribute locations.
      • invalidate

        public void invalidate()
        Invalidates the InstanceBufferObject so a new OpenGL buffer handle is created. Use this in case of a context loss.
        Specified by:
        invalidate in interface InstanceData
      • dispose

        public void dispose()
        Disposes of all resources this InstanceBufferObject uses.
        Specified by:
        dispose in interface Disposable
        Specified by:
        dispose in interface InstanceData
      • getBufferHandle

        public int getBufferHandle()
        Returns the InstanceBufferObject handle
        Returns:
        the InstanceBufferObject handle