29package com.jogamp.opengl.test.junit.jogl.awt;
32import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
33import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
34import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw02ES2ListenerFBO;
35import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
36import com.jogamp.opengl.test.junit.util.MiscUtils;
37import com.jogamp.opengl.test.junit.util.QuitAdapter;
38import com.jogamp.opengl.test.junit.util.UITestCase;
40import com.jogamp.opengl.GL;
41import com.jogamp.opengl.GL2ES2;
42import com.jogamp.opengl.GLAutoDrawable;
43import com.jogamp.opengl.GLEventListener;
44import com.jogamp.opengl.GLProfile;
45import com.jogamp.opengl.GLCapabilities;
46import com.jogamp.opengl.awt.GLJPanel;
47import javax.swing.JFrame;
49import com.jogamp.opengl.util.texture.TextureIO;
50import com.jogamp.opengl.util.texture.TextureState;
51import com.jogamp.opengl.util.GLReadBufferUtil;
53import java.awt.Dimension;
54import java.io.IOException;
56import org.junit.Assert;
57import org.junit.Assume;
58import org.junit.BeforeClass;
60import org.junit.FixMethodOrder;
61import org.junit.runners.MethodSorters;
66@FixMethodOrder(MethodSorters.NAME_ASCENDING)
68 static boolean showFPS =
false;
69 static long duration = 250;
75 static void setFrameSize(
final JFrame frame,
final boolean frameLayout,
final java.awt.Dimension new_sz) {
77 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
79 frame.setSize(new_sz);
84 }
catch(
final Throwable throwable ) {
85 throwable.printStackTrace();
86 Assume.assumeNoException( throwable );
90 public void testImpl(
final boolean keepTextureBound,
final int texUnit)
91 throws InterruptedException, IOException
98 System.err.println(getSimpleTestName(
".")+
": GLProfile n/a");
105 final Dimension glc_sz =
new Dimension(640, 480);
106 final Dimension glc_sz2 =
new Dimension(800, 400);
107 glc.setMinimumSize(glc_sz);
108 glc.setPreferredSize(glc_sz);
109 final JFrame frame =
new JFrame(
"TestGLJPanelTextureStateAWT");
110 Assert.assertNotNull(frame);
111 frame.getContentPane().add(glc);
130 final boolean[] glelError = {
false };
133 int gle0X, gle0Y, gle0W, gle0H;
134 int gle1X, gle1Y, gle1W, gle1H;
138 void setupTex(
final GL gl) {
140 if( keepTextureBound ) {
184 final int[] viewport =
new int[] { 0, 0, 0, 0 };
186 if( gle1X != viewport[0] || gle1Y != viewport[1] || gle1W != viewport[2] || gle1H != viewport[3] ) {
187 final String msg =
"Expected "+gle1X+
"/"+gle1Y+
" "+gle1W+
"x"+gle1H+
188 ", actual "+viewport[0]+
"/"+viewport[1]+
" "+viewport[2]+
"x"+viewport[3];
189 Assert.assertTrue(
"Viewport not restored: "+msg,
false);
210 if( keepTextureBound ) {
219 final int border = 5;
221 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
224 gle0W = width/2 - 2*border;
228 gle1X = gle0X + gle0W + 2*border;
230 gle1W = width/2 - 2*border;
242 gle0.
reshape(drawable, 0, 0, gle0W, gle0H);
245 gle1.
reshape(drawable, 0, 0, gle1W, gle1H);
247 if( keepTextureBound ) {
254 new com.jogamp.newt.event.awt.AWTKeyAdapter(quitAdapter, glc).addTo(glc);
255 new com.jogamp.newt.event.awt.AWTWindowAdapter(quitAdapter, glc).addTo(glc);
257 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
260 frame.setVisible(
true);
262 }
catch(
final Throwable throwable ) {
263 throwable.printStackTrace();
264 Assume.assumeNoException( throwable );
269 setFrameSize(frame,
true, glc_sz2);
273 final long t0 = System.currentTimeMillis();
274 while(!quitAdapter.shouldQuit() && System.currentTimeMillis()-t0<duration) {
280 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
282 frame.setVisible(
false);
286 }
catch(
final Throwable throwable ) {
287 throwable.printStackTrace();
288 Assume.assumeNoException( throwable );
290 Assume.assumeFalse(
"Error occured in GLEL .. see log file above", glelError[0]);
295 testImpl(
false , 0 );
306 public static void main(
final String args[])
throws IOException {
307 for(
int i=0; i<args.length; i++) {
308 if(args[i].equals(
"-time")) {
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
A lightweight Swing component which provides OpenGL rendering support.
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Unit test for bug 826, test GLJPanel's TextureState save and restore.
static void main(final String args[])
void test01_texUnit0_keepTex0_ES2()
void test02_texUnit0_keepTex1_ES2()
void testImpl(final boolean keepTextureBound, final int texUnit)
void test03_texUnit1_keepTex1_ES2()
void setClearBuffers(final boolean v)
void setKeepTextureBound(final boolean v)
void setClearBuffers(final boolean v)
static boolean waitForRealized(final java.awt.Component comp, final boolean realized, final Runnable waitAction)
static boolean waitForVisible(final java.awt.Component comp, final boolean visible, final Runnable waitAction)
static long atol(final String str, final long def)
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Preserves a [ texture-unit, texture-target ] state.
final int getMinFilter()
Returns the state's min-filter param.
final int getWrapT()
Returns the state's wrap-t param.
final int getWrapS()
Returns the state's wrap-s param.
final int getUnit()
Returns the texture-unit of this state, key value.
final int getMagFilter()
Returns the state's mag-filter param.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GL2ES2 getGL2ES2()
Casts this object to the GL2ES2 interface.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void dispose(GLAutoDrawable drawable)
Notifies the listener to perform the release of all OpenGL resources per GLContext,...
void display(GLAutoDrawable drawable)
Called by the drawable to initiate OpenGL rendering by the client.
void init(GLAutoDrawable drawable)
Called by the drawable immediately after the OpenGL context is initialized.
void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
Called by the drawable during the first repaint after the component has been resized.
static final int GL_TEXTURE_MAG_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MAG_FILTER" w...
void glGetIntegerv(int pname, IntBuffer data)
Entry point to C language function: void {@native glGetIntegerv}(GLenum pname, GLint * data) Part ...
static final int GL_REPEAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_REPEAT" with expressi...
static final int GL_TEXTURE_2D
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expr...
static final int GL_TEXTURE_WRAP_S
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_S" with ...
void glBindTexture(int target, int texture)
Entry point to C language function: void {@native glBindTexture}(GLenum target, GLuint texture) Pa...
static final int GL_LINEAR
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LINEAR" with expressi...
static final int GL_TEXTURE_MIN_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MIN_FILTER" w...
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
static final int GL_TEXTURE_WRAP_T
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_T" with ...
void glActiveTexture(int texture)
Entry point to C language function: void {@native glActiveTexture}(GLenum texture) Part of GL_ES_V...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glTexParameteri(int target, int pname, int param)
Entry point to C language function: void {@native glTexParameteri}(GLenum target,...
static final int GL_NEAREST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NEAREST" with express...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
static final int GL_TEXTURE0
GL_ES_VERSION_2_0, GL_VERSION_1_3, GL_VERSION_ES_1_0, GL_ARB_multitexture Alias for: GL_TEXTURE0_ARB ...
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
static final int GL_VIEWPORT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VIEWPORT" with expres...