Class TileRendererBase
- java.lang.Object
-
- com.jogamp.opengl.util.TileRendererBase
-
- Direct Known Subclasses:
RandomTileRenderer,TileRenderer
public abstract class TileRendererBase extends Object
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d.org/brianp/TR.html . I've java-fied it, but the functionality is the same.Original code Copyright (C) 1997-2005 Brian Paul. Licensed under BSD-compatible terms with permission of the author. See LICENSE.txt for license information.
Enhanced for
GLandGL2ES3, abstracted to suitTileRendererandRandomTileRenderer.PMV Matrix Considerations
The PMV matrix needs to be reshaped in user code after calling
beginTile(GL), SeebeginTile(GL).If
attaching toanGLAutoDrawable, theTileRendererBase.TileRendererListener.reshapeTile(TileRendererBase, int, int, int, int, int, int)method is being called afterbeginTile(GL)for each rendered tile. It's implementation shall reshape the PMV matrix according tobeginTile(GL).GL Profile Requirement
Note that
image buffercan only be used in conjunction w/ aGLinstance ≥GL2ES3passed tobeginTile(GL)andendTile(GL).
This is due to setting up thepack row lengthfor animage width!= tile-width, which usually is the case.
Hence aGLExceptionis thrown in both methods, if using animage bufferand passing aGLinstance <GL2ES3.Further more, reading back of MSAA buffers is only supported since
GL2ES3since it requires to set theread-buffer.- Author:
- ryanm, sgothel
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTileRendererBase.TileRendererListenerListener for tile renderer events, intended to extendGLEventListenerimplementations, enabling tile rendering viaattachAutoDrawable(GLAutoDrawable).
-
Field Summary
Fields Modifier and Type Field Description static intTR_CURRENT_TILE_HEIGHTThe height of the current tile.static intTR_CURRENT_TILE_WIDTHThe width of the current tile.static intTR_CURRENT_TILE_X_POSThe x-pos of the current tile.static intTR_CURRENT_TILE_Y_POSThe y-pos of the current tile.static intTR_IMAGE_HEIGHTThe height of the final image.static intTR_IMAGE_WIDTHThe width of the final image.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidattachAutoDrawable(GLAutoDrawable glad)Attaches the givenGLAutoDrawableto this tile renderer.abstract voidbeginTile(GL gl)Begins rendering a tile.voiddetachAutoDrawable()Detaches the givenGLAutoDrawablefrom this tile renderer.voiddisplay()Rendering one tile, by simply callingGLAutoDrawable.display().abstract voidendTile(GL gl)Must be called after rendering the scene, seebeginTile(GL).abstract booleaneot()Returns true if end of tiling has been reached, otherwise false.GLAutoDrawablegetAttachedDrawable()GLPixelBuffergetImageBuffer()DimensionImmutablegetImageSize()abstract intgetParam(int pname)Gets the parameters of this TileRenderer objectGLPixelBuffergetTileBuffer()abstract booleanisSetup()Returns true if this instance is setup properly, i.e.booleanreqPreSwapBuffers(GLCapabilitiesImmutable chosenCaps)Determines whether the chosenGLCapabilitiesImmutablerequires a pre-swap-buffersbefore accessing the results, i.e.abstract voidreset()Method resets implementation's internal state to start of tiling as required forbeginTile(GL)ifend of tilinghas been reached.voidsetGLEventListener(GLEventListener preTile, GLEventListener postTile)SetGLEventListenerfor pre- and post operations when used w/attachAutoDrawable(GLAutoDrawable)for eachGLEventListenercallback.voidsetImageBuffer(GLPixelBuffer buffer)Sets the buffer in which to store the final imagevoidsetImageSize(int width, int height)Sets the desired size of the final imagevoidsetTileBuffer(GLPixelBuffer buffer)Specify a buffer the tiles to be copied to.StringtoString()StringBuildertoString(StringBuilder sb)
-
-
-
Field Detail
-
TR_IMAGE_WIDTH
public static final int TR_IMAGE_WIDTH
The width of the final image. SeegetParam(int).- See Also:
- Constant Field Values
-
TR_IMAGE_HEIGHT
public static final int TR_IMAGE_HEIGHT
The height of the final image. SeegetParam(int).- See Also:
- Constant Field Values
-
TR_CURRENT_TILE_X_POS
public static final int TR_CURRENT_TILE_X_POS
The x-pos of the current tile. SeegetParam(int).- See Also:
- Constant Field Values
-
TR_CURRENT_TILE_Y_POS
public static final int TR_CURRENT_TILE_Y_POS
The y-pos of the current tile. SeegetParam(int).- See Also:
- Constant Field Values
-
TR_CURRENT_TILE_WIDTH
public static final int TR_CURRENT_TILE_WIDTH
The width of the current tile. SeegetParam(int).- See Also:
- Constant Field Values
-
TR_CURRENT_TILE_HEIGHT
public static final int TR_CURRENT_TILE_HEIGHT
The height of the current tile. SeegetParam(int).- See Also:
- Constant Field Values
-
-
Method Detail
-
toString
public StringBuilder toString(StringBuilder sb)
-
getParam
public abstract int getParam(int pname) throws IllegalArgumentExceptionGets the parameters of this TileRenderer object- Parameters:
pname- The parameter name that is to be retrieved- Returns:
- the value of the parameter
- Throws:
IllegalArgumentException- ifpnameis not handled
-
setTileBuffer
public final void setTileBuffer(GLPixelBuffer buffer)
Specify a buffer the tiles to be copied to. This is not necessary for the creation of the final image, but useful if you want to inspect each tile in turn.- Parameters:
buffer- The buffer itself. Must be large enough to contain a random tile
-
getTileBuffer
public final GLPixelBuffer getTileBuffer()
- See Also:
setTileBuffer(GLPixelBuffer)
-
setImageSize
public void setImageSize(int width, int height)Sets the desired size of the final image- Parameters:
width- The width of the final imageheight- The height of the final image
-
getImageSize
public final DimensionImmutable getImageSize()
- See Also:
setImageSize(int, int)
-
setImageBuffer
public final void setImageBuffer(GLPixelBuffer buffer)
Sets the buffer in which to store the final image- Parameters:
buffer- the buffer itself, must be large enough to hold the final image
-
getImageBuffer
public final GLPixelBuffer getImageBuffer()
- See Also:
setImageBuffer(GLPixelBuffer)
-
isSetup
public abstract boolean isSetup()
Returns true if this instance is setup properly, i.e.setImageSize(int, int).., and ready forbeginTile(GL). Otherwise returns false.
-
eot
public abstract boolean eot()
Returns true if end of tiling has been reached, otherwise false.end of tiling criteria is implementation specific and may never be reached.
User needs to
reset()tiling after reaching end of tiling before callingbeginTile(GL)again.
-
reset
public abstract void reset()
Method resets implementation's internal state to start of tiling as required forbeginTile(GL)ifend of tilinghas been reached.Implementation is a nop where
end of tilingis never reached.
-
beginTile
public abstract void beginTile(GL gl) throws IllegalStateException, GLException
Begins rendering a tile.This method modifies the viewport, see below. User shall reset the viewport when finishing all tile rendering, i.e. after very last call of
endTile(GL)!The PMV Matrix must be reshaped after this call using:
- Current Viewport
current tile's x-poscurrent tile's y-posfinal image widthfinal image height
Use shall render the scene afterwards, concluded with a call to this renderer
endTile(GL).User has to comply with the GL profile requirement.
If
end of tilinghas been reached, user needs toreset()tiling before calling this method.- Parameters:
gl- The gl context- Throws:
IllegalStateException- ifimage-sizeis undefined, animplementation related setuphas not be performed or {@ link #eot()} has been reached. See implementing classes.GLException- ifimage bufferis used butglinstance is <GL2ES3- See Also:
isSetup(),eot(),reset()
-
endTile
public abstract void endTile(GL gl) throws IllegalStateException, GLException
Must be called after rendering the scene, seebeginTile(GL).Please consider
reqPreSwapBuffers(GLCapabilitiesImmutable)to determine whether you need to performswap-buffersbefore or after calling this method!User has to comply with the GL profile requirement.
- Parameters:
gl- the gl context- Throws:
IllegalStateException- if beginTile(gl) has not been calledGLException- ifimage bufferis used butglinstance is <GL2ES3
-
reqPreSwapBuffers
public final boolean reqPreSwapBuffers(GLCapabilitiesImmutable chosenCaps)
Determines whether the chosenGLCapabilitiesImmutablerequires a pre-swap-buffersbefore accessing the results, i.e. beforeendTile(GL).See
GLDrawableUtil.swapBuffersBeforeRead(GLCapabilitiesImmutable).
-
attachAutoDrawable
public final void attachAutoDrawable(GLAutoDrawable glad) throws IllegalStateException
Attaches the givenGLAutoDrawableto this tile renderer.The
GLAutoDrawable's originalGLEventListenerare moved to this tile renderer.GLEventListenersnot implementingTileRendererBase.TileRendererListenerare ignored while tile rendering.The
GLAutoDrawable'sauto-swap modeis cached and set tofalse, sinceswapBuffers()maybe issued beforeendTile(GL), seereqPreSwapBuffers(GLCapabilitiesImmutable).This tile renderer's internal
GLEventListeneris then added to the attachedGLAutoDrawableto handle the tile rendering, replacing the originalGLEventListener.
It'sdisplayimplementations issues:- Optional
pre-glel.display(..) beginTile(GL)- for all original
TileRendererBase.TileRendererListener: - if (
pre-swap) {swapBuffers()} endTile(GL)- if ( !
pre-swap) {swapBuffers()} - Optional
post-glel.display(..)
Consider using
setGLEventListener(GLEventListener, GLEventListener)to add pre- and post hooks to be performed on this rendererGLEventListener.
The pre-hook is able to allocate memory and setup parameters, since it's called beforebeginTile(GL).
The post-hook is able to use the rendering result and can even shutdown tile-rendering, since it's called afterendTile(GL).Call
detachAutoDrawable()to remove the attachedGLAutoDrawablefrom this tile renderer and to restore it's originalGLEventListener.- Parameters:
glad- theGLAutoDrawableto attach.- Throws:
IllegalStateException- if anGLAutoDrawableis already attached- See Also:
getAttachedDrawable(),detachAutoDrawable()
- Optional
-
getAttachedDrawable
public final GLAutoDrawable getAttachedDrawable()
Returns a previouslyattachedGLAutoDrawable,nullif none is attached.If called from
TileRendererBase.TileRendererListener.addTileRendererNotify(TileRendererBase)orTileRendererBase.TileRendererListener.removeTileRendererNotify(TileRendererBase), method returns the just attached or soon to be detachedGLAutoDrawable.
-
detachAutoDrawable
public final void detachAutoDrawable()
Detaches the givenGLAutoDrawablefrom this tile renderer.
-
setGLEventListener
public final void setGLEventListener(GLEventListener preTile, GLEventListener postTile)
SetGLEventListenerfor pre- and post operations when used w/attachAutoDrawable(GLAutoDrawable)for eachGLEventListenercallback.- Parameters:
preTile- the pre operationspostTile- the post operations
-
display
public final void display() throws IllegalStateExceptionRendering one tile, by simply callingGLAutoDrawable.display().- Throws:
IllegalStateException- if noGLAutoDrawableisattachedor imageSize is not set
-
-