Class OGLGraphics

java.lang.Object
com.blackrook.gloop.opengl.OGLGraphics
All Implemented Interfaces:
OGLVersioned
Direct Known Subclasses:
OGL11Graphics

public abstract class OGLGraphics extends Object implements OGLVersioned
A common encapsulator for all OpenGL implementations.

NOTE: No functions outside of the rendering thread (the thread that is triggered by OGLSystem.display()) should call any function in this.

Author:
Matthew Tropiano
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Describes how to handle a particular situation in the graphics runtime.
    class 
    Information about this context implementation.
    static interface 
    An options class for changing runtime behavior for a created system.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    OGLGraphics(OGLGraphics.Options options, boolean core)
    Initializes this graphics.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Tests for an OpenGL error via glGetError(), but only if error checking is enabled.
    void
    Clears the error bits for the GL Error flags.
    protected abstract OGLGraphics.Info
    Called once in order to fetch context info.
    boolean
    Current blitting bit.
    long
     
    long
     
    double
     
    long
     
    float
    Gets the amount of milliseconds passed between this frame and the last one.
    float
    Gets the fractional amount of nanoseconds passed between this frame and the last one.
    protected void
    Destroys an object, presumably created by this graphics object.
    protected abstract void
    Called on frame end - mostly does cleanup of objects that were abandoned in OpenGL.
    boolean
    fromGLBool(int glBoolean)
    Converts a GL boolean value to a Java boolean value.
    float
     
    int
     
    int
     
    float
    getFloat(int glEnum)
    Grabs an OpenGL context float value using a GL value enum.
    void
    getFloats(int glEnum, float[] out)
    Grabs a series of OpenGL context float values using a GL value enum.
    static String
    getGLErrorName(int glEnum)
    Gets the error name of a GL error enumeration value.
    Gets an info object that returns a lot of OpenGL limits and such for this context implementation.
    int
    getInt(int glEnum)
    Grabs an OpenGL context integer value using a GL value enum.
    void
    getInts(int glEnum, int[] out)
    Grabs a series of OpenGL context integer values using a GL value enum.
    protected <O extends OGLObject>
    void
    handleUndeletedObjects(Class<O> type, int amount)
    Handles the result of undeleted objects.
    boolean
     
    void
    setClientFlag(int glEnum, boolean flag)
    Enables/disables an OpenGL client state bit.
    void
    setFlag(int glEnum, boolean flag)
    Enables/disables an OpenGL state bit.
    boolean
    Checks the version of this graphics implementation against a versioned object, and if the object is from a later version, return false.
    int
    toGLBool(boolean val)
    Converts a Java boolean to an OpenGL GL_TRUE or GL_FALSE value.
    void
    Checks the version of this graphics implementation against a versioned object, and if the object is from a later version, throw an exception.
    void
    Checks if the version of this graphics implementation is non-core, and if it is, it throws an exception.

    Methods inherited from class Object

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

    Methods inherited from interface OGLVersioned

    getVersion
  • Constructor Details

    • OGLGraphics

      protected OGLGraphics(OGLGraphics.Options options, boolean core)
      Initializes this graphics.
      Parameters:
      options - system options.
      core - true if this is a core implementation, false if not.
  • Method Details

    • createInfo

      protected abstract OGLGraphics.Info createInfo()
      Called once in order to fetch context info.
      Returns:
      the info object.
    • getInfo

      public OGLGraphics.Info getInfo()
      Gets an info object that returns a lot of OpenGL limits and such for this context implementation.

      After this is called once in the OpenGL thread, this can be fetched by any thread.

      Returns:
      the graphics context info.
    • endFrame

      protected abstract void endFrame()
      Called on frame end - mostly does cleanup of objects that were abandoned in OpenGL.
    • supports

      public boolean supports(OGLVersioned versioned)
      Checks the version of this graphics implementation against a versioned object, and if the object is from a later version, return false.
      Parameters:
      versioned - the versioned element to check against.
      Returns:
      true if the object is supported by this graphics implementation's version, or false if if the versioned object is a later version than this one, or is not core if this graphics instance is.
    • verifyFeatureSupport

      public void verifyFeatureSupport(OGLVersioned versioned)
      Checks the version of this graphics implementation against a versioned object, and if the object is from a later version, throw an exception. This will also throw an exception if this version is core and the provided object is not.
      Parameters:
      versioned - the versioned element to check against.
      Throws:
      UnsupportedOperationException - if the versioned object is a later version than this one, or is not core if this graphics instance is, and Options#handleVersionChecking() returns OGLGraphics.ErrorHandlingType.EXCEPTION.
    • verifyNonCore

      public void verifyNonCore()
      Checks if the version of this graphics implementation is non-core, and if it is, it throws an exception.
      Throws:
      UnsupportedOperationException - if this graphics instance is a core implementation and Options#handleVersionChecking() returns OGLGraphics.ErrorHandlingType.EXCEPTION.
    • isCore

      public boolean isCore()
      Specified by:
      isCore in interface OGLVersioned
      Returns:
      true if this object is considered part of core spec, false otherwise.
    • getCanvasWidth

      public int getCanvasWidth()
      Returns:
      the framebuffer width in pixels.
    • getCanvasHeight

      public int getCanvasHeight()
      Returns:
      the framebuffer height in pixels.
    • getCanvasAspect

      public float getCanvasAspect()
      Returns:
      the aspect ratio of the framebuffer, width to height.
    • currentTimeMillis

      public long currentTimeMillis()
      Returns:
      the system milliseconds time, synced to the beginning of the current frame.
    • currentTime

      public double currentTime()
      Returns:
      the seconds time from graphics creation, synced to the beginning of the current frame.
    • currentNanos

      public long currentNanos()
      Returns:
      the system nanosecond time, synced to the beginning of the current frame.
    • currentTimeStepMillis

      public float currentTimeStepMillis()
      Gets the amount of milliseconds passed between this frame and the last one. If this is the first frame, this is 0. If this is BEFORE the first frame, this is -1f.
      Returns:
      the time step in milliseconds.
    • currentTimeStepNanos

      public float currentTimeStepNanos()
      Gets the fractional amount of nanoseconds passed between this frame and the last one. If this is the first frame, this is 0. If this is BEFORE the first frame, this is -1f.
      Returns:
      the fractional time step in nanoseconds.
    • currentBlit

      public boolean currentBlit()
      Current blitting bit. This will alternate between true and false each frame.
      Returns:
      the current bit value.
    • currentFrame

      public long currentFrame()
      Returns:
      current frame rendered (number).
    • getInt

      public int getInt(int glEnum)
      Grabs an OpenGL context integer value using a GL value enum.
      Parameters:
      glEnum - the GL enum.
      Returns:
      the value.
    • getInts

      public void getInts(int glEnum, int[] out)
      Grabs a series of OpenGL context integer values using a GL value enum.
      Parameters:
      glEnum - the GL enum.
      out - the output array.
    • getFloat

      public float getFloat(int glEnum)
      Grabs an OpenGL context float value using a GL value enum.
      Parameters:
      glEnum - the GL enum.
      Returns:
      the value.
    • getFloats

      public void getFloats(int glEnum, float[] out)
      Grabs a series of OpenGL context float values using a GL value enum.
      Parameters:
      glEnum - the GL enum.
      out - the output array.
    • setFlag

      public void setFlag(int glEnum, boolean flag)
      Enables/disables an OpenGL state bit.
      Parameters:
      glEnum - the OpenGL enumerant.
      flag - if true, enable. if false, disable.
    • setClientFlag

      public void setClientFlag(int glEnum, boolean flag)
      Enables/disables an OpenGL client state bit.
      Parameters:
      glEnum - the OpenGL enumerant.
      flag - if true, enable. if false, disable.
    • toGLBool

      public int toGLBool(boolean val)
      Converts a Java boolean to an OpenGL GL_TRUE or GL_FALSE value.
      Parameters:
      val - the boolean value.
      Returns:
      the GL boolean equivalent.
    • fromGLBool

      public boolean fromGLBool(int glBoolean)
      Converts a GL boolean value to a Java boolean value.
      Parameters:
      glBoolean - the GL boolean value.
      Returns:
      true if GL_TRUE, false otherwise.
    • clearError

      public void clearError()
      Clears the error bits for the GL Error flags.
    • getGLErrorName

      public static String getGLErrorName(int glEnum)
      Gets the error name of a GL error enumeration value.
      Parameters:
      glEnum - the value.
      Returns:
      a string representing the error.
    • checkError

      public void checkError()
      Tests for an OpenGL error via glGetError(), but only if error checking is enabled.
      Throws:
      GraphicsException - if an error is raised and Options#handleErrorChecking() returns OGLGraphics.ErrorHandlingType.EXCEPTION.
      See Also:
    • destroyObject

      protected void destroyObject(OGLObject object)
      Destroys an object, presumably created by this graphics object.
      Parameters:
      object - the object to destroy.
    • handleUndeletedObjects

      protected <O extends OGLObject> void handleUndeletedObjects(Class<O> type, int amount)
      Handles the result of undeleted objects.
      Type Parameters:
      O - the object type.
      Parameters:
      type - the object type.
      amount - the amount of objects deleted.