org.artoolkitx.arx.arxj.rendering

## Class ShaderProgram

- java.lang.Object
- - org.artoolkitx.arx.arxj.rendering.ShaderProgram

- Direct Known Subclasses:
    SimpleShaderProgram

      public abstract class ShaderProgram
      extends java.lang.Object

  Created by Thorsten Bux on 21.01.2016.
  The shader program links together the vertex shader and the fragment shader and compiles them. It also is responsible for binding the attributes. Attributes can be used to pass in values to the shader during runtime.
  It is important to call `setupShaderUsage()` as first method inside your implementation of the `render(float[])` render()} method.
  This abstract class provides the basic implementation for binding shaders see `createProgram(int, int)` you can just call this method and do not need to worry about binding shaders.
  This class also provides stubs of methodes you might want to override when you create your own Shader Program. You can see an example Shader Program in `SimpleShaderProgram`
  Finally it renders the given geometry.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `colorDataSize`
    `protected int` | `colorStrideBytes`
    `protected int` | `positionDataSize`
    `protected int` | `positionStrideBytes`
    `protected int` | `shaderProgramHandle`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ShaderProgram(OpenGLShader vertexShader, OpenGLShader fragmentShader)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `bindAttributes()`
    `abstract int` | `getModelViewMatrixHandle()`
    `abstract int` | `getProjectionMatrixHandle()`
    `int` | `getShaderProgramHandle()`
    `void` | `render(float[] position)` Only render a simple position.
    `void` | `render(java.nio.FloatBuffer vertexBuffer, java.nio.ByteBuffer indexBuffer)`
    `void` | `render(java.nio.FloatBuffer vertexBuffer, java.nio.FloatBuffer colorBuffer, java.nio.ByteBuffer indexBuffer)` Full loaded render function.
    `void` | `setModelViewMatrix(float[] modelViewMatrix)`
    `void` | `setProjectionMatrix(float[] projectionMatrix)`
    `protected void` | `setupShaderUsage()` Sets some basic settings for shader usage.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### positionDataSize

          protected final int positionDataSize

      See Also:
        Constant Field Values

    - #### colorDataSize

          protected final int colorDataSize

      See Also:
        Constant Field Values

    - #### positionStrideBytes

          protected final int positionStrideBytes

      See Also:
        Constant Field Values

    - #### colorStrideBytes

          protected final int colorStrideBytes

      See Also:
        Constant Field Values

    - #### shaderProgramHandle

          protected final int shaderProgramHandle

  - ### Constructor Detail

    - #### ShaderProgram

          public ShaderProgram(OpenGLShader vertexShader,
                               OpenGLShader fragmentShader)

  - ### Method Detail

    - #### getProjectionMatrixHandle

          public abstract int getProjectionMatrixHandle()

    - #### getModelViewMatrixHandle

          public abstract int getModelViewMatrixHandle()

    - #### bindAttributes

          protected abstract void bindAttributes()

    - #### getShaderProgramHandle

          public int getShaderProgramHandle()

    - #### render

          public void render(java.nio.FloatBuffer vertexBuffer,
                             java.nio.FloatBuffer colorBuffer,
                             java.nio.ByteBuffer indexBuffer)

      Full loaded render function. You should at least override this one. You need to set the projection and/or modelview matrix befor calling a render method.
      Parameters:
        `vertexBuffer` - position vertex information
        `colorBuffer` - color information
        `indexBuffer` - index

    - #### render

          public void render(java.nio.FloatBuffer vertexBuffer,
                             java.nio.ByteBuffer indexBuffer)

    - #### render

          public void render(float[] position)

      Only render a simple position. In this case the implementation if forwarded to the `render(FloatBuffer, FloatBuffer, ByteBuffer)` but you can override this one directly as shown in `SimpleShaderProgram`
      Parameters:
        `position` - The position to be rendered

    - #### setProjectionMatrix

          public void setProjectionMatrix(float[] projectionMatrix)

    - #### setModelViewMatrix

          public void setModelViewMatrix(float[] modelViewMatrix)

    - #### setupShaderUsage

          protected void setupShaderUsage()

      Sets some basic settings for shader usage. Needs to be called as first method from your implementation inside the `renderer()` method.