2005-02-20 06:24:22 -05:00
|
|
|
/*
|
2008-04-07 14:36:09 -04:00
|
|
|
* Copyright (c) 2002-2008 LWJGL Project
|
2005-02-20 06:24:22 -05:00
|
|
|
* 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 org.lwjgl.LWJGLException;
|
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.IntBuffer;
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
/**
|
|
|
|
* @author elias_naur <elias_naur@users.sourceforge.net>
|
|
|
|
* @version $Revision$
|
2008-08-19 12:46:03 -04:00
|
|
|
* $Id$
|
2005-02-20 06:24:22 -05:00
|
|
|
*/
|
|
|
|
final class LinuxContextImplementation implements ContextImplementation {
|
2008-08-19 12:46:03 -04:00
|
|
|
|
|
|
|
public ByteBuffer create(PeerInfo peer_info, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException {
|
2005-02-20 06:24:22 -05:00
|
|
|
LinuxDisplay.lockAWT();
|
|
|
|
try {
|
|
|
|
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
|
|
|
try {
|
2008-08-19 12:46:03 -04:00
|
|
|
return nCreate(peer_handle, attribs, shared_context_handle);
|
2005-02-20 06:24:22 -05:00
|
|
|
} finally {
|
|
|
|
peer_info.unlock();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
LinuxDisplay.unlockAWT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 12:46:03 -04:00
|
|
|
private static native ByteBuffer nCreate(ByteBuffer peer_handle, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException;
|
2006-06-07 02:35:52 -04:00
|
|
|
|
2010-09-26 19:43:24 -04:00
|
|
|
native long getGLXContext(ByteBuffer context_handle);
|
|
|
|
|
|
|
|
native long getDisplay(ByteBuffer peer_info_handle);
|
|
|
|
|
2006-06-07 02:35:52 -04:00
|
|
|
public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException {
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public void swapBuffers() throws LWJGLException {
|
2011-05-17 12:53:57 -04:00
|
|
|
ContextGL current_context = ContextGL.getCurrentContext();
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( current_context == null )
|
2005-02-20 06:24:22 -05:00
|
|
|
throw new IllegalStateException("No context is current");
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( current_context ) {
|
2005-02-23 07:12:47 -05:00
|
|
|
PeerInfo current_peer_info = current_context.getPeerInfo();
|
|
|
|
LinuxDisplay.lockAWT();
|
2005-02-20 06:24:22 -05:00
|
|
|
try {
|
2005-02-23 07:12:47 -05:00
|
|
|
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
|
|
|
try {
|
|
|
|
nSwapBuffers(peer_handle);
|
|
|
|
} finally {
|
|
|
|
current_peer_info.unlock();
|
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
} finally {
|
2005-02-23 07:12:47 -05:00
|
|
|
LinuxDisplay.unlockAWT();
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException;
|
|
|
|
|
|
|
|
public void releaseCurrentContext() throws LWJGLException {
|
2011-05-17 12:53:57 -04:00
|
|
|
ContextGL current_context = ContextGL.getCurrentContext();
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( current_context == null )
|
2005-02-23 07:12:47 -05:00
|
|
|
throw new IllegalStateException("No context is current");
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( current_context ) {
|
2005-02-23 07:12:47 -05:00
|
|
|
PeerInfo current_peer_info = current_context.getPeerInfo();
|
|
|
|
LinuxDisplay.lockAWT();
|
2005-02-20 06:24:22 -05:00
|
|
|
try {
|
2005-02-23 07:12:47 -05:00
|
|
|
ByteBuffer peer_handle = current_peer_info.lockAndGetHandle();
|
|
|
|
try {
|
|
|
|
nReleaseCurrentContext(peer_handle);
|
|
|
|
} finally {
|
|
|
|
current_peer_info.unlock();
|
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
} finally {
|
2005-02-23 07:12:47 -05:00
|
|
|
LinuxDisplay.unlockAWT();
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
private static native void nReleaseCurrentContext(ByteBuffer peer_info_handle) throws LWJGLException;
|
|
|
|
|
2005-02-23 06:11:08 -05:00
|
|
|
public void update(ByteBuffer context_handle) {
|
|
|
|
}
|
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
|
|
|
|
LinuxDisplay.lockAWT();
|
|
|
|
try {
|
|
|
|
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
|
|
|
try {
|
|
|
|
nMakeCurrent(peer_handle, handle);
|
|
|
|
} finally {
|
|
|
|
peer_info.unlock();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
LinuxDisplay.unlockAWT();
|
|
|
|
}
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
private static native void nMakeCurrent(ByteBuffer peer_handle, ByteBuffer context_handle) throws LWJGLException;
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
public boolean isCurrent(ByteBuffer handle) throws LWJGLException {
|
|
|
|
LinuxDisplay.lockAWT();
|
|
|
|
try {
|
|
|
|
boolean result = nIsCurrent(handle);
|
|
|
|
return result;
|
|
|
|
} finally {
|
|
|
|
LinuxDisplay.unlockAWT();
|
|
|
|
}
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException;
|
|
|
|
|
2006-01-01 14:50:06 -05:00
|
|
|
public void setSwapInterval(int value) {
|
2011-05-17 12:53:57 -04:00
|
|
|
ContextGL current_context = ContextGL.getCurrentContext();
|
2008-08-19 12:46:03 -04:00
|
|
|
if ( current_context == null )
|
2005-02-24 05:44:34 -05:00
|
|
|
throw new IllegalStateException("No context is current");
|
2008-08-19 12:46:03 -04:00
|
|
|
synchronized ( current_context ) {
|
2005-02-24 05:44:34 -05:00
|
|
|
LinuxDisplay.lockAWT();
|
2006-01-01 14:50:06 -05:00
|
|
|
nSetSwapInterval(current_context.getHandle(), value);
|
2005-02-24 05:44:34 -05:00
|
|
|
LinuxDisplay.unlockAWT();
|
|
|
|
}
|
2005-02-20 06:24:22 -05:00
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2006-01-01 14:50:06 -05:00
|
|
|
private static native void nSetSwapInterval(ByteBuffer context_handle, int value);
|
2005-02-20 06:24:22 -05:00
|
|
|
|
|
|
|
public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException {
|
|
|
|
LinuxDisplay.lockAWT();
|
|
|
|
try {
|
|
|
|
ByteBuffer peer_handle = peer_info.lockAndGetHandle();
|
|
|
|
try {
|
|
|
|
nDestroy(peer_handle, handle);
|
|
|
|
} finally {
|
|
|
|
peer_info.unlock();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
LinuxDisplay.unlockAWT();
|
|
|
|
}
|
|
|
|
}
|
2008-08-19 12:46:03 -04:00
|
|
|
|
2005-02-20 06:24:22 -05:00
|
|
|
private static native void nDestroy(ByteBuffer peer_handle, ByteBuffer context_handle) throws LWJGLException;
|
|
|
|
}
|