32package com.jogamp.opengl.test.junit.jogl.acore;
34import java.awt.BorderLayout;
35import java.lang.reflect.InvocationTargetException;
36import java.nio.FloatBuffer;
38import com.jogamp.opengl.GL;
39import com.jogamp.opengl.GL2;
40import com.jogamp.opengl.GLAutoDrawable;
41import com.jogamp.opengl.GLCapabilities;
42import com.jogamp.opengl.GLContext;
43import com.jogamp.opengl.GLEventListener;
44import com.jogamp.opengl.GLProfile;
45import com.jogamp.opengl.awt.GLCanvas;
46import com.jogamp.opengl.fixedfunc.GLLightingFunc;
47import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
48import com.jogamp.opengl.fixedfunc.GLPointerFunc;
49import javax.swing.JFrame;
50import javax.swing.JPanel;
51import javax.swing.JTabbedPane;
52import javax.swing.SwingUtilities;
53import javax.swing.WindowConstants;
55import org.junit.Assert;
56import org.junit.FixMethodOrder;
58import org.junit.runners.MethodSorters;
60import com.jogamp.common.nio.Buffers;
61import com.jogamp.opengl.test.junit.util.MiscUtils;
62import com.jogamp.opengl.test.junit.util.UITestCase;
64@FixMethodOrder(MethodSorters.NAME_ASCENDING)
67 static class DemoInstance {
83 @SuppressWarnings(
"serial")
88 public SharedGLPanel(
final GLCanvas shareWith,
final int width,
final int height) {
90 System.err.println(
"XXX WWPanel: shareWith "+shareWith+
", sharedCtx "+sharedCtx);
92 if(
null != shareWith) {
98 canvas.
setSize(
new java.awt.Dimension(width, height));
100 setLayout(
new BorderLayout(5, 5));
101 add(canvas, BorderLayout.CENTER);
110 Assert.assertNull(
"Buffer is set, but instance is share master", bufferId);
111 makeVBO(glAutoDrawable);
112 System.err.println(
"XXX Create Buffer "+bufferId[0]);
114 Assert.assertNotNull(
"Buffer is not set, but instance is share slave", bufferId);
116 System.err.println(
"XXX Reuse Buffer "+bufferId[0]);
145 public void reshape(
final GLAutoDrawable glAutoDrawable,
final int i,
final int i1,
final int i2,
final int i3) {
146 final int w = getWidth();
147 final int h = getHeight();
163 bufferId =
new int[1];
167 final FloatBuffer vertices = Buffers.newDirectFloatBuffer(6);
168 vertices.put(0).put(0).put(0);
169 vertices.put(1).put(1).put(0);
173 public JTabbedPane tabbedPanel;
175 public DemoInstance(
final JFrame f) {
179 System.err.println(
"XXX START DEMO XXX");
182 tabbedPanel =
new JTabbedPane();
183 f.add(tabbedPanel, BorderLayout.CENTER);
186 final SharedGLPanel wwpA =
new SharedGLPanel(
null, 600, 600);
187 final SharedGLPanel wwpB =
new SharedGLPanel(wwpA.canvas, wwpA.getWidth(), wwpA.getHeight());
189 tabbedPanel.add(wwpA,
"Window A");
190 tabbedPanel.add(wwpB,
"Window B");
193 f.add(tabbedPanel, BorderLayout.CENTER);
196 f.setTitle(
"Multi-Window Tabbed Pane");
197 f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
199 f.setResizable(
true);
200 }
catch (
final Exception e) {
206 static long durationPerTest = 500*4;
207 static boolean manual =
false;
210 public void test01() throws InterruptedException, InvocationTargetException {
211 final JFrame f =
new JFrame();
212 f.setTitle(
"Shared GLContext AWT GLCanvas JTabbedPane");
213 final DemoInstance demo =
new DemoInstance(f);
214 SwingUtilities.invokeLater(
new Runnable() {
217 System.err.println(
"XXX SetVisible XXX");
222 for(
long w=durationPerTest; w>0; w-=100) {
226 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
229 demo.tabbedPanel.setSelectedIndex(0);
231 Thread.sleep(durationPerTest/4);
233 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
236 demo.tabbedPanel.setSelectedIndex(1);
238 Thread.sleep(durationPerTest/4);
240 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
243 demo.tabbedPanel.setSelectedIndex(0);
245 Thread.sleep(durationPerTest/4);
247 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
250 demo.tabbedPanel.setSelectedIndex(1);
252 Thread.sleep(durationPerTest/4);
255 SwingUtilities.invokeLater(
new Runnable() {
259 System.err.println(
"XXX SetVisible XXX");
264 public static void main(
final String args[]) {
265 for(
int i=0; i<args.length; i++) {
266 if(args[i].equals(
"-time")) {
267 durationPerTest =
MiscUtils.
atoi(args[++i], (
int)durationPerTest);
268 }
else if(args[i].equals(
"-manual")) {
void setRedBits(final int redBits)
Sets the number of bits requested for the color buffer's red component.
void setGreenBits(final int greenBits)
Sets the number of bits requested for the color buffer's green component.
void setBlueBits(final int blueBits)
Sets the number of bits requested for the color buffer's blue component.
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
void setDepthBits(final int depthBits)
Sets the number of bits requested for the depth buffer.
Abstraction for an OpenGL rendering context.
final boolean isShared()
Returns true if this GLContext is shared, otherwise false.
Specifies the the OpenGL profile.
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
static void initSingleton()
Static initialization of JOGL.
A heavyweight AWT component which provides OpenGL rendering support.
final void setSharedAutoDrawable(final GLAutoDrawable sharedAutoDrawable)
Specifies an GLAutoDrawable, which OpenGL context shall be shared by this GLAutoDrawable's GLContext.
GLContext getContext()
Returns the context associated with this drawable.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
static void main(final String args[])
static int atoi(final String str, final int def)
void glOrtho(double left, double right, double bottom, double top, double near_val, double far_val)
void glEnableClientState(int cap)
Entry point to C language function: void {@native glEnableClientState}(GLenum cap) Part of GL_NV_v...
void glColor3f(float red, float green, float blue)
Entry point to C language function: void {@native glColor3f}(GLfloat red, GLfloat green,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
GLContext getContext()
Returns the context associated with this drawable.
GL2 getGL2()
Casts this object to the GL2 interface.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
void glGenBuffers(int n, IntBuffer buffers)
Entry point to C language function: void {@native glGenBuffers}(GLsizei n, GLuint * buffers) Part ...
void glDrawArrays(int mode, int first, int count)
Entry point to C language function: void {@native glDrawArrays}(GLenum mode, GLint first,...
static final int GL_STATIC_DRAW
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_STATI...
static final int GL_FLOAT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_FLOAT" with expressio...
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,...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
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_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_LINES
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_LINES" with expressio...
void glBindBuffer(int target, int buffer)
Entry point to C language function: void {@native glBindBuffer}(GLenum target, GLuint buffer) Part...
void glBufferData(int target, long size, Buffer data, int usage)
Entry point to C language function: void {@native glBufferData}(GLenum target, GLsizeiptr size,...
static final int GL_ARRAY_BUFFER
GL_VERSION_1_5, GL_ES_VERSION_2_0, GL_VERSION_ES_1_0, GL_ARB_vertex_buffer_object Alias for: GL_ARRAY...
void setSize(int width, int height)
Requests a new width and height for this AWTGLAutoDrawable.
void glShadeModel(int mode)
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.
static final int GL_VERTEX_ARRAY
void glVertexPointer(GLArrayData array)