public abstract class TileRendererBase extends Object
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
.
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)
.
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
.
Modifier and Type | Class and Description |
---|---|
static interface |
TileRendererBase.TileRendererListener
Listener for tile renderer events, intended to extend
GLEventListener implementations,
enabling tile rendering via attachAutoDrawable(GLAutoDrawable) . |
Modifier and Type | Field and Description |
---|---|
static int |
TR_CURRENT_TILE_HEIGHT
The height of the current tile.
|
static int |
TR_CURRENT_TILE_WIDTH
The width of the current tile.
|
static int |
TR_CURRENT_TILE_X_POS
The x-pos of the current tile.
|
static int |
TR_CURRENT_TILE_Y_POS
The y-pos of the current tile.
|
static int |
TR_IMAGE_HEIGHT
The height of the final image.
|
static int |
TR_IMAGE_WIDTH
The width of the final image.
|
Modifier and Type | Method and Description |
---|---|
void |
attachAutoDrawable(GLAutoDrawable glad)
Attaches the given
GLAutoDrawable to this tile renderer. |
abstract void |
beginTile(GL gl)
Begins rendering a tile.
|
void |
detachAutoDrawable()
Detaches the given
GLAutoDrawable from this tile renderer. |
void |
display()
Rendering one tile, by simply calling
GLAutoDrawable.display() . |
abstract void |
endTile(GL gl)
Must be called after rendering the scene,
see
beginTile(GL) . |
abstract boolean |
eot()
Returns true if end of tiling has been reached, otherwise false.
|
GLAutoDrawable |
getAttachedDrawable()
|
GLPixelBuffer |
getImageBuffer() |
DimensionImmutable |
getImageSize() |
abstract int |
getParam(int pname)
Gets the parameters of this TileRenderer object
|
GLPixelBuffer |
getTileBuffer() |
abstract boolean |
isSetup()
Returns true if this instance is setup properly, i.e.
|
boolean |
reqPreSwapBuffers(GLCapabilitiesImmutable chosenCaps)
Determines whether the chosen
GLCapabilitiesImmutable
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 for
beginTile(GL) if end of tiling has been reached. |
void |
setGLEventListener(GLEventListener preTile,
GLEventListener postTile)
Set
GLEventListener for pre- and post operations when used w/
attachAutoDrawable(GLAutoDrawable)
for each GLEventListener callback. |
void |
setImageBuffer(GLPixelBuffer buffer)
Sets the buffer in which to store the final image
|
void |
setImageSize(int width,
int height)
Sets the desired size of the final image
|
void |
setTileBuffer(GLPixelBuffer buffer)
Specify a buffer the tiles to be copied to.
|
String |
toString() |
StringBuilder |
toString(StringBuilder sb) |
public static final int TR_IMAGE_WIDTH
getParam(int)
.public static final int TR_IMAGE_HEIGHT
getParam(int)
.public static final int TR_CURRENT_TILE_X_POS
getParam(int)
.public static final int TR_CURRENT_TILE_Y_POS
getParam(int)
.public static final int TR_CURRENT_TILE_WIDTH
getParam(int)
.public static final int TR_CURRENT_TILE_HEIGHT
getParam(int)
.public StringBuilder toString(StringBuilder sb)
public abstract int getParam(int pname) throws IllegalArgumentException
pname
- The parameter name that is to be retrievedIllegalArgumentException
- if pname
is not handledpublic final void setTileBuffer(GLPixelBuffer buffer)
buffer
- The buffer itself. Must be large enough to contain a random tilepublic final GLPixelBuffer getTileBuffer()
setTileBuffer(GLPixelBuffer)
public void setImageSize(int width, int height)
width
- The width of the final imageheight
- The height of the final imagepublic final DimensionImmutable getImageSize()
setImageSize(int, int)
public final void setImageBuffer(GLPixelBuffer buffer)
buffer
- the buffer itself, must be large enough to hold the final imagepublic final GLPixelBuffer getImageBuffer()
setImageBuffer(GLPixelBuffer)
public abstract boolean isSetup()
setImageSize(int, int)
..,
and ready for beginTile(GL)
.
Otherwise returns false.public abstract boolean eot()
end of tiling criteria is implementation specific and may never be reached.
User needs to reset()
tiling after reaching end of tiling
before calling beginTile(GL)
again.
public abstract void reset()
beginTile(GL)
if end of tiling
has been reached.
Implementation is a nop where end of tiling
is never reached.
public abstract void beginTile(GL gl) throws IllegalStateException, GLException
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 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 to reset()
tiling before calling this method.
gl
- The gl contextIllegalStateException
- if image-size
is undefined,
an implementation related setup
has not be performed
or has been reached. See implementing classes.GLException
- if image buffer
is used but gl
instance is < GL2ES3
isSetup()
,
eot()
,
reset()
public abstract void endTile(GL gl) throws IllegalStateException, GLException
beginTile(GL)
.
Please consider reqPreSwapBuffers(GLCapabilitiesImmutable)
to determine
whether you need to perform swap-buffers
before or after
calling this method!
User has to comply with the GL profile requirement.
gl
- the gl contextIllegalStateException
- if beginTile(gl) has not been calledGLException
- if image buffer
is used but gl
instance is < GL2ES3
public final boolean reqPreSwapBuffers(GLCapabilitiesImmutable chosenCaps)
GLCapabilitiesImmutable
requires a pre-swap-buffers
before accessing the results, i.e. before endTile(GL)
.
See GLDrawableUtil.swapBuffersBeforeRead(GLCapabilitiesImmutable)
.
public final void attachAutoDrawable(GLAutoDrawable glad) throws IllegalStateException
GLAutoDrawable
to this tile renderer.
The GLAutoDrawable
's original GLEventListener
are moved to this tile renderer.
GLEventListeners
not implementing TileRendererBase.TileRendererListener
are ignored while tile rendering.
The GLAutoDrawable
's auto-swap mode
is cached
and set to false
, since swapBuffers()
maybe issued before endTile(GL)
,
see reqPreSwapBuffers(GLCapabilitiesImmutable)
.
This tile renderer's internal GLEventListener
is then added to the attached GLAutoDrawable
to handle the tile rendering, replacing the original GLEventListener
.
It's display
implementations issues:
pre-glel
.display(..)
beginTile(GL)
TileRendererBase.TileRendererListener
:
pre-swap
) { swapBuffers()
}endTile(GL)
pre-swap
) { swapBuffers()
}post-glel
.display(..)
Consider using setGLEventListener(GLEventListener, GLEventListener)
to add pre- and post
hooks to be performed on this renderer GLEventListener
.
The pre-hook is able to allocate memory and setup parameters, since it's called before beginTile(GL)
.
The post-hook is able to use the rendering result and can even shutdown tile-rendering,
since it's called after endTile(GL)
.
Call detachAutoDrawable()
to remove the attached GLAutoDrawable
from this tile renderer
and to restore it's original GLEventListener
.
glad
- the GLAutoDrawable
to attach.IllegalStateException
- if an GLAutoDrawable
is already attachedgetAttachedDrawable()
,
detachAutoDrawable()
public final GLAutoDrawable getAttachedDrawable()
attached
GLAutoDrawable
,
null
if none is attached.
If called from TileRendererBase.TileRendererListener.addTileRendererNotify(TileRendererBase)
or TileRendererBase.TileRendererListener.removeTileRendererNotify(TileRendererBase)
, method returns the
just attached or soon to be detached GLAutoDrawable
.
public final void detachAutoDrawable()
GLAutoDrawable
from this tile renderer.public final void setGLEventListener(GLEventListener preTile, GLEventListener postTile)
GLEventListener
for pre- and post operations when used w/
attachAutoDrawable(GLAutoDrawable)
for each GLEventListener
callback.preTile
- the pre operationspostTile
- the post operationspublic final void display() throws IllegalStateException
GLAutoDrawable.display()
.IllegalStateException
- if no GLAutoDrawable
is attached
or imageSize is not setCopyright 2010 JogAmp Community.