37package com.jogamp.opengl.util;
39import com.jogamp.nativewindow.util.Dimension;
40import com.jogamp.nativewindow.util.DimensionImmutable;
41import com.jogamp.opengl.GL;
42import com.jogamp.opengl.GL2ES3;
43import com.jogamp.opengl.GLException;
45import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
128 private static final int DEFAULT_TILE_WIDTH = 256;
129 private static final int DEFAULT_TILE_HEIGHT = 256;
130 private static final int DEFAULT_TILE_BORDER = 0;
132 private final Dimension tileSize =
new Dimension(DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT);
133 private final Dimension tileSizeNB =
new Dimension(DEFAULT_TILE_WIDTH - 2 * DEFAULT_TILE_BORDER, DEFAULT_TILE_HEIGHT - 2 * DEFAULT_TILE_BORDER);
135 private boolean isInit =
false;
136 private Dimension imageClippingDim =
null;
137 private int tileBorder = DEFAULT_TILE_BORDER;
141 private int currentTile = 0;
142 private int currentRow;
143 private int currentColumn;
149 sb.append(
"# "+currentTile+
": ["+currentColumn+
"]["+currentRow+
"] / "+columns+
"x"+rows+
", ")
150 .append(
"rowOrder "+rowOrder+
", offset/size "+offsetX+
"/"+offsetY+
" "+tileSize.
getWidth()+
"x"+tileSize.
getHeight()+
" brd "+tileBorder+
", ");
151 return super.tileDetails(sb);
169 super.setImageSize(width, height);
188 if(
null == imageClippingDim ) {
189 imageClippingDim =
new Dimension(width, height);
191 imageClippingDim.
set(width, height);
212 if(
null != imageClippingDim ) {
239 public final void setTileSize(
final int width,
final int height,
final int border) {
241 throw new IllegalArgumentException(
"Tile border must be >= 0");
243 if( 2 * border >= width || 2 * border >= height ) {
244 throw new IllegalArgumentException(
"Tile size must be > 0x0 minus 2*border");
247 tileSize.
set( width, height );
248 tileSizeNB.
set( width - 2 * border, height - 2 * border );
299 final int getCurrentTile() {
return currentTile; }
317 return null != imageClippingDim ? imageClippingDim.
getWidth() : 0;
319 return null != imageClippingDim ? imageClippingDim.
getHeight() : 0;
339 return currentColumn;
343 throw new IllegalArgumentException(
"Invalid pname: "+pname);
356 throw new IllegalArgumentException(
"Must pass TR_TOP_TO_BOTTOM or TR_BOTTOM_TO_TOP");
377 public final boolean eot() {
381 return 0 > currentTile || 0 >= columns*rows;
393 throw new IllegalStateException(
"Image size has not been set: "+
this);
396 throw new IllegalStateException(
"EOT reached: "+
this);
402 currentRow = currentTile / columns;
403 currentColumn = currentTile % columns;
405 currentRow = rows - ( currentTile / columns ) - 1;
406 currentColumn = currentTile % columns;
408 assert ( currentRow < rows );
409 assert ( currentColumn < columns );
411 final int border = tileBorder;
417 if (currentRow < rows - 1) {
420 tH = clippedImageSize.
getHeight() - ( rows - 1 ) * ( tileSizeNB.
getHeight() ) + 2 * border;
423 if (currentColumn < columns - 1) {
426 tW = clippedImageSize.
getWidth() - ( columns - 1 ) * ( tileSizeNB.
getWidth() ) + 2 * border;
436 gl.glViewport( 0, 0, tW, tH );
439 System.err.println(
"TileRenderer.begin: "+this.
toString());
451 throw new IllegalStateException(
"beginTile(..) has not been called");
461 final int readBuffer;
462 if( gl.isGL2ES3() ) {
471 System.err.println(
"TileRenderer.end.0: readBuffer 0x"+Integer.toHexString(readBuffer)+
", "+
this.toString());
474 final int tmp[] =
new int[1];
478 final int srcX = tileBorder;
479 final int srcY = tileBorder;
480 final int srcWidth = tileSizeNB.
getWidth();
481 final int srcHeight = tileSizeNB.
getHeight();
485 throw new IndexOutOfBoundsException(
"Required " + readPixelSize +
" bytes of buffer, only had " +
tileBuffer);
496 final int srcX = tileBorder;
497 final int srcY = tileBorder;
508 final int skipPixels = currentColumn * tileSizeNB.
getWidth();
509 final int skipRows = currentRow * tileSizeNB.
getHeight();
510 final int ibPos = ( skipPixels + ( skipRows * rowLength ) ) * pixelAttribs.
pfmt.
comp.
bytesPerPixel();
511 final int ibLim = ibPos + readPixelSize;
514 throw new IndexOutOfBoundsException(
"Required " + ibLim +
" bytes of buffer, only had " +
imageBuffer);
532 if( currentTile >= rows * columns ) {
final void set(final int width, final int height)
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Utility routines for dealing with direct buffers.
static final int sizeof(final GL gl, final int tmp[], final int bytesPerPixel, int width, int height, int depth, final boolean pack)
Returns the number of bytes required to read/write a memory buffer via OpenGL using the current GL pi...
final int type
The OpenGL pixel data type
final PixelFormat pfmt
PixelFormat describing the component layout
final int format
The OpenGL pixel data format.
int position()
Returns the byte position of the buffer.
Buffer flip()
See Buffer#flip().
final GLPixelAttributes pixelAttributes
The GLPixelAttributes.
Buffer clear()
See Buffer#clear().
boolean requiresNewBuffer(final GL gl, final int newWidth, final int newHeight, int newByteSize)
Returns true, if invalid or implementation requires a new buffer based on the new size due to pixel a...
final Buffer buffer
Buffer holding the pixel data.
final void setPackRowLength(final GL2ES3 gl, final int packRowLength)
Sets the GL2ES3#GL_PACK_ROW_LENGTH.
final void restore(final GL gl)
Restores PACK and UNPACK pixel storage mode previously saved w/ saveAll(GL) or savePack(GL) and saveU...
final void setPackAlignment(final GL gl, final int packAlignment)
Sets the GL#GL_PACK_ALIGNMENT.
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d....
GLPixelBuffer imageBuffer
static final int TR_CURRENT_TILE_WIDTH
The width of the current tile.
final Dimension imageSize
static final int TR_IMAGE_WIDTH
The width of the final image.
final GLPixelStorageModes psm
static final int TR_CURRENT_TILE_HEIGHT
The height of the current tile.
static final int TR_CURRENT_TILE_X_POS
The x-pos of the current tile.
static final int TR_CURRENT_TILE_Y_POS
The y-pos of the current tile.
static final int TR_IMAGE_HEIGHT
The height of the final image.
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d....
final void clipImageSize(final int width, final int height)
Clips the image-size this tile-renderer iterates through, which can be retrieved via getClippedImageS...
static final int TR_IMAGE_CLIPPING_HEIGHT
The height of the final clipped image.
static final int TR_ROW_ORDER
The order that the rows are traversed.
final int getParam(final int pname)
Gets the parameters of this TileRenderer object.
static final int TR_BOTTOM_TO_TOP
Indicates we are traversing rows from the bottom to the top (default).
static final int TR_TILE_Y_OFFSET
The tiles y-offset.
final boolean eot()
Returns true if end of tiling has been reached, otherwise false.end of tiling criteria is implementat...
TileRenderer()
Creates a new TileRenderer object.
static final int TR_TOP_TO_BOTTOM
Indicates we are traversing rows from the top to the bottom.
void setTileOffset(final int xoff, final int yoff)
Sets an xy offset for the resulting tiles x-pos and y-pos.
StringBuilder tileDetails(final StringBuilder sb)
final void beginTile(final GL gl)
Begins rendering a tile.This method modifies the viewport, see below. User shall reset the viewport w...
static final int TR_TILE_X_OFFSET
The tiles x-offset.
final void reset()
Method resets implementation's internal state to start of tiling as required for beginTile(GL) if end...
static final int TR_TILE_HEIGHT
The height of the tiles.
static final int TR_ROWS
The number of rows of tiles.
static final int TR_CURRENT_TILE_NUM
The current tile number.
static final int TR_COLUMNS
The number of columns of tiles.
static final int TR_TILE_WIDTH
The width of the tiles.
static final int TR_TILE_BORDER
The width of the border around the tiles.
static final int TR_CURRENT_COLUMN
The current column number.
final DimensionImmutable getClippedImageSize()
Returns the clipped image-size.
static final int TR_IMAGE_CLIPPING_WIDTH
The width of the final clipped image.
final void setRowOrder(final int order)
Sets the order of row traversal, default is TR_BOTTOM_TO_TOP.
void endTile(final GL gl)
Must be called after rendering the scene, see beginTile(GL).
final void setImageSize(final int width, final int height)
Sets the desired size of the final image.
static final int TR_CURRENT_ROW
The current row number.
final boolean isSetup()
Returns true if this instance is setup properly, i.e.
final void setTileSize(final int width, final int height, final int border)
Sets the size of the tiles to use in rendering.
Immutable Dimension Interface, consisting of it's read only components:
void glReadBuffer(int mode)
Entry point to C language function: void {@native glReadBuffer}(GLenum mode) Part of GL_ES_VERSION...
GL2ES3 getGL2ES3()
Casts this object to the GL2ES3 interface.
int getDefaultReadBuffer()
Returns the default color buffer within the current bound getDefaultReadFramebuffer(),...