Class TileRendererBase
- Direct Known Subclasses:
RandomTileRenderer,TileRenderer
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 GL and GL2ES3, abstracted to suit TileRenderer and RandomTileRenderer.
PMV Matrix Considerations
The PMV matrix needs to be reshaped in user code
after calling beginTile(GL), See beginTile(GL).
If attaching to an GLAutoDrawable,
the TileRendererBase.TileRendererListener.reshapeTile(TileRendererBase, int, int, int, int, int, int) method
is being called after beginTile(GL) for each rendered tile.
It's implementation shall reshape the PMV matrix according to beginTile(GL).
GL Profile Requirement
Note that image buffer can only be used
in conjunction w/ a GL instance ≥ GL2ES3 passed to beginTile(GL) and endTile(GL).
This is due to setting up the pack row length
for an image width != tile-width, which usually is the case.
Hence a GLException is thrown in both methods,
if using an image buffer
and passing a GL instance < GL2ES3.
Further more, reading back of MSAA buffers is only supported since GL2ES3
since it requires to set the read-buffer.
- Author:
- ryanm, sgothel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener for tile renderer events, intended to extendGLEventListenerimplementations, enabling tile rendering viaattachAutoDrawable(GLAutoDrawable). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe height of the current tile.static final intThe width of the current tile.static final intThe x-pos of the current tile.static final intThe y-pos of the current tile.static final intThe height of the final image.static final intThe width of the final image. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidAttaches the givenGLAutoDrawableto this tile renderer.abstract voidBegins rendering a tile.final voidDetaches the givenGLAutoDrawablefrom this tile renderer.final voiddisplay()Rendering one tile, by simply callingGLAutoDrawable.display().abstract voidMust be called after rendering the scene, seebeginTile(GL).abstract booleaneot()Returns true if end of tiling has been reached, otherwise false.final GLAutoDrawablefinal GLPixelBufferfinal DimensionImmutableabstract intgetParam(int pname) Gets the parameters of this TileRenderer objectfinal GLPixelBufferabstract booleanisSetup()Returns true if this instance is setup properly, i.e.final 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.final voidsetGLEventListener(GLEventListener preTile, GLEventListener postTile) SetGLEventListenerfor pre- and post operations when used w/attachAutoDrawable(GLAutoDrawable)for eachGLEventListenercallback.final voidsetImageBuffer(GLPixelBuffer buffer) Sets the buffer in which to store the final imagevoidsetImageSize(int width, int height) Sets the desired size of the final imagefinal voidsetTileBuffer(GLPixelBuffer buffer) Specify a buffer the tiles to be copied to.toString()
-
Field Details
-
TR_IMAGE_WIDTH
public static final int TR_IMAGE_WIDTHThe width of the final image. SeegetParam(int).- See Also:
-
TR_IMAGE_HEIGHT
public static final int TR_IMAGE_HEIGHTThe height of the final image. SeegetParam(int).- See Also:
-
TR_CURRENT_TILE_X_POS
public static final int TR_CURRENT_TILE_X_POSThe x-pos of the current tile. SeegetParam(int).- See Also:
-
TR_CURRENT_TILE_Y_POS
public static final int TR_CURRENT_TILE_Y_POSThe y-pos of the current tile. SeegetParam(int).- See Also:
-
TR_CURRENT_TILE_WIDTH
public static final int TR_CURRENT_TILE_WIDTHThe width of the current tile. SeegetParam(int).- See Also:
-
TR_CURRENT_TILE_HEIGHT
public static final int TR_CURRENT_TILE_HEIGHTThe height of the current tile. SeegetParam(int).- See Also:
-
-
Method Details
-
toString
-
toString
-
getParam
Gets 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
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
- See Also:
-
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
- See Also:
-
setImageBuffer
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
- See Also:
-
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
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:
-
endTile
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
Determines whether the chosenGLCapabilitiesImmutablerequires a pre-swap-buffersbefore accessing the results, i.e. beforeendTile(GL).See
GLDrawableUtil.swapBuffersBeforeRead(GLCapabilitiesImmutable). -
attachAutoDrawable
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:
- Optional
-
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
SetGLEventListenerfor pre- and post operations when used w/attachAutoDrawable(GLAutoDrawable)for eachGLEventListenercallback.- Parameters:
preTile- the pre operationspostTile- the post operations
-
display
Rendering one tile, by simply callingGLAutoDrawable.display().- Throws:
IllegalStateException- if noGLAutoDrawableisattachedor imageSize is not set
-