1 /* 2 * Copyright (c) 2002-2008 LWJGL Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'LWJGL' nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.lwjgl.opengl; 33 34 import org.lwjgl.LWJGLException; 35 import org.lwjgl.LWJGLUtil; 36 37 import java.nio.ByteBuffer; 38 import java.nio.IntBuffer; 39 40 /** 41 * @author elias_naur <elias_naur@users.sourceforge.net> 42 * @version $Revision$ 43 * $Id$ 44 */ 45 final class WindowsContextImplementation implements ContextImplementation { 46 create(PeerInfo peer_info, IntBuffer attribs, ByteBuffer shared_context_handle)47 public ByteBuffer create(PeerInfo peer_info, IntBuffer attribs, ByteBuffer shared_context_handle) throws LWJGLException { 48 ByteBuffer peer_handle = peer_info.lockAndGetHandle(); 49 try { 50 return nCreate(peer_handle, attribs, shared_context_handle); 51 } finally { 52 peer_info.unlock(); 53 } 54 } 55 nCreate(ByteBuffer peer_handle, IntBuffer attribs_handle, ByteBuffer shared_context_handle)56 private static native ByteBuffer nCreate(ByteBuffer peer_handle, IntBuffer attribs_handle, ByteBuffer shared_context_handle) throws LWJGLException; 57 getHGLRC(ByteBuffer context_handle)58 native long getHGLRC(ByteBuffer context_handle); 59 getHDC(ByteBuffer peer_info_handle)60 native long getHDC(ByteBuffer peer_info_handle); 61 swapBuffers()62 public void swapBuffers() throws LWJGLException { 63 ContextGL current_context = ContextGL.getCurrentContext(); 64 if ( current_context == null ) 65 throw new IllegalStateException("No context is current"); 66 synchronized ( current_context ) { 67 PeerInfo current_peer_info = current_context.getPeerInfo(); 68 ByteBuffer peer_handle = current_peer_info.lockAndGetHandle(); 69 try { 70 nSwapBuffers(peer_handle); 71 } finally { 72 current_peer_info.unlock(); 73 } 74 } 75 } 76 nSwapBuffers(ByteBuffer peer_info_handle)77 private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException; 78 releaseDrawable(ByteBuffer context_handle)79 public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException { 80 } 81 update(ByteBuffer context_handle)82 public void update(ByteBuffer context_handle) { 83 } 84 releaseCurrentContext()85 public void releaseCurrentContext() throws LWJGLException { 86 nReleaseCurrentContext(); 87 } 88 nReleaseCurrentContext()89 private static native void nReleaseCurrentContext() throws LWJGLException; 90 makeCurrent(PeerInfo peer_info, ByteBuffer handle)91 public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { 92 ByteBuffer peer_handle = peer_info.lockAndGetHandle(); 93 try { 94 nMakeCurrent(peer_handle, handle); 95 } finally { 96 peer_info.unlock(); 97 } 98 } 99 nMakeCurrent(ByteBuffer peer_handle, ByteBuffer context_handle)100 private static native void nMakeCurrent(ByteBuffer peer_handle, ByteBuffer context_handle) throws LWJGLException; 101 isCurrent(ByteBuffer handle)102 public boolean isCurrent(ByteBuffer handle) throws LWJGLException { 103 boolean result = nIsCurrent(handle); 104 return result; 105 } 106 nIsCurrent(ByteBuffer context_handle)107 private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException; 108 setSwapInterval(int value)109 public void setSwapInterval(int value) { 110 boolean success = nSetSwapInterval(value); 111 if ( !success ) 112 LWJGLUtil.log("Failed to set swap interval"); 113 Util.checkGLError(); 114 } 115 nSetSwapInterval(int value)116 private static native boolean nSetSwapInterval(int value); 117 destroy(PeerInfo peer_info, ByteBuffer handle)118 public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { 119 nDestroy(handle); 120 } 121 nDestroy(ByteBuffer context_handle)122 private static native void nDestroy(ByteBuffer context_handle) throws LWJGLException; 123 } 124