1package com.jogamp.opengl.test.junit.jogl.acore;
3import java.awt.EventQueue;
4import java.awt.event.ActionEvent;
5import java.awt.event.ActionListener;
6import java.lang.reflect.InvocationTargetException;
7import java.util.concurrent.CountDownLatch;
8import java.util.concurrent.Executors;
9import java.util.concurrent.ScheduledExecutorService;
10import java.util.concurrent.TimeUnit;
12import javax.swing.Timer;
16import com.jogamp.common.os.Platform;
17import com.jogamp.common.util.InterruptSource;
18import com.jogamp.common.util.locks.LockFactory;
19import com.jogamp.common.util.locks.RecursiveLock;
20import com.jogamp.opengl.*;
21import com.jogamp.opengl.test.junit.util.DumpGLInfo;
32 static final int LATCH_COUNT = 5;
34 private void doTest(
final boolean aUseEDT)
throws Exception {
35 final CountDownLatch testLatch =
new CountDownLatch(1);
36 final CountDownLatch masterLatch =
new CountDownLatch(1);
37 final CountDownLatch slaveLatch =
new CountDownLatch(LATCH_COUNT);
38 final MyGLEventListener listener =
new MyGLEventListener(aUseEDT, slaveLatch);
45 final Runnable runnable =
new Runnable() {
47 System.err.println(
"Master Thread Start: "+Thread.currentThread().getName());
57 masterLatch.countDown();
62 }
catch (
final InterruptedException e) {
65 System.err.println(
"Master Thread End: "+Thread.currentThread().getName());
73 final Thread thread =
new InterruptSource.Thread(
null, runnable);
74 thread.setDaemon(
true);
76 masterLatch.await(3, TimeUnit.SECONDS);
79 slaveLatch.await(3, TimeUnit.SECONDS);
82 testLatch.countDown();
85 final Exception e = listener.fException;
107 final boolean fUseEDT;
108 final CountDownLatch fLatch;
109 final RecursiveLock masterLock = LockFactory.createRecursiveLock();
111 private Exception fException =
null;
113 public MyGLEventListener(
final boolean aUseEDT,
final CountDownLatch aLatch) {
127 System.err.println(); System.err.println();
128 System.err.println(
"Master (orig) Ct: "+drawable.
getContext());
131 System.err.println(); System.err.println();
132 System.err.println(
"External Context: "+master);
135 final Runnable initializer =
new Runnable() {
147 fOffscreenDrawable.
addGLEventListener(
new DumpGLInfo(Platform.getNewline()+Platform.getNewline()+
"Slave GLContext",
false,
false,
false));
150 System.err.println(); System.err.println();
182 EventQueue.invokeLater(initializer);
183 }
catch (
final Exception e) {
188 final Timer t =
new Timer(200,
new ActionListener() {
192 public void actionPerformed(
final ActionEvent e) {
193 if (++i > LATCH_COUNT) {
197 System.err.println(
"Update on EDT");
205 final ScheduledExecutorService exe = Executors.newSingleThreadScheduledExecutor();
206 exe.submit(initializer);
207 exe.scheduleAtFixedRate(
new Runnable() {
212 if (++i > LATCH_COUNT) {
216 System.err.println(
"Update on Executor thread");
220 }, 0, 200, TimeUnit.MILLISECONDS);
248 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
258 public static void main(
final String[] pArgs)
Specifies a set of OpenGL capabilities.
Abstraction for an OpenGL rendering context.
static GLContext getCurrent()
Returns this thread current context.
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...
abstract GLContext createExternalGLContext()
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
static AbstractGraphicsDevice getDefaultDevice()
static void main(final String[] pArgs)
void test02OnExecutorThread()
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
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.
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.
Platform-independent GLAutoDrawable specialization, exposing offscreen functionality.
void setSharedContext(GLContext sharedContext)
Specifies an OpenGL context, which shall be shared by this GLAutoDrawable's GLContext.
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_...