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 interface
Listener for tile renderer events, intended to extendGLEventListener
implementations, enabling tile rendering viaattachAutoDrawable(GLAutoDrawable)
. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The height of the current tile.static final int
The width of the current tile.static final int
The x-pos of the current tile.static final int
The y-pos of the current tile.static final int
The height of the final image.static final int
The width of the final image. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Attaches the givenGLAutoDrawable
to this tile renderer.abstract void
Begins rendering a tile.final void
Detaches the givenGLAutoDrawable
from this tile renderer.final void
display()
Rendering one tile, by simply callingGLAutoDrawable.display()
.abstract void
Must be called after rendering the scene, seebeginTile(GL)
.abstract boolean
eot()
Returns true if end of tiling has been reached, otherwise false.final GLAutoDrawable
final GLPixelBuffer
final DimensionImmutable
abstract int
getParam
(int pname) Gets the parameters of this TileRenderer objectfinal GLPixelBuffer
abstract boolean
isSetup()
Returns true if this instance is setup properly, i.e.final boolean
reqPreSwapBuffers
(GLCapabilitiesImmutable chosenCaps) Determines whether the chosenGLCapabilitiesImmutable
requires a pre-swap-buffers
before accessing the results, i.e.abstract void
reset()
Method resets implementation's internal state to start of tiling as required forbeginTile(GL)
ifend of tiling
has been reached.final void
setGLEventListener
(GLEventListener preTile, GLEventListener postTile) SetGLEventListener
for pre- and post operations when used w/attachAutoDrawable(GLAutoDrawable)
for eachGLEventListener
callback.final void
setImageBuffer
(GLPixelBuffer buffer) Sets the buffer in which to store the final imagevoid
setImageSize
(int width, int height) Sets the desired size of the final imagefinal void
setTileBuffer
(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
- ifpname
is 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 tiling
has been reached.Implementation is a nop where
end of tiling
is 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-pos
current tile's y-pos
final image width
final 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 tiling
has been reached, user needs toreset()
tiling before calling this method.- Parameters:
gl
- The gl context- Throws:
IllegalStateException
- ifimage-size
is undefined, animplementation related setup
has not be performed or {@ link #eot()} has been reached. See implementing classes.GLException
- ifimage buffer
is used butgl
instance 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-buffers
before 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 buffer
is used butgl
instance is <GL2ES3
-
reqPreSwapBuffers
Determines whether the chosenGLCapabilitiesImmutable
requires a pre-swap-buffers
before accessing the results, i.e. beforeendTile(GL)
.See
GLDrawableUtil.swapBuffersBeforeRead(GLCapabilitiesImmutable)
. -
attachAutoDrawable
Attaches the givenGLAutoDrawable
to this tile renderer.The
GLAutoDrawable
's originalGLEventListener
are moved to this tile renderer.GLEventListeners
not implementingTileRendererBase.TileRendererListener
are ignored while tile rendering.The
GLAutoDrawable
'sauto-swap mode
is cached and set tofalse
, sinceswapBuffers()
maybe issued beforeendTile(GL)
, seereqPreSwapBuffers(GLCapabilitiesImmutable)
.This tile renderer's internal
GLEventListener
is then added to the attachedGLAutoDrawable
to handle the tile rendering, replacing the originalGLEventListener
.
It'sdisplay
implementations 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 attachedGLAutoDrawable
from this tile renderer and to restore it's originalGLEventListener
.- Parameters:
glad
- theGLAutoDrawable
to attach.- Throws:
IllegalStateException
- if anGLAutoDrawable
is already attached- See Also:
- Optional
-
getAttachedDrawable
Returns a previouslyattached
GLAutoDrawable
,null
if 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 givenGLAutoDrawable
from this tile renderer. -
setGLEventListener
SetGLEventListener
for pre- and post operations when used w/attachAutoDrawable(GLAutoDrawable)
for eachGLEventListener
callback.- Parameters:
preTile
- the pre operationspostTile
- the post operations
-
display
Rendering one tile, by simply callingGLAutoDrawable.display()
.- Throws:
IllegalStateException
- if noGLAutoDrawable
isattached
or imageSize is not set
-