28package com.jogamp.opengl.test.junit.jogl.tile;
30import com.jogamp.newt.opengl.GLWindow;
31import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
32import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears;
33import com.jogamp.opengl.test.junit.util.UITestCase;
34import com.jogamp.opengl.util.GLPixelBuffer;
35import com.jogamp.opengl.util.TileRenderer;
36import com.jogamp.opengl.util.TileRendererBase;
37import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes;
38import com.jogamp.opengl.util.texture.TextureData;
39import com.jogamp.opengl.util.texture.TextureIO;
42import java.io.IOException;
44import com.jogamp.nativewindow.util.PixelFormat;
45import com.jogamp.opengl.GL;
46import com.jogamp.opengl.GLAutoDrawable;
47import com.jogamp.opengl.GLCapabilities;
48import com.jogamp.opengl.GLDrawableFactory;
49import com.jogamp.opengl.GLEventListener;
50import com.jogamp.opengl.GLProfile;
51import com.jogamp.opengl.GLRunnable;
53import org.junit.FixMethodOrder;
55import org.junit.runners.MethodSorters;
75@FixMethodOrder(MethodSorters.NAME_ASCENDING)
77 static long duration = 500;
79 static GLProfile getGLProfile(
final String profile) {
81 System.err.println(
"Profile "+profile+
" n/a");
88 if(
null == glp || !glp.
isGL2ES3() ) {
89 System.err.println(
"GL2ES3 n/a, has max-core "+glp);
101 doTest(
false,
new Gears(), glp, 0);
109 doTest(
false,
new Gears(), glp, 8);
117 doTest(
false,
new GearsES2(), glp, 0);
125 doTest(
false,
new GearsES2(), glp, 8);
133 doTest(
true,
new Gears(), glp, 0);
141 doTest(
true,
new Gears(), glp, 8);
149 doTest(
true,
new GearsES2(), glp, 0);
157 doTest(
true,
new GearsES2(), glp, 8);
160 void doTest(
final boolean onscreen,
final GLEventListener demo,
final GLProfile glp,
final int msaaCount)
throws IOException {
163 if( msaaCount > 0 ) {
168 final int maxTileSize = 256;
171 final GLWindow glWin = GLWindow.create(caps);
172 glWin.setSize(maxTileSize, maxTileSize);
173 glWin.setVisible(
true);
186 final String filename = this.getSnapshotFilename(0,
"-tile", glad.
getChosenGLCapabilities(), imageWidth, imageHeight,
false, TextureIO.PNG,
null);
187 final File file =
new File(filename);
190 final TileRenderer renderer =
new TileRenderer();
191 renderer.setImageSize(imageWidth, imageHeight);
193 renderer.attachAutoDrawable(glad);
195 final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider = GLPixelBuffer.defaultProviderWithRowStride;
196 final boolean[] flipVertically = {
false };
201 final GL gl = drawable.
getGL();
202 final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.
getGLProfile(), 3);
203 final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3,
true);
204 final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs,
true, imageWidth, imageHeight, 1, 0);
205 renderer.setImageBuffer(pixelBuffer);
207 flipVertically[0] =
false;
209 flipVertically[0] =
true;
213 public void dispose(
final GLAutoDrawable drawable) {}
215 public void display(
final GLAutoDrawable drawable) {}
217 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {}
219 renderer.setGLEventListener(preTileGLEL,
null);
221 while ( !renderer.eot() ) {
225 renderer.detachAutoDrawable();
229 glad.
invoke(
true,
new GLRunnable() {
231 public boolean run(
final GLAutoDrawable drawable) {
232 drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
233 demo.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
238 final GLPixelBuffer imageBuffer = renderer.getImageBuffer();
239 final TextureData textureData =
new TextureData(
242 imageWidth, imageHeight,
244 imageBuffer.pixelAttributes,
250 TextureIO.write(textureData, file);
255 public static void main(
final String args[]) {
256 for(
int i=0; i<args.length; i++) {
257 if(args[i].equals(
"-time")) {
260 duration = Integer.parseInt(args[i]);
261 }
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.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
static GLProfile getMaxProgrammableCore(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the programmable shader core pipeline only.
final boolean isGL2ES3()
Indicates whether this profile is capable of GL2ES3.
Gears.java author: Brian Paul (converted to Java by Ron Cemer and Sven Gothel)
Demos offscreen GLAutoDrawable being used for TileRenderer rendering to produce a PNG file.
void test011_off_gl2es3_aa0()
static void main(final String args[])
void test112_on__gl2es3_aa8()
void test111_on__gl2es3_aa0()
void test012_off_gl2es3_aa8()
void test102_on__gl2___aa8()
void test101_on__gl2___aa0()
void test001_off_gl2___aa0()
void test002_off_gl2___aa8()
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...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
boolean isGLOriented()
Returns true if the drawable is rendered in OpenGL's coordinate system, origin at bottom left.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.