com.threerings.opengl.renderer
Class Renderer

java.lang.Object
  extended by com.threerings.opengl.renderer.Renderer

public class Renderer
extends Object

Provides access to state associated with the renderer. Any state changes made should be done through this object so that its internal state is synchronized with the OpenGL state.


Nested Class Summary
protected static class Renderer.ClientArrayRecord
          Represents the state of a single client array.
protected static class Renderer.ClipPlaneRecord
          Represents the state of a single clip plane.
protected static class Renderer.LightRecord
          Represents the current state of a single light.
static interface Renderer.Observer
          An interface for objects interested in renderer state changes.
protected static class Renderer.TextureUnitRecord
          Represents the current state of a single texture unit.
 
Field Summary
protected  int _activeUnit
          The active texture unit.
protected  int _alphaBits
          The number of alpha bit planes in the frame buffer.
protected  Boolean _alphaMask
          The current color mask state.
protected  Boolean _alphaTestEnabled
          Whether or not alpha testing is enabled.
protected  int _alphaTestFunc
          The alpha test function.
protected  float _alphaTestRef
          The reference alpha value for testing.
protected  BufferObject _arrayBuffer
          The currently bound array buffer object.
protected  boolean _ati
          Vendor flags for special casery.
protected  Color4f _backAmbient
          The current material's back ambient color.
protected  Color4f _backDiffuse
          The current material's back diffuse color.
protected  Color4f _backEmission
          The current material's back emissive color.
protected  int _backPolygonMode
          The polygon mode for back-facing polygons.
protected  float _backShininess
          The current material's back shininess.
protected  Color4f _backSpecular
          The current material's back specular color.
protected  int _batchCount
          The number of batches rendered in the current frame.
protected  Boolean _blendEnabled
          Whether or not blending is enabled.
protected  Boolean _blueMask
          The current color mask state.
protected  float _bottom
          The projection parameters.
protected  int _bufferObjectBytes
          The total number of bytes in buffer objects.
protected  int _bufferObjectCount
          The number of active buffer objects.
protected  Color4f _clearColor
          The clear color.
protected  float _clearDepth
          The clear depth.
protected  int _clearStencil
          The clear stencil.
protected  int _clientActiveUnit
          The active client texture unit.
protected  int _clipPlaneEnd
          One greater than the index of the last clipping plane possibly enabled.
protected  Renderer.ClipPlaneRecord[] _clipPlanes
          The user clip plane records.
protected  Color4f _color
          The current render color.
protected  Renderer.ClientArrayRecord _colorArray
          The state of the color array.
protected  Boolean _colorMaterialEnabled
          Whether or not color material tracking is enabled.
protected  int _colorMaterialFace
          The color material face.
protected  int _colorMaterialMode
          The color material mode.
protected  int _cullFace
          The cull face.
protected  Boolean _cullFaceEnabled
          Whether or not face culling is enabled.
protected  DoubleBuffer _dbuf
          A buffer for double values.
protected  Boolean _depthMask
          Whether or not depth writing is currently enabled.
protected  Boolean _depthTestEnabled
          Whether or not depth testing is enabled.
protected  int _depthTestFunc
          The depth test function.
protected  int _destBlendFactor
          The destination blend factor.
protected  int _displayListCount
          The number of active display lists.
protected  Drawable _drawable
          The drawable with which this renderer is being used.
protected  int _drawBuffer
          The active buffers for drawing and reading.
protected  BufferObject _elementArrayBuffer
          The currently bound element array buffer object.
protected  float _far
          The projection parameters.
protected  int _finalizedBufferObjectBytes
          The total number of bytes in the buffer objects to be deleted.
protected  int[] _finalizedBufferObjects
          The list of buffer objects to be deleted.
protected  int[] _finalizedDisplayLists
          The list of display lists to be deleted.
protected  int[] _finalizedFramebuffers
          The list of frame buffers to be deleted.
protected  Object[] _finalizedPbuffers
          The list of pbuffers to be destroyed.
protected  int[] _finalizedQueries
          The list of queries to be deleted.
protected  int[] _finalizedRenderbuffers
          The list of render buffers to be deleted.
protected  int[] _finalizedShaderObjects
          The list of shader objects to be deleted.
protected  int _finalizedTextureBytes
          The total number of bytes in the textures to be deleted.
protected  int[] _finalizedTextures
          The list of textures to be deleted.
protected  Boolean _flatShading
          Whether or not we are using flat shading.
protected  Color4f _fogColor
          The current fog color.
protected  float _fogDensity
          The current fog density.
protected  Boolean _fogEnabled
          Whether or not fog is enabled.
protected  float _fogEnd
          The current fog end distance.
protected  int _fogMode
          The current fog mode.
protected  float _fogStart
          The current fog start distance.
protected  Framebuffer _framebuffer
          The currently bound frame buffer.
protected  Color4f _frontAmbient
          The current material's front ambient color.
protected  Color4f _frontDiffuse
          The current material's front diffuse color.
protected  Color4f _frontEmission
          The current material's front emissive color.
protected  int _frontFace
          The front face.
protected  int _frontPolygonMode
          The polygon mode for front-facing polygons.
protected  float _frontShininess
          The current material's front shininess.
protected  Color4f _frontSpecular
          The current material's front specular color.
protected  Color4f _globalAmbient
          The current global ambient intensity.
protected  Boolean _greenMask
          The current color mask state.
protected  int _height
          The width and height of the drawable surface.
protected  boolean _intel
          Vendor flags for special casery.
protected  float _left
          The projection parameters.
protected  int _lightEnd
          One greater than the index of the last light possibly enabled.
protected  Boolean _lightingEnabled
          Whether or not lighting is currently enabled.
protected  Renderer.LightRecord[] _lights
          The state of the lights.
protected  float _lineWidth
          The current line width.
protected  Boolean _localViewer
          Whether or not specular colors are calculated using a local viewer model.
protected  Matrix4f _mat
          Temporary matrix.
protected  int _matrixMode
          The current matrix mode.
protected  int _maxClipPlanes
          The maximum number of clip planes supported.
protected  int _maxLights
          The maximum number of lights supported.
protected  int _maxTextureImageUnits
          The maximum number of textures available in the programmable pipeline.
protected  int _maxTextureUnits
          The maximum number of textures available in the fixed function pipeline.
protected  int _maxVertexAttribs
          The maximum number of vertex attributes available to vertex shaders.
protected  Transform3D _modelview
          The current modelview transform.
protected  boolean _modelviewMatrixValid
          Whether or not the modelview matrix is valid.
protected  float _near
          The projection parameters.
protected  Vector3f _nearFarNormal
          The normal of the near/far clip planes.
protected  Renderer.ClientArrayRecord _normalArray
          The state of the normal array.
protected  Boolean _normalize
          Whether or not to normalize normals after transformation.
protected  boolean _nvidia
          Vendor flags for special casery.
protected  WeakObserverList<Renderer.Observer> _observers
          The list of renderer observers.
protected  boolean _ortho
          Whether or not we're using orthographic projection.
protected  float _pointSize
          The point size.
protected  float _polygonOffsetFactor
          The proportional polygon offset.
protected  Boolean _polygonOffsetFillEnabled
          Whether or not offsets are enabled for filled polygons.
protected  Boolean _polygonOffsetLineEnabled
          Whether or not offsets are enabled for line polygons.
protected  Boolean _polygonOffsetPointEnabled
          Whether or not offsets are enabled for point polygons.
protected  float _polygonOffsetUnits
          The constant polygon offset.
protected  int _primitiveCount
          The number of primitives rendered in the current frame.
protected  Program _program
          The currently bound shader program.
protected  int _readBuffer
          The active buffers for drawing and reading.
protected  Boolean _redMask
          The current color mask state.
protected  Renderbuffer _renderbuffer
          The currently bound render buffer.
protected  Boolean _rescaleNormal
          Whether or not to rescale normals according to the modelview matrix scale.
protected  float _right
          The projection parameters.
protected  Query _samplesPassed
          The current query for the samples-passed target, if any.
protected  Rectangle _scissor
          The scissor box.
protected  Boolean _scissorTestEnabled
          Whether or not scissor testing is enabled (where null means "unknown").
protected  Boolean _separateSpecular
          Whether or not specular highlights are applied as a separate pass.
protected  int _shaderObjectCount
          The number of active shader objects.
protected  int _srcBlendFactor
          The source blend factor.
protected  RenderState[] _states
          References to the last states applied.
protected  int _stencilBits
          The number of stencil bit planes in the frame buffer.
protected  int _stencilDepthFailOp
          The current stencil test depth failure op.
protected  int _stencilFailOp
          The current stencil test failure op.
protected  int _stencilPassOp
          The current stencil test pass op.
protected  Boolean _stencilTestEnabled
          Whether or not stencil testing is enabled.
protected  int _stencilTestFunc
          The current stencil test function.
protected  int _stencilTestMask
          The current stencil test mask.
protected  int _stencilTestRef
          The current stencil test reference value.
protected  int _stencilWriteMask
          The current stencil write mask.
protected  int _texCoordArrayEnd
          One greater than the index of the last texture coordinate array possibly enabled.
protected  Renderer.ClientArrayRecord[] _texCoordArrays
          The state of the texture coordinate arrays.
protected  int _textureBytes
          The total number of bytes in textures.
protected  int _textureChangeCount
          The number of texture changes in the current frame.
protected  int _textureCount
          The number of active textures.
protected  float _top
          The projection parameters.
protected  Boolean _twoSide
          Whether or not two-sided lighting is enabled.
protected  int _unitEnd
          One greater than the index of the last texture unit possibly enabled.
protected  Renderer.TextureUnitRecord[] _units
          The state of the texture units.
protected  FloatBuffer _vbuf
          A buffer for floating point values.
protected  Renderer.ClientArrayRecord _vertexArray
          The state of the vertex array.
protected  int _vertexAttribArrayEnd
          One greater than the index of the last vertex attribute array possibly enabled.
protected  Renderer.ClientArrayRecord[] _vertexAttribArrays
          The state of the vertex attribute arrays.
protected  int _vertexAttribArrayStart
          The index of the first vertex attribute array possibly enabled.
protected  Boolean _vertexProgramTwoSide
          Whether or not two-sided vertex program mode is enabled.
protected  Rectangle _viewport
          The active viewport.
protected  int _width
          The width and height of the drawable surface.
protected  boolean _wouldEnableFog
          Whether or not we would enable fog if not for the shader state.
protected static BufferObject INVALID_BUFFER
          An invalid buffer to force reapplication.
protected static Program INVALID_PROGRAM
          An invalid program to force reapplication.
protected static Texture INVALID_TEXTURE
          An invalid texture to force reapplication.
 
Constructor Summary
Renderer()
           
 
Method Summary
 void addObserver(Renderer.Observer observer)
          Adds an observer to the list of objects interested in state changes.
protected  void bufferObjectCreated()
          Notes that a buffer object has been created.
protected  void bufferObjectDeleted(int bytes)
          Notes that a buffer object has been deleted.
protected  void bufferObjectFinalized(int id, int bytes)
          Called when a buffer object has been finalized.
protected  void bufferObjectResized(int delta)
          Notes that a buffer object's size has changed.
 void cleanup()
          Gives the renderer a chance to perform any periodic cleanup necessary.
protected  boolean clearModelviewOrTransposeTransform(boolean cleared, Vector4f vector, FloatBuffer result)
          On Intel cards, this clears the modelview matrix and loads the plane coefficients into the supplied buffer.
protected  void deleteFinalizedObjects()
          Deletes all finalized objects.
protected  void displayListCreated()
          Notes that a display list has been created.
protected  void displayListDeleted()
          Notes that a display list has been deleted.
protected  void displayListFinalized(int id)
          Called when a display list has been finalized.
protected  void framebufferFinalized(int id)
          Called when a frame buffer has been finalized.
 int getAlphaBits()
          Returns the number of alpha bit planes in the frame buffer.
 int getBatchCount()
          Returns the number of batches rendered since the last call to resetStats().
 float getBottom()
          Returns the bottom projection parameter.
 int getBufferObjectBytes()
          Returns the total number of bytes in buffer objects.
 int getBufferObjectCount()
          Returns the number of active buffer objects.
 Color4f getClearColor()
          Returns a reference to the clear color.
 float getClearDepth()
          Returns the clear depth.
 int getClearStencil()
          Returns the clear stencil value.
 int getDisplayListCount()
          Returns the number of active display lists.
 Drawable getDrawable()
          Returns a reference to the drawable target of this renderer.
protected  int getDrawBuffer()
          Returns the active draw buffer.
 float getFar()
          Returns the far projection parameter.
protected  Framebuffer getFramebuffer()
          Returns a reference to the currently bound frame buffer.
 int getFrontFace()
          Returns the current front face.
 int getHeight()
          Returns the height of the renderer's drawable surface.
 float getLeft()
          Returns the left projection parameter.
 int getMaxClipPlanes()
          Returns the maximum number of user clip planes supported.
 int getMaxLights()
          Returns the maximum number of lights supported.
 int getMaxTextureImageUnits()
          Returns the maximum number of texture units usable with the programmable pipeline.
 int getMaxTextureUnits()
          Returns the maximum number of texture units usable with the fixed-function pipeline.
 int getMaxVertexAttribs()
          Returns the maximum number of vertex attributes available to vertex shaders.
protected  Matrix4f getModelviewMatrix()
          Returns a reference to the modelview matrix, ensuring that it is up-to-date.
 float getNear()
          Returns the near projection parameter.
 Vector3f getNearFarNormal()
          Returns a reference to the near/far normal projection parameter.
 int getPrimitiveCount()
          Returns the number of primitives rendered since the last call to resetStats().
protected  int getReadBuffer()
          Returns the active read buffer.
 float getRight()
          Returns the right projection parameter.
 Rectangle getScissor()
          Returns a reference to the scissor box, or null if scissor testing is disabled.
 int getShaderObjectCount()
          Returns the number of active shader objects.
 int getStencilBits()
          Returns the number of stencil bit planes in the frame buffer.
 int getTextureBytes()
          Returns the total number of bytes in textures.
 int getTextureChangeCount()
          Returns the number of texture changes since the last call to resetStats().
 int getTextureCount()
          Returns the number of active textures.
 float getTop()
          Returns the top projection parameter.
 Rectangle getViewport()
          Returns the current viewport state.
 int getWidth()
          Returns the width of the renderer's drawable surface.
 void init(Drawable drawable, int width, int height)
          Initializes the renderer.
 void invalidateAlphaState()
          Invalidates the alpha state, forcing it to be reapplied.
 void invalidateArrayState()
          Invalidates the array state, forcing it to be reapplied.
 void invalidateColorMaskState()
          Invalidates the color mask state, forcing it to be reapplied.
 void invalidateColorState()
          Invalidates the color state, forcing it to be reapplied.
 void invalidateCullState()
          Invalidates the back-face culling state, forcing it to be reapplied.
 void invalidateDepthState()
          Invalidates the depth state, forcing it to be reapplied.
 void invalidateFogState()
          Invalidates the fog state, forcing it to be reapplied.
 void invalidateLightState()
          Invalidates the light state, forcing it to be reapplied.
 void invalidateLineState()
          Invalidates the line state, forcing it to be reapplied.
 void invalidateMaterialState()
          Invalidates the material state, forcing it to be reapplied.
 void invalidatePointState()
          Invalidates the point state, forcing it to be reapplied.
 void invalidatePolygonState()
          Invalidates the polygon state, forcing it to be reapplied.
 void invalidateShaderState()
          Invalidates the shader state, forcing it to be reapplied.
 void invalidateStencilState()
          Invalidates the stencil state, forcing it to be reapplied.
 void invalidateTextureState()
          Invalidates the texture state, forcing it to be reapplied.
 void invalidateTransformState()
          Invalidates the transform state, forcing it to be reapplied.
 boolean isOrtho()
          Returns the ortho projection parameter.
protected  void loadTransformMatrix(Transform3D transform)
          Loads the specified transform into the current matrix slot.
protected  boolean maybeClearModelview(boolean cleared)
          Clears the modelview matrix if it hasn't already been.
protected  void maybeRestoreModelview(boolean cleared)
          Restores the stored modelview matrix if it was previously cleared.
protected  void pbufferFinalized(Pbuffer pbuffer)
          Called when a pbuffer has been finalized.
protected  void queryFinalized(int id)
          Called when a query has been finalized.
 void removeObserver(Renderer.Observer observer)
          Removes an observer from the list.
 void render(List<Batch> batches)
          Renders the provided list of batches.
protected  void renderbufferFinalized(int id)
          Called when a render buffer has been finalized.
 void resetStats()
          Resets the per-frame stats.
protected  void setActiveUnit(int unit)
          Sets the active texture unit.
 void setAlphaState(int alphaTestFunc, float alphaTestRef, int srcBlendFactor, int destBlendFactor)
          Sets the alpha testing and blending state.
protected  void setArrayBuffer(BufferObject arrayBuffer)
          Binds the specified array buffer.
 void setArrayState(int firstVertexAttribIndex, ClientArray[] vertexAttribArrays, ClientArray[] texCoordArrays, ClientArray colorArray, ClientArray normalArray, ClientArray vertexArray, BufferObject elementArrayBuffer)
          Sets the client array state.
protected  void setBuffers(int drawBuffer, int readBuffer)
          Sets the active buffers for drawing and reading.
protected static void setCapability(int capability, boolean enable)
          Enables or disables an OpenGL capability.
 void setClearColor(Color4f color)
          Sets the clear color.
 void setClearDepth(float depth)
          Sets the clear depth.
 void setClearStencil(int stencil)
          Sets the clear stencil value.
protected  void setClientActiveUnit(int unit)
          Sets the active client texture unit.
protected static void setClientCapability(int capability, boolean enable)
          Enables or disables an OpenGL client capability.
 void setClipPlanes(Plane[] planes)
          Sets the user clip planes.
protected  void setColorArray(ClientArray array)
          Sets the color array to the one supplied.
 void setColorMaskState(boolean red, boolean green, boolean blue, boolean alpha)
          Sets the color mask state.
 void setColorState(Color4f color)
          Sets the draw color state.
 void setColorState(float r, float g, float b, float a)
          Sets the draw color state.
 void setCullState(int cullFace)
          Sets the back-face culling state.
 void setDepthState(int depthTestFunc, boolean depthMask)
          Sets the depth buffer testing/writing state.
 void setFogState(int fogMode, float fogDensity, Color4f fogColor)
          Sets the fog state.
 void setFogState(int fogMode, float fogStart, float fogEnd, Color4f fogColor)
          Sets the linear fog state.
protected  void setFramebuffer(Framebuffer framebuffer)
          Binds the specified frame buffer.
 void setFrontFace(int face)
          Sets the front face.
 void setLightState(Light[] lights, Color4f globalAmbient)
          Sets the light state.
 void setLineState(float lineWidth)
          Sets the line state.
 void setMaterialState(Color4f frontAmbient, Color4f frontDiffuse, Color4f frontSpecular, Color4f frontEmission, float frontShininess, Color4f backAmbient, Color4f backDiffuse, Color4f backSpecular, Color4f backEmission, float backShininess, int colorMaterialMode, int colorMaterialFace, boolean twoSide, boolean localViewer, boolean separateSpecular, boolean flatShading)
          Sets the material state.
 void setMatrixMode(int matrixMode)
          Sets the matrix mode.
protected  void setNormalArray(ClientArray array)
          Sets the normal array to the one supplied.
 void setNormalize(boolean normalize, boolean rescaleNormal)
          Sets the normalization parameters.
 void setPointState(float pointSize)
          Sets the point state.
 void setPolygonState(int frontPolygonMode, int backPolygonMode, float polygonOffsetFactor, float polygonOffsetUnits)
          Sets the polygon state.
 void setProjection(float left, float right, float bottom, float top, float near, float far, Vector3f nearFarNormal, boolean ortho)
          Sets the projection matrix.
protected  void setRenderbuffer(Renderbuffer renderbuffer)
          Binds the specified render buffer.
 void setScissor(Rectangle box)
          Sets the scissor box.
 void setShaderState(Program program, boolean vertexProgramTwoSide)
          Sets the GLSL shader state.
 void setSize(int width, int height)
          Notes that the size of the renderer's drawable surface has changed.
 void setState(RenderState state)
          Sets a single render state.
 void setStates(RenderState[] states)
          Sets an entire group of states at once.
 void setStencilState(int stencilTestFunc, int stencilTestRef, int stencilTestMask, int stencilFailOp, int stencilDepthFailOp, int stencilPassOp, int stencilWriteMask)
          Sets the stencil state.
protected  void setTexCoordArray(ClientArray array)
          Sets the texture coordinate array to the one supplied.
protected  void setTexture(Texture texture)
          Binds the specified texture in the active unit.
 void setTextureState(TextureUnit[] units)
          Sets the texture state.
 void setTransformState(Transform3D modelview)
          Sets the transform state.
protected  void setVertexArray(ClientArray array)
          Sets the vertex array to the one supplied.
protected  void setVertexAttribArray(int idx, ClientArray array)
          Sets one of the vertex attribute arrays to the one supplied.
 void setViewport(int x, int y, int width, int height)
          Sets the viewport state.
 void setViewport(Rectangle viewport)
          Sets the viewport state.
protected  void shaderObjectCreated()
          Notes that a shader object has been created.
protected  void shaderObjectDeleted()
          Notes that a shader object has been deleted.
protected  void shaderObjectFinalized(int id)
          Called when a shader object has been finalized.
 void startQuery(Query query)
          Starts a query.
 void stopQuery(Query query)
          Stops a query.
protected  void textureCreated()
          Notes that a texture has been created.
protected  void textureDeleted(int bytes)
          Notes that a texture has been deleted.
protected  void textureFinalized(int id, int bytes)
          Called when a texture has been finalized.
protected  void textureResized(int delta)
          Notes that a texture's size has changed.
protected  void transposeTransform(Vector4f vector, FloatBuffer result)
          Transforms a vector by the transpose of the modelview matrix and stores it in the supplied buffer.
protected  void updateFogEnabled()
          Updates the fog enabled state, which depends on the fog state and the shader state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_drawable

protected Drawable _drawable
The drawable with which this renderer is being used.


_width

protected int _width
The width and height of the drawable surface.


_height

protected int _height
The width and height of the drawable surface.


_observers

protected WeakObserverList<Renderer.Observer> _observers
The list of renderer observers.


_alphaBits

protected int _alphaBits
The number of alpha bit planes in the frame buffer.


_stencilBits

protected int _stencilBits
The number of stencil bit planes in the frame buffer.


_maxClipPlanes

protected int _maxClipPlanes
The maximum number of clip planes supported.


_maxLights

protected int _maxLights
The maximum number of lights supported.


_maxTextureUnits

protected int _maxTextureUnits
The maximum number of textures available in the fixed function pipeline.


_maxTextureImageUnits

protected int _maxTextureImageUnits
The maximum number of textures available in the programmable pipeline.


_maxVertexAttribs

protected int _maxVertexAttribs
The maximum number of vertex attributes available to vertex shaders.


_nvidia

protected boolean _nvidia
Vendor flags for special casery.


_ati

protected boolean _ati
Vendor flags for special casery.


_intel

protected boolean _intel
Vendor flags for special casery.


_textureChangeCount

protected int _textureChangeCount
The number of texture changes in the current frame.


_batchCount

protected int _batchCount
The number of batches rendered in the current frame.


_primitiveCount

protected int _primitiveCount
The number of primitives rendered in the current frame.


_states

protected RenderState[] _states
References to the last states applied.


_clearColor

protected Color4f _clearColor
The clear color.


_clearDepth

protected float _clearDepth
The clear depth.


_clearStencil

protected int _clearStencil
The clear stencil.


_viewport

protected Rectangle _viewport
The active viewport.


_left

protected float _left
The projection parameters.


_right

protected float _right
The projection parameters.


_bottom

protected float _bottom
The projection parameters.


_top

protected float _top
The projection parameters.


_near

protected float _near
The projection parameters.


_far

protected float _far
The projection parameters.


_nearFarNormal

protected Vector3f _nearFarNormal
The normal of the near/far clip planes.


_ortho

protected boolean _ortho
Whether or not we're using orthographic projection.


_clipPlanes

protected Renderer.ClipPlaneRecord[] _clipPlanes
The user clip plane records.


_clipPlaneEnd

protected int _clipPlaneEnd
One greater than the index of the last clipping plane possibly enabled.


_scissorTestEnabled

protected Boolean _scissorTestEnabled
Whether or not scissor testing is enabled (where null means "unknown").


_scissor

protected Rectangle _scissor
The scissor box.


_samplesPassed

protected Query _samplesPassed
The current query for the samples-passed target, if any.


_alphaTestEnabled

protected Boolean _alphaTestEnabled
Whether or not alpha testing is enabled.


_alphaTestFunc

protected int _alphaTestFunc
The alpha test function.


_alphaTestRef

protected float _alphaTestRef
The reference alpha value for testing.


_blendEnabled

protected Boolean _blendEnabled
Whether or not blending is enabled.


_srcBlendFactor

protected int _srcBlendFactor
The source blend factor.


_destBlendFactor

protected int _destBlendFactor
The destination blend factor.


_arrayBuffer

protected BufferObject _arrayBuffer
The currently bound array buffer object.


_elementArrayBuffer

protected BufferObject _elementArrayBuffer
The currently bound element array buffer object.


_clientActiveUnit

protected int _clientActiveUnit
The active client texture unit.


_vertexAttribArrays

protected Renderer.ClientArrayRecord[] _vertexAttribArrays
The state of the vertex attribute arrays.


_vertexAttribArrayStart

protected int _vertexAttribArrayStart
The index of the first vertex attribute array possibly enabled.


_vertexAttribArrayEnd

protected int _vertexAttribArrayEnd
One greater than the index of the last vertex attribute array possibly enabled.


_texCoordArrays

protected Renderer.ClientArrayRecord[] _texCoordArrays
The state of the texture coordinate arrays.


_texCoordArrayEnd

protected int _texCoordArrayEnd
One greater than the index of the last texture coordinate array possibly enabled.


_colorArray

protected Renderer.ClientArrayRecord _colorArray
The state of the color array.


_normalArray

protected Renderer.ClientArrayRecord _normalArray
The state of the normal array.


_vertexArray

protected Renderer.ClientArrayRecord _vertexArray
The state of the vertex array.


_color

protected Color4f _color
The current render color.


_redMask

protected Boolean _redMask
The current color mask state.


_greenMask

protected Boolean _greenMask
The current color mask state.


_blueMask

protected Boolean _blueMask
The current color mask state.


_alphaMask

protected Boolean _alphaMask
The current color mask state.


_cullFaceEnabled

protected Boolean _cullFaceEnabled
Whether or not face culling is enabled.


_cullFace

protected int _cullFace
The cull face.


_frontFace

protected int _frontFace
The front face.


_normalize

protected Boolean _normalize
Whether or not to normalize normals after transformation.


_rescaleNormal

protected Boolean _rescaleNormal
Whether or not to rescale normals according to the modelview matrix scale.


_depthTestEnabled

protected Boolean _depthTestEnabled
Whether or not depth testing is enabled.


_depthTestFunc

protected int _depthTestFunc
The depth test function.


_depthMask

protected Boolean _depthMask
Whether or not depth writing is currently enabled.


_fogEnabled

protected Boolean _fogEnabled
Whether or not fog is enabled.


_wouldEnableFog

protected boolean _wouldEnableFog
Whether or not we would enable fog if not for the shader state.


_fogMode

protected int _fogMode
The current fog mode.


_fogDensity

protected float _fogDensity
The current fog density.


_fogStart

protected float _fogStart
The current fog start distance.


_fogEnd

protected float _fogEnd
The current fog end distance.


_fogColor

protected Color4f _fogColor
The current fog color.


_lightingEnabled

protected Boolean _lightingEnabled
Whether or not lighting is currently enabled.


_lights

protected Renderer.LightRecord[] _lights
The state of the lights.


_lightEnd

protected int _lightEnd
One greater than the index of the last light possibly enabled.


_lineWidth

protected float _lineWidth
The current line width.


_globalAmbient

protected Color4f _globalAmbient
The current global ambient intensity.


_frontAmbient

protected Color4f _frontAmbient
The current material's front ambient color.


_frontDiffuse

protected Color4f _frontDiffuse
The current material's front diffuse color.


_frontSpecular

protected Color4f _frontSpecular
The current material's front specular color.


_frontEmission

protected Color4f _frontEmission
The current material's front emissive color.


_frontShininess

protected float _frontShininess
The current material's front shininess.


_backAmbient

protected Color4f _backAmbient
The current material's back ambient color.


_backDiffuse

protected Color4f _backDiffuse
The current material's back diffuse color.


_backSpecular

protected Color4f _backSpecular
The current material's back specular color.


_backEmission

protected Color4f _backEmission
The current material's back emissive color.


_backShininess

protected float _backShininess
The current material's back shininess.


_colorMaterialEnabled

protected Boolean _colorMaterialEnabled
Whether or not color material tracking is enabled.


_colorMaterialFace

protected int _colorMaterialFace
The color material face.


_colorMaterialMode

protected int _colorMaterialMode
The color material mode.


_twoSide

protected Boolean _twoSide
Whether or not two-sided lighting is enabled.


_localViewer

protected Boolean _localViewer
Whether or not specular colors are calculated using a local viewer model.


_separateSpecular

protected Boolean _separateSpecular
Whether or not specular highlights are applied as a separate pass.


_flatShading

protected Boolean _flatShading
Whether or not we are using flat shading.


_pointSize

protected float _pointSize
The point size.


_frontPolygonMode

protected int _frontPolygonMode
The polygon mode for front-facing polygons.


_backPolygonMode

protected int _backPolygonMode
The polygon mode for back-facing polygons.


_polygonOffsetFillEnabled

protected Boolean _polygonOffsetFillEnabled
Whether or not offsets are enabled for filled polygons.


_polygonOffsetLineEnabled

protected Boolean _polygonOffsetLineEnabled
Whether or not offsets are enabled for line polygons.


_polygonOffsetPointEnabled

protected Boolean _polygonOffsetPointEnabled
Whether or not offsets are enabled for point polygons.


_polygonOffsetFactor

protected float _polygonOffsetFactor
The proportional polygon offset.


_polygonOffsetUnits

protected float _polygonOffsetUnits
The constant polygon offset.


_program

protected Program _program
The currently bound shader program.


_vertexProgramTwoSide

protected Boolean _vertexProgramTwoSide
Whether or not two-sided vertex program mode is enabled.


_stencilTestEnabled

protected Boolean _stencilTestEnabled
Whether or not stencil testing is enabled.


_stencilTestFunc

protected int _stencilTestFunc
The current stencil test function.


_stencilTestRef

protected int _stencilTestRef
The current stencil test reference value.


_stencilTestMask

protected int _stencilTestMask
The current stencil test mask.


_stencilFailOp

protected int _stencilFailOp
The current stencil test failure op.


_stencilDepthFailOp

protected int _stencilDepthFailOp
The current stencil test depth failure op.


_stencilPassOp

protected int _stencilPassOp
The current stencil test pass op.


_stencilWriteMask

protected int _stencilWriteMask
The current stencil write mask.


_units

protected Renderer.TextureUnitRecord[] _units
The state of the texture units.


_unitEnd

protected int _unitEnd
One greater than the index of the last texture unit possibly enabled.


_activeUnit

protected int _activeUnit
The active texture unit.


_matrixMode

protected int _matrixMode
The current matrix mode.


_modelview

protected Transform3D _modelview
The current modelview transform.


_modelviewMatrixValid

protected boolean _modelviewMatrixValid
Whether or not the modelview matrix is valid.


_framebuffer

protected Framebuffer _framebuffer
The currently bound frame buffer.


_renderbuffer

protected Renderbuffer _renderbuffer
The currently bound render buffer.


_drawBuffer

protected int _drawBuffer
The active buffers for drawing and reading.


_readBuffer

protected int _readBuffer
The active buffers for drawing and reading.


_bufferObjectCount

protected int _bufferObjectCount
The number of active buffer objects.


_bufferObjectBytes

protected int _bufferObjectBytes
The total number of bytes in buffer objects.


_displayListCount

protected int _displayListCount
The number of active display lists.


_shaderObjectCount

protected int _shaderObjectCount
The number of active shader objects.


_textureCount

protected int _textureCount
The number of active textures.


_textureBytes

protected int _textureBytes
The total number of bytes in textures.


_finalizedBufferObjects

protected int[] _finalizedBufferObjects
The list of buffer objects to be deleted.


_finalizedBufferObjectBytes

protected int _finalizedBufferObjectBytes
The total number of bytes in the buffer objects to be deleted.


_finalizedDisplayLists

protected int[] _finalizedDisplayLists
The list of display lists to be deleted.


_finalizedFramebuffers

protected int[] _finalizedFramebuffers
The list of frame buffers to be deleted.


_finalizedPbuffers

protected Object[] _finalizedPbuffers
The list of pbuffers to be destroyed.


_finalizedQueries

protected int[] _finalizedQueries
The list of queries to be deleted.


_finalizedRenderbuffers

protected int[] _finalizedRenderbuffers
The list of render buffers to be deleted.


_finalizedShaderObjects

protected int[] _finalizedShaderObjects
The list of shader objects to be deleted.


_finalizedTextures

protected int[] _finalizedTextures
The list of textures to be deleted.


_finalizedTextureBytes

protected int _finalizedTextureBytes
The total number of bytes in the textures to be deleted.


_mat

protected Matrix4f _mat
Temporary matrix.


_vbuf

protected FloatBuffer _vbuf
A buffer for floating point values.


_dbuf

protected DoubleBuffer _dbuf
A buffer for double values.


INVALID_BUFFER

protected static final BufferObject INVALID_BUFFER
An invalid buffer to force reapplication.


INVALID_PROGRAM

protected static final Program INVALID_PROGRAM
An invalid program to force reapplication.


INVALID_TEXTURE

protected static final Texture INVALID_TEXTURE
An invalid texture to force reapplication.

Constructor Detail

Renderer

public Renderer()
Method Detail

init

public void init(Drawable drawable,
                 int width,
                 int height)
Initializes the renderer.

Parameters:
drawable - the drawable surface with which this renderer will be used.
width - the initial viewport width.
height - the initial viewport height.

getDrawable

public Drawable getDrawable()
Returns a reference to the drawable target of this renderer.


setSize

public void setSize(int width,
                    int height)
Notes that the size of the renderer's drawable surface has changed. This does not change the viewport, scissor region, etc.; it simply records the change and notifies the observers.


getWidth

public int getWidth()
Returns the width of the renderer's drawable surface.


getHeight

public int getHeight()
Returns the height of the renderer's drawable surface.


addObserver

public void addObserver(Renderer.Observer observer)
Adds an observer to the list of objects interested in state changes. Note that only a weak reference to the observer will be retained, and thus this will not prevent the observer from being garbage-collected.


removeObserver

public void removeObserver(Renderer.Observer observer)
Removes an observer from the list.


getAlphaBits

public int getAlphaBits()
Returns the number of alpha bit planes in the frame buffer.


getStencilBits

public int getStencilBits()
Returns the number of stencil bit planes in the frame buffer.


getMaxClipPlanes

public int getMaxClipPlanes()
Returns the maximum number of user clip planes supported.


getMaxLights

public int getMaxLights()
Returns the maximum number of lights supported.


getMaxTextureUnits

public int getMaxTextureUnits()
Returns the maximum number of texture units usable with the fixed-function pipeline.


getMaxTextureImageUnits

public int getMaxTextureImageUnits()
Returns the maximum number of texture units usable with the programmable pipeline.


getMaxVertexAttribs

public int getMaxVertexAttribs()
Returns the maximum number of vertex attributes available to vertex shaders.


getTextureChangeCount

public int getTextureChangeCount()
Returns the number of texture changes since the last call to resetStats().


getBatchCount

public int getBatchCount()
Returns the number of batches rendered since the last call to resetStats().


getPrimitiveCount

public int getPrimitiveCount()
Returns the number of primitives rendered since the last call to resetStats().


resetStats

public void resetStats()
Resets the per-frame stats.


getBufferObjectCount

public int getBufferObjectCount()
Returns the number of active buffer objects.


getBufferObjectBytes

public int getBufferObjectBytes()
Returns the total number of bytes in buffer objects.


getDisplayListCount

public int getDisplayListCount()
Returns the number of active display lists.


getShaderObjectCount

public int getShaderObjectCount()
Returns the number of active shader objects.


getTextureCount

public int getTextureCount()
Returns the number of active textures.


getTextureBytes

public int getTextureBytes()
Returns the total number of bytes in textures.


cleanup

public void cleanup()
Gives the renderer a chance to perform any periodic cleanup necessary.


setClearColor

public void setClearColor(Color4f color)
Sets the clear color.


getClearColor

public Color4f getClearColor()
Returns a reference to the clear color.


setClearDepth

public void setClearDepth(float depth)
Sets the clear depth.


getClearDepth

public float getClearDepth()
Returns the clear depth.


setClearStencil

public void setClearStencil(int stencil)
Sets the clear stencil value.


getClearStencil

public int getClearStencil()
Returns the clear stencil value.


setViewport

public void setViewport(Rectangle viewport)
Sets the viewport state.


setViewport

public void setViewport(int x,
                        int y,
                        int width,
                        int height)
Sets the viewport state.


getViewport

public Rectangle getViewport()
Returns the current viewport state.


setProjection

public void setProjection(float left,
                          float right,
                          float bottom,
                          float top,
                          float near,
                          float far,
                          Vector3f nearFarNormal,
                          boolean ortho)
Sets the projection matrix.


getLeft

public float getLeft()
Returns the left projection parameter.


getRight

public float getRight()
Returns the right projection parameter.


getBottom

public float getBottom()
Returns the bottom projection parameter.


getTop

public float getTop()
Returns the top projection parameter.


getNear

public float getNear()
Returns the near projection parameter.


getFar

public float getFar()
Returns the far projection parameter.


getNearFarNormal

public Vector3f getNearFarNormal()
Returns a reference to the near/far normal projection parameter.


isOrtho

public boolean isOrtho()
Returns the ortho projection parameter.


setClipPlanes

public void setClipPlanes(Plane[] planes)
Sets the user clip planes.

Parameters:
planes - the array of clip planes to set, or null to disable all planes.

setScissor

public void setScissor(Rectangle box)
Sets the scissor box.

Parameters:
box - the scissor box, or null to disable the scissor test.

getScissor

public Rectangle getScissor()
Returns a reference to the scissor box, or null if scissor testing is disabled.


setFrontFace

public void setFrontFace(int face)
Sets the front face.


getFrontFace

public int getFrontFace()
Returns the current front face.


setNormalize

public void setNormalize(boolean normalize,
                         boolean rescaleNormal)
Sets the normalization parameters.


startQuery

public void startQuery(Query query)
Starts a query.


stopQuery

public void stopQuery(Query query)
Stops a query.


setStates

public void setStates(RenderState[] states)
Sets an entire group of states at once.


setState

public void setState(RenderState state)
Sets a single render state.


setAlphaState

public void setAlphaState(int alphaTestFunc,
                          float alphaTestRef,
                          int srcBlendFactor,
                          int destBlendFactor)
Sets the alpha testing and blending state. If alphaTestFunc is GL11.GL_ALWAYS, alpha testing will be disabled. If srcBlendFactor is GL11.GL_ONE and destBlendFactor is GL11.GL_ZERO, blending will be disabled.


invalidateAlphaState

public void invalidateAlphaState()
Invalidates the alpha state, forcing it to be reapplied.


setArrayState

public void setArrayState(int firstVertexAttribIndex,
                          ClientArray[] vertexAttribArrays,
                          ClientArray[] texCoordArrays,
                          ClientArray colorArray,
                          ClientArray normalArray,
                          ClientArray vertexArray,
                          BufferObject elementArrayBuffer)
Sets the client array state.


invalidateArrayState

public void invalidateArrayState()
Invalidates the array state, forcing it to be reapplied.


setColorState

public void setColorState(Color4f color)
Sets the draw color state.


setColorState

public void setColorState(float r,
                          float g,
                          float b,
                          float a)
Sets the draw color state.


invalidateColorState

public void invalidateColorState()
Invalidates the color state, forcing it to be reapplied.


setColorMaskState

public void setColorMaskState(boolean red,
                              boolean green,
                              boolean blue,
                              boolean alpha)
Sets the color mask state.


invalidateColorMaskState

public void invalidateColorMaskState()
Invalidates the color mask state, forcing it to be reapplied.


setCullState

public void setCullState(int cullFace)
Sets the back-face culling state.


invalidateCullState

public void invalidateCullState()
Invalidates the back-face culling state, forcing it to be reapplied.


setDepthState

public void setDepthState(int depthTestFunc,
                          boolean depthMask)
Sets the depth buffer testing/writing state. If depthTestFunc is GL11.GL_ALWAYS and depthMask is false, depth testing will be disabled.


invalidateDepthState

public void invalidateDepthState()
Invalidates the depth state, forcing it to be reapplied.


setFogState

public void setFogState(int fogMode,
                        float fogDensity,
                        Color4f fogColor)
Sets the fog state. If fogMode is -1, fog will be disabled.


setFogState

public void setFogState(int fogMode,
                        float fogStart,
                        float fogEnd,
                        Color4f fogColor)
Sets the linear fog state. If fogMode is -1, fog will be disabled.


invalidateFogState

public void invalidateFogState()
Invalidates the fog state, forcing it to be reapplied.


setLightState

public void setLightState(Light[] lights,
                          Color4f globalAmbient)
Sets the light state. If lights is null, lighting will be disabled.


invalidateLightState

public void invalidateLightState()
Invalidates the light state, forcing it to be reapplied.


setLineState

public void setLineState(float lineWidth)
Sets the line state.


invalidateLineState

public void invalidateLineState()
Invalidates the line state, forcing it to be reapplied.


setMaterialState

public void setMaterialState(Color4f frontAmbient,
                             Color4f frontDiffuse,
                             Color4f frontSpecular,
                             Color4f frontEmission,
                             float frontShininess,
                             Color4f backAmbient,
                             Color4f backDiffuse,
                             Color4f backSpecular,
                             Color4f backEmission,
                             float backShininess,
                             int colorMaterialMode,
                             int colorMaterialFace,
                             boolean twoSide,
                             boolean localViewer,
                             boolean separateSpecular,
                             boolean flatShading)
Sets the material state.


invalidateMaterialState

public void invalidateMaterialState()
Invalidates the material state, forcing it to be reapplied.


setPointState

public void setPointState(float pointSize)
Sets the point state.


invalidatePointState

public void invalidatePointState()
Invalidates the point state, forcing it to be reapplied.


setPolygonState

public void setPolygonState(int frontPolygonMode,
                            int backPolygonMode,
                            float polygonOffsetFactor,
                            float polygonOffsetUnits)
Sets the polygon state.


invalidatePolygonState

public void invalidatePolygonState()
Invalidates the polygon state, forcing it to be reapplied.


setShaderState

public void setShaderState(Program program,
                           boolean vertexProgramTwoSide)
Sets the GLSL shader state.


invalidateShaderState

public void invalidateShaderState()
Invalidates the shader state, forcing it to be reapplied.


setStencilState

public void setStencilState(int stencilTestFunc,
                            int stencilTestRef,
                            int stencilTestMask,
                            int stencilFailOp,
                            int stencilDepthFailOp,
                            int stencilPassOp,
                            int stencilWriteMask)
Sets the stencil state.


invalidateStencilState

public void invalidateStencilState()
Invalidates the stencil state, forcing it to be reapplied.


setTextureState

public void setTextureState(TextureUnit[] units)
Sets the texture state.


invalidateTextureState

public void invalidateTextureState()
Invalidates the texture state, forcing it to be reapplied.


setTransformState

public void setTransformState(Transform3D modelview)
Sets the transform state.


invalidateTransformState

public void invalidateTransformState()
Invalidates the transform state, forcing it to be reapplied.


setMatrixMode

public void setMatrixMode(int matrixMode)
Sets the matrix mode.


render

public void render(List<Batch> batches)
Renders the provided list of batches.


setVertexAttribArray

protected void setVertexAttribArray(int idx,
                                    ClientArray array)
Sets one of the vertex attribute arrays to the one supplied.


setTexCoordArray

protected void setTexCoordArray(ClientArray array)
Sets the texture coordinate array to the one supplied.


setColorArray

protected void setColorArray(ClientArray array)
Sets the color array to the one supplied.


setNormalArray

protected void setNormalArray(ClientArray array)
Sets the normal array to the one supplied.


setVertexArray

protected void setVertexArray(ClientArray array)
Sets the vertex array to the one supplied.


setArrayBuffer

protected void setArrayBuffer(BufferObject arrayBuffer)
Binds the specified array buffer.


updateFogEnabled

protected void updateFogEnabled()
Updates the fog enabled state, which depends on the fog state and the shader state.


loadTransformMatrix

protected void loadTransformMatrix(Transform3D transform)
Loads the specified transform into the current matrix slot.


clearModelviewOrTransposeTransform

protected boolean clearModelviewOrTransposeTransform(boolean cleared,
                                                     Vector4f vector,
                                                     FloatBuffer result)
On Intel cards, this clears the modelview matrix and loads the plane coefficients into the supplied buffer. On non-Intel cards, it multiplies the coefficients by the transpose of the modelview matrix and stores them in the buffer. It's a workaround for dueling issues with the ATI and Intel drivers.

Returns:
true if we cleared the modelview matrix.

maybeClearModelview

protected boolean maybeClearModelview(boolean cleared)
Clears the modelview matrix if it hasn't already been.

Returns:
the new value for the cleared flag (true).

maybeRestoreModelview

protected void maybeRestoreModelview(boolean cleared)
Restores the stored modelview matrix if it was previously cleared.


transposeTransform

protected void transposeTransform(Vector4f vector,
                                  FloatBuffer result)
Transforms a vector by the transpose of the modelview matrix and stores it in the supplied buffer.


getModelviewMatrix

protected Matrix4f getModelviewMatrix()
Returns a reference to the modelview matrix, ensuring that it is up-to-date.


setClientActiveUnit

protected void setClientActiveUnit(int unit)
Sets the active client texture unit.


setActiveUnit

protected void setActiveUnit(int unit)
Sets the active texture unit.


setTexture

protected void setTexture(Texture texture)
Binds the specified texture in the active unit.


setBuffers

protected void setBuffers(int drawBuffer,
                          int readBuffer)
Sets the active buffers for drawing and reading.


getDrawBuffer

protected int getDrawBuffer()
Returns the active draw buffer.


getReadBuffer

protected int getReadBuffer()
Returns the active read buffer.


setFramebuffer

protected void setFramebuffer(Framebuffer framebuffer)
Binds the specified frame buffer.


getFramebuffer

protected Framebuffer getFramebuffer()
Returns a reference to the currently bound frame buffer.


setRenderbuffer

protected void setRenderbuffer(Renderbuffer renderbuffer)
Binds the specified render buffer.


bufferObjectCreated

protected void bufferObjectCreated()
Notes that a buffer object has been created.


bufferObjectResized

protected void bufferObjectResized(int delta)
Notes that a buffer object's size has changed.

Parameters:
delta - the difference in bytes between the new and old sizes.

bufferObjectDeleted

protected void bufferObjectDeleted(int bytes)
Notes that a buffer object has been deleted.


displayListCreated

protected void displayListCreated()
Notes that a display list has been created.


displayListDeleted

protected void displayListDeleted()
Notes that a display list has been deleted.


shaderObjectCreated

protected void shaderObjectCreated()
Notes that a shader object has been created.


shaderObjectDeleted

protected void shaderObjectDeleted()
Notes that a shader object has been deleted.


textureCreated

protected void textureCreated()
Notes that a texture has been created.


textureResized

protected void textureResized(int delta)
Notes that a texture's size has changed.

Parameters:
delta - the difference in bytes between the new and old sizes.

textureDeleted

protected void textureDeleted(int bytes)
Notes that a texture has been deleted.


bufferObjectFinalized

protected void bufferObjectFinalized(int id,
                                     int bytes)
Called when a buffer object has been finalized.


displayListFinalized

protected void displayListFinalized(int id)
Called when a display list has been finalized.


framebufferFinalized

protected void framebufferFinalized(int id)
Called when a frame buffer has been finalized.


pbufferFinalized

protected void pbufferFinalized(Pbuffer pbuffer)
Called when a pbuffer has been finalized.


queryFinalized

protected void queryFinalized(int id)
Called when a query has been finalized.


renderbufferFinalized

protected void renderbufferFinalized(int id)
Called when a render buffer has been finalized.


shaderObjectFinalized

protected void shaderObjectFinalized(int id)
Called when a shader object has been finalized.


textureFinalized

protected void textureFinalized(int id,
                                int bytes)
Called when a texture has been finalized.


deleteFinalizedObjects

protected void deleteFinalizedObjects()
Deletes all finalized objects.


setCapability

protected static void setCapability(int capability,
                                    boolean enable)
Enables or disables an OpenGL capability.


setClientCapability

protected static void setClientCapability(int capability,
                                          boolean enable)
Enables or disables an OpenGL client capability.