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

@ -576,7 +576,11 @@
<class name="org.lwjgl.opengl.Win32ContextImplementation" /> <class name="org.lwjgl.opengl.Win32ContextImplementation" />
</javah> </javah>
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx" force="yes"> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx" force="yes">
<class name="org.lwjgl.opengl.MacOSXCanvasPeerInfo" />
<class name="org.lwjgl.opengl.MacOSXPeerInfo" />
<class name="org.lwjgl.opengl.MacOSXPbufferPeerInfo" />
<class name="org.lwjgl.opengl.MacOSXDisplay" /> <class name="org.lwjgl.opengl.MacOSXDisplay" />
<class name="org.lwjgl.opengl.MacOSXContextImplementation" />
</javah> </javah>
<!-- lwjgl --> <!-- lwjgl -->
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes"> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">

View File

@ -39,6 +39,13 @@ import java.awt.GraphicsEnvironment;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.Sys; 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$ * $Id$
* <p> * <p>
@ -47,8 +54,9 @@ import org.lwjgl.Sys;
* @version $Revision$ * @version $Revision$
* @author $Author$ * @author $Author$
*/ */
public class AWTGLCanvas extends Canvas implements Drawable { public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, HierarchyListener {
private final static AWTCanvasImplementation implementation; private final static AWTCanvasImplementation implementation;
private boolean update_context;
static { static {
Sys.initialize(); Sys.initialize();
@ -59,7 +67,7 @@ public class AWTGLCanvas extends Canvas implements Drawable {
} else if (OS_NAME.startsWith("Windows")) { } else if (OS_NAME.startsWith("Windows")) {
class_name = "org.lwjgl.opengl.Win32CanvasImplementation"; class_name = "org.lwjgl.opengl.Win32CanvasImplementation";
} else if (OS_NAME.startsWith("Mac")) { } else if (OS_NAME.startsWith("Mac")) {
class_name = "org.lwjgl.opengl.DefaultCanvasImplementation"; class_name = "org.lwjgl.opengl.MacOSXCanvasImplementation";
} else } else
throw new IllegalStateException("The platform " + OS_NAME + " is not supported"); throw new IllegalStateException("The platform " + OS_NAME + " is not supported");
try { try {
@ -75,14 +83,20 @@ public class AWTGLCanvas extends Canvas implements Drawable {
} }
/** The requested pixel format */ /** The requested pixel format */
private final PeerInfo peer_info; private final PixelFormat pixel_format;
/** The drawable to share context with */ /** The drawable to share context with */
private final Drawable drawable; private final Drawable drawable;
/** Context handle */ /** Context handle */
private PeerInfo peer_info;
private Context context; private Context context;
private synchronized void setUpdate() {
update_context = true;
}
/** /**
* This method should only be called internally. * 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 { public AWTGLCanvas(GraphicsDevice device, PixelFormat pixel_format, Drawable drawable) throws LWJGLException {
super(implementation.findConfiguration(device, pixel_format)); super(implementation.findConfiguration(device, pixel_format));
this.peer_info = implementation.createPeerInfo(this, pixel_format); addHierarchyListener(this);
this.drawable = drawable; this.drawable = drawable;
this.pixel_format = pixel_format;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -188,6 +203,8 @@ public class AWTGLCanvas extends Canvas implements Drawable {
if (context != null) { if (context != null) {
context.forceDestroy(); context.forceDestroy();
context = null; context = null;
peer_info.destroy();
peer_info = null;
} }
} catch (LWJGLException e) { } catch (LWJGLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -202,12 +219,19 @@ public class AWTGLCanvas extends Canvas implements Drawable {
public final void paint(Graphics g) { public final void paint(Graphics g) {
try { try {
if (peer_info == null)
this.peer_info = implementation.createPeerInfo(this, pixel_format);
peer_info.lockAndGetHandle(); peer_info.lockAndGetHandle();
try { try {
if (context == null) if (context == null) {
context = new Context(peer_info, drawable != null ? drawable.getContext() : null); this.context = new Context(peer_info, drawable != null ? drawable.getContext() : null);
}
if (!context.isCurrent()) if (!context.isCurrent())
context.makeCurrent(); context.makeCurrent();
if (update_context) {
context.update();
update_context = false;
}
paintGL(); paintGL();
} finally { } finally {
peer_info.unlock(); peer_info.unlock();
@ -223,4 +247,47 @@ public class AWTGLCanvas extends Canvas implements Drawable {
public void update(Graphics g) { public void update(Graphics g) {
paint(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 * Swap the buffers on the current context. Only valid for double-buffered contexts
*/ */
@ -168,6 +177,10 @@ final class Context {
GLContext.useContext(this); GLContext.useContext(this);
} }
ByteBuffer getHandle() {
return handle;
}
/** /**
* Query whether the context is current * Query whether the context is current
*/ */

View File

@ -60,6 +60,11 @@ interface ContextImplementation {
*/ */
public void releaseCurrentContext() throws LWJGLException; 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 * Query whether the context is current
*/ */

View File

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

View File

@ -108,7 +108,7 @@ public interface DisplayImplementation {
*/ */
PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException; 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 * 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 pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException; IntBuffer pBufferAttribs) throws LWJGLException;
/**
* Destroy pbuffer
*/
public void destroyPbuffer(PeerInfo handle);
public void setPbufferAttrib(PeerInfo handle, int attrib, int value); public void setPbufferAttrib(PeerInfo handle, int attrib, int value);
public void bindTexImageToPbuffer(PeerInfo handle, int buffer); 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; 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 { public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
LinuxDisplay.lockAWT(); LinuxDisplay.lockAWT();
try { try {

View File

@ -185,35 +185,10 @@ final class LinuxDisplay implements DisplayImplementation {
private static native boolean nIsDirty(); private static native boolean nIsDirty();
public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException { public PeerInfo createPeerInfo(PixelFormat pixel_format) throws LWJGLException {
lockAWT(); peer_info = new LinuxDisplayPeerInfo(pixel_format);
try { return peer_info;
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();
}
} }
public void destroyPeerInfo() {
lockAWT();
peer_info = null;
GLContext.unloadOpenGLLibrary();
decDisplay();
unlockAWT();
}
public void update() { public void update() {
lockAWT(); lockAWT();
nUpdate(); nUpdate();
@ -432,33 +407,7 @@ final class LinuxDisplay implements DisplayImplementation {
public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format, public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps, IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException { IntBuffer pBufferAttribs) throws LWJGLException {
lockAWT(); return new LinuxPbufferPeerInfo(width, height, pixel_format);
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();
} }
public void setPbufferAttrib(PeerInfo handle, int attrib, int value) { 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 { public LinuxDisplayPeerInfo(PixelFormat pixel_format) throws LWJGLException {
LinuxDisplay.lockAWT(); LinuxDisplay.lockAWT();
try { 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 { } finally {
LinuxDisplay.unlockAWT(); LinuxDisplay.unlockAWT();
} }
@ -67,4 +79,12 @@ final class LinuxDisplayPeerInfo extends LinuxPeerInfo {
protected void doUnlock() throws LWJGLException { protected void doUnlock() throws LWJGLException {
// NO-OP // 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 { final class LinuxPbufferPeerInfo extends LinuxPeerInfo {
public LinuxPbufferPeerInfo(int width, int height, PixelFormat pixel_format) throws LWJGLException { 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; private static native void nInitHandle(ByteBuffer handle, int width, int height, PixelFormat pixel_format) throws LWJGLException;
public void destroy() { public void destroy() {
LinuxDisplay.lockAWT();
nDestroy(getHandle()); nDestroy(getHandle());
LinuxDisplay.decDisplay();
GLContext.unloadOpenGLLibrary();
LinuxDisplay.unlockAWT();
} }
private static native void nDestroy(ByteBuffer handle); 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 (frame != null) {
if (MacOSXFrame.getDevice().getFullScreenWindow() == frame) if (MacOSXFrame.getDevice().getFullScreenWindow() == frame)
MacOSXFrame.getDevice().setFullScreenWindow(null); MacOSXFrame.getDevice().setFullScreenWindow(null);
setView(null); // setView(null);
if (frame.isDisplayable()) if (frame.isDisplayable())
frame.dispose(); frame.dispose();
frame = null; frame = null;
@ -193,29 +193,35 @@ final class MacOSXDisplay implements DisplayImplementation {
return frame.syncIsActive(); return frame.syncIsActive();
} }
public MacOSXFrame getFrame() {
return frame;
}
public boolean isDirty() { public boolean isDirty() {
return frame.getCanvas().syncIsDirty(); return frame.getCanvas().syncIsDirty();
} }
public native void setView(MacOSXGLCanvas canvas); // public native void setView(MacOSXGLCanvas canvas);
// public native void swapBuffers(); // public native void swapBuffers();
// public native void makeCurrent() throws LWJGLException; // public native void makeCurrent() throws LWJGLException;
public PeerInfo createPeerInfo(PixelFormat pixel_format) 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 createContext(PixelFormat pixel_format) throws LWJGLException;
public native void destroyPeerInfo(); // public native void destroyPeerInfo();
// public native void destroyContext(); // public native void destroyContext();
public void update() { public void update() {
if (frame.syncShouldUpdateContext()) { if (frame.getCanvas().syncShouldUpdateContext()) {
updateContext(); Display.getContext().update();
/* This is necessary to make sure the context won't "forget" about the view size */ /* 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()); GL11.glViewport(0, 0, frame.getCanvas().syncGetWidth(), frame.getCanvas().syncGetHeight());
}
if (frame.syncShouldWarpCursor()) {
warpCursor(); warpCursor();
} }
} }
@ -240,7 +246,7 @@ final class MacOSXDisplay implements DisplayImplementation {
private native void updateContext(); 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) { public void reshape(int x, int y, int width, int height) {
frame.resize(x, y, width, 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, public PeerInfo createPbuffer(int width, int height, PixelFormat pixel_format,
IntBuffer pixelFormatCaps, IntBuffer pixelFormatCaps,
IntBuffer pBufferAttribs) throws LWJGLException { 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, /* 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; IntBuffer pBufferAttribs, ByteBuffer shared_pbuffer_handle) throws LWJGLException;
*/ */
// public native void destroyPbuffer(ByteBuffer handle); // public native void destroyPbuffer(ByteBuffer handle);
public native void destroyPbuffer(PeerInfo handle);
public void setPbufferAttrib(PeerInfo handle, int attrib, int value) { public void setPbufferAttrib(PeerInfo handle, int attrib, int value) {
throw new UnsupportedOperationException(); 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 */ /* States */
private Rectangle bounds; private Rectangle bounds;
private boolean should_update;
private boolean active; private boolean active;
private boolean visible; private boolean visible;
private boolean minimized; private boolean minimized;
private boolean should_warp_cursor;
MacOSXFrame(DisplayMode mode, java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException { MacOSXFrame(DisplayMode mode, java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException {
setResizable(false); setResizable(false);
@ -160,8 +160,8 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
public void windowActivated(WindowEvent e) { public void windowActivated(WindowEvent e) {
synchronized ( this ) { synchronized ( this ) {
should_update = true;
active = true; active = true;
should_warp_cursor = true;
} }
} }
@ -190,11 +190,11 @@ final class MacOSXFrame extends Frame implements WindowListener, ComponentListen
return canvas; return canvas;
} }
public boolean syncShouldUpdateContext() { public boolean syncShouldWarpCursor() {
boolean result; boolean result;
synchronized ( this ) { synchronized ( this ) {
result = canvas.syncShouldUpdateContext() || should_update; result = should_warp_cursor;
should_update = false; should_warp_cursor = false;
} }
return result; return result;
} }

View File

@ -42,8 +42,10 @@ import java.awt.Graphics;
import java.awt.Point; import java.awt.Point;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener; 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 width;
private int height; 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 */ /* Input methods are not enabled in fullscreen anyway, so disable always */
enableInputMethods(false); enableInputMethods(false);
addComponentListener(this); addComponentListener(this);
((MacOSXDisplay)Display.getImplementation()).setView(this); addHierarchyListener(this);
// ((MacOSXDisplay)Display.getImplementation()).setView(this);
setUpdate(); setUpdate();
} }
@ -148,4 +151,8 @@ final class MacOSXGLCanvas extends Canvas implements ComponentListener {
super.setBounds(x, y, width, height); super.setBounds(x, y, width, height);
setUpdate(); 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; return;
try { try {
context.forceDestroy(); context.forceDestroy();
Display.getImplementation().destroyPbuffer(peer_info); peer_info.destroy();
destroyed = true; destroyed = true;
} catch (LWJGLException e) { } catch (LWJGLException e) {
Sys.log("Exception occurred while destroying pbuffer: " + e); Sys.log("Exception occurred while destroying pbuffer: " + e);

View File

@ -85,4 +85,7 @@ abstract class PeerInfo {
protected final ByteBuffer getHandle() { protected final ByteBuffer getHandle() {
return handle; 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; private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
public void update(ByteBuffer context_handle) {
}
public void releaseCurrentContext() throws LWJGLException { public void releaseCurrentContext() throws LWJGLException {
nReleaseCurrentContext(); nReleaseCurrentContext();
} }

View File

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

View File

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

View File

@ -33,16 +33,28 @@
/** /**
* $Id$ * $Id$
* *
* Mac OS Xspecific display functions. * Base Win32 display
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$ * @version $Revision$
*/ */
#import <Cocoa/Cocoa.h> #ifndef __LWJGL_CONTEXT_H
#import "common_tools.h" #define __LWJGL_CONTEXT_H
/* Will return NULL and throw exception if it fails */ #include <Cocoa/Cocoa.h>
extern NSOpenGLContext *createContext(JNIEnv *env, jobject pixel_format, bool double_buffered, bool use_display_bpp, long drawable_type, NSOpenGLContext *share_context); #include <OpenGL/gl.h>
extern NSOpenGLContext *getDisplayContext(); #include <OpenGL/glext.h>
#include "common_tools.h"
typedef struct {
NSOpenGLPixelFormat *pixel_format;
bool window;
union {
NSView *nsview;
NSOpenGLPixelBuffer *pbuffer;
};
} MacOSXPeerInfo;
NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool use_display_bpp, bool support_window, bool support_pbuffer, bool double_buffered);
#endif

View File

@ -0,0 +1,91 @@
/*
* 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.
*/
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#import "context.h"
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool use_display_bpp, bool support_window, bool support_pbuffer, bool double_buffered) {
int bpp;
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
if (use_display_bpp)
bpp = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
else
bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "bpp", "I"));
int alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "alpha", "I"));
int depth = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "depth", "I"));
int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
bool stereo = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
attrib_list_t attribs;
jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Display.allowSoftwareOpenGL");
initAttribList(&attribs);
if (!allow_software_acceleration)
putAttrib(&attribs, NSOpenGLPFAAccelerated);
if (double_buffered)
putAttrib(&attribs, NSOpenGLPFADoubleBuffer);
putAttrib(&attribs, NSOpenGLPFAColorSize); putAttrib(&attribs, bpp);
putAttrib(&attribs, NSOpenGLPFAAlphaSize); putAttrib(&attribs, alpha);
putAttrib(&attribs, NSOpenGLPFADepthSize); putAttrib(&attribs, depth);
putAttrib(&attribs, NSOpenGLPFAStencilSize); putAttrib(&attribs, stencil);
putAttrib(&attribs, NSOpenGLPFAAccumSize); putAttrib(&attribs, accum_bpp + accum_alpha);
putAttrib(&attribs, NSOpenGLPFASampleBuffers); putAttrib(&attribs, samples > 0 ? 1 : 0);
putAttrib(&attribs, NSOpenGLPFASamples); putAttrib(&attribs, samples);
putAttrib(&attribs, NSOpenGLPFAAuxBuffers); putAttrib(&attribs, num_aux_buffers);
if (support_window)
putAttrib(&attribs, NSOpenGLPFAWindow);
if (support_pbuffer)
putAttrib(&attribs, NSOpenGLPFAPixelBuffer);
if (stereo)
putAttrib(&attribs, NSOpenGLPFAStereo);
putAttrib(&attribs, 0);
NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs.attribs];
if (fmt == nil) {
throwException(env, "Could not create pixel format");
return NULL;
}
return fmt;
}

View File

@ -33,7 +33,7 @@
/** /**
* $Id$ * $Id$
* *
* Mac OS Xspecific display functions. * Mac OS X specific display functions.
* *
* @author elias_naur <elias_naur@users.sourceforge.net> * @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$ * @version $Revision$
@ -44,12 +44,12 @@
#import <jawt_md.h> #import <jawt_md.h>
#import <jni.h> #import <jni.h>
#import <unistd.h> #import <unistd.h>
#import "display.h" //#import "display.h"
#import "common_tools.h" #import "common_tools.h"
#define WAIT_DELAY 100 #define WAIT_DELAY 100
static NSOpenGLContext *gl_context; /*static NSOpenGLContext *gl_context;
NSOpenGLContext *createContext(JNIEnv *env, jobject pixel_format, bool double_buffered, bool use_display_bpp, long drawable_type, NSOpenGLContext *share_context) { NSOpenGLContext *createContext(JNIEnv *env, jobject pixel_format, bool double_buffered, bool use_display_bpp, long drawable_type, NSOpenGLContext *share_context) {
int bpp; int bpp;
@ -173,7 +173,7 @@ static void setView(JNIEnv *env, jobject canvas) {
ds->Unlock(ds); ds->Unlock(ds);
awt.FreeDrawingSurface(ds); awt.FreeDrawingSurface(ds);
} }
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_restoreGamma(JNIEnv *env, jobject this) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_restoreGamma(JNIEnv *env, jobject this) {
CGDisplayRestoreColorSyncSettings(); CGDisplayRestoreColorSyncSettings();
} }
@ -194,7 +194,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_hideUI(JNIEnv *env, j
SetSystemUIMode(kUIModeNormal, 0); SetSystemUIMode(kUIModeNormal, 0);
} }
} }
/*
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_setVSyncEnabled(JNIEnv *env, jobject this, jboolean vsync) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_setVSyncEnabled(JNIEnv *env, jobject this, jboolean vsync) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
long vsync_value = vsync == JNI_TRUE ? 1 : 0; long vsync_value = vsync == JNI_TRUE ? 1 : 0;
@ -233,3 +233,4 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_destroyContext(JNIEnv
} }
[pool release]; [pool release];
} }
*/

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.
*/
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#include <jni.h>
#include <jawt.h>
#include <jawt_md.h>
#include "awt_tools.h"
#include "org_lwjgl_opengl_MacOSXCanvasPeerInfo.h"
#include "context.h"
#include "common_tools.h"
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nInitHandle
(JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject peer_info_handle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
JAWT_MacOSXDrawingSurfaceInfo *macosx_dsi = (JAWT_MacOSXDrawingSurfaceInfo *)surface->dsi->platformInfo;
peer_info->nsview = macosx_dsi->cocoaViewRef;
peer_info->window = true;
[pool release];
}

View File

@ -0,0 +1,78 @@
/*
* 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.
*/
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#import <jni.h>
#import <Cocoa/Cocoa.h>
#import "org_lwjgl_opengl_MacOSXPbufferPeerInfo.h"
#import "context.h"
#import "common_tools.h"
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXPbufferPeerInfo_nCreate(JNIEnv *env, jclass clazz, jobject peer_info_handle, jint width, jint height) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSOpenGLPixelBuffer *pbuffer = nil;
// check if the texture is power of 2
if ( (( width > 0 ) && ( width & ( width-1)) == 0) || (( height > 0 ) && ( height & ( height-1)) == 0) )
{
pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_2D
textureInternalFormat:GL_RGBA
textureMaxMipMapLevel:0
pixelsWide:width
pixelsHigh:height];
}
else
{
pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_RECTANGLE_EXT
textureInternalFormat:GL_RGBA
textureMaxMipMapLevel:0
pixelsWide:width
pixelsHigh:height];
}
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
peer_info->pbuffer = pbuffer;
peer_info->window = false;
[pool release];
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXPbufferPeerInfo_nDestroy
(JNIEnv *env, jclass clazz, jobject peer_info_handle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
[peer_info->pbuffer release];
[pool release];
}

View File

@ -0,0 +1,73 @@
/*
* 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.
*/
/**
* $Id$
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#import <jni.h>
#import <Cocoa/Cocoa.h>
#import "org_lwjgl_opengl_MacOSXPeerInfo.h"
#import "context.h"
#import "common_tools.h"
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXPeerInfo_createHandle
(JNIEnv *env, jclass clazz) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
jobject handle = newJavaManagedByteBuffer(env, sizeof(MacOSXPeerInfo));
[pool release];
return handle;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXPeerInfo_nChoosePixelFormat
(JNIEnv *env, jclass clazz, jobject peer_info_handle, jobject pixel_format, jboolean use_display_bpp, jboolean support_window, jboolean support_pbuffer, jboolean double_buffered) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
NSOpenGLPixelFormat *macosx_pixel_format = choosePixelFormat(env, pixel_format, use_display_bpp, support_window, support_pbuffer, double_buffered);
if (pixel_format == nil) {
throwException(env, "Could not find pixel format");
return;
}
peer_info->pixel_format = macosx_pixel_format;
[pool release];
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXPeerInfo_nDestroy
(JNIEnv *env, jclass clazz, jobject peer_info_handle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
[peer_info->pixel_format release];
[pool release];
}

View File

@ -1,155 +0,0 @@
/*
* 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.
*/
/**
* $Id$
*
* Mac OS X Pbuffer.
*
* @author elias_naur <elias_naur@users.sourceforge.net>
* @version $Revision$
*/
#import <jni.h>
#import <OpenGL/gl.h>
#import <OpenGL/glext.h>
#import "org_lwjgl_opengl_MacOSXDisplay.h"
#import "org_lwjgl_opengl_Pbuffer.h"
#import "display.h"
typedef struct {
NSOpenGLPixelBuffer *pbuffer;
NSOpenGLContext *context;
} PbufferInfo;
/* Check capacity and throw i not large enough to hold a PbufferInfo struct */
static bool checkCapacity(JNIEnv *env, jobject pbuffer_handle) {
if ((*env)->GetDirectBufferCapacity(env, pbuffer_handle) < sizeof(PbufferInfo)) {
throwException(env, "Handle buffer not large enough");
return false;
} else
return true;
}
static PbufferInfo *getPbufferInfoFromBuffer(JNIEnv *env, jobject pbuffer_handle) {
if (checkCapacity(env, pbuffer_handle))
return (PbufferInfo *)(*env)->GetDirectBufferAddress(env, pbuffer_handle);
else
return NULL;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_makePbufferCurrent(JNIEnv *env, jobject this, jobject pbuffer_handle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
PbufferInfo *pbuffer_handle_ptr = getPbufferInfoFromBuffer(env, pbuffer_handle);
if (pbuffer_handle_ptr == NULL)
return;
[pbuffer_handle_ptr->context makeCurrentContext];
[pool release];
}
static void createPbuffer(JNIEnv *env, jobject pbuffer_handle, jint width, jint height, jobject pixel_format, NSOpenGLContext *shared_context)
{
if (!checkCapacity(env, pbuffer_handle))
return;
NSOpenGLPixelBuffer *pbuffer = nil;
// check if the texture is power of 2
if ( (( width > 0 ) && ( width & ( width-1)) == 0) || (( height > 0 ) && ( height & ( height-1)) == 0) )
{
pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_2D
textureInternalFormat:GL_RGBA
textureMaxMipMapLevel:0
pixelsWide:width
pixelsHigh:height];
}
else
{
pbuffer = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:GL_TEXTURE_RECTANGLE_EXT
textureInternalFormat:GL_RGBA
textureMaxMipMapLevel:0
pixelsWide:width
pixelsHigh:height];
}
if (pbuffer == nil)
{
throwException(env, "Could not allocate Pbuffer");
return;
}
NSOpenGLContext *context = createContext(env, pixel_format, false, false, NSOpenGLPFAPixelBuffer, shared_context);
if (context == nil)
{
return;
}
int screen;
if (getDisplayContext() != NULL)
{
screen = [getDisplayContext() currentVirtualScreen];
}
else
{
screen = 0;
}
[context setPixelBuffer:pbuffer cubeMapFace:0 mipMapLevel:0 currentVirtualScreen:screen];
PbufferInfo *pbuffer_handle_ptr = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, pbuffer_handle);
pbuffer_handle_ptr->pbuffer = pbuffer;
pbuffer_handle_ptr->context = context;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreatePbuffer(JNIEnv *env, jobject this, jobject pbuffer_handle, jint width, jint height, jobject pixel_format, jobject pixelFormatCaps, jobject pBufferAttribs, jobject shared_context_handle_buffer) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSOpenGLContext *shared_context = getDisplayContext();
if (shared_context_handle_buffer != NULL) {
PbufferInfo *pbuffer_handle_ptr = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, shared_context_handle_buffer);
shared_context = pbuffer_handle_ptr->context;
}
createPbuffer(env, pbuffer_handle, width, height, pixel_format, shared_context);
[pool release];
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_destroyPbuffer(JNIEnv *env, jobject this, jobject pbuffer_handle) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
PbufferInfo *pbuffer_handle_ptr = getPbufferInfoFromBuffer(env, pbuffer_handle);
if (pbuffer_handle_ptr == NULL)
return;
[pbuffer_handle_ptr->context clearDrawable];
[pbuffer_handle_ptr->context release];
[pbuffer_handle_ptr->pbuffer release];
[pool release];
}

View File

@ -47,7 +47,6 @@
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32AWTGLCanvasPeerInfo_nInitHandle JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32AWTGLCanvasPeerInfo_nInitHandle
(JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject peer_info_handle) { (JNIEnv *env, jclass clazz, jobject lock_buffer_handle, jobject peer_info_handle) {
const AWTSurfaceLock *awt_lock = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle);
AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle); AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
JAWT_Win32DrawingSurfaceInfo *win32_dsi = (JAWT_Win32DrawingSurfaceInfo *)surface->dsi->platformInfo; JAWT_Win32DrawingSurfaceInfo *win32_dsi = (JAWT_Win32DrawingSurfaceInfo *)surface->dsi->platformInfo;