Class OGLGraphics
java.lang.Object
com.blackrook.gloop.opengl.OGLGraphics
- All Implemented Interfaces:
OGLVersioned
- Direct Known Subclasses:
OGL11Graphics
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 ClassesModifier and TypeClassDescriptionstatic enumDescribes how to handle a particular situation in the graphics runtime.classInformation about this context implementation.static interfaceAn options class for changing runtime behavior for a created system. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOGLGraphics(OGLGraphics.Options options, boolean core) Initializes this graphics. -
Method Summary
Modifier and TypeMethodDescriptionvoidTests for an OpenGL error via glGetError(), but only if error checking is enabled.voidClears the error bits for the GL Error flags.protected abstract OGLGraphics.InfoCalled once in order to fetch context info.booleanCurrent blitting bit.longlongdoublelongfloatGets the amount of milliseconds passed between this frame and the last one.floatGets the fractional amount of nanoseconds passed between this frame and the last one.protected voiddestroyObject(OGLObject object) Destroys an object, presumably created by this graphics object.protected abstract voidendFrame()Called on frame end - mostly does cleanup of objects that were abandoned in OpenGL.booleanfromGLBool(int glBoolean) Converts a GL boolean value to a Java boolean value.floatintintfloatgetFloat(int glEnum) Grabs an OpenGL context float value using a GL value enum.voidgetFloats(int glEnum, float[] out) Grabs a series of OpenGL context float values using a GL value enum.static StringgetGLErrorName(int glEnum) Gets the error name of a GL error enumeration value.getInfo()Gets an info object that returns a lot of OpenGL limits and such for this context implementation.intgetInt(int glEnum) Grabs an OpenGL context integer value using a GL value enum.voidgetInts(int glEnum, int[] out) Grabs a series of OpenGL context integer values using a GL value enum.protected <O extends OGLObject>
voidhandleUndeletedObjects(Class<O> type, int amount) Handles the result of undeleted objects.booleanisCore()voidsetClientFlag(int glEnum, boolean flag) Enables/disables an OpenGL client state bit.voidsetFlag(int glEnum, boolean flag) Enables/disables an OpenGL state bit.booleansupports(OGLVersioned versioned) Checks the version of this graphics implementation against a versioned object, and if the object is from a later version, return false.inttoGLBool(boolean val) Converts a Java boolean to an OpenGL GL_TRUE or GL_FALSE value.voidverifyFeatureSupport(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.voidChecks 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, waitMethods inherited from interface OGLVersioned
getVersion
-
Constructor Details
-
OGLGraphics
Initializes this graphics.- Parameters:
options- system options.core- true if this is a core implementation, false if not.
-
-
Method Details
-
createInfo
Called once in order to fetch context info.- Returns:
- the info object.
-
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
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
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() returnsOGLGraphics.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() returnsOGLGraphics.ErrorHandlingType.EXCEPTION.
-
isCore
public boolean isCore()- Specified by:
isCorein interfaceOGLVersioned- 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
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() returnsOGLGraphics.ErrorHandlingType.EXCEPTION.- See Also:
-
destroyObject
Destroys an object, presumably created by this graphics object.- Parameters:
object- the object to destroy.
-
handleUndeletedObjects
-