Mac OS X port of the refactoring. Linux and Win32 fixes.
This commit is contained in:
parent
acbbf03fe6
commit
3085702a38
|
@ -576,7 +576,11 @@
|
|||
<class name="org.lwjgl.opengl.Win32ContextImplementation" />
|
||||
</javah>
|
||||
<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.MacOSXContextImplementation" />
|
||||
</javah>
|
||||
<!-- lwjgl -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -85,4 +85,7 @@ abstract class PeerInfo {
|
|||
protected final ByteBuffer getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,16 +33,28 @@
|
|||
/**
|
||||
* $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$
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "common_tools.h"
|
||||
#ifndef __LWJGL_CONTEXT_H
|
||||
#define __LWJGL_CONTEXT_H
|
||||
|
||||
/* Will return NULL and throw exception if it fails */
|
||||
extern NSOpenGLContext *createContext(JNIEnv *env, jobject pixel_format, bool double_buffered, bool use_display_bpp, long drawable_type, NSOpenGLContext *share_context);
|
||||
extern NSOpenGLContext *getDisplayContext();
|
||||
#include <Cocoa/Cocoa.h>
|
||||
#include <OpenGL/gl.h>
|
||||
#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
|
|
@ -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;
|
||||
}
|
|
@ -33,7 +33,7 @@
|
|||
/**
|
||||
* $Id$
|
||||
*
|
||||
* Mac OS Xspecific display functions.
|
||||
* Mac OS X specific display functions.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
|
@ -44,12 +44,12 @@
|
|||
#import <jawt_md.h>
|
||||
#import <jni.h>
|
||||
#import <unistd.h>
|
||||
#import "display.h"
|
||||
//#import "display.h"
|
||||
#import "common_tools.h"
|
||||
|
||||
#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) {
|
||||
int bpp;
|
||||
|
@ -173,7 +173,7 @@ static void setView(JNIEnv *env, jobject canvas) {
|
|||
ds->Unlock(ds);
|
||||
awt.FreeDrawingSurface(ds);
|
||||
}
|
||||
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_restoreGamma(JNIEnv *env, jobject this) {
|
||||
CGDisplayRestoreColorSyncSettings();
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_hideUI(JNIEnv *env, j
|
|||
SetSystemUIMode(kUIModeNormal, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_setVSyncEnabled(JNIEnv *env, jobject this, jboolean vsync) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
long vsync_value = vsync == JNI_TRUE ? 1 : 0;
|
||||
|
@ -233,3 +233,4 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_destroyContext(JNIEnv
|
|||
}
|
||||
[pool release];
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -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];
|
||||
}
|
|
@ -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];
|
||||
}
|
|
@ -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];
|
||||
}
|
|
@ -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];
|
||||
}
|
|
@ -47,7 +47,6 @@
|
|||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32AWTGLCanvasPeerInfo_nInitHandle
|
||||
(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);
|
||||
AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle);
|
||||
JAWT_Win32DrawingSurfaceInfo *win32_dsi = (JAWT_Win32DrawingSurfaceInfo *)surface->dsi->platformInfo;
|
||||
|
|
Loading…
Reference in New Issue