28package com.jogamp.opengl.test.junit.jogl.tile;
30import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
31import com.jogamp.opengl.test.junit.util.UITestCase;
32import com.jogamp.opengl.util.GLPixelBuffer;
33import com.jogamp.opengl.util.TileRenderer;
34import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
35import com.jogamp.opengl.util.TileRendererBase;
36import com.jogamp.opengl.util.texture.TextureData;
37import com.jogamp.opengl.util.texture.TextureIO;
40import java.io.IOException;
42import com.jogamp.nativewindow.util.PixelFormat;
43import com.jogamp.opengl.GL2;
44import com.jogamp.opengl.GLAutoDrawable;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.GLContext;
47import com.jogamp.opengl.GLDrawable;
48import com.jogamp.opengl.GLDrawableFactory;
49import com.jogamp.opengl.GLEventListener;
50import com.jogamp.opengl.GLProfile;
52import org.junit.Assert;
53import org.junit.FixMethodOrder;
55import org.junit.runners.MethodSorters;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static long duration = 500;
70 static class DrawableContext {
79 private static DrawableContext createDrawableAndCurrentCtx(
final GLCapabilities glCaps,
final int width,
final int height) {
86 return new DrawableContext(d, glc);
89 private static void destroyDrawableContext(
final DrawableContext dc) {
95 dc.d.setRealized(
false);
101 public void test01() throws IOException {
106 final int maxTileSize = 256;
107 final DrawableContext dc = createDrawableAndCurrentCtx(caps, maxTileSize, maxTileSize);
111 final int imageWidth = dc.d.getSurfaceWidth() * 6;
112 final int imageHeight = dc.d.getSurfaceHeight() * 4;
114 final String filename = this.getSnapshotFilename(0,
"-tile", dc.d.getChosenGLCapabilities(), imageWidth, imageHeight,
false,
TextureIO.
PNG,
null);
115 final File file =
new File(filename);
119 renderer.
setTileSize(dc.d.getSurfaceWidth(), dc.d.getSurfaceHeight(), 0);
123 final boolean[] flipVertically = {
false };
126 final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3,
true);
127 final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs,
true, imageWidth, imageHeight, 1, 0);
129 flipVertically[0] =
false;
136 while( !renderer.
eot() ) {
147 destroyDrawableContext(dc);
153 imageWidth, imageHeight,
170 final int maxTileSize = 256;
171 final DrawableContext dc = createDrawableAndCurrentCtx(caps, maxTileSize, maxTileSize);
175 final int imageWidth = dc.d.getSurfaceWidth() * 6;
176 final int imageHeight = dc.d.getSurfaceHeight() * 4;
180 renderer.
setTileSize(dc.d.getSurfaceWidth(), dc.d.getSurfaceHeight(), 0);
182 IllegalStateException ise =
null;
185 }
catch (
final IllegalStateException _ise) {
187 System.err.println(
"Expected "+ise.getClass().getSimpleName()+
": "+ise.getMessage());
189 Assert.assertNotNull(
"TileRenderer.beginTile: Image-size exception missing", ise);
196 }
catch (
final IllegalStateException _ise) {
198 System.err.println(
"Expected "+ise.getClass().getSimpleName()+
": "+ise.getMessage());
200 Assert.assertNotNull(
"TileRenderer.beginTile: EOT (1) exception missing", ise);
210 while( !renderer.
eot() ) {
222 }
catch (
final IllegalStateException _ise) {
224 System.err.println(
"Expected "+ise.getClass().getSimpleName()+
": "+ise.getMessage());
226 Assert.assertNotNull(
"TileRenderer.beginTile: EOT (2) exception missing", ise);
229 Assert.assertTrue(
"TileRenderer not rendered more than one tile but "+numTiles, numTiles > 1);
231 destroyDrawableContext(dc);
234 public static void main(
final String args[]) {
235 for(
int i=0; i<args.length; i++) {
236 if(args[i].equals(
"-time")) {
239 duration = Integer.parseInt(args[i]);
240 }
catch (
final Exception ex) { ex.printStackTrace(); }
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Specifies a set of OpenGL capabilities.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
Abstraction for an OpenGL rendering context.
static final int CONTEXT_NOT_CURRENT
Indicates that the context was not made current during the last call to makeCurrent,...
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
abstract GLDrawable createOffscreenDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates an unrealized offscreen GLDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
void removeTileRendererNotify(final TileRendererBase tr)
The owning GLAutoDrawable is detached from the given TileRendererBase instance.
void reshape(final GLAutoDrawable glad, final int x, final int y, final int width, final int height)
Called by the drawable during the first repaint after the component has been resized.
void addTileRendererNotify(final TileRendererBase tr)
The owning GLAutoDrawable is attached to the given TileRendererBase instance.
void init(final GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void display(final GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void setVerbose(final boolean v)
Demos offscreen GLDrawable being used for TileRenderer rendering to produce a PNG file.
static void main(final String args[])
OpenGL pixel data buffer, allowing user to provide buffers via their GLPixelBufferProvider implementa...
static final GLPixelBufferProvider defaultProviderWithRowStride
Default GLPixelBufferProvider with GLPixelBufferProvider#getAllowRowStride() == true,...
final GLPixelAttributes pixelAttributes
The GLPixelAttributes.
final Buffer buffer
Buffer holding the pixel data.
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d....
final void setImageBuffer(final GLPixelBuffer buffer)
Sets the buffer in which to store the final image.
static final int TR_CURRENT_TILE_WIDTH
The width of the current tile.
static final int TR_IMAGE_WIDTH
The width of the final image.
static final int TR_CURRENT_TILE_HEIGHT
The height of the current tile.
final GLPixelBuffer getImageBuffer()
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...
final int getParam(final int pname)
Gets the parameters of this TileRenderer object.
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.
final void beginTile(final GL gl)
Begins rendering a tile.This method modifies the viewport, see below. User shall reset the viewport w...
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.
final void setTileSize(final int width, final int height, final int border)
Sets the size of the tiles to use in rendering.
Represents the data for an OpenGL texture.
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
static void write(final Texture texture, final File file)
Writes the given texture to a file.
GL getGL()
Casts this object to the GL interface.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GL2 getGL2()
Casts this object to the GL2 interface.
An abstraction for an OpenGL rendering target.
void setRealized(boolean realized)
Indicates to GLDrawable implementations whether the underlying surface has been created and can be dr...
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...
PixelFormat.Composition getHostPixelComp(final GLProfile glp, final int componentCount)
Returns the host PixelFormat.Composition matching GL and componentCount if required by implementation...