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 GLEventListener.reshape(GLAutoDrawable, int, int, int, int)
method
is being called after beginTile(GL)
.
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.TileRendererNotify
Notifies
GLEventListener implementing this interface
that the owning GLAutoDrawable is attached
to a tile renderer or detached from it. |
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 |
attachToAutoDrawable(GLAutoDrawable glad)
Attaches this renderer to the
GLAutoDrawable . |
abstract void |
beginTile(GL gl)
Begins rendering a tile.
|
void |
detachFromAutoDrawable()
Detaches this renderer from the
GLAutoDrawable . |
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) . |
GLPixelBuffer |
getImageBuffer() |
DimensionImmutable |
getImageSize() |
abstract int |
getParam(int pname)
Gets the parameters of this TileRenderer object
|
GLPixelBuffer |
getTileBuffer() |
boolean |
reqPreSwapBuffers(GLCapabilitiesImmutable chosenCaps)
Determines whether the chosen
GLCapabilitiesImmutable
requires a pre-swap-buffers
before accessing the results, i.e. |
void |
setGLEventListener(GLEventListener preTile,
GLEventListener postTile)
Set
GLEventListener for pre- and post operations when used w/
attachToAutoDrawable(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 final 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 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:
tile width
tile height
tile x-pos
tile y-pos
image width
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.
gl
- The gl contextIllegalStateException
- if image-size has not been setGLException
- if image buffer
is used but gl
instance is < GL2ES3
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)
.
Usually one uses the default-read-buffer
, i.e.
GL.GL_FRONT
for single-buffer and GL.GL_BACK
for double-buffer GLDrawable
s
and GL.GL_COLOR_ATTACHMENT0
for offscreen framebuffer objects.
Here swap-buffers
shall happen after calling endTile(GL)
, the default.
However, multisampling offscreen GLFBODrawable
s
utilize swap-buffers
to downsample
the multisamples into the readable sampling sink.
In this case, we require a swap-buffers
before calling endTile(GL)
.
chosenCaps
- the chosen GLCapabilitiesImmutable
public void attachToAutoDrawable(GLAutoDrawable glad) throws IllegalStateException
GLAutoDrawable
.
The GLAutoDrawable
's original GLEventListener
are moved to this tile renderer.
It is highly recommended that the original GLEventListener
implement
TileRendererBase.TileRendererNotify
, so they get notified
about this event.
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 GLEventListener
is then added to handle the tile rendering,
replacing the original GLEventListener
.
This display
implementations issues:
pre-glel
.display(..)
beginTile(GL)
GLEventListener
:
pre-swap
) { swapBuffers()
}endTile(GL)
pre-swap
) { swapBuffers()
}post-glel
.display(..)
The PMV Matrix shall be reshaped in the
original GLEventListener
's reshape
method
according to the tile-position, -size and image-size
The reshape
method is called for each tile
w/ the current viewport of tile-size, where the tile-position and image-size can be retrieved by this tile renderer,
see details in beginTile(GL)
.
The original GLEventListener
implementing TileRendererBase.TileRendererNotify
is aware of this
tile renderer instance.
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 detachFromAutoDrawable()
to remove this renderer from the GLAutoDrawable
and to restore it's original GLEventListener
.
glad
- IllegalStateException
- if an GLAutoDrawable
is already attachedpublic void detachFromAutoDrawable()
GLAutoDrawable
.
It is highly recommended that the original GLEventListener
implement
TileRendererBase.TileRendererNotify
, so they get notified
about this event.
public void setGLEventListener(GLEventListener preTile, GLEventListener postTile)
GLEventListener
for pre- and post operations when used w/
attachToAutoDrawable(GLAutoDrawable)
for each GLEventListener
callback.preTile
- the pre operationspostTile
- the post operationspublic void display() throws IllegalStateException
GLAutoDrawable.display()
.IllegalStateException
- if no GLAutoDrawable
is attached
or imageSize is not setCopyright 2010 JogAmp Community.