aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/com/sun/javafx/newt/GLWindow.java18
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/NewtFactory.java26
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/Window.java40
-rw-r--r--src/classes/com/sun/javafx/newt/awt/AWTWindow.java5
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/kd/KDDisplay.java60
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/kd/KDScreen.java46
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/kd/KDWindow.java172
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/macosx/MacWindow.java6
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/windows/WindowsWindow.java6
-rwxr-xr-xsrc/classes/com/sun/javafx/newt/x11/X11Window.java5
-rw-r--r--src/classes/com/sun/opengl/impl/egl/EGLConfig.java164
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLContext.java2
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLDrawable.java76
-rwxr-xr-xsrc/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java24
14 files changed, 549 insertions, 101 deletions
diff --git a/src/classes/com/sun/javafx/newt/GLWindow.java b/src/classes/com/sun/javafx/newt/GLWindow.java
index d66de7149..89886c24f 100644
--- a/src/classes/com/sun/javafx/newt/GLWindow.java
+++ b/src/classes/com/sun/javafx/newt/GLWindow.java
@@ -70,9 +70,8 @@ public class GLWindow extends Window implements GLAutoDrawable {
/** Constructor. Do not call this directly -- use {@link
create()} instead. */
- protected GLWindow(Window window, GLCapabilities caps) {
+ protected GLWindow(Window window) {
this.window = window;
- this.caps = caps;
window.addWindowListener(new WindowListener() {
public void windowResized(WindowEvent e) {
sendReshape = true;
@@ -115,16 +114,16 @@ public class GLWindow extends Window implements GLAutoDrawable {
public static GLWindow create(Window window,
GLCapabilities caps,
boolean undecorated) {
+ if (caps == null) {
+ caps = new GLCapabilities();
+ }
if (window == null) {
Display display = NewtFactory.createDisplay(null); // local display
Screen screen = NewtFactory.createScreen(display, 0); // screen 0
- window = NewtFactory.createWindow(screen, 0, undecorated); // dummy VisualID
- }
- if (caps == null) {
- caps = new GLCapabilities();
+ window = NewtFactory.createWindow(screen, caps, undecorated);
}
- return new GLWindow(window, caps);
+ return new GLWindow(window);
}
public boolean isTerminalObject() {
@@ -132,7 +131,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
return false;
}
- protected void createNative() {
+ protected void createNative(GLCapabilities caps) {
shouldNotCallThis();
}
@@ -236,7 +235,7 @@ public class GLWindow extends Window implements GLAutoDrawable {
window.setVisible(visible);
if (visible && context == null) {
factory = GLDrawableFactory.getFactory(window);
- drawable = factory.createGLDrawable(window, caps, null);
+ drawable = factory.createGLDrawable(window, window.getChosenCapabilities(), null);
window.setVisible(true);
drawable.setRealized(true);
context = drawable.createContext(null);
@@ -337,7 +336,6 @@ public class GLWindow extends Window implements GLAutoDrawable {
private int eventHandlerMode = EVENT_HANDLER_GL_CURRENT;
private GLDrawableFactory factory;
- private GLCapabilities caps;
private GLDrawable drawable;
private GLContext context;
private GLDrawableHelper helper = new GLDrawableHelper();
diff --git a/src/classes/com/sun/javafx/newt/NewtFactory.java b/src/classes/com/sun/javafx/newt/NewtFactory.java
index 4f2ecf569..d277fc65e 100755
--- a/src/classes/com/sun/javafx/newt/NewtFactory.java
+++ b/src/classes/com/sun/javafx/newt/NewtFactory.java
@@ -33,6 +33,7 @@
package com.sun.javafx.newt;
+import javax.media.opengl.GLCapabilities;
import java.util.ArrayList;
import java.util.Iterator;
@@ -54,10 +55,15 @@ public abstract class NewtFactory {
/** Creates a Window of the default type for the current operating system. */
public static String getWindowType() {
- String osName = System.getProperty("os.name");
+ String osName = System.getProperty("newt.ws.name");
+ if(null==osName||osName.length()==0) {
+ osName = System.getProperty("os.name");
+ }
String osNameLowerCase = osName.toLowerCase();
String windowType;
- if (osNameLowerCase.startsWith("wind")) {
+ if (osNameLowerCase.startsWith("kd")) {
+ windowType = KD;
+ } else if (osNameLowerCase.startsWith("wind")) {
windowType = WINDOWS;
} else if (osNameLowerCase.startsWith("mac os x")) {
// For the time being, use the AWT on Mac OS X since
@@ -103,19 +109,19 @@ public abstract class NewtFactory {
/**
* Create a Window entity, incl native creation
*/
- public static Window createWindow(Screen screen, long visualID) {
- return Window.create(getWindowType(), screen, visualID);
+ public static Window createWindow(Screen screen, GLCapabilities caps) {
+ return Window.create(getWindowType(), screen, caps);
}
- public static Window createWindow(Screen screen, long visualID, boolean undecorated) {
- return Window.create(getWindowType(), screen, visualID, undecorated);
+ public static Window createWindow(Screen screen, GLCapabilities caps, boolean undecorated) {
+ return Window.create(getWindowType(), screen, caps, undecorated);
}
/**
* Create a Window entity using the given implementation type, incl native creation
*/
- public static Window createWindow(String type, Screen screen, long visualID) {
- return Window.create(type, screen, visualID);
+ public static Window createWindow(String type, Screen screen, GLCapabilities caps) {
+ return Window.create(type, screen, caps);
}
/**
@@ -135,10 +141,10 @@ public abstract class NewtFactory {
/**
* Instantiate a Window entity using the native handle.
*/
- public static Window wrapWindow(Screen screen, long visualID,
+ public static Window wrapWindow(Screen screen, GLCapabilities caps, long visualID,
long windowHandle, boolean fullscreen, boolean visible,
int x, int y, int width, int height) {
- return Window.wrapHandle(getWindowType(), screen, visualID,
+ return Window.wrapHandle(getWindowType(), screen, caps, visualID,
windowHandle, fullscreen, visible, x, y, width, height);
}
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java
index 98f4eeeff..a2db7623b 100755
--- a/src/classes/com/sun/javafx/newt/Window.java
+++ b/src/classes/com/sun/javafx/newt/Window.java
@@ -33,6 +33,7 @@
package com.sun.javafx.newt;
+import javax.media.opengl.GLCapabilities;
import javax.media.opengl.NativeWindow;
import javax.media.opengl.NativeWindowException;
@@ -66,19 +67,19 @@ public abstract class Window implements NativeWindow
return windowClass;
}
- protected static Window create(String type, Screen screen, long visualID) {
- return create(type, screen, visualID, false);
+ protected static Window create(String type, Screen screen, GLCapabilities caps) {
+ return create(type, screen, caps, false);
}
- protected static Window create(String type, Screen screen, long visualID, boolean undecorated) {
+ protected static Window create(String type, Screen screen, GLCapabilities caps, boolean undecorated) {
try {
Class windowClass = getWindowClass(type);
Window window = (Window) windowClass.newInstance();
window.invalidate();
window.screen = screen;
- window.visualID = visualID;
+ window.visualID = 0;
window.setUndecorated(undecorated);
- window.createNative();
+ window.createNative(caps);
return window;
} catch (Throwable t) {
t.printStackTrace();
@@ -86,7 +87,7 @@ public abstract class Window implements NativeWindow
}
}
- protected static Window wrapHandle(String type, Screen screen, long visualID,
+ protected static Window wrapHandle(String type, Screen screen, GLCapabilities caps, long visualID,
long windowHandle, boolean fullscreen, boolean visible,
int x, int y, int width, int height)
{
@@ -95,6 +96,7 @@ public abstract class Window implements NativeWindow
Window window = (Window) windowClass.newInstance();
window.invalidate();
window.screen = screen;
+ window.chosenCaps = caps;
window.visualID = visualID;
window.windowHandle = windowHandle;
window.fullscreen=fullscreen;
@@ -113,9 +115,12 @@ public abstract class Window implements NativeWindow
public abstract boolean isTerminalObject();
/**
- * create native windowHandle, ie creates a new native invisible window
+ * Create native windowHandle, ie creates a new native invisible window
+ *
+ * Shall use the capabilities to determine the visualID
+ * and shall set chosenCaps.
*/
- protected abstract void createNative();
+ protected abstract void createNative(GLCapabilities caps);
protected abstract void closeNative();
@@ -154,11 +159,21 @@ public abstract class Window implements NativeWindow
", visible "+isVisible()+
", wrappedWindow "+getWrappedWindow()+
", terminalObject "+isTerminalObject()+
+ ", visualID "+visualID+
+ ", "+chosenCaps+
", screen handle/index "+getScreenHandle()+"/"+getScreenIndex() +
", display handle "+getDisplayHandle()+ "]";
}
protected Screen screen;
+
+ /**
+ * The GLCapabilities shall be used to determine the visualID
+ */
+ protected GLCapabilities chosenCaps;
+ /**
+ * The visualID shall be determined using the GLCapabilities
+ */
protected long visualID;
protected long windowHandle;
protected boolean locked=false;
@@ -223,6 +238,7 @@ public abstract class Window implements NativeWindow
unlockSurface();
screen = null;
visualID = 0;
+ chosenCaps = null;
windowHandle = 0;
locked = false;
fullscreen=false;
@@ -264,6 +280,14 @@ public abstract class Window implements NativeWindow
return windowHandle; // default: return window handle
}
+ public GLCapabilities getChosenCapabilities() {
+ if (chosenCaps == null)
+ return null;
+
+ // Must return a new copy to avoid mutation by end user
+ return (GLCapabilities) chosenCaps.clone();
+ }
+
public long getVisualID() {
return visualID;
}
diff --git a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java
index 6ec1622ac..07510e7a6 100644
--- a/src/classes/com/sun/javafx/newt/awt/AWTWindow.java
+++ b/src/classes/com/sun/javafx/newt/awt/AWTWindow.java
@@ -45,6 +45,7 @@ import java.lang.reflect.InvocationTargetException;
import java.awt.event.*;
import java.util.*;
import com.sun.javafx.newt.Window;
+import javax.media.opengl.GLCapabilities;
/** An implementation of the Newt Window class built using the
AWT. This is provided for convenience of porting to platforms
@@ -93,7 +94,9 @@ public class AWTWindow extends Window {
}
}
- protected void createNative() {
+ protected void createNative(GLCapabilities caps) {
+ chosenCaps = (GLCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
+ visualID = 0; // n/a
runOnEDT(new Runnable() {
public void run() {
frame = new Frame(getTitle());
diff --git a/src/classes/com/sun/javafx/newt/kd/KDDisplay.java b/src/classes/com/sun/javafx/newt/kd/KDDisplay.java
new file mode 100755
index 000000000..e919daacd
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/kd/KDDisplay.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.windows;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+import com.sun.opengl.impl.egl.*;
+import javax.media.opengl.GLException;
+
+public class KDDisplay extends Display {
+ static {
+ NativeLibLoader.loadNEWT();
+ }
+
+ public KDDisplay() {
+ }
+
+ protected void createNative() {
+ // FIXME: map name to EGL_*_DISPLAY
+ handle = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY);
+ if (handle == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("eglGetDisplay failed");
+ }
+ if (!EGL.eglInitialize(handle, null, null)) {
+ throw new GLException("eglInitialize failed");
+ }
+ }
+}
+
diff --git a/src/classes/com/sun/javafx/newt/kd/KDScreen.java b/src/classes/com/sun/javafx/newt/kd/KDScreen.java
new file mode 100755
index 000000000..2915b1161
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/kd/KDScreen.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.windows;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+
+public class KDScreen extends Screen {
+ public KDScreen() {
+ }
+
+ protected void createNative() {
+ handle = 0;
+ }
+}
diff --git a/src/classes/com/sun/javafx/newt/kd/KDWindow.java b/src/classes/com/sun/javafx/newt/kd/KDWindow.java
new file mode 100755
index 000000000..7cc4724bc
--- /dev/null
+++ b/src/classes/com/sun/javafx/newt/kd/KDWindow.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ */
+
+package com.sun.javafx.newt.kd;
+
+import com.sun.javafx.newt.*;
+import com.sun.opengl.impl.*;
+import com.sun.opengl.impl.egl.*;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.NativeWindowException;
+
+public class KDWindow extends Window {
+ private static final String WINDOW_CLASS_NAME = "NewtWindow";
+ // fullscreen size
+ // this will be correct _after_ setting fullscreen on,
+ // but KD has no method to ask for the display size
+ private int fs_width=800, fs_height=480;
+ // non fullscreen dimensions ..
+ private int nfs_width, nfs_height, nfs_x, nfs_y;
+
+ static {
+ NativeLibLoader.loadNEWT();
+
+ if (!initIDs()) {
+ throw new RuntimeException("Failed to initialize jmethodIDs");
+ }
+ }
+
+ public KDWindow() {
+ }
+
+ public final boolean isTerminalObject() {
+ return true;
+ }
+
+ protected void createNative(GLCapabilities caps) {
+ int eglRenderableType;
+ if(GLProfile.isGLES1()) {
+ eglRenderableType = EGL.EGL_OPENGL_ES_BIT;
+ }
+ else if(GLProfile.isGLES2()) {
+ eglRenderableType = EGL.EGL_OPENGL_ES2_BIT;
+ } else {
+ eglRenderableType = EGL.EGL_OPENGL_BIT;
+ }
+ EGLConfig config = new EGLConfig(getDisplayHandle(), caps);
+ visualID = config.getNativeConfigID();
+ chosenCaps = config.getCapabilities();
+
+ windowHandle = CreateWindow(getDisplayHandle(), visualID, eglRenderableType);
+ if (windowHandle == 0) {
+ throw new RuntimeException("Error creating window: "+windowHandle);
+ }
+ nativeWindowHandle = RealizeWindow(windowHandle);
+ if (nativeWindowHandle == 0) {
+ throw new RuntimeException("Error native Window Handle is null");
+ }
+
+ windowHandleClose = windowHandle;
+ }
+
+ protected void closeNative() {
+ if(0!=windowHandleClose) {
+ CloseWindow(windowHandleClose);
+ }
+ }
+
+ public void setVisible(boolean visible) {
+ if(this.visible!=visible) {
+ this.visible=visible;
+ setVisible0(windowHandle, visible);
+ clearEventMask();
+ }
+ }
+
+ public void setSize(int width, int height) {
+ setSize0(windowHandle, width, height);
+ }
+
+ public void setPosition(int x, int y) {
+ // n/a in KD
+ System.err.println("setPosition n/a in KD");
+ }
+
+ public boolean setFullscreen(boolean fullscreen) {
+ if(this.fullscreen!=fullscreen) {
+ this.fullscreen=fullscreen;
+ if(this.fullscreen) {
+ setFullScreen0(windowHandle, true);
+ } else {
+ setFullScreen0(windowHandle, false);
+ setSize0(windowHandle, nfs_width, nfs_height);
+ }
+ }
+ return true;
+ }
+
+ public int getDisplayWidth() {
+ return fs_width;
+ }
+
+ public int getDisplayHeight() {
+ return fs_height;
+ }
+
+ protected void dispatchMessages(int eventMask) {
+ DispatchMessages(windowHandle, eventMask);
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only
+ //
+
+ private static native boolean initIDs();
+ private native long CreateWindow(long displayHandle, long eglConfig, int eglRenderableType);
+ private native long RealizeWindow(long windowHandle);
+ private native int CloseWindow(long windowHandle);
+ private native void setVisible0(long windowHandle, boolean visible);
+ private native void setSize0(long windowHandle, int width, int height);
+ private native void setFullScreen0(long windowHandle, boolean fullscreen);
+ private native void DispatchMessages(long windowHandle, int eventMask);
+
+ private void sizeChanged(int newWidth, int newHeight) {
+ width = newWidth;
+ height = newHeight;
+ if(!fullscreen) {
+ nfs_width=width;
+ nfs_height=height;
+ } else {
+ fs_width = width;
+ fs_height = width;
+ }
+ sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED);
+ }
+
+ private void windowClosed() {
+ }
+
+ private long nativeWindowHandle; // THE KD underlying native window handle
+ private long windowHandleClose;
+}
diff --git a/src/classes/com/sun/javafx/newt/macosx/MacWindow.java b/src/classes/com/sun/javafx/newt/macosx/MacWindow.java
index cebd356c2..8427bb607 100755
--- a/src/classes/com/sun/javafx/newt/macosx/MacWindow.java
+++ b/src/classes/com/sun/javafx/newt/macosx/MacWindow.java
@@ -33,6 +33,8 @@
package com.sun.javafx.newt.macosx;
+import javax.media.opengl.GLCapabilities;
+
import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
@@ -51,7 +53,9 @@ public class MacWindow extends Window {
public MacWindow() {
}
- protected final void createNative() {
+ protected final void createNative(GLCapabilities caps) {
+ chosenCaps = (GLCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
+ visualID = 0; // n/a
}
protected final void closeNative() {
diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
index e520b8394..e1a1255ff 100755
--- a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
+++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java
@@ -33,6 +33,8 @@
package com.sun.javafx.newt.windows;
+import javax.media.opengl.GLCapabilities;
+
import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
@@ -64,8 +66,10 @@ public class WindowsWindow extends Window {
return hdc;
}
- protected void createNative() {
+ protected void createNative(GLCapabilities caps) {
long wndClass = getWindowClass();
+ chosenCaps = (GLCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
+ visualID = 0; // n/a
windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), visualID, x, y, width, height);
if (windowHandle == 0) {
throw new RuntimeException("Error creating window");
diff --git a/src/classes/com/sun/javafx/newt/x11/X11Window.java b/src/classes/com/sun/javafx/newt/x11/X11Window.java
index 395fad8c4..311ba7dae 100755
--- a/src/classes/com/sun/javafx/newt/x11/X11Window.java
+++ b/src/classes/com/sun/javafx/newt/x11/X11Window.java
@@ -35,6 +35,7 @@ package com.sun.javafx.newt.x11;
import com.sun.javafx.newt.*;
import com.sun.opengl.impl.*;
+import javax.media.opengl.GLCapabilities;
import javax.media.opengl.NativeWindowException;
public class X11Window extends Window {
@@ -57,7 +58,9 @@ public class X11Window extends Window {
return true;
}
- protected void createNative() {
+ protected void createNative(GLCapabilities caps) {
+ chosenCaps = (GLCapabilities) caps.clone(); // FIXME: visualID := f1(caps); caps := f2(visualID)
+ visualID = 0; // n/a
long w = CreateWindow(getDisplayHandle(), getScreenHandle(), getScreenIndex(), visualID, x, y, width, height);
if (w == 0 || w!=windowHandle) {
throw new RuntimeException("Error creating window: "+w);
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLConfig.java b/src/classes/com/sun/opengl/impl/egl/EGLConfig.java
new file mode 100644
index 000000000..0b33f91cc
--- /dev/null
+++ b/src/classes/com/sun/opengl/impl/egl/EGLConfig.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistribution in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of Sun Microsystems, Inc. or the names of
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
+ * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
+ * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
+ * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
+ * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
+ * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
+ * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
+ * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
+ * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ *
+ * Sun gratefully acknowledges that this software was originally authored
+ * and developed by Kenneth Bradley Russell and Christopher John Kline.
+ */
+
+package com.sun.opengl.impl.egl;
+
+import java.util.*;
+import javax.media.opengl.*;
+import com.sun.opengl.impl.*;
+import com.sun.gluegen.runtime.NativeLibrary;
+
+public class EGLConfig {
+
+ public _EGLConfig getNativeConfig() {
+ return _config;
+ }
+
+ public int getNativeConfigID() {
+ return configID;
+ }
+
+ public GLCapabilities getCapabilities() {
+ return capabilities;
+ }
+
+ public EGLConfig(long display, int configID) {
+ int[] attrs = new int[] {
+ EGL.EGL_RENDERABLE_TYPE, -1,
+ EGL.EGL_CONFIG_ID, configID,
+ EGL.EGL_NONE
+ };
+ if (GLProfile.isGLES2()) {
+ attrs[1] = EGL.EGL_OPENGL_ES2_BIT;
+ } else if (GLProfile.isGLES1()) {
+ attrs[1] = EGL.EGL_OPENGL_ES_BIT;
+ } else {
+ throw new GLException("Error creating EGL drawable - invalid GLProfile");
+ }
+ _EGLConfig[] configs = new _EGLConfig[1];
+ int[] numConfigs = new int[1];
+ if (!EGL.eglChooseConfig(display,
+ attrs, 0,
+ configs, 1,
+ numConfigs, 0)) {
+ throw new GLException("Graphics configuration selection (eglChooseConfig) failed");
+ }
+ if (numConfigs[0] == 0) {
+ throw new GLException("No valid graphics configuration selected from eglChooseConfig");
+ }
+ capabilities = new GLCapabilities();
+ setup(display, configID, configs[0]);
+ }
+
+ public EGLConfig(long display, GLCapabilities caps) {
+ int[] attrs = glCapabilities2AttribList(caps);
+ _EGLConfig[] configs = new _EGLConfig[1];
+ int[] numConfigs = new int[1];
+ if (!EGL.eglChooseConfig(display,
+ attrs, 0,
+ configs, 1,
+ numConfigs, 0)) {
+ throw new GLException("Graphics configuration selection (eglChooseConfig) failed");
+ }
+ if (numConfigs[0] == 0) {
+ throw new GLException("No valid graphics configuration selected from eglChooseConfig");
+ }
+ capabilities = (GLCapabilities)caps.clone();
+ setup(display, -1, configs[0]);
+ }
+
+ private void setup(long display, int setConfigID, _EGLConfig _config) {
+ this._config = _config;
+ int[] val = new int[1];
+ // get the configID
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_CONFIG_ID, val, 0)) {
+ configID = val[0];
+ if( setConfigID>=0 && setConfigID!=this.configID ) {
+ throw new GLException("EGL ConfigID mismatch, ask "+setConfigID+", got "+configID);
+ }
+ } else {
+ throw new GLException("EGL couldn't retrieve ConfigID");
+ }
+ // Read the actual configuration into the choosen caps
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_RED_SIZE, val, 0)) {
+ capabilities.setRedBits(val[0]);
+ }
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_GREEN_SIZE, val, 0)) {
+ capabilities.setGreenBits(val[0]);
+ }
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_BLUE_SIZE, val, 0)) {
+ capabilities.setBlueBits(val[0]);
+ }
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_ALPHA_SIZE, val, 0)) {
+ capabilities.setAlphaBits(val[0]);
+ }
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_STENCIL_SIZE, val, 0)) {
+ capabilities.setStencilBits(val[0]);
+ }
+ if(EGL.eglGetConfigAttrib(display, _config, EGL.EGL_DEPTH_SIZE, val, 0)) {
+ capabilities.setDepthBits(val[0]);
+ }
+ }
+
+ public static int[] glCapabilities2AttribList(GLCapabilities caps) {
+ int[] attrs = new int[] {
+ EGL.EGL_RENDERABLE_TYPE, -1,
+ // FIXME: does this need to be configurable?
+ EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT,
+ EGL.EGL_RED_SIZE, caps.getRedBits(),
+ EGL.EGL_GREEN_SIZE, caps.getGreenBits(),
+ EGL.EGL_BLUE_SIZE, caps.getBlueBits(),
+ EGL.EGL_ALPHA_SIZE, (caps.getAlphaBits() > 0 ? caps.getAlphaBits() : EGL.EGL_DONT_CARE),
+ EGL.EGL_STENCIL_SIZE, (caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE),
+ EGL.EGL_DEPTH_SIZE, caps.getDepthBits(),
+ EGL.EGL_NONE
+ };
+ if (GLProfile.isGLES2()) {
+ attrs[1] = EGL.EGL_OPENGL_ES2_BIT;
+ } else if (GLProfile.isGLES1()) {
+ attrs[1] = EGL.EGL_OPENGL_ES_BIT;
+ } else {
+ throw new GLException("Error creating EGL drawable - invalid GLProfile");
+ }
+
+ return attrs;
+ }
+
+ private _EGLConfig _config;
+ private int configID;
+ private GLCapabilities capabilities;
+
+}
+
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/classes/com/sun/opengl/impl/egl/EGLContext.java
index 2be9537b2..8ba07bc51 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLContext.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLContext.java
@@ -181,7 +181,7 @@ public class EGLContext extends GLContextImpl {
protected void create() throws GLException {
long display = drawable.getDisplay();
- _EGLConfig config = drawable.getConfig();
+ _EGLConfig config = drawable.getEGLConfig().getNativeConfig();
long shareWith = 0;
if (display == 0) {
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
index c18af5a89..77698f76d 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java
@@ -36,13 +36,14 @@
package com.sun.opengl.impl.egl;
import com.sun.opengl.impl.GLDrawableImpl;
+import com.sun.opengl.impl.GLReflection;
import javax.media.opengl.*;
public class EGLDrawable extends GLDrawableImpl {
private GLCapabilitiesChooser chooser;
private long display;
- private _EGLConfig config;
+ private EGLConfig config;
private long surface;
private int[] tmp = new int[1];
@@ -53,48 +54,35 @@ public class EGLDrawable extends GLDrawableImpl {
super(factory, component, false);
this.chooser = chooser;
surface=EGL.EGL_NO_SURFACE;
-
- display = EGL.eglGetDisplay((0!=component.getDisplayHandle())?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY);
- if (display == EGL.EGL_NO_DISPLAY) {
- throw new GLException("eglGetDisplay failed");
- }
- if (!EGL.eglInitialize(display, null, null)) {
- throw new GLException("eglInitialize failed");
- }
- int[] attrs = factory.glCapabilities2AttribList(capabilities);
- _EGLConfig[] configs = new _EGLConfig[1];
- int[] numConfigs = new int[1];
- if (!EGL.eglChooseConfig(display,
- attrs, 0,
- configs, 1,
- numConfigs, 0)) {
- throw new GLException("Graphics configuration selection (eglChooseConfig) failed");
- }
- if (numConfigs[0] == 0) {
- throw new GLException("No valid graphics configuration selected from eglChooseConfig");
- }
- config = configs[0];
- // Read the actual configuration into the choosen caps
- int[] val = new int[1];
- if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_RED_SIZE, val, 0)) {
- capabilities.setRedBits(val[0]);
- }
- if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_GREEN_SIZE, val, 0)) {
- capabilities.setGreenBits(val[0]);
- }
- if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_BLUE_SIZE, val, 0)) {
- capabilities.setBlueBits(val[0]);
- }
- if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_ALPHA_SIZE, val, 0)) {
- capabilities.setAlphaBits(val[0]);
- }
- if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_STENCIL_SIZE, val, 0)) {
- capabilities.setStencilBits(val[0]);
- }
- if(EGL.eglGetConfigAttrib(display, config, EGL.EGL_DEPTH_SIZE, val, 0)) {
- capabilities.setDepthBits(val[0]);
+ display=0;
+ config=null;
+
+ if( GLReflection.instanceOf(component, "com.sun.javafx.newt.kd.KDWindow") ) {
+ // KDWindows holds already determined EGL values
+ display = component.getDisplayHandle();
+ if(display==0) {
+ throw new GLException("KDWindow has null display");
+ }
+ if (display == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("KDWindow has EGL_NO_DISPLAY");
+ }
+ Long setConfigID = new Long(component.getVisualID());
+ if( 0 <= setConfigID.longValue() && setConfigID.longValue() <= Integer.MAX_VALUE ) {
+ config = new EGLConfig(display, setConfigID.intValue());
+ } else {
+ throw new GLException("KDWindow has invalid visualID/configID");
+ }
+ } else {
+ display = EGL.eglGetDisplay((0!=component.getDisplayHandle())?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY);
+ if (display == EGL.EGL_NO_DISPLAY) {
+ throw new GLException("eglGetDisplay failed");
+ }
+ if (!EGL.eglInitialize(display, null, null)) {
+ throw new GLException("eglInitialize failed");
+ }
+ config = new EGLConfig(display, capabilities);
}
- setChosenGLCapabilities(capabilities);
+ setChosenGLCapabilities(config.getCapabilities());
}
public long getDisplay() {
@@ -110,7 +98,7 @@ public class EGLDrawable extends GLDrawableImpl {
super.destroy();
}
- public _EGLConfig getConfig() {
+ public EGLConfig getEGLConfig() {
return config;
}
@@ -123,7 +111,7 @@ public class EGLDrawable extends GLDrawableImpl {
try {
lockSurface();
// Create the window surface
- surface = EGL.eglCreateWindowSurface(display, config, component.getWindowHandle(), null);
+ surface = EGL.eglCreateWindowSurface(display, config.getNativeConfig(), component.getWindowHandle(), null);
if (EGL.EGL_NO_SURFACE==surface) {
throw new GLException("Creation of window surface (eglCreateWindowSurface) failed, component: "+component);
}
diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
index 30665ce01..7f7c65a78 100755
--- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
+++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java
@@ -206,30 +206,6 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl {
return false;
}
- public int[] glCapabilities2AttribList(GLCapabilities caps) {
- int[] attrs = new int[] {
- EGL.EGL_RENDERABLE_TYPE, -1,
- // FIXME: does this need to be configurable?
- EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT,
- EGL.EGL_RED_SIZE, caps.getRedBits(),
- EGL.EGL_GREEN_SIZE, caps.getGreenBits(),
- EGL.EGL_BLUE_SIZE, caps.getBlueBits(),
- EGL.EGL_ALPHA_SIZE, (caps.getAlphaBits() > 0 ? caps.getAlphaBits() : EGL.EGL_DONT_CARE),
- EGL.EGL_STENCIL_SIZE, (caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE),
- EGL.EGL_DEPTH_SIZE, caps.getDepthBits(),
- EGL.EGL_NONE
- };
- if (GLProfile.isGLES2()) {
- attrs[1] = EGL.EGL_OPENGL_ES2_BIT;
- } else if (GLProfile.isGLES1()) {
- attrs[1] = EGL.EGL_OPENGL_ES_BIT;
- } else {
- throw new GLException("Error creating EGL drawable - invalid GLProfile");
- }
-
- return attrs;
- }
-
/*
// FIXME: this is the OpenGL ES 2 initialization order