diff options
author | Sven Gothel <[email protected]> | 2001-02-23 05:20:21 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2001-02-23 05:20:21 +0000 |
commit | 86443be0a3795fa860850f0cf81ae7cc6843858d (patch) | |
tree | 2c03c1da3f6deb45eed12e7503821f73a504697f /gl4java | |
parent | 991622dd909d94b6ed83b84b744f0839b9ab6807 (diff) |
Version 2.6.0.0rel-2-6-0-0
Diffstat (limited to 'gl4java')
-rwxr-xr-x | gl4java/GLCapabilities.java | 313 | ||||
-rw-r--r-- | gl4java/drawable/DummyGLDrawableFactory.java | 39 | ||||
-rw-r--r-- | gl4java/drawable/GLDrawable.java | 73 | ||||
-rw-r--r-- | gl4java/drawable/GLDrawableFactory.java | 222 | ||||
-rw-r--r-- | gl4java/drawable/GLEventListener.java | 102 | ||||
-rw-r--r-- | gl4java/drawable/MacSunJDK13GLDrawableFactory.java | 23 | ||||
-rwxr-xr-x | gl4java/drawable/SunJDK13GLDrawableFactory.java | 74 | ||||
-rw-r--r-- | gl4java/drawable/Win32SunJDK13GLDrawableFactory.java | 327 | ||||
-rw-r--r-- | gl4java/drawable/Win32SunJDK13GLDrawableFactory.java-jau | 47 | ||||
-rw-r--r-- | gl4java/drawable/X11SunJDK13GLDrawableFactory.java | 45 | ||||
-rw-r--r-- | gl4java/drawable/utils/GLEventListenerList.java | 89 |
11 files changed, 1354 insertions, 0 deletions
diff --git a/gl4java/GLCapabilities.java b/gl4java/GLCapabilities.java new file mode 100755 index 0000000..f3beb79 --- /dev/null +++ b/gl4java/GLCapabilities.java @@ -0,0 +1,313 @@ +package gl4java;
+
+/** Specifies a set of OpenGL capabilities that a rendering context
+ must support, such as color depth and whether stereo is
+ enabled. It currently contains the minimal number of routines
+ which allow configuration on all supported window systems. */
+
+public class GLCapabilities
+ implements Cloneable
+{
+
+ private static final int BUFFER_SINGLE = 0;
+ private static final int BUFFER_DOUBLE = 1;
+
+ private static final int COLOR_INDEX = 0;
+ private static final int COLOR_RGBA = 1;
+
+ private static final int STEREO_OFF = 0;
+ private static final int STEREO_ON = 1;
+
+ // Boolean attributes
+ // NOTE that we do not specify on- or off-screen visuals here --
+ // that will be taken care of by the factory.
+
+ /* x11: exact value
+ w32: exact value
+ */
+ private int buffer = BUFFER_DOUBLE;
+
+ /* x11: exact value
+ w32: exact value
+ */
+ private int color = COLOR_RGBA;
+
+ /* x11: exact value
+ w32: exact value
+ */
+ private int stereo = STEREO_OFF;
+
+ /* x11: getting the largest regardless the value if >0, set to max
+ w32: getting the best from it's max
+ */
+ private int depthBits = 24;
+
+ /* x11: getting the best from it's max
+ w32: getting the best from it's max
+ */
+ private int stencilBits = 0;
+
+ /* x11: getting the largest regardless the value if >0, set to max
+
+ w32: getting the best from it's max
+ cColorBits := redBits + greenBits + blueBits
+ */
+ private int redBits = 8;
+ private int greenBits = 8;
+ private int blueBits = 8;
+ private int alphaBits = 0;
+
+ /* x11: getting the largest regardless the value if >0, set to max
+
+ w32: getting the best from it's max
+ cAccumBits := accumRedBits + accumGreenBits + accumBlueBits +
+ accumAlphaBits
+ */
+ private int accumRedBits = 0;
+ private int accumGreenBits = 0;
+ private int accumBlueBits = 0;
+ private int accumAlphaBits = 0;
+
+ /**
+ * this is the holder for the native visualID,
+ * e.g. Win32's number of the PIXELFORMATDESC,
+ * or X11's VisualID
+ */
+ private long nativeVisualID = -1;
+
+ // Shift bits from PIXELFORMATDESCRIPTOR not present because they
+ // are unlikely to be supported on Windows anyway
+
+ /** Creates a GLCapabilities object. All attributes are in
+ a default state, they can be configured by the client.
+ The arguments are the usual user defined capabilities,
+ which can be set here for construction.
+ */
+ public GLCapabilities(boolean doubleBuffer, boolean stereoView,
+ boolean rgba,
+ int stencilBits,
+ int accumRedSize, int accumGreenSize,
+ int accumBlueSize, int accumAlphaSize)
+ {
+ setDoubleBuffered(doubleBuffer);
+ setStereo(stereoView);
+ setTrueColor(rgba);
+ setStencilBits(stencilBits);
+ setAccumRedBits(accumRedSize);
+ setAccumGreenBits(accumGreenSize);
+ setAccumBlueBits(accumBlueSize);
+ setAccumAlphaBits(accumAlphaSize);
+ }
+
+ /** Creates a GLCapabilities object. All attributes are in
+ a default state, they can be configured by the client.
+ */
+ public GLCapabilities() {}
+
+ public Object clone()
+ throws CloneNotSupportedException
+ {
+ GLCapabilities nobj = new GLCapabilities();
+ nobj.buffer=buffer;
+ nobj.color=color;
+ nobj.stereo=stereo;
+ nobj.depthBits=depthBits;
+ nobj.stencilBits=stencilBits;
+ nobj.redBits=redBits;
+ nobj.greenBits=greenBits;
+ nobj.blueBits=blueBits;
+ nobj.alphaBits=alphaBits;
+ nobj.accumRedBits=accumRedBits;
+ nobj.accumGreenBits=accumGreenBits;
+ nobj.accumBlueBits=accumBlueBits;
+ nobj.accumAlphaBits=accumAlphaBits;
+ nobj.nativeVisualID=nativeVisualID;
+ return nobj;
+ }
+
+ /** Indicates whether double-buffering is enabled. */
+ public boolean getDoubleBuffered() { return buffer == BUFFER_DOUBLE; }
+
+ /** Indicates whether true color (as opposed to indexed color) is
+ enabled. */
+ public boolean getTrueColor() { return color == COLOR_RGBA; }
+
+ /** Indicates whether stereo is enabled. */
+ public boolean getStereo() { return stereo == STEREO_ON; }
+
+ /** Enables or disables double buffering. */
+ public void setDoubleBuffered(boolean onOrOff) {
+ buffer = (onOrOff ? BUFFER_DOUBLE : BUFFER_SINGLE);
+ }
+
+ /** Enables or disables true color (RGBA mode). */
+ public void setTrueColor(boolean onOrOff) {
+ color = (onOrOff ? COLOR_RGBA : COLOR_INDEX);
+ }
+
+ /** Enables or disables stereo viewing. */
+ public void setStereo(boolean onOrOff) {
+ stereo = (onOrOff ? STEREO_ON : STEREO_OFF);
+ }
+
+ /** Returns number of bits requested for depth buffer */
+ public int getDepthBits() { return depthBits; }
+
+ /** Sets number of bits requested for depth buffer */
+ public void setDepthBits(int depthBits) { this.depthBits = depthBits; }
+
+ /** Returns number of bits requested for stencil buffer */
+ public int getStencilBits() { return stencilBits; }
+
+ /** Sets number of bits requested for stencil buffer */
+ public void setStencilBits(int stencilBits) { this.stencilBits = stencilBits; }
+
+ /** Returns number of bits requested for color buffer's red
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public int getRedBits() { return redBits; }
+
+ /** Sets number of bits requested for color buffer's red
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public void setRedBits(int redBits) { this.redBits = redBits; }
+
+ /** Returns number of bits requested for color buffer's green
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public int getGreenBits() { return greenBits; }
+
+ /** Sets number of bits requested for color buffer's green
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public void setGreenBits(int greenBits) { this.greenBits = greenBits; }
+
+ /** Returns number of bits requested for color buffer's blue
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public int getBlueBits() { return blueBits; }
+
+ /** Sets number of bits requested for color buffer's blue
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public void setBlueBits(int blueBits) { this.blueBits = blueBits; }
+
+ /** Returns number of bits requested for color buffer's alpha
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public int getAlphaBits() { return alphaBits; }
+
+ /** Sets number of bits requested for color buffer's alpha
+ component. On some systems and in color index mode only the
+ color depth, which is the sum of the red, green, and blue bits,
+ is considered. */
+ public void setAlphaBits(int alphaBits) { this.alphaBits = alphaBits; }
+
+ /** Returns number of bits requested for accumulation buffer's red
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public int getAccumRedBits() { return accumRedBits; }
+
+ /** Sets number of bits requested for accumulation buffer's red
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public void setAccumRedBits(int accumRedBits) { this.accumRedBits = accumRedBits; }
+
+ /** Returns number of bits requested for accumulation buffer's green
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public int getAccumGreenBits() { return accumGreenBits; }
+
+ /** Sets number of bits requested for accumulation buffer's green
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public void setAccumGreenBits(int accumGreenBits) { this.accumGreenBits = accumGreenBits; }
+
+ /** Returns number of bits requested for accumulation buffer's blue
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public int getAccumBlueBits() { return accumBlueBits; }
+
+ /** Sets number of bits requested for accumulation buffer's blue
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public void setAccumBlueBits(int accumBlueBits) { this.accumBlueBits = accumBlueBits; }
+
+ /** Returns number of bits requested for accumulation buffer's alpha
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public int getAccumAlphaBits() { return accumAlphaBits; }
+
+ /** Sets number of bits requested for accumulation buffer's alpha
+ component. On some systems only the accumulation buffer depth,
+ which is the sum of the red, green, and blue bits, is
+ considered. */
+ public void setAccumAlphaBits(int accumAlphaBits) { this.accumAlphaBits = accumAlphaBits; }
+
+ /**
+ * Set the fetched native VisualID.
+ * This is an interface for the Factory and GLContext.
+ *
+ * Because the GLCapabilities are copied through
+ * the handling between the Factory and GLContext,
+ * you cannot missuse it ..
+ *
+ * this is the holder for the native visualID,
+ * e.g. Win32's number of the PIXELFORMATDESC,
+ * or X11's VisualID
+ */
+ public void setNativeVisualID(long id)
+ { nativeVisualID = id; }
+
+ /**
+ * Get the fetched native VisualID.
+ * This is an interface for the Factory and GLContext.
+ *
+ * this is the holder for the native visualID,
+ * e.g. Win32's number of the PIXELFORMATDESC,
+ * or X11's VisualID
+ */
+ public long getNativeVisualID()
+ { return nativeVisualID ; }
+
+
+ public String toString()
+ {
+ return "GLCapabilities ["+
+ "DoubleBuffer: "+buffer+", "+
+ "RGBA: "+ color+", "+
+ "Stereo: "+ stereo+",\n\t"+
+ "DepthSize: "+ depthBits+", "+
+ "StencilSize: "+ stencilBits+",\n\t"+
+ "Red: "+ redBits+", "+
+ "Green: "+ greenBits+", "+
+ "Blue: "+ blueBits+", "+
+ "Alpha: "+ alphaBits+",\n\t"+
+ "Red Accum: "+ accumRedBits+", "+
+ "Green Accum: "+ accumGreenBits+", "+
+ "Blue Accum: "+ accumBlueBits+", "+
+ "Alpha Accum: "+ accumAlphaBits+",\n\t"+
+ "NativeVisualID: "+nativeVisualID+
+ "] ";
+ }
+
+ public static void main( String args[] )
+ {
+ GLCapabilities glCaps = new GLCapabilities();
+ System.out.println("Default GLCapabilities:\n"+glCaps);
+ }
+}
diff --git a/gl4java/drawable/DummyGLDrawableFactory.java b/gl4java/drawable/DummyGLDrawableFactory.java new file mode 100644 index 0000000..0ba0429 --- /dev/null +++ b/gl4java/drawable/DummyGLDrawableFactory.java @@ -0,0 +1,39 @@ +package gl4java.drawable;
+
+import gl4java.*;
+import gl4java.awt.*;
+
+public class DummyGLDrawableFactory extends GLDrawableFactory {
+
+ DummyGLDrawableFactory() {
+ }
+
+ public GLAnimCanvas createGLAnimCanvas(GLCapabilities capabilities,
+ int width,
+ int height,
+ String glName,
+ String gluName)
+ {
+ GLCapabilities own = null;
+ try {
+ own = (GLCapabilities) capabilities.clone();
+ } catch (Exception ex) { System.out.println(ex); own=capabilities; }
+
+ return new GLAnimCanvas(own, width, height, glName, gluName);
+ }
+
+ public GLCanvas createGLCanvas(GLCapabilities capabilities,
+ int width,
+ int height,
+ String glName,
+ String gluName)
+ {
+ GLCapabilities own = null;
+ try {
+ own = (GLCapabilities) capabilities.clone();
+ } catch (Exception ex) { System.out.println(ex); own=capabilities; }
+
+ return new GLCanvas(own, width, height, glName, gluName);
+ }
+
+}
diff --git a/gl4java/drawable/GLDrawable.java b/gl4java/drawable/GLDrawable.java new file mode 100644 index 0000000..a0818c0 --- /dev/null +++ b/gl4java/drawable/GLDrawable.java @@ -0,0 +1,73 @@ +package gl4java.drawable;
+
+import java.awt.event.*;
+import java.util.EventListener;
+
+import gl4java.*;
+
+/** Abstracts common functionality among the OpenGL components such as
+ GLCanvas and GLJPanel. The GLDrawable/GLEventListener interfaces
+ allow client code to draw using OpenGL without subclassing. */
+
+public interface GLDrawable
+{
+ /** Add a GLEventListener to this drawable. If multiple listeners
+ are added to a given drawable, they are notified of events in an
+ arbitrary order. */
+ public void addGLEventListener(GLEventListener listener);
+
+ /** Remove a GLEventListener from this drawable. */
+ public void removeGLEventListener(GLEventListener listener);
+
+ /** Gets the GL functions used by this drawable. */
+ public GLFunc getGL();
+
+ /** Gets the GLU functions used by this drawable. */
+ public GLUFunc getGLU();
+
+ /**
+ * Used to return the created GLContext
+ */
+ public GLContext getGLContext();
+
+ /**
+ * the components listener's should be implemented also !
+ * since JDK 1.1
+ */
+ public void addComponentListener(ComponentListener l);
+ public void removeComponentListener(ComponentListener l);
+ public void addFocusListener(FocusListener l);
+ public void addKeyListener(KeyListener l);
+ public void removeFocusListener(FocusListener l);
+ public void addMouseListener(MouseListener l);
+ public void removeMouseListener(MouseListener l);
+ public void addMouseMotionListener(MouseMotionListener l);
+ public void removeMouseMotionListener(MouseMotionListener l);
+
+ /**
+ * JDK 1.2 the components listener's are left,
+ * because of JDK 1.1 compatibility
+ *
+ public void addInputMethodListener(InputMethodListener l);
+ public void removeInputMethodListener(InputMethodListener l);
+ */
+
+ /**
+ * JDK 1.3 the components listener's are left,
+ * because of JDK 1.1 compatibility
+ *
+ public void addHierarchyListener(HierarchyListener l);
+ public void removeHierarchyListener(HierarchyListener l);
+ public void addHierarchyBoundsListener(HierarchyBoundsListener l);
+ public void removeHierarchyBoundsListener(HierarchyBoundsListener l);
+ */
+
+
+ /**
+ * JDK 1.3 the listener's methods are left,
+ * because of JDK 1.1 compatibility
+ * since JDK 1.3, e.g. implemented within GLCanvas
+ *
+ public EventListener[] getListeners(Class listenerType);
+ */
+}
diff --git a/gl4java/drawable/GLDrawableFactory.java b/gl4java/drawable/GLDrawableFactory.java new file mode 100644 index 0000000..603cf37 --- /dev/null +++ b/gl4java/drawable/GLDrawableFactory.java @@ -0,0 +1,222 @@ +package gl4java.drawable;
+
+import java.awt.*;
+import gl4java.*;
+import gl4java.awt.*;
+import gl4java.swing.*;
+
+/** <P> Provides a VM- and OS-independent mechanism for creating
+ {@link gl4java.awt.GLAnimCanvas},
+ {@link gl4java.awt.GLCanvas},
+ {@link gl4java.swing.GLAnimJPanel}
+ and {@link gl4java.swing.GLJPanel}
+ objects. Most useful when used in conjunction with the {@link
+ gl4java.drawable.GLEventListener} model, where subclassing is not
+ required. </P>
+
+ <P> The {@link gl4java.GLCapabilities} objects passed in to the
+ various factory methods are used as a minimum specification for
+ the properties of the returned GLCanvas. The canvas will either
+ meet or exceed all of the integer properties such as color and
+ accumulation buffer depth and will match all of the boolean
+ properties such as enabling or disabling of stereo. The selection
+ algorithm in general attempts to select the most minimal window
+ type to meet the criteria, but is otherwise left loosely
+ specified.
+ </P>
+
+ <P> The implementing class of this abstract factory methods
+ does clone your given GLCapabilities. So your version is unchanged.
+ The GLContext's GLCapabilites instance is changed to
+ the used capabilities, so you can query GLContext's GLCapabilites!
+ </P>
+
+ <P> It is currently not possible to specify GLCapabilities for
+ lightweight components. </P>
+*/
+
+public abstract class GLDrawableFactory {
+
+ static {
+ GLContext.loadNativeLibraries(null, null, null);
+ }
+
+ private static GLDrawableFactory soleInstance;
+
+ /** Returns the sole instance of the GLCanvasFactory (singleton
+ pattern). */
+ public static GLDrawableFactory getFactory() {
+
+ GLContext.loadNativeLibraries(null, null, null);
+
+ String jvmVendor = GLContext.getJVMVendor();
+ boolean isIBMJvm = jvmVendor!=null && jvmVendor.indexOf("IBM")>=0 ;
+ boolean isMicrosoftJvm =
+ jvmVendor!=null && jvmVendor.indexOf("Microsoft")>=0 ;
+
+ if (soleInstance == null) {
+ if( GLContext.getJVMVersionMajor()>=2 ||
+ ( GLContext.getJVMVersionMajor()==1 &&
+ GLContext.getJVMVersionMinor()>=4
+ ) ||
+ ( GLContext.getJVMVersionMajor()==1 &&
+ GLContext.getJVMVersionMinor()>=3 &&
+ !isIBMJvm && !isMicrosoftJvm
+ )
+ )
+ {
+ String clazzName = null;
+
+ switch(GLContext.getNativeOSType())
+ {
+ case GLContext.OsWindoof:
+ clazzName =
+ "gl4java.drawable.Win32SunJDK13GLDrawableFactory";
+ break;
+ case GLContext.OsMac:
+ clazzName =
+ "gl4java.drawable.MacSunJDK13GLDrawableFactory";
+ break;
+ case GLContext.OsX11:
+ clazzName =
+ "gl4java.drawable.X11SunJDK13GLDrawableFactory";
+ break;
+ default:
+ System.out.println("GLDrawableFactory: Unsupported OS: "+
+ GLContext.getNativeOSName() + ", using DummyGLDrawableFactory");
+ }
+
+ if(clazzName!=null)
+ {
+ try {
+ soleInstance = (GLDrawableFactory)
+ Class.forName(clazzName).newInstance();
+ } catch (Exception ex) {
+ System.out.println("GLDrawableFactory: could not create instance of: "+ clazzName + ", using DummyGLDrawableFactory");
+ }
+ }
+ }
+
+ if( soleInstance == null )
+ {
+ soleInstance = new DummyGLDrawableFactory();
+ }
+ }
+ return soleInstance;
+ }
+
+ /** Create a new GLAnimCanvas given the specified GLCapabilities.
+
+ @param capabilities the requested set of OpenGL capabilities of
+ the canvas
+ @param width the canvas's initial width
+ @param height the canvas's initial height
+
+ @return a GLAnimCanvas supporting the set of specified capabilities,
+ or null if there was no matching visual */
+ public GLAnimCanvas createGLAnimCanvas(GLCapabilities capabilities,
+ int width,
+ int height)
+ {
+ return createGLAnimCanvas(capabilities, width, height, null, null);
+ }
+
+ /** Create a new GLAnimCanvas given the specified GLCapabilities.
+
+ @param capabilities the requested set of OpenGL capabilities of
+ the canvas
+ @param width the canvas's initial width
+ @param height the canvas's initial height
+ @param glName the name of the GLFunc implementation.
+ If null, the default class will be used
+ @param gluName the name of the GLUFunc implementation.
+ If null, the default class will be used
+
+ @return a GLAnimCanvas supporting the set of specified capabilities,
+ or null if there was no matching visual */
+ public abstract GLAnimCanvas createGLAnimCanvas(GLCapabilities capabilities,
+ int width,
+ int height,
+ String glName,
+ String gluName);
+
+ /** Create a new GLCanvas given the specified GLCapabilities.
+
+ @param capabilities the requested set of OpenGL capabilities of
+ the canvas
+ @param width the canvas's initial width
+ @param height the canvas's initial height
+
+ @return a GLCanvas supporting the set of specified capabilities,
+ or null if there was no matching visual */
+ public GLCanvas createGLCanvas(GLCapabilities capabilities,
+ int width,
+ int height)
+ {
+ return createGLCanvas(capabilities, width, height, null, null);
+ }
+
+ /** Create a new GLCanvas given the specified GLCapabilities.
+
+ @param capabilities the requested set of OpenGL capabilities of
+ the canvas
+ @param width the canvas's initial width
+ @param height the canvas's initial height
+ @param glName the name of the GLFunc implementation.
+ If null, the default class will be used
+ @param gluName the name of the GLUFunc implementation.
+ If null, the default class will be used
+
+ @return a GLCanvas supporting the set of specified capabilities,
+ or null if there was no matching visual */
+ public abstract GLCanvas createGLCanvas(GLCapabilities capabilities,
+ int width,
+ int height,
+ String glName,
+ String gluName);
+
+ /** Create a new GLAnimJPanel. */
+ public GLAnimJPanel createGLAnimJPanel() {
+ return new GLAnimJPanel();
+ }
+
+ /** Create a new GLAnimJPanel with the specified GL/GLU library names,
+ LayoutManager, and double buffering specification.
+
+ @param glName the name of the GLFunc implementation.
+ If null, the default class will be used
+ @param gluName the name of the GLUFunc implementation.
+ If null, the default class will be used
+ @param layout the layout manager
+ @param isDoubleBuffered indicates if double buffering should be used
+ */
+ public GLAnimJPanel createGLAnimJPanel(String glName,
+ String gluName,
+ LayoutManager layout,
+ boolean isDoubleBuffered) {
+ return new GLAnimJPanel(glName, gluName, layout, isDoubleBuffered);
+ }
+
+ /** Create a new GLJPanel. */
+ public GLJPanel createGLJPanel() {
+ return new GLJPanel();
+ }
+
+ /** Create a new GLJPanel with the specified GL/GLU library names,
+ LayoutManager, and double buffering specification.
+
+ @param glName the name of the GLFunc implementation.
+ If null, the default class will be used
+ @param gluName the name of the GLUFunc implementation.
+ If null, the default class will be used
+ @param layout the layout manager
+ @param isDoubleBuffered indicates if double buffering should be used
+ */
+ public GLJPanel createGLJPanel(String glName,
+ String gluName,
+ LayoutManager layout,
+ boolean isDoubleBuffered) {
+ return new GLJPanel(glName, gluName, layout, isDoubleBuffered);
+ }
+
+}
diff --git a/gl4java/drawable/GLEventListener.java b/gl4java/drawable/GLEventListener.java new file mode 100644 index 0000000..feb388d --- /dev/null +++ b/gl4java/drawable/GLEventListener.java @@ -0,0 +1,102 @@ +package gl4java.drawable;
+
+import gl4java.GLEnum;
+import gl4java.GLUEnum;
+
+/** Declares events which client code can handle to perform OpenGL
+ rendering into a GLDrawable without subclassing. */
+
+public interface GLEventListener
+ extends java.util.EventListener, GLEnum, GLUEnum
+{
+ /** Called by the drawable immediately after the OpenGL context is
+ initialized; the GLContext has already been made current when
+ this method is called. Can be used to perform one-time OpenGL
+ initialization such as setup of lights and display lists.
+
+ @see gl4java.awt.GLCanvas#init
+ @see gl4java.swing.GLJPanel#init
+ */
+ public void init(GLDrawable drawable);
+
+ /** Called by the drawable before initiate rendering by the client. At
+ the time this method is called, the duration for this frames
+ time consume is started.
+ After all GLEventListeners have been notified of a preDisplay event,
+ the drawable will continues with the
+ {@link gl4java.drawable.GLEventListener#display} event.
+
+ @see gl4java.awt.GLAnimCanvas#display
+ @see gl4java.awt.GLCanvas#display
+ @see gl4java.swing.GLJPanel#display
+ @see gl4java.drawable.GLEventListener#display
+ @see gl4java.drawable.GLEventListener#postDisplay
+ */
+ public void preDisplay(GLDrawable drawable);
+
+ /** Called by the drawable to initiate rendering by the client. At
+ the time this method is called, the drawable has already called
+ {@link gl4java.drawable.GLEventListener#preDisplay} and made
+ its associated GLContext current by a call to {@link
+ gl4java.GLContext#gljMakeCurrent}. After all GLEventListeners
+ have been notified of a display event, the drawable will swap
+ its buffers if necessary and then free its GLContext with a call
+ to {@link gl4java.GLContext#gljFree} and
+ and continues with the
+ {@link gl4java.drawable.GLEventListener#postDisplay} event.
+ So the GLContext is locked while the GLEventListeners
+ receives this display event.
+
+ @see gl4java.awt.GLAnimCanvas#display
+ @see gl4java.awt.GLCanvas#display
+ @see gl4java.swing.GLJPanel#display
+ @see gl4java.drawable.GLEventListener#preDisplay
+ @see gl4java.drawable.GLEventListener#postDisplay
+ */
+ public void display(GLDrawable drawable);
+
+ /** Called by the drawable after initiate rendering by the client. At
+ the time this method is called, the drawable has already called
+ {@link gl4java.drawable.GLEventListener#display}.
+ After all GLEventListeners
+ have been notified of a postDisplay event, the
+ duration for the consumed time is stopped.
+
+ @see gl4java.awt.GLAnimCanvas#display
+ @see gl4java.awt.GLCanvas#display
+ @see gl4java.swing.GLJPanel#display
+ @see gl4java.drawable.GLEventListener#preDisplay
+ @see gl4java.drawable.GLEventListener#display
+ @see gl4java.drawable.GLEventListener#postDisplay
+ */
+ public void postDisplay(GLDrawable drawable);
+
+ /** Called by the drawable if it wants to destroy itself.
+ Here you can clean up any OpenGL stuff (delete textures
+ or whatever) prior to actually deleting the OpenGL context.
+
+ @see gl4java.awt.GLCanvas#doCleanup
+ @see gl4java.swing.GLJPanel#doCleanup
+ */
+ public void cleanup(GLDrawable drawable);
+
+ /** Called by the drawable during the first repaint after the
+ component has been resized. The client can update the viewport
+ and view volume of the window appropriately, for example by a
+ call to {@link gl4java.GLFunc#glViewport}; note that for
+ convenience the component has already called {@link
+ gl4java.GLContext#gljResize}(width, height) and {@link
+ gl4java.GLFunc.glViewport}(0, 0, width, height) when this method
+ is called, so the client may not have to do anything in this
+ method. At the time this method is called, the drawable has
+ already made its associated GLContext current by a call to
+ {@link gl4java.GLContext#gljMakeCurrent}. After all
+ GLEventListeners have been notified of a reshape event, the
+ drawable will free its GLContext with a call to {@link
+ gl4java.GLContext#gljFree}.
+
+ @see gl4java.awt.GLCanvas#reshape
+ @see gl4java.swing.GLJPanel#reshape
+ */
+ public void reshape(GLDrawable drawable, int width, int height);
+}
diff --git a/gl4java/drawable/MacSunJDK13GLDrawableFactory.java b/gl4java/drawable/MacSunJDK13GLDrawableFactory.java new file mode 100644 index 0000000..7cf368d --- /dev/null +++ b/gl4java/drawable/MacSunJDK13GLDrawableFactory.java @@ -0,0 +1,23 @@ +package gl4java.drawable;
+
+import sun.awt.*;
+import gl4java.*;
+
+public class MacSunJDK13GLDrawableFactory
+ extends SunJDK13GLDrawableFactory
+{
+
+ public MacSunJDK13GLDrawableFactory() { }
+
+ public GraphicsConfiguration
+ getGraphicsConfiguration(GLCapabilities capabilities,
+ GraphicsDevice device)
+ {
+ return null;
+ }
+
+ // Needs to return an XVisualID which can be wrapped in an
+ // X11GraphicsConfig object
+ //public static native long glXChooseVisual(int screen,
+ // GLCapabilities capabilities);
+}
diff --git a/gl4java/drawable/SunJDK13GLDrawableFactory.java b/gl4java/drawable/SunJDK13GLDrawableFactory.java new file mode 100755 index 0000000..bc707d8 --- /dev/null +++ b/gl4java/drawable/SunJDK13GLDrawableFactory.java @@ -0,0 +1,74 @@ +package gl4java.drawable;
+
+import java.awt.*;
+import gl4java.*;
+import gl4java.awt.*;
+
+/** A GLDrawableFactory which works with Sun's JDK 1.3 or greater. */
+
+public abstract class SunJDK13GLDrawableFactory extends GLDrawableFactory {
+
+ public GLAnimCanvas createGLAnimCanvas(GLCapabilities capabilities,
+ int width,
+ int height,
+ String glName,
+ String gluName)
+ {
+ GLCapabilities own = null;
+ try {
+ own = (GLCapabilities) capabilities.clone();
+ } catch (Exception ex) { System.out.println(ex); own=capabilities; }
+
+ GraphicsConfiguration config = getGraphicsConfiguration(own);
+ if (config == null) {
+ return null;
+ }
+ return new GLAnimCanvas(config, own,
+ width, height, glName, gluName);
+ }
+
+ public GLCanvas createGLCanvas(GLCapabilities capabilities,
+ int width,
+ int height,
+ String glName,
+ String gluName)
+ {
+ GLCapabilities own = null;
+ try {
+ own = (GLCapabilities) capabilities.clone();
+ } catch (Exception ex) { System.out.println(ex); own=capabilities; }
+
+ GraphicsConfiguration config = getGraphicsConfiguration(own);
+ if (config == null) {
+ return null;
+ }
+ return new GLCanvas(config, own,
+ width, height, glName, gluName);
+ }
+
+ /** Returns the GraphicsConfiguration most closely matching the
+ specified set of GLCapabilities, or null if there was no
+ matching visual.
+
+ @param capabilities the requested set of OpenGL capabilities of
+ the canvas
+ @return a GraphicsConfiguration supporting the set of specified capabilities,
+ or null if there was no matching visual
+ */
+ public GraphicsConfiguration getGraphicsConfiguration
+ (GLCapabilities capabilities)
+ {
+ return getGraphicsConfiguration(capabilities,
+ GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ /** The choice of the GraphicsDevice is not yet exported to
+ clients. */
+ abstract GraphicsConfiguration
+ getGraphicsConfiguration(GLCapabilities capabilities,
+ GraphicsDevice device);
+}
diff --git a/gl4java/drawable/Win32SunJDK13GLDrawableFactory.java b/gl4java/drawable/Win32SunJDK13GLDrawableFactory.java new file mode 100644 index 0000000..da8fd93 --- /dev/null +++ b/gl4java/drawable/Win32SunJDK13GLDrawableFactory.java @@ -0,0 +1,327 @@ +package gl4java.drawable;
+
+import java.awt.*;
+import java.lang.reflect.*;
+import java.util.*;
+import sun.awt.*;
+import gl4java.*;
+
+public class Win32SunJDK13GLDrawableFactory
+ extends SunJDK13GLDrawableFactory
+{
+ // Use reflection to get access to internal methods in sun.awt.*
+ private static Method getMaxConfigsMethod;
+ private static Method getDefaultPixIDMethod;
+
+ static {
+ try {
+ getMaxConfigsMethod =
+ sun.awt.Win32GraphicsDevice.class.
+ getDeclaredMethod("getMaxConfigs",
+ new Class[] { Integer.TYPE });
+ getMaxConfigsMethod.setAccessible(true);
+
+ getDefaultPixIDMethod =
+ sun.awt.Win32GraphicsDevice.class.
+ getDeclaredMethod("getDefaultPixID",
+ new Class[] { Integer.TYPE });
+ getDefaultPixIDMethod.setAccessible(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new InternalError(e.toString());
+ }
+ }
+
+ public Win32SunJDK13GLDrawableFactory() {
+ // describeAllGraphicsConfigurations();
+ }
+
+ public GraphicsConfiguration
+ getGraphicsConfiguration(GLCapabilities capabilities,
+ GraphicsDevice device) {
+ // On Windows, ChoosePixelFormat does not work as desired; it
+ // shoehorns the given pixel format descriptor into what a
+ // particular window can render. Instead we enumerate all possible
+ // pixel formats for a given GraphicsDevice and try to find one
+ // matching the given capabilities. To do this we provide
+ // accessors which query the OpenGL-related properties of a
+ // GraphicsConfiguration. FIXME: should implement better selection
+ // algorithm; this one does not choose the most minimal.
+
+ Win32GraphicsConfig[] configs =
+ getAllGraphicsConfigurations((Win32GraphicsDevice) device);
+
+ int maxDepth = 0;
+ int maxColor = 0;
+ int maxStencil = 0;
+ int maxAccum = 0;
+
+ for (int i = 0; i < configs.length; i++) {
+ Win32GraphicsConfig config = configs[i];
+
+ if( ! getConfigSupportsOpenGL(config) )
+ continue;
+
+ if(getConfigDepthBits(config)>maxDepth) maxDepth=getConfigDepthBits(config);
+ if(getConfigColorBits(config)>maxColor) maxColor=getConfigColorBits(config);
+ if(getConfigStencilBits(config)>maxStencil) maxStencil=getConfigStencilBits(config);
+ if(getConfigAccumBits(config)>maxAccum) maxAccum=getConfigAccumBits(config);
+ }
+
+ if(maxDepth>24) maxDepth=24;
+
+ /** fall down to overall's maximum **/
+ if(capabilities.getDepthBits()>maxDepth) capabilities.setDepthBits(maxDepth);
+ if(capabilities.getStencilBits()>maxStencil) capabilities.setStencilBits(maxStencil);
+
+ if(getCapsColorBits(capabilities)>maxColor)
+ { capabilities.setRedBits(maxColor/3);
+ capabilities.setGreenBits(maxColor/3+maxColor%3);
+ capabilities.setBlueBits(maxColor/3);
+ }
+
+ if(getCapsAccumBits(capabilities)>maxAccum)
+ { capabilities.setAccumRedBits(maxAccum/3);
+ capabilities.setAccumGreenBits(maxAccum/3+maxAccum%3);
+ capabilities.setAccumBlueBits(maxAccum/3);
+ }
+
+ Win32GraphicsConfig config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config;
+
+ /* lets .. fall down .. individual .. */
+
+ /* general normals .. */
+ boolean tryit = false;
+ if(capabilities.getDepthBits()>24) { capabilities.setDepthBits(24); tryit=true; }
+ else if(capabilities.getDepthBits()>16) { capabilities.setDepthBits(16); tryit=true; }
+ if(getCapsColorBits(capabilities)>24)
+ { capabilities.setRedBits(8); capabilities.setGreenBits(8); capabilities.setBlueBits(8); tryit=true; }
+ if(capabilities.getAlphaBits()>8) { capabilities.setAlphaBits(8); tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* no stereo .. */
+ if(capabilities.getStereo()) { capabilities.setStereo(false); tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* stencil<=16 .. */
+ if(capabilities.getStencilBits()>16) { capabilities.setStencilBits(16); tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* accum rgb each <=16.. */
+ if(getCapsAccumBits(capabilities)>48)
+ { capabilities.setAccumRedBits(16); capabilities.setAccumGreenBits(16); capabilities.setAccumBlueBits(16);
+ tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* stencil<=8 .. */
+ if(capabilities.getStencilBits()>8) { capabilities.setStencilBits(8); tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* accum rgb each <=8.. */
+ if(getCapsAccumBits(capabilities)>24)
+ { capabilities.setAccumRedBits(8); capabilities.setAccumGreenBits(8); capabilities.setAccumBlueBits(8);
+ tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* stencil=0 .. */
+ if(capabilities.getStencilBits()>0) { capabilities.setStencilBits(0); tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ /* alpha=0 */
+ if(capabilities.getAlphaBits()>0) { capabilities.setAlphaBits(0); tryit=true; }
+ if(tryit) config = configsSupportsCapabilities(configs, capabilities, maxDepth);
+ if(config!=null) return config; tryit=false;
+
+ return null;
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ private Win32GraphicsConfig configsSupportsCapabilities(Win32GraphicsConfig[] configs,
+ GLCapabilities glCaps,
+ int maxDepth)
+ {
+ if(GLContext.gljNativeDebug)
+ {
+ System.out.println("---------------");
+ System.out.println("---------------");
+ System.out.println("---------------");
+ System.out.println("->check caps: "+glCaps);
+ System.out.println("---------------");
+ }
+ for (int i = 0; i < configs.length; i++) {
+ if (configSupportsCapabilities(configs[i], glCaps, maxDepth)) {
+ glCaps.setNativeVisualID( (long) configs[i].getVisual() );
+ return configs[i];
+ }
+ }
+ return null;
+ }
+
+ private Win32GraphicsConfig[]
+ getAllGraphicsConfigurations(Win32GraphicsDevice device)
+ {
+ try {
+ int max =
+ ((Integer) getMaxConfigsMethod.invoke(device,
+ new Object[] {
+ new Integer(device.getScreen())
+ })).intValue();
+ int defaultPixID =
+ ((Integer) getDefaultPixIDMethod.invoke(device,
+ new Object[] {
+ new Integer(device.getScreen())
+ })).intValue();
+ java.util.List l = new ArrayList(max);
+ if (defaultPixID == 0) {
+ // From Win32GraphicsDevice: workaround for failing GDI calls
+ l.add(Win32GraphicsConfig.getConfig(device, defaultPixID));
+ } else {
+ for (int i = 1; i <= max; i++) {
+ l.add(Win32GraphicsConfig.getConfig(device, i));
+ }
+ }
+ Win32GraphicsConfig[] configs = new Win32GraphicsConfig[l.size()];
+ l.toArray(configs);
+ return configs;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new InternalError(e.toString());
+ }
+ }
+
+ private boolean configSupportsCapabilities(Win32GraphicsConfig config,
+ GLCapabilities caps, int maxDepth)
+ {
+ boolean res = ( getConfigSupportsOpenGL(config)
+ && getConfigDoubleBuffered(config) == caps.getDoubleBuffered()
+ && caps.getTrueColor() == getConfigTrueColor(config)
+ && caps.getDepthBits() <= getConfigDepthBits(config)
+ && maxDepth >= getConfigDepthBits(config)
+ && caps.getStencilBits() <= getConfigStencilBits(config)
+ && (caps.getStereo() ? getConfigStereo(config):true)
+ && getCapsColorBits(caps) <= getConfigColorBits(config)
+ /* && caps.getAlphaBits() <= getConfigAlphaBits(config) N.A. */
+ && getCapsAccumBits(caps) <= getConfigAccumBits(config));
+
+ if(GLContext.gljNativeDebug)
+ {
+ System.out.println("->against config: ");
+ describeGraphicsConfiguration(config);
+ System.out.println("---------------");
+ System.out.println("result: "+res);
+ System.out.println("---------------");
+ }
+ return res;
+ }
+
+ private static int getCapsColorBits(GLCapabilities caps) {
+ return caps.getRedBits() + caps.getGreenBits() + caps.getBlueBits();
+ }
+
+ private static int getCapsAccumBits(GLCapabilities caps) {
+ return caps.getAccumRedBits() + caps.getAccumGreenBits() + caps.getAccumBlueBits();
+ }
+
+ private static boolean getConfigSupportsOpenGL(Win32GraphicsConfig config) {
+ return getVisualSupportsOpenGL(getScreen(config), config.getVisual());
+ }
+
+ private static boolean getConfigDoubleBuffered(Win32GraphicsConfig config) {
+ return getVisualDoubleBuffered(getScreen(config), config.getVisual());
+ }
+
+ private static boolean getConfigTrueColor(Win32GraphicsConfig config) {
+ return getVisualTrueColor(getScreen(config), config.getVisual());
+ }
+
+ private static boolean getConfigStereo(Win32GraphicsConfig config) {
+ return getVisualStereo(getScreen(config), config.getVisual());
+ }
+
+ private static int getConfigDepthBits(Win32GraphicsConfig config) {
+ return getVisualDepthBits(getScreen(config), config.getVisual());
+ }
+
+ private static int getConfigStencilBits(Win32GraphicsConfig config) {
+ return getVisualStencilBits(getScreen(config), config.getVisual());
+ }
+
+ private static int getConfigColorShiftBits(Win32GraphicsConfig config) {
+ return getVisualColorShiftBits(getScreen(config), config.getVisual());
+ }
+
+ private static int getConfigColorBits(Win32GraphicsConfig config) {
+ return getVisualColorBits(getScreen(config), config.getVisual());
+ }
+
+ private static int getConfigAlphaBits(Win32GraphicsConfig config) {
+ return getVisualAlphaBits(getScreen(config), config.getVisual());
+ }
+
+ private static int getConfigAccumBits(Win32GraphicsConfig config) {
+ return getVisualAccumBits(getScreen(config), config.getVisual());
+ }
+
+ private static int getScreen(Win32GraphicsConfig config) {
+ return ((Win32GraphicsDevice) config.getDevice()).getScreen();
+ }
+
+ // Native support routines that are not in GraphicsConfiguration or
+ // Win32GraphicsConfig. These are only necessary on Windows because
+ // X11's glXChooseVisual can implement getGraphicsConfiguration
+ // directly.
+ private static native boolean getVisualSupportsOpenGL (int screen, int pixelFormatIdx);
+ private static native boolean getVisualDoubleBuffered (int screen, int pixelFormatIdx);
+ private static native boolean getVisualTrueColor (int screen, int pixelFormatIdx);
+ private static native boolean getVisualStereo (int screen, int pixelFormatIdx);
+ private static native int getVisualDepthBits (int screen, int pixelFormatIdx);
+ private static native int getVisualStencilBits (int screen, int pixelFormatIdx);
+ private static native int getVisualColorShiftBits (int screen, int pixelFormatIdx);
+ private static native int getVisualColorBits (int screen, int pixelFormatIdx);
+ private static native int getVisualAlphaBits (int screen, int pixelFormatIdx);
+ private static native int getVisualAccumBits (int screen, int pixelFormatIdx);
+
+ // Debugging only
+ private void describeAllGraphicsConfigurations() {
+ Win32GraphicsConfig[] configs =
+ getAllGraphicsConfigurations(
+ (Win32GraphicsDevice)
+ GraphicsEnvironment.getLocalGraphicsEnvironment().
+ getDefaultScreenDevice()
+ );
+ System.err.println(configs.length + " graphics configurations found");
+ for (int i = 0; i < configs.length; i++) {
+ System.err.println(i + ".");
+ Win32GraphicsConfig config = configs[i];
+ describeGraphicsConfiguration(config);
+ System.err.println();
+ }
+ }
+
+ private void describeGraphicsConfiguration(Win32GraphicsConfig config)
+ {
+ boolean supportsOpenGL = getConfigSupportsOpenGL(config);
+ System.err.println(" SupportsOpenGL: " + supportsOpenGL);
+ if (supportsOpenGL) {
+ System.err.print(" DoubleBuffered: " + getConfigDoubleBuffered(config));
+ System.err.print(" TrueColor: " + getConfigTrueColor(config));
+ System.err.println(" Stereo: " + getConfigStereo(config));
+ System.err.print(" DepthBits: " + getConfigDepthBits(config));
+ System.err.println(" StencilBits: " + getConfigStencilBits(config));
+ System.err.print(" ColorBits: " + getConfigColorBits(config));
+ System.err.print(" AlphaBits: " + getConfigAlphaBits(config));
+ System.err.println(" AccumBits: " + getConfigAccumBits(config));
+ }
+ }
+}
diff --git a/gl4java/drawable/Win32SunJDK13GLDrawableFactory.java-jau b/gl4java/drawable/Win32SunJDK13GLDrawableFactory.java-jau new file mode 100644 index 0000000..c10572e --- /dev/null +++ b/gl4java/drawable/Win32SunJDK13GLDrawableFactory.java-jau @@ -0,0 +1,47 @@ +package gl4java.drawable;
+
+import java.awt.*;
+import java.lang.reflect.*;
+import java.util.*;
+import sun.awt.*;
+import gl4java.*;
+
+public class Win32SunJDK13GLDrawableFactory
+ extends SunJDK13GLDrawableFactory
+{
+ public Win32SunJDK13GLDrawableFactory() {
+ // describeAllGraphicsConfigurations();
+ }
+
+ public GraphicsConfiguration
+ getGraphicsConfiguration(GLCapabilities capabilities,
+ GraphicsDevice device) {
+ // On Windows, ChoosePixelFormat does not work as desired; it
+ // shoehorns the given pixel format descriptor into what a
+ // particular window can render. Instead we enumerate all possible
+ // pixel formats for a given GraphicsDevice and try to find one
+ // matching the given capabilities. To do this we provide
+ // accessors which query the OpenGL-related properties of a
+ // GraphicsConfiguration. FIXME: should implement better selection
+ // algorithm; this one does not choose the most minimal.
+
+ Win32GraphicsDevice w32Device = (Win32GraphicsDevice) device;
+ int screen = w32Device.getScreen();
+
+ int nPixelFormat = (int) ChoosePixelFormatNum (screen,
+ capabilities,
+ GLContext.gljNativeDebug);
+
+ return Win32GraphicsConfig.getConfig(w32Device, nPixelFormat);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ // Needs to return an PixelFormatNumber can be wrapped in an
+ // X11GraphicsConfig object
+ static native long ChoosePixelFormatNum (int screen,
+ GLCapabilities capabilities,
+ boolean verbose);
+}
diff --git a/gl4java/drawable/X11SunJDK13GLDrawableFactory.java b/gl4java/drawable/X11SunJDK13GLDrawableFactory.java new file mode 100644 index 0000000..0cdf40c --- /dev/null +++ b/gl4java/drawable/X11SunJDK13GLDrawableFactory.java @@ -0,0 +1,45 @@ +package gl4java.drawable;
+
+import java.awt.*;
+import sun.awt.*;
+import gl4java.*;
+
+public class X11SunJDK13GLDrawableFactory
+ extends SunJDK13GLDrawableFactory
+{
+
+ public X11SunJDK13GLDrawableFactory() { }
+
+ GraphicsConfiguration
+ getGraphicsConfiguration(GLCapabilities capabilities,
+ GraphicsDevice device)
+ {
+ // glXChooseVisual behaves as we want. We just need to fetch
+ // the screen and visual ID and call into native code, passing
+ // in all of the parameters from the GLCapabilities,
+ X11GraphicsDevice x11Dev = (X11GraphicsDevice) device;
+
+ // From the code, this is ":0.<screen>".
+ // It looks like the X Display this is associated with is
+ // acquired via XOpenDisplay(NULL). It doesn't look like it's
+ // necessary to call X11GraphicsDevice.getDisplay(), though if
+ // it is, that int return value can be cast to a Display*.
+ int screen = x11Dev.getScreen();
+ long display = x11Dev.getDisplay();
+ int visualID = (int) glXChooseVisualID (screen, display,
+ capabilities,
+ GLContext.gljNativeDebug);
+
+ capabilities.setNativeVisualID( (long)visualID );
+
+ // Check for invalid return value (what will it be?)
+ // if (visualID invalid) return null;
+ return X11GraphicsConfig.getConfig(x11Dev, visualID);
+ }
+
+ // Needs to return an XVisualID which can be wrapped in an
+ // X11GraphicsConfig object
+ static native long glXChooseVisualID (int screen, long display,
+ GLCapabilities capabilities,
+ boolean verbose);
+}
diff --git a/gl4java/drawable/utils/GLEventListenerList.java b/gl4java/drawable/utils/GLEventListenerList.java new file mode 100644 index 0000000..e63b6e7 --- /dev/null +++ b/gl4java/drawable/utils/GLEventListenerList.java @@ -0,0 +1,89 @@ +package gl4java.drawable.utils;
+
+import gl4java.drawable.GLDrawable;
+import gl4java.drawable.GLEventListener;
+import java.util.EventListener;
+
+/** Helper class for implementing a list of GLEventListeners. This is
+ only needed because we can not use the JDK 1.2 collection classes
+ since we have to be backward compatible with JDK 1.1. */
+
+public class GLEventListenerList {
+ private GLEventListener[] data = new GLEventListener[2];
+ private int nextFreeIdx = 0;
+
+ public GLEventListenerList() {
+ }
+
+ public void add(GLEventListener listener) {
+ if (nextFreeIdx == data.length) {
+ grow();
+ }
+ data[nextFreeIdx++] = listener;
+ }
+
+ public void remove(GLEventListener listener) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ if (data[i] == listener) {
+ for (int j = i; j < nextFreeIdx - 1; j++) {
+ data[j] = data[j+1];
+ }
+ data[nextFreeIdx - 1] = null;
+ --nextFreeIdx;
+ return;
+ }
+ }
+ }
+
+ public void sendInitEvent(GLDrawable from) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ data[i].init(from);
+ }
+ }
+
+ public void sendPreDisplayEvent(GLDrawable from) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ data[i].preDisplay(from);
+ }
+ }
+
+ public void sendDisplayEvent(GLDrawable from) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ data[i].display(from);
+ }
+ }
+
+ public void sendPostDisplayEvent(GLDrawable from) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ data[i].postDisplay(from);
+ }
+ }
+
+ public void sendCleanupEvent(GLDrawable from) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ data[i].cleanup(from);
+ }
+ }
+
+ public void sendReshapeEvent(GLDrawable from, int width, int height) {
+ for (int i = 0; i < nextFreeIdx; i++) {
+ data[i].reshape(from, width, height);
+ }
+ }
+
+ public EventListener[] getListeners()
+ {
+ GLEventListener[] _new = new GLEventListener[nextFreeIdx];
+ System.arraycopy(data, 0, _new, 0, nextFreeIdx);
+ return _new;
+ }
+
+ public int size()
+ { return nextFreeIdx; }
+
+ private void grow() {
+ GLEventListener[] newData = new GLEventListener[2 * data.length];
+ System.arraycopy(data, 0, newData, 0, data.length);
+ data = newData;
+ }
+}
|