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.RandomTileRenderer;
34import com.jogamp.opengl.util.TileRendererBase;
35import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
36import com.jogamp.opengl.util.texture.TextureData;
37import com.jogamp.opengl.util.texture.TextureIO;
40import java.io.IOException;
41import java.lang.reflect.InvocationTargetException;
43import com.jogamp.nativewindow.util.PixelFormat;
44import com.jogamp.opengl.GL;
45import com.jogamp.opengl.GLAutoDrawable;
46import com.jogamp.opengl.GLCapabilities;
47import com.jogamp.opengl.GLDrawableFactory;
48import com.jogamp.opengl.GLEventListener;
49import com.jogamp.opengl.GLOffscreenAutoDrawable;
50import com.jogamp.opengl.GLRunnable;
52import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
74@FixMethodOrder(MethodSorters.NAME_ASCENDING)
76 static long duration = 500;
79 public void test01_aa0() throws IOException, InterruptedException, InvocationTargetException {
83 public void test02_aa8() throws IOException, InterruptedException, InvocationTargetException {
87 void doTest(
final int msaaCount)
throws IOException, InterruptedException, InvocationTargetException {
95 final int maxTileSize = 64;
99 final Gears gears =
new Gears();
103 final int imageWidth = 256 * 6;
104 final int imageHeight = 256 * 4;
106 final String filename = this.getSnapshotFilename(0,
"-tile", glad.
getChosenGLCapabilities(), imageWidth, imageHeight,
false, TextureIO.PNG,
null);
107 final File file =
new File(filename);
110 final RandomTileRenderer renderer =
new RandomTileRenderer();
111 renderer.attachAutoDrawable(glad);
112 renderer.setImageSize(imageWidth, imageHeight);
114 final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider = GLPixelBuffer.defaultProviderWithRowStride;
115 final boolean[] flipVertically = {
false };
120 final GL gl = drawable.
getGL();
121 final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.
getGLProfile(), 3);
122 final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3,
true);
123 final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs,
true, imageWidth, imageHeight, 1, 0);
124 renderer.setImageBuffer(pixelBuffer);
126 flipVertically[0] =
false;
128 flipVertically[0] =
true;
132 public void dispose(
final GLAutoDrawable drawable) {}
134 public void display(
final GLAutoDrawable drawable) {}
136 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
138 renderer.setGLEventListener(preTileGLEL,
null);
140 final int w = maxTileSize, h = maxTileSize;
142 while( dx+w <= imageWidth && dy+h <= imageHeight ) {
143 renderer.display(dx, dy, w, h);
145 if( dx + w > imageWidth ) {
151 renderer.detachAutoDrawable();
155 glad.
invoke(
true,
new GLRunnable() {
157 public boolean run(
final GLAutoDrawable drawable) {
158 drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
159 gears.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
166 final GLPixelBuffer imageBuffer = renderer.getImageBuffer();
168 System.err.println(
"XXX2: "+imageBuffer);
169 final TextureData textureData =
new TextureData(
172 imageWidth, imageHeight,
174 imageBuffer.pixelAttributes,
179 System.err.println(
"XXX3: "+textureData.getPixelFormat()+
", "+textureData.getPixelAttributes());
181 TextureIO.write(textureData, file);
184 public static void main(
final String args[]) {
185 for(
int i=0; i<args.length; i++) {
186 if(args[i].equals(
"-time")) {
189 duration = Integer.parseInt(args[i]);
190 }
catch (
final Exception ex) { ex.printStackTrace(); }
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
void setSampleBuffers(final boolean enable)
Defaults to false.
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Demos offscreen GLAutoDrawable being used for RandomTileRenderer rendering to produce a PNG file.
static void main(final String args[])
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
boolean isGLOriented()
Returns true if the drawable is rendered in OpenGL's coordinate system, origin at bottom left.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.