Mac OS X port of the refactoring. Linux and Win32 fixes.

This commit is contained in:
Elias Naur 2005-02-23 11:11:08 +00:00
parent acbbf03fe6
commit 3085702a38
33 changed files with 1029 additions and 277 deletions

View file

@ -39,6 +39,13 @@ import java.awt.GraphicsEnvironment;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import java.awt.Point;
import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.HierarchyEvent;
import java.awt.event.ComponentListener;
import java.awt.event.HierarchyListener;
/**
* $Id$
* <p>
@ -47,8 +54,9 @@ import org.lwjgl.Sys;
* @version $Revision$
* @author $Author$
*/
public class AWTGLCanvas extends Canvas implements Drawable {
public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, HierarchyListener {
private final static AWTCanvasImplementation implementation;
private boolean update_context;
static {
Sys.initialize();
@ -59,7 +67,7 @@ public class AWTGLCanvas extends Canvas implements Drawable {
} else if (OS_NAME.startsWith("Windows")) {
class_name = "org.lwjgl.opengl.Win32CanvasImplementation";
} else if (OS_NAME.startsWith("Mac")) {
class_name = "org.lwjgl.opengl.DefaultCanvasImplementation";
class_name = "org.lwjgl.opengl.MacOSXCanvasImplementation";
} else
throw new IllegalStateException("The platform " + OS_NAME + " is not supported");
try {
@ -75,14 +83,20 @@ public class AWTGLCanvas extends Canvas implements Drawable {
}
/** The requested pixel format */
private final PeerInfo peer_info;
private final PixelFormat pixel_format;
/** The drawable to share context with */
private final Drawable drawable;
/** Context handle */
private PeerInfo peer_info;
private Context context;
private synchronized void setUpdate() {
update_context = true;
}
/**
* This method should only be called internally.
*/
@ -126,8 +140,9 @@ public class AWTGLCanvas extends Canvas implements Drawable {
*/
public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format, Drawable drawable) throws LWJGLException {
super(implementation.findConfiguration(device, pixel_format));
this.peer_info = implementation.createPeerInfo(this, pixel_format);
addHierarchyListener(this);
this.drawable = drawable;
this.pixel_format = pixel_format;
}
/* (non-Javadoc)
@ -188,6 +203,8 @@ public class AWTGLCanvas extends Canvas implements Drawable {
if (context != null) {
context.forceDestroy();
context = null;
peer_info.destroy();
peer_info = null;
}
} catch (LWJGLException e) {
throw new RuntimeException(e);
@ -202,12 +219,19 @@ public class AWTGLCanvas extends Canvas implements Drawable {
public final void paint(Graphics g) {
try {
if (peer_info == null)
this.peer_info = implementation.createPeerInfo(this, pixel_format);
peer_info.lockAndGetHandle();
try {
if (context == null)
context = new Context(peer_info, drawable != null ? drawable.getContext() : null);
if (context == null) {
this.context = new Context(peer_info, drawable != null ? drawable.getContext() : null);
}
if (!context.isCurrent())
context.makeCurrent();
if (update_context) {
context.update();
update_context = false;
}
paintGL();
} finally {
peer_info.unlock();
@ -223,4 +247,47 @@ public class AWTGLCanvas extends Canvas implements Drawable {
public void update(Graphics g) {
paint(g);
}
public void componentShown(ComponentEvent e) {
}
public void componentHidden(ComponentEvent e) {
}
public void componentResized(ComponentEvent e) {
setUpdate();
}
public void componentMoved(ComponentEvent e) {
setUpdate();
}
public void setLocation(int x, int y) {
super.setLocation(x, y);
setUpdate();
}
public void setLocation(Point p) {
super.setLocation(p);
setUpdate();
}
public void setSize(Dimension d) {
super.setSize(d);
setUpdate();
}
public void setSize(int width, int height) {
super.setSize(width, height);
setUpdate();
}
public void setBounds(int x, int y, int width, int height) {
super.setBounds(x, y, width, height);
setUpdate();
}
public void hierarchyChanged(HierarchyEvent e) {
setUpdate();
}
}

View file

@ -139,6 +139,15 @@ final class Context {
}
}
/**
* Update the context. Should be called whenever it's drawable is moved or resized
*/
public synchronized void update() {
if (destroyed)
throw new IllegalStateException("Context is destroyed");
implementation.update(getHandle());
}
/**
* Swap the buffers on the current context. Only valid for double-buffered contexts
*/
@ -168,6 +177,10 @@ final class Context {
GLContext.useContext(this);
}
ByteBuffer getHandle() {
return handle;
}
/**
* Query whether the context is current
*/

View file

@ -60,6 +60,11 @@ interface ContextImplementation {
*/
public void releaseCurrentContext() throws LWJGLException;
/**
* Update the context. Should be called whenever it's drawable is moved or resized
*/
public void update(ByteBuffer context_handle);
/**
* Query whether the context is current
*/

View file

@ -86,6 +86,7 @@ public final class Display {
private static boolean vsync;
/** A unique context object, so we can track different contexts between creates() and destroys() */
private static PeerInfo peer_info;
private static Context context;
private static boolean window_created = false;
@ -252,6 +253,13 @@ public final class Display {
}
private static void destroyWindow() {
try {
if (context.isCurrent())
Context.releaseCurrentContext();
} catch (LWJGLException e) {
Sys.log("Exception occurred while trying to release context");
}
if (!window_created)
throw new InternalError("Window already created");
// Automatically destroy keyboard, mouse, and controller
@ -583,7 +591,7 @@ public final class Display {
if (fullscreen)
switchDisplayMode();
try {
PeerInfo peer_info = display_impl.createPeerInfo(pixel_format);
peer_info = display_impl.createPeerInfo(pixel_format);
context = new Context(peer_info, shared_drawable != null ? shared_drawable.getContext() : null);
try {
createWindow();
@ -659,11 +667,11 @@ public final class Display {
private static void destroyContext() {
try {
context.forceDestroy();
peer_info.destroy();
} catch (LWJGLException e) {
throw new RuntimeException(e);
} finally {
context = null;
display_impl.destroyPeerInfo();
}
}

View file

@ -108,7 +108,7 @@ public interface DisplayImplementation {
*/
PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException;
void destroyPeerInfo();
// void destroyPeerInfo();
/**
* Updates the windows internal state. This must be called at least once per video frame
@ -221,11 +221,6 @@ public interface DisplayImplementation {
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException;
/**
* Destroy pbuffer
*/
public void destroyPbuffer(PeerInfo handle);
public void setPbufferAttrib(PeerInfo handle, int attrib, int value);
public void bindTexImageToPbuffer(PeerInfo handle, int buffer);

View file

@ -99,6 +99,9 @@ final class LinuxContextImplementation implements ContextImplementation {
}
private static native void nReleaseCurrentContext(ByteBuffer peer_info_handle) throws LWJGLException;
public void update(ByteBuffer context_handle) {
}
public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
LinuxDisplay.lockAWT();
try {

View file

@ -185,35 +185,10 @@ final class LinuxDisplay implements DisplayImplementation {
private static native boolean nIsDirty();
public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException {
lockAWT();
try {
incDisplay();
try {
GLContext.loadOpenGLLibrary();
try {
peer_info = new LinuxDisplayPeerInfo(pixel_format);
return peer_info;
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
}
} catch (LWJGLException e) {
decDisplay();
throw e;
}
} finally {
unlockAWT();
}
peer_info = new LinuxDisplayPeerInfo(pixel_format);
return peer_info;
}
public void destroyPeerInfo() {
lockAWT();
peer_info = null;
GLContext.unloadOpenGLLibrary();
decDisplay();
unlockAWT();
}
public void update() {
lockAWT();
nUpdate();
@ -432,33 +407,7 @@ final class LinuxDisplay implements DisplayImplementation {
public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException {
lockAWT();
try {
incDisplay();
try {
GLContext.loadOpenGLLibrary();
try {
PeerInfo peer_info = new LinuxPbufferPeerInfo(width, height, pixel_format);
return peer_info;
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
}
} catch (LWJGLException e) {
decDisplay();
throw e;
}
} finally {
unlockAWT();
}
}
public void destroyPbuffer(PeerInfo handle) {
lockAWT();
((LinuxPbufferPeerInfo)handle).destroy();
decDisplay();
GLContext.unloadOpenGLLibrary();
unlockAWT();
return new LinuxPbufferPeerInfo(width, height, pixel_format);
}
public void setPbufferAttrib(PeerInfo handle, int attrib, int value) {

View file

@ -47,7 +47,19 @@ final class LinuxDisplayPeerInfo extends LinuxPeerInfo {
public LinuxDisplayPeerInfo(PixelFormat pixel_format) throws LWJGLException {
LinuxDisplay.lockAWT();
try {
initDefaultPeerInfo(getHandle(), pixel_format);
LinuxDisplay.incDisplay();
try {
GLContext.loadOpenGLLibrary();
try {
initDefaultPeerInfo(getHandle(), pixel_format);
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
}
} catch (LWJGLException e) {
LinuxDisplay.decDisplay();
throw e;
}
} finally {
LinuxDisplay.unlockAWT();
}
@ -67,4 +79,12 @@ final class LinuxDisplayPeerInfo extends LinuxPeerInfo {
protected void doUnlock() throws LWJGLException {
// NO-OP
}
public void destroy() {
super.destroy();
LinuxDisplay.lockAWT();
GLContext.unloadOpenGLLibrary();
LinuxDisplay.decDisplay();
LinuxDisplay.unlockAWT();
}
}

View file

@ -45,12 +45,33 @@ import org.lwjgl.Sys;
*/
final class LinuxPbufferPeerInfo extends LinuxPeerInfo {
public LinuxPbufferPeerInfo(int width, int height, PixelFormat pixel_format) throws LWJGLException {
nInitHandle(getHandle(), width, height, pixel_format);
LinuxDisplay.lockAWT();
try {
LinuxDisplay.incDisplay();
try {
GLContext.loadOpenGLLibrary();
try {
nInitHandle(getHandle(), width, height, pixel_format);
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
}
} catch (LWJGLException e) {
LinuxDisplay.decDisplay();
throw e;
}
} finally {
LinuxDisplay.unlockAWT();
}
}
private static native void nInitHandle(ByteBuffer handle, int width, int height, PixelFormat pixel_format) throws LWJGLException;
public void destroy() {
LinuxDisplay.lockAWT();
nDestroy(getHandle());
LinuxDisplay.decDisplay();
GLContext.unloadOpenGLLibrary();
LinuxDisplay.unlockAWT();
}
private static native void nDestroy(ByteBuffer handle);

View file

@ -0,0 +1,57 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
final class MacOSXAWTGLCanvasPeerInfo extends MacOSXCanvasPeerInfo {
private final AWTGLCanvas canvas;
public MacOSXAWTGLCanvasPeerInfo(AWTGLCanvas canvas, PixelFormat pixel_format) throws LWJGLException {
super(pixel_format);
this.canvas = canvas;
}
protected void doLockAndInitHandle() throws LWJGLException {
initHandle(canvas);
}
}

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import org.lwjgl.LWJGLException;
import org.lwjgl.BufferUtils;
import java.awt.GraphicsDevice;
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.lang.reflect.Method;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
final class MacOSXCanvasImplementation implements AWTCanvasImplementation {
public PeerInfo createPeerInfo(AWTGLCanvas canvas, PixelFormat pixel_format) throws LWJGLException {
return new MacOSXAWTGLCanvasPeerInfo(canvas, pixel_format);
}
/**
* Find a proper GraphicsConfiguration from the given GraphicsDevice and PixelFormat.
*
* @return The GraphicsConfiguration corresponding to a visual that matches the pixel format.
*/
public GraphicsConfiguration findConfiguration(GraphicsDevice device, PixelFormat pixel_format) throws LWJGLException {
/*
* It seems like the best way is to simply return null
*/
return null;
}
}

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import java.awt.Canvas;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo {
private final AWTSurfaceLock awt_surface = new AWTSurfaceLock();
public MacOSXCanvasPeerInfo(PixelFormat pixel_format) throws LWJGLException {
super(pixel_format, true, true, false, true);
}
protected void initHandle(Canvas canvas) throws LWJGLException {
nInitHandle(awt_surface.lockAndGetHandle(canvas), getHandle());
}
private static native void nInitHandle(ByteBuffer surface_buffer, ByteBuffer peer_info_handle) throws LWJGLException;
protected void doUnlock() throws LWJGLException {
awt_surface.unlock();
}
}

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import org.lwjgl.LWJGLException;
import org.lwjgl.BufferUtils;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
final class MacOSXContextImplementation implements ContextImplementation {
private static PeerInfo getCurrentPeerInfo() {
return Context.getCurrentContext().getPeerInfo();
}
public ByteBuffer create(PeerInfo peer_info, ByteBuffer shared_context_handle) throws LWJGLException {
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try {
return nCreate(peer_handle, shared_context_handle);
} finally {
peer_info.unlock();
}
}
private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException;
public void swapBuffers() throws LWJGLException {
Context current_context = Context.getCurrentContext();
nSwapBuffers(current_context.getHandle());
}
private static native void nSwapBuffers(ByteBuffer context_handle) throws LWJGLException;
public void update(ByteBuffer context_handle) {
System.out.println("context_handle = " + context_handle);
nUpdate(context_handle);
}
private static native void nUpdate(ByteBuffer context_handle);
public void releaseCurrentContext() throws LWJGLException {
Context current_context = Context.getCurrentContext();
if (current_context != null)
clearDrawable(current_context.getHandle());
nReleaseCurrentContext();
}
private static native void nReleaseCurrentContext() throws LWJGLException;
private static native void clearDrawable(ByteBuffer handle) throws LWJGLException;
public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
try {
setView(peer_handle, handle);
nMakeCurrent(handle);
} finally {
peer_info.unlock();
}
}
private static native void setView(ByteBuffer peer_handle, ByteBuffer context_handle) throws LWJGLException;
private static native void nMakeCurrent(ByteBuffer context_handle) throws LWJGLException;
public boolean isCurrent(ByteBuffer handle) throws LWJGLException {
boolean result = nIsCurrent(handle);
return result;
}
private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException;
public void setVSync(boolean enabled) {
nSetVSync(Context.getCurrentContext().getHandle(), enabled);
}
private static native void nSetVSync(ByteBuffer context_handle, boolean enabled);
public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
nDestroy(handle);
}
private static native void nDestroy(ByteBuffer context_handle) throws LWJGLException;
}

View file

@ -95,7 +95,7 @@ final class MacOSXDisplay implements DisplayImplementation {
if (frame != null) {
if (MacOSXFrame.getDevice().getFullScreenWindow() == frame)
MacOSXFrame.getDevice().setFullScreenWindow(null);
setView(null);
// setView(null);
if (frame.isDisplayable())
frame.dispose();
frame = null;
@ -193,29 +193,35 @@ final class MacOSXDisplay implements DisplayImplementation {
return frame.syncIsActive();
}
public MacOSXFrame getFrame() {
return frame;
}
public boolean isDirty() {
return frame.getCanvas().syncIsDirty();
}
public native void setView(MacOSXGLCanvas canvas);
// public native void setView(MacOSXGLCanvas canvas);
// public native void swapBuffers();
// public native void makeCurrent() throws LWJGLException;
public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException {
throw new RuntimeException("Not supported yet");
return new MacOSXDisplayPeerInfo(pixel_format);
}
// public native void createContext(PixelFormat pixel_format) throws LWJGLException;
public native void destroyPeerInfo();
// public native void destroyPeerInfo();
// public native void destroyContext();
public void update() {
if (frame.syncShouldUpdateContext()) {
updateContext();
if (frame.getCanvas().syncShouldUpdateContext()) {
Display.getContext().update();
/* This is necessary to make sure the context won't "forget" about the view size */
GL11.glViewport(0, 0, frame.getCanvas().syncGetWidth(), frame.getCanvas().syncGetHeight());
}
if (frame.syncShouldWarpCursor()) {
warpCursor();
}
}
@ -240,7 +246,7 @@ final class MacOSXDisplay implements DisplayImplementation {
private native void updateContext();
public native void setVSyncEnabled(boolean sync);
// public native void setVSyncEnabled(boolean sync);
public void reshape(int x, int y, int width, int height) {
frame.resize(x, y, width, height);
@ -422,7 +428,7 @@ final class MacOSXDisplay implements DisplayImplementation {
public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException {
throw new RuntimeException("Not yet supported");
return new MacOSXPbufferPeerInfo(width, height, pixel_format);
}
/* public ByteBuffer createPbuffer(int width, int height, PixelFormat pixel_format,
@ -438,7 +444,6 @@ final class MacOSXDisplay implements DisplayImplementation {
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
*/
// public native void destroyPbuffer(ByteBuffer handle);
public native void destroyPbuffer(PeerInfo handle);
public void setPbufferAttrib(PeerInfo handle, int attrib, int value) {
throw new UnsupportedOperationException();

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import java.awt.Canvas;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
final class MacOSXDisplayPeerInfo extends MacOSXCanvasPeerInfo {
private boolean locked = false;
public MacOSXDisplayPeerInfo(PixelFormat pixel_format) throws LWJGLException {
super(pixel_format);
}
protected void doLockAndInitHandle() throws LWJGLException {
if (locked)
throw new RuntimeException("Already locked");
MacOSXFrame frame = ((MacOSXDisplay)Display.getImplementation()).getFrame();
if (frame != null) {
Canvas gl_canvas = frame.getCanvas();
initHandle(gl_canvas);
locked = true;
}
}
protected void doUnlock() throws LWJGLException {
if (locked) {
super.doUnlock();
locked = false;
}
}
}

View file

@ -57,10 +57,10 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
/* States */
private Rectangle bounds;
private boolean should_update;
private boolean active;
private boolean visible;
private boolean minimized;
private boolean should_warp_cursor;
MacOSXFrame(DisplayMode mode, java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException {
setResizable(false);
@ -160,8 +160,8 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
public void windowActivated(WindowEvent e) {
synchronized ( this ) {
should_update = true;
active = true;
should_warp_cursor = true;
}
}
@ -190,11 +190,11 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
return canvas;
}
public boolean syncShouldUpdateContext() {
public boolean syncShouldWarpCursor() {
boolean result;
synchronized ( this ) {
result = canvas.syncShouldUpdateContext() || should_update;
should_update = false;
result = should_warp_cursor;
should_warp_cursor = false;
}
return result;
}

View file

@ -42,8 +42,10 @@ import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
final class MacOSXGLCanvas extends Canvas implements ComponentListener {
final class MacOSXGLCanvas extends Canvas implements ComponentListener, HierarchyListener {
private int width;
private int height;
@ -68,7 +70,8 @@ final class MacOSXGLCanvas extends Canvas implements ComponentListener {
/* Input methods are not enabled in fullscreen anyway, so disable always */
enableInputMethods(false);
addComponentListener(this);
((MacOSXDisplay)Display.getImplementation()).setView(this);
addHierarchyListener(this);
// ((MacOSXDisplay)Display.getImplementation()).setView(this);
setUpdate();
}
@ -148,4 +151,8 @@ final class MacOSXGLCanvas extends Canvas implements ComponentListener {
super.setBounds(x, y, width, height);
setUpdate();
}
public void hierarchyChanged(HierarchyEvent e) {
setUpdate();
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
final class MacOSXPbufferPeerInfo extends MacOSXPeerInfo {
public MacOSXPbufferPeerInfo(int width, int height, PixelFormat pixel_format) throws LWJGLException {
super(pixel_format, false, false, true, false);
nCreate(getHandle(), width, height);
}
private static native void nCreate(ByteBuffer handle, int width, int height) throws LWJGLException;
public void destroy() {
nDestroy(getHandle());
}
private static native void nDestroy(ByteBuffer handle);
protected void doLockAndInitHandle() throws LWJGLException {
// NO-OP
}
protected void doUnlock() throws LWJGLException {
// NO-OP
}
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions 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 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import java.nio.IntBuffer;
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
abstract class MacOSXPeerInfo extends PeerInfo {
public MacOSXPeerInfo(PixelFormat pixel_format, boolean use_display_bpp, boolean support_window, boolean support_pbuffer, boolean double_buffered) throws LWJGLException {
super(createHandle());
choosePixelFormat(pixel_format, use_display_bpp, support_window, support_pbuffer, double_buffered);
}
private static native ByteBuffer createHandle();
private void choosePixelFormat(PixelFormat pixel_format, boolean use_display_bpp, boolean support_window, boolean support_pbuffer, boolean double_buffered) throws LWJGLException {
nChoosePixelFormat(getHandle(), pixel_format, use_display_bpp, support_window, support_pbuffer, double_buffered);
}
private static native void nChoosePixelFormat(ByteBuffer peer_info_handle, PixelFormat pixel_format, boolean use_display_bpp, boolean support_window, boolean support_pbuffer, boolean double_buffered) throws LWJGLException;
public void destroy() {
nDestroy(getHandle());
}
private static native void nDestroy(ByteBuffer handle);
}

View file

@ -247,7 +247,7 @@ public final class Pbuffer implements Drawable {
return;
try {
context.forceDestroy();
Display.getImplementation().destroyPbuffer(peer_info);
peer_info.destroy();
destroyed = true;
} catch (LWJGLException e) {
Sys.log("Exception occurred while destroying pbuffer: " + e);

View file

@ -85,4 +85,7 @@ abstract class PeerInfo {
protected final ByteBuffer getHandle() {
return handle;
}
public void destroy() {
}
}

View file

@ -70,6 +70,9 @@ final class Win32ContextImplementation implements ContextImplementation {
}
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
public void update(ByteBuffer context_handle) {
}
public void releaseCurrentContext() throws LWJGLException {
nReleaseCurrentContext();
}

View file

@ -73,21 +73,11 @@ final class Win32Display implements DisplayImplementation {
// public native void swapBuffers();
// public native void makeCurrent() throws LWJGLException;
public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException {
GLContext.loadOpenGLLibrary();
try {
peer_info = new Win32DisplayPeerInfo(pixel_format);
return peer_info;
} catch (LWJGLException e) {
GLContext.unloadOpenGLLibrary();
throw e;
}
peer_info = new Win32DisplayPeerInfo(pixel_format);
return peer_info;
}
// public native void createContext(PixelFormat pixel_format) throws LWJGLException;
// public native void destroyContext();
public void destroyPeerInfo() {
peer_info.destroy();
GLContext.unloadOpenGLLibrary();
}
public void update() {
nUpdate();
if (didMaximize()) {
@ -167,9 +157,6 @@ final class Win32Display implements DisplayImplementation {
IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
*/
public void destroyPbuffer(PeerInfo handle) {
((Win32PbufferPeerInfo)handle).destroy();
}
// public native void destroyPbuffer(ByteBuffer handle);
public void setPbufferAttrib(PeerInfo handle, int attrib, int value) {

View file

@ -45,11 +45,17 @@ import org.lwjgl.Sys;
*/
final class Win32DisplayPeerInfo extends Win32PeerInfo {
public Win32DisplayPeerInfo(PixelFormat pixel_format) throws LWJGLException {
createDummyDC(getHandle());
GLContext.loadOpenGLLibrary();
try {
choosePixelFormat(0, 0, pixel_format, null, true, true, false, true);
createDummyDC(getHandle());
try {
choosePixelFormat(0, 0, pixel_format, null, true, true, false, true);
} catch (LWJGLException e) {
nDestroy(getHandle());
throw e;
}
} catch (LWJGLException e) {
destroy();
GLContext.unloadOpenGLLibrary();
throw e;
}
}
@ -60,10 +66,6 @@ final class Win32DisplayPeerInfo extends Win32PeerInfo {
}
private static native void nInitDC(ByteBuffer peer_info_handle);
void destroy() {
nDestroy(getHandle());
}
private static native void nDestroy(ByteBuffer peer_info_handle);
protected void doLockAndInitHandle() throws LWJGLException {
@ -75,4 +77,10 @@ final class Win32DisplayPeerInfo extends Win32PeerInfo {
protected void doUnlock() throws LWJGLException {
// NO-OP
}
public void destroy() {
super.destroy();
nDestroy(getHandle());
GLContext.unloadOpenGLLibrary();
}
}