1 /* 2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * - Redistribution of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * - Redistribution in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * Neither the name of Sun Microsystems, Inc. or the names of 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * This software is provided "AS IS," without a warranty of any kind. ALL 20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN 23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR 24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR 26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR 27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE 28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, 29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF 30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 31 * 32 * You acknowledge that this software is not designed or intended for use 33 * in the design, construction, operation or maintenance of any nuclear 34 * facility. 35 * 36 * Sun gratefully acknowledges that this software was originally authored 37 * and developed by Kenneth Bradley Russell and Christopher John Kline. 38 */ 39 40 package com.sun.opengl.impl.windows; 41 42 import java.nio.*; 43 import java.util.*; 44 import javax.media.opengl.*; 45 import com.sun.opengl.impl.*; 46 47 public class WindowsExternalGLContext extends WindowsGLContext { 48 private boolean firstMakeCurrent = true; 49 private boolean created = true; 50 private GLContext lastContext; 51 WindowsExternalGLContext()52 public WindowsExternalGLContext() { 53 super(null, null, true); 54 hglrc = WGL.wglGetCurrentContext(); 55 if (hglrc == 0) { 56 throw new GLException("Error: attempted to make an external GLContext without a drawable/context current"); 57 } 58 if (DEBUG) { 59 System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(hglrc) + " for " + this); 60 } 61 GLContextShareSet.contextCreated(this); 62 resetGLFunctionAvailability(); 63 } 64 makeCurrent()65 public int makeCurrent() throws GLException { 66 // Save last context if necessary to allow external GLContexts to 67 // talk to other GLContexts created by this library 68 GLContext cur = getCurrent(); 69 if (cur != null && cur != this) { 70 lastContext = cur; 71 setCurrent(null); 72 } 73 return super.makeCurrent(); 74 } 75 release()76 public void release() throws GLException { 77 super.release(); 78 setCurrent(lastContext); 79 lastContext = null; 80 } 81 makeCurrentImpl()82 protected int makeCurrentImpl() throws GLException { 83 if (firstMakeCurrent) { 84 firstMakeCurrent = false; 85 return CONTEXT_CURRENT_NEW; 86 } 87 return CONTEXT_CURRENT; 88 } 89 releaseImpl()90 protected void releaseImpl() throws GLException { 91 } 92 destroyImpl()93 protected void destroyImpl() throws GLException { 94 created = false; 95 GLContextShareSet.contextDestroyed(this); 96 } 97 isCreated()98 public boolean isCreated() { 99 return created; 100 } 101 } 102