Class OGL20Graphics

All Implemented Interfaces:
OGLVersioned
Direct Known Subclasses:
OGL21Graphics

public class OGL20Graphics extends OGL15Graphics
OpenGL 2.0 Graphics Implementation.
Author:
Matthew Tropiano
  • Constructor Details

  • Method Details

    • getVersion

      public OGLVersion getVersion()
      Specified by:
      getVersion in interface OGLVersioned
      Overrides:
      getVersion in class OGL15Graphics
      Returns:
      the version that this object or value is available for (and higher).
    • createInfo

      protected OGLGraphics.Info createInfo()
      Description copied from class: OGLGraphics
      Called once in order to fetch context info.
      Overrides:
      createInfo in class OGL13Graphics
      Returns:
      the info object.
    • endFrame

      protected void endFrame()
      Description copied from class: OGLGraphics
      Called on frame end - mostly does cleanup of objects that were abandoned in OpenGL.
      Overrides:
      endFrame in class OGL15Graphics
    • setPointSpritesEnabled

      public void setPointSpritesEnabled(boolean enabled)
      Enables/Disables point sprite conversion. Internally, OpenGL will convert point geometry into billboarded quads or actual polygonal information.
      Parameters:
      enabled - true to enable, false to disable.
    • setPointSpriteTexCoordGeneration

      public void setPointSpriteTexCoordGeneration(boolean enabled)
      Sets if texture coordinates are to be generated across point geometry dimensions. Useful for Point Sprites, obviously.
      Parameters:
      enabled - true to enable, false to disable.
    • setFrameBufferWrite

      public void setFrameBufferWrite(FrameBufferType... types)
      Sets the multiple buffers to write to for pixel drawing/rasterizing operations. By default, this is just the BACK buffer in double-buffered contexts.
      Parameters:
      types - the buffers to write to from now on, made available to shader programs.
      Throws:
      GraphicsException - if one of the types is NONE, LEFT, RIGHT, FRONT, BACK, or FRONT_AND_BACK.
    • createProgramBuilder

      public ProgramBuilder createProgramBuilder()
      Creates a new program builder.

      This program builder aids in building shader program objects, and its ProgramBuilder.create() method will compile and link all of the shaders and return the new object.

      Limitations on this implementation version are: No fragment data binding.

      Returns:
      a new program builder.
    • createProgramShader

      public OGLProgramShader createProgramShader(ShaderType type, String streamName, String sourceCode)
      Creates a new shader object (vertex, fragment, etc.).
      Parameters:
      type - the shader type. if not a valid shader type, this throws an exception.
      streamName - the name of the originating stream (can appear in exceptions).
      sourceCode - the code to compile.
      Returns:
      the instantiated shader.
      Throws:
      UnsupportedOperationException - if the provided shader type is unavailable in this version.
      NullPointerException - if either string is null.
    • createProgramShader

      public OGLProgramShader createProgramShader(ShaderType type, String streamName, Supplier<String> sourceSupplier)
      Creates a new shader object (vertex, fragment, etc.).
      Parameters:
      type - the shader type. if not a valid shader type, this throws an exception.
      streamName - the name of the originating stream (can appear in exceptions).
      sourceSupplier - the supplier function for the source code.
      Returns:
      the instantiated shader.
      Throws:
      UnsupportedOperationException - if the provided shader type is unavailable in this version.
      NullPointerException - if either string is null.
    • destroyProgramShader

      public void destroyProgramShader(OGLProgramShader shader)
      Destroys a program shader.
      Parameters:
      shader - the shader to destroy.
    • createProgram

      public OGLProgram createProgram()
      Creates a new program object.
      Returns:
      a new program object.
      Throws:
      GraphicsException - if the object could not be created.
    • destroyProgram

      public void destroyProgram(OGLProgram program)
      Destroys a program.
      Parameters:
      program - the program to destroy.
    • attachProgramShaders

      public void attachProgramShaders(OGLProgram program, OGLProgramShader... shaders)
      Attaches a shader to a program. Throws an error if this program was already linked, or if a program of the same type was already attached.
      Parameters:
      program - the program to attach the shaders to.
      shaders - the shaders to attach.
      Throws:
      GraphicsException - if this program was already linked, or if a shader of the same type was already attached.
    • detachProgramShaders

      public void detachProgramShaders(OGLProgram program, OGLProgramShader... shaders)
      Detaches a shader from a program. Throws an error if a program of the same type was already detached.
      Parameters:
      program - the program to detach shaders from.
      shaders - the shaders to detach.
    • refreshProgramLinkStatusAndUniforms

      protected void refreshProgramLinkStatusAndUniforms(OGLProgram program)
      Refreshes an OGLProgram's link status, uniforms, and attributes. Should be called when a program is updated via binary upload.
      Parameters:
      program - the program to update.
    • setProgramVertexAttribLocation

      public void setProgramVertexAttribLocation(OGLProgram program, String attribName, int index)
      Binds a specific index to a vertex attribute by name. Must be done before program link.
      Parameters:
      program - the program.
      attribName - the vertex attribute name in the shader.
      index - the desired index.
      Throws:
      GraphicsException - if the program shader has been linked already.
    • linkProgram

      public void linkProgram(OGLProgram program)
      Links the program with its attached program shaders.
      Parameters:
      program - the program to link.
      Throws:
      GraphicsException - if an error occurred during link.
    • getProgram

      public OGLProgram getProgram()
      Gets the currently bound program.
      Returns:
      the program, or null if no bound program.
    • setProgram

      public void setProgram(OGLProgram program)
      Binds a program to the current context.
      Parameters:
      program - the program to bind.
    • setProgramUniformInt

      public void setProgramUniformInt(int locationId, int value)
      Sets a uniform integer value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value - the value to set.
    • setProgramUniformIntArray

      public void setProgramUniformIntArray(int locationId, int... values)
      Sets a uniform integer value array on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      values - the values to set.
    • setProgramUniformFloat

      public void setProgramUniformFloat(int locationId, float value)
      Sets a uniform float value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value - the value to set.
    • setProgramUniformFloatArray

      public void setProgramUniformFloatArray(int locationId, float... values)
      Sets a uniform float array value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      values - the values to set.
    • setProgramUniformVec2

      public void setProgramUniformVec2(int locationId, float value0, float value1)
      Sets a uniform vec2 value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value0 - the first value to set.
      value1 - the second value to set.
    • setProgramUniformVec3

      public void setProgramUniformVec3(int locationId, float value0, float value1, float value2)
      Sets a uniform vec3 value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value0 - the first value to set.
      value1 - the second value to set.
      value2 - the third value to set.
    • setProgramUniformVec4

      public void setProgramUniformVec4(int locationId, float value0, float value1, float value2, float value3)
      Sets a uniform vec4 value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value0 - the first value to set.
      value1 - the second value to set.
      value2 - the third value to set.
      value3 - the fourth value to set.
    • setProgramUniformIVec2

      public void setProgramUniformIVec2(int locationId, int value0, int value1)
      Sets a uniform integer vec2 value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value0 - the first value to set.
      value1 - the second value to set.
    • setProgramUniformIVec3

      public void setProgramUniformIVec3(int locationId, int value0, int value1, int value2)
      Sets a uniform integer vec3 value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value0 - the first value to set.
      value1 - the second value to set.
      value2 - the third value to set.
    • setProgramUniformIVec4

      public void setProgramUniformIVec4(int locationId, int value0, int value1, int value2, int value3)
      Sets a uniform integer vec4 value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      value0 - the first value to set.
      value1 - the second value to set.
      value2 - the third value to set.
      value3 - the fourth value to set.
    • setProgramUniformMatrix2

      public void setProgramUniformMatrix2(int locationId, float[] matrix)
      Sets a uniform matrix (mat2) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the column-major array of values.
      Throws:
      ArrayIndexOutOfBoundsException - if matrix is not 4 elements or greater and a value is fetched out-of-bounds.
    • setProgramUniformMatrix2

      public void setProgramUniformMatrix2(int locationId, float[][] matrix)
      Sets a uniform matrix (mat2) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the multidimensional array of values, each array as one row of values.
      Throws:
      ArrayIndexOutOfBoundsException - if matrix is not 2x2 or greater and a value is fetched out-of-bounds.
    • setProgramUniformMatrix3

      public void setProgramUniformMatrix3(int locationId, float[] matrix)
      Sets a uniform matrix (mat3) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the column-major array of values.
      Throws:
      ArrayIndexOutOfBoundsException - if matrix is not 9 elements or greater and a value is fetched out-of-bounds.
    • setProgramUniformMatrix3

      public void setProgramUniformMatrix3(int locationId, float[][] matrix)
      Sets a uniform matrix (mat3) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the multidimensional array of values, each array as one row of values.
      Throws:
      ArrayIndexOutOfBoundsException - if matrix is not 3x3 or greater and a value is fetched out-of-bounds.
    • setProgramUniformMatrix4

      public void setProgramUniformMatrix4(int locationId, float[] matrix)
      Sets a uniform matrix (mat4) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the column-major array of values.
      Throws:
      ArrayIndexOutOfBoundsException - if matrix is not 16 elements or greater and a value is fetched out-of-bounds.
    • setProgramUniformMatrix4

      public void setProgramUniformMatrix4(int locationId, float[][] matrix)
      Sets a uniform matrix (mat4) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the multidimensional array of values, each array as one row of values.
      Throws:
      ArrayIndexOutOfBoundsException - if matrix is not 4x4 or greater and a value is fetched out-of-bounds.
    • setProgramUniformMatrix4

      public void setProgramUniformMatrix4(int locationId, Matrix4F matrix)
      Sets a uniform matrix (mat4) value on the currently-bound program.
      Parameters:
      locationId - the uniform location.
      matrix - the multidimensional array of values, each array as one row of values.
    • setProgramUniformMatrix4

      public void setProgramUniformMatrix4(int locationId, MatrixMode matrixMode)
      Sets a uniform matrix (mat4) value on the currently-bound program using a matrix in the matrix stack.
      Parameters:
      locationId - the uniform location.
      matrixMode - the matrix to grab values from.
      Throws:
      UnsupportedOperationException - if matrix modes are unavailable in this version (core implementation).
    • unsetProgram

      public void unsetProgram()
      Unbinds a program from the current context.
    • setVertexAttribEnabled

      public void setVertexAttribEnabled(int index, boolean enable)
      Enables or disables the processing of bound vertex arrays and/or buffers at a specific attrib index.
      Parameters:
      index - the attribute index or uniform location id.
      enable - true to enable, false to disable.
    • setVertexAttribBufferPointer

      public void setVertexAttribBufferPointer(int index, DataType dataType, boolean normalize, int dimensions, int stride, int offset)
      Sets what positions in the current BufferTargetType.GEOMETRY-bound buffer are used to draw polygonal information: This sets the vertex attribute pointers. The index on this can also be a uniform location for an attrib pointer.
      Parameters:
      index - the attribute index.
      dataType - the data type contained in the buffer that will be read (calculates actual sizes of data).
      normalize - if true, the data is normalized on read ([-1, 1] for signed values, [0, 1] for unsigned). Else, read as-is.
      dimensions - the dimensions of a full set of attribute components (in elements; 3-dimensional vertices = 3).
      stride - the distance (in elements) between each attribute.
      offset - the offset in each stride where each attribute starts (in elements).
      See Also:
    • createFileSourceSupplier

      public static Supplier<String> createFileSourceSupplier(File sourceFile) throws FileNotFoundException, IOException
      Creates a supplier that gets the source from a file. Assumes system encoding.
      Parameters:
      sourceFile - the source file.
      Returns:
      a supplier function for retrieving the source data.
      Throws:
      FileNotFoundException - if the source file was not found.
      IOException - if the file could not be opened.
      SecurityException - if the file could not be opened, due to OS restrictions.
    • createFileSourceSupplier

      public static Supplier<String> createFileSourceSupplier(File sourceFile, Charset encoding) throws FileNotFoundException, IOException
      Creates a supplier that gets the source from a file.
      Parameters:
      sourceFile - the source file.
      encoding - the encoding type of the file.
      Returns:
      a supplier function for retrieving the source data.
      Throws:
      FileNotFoundException - if the source file was not found.
      IOException - if the file could not be opened.
      SecurityException - if the file could not be opened, due to OS restrictions.
    • createStreamSourceSupplier

      public static Supplier<String> createStreamSourceSupplier(InputStream sourceStream)
      Creates a supplier that gets the source from an input stream. Assumes system encoding.
      Parameters:
      sourceStream - the input stream.
      Returns:
      a supplier function for retrieving the source data.
    • createStreamSourceSupplier

      public static Supplier<String> createStreamSourceSupplier(InputStream sourceStream, Charset encoding)
      Creates a supplier that gets the source from an input stream.
      Parameters:
      sourceStream - the input stream.
      encoding - the encoding type of the incoming data.
      Returns:
      a supplier function for retrieving the source data.
    • createReaderSourceSupplier

      public static Supplier<String> createReaderSourceSupplier(Reader reader)
      Creates a supplier that gets the source from a Reader. The reader is closed after the read.
      Parameters:
      reader - the supplied reader.
      Returns:
      a supplier function for retrieving the source data.