예제 #1
0
 protected void releaseImpl() throws GLException {
   if (isNSContext) {
     if (!CGL.clearCurrentContext(contextHandle)) {
       throw new GLException("Error freeing OpenGL Context (NS)");
     }
   } else {
     CGL.CGLReleaseContext(contextHandle);
   }
 }
예제 #2
0
 protected void makeCurrentImpl(boolean newCreated) throws GLException {
   if (isNSContext) {
     if (!CGL.makeCurrentContext(contextHandle)) {
       throw new GLException("Error making Context (NS) current");
     }
   } else {
     if (CGL.kCGLNoError != CGL.CGLSetCurrentContext(contextHandle)) {
       throw new GLException("Error making Context (CGL) current");
     }
   }
 }
예제 #3
0
 protected void setSwapIntervalImpl(int interval) {
   if (!isCreated()) {
     throw new GLException("OpenGL context not created");
   }
   if (isNSContext) {
     CGL.setSwapInterval(contextHandle, interval);
   } else {
     int[] lval = new int[] {(int) interval};
     CGL.CGLSetParameter(contextHandle, CGL.kCGLCPSwapInterval, lval, 0);
   }
   currentSwapInterval = interval;
 }
예제 #4
0
 protected void copyImpl(GLContext source, int mask) throws GLException {
   long dst = getHandle();
   long src = source.getHandle();
   if (!isNSContext()) {
     if (((MacOSXCGLContext) source).isNSContext()) {
       throw new GLException("Source OpenGL Context is NS ; Destination Context is CGL.");
     }
     CGL.CGLCopyContext(src, dst, mask);
   } else {
     if (!((MacOSXCGLContext) source).isNSContext()) {
       throw new GLException("Source OpenGL Context is CGL ; Destination Context is NS.");
     }
     CGL.copyContext(dst, src, mask);
   }
 }
예제 #5
0
 protected void swapBuffers() {
   DefaultGraphicsConfiguration config =
       (DefaultGraphicsConfiguration)
           drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
   GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
   if (caps.isOnscreen()) {
     if (isNSContext) {
       if (!CGL.flushBuffer(contextHandle)) {
         throw new GLException("Error swapping buffers (NS)");
       }
     } else {
       if (CGL.kCGLNoError != CGL.CGLFlushDrawable(contextHandle)) {
         throw new GLException("Error swapping buffers (CGL)");
       }
     }
   }
 }
예제 #6
0
 protected void destroyImpl() throws GLException {
   if (!isNSContext) {
     if (CGL.kCGLNoError != CGL.CGLDestroyContext(contextHandle)) {
       throw new GLException("Unable to delete OpenGL Context (CGL)");
     }
     if (DEBUG) {
       System.err.println("!!! Destroyed OpenGL Context (CGL) " + contextHandle);
     }
   } else {
     if (!CGL.deleteContext(contextHandle)) {
       throw new GLException("Unable to delete OpenGL Context (NS)");
     }
     if (DEBUG) {
       System.err.println("!!! Destroyed OpenGL Context (NS) " + contextHandle);
     }
   }
 }
예제 #7
0
  /**
   * Creates and initializes an appropriate OpenGl Context (NS). Should only be called by {@link
   * makeCurrentImpl()}.
   */
  protected boolean create(boolean pbuffer, boolean floatingPoint) {
    MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this);
    long share = 0;
    if (other != null) {
      if (!other.isNSContext()) {
        throw new GLException("GLContextShareSet is not a NS Context");
      }
      share = other.getHandle();
      if (share == 0) {
        throw new GLException("GLContextShareSet returned a NULL OpenGL context");
      }
    }
    MacOSXCGLGraphicsConfiguration config =
        (MacOSXCGLGraphicsConfiguration)
            drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
    GLCapabilitiesImmutable capabilitiesRequested =
        (GLCapabilitiesImmutable) config.getRequestedCapabilities();
    GLProfile glProfile = capabilitiesRequested.getGLProfile();
    if (glProfile.isGL3()) {
      throw new GLException(
          "GL3 profile currently not supported on MacOSX, due to the lack of a OpenGL 3.1 implementation");
    }
    // HACK .. bring in OnScreen/PBuffer selection to the DrawableFactory !!
    GLCapabilities capabilities = (GLCapabilities) capabilitiesRequested.cloneMutable();
    capabilities.setPBuffer(pbuffer);
    capabilities.setPbufferFloatingPointBuffers(floatingPoint);

    long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(capabilities);
    if (pixelFormat == 0) {
      throw new GLException("Unable to allocate pixel format with requested GLCapabilities");
    }
    config.setChosenPixelFormat(pixelFormat);
    try {
      int[] viewNotReady = new int[1];
      // Try to allocate a context with this
      contextHandle = CGL.createContext(share, drawable.getHandle(), pixelFormat, viewNotReady, 0);
      if (contextHandle == 0) {
        if (viewNotReady[0] == 1) {
          if (DEBUG) {
            System.err.println("!!! View not ready for " + getClass().getName());
          }
          // View not ready at the window system level -- this is OK
          return false;
        }
        throw new GLException("Error creating NSOpenGLContext with requested pixel format");
      }

      if (!pbuffer && !capabilities.isBackgroundOpaque()) {
        // Set the context opacity
        CGL.setContextOpacity(contextHandle, 0);
      }

      GLCapabilitiesImmutable caps =
          MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(glProfile, pixelFormat);
      config.setChosenCapabilities(caps);
    } finally {
      CGL.deletePixelFormat(pixelFormat);
    }
    if (!CGL.makeCurrentContext(contextHandle)) {
      throw new GLException("Error making Context (NS) current");
    }
    isNSContext = true;
    setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT | CTX_OPTION_ANY);
    GLContextShareSet.contextCreated(this);
    return true;
  }