diff options
Diffstat (limited to 'src/classes')
6 files changed, 255 insertions, 18 deletions
diff --git a/src/classes/com/sun/javafx/newt/Window.java b/src/classes/com/sun/javafx/newt/Window.java new file mode 100755 index 000000000..c9437a196 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/Window.java @@ -0,0 +1,94 @@ +/* + * 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; + +public abstract class Window { + /** OpenKODE window type */ + public static final String KD = "KD"; + + /** Microsoft Windows window type */ + public static final String WINDOWS = "Windows"; + + /** X11 window type */ + public static final String X11 = "X11"; + + /** Mac OS X window type */ + public static final String MACOSX = "MacOSX"; + + /** Creates a Window of the default type for the current operating system. */ + public static Window create() { + String osName = System.getProperty("os.name"); + String osNameLowerCase = osName.toLowerCase(); + String windowType; + if (osNameLowerCase.startsWith("wind")) { + windowType = WINDOWS; + } else if (osNameLowerCase.startsWith("mac os x")) { + windowType = MACOSX; + } else { + windowType = X11; + } + return create(windowType); + } + + + public static Window create(String type) { + try { + Class windowClass = null; + if (KD.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.kd.KDWindow"); + } else if (WINDOWS.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.windows.WindowsWindow"); + } else if (X11.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.x11.X11Window"); + } else if (MACOSX.equals(type)) { + windowClass = Class.forName("com.sun.javafx.newt.macosx.MacOSXWindow"); + } else { + throw new RuntimeException("Unknown window type \"" + type + "\""); + } + return (Window) windowClass.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected Window() { + } + + public abstract void setSize(int width, int height); + public abstract int getWidth(); + public abstract int getHeight(); + public abstract boolean setFullscreen(boolean fullscreen); + public abstract long getWindowHandle(); + public abstract void pumpMessages(); +} diff --git a/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java new file mode 100755 index 000000000..dfe423096 --- /dev/null +++ b/src/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -0,0 +1,136 @@ +/* + * 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 WindowsWindow extends Window { + private long window; + private static final String WINDOW_CLASS_NAME = "NewtWindow"; + // Default width and height -- will likely be re-set immediately by user + private int width = 100; + private int height = 100; + + static { + NativeLibLoader.loadCore(); + + if (!initIDs()) { + throw new RuntimeException("Failed to initialize jmethodIDs"); + } + } + + public WindowsWindow() { + long wndClass = getWindowClass(); + window = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), width, height); + if (window == 0) { + throw new RuntimeException("Error creating window"); + } + } + + public void setSize(int width, int height) { + setSize0(window, width, height); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public boolean setFullscreen(boolean fullscreen) { + return setFullScreen0(window, fullscreen); + } + + public long getWindowHandle() { + return window; + } + + public void pumpMessages() { + DispatchMessages(window); + } + + //---------------------------------------------------------------------- + // Internals only + // + + private static long windowClass; + private static synchronized long getWindowClass() { + if (windowClass == 0) { + windowClass = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); + if (windowClass == 0) { + throw new RuntimeException("Error while registering window class"); + } + } + return windowClass; + } + private static long hInstance; + private static synchronized long getHInstance() { + if (hInstance == 0) { + // FIXME: will require modification once this is moved into its own DLL ("newt") + hInstance = LoadLibraryW("jogl"); + if (hInstance == 0) { + throw new RuntimeException("Error finding HINSTANCE for \"jogl\""); + } + } + return hInstance; + } + + private static native boolean initIDs(); + private static native long LoadLibraryW(String libraryName); + private static native long RegisterWindowClass(String windowClassName, long hInstance); + private native long CreateWindow(String windowClassName, long hInstance, int width, int height); + private static native void DispatchMessages(long window); + private native void setSize0(long window, int width, int height); + private native boolean setFullScreen0(long window, boolean fullscreen); + + private void keyDown(long key) { + } + + private void keyUp(long key) { + } + + private void sizeChanged(int newWidth, int newHeight) { + width = newWidth; + height = newHeight; + } + + private void windowClosed() { + } + + private void windowDestroyed() { + } +} diff --git a/src/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/classes/com/sun/opengl/impl/egl/EGLContext.java index f55b611ca..25ac2c726 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLContext.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLContext.java @@ -123,11 +123,16 @@ public class EGLContext extends GLContextImpl { } EGLDrawableFactory factory = (EGLDrawableFactory) GLDrawableFactory.getFactory(); - int clientVersion = (EGLDrawableFactory.PROFILE_GLES2.equals(factory.getProfile()) ? 2 : 1); - int[] contextAttrs = new int[] { - EGL.EGL_CONTEXT_CLIENT_VERSION, clientVersion, - EGL.EGL_NONE - }; + boolean isGLES2 = EGLDrawableFactory.PROFILE_GLES2.equals(factory.getProfile()); + int[] contextAttrs = null; + // FIXME: need to determine whether to specify the context + // attributes based on the EGL version + if (isGLES2) { + contextAttrs = new int[] { + EGL.EGL_CONTEXT_CLIENT_VERSION, 2, + EGL.EGL_NONE + }; + } context = EGL.eglCreateContext(display, config, shareWith, contextAttrs, 0); if (context == 0) { throw new GLException("Error creating OpenGL context"); diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java index c9cc19913..49dea75ce 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -92,7 +92,7 @@ public class EGLDrawable implements GLDrawable { if (realized) { // Create the window surface surface = EGL.eglCreateWindowSurface(display, config, nativeWindow, null); - if (surface == 0) { + if (surface == EGL.EGL_NO_SURFACE) { throw new GLException("Creation of window surface (eglCreateWindowSurface) failed"); } } diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java index bbef9a54f..be594ce46 100755 --- a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -190,18 +190,7 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } public int[] glCapabilities2AttribList(GLCapabilities caps) { - int renderBit; - - if (PROFILE_GLES1.equals(getProfile())) { - renderBit = EGL.EGL_OPENGL_ES_BIT; - } else if (PROFILE_GLES2.equals(getProfile())) { - renderBit = EGL.EGL_OPENGL_ES2_BIT; - } else { - throw new GLException("Unknown profile \"" + getProfile() + "\" (expected OpenGL ES 1 or OpenGL ES 2)"); - } - - return new int[] { - EGL.EGL_RENDERABLE_TYPE, renderBit, + int[] attrs = new int[] { EGL.EGL_DEPTH_SIZE, caps.getDepthBits(), // FIXME: does this need to be configurable? EGL.EGL_SURFACE_TYPE, EGL.EGL_WINDOW_BIT, @@ -210,8 +199,19 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { EGL.EGL_BLUE_SIZE, caps.getBlueBits(), EGL.EGL_ALPHA_SIZE, caps.getAlphaBits(), EGL.EGL_STENCIL_SIZE, (caps.getStencilBits() > 0 ? caps.getStencilBits() : EGL.EGL_DONT_CARE), + EGL.EGL_NONE, EGL.EGL_NONE, EGL.EGL_NONE }; + + // FIXME: we need to query the EGL version to determine + // whether we are allowed to specify the renderable type + + if (PROFILE_GLES2.equals(getProfile())) { + attrs[attrs.length - 3] = EGL.EGL_RENDERABLE_TYPE; + attrs[attrs.length - 2] = EGL.EGL_OPENGL_ES2_BIT; + } + + return attrs; } /* diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java index 42727fc48..45b3e0dc4 100644 --- a/src/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/classes/javax/media/opengl/GLDrawableFactory.java @@ -104,7 +104,9 @@ public abstract class GLDrawableFactory { Class clazz = Class.forName("com.sun.opengl.impl.egl.EGLDrawableFactory"); Constructor c = clazz.getDeclaredConstructor(new Class[] { String.class }); factory = (GLDrawableFactory) c.newInstance(new Object[] { profile }); + return; } catch (Exception e) { + e.printStackTrace(); } } else if (!PROFILE_GL_20.equals(profile)) { // We require that the user passes in one of the known profiles |