Package javax.media.opengl

Examples of javax.media.opengl.GLContext


            // we need to temporarily release the AWT lock before we lock the dirty rectangle and then reacquire
            // the AWT lock afterward.
            // NOTE: we need to do this manually, rather than using a swingsafe processor, because
            // we need to be holding the AWT lock when we return from this method.
            // TODO: low: MTgame probably provides a cleaner way to reacquire the lock.
            GLContext glContext = null;
            if (isAWTLockHeldByCurrentThreadMethod != null) {
                try {
                    Boolean ret = (Boolean) isAWTLockHeldByCurrentThreadMethod.invoke(null);
                    if (ret.booleanValue()) {
                        glContext = GLContext.getCurrent();
                        glContext.release();
                    }
                } catch (Exception ex) {
                }
            }

            final int texid = getTexture().getTextureId();

            // In this implementation, we need to check our DirtyTrackingGraphics to see whether it is dirty.
            // If it is dirty, we copy the entire buffered image into the imageGraphics.
            g.executeAtomic(new Runnable() {

                public void run() {
                    Rectangle dirtyRect = g.getDirtyRectangle();
                    if (dirtyRect != null) {

                        //System.err.println("DBSI: Rendering into texid = " + texid);

      int x1 = dirtyRect.x;
      int y1 = dirtyRect.y;
      int x2 = dirtyRect.x + dirtyRect.width - 1;
      int y2 = dirtyRect.y + dirtyRect.height - 1;

                        if (!imageGraphics.drawImage(bufImage, x1, y1, x2, y2,
                                       x1, y1, x2, y2, null, null)) {
                            logger.warning("drawImage returned false. Skipping image rendering.");
                        }

                        g.clearDirty();
                        checkForUpdateReturn = true;
                    } else {
                        checkForUpdateReturn = false;
                    }
                }
            });

            // Linux-specific workaround: Reacquire the lock if necessary.
            if (glContext != null) {
                glContext.makeCurrent();
            }

            return checkForUpdateReturn;
        }
View Full Code Here


  private GLContext createGLContext() {

    try {
      logger.info("Create context...");
      GLDrawableFactory drawableFactory = GLDrawableFactory.getFactory(DEFAULT_PROFILE);
      GLContext result = drawableFactory.createExternalGLContext();
      logger.info("    Done.");

      return result;
    } catch (Throwable errGl) {
      errGl.printStackTrace();
View Full Code Here

            int vertexAttrCount, int[] vertexAttrSizes,
            float[] varray, FloatBuffer varrayBuffer,
            float[] carray, int cDirty) {
        if (VERBOSE) System.err.println("JoglPipeline.executeGeometryArray()");
        JoglContext ctx = (JoglContext) absCtx;
        GLContext context = context(ctx);
    GL2 gl = context.getGL().getGL2();

        boolean useInterleavedArrays;
        int iaFormat = 0;
        int primType = 0;
        int stride = 0, coordoff = 0, normoff = 0, coloroff = 0, texCoordoff = 0;
View Full Code Here

            int cdirty,
            int[] sarray,
            int strip_len,
            int[] start_array) {
        JoglContext ctx = (JoglContext) absCtx;
        GLContext context = context(ctx);
    GL2 gl = context.getGL().getGL2();

        boolean floatCoordDefined  = ((vdefined & GeometryArrayRetained.COORD_FLOAT)    != 0);
        boolean doubleCoordDefined = ((vdefined & GeometryArrayRetained.COORD_DOUBLE)   != 0);
        boolean floatColorsDefined = ((vdefined & GeometryArrayRetained.COLOR_FLOAT)    != 0);
        boolean byteColorsDefined  = ((vdefined & GeometryArrayRetained.COLOR_BYTE)     != 0);
View Full Code Here

    int newWidth = Math.max(1, cvWidth);
    int newHeight = Math.max(1, cvHeight);

    GLDrawable glDrawble = joglDrawable.getGLDrawable();
    GLContext glContext = context(cv.ctx);

    // Assuming glContext != null

    final NativeSurface surface = glDrawble.getNativeSurface();
      final ProxySurface proxySurface = (surface instanceof ProxySurface) ? (ProxySurface)surface : null;

    final int lockRes = surface.lockSurface();

    try {
      // propagate new size - seems not relevant here
      if (proxySurface != null) {
        final UpstreamSurfaceHook ush = proxySurface.getUpstreamSurfaceHook();
        if (ush instanceof UpstreamSurfaceHook.MutableSize) {
          ((UpstreamSurfaceHook.MutableSize)ush).setSurfaceSize(newWidth, newHeight);
        }
      }
      /*else if(DEBUG) { // we have to assume surface contains the new size already, hence size check @ bottom
                System.err.println("GLDrawableHelper.resizeOffscreenDrawable: Drawable's offscreen surface n.a. ProxySurface, but "+ns.getClass().getName()+": "+ns);
      }*/

      GL2 gl = glContext.getGL().getGL2();

      // FBO : should be the default case on Mac OS X
      if (glDrawble instanceof GLFBODrawable) {

        // Resize GLFBODrawable
        // TODO msaa gets lost
//        ((GLFBODrawable)glDrawble).resetSize(gl);

        // Alternative: resize GL_BACK FBObject directly,
        // if multisampled the FBO sink (GL_FRONT) will be resized before the swap is executed
        int numSamples = ((GLFBODrawable)glDrawble).getChosenGLCapabilities().getNumSamples();
        FBObject fboObjectBack = ((GLFBODrawable)glDrawble).getFBObject( GL.GL_BACK );
        fboObjectBack.reset(gl, newWidth, newHeight, numSamples, false); // false = don't reset SamplingSinkFBO immediately
        fboObjectBack.bind(gl);

        // If double buffered without antialiasing the GL_FRONT FBObject
        // will be resized by glDrawble after the next swap-call
      }
      // pbuffer - not tested because Mac OS X 10.7+ supports FBO
      else {
        // Create new GLDrawable (pbuffer) and update the coresponding GLContext

        final GLContext currentContext = GLContext.getCurrent();
        final GLDrawableFactory factory = glDrawble.getFactory();

        // Ensure to sync GL command stream
        if (currentContext != glContext) {
          glContext.makeCurrent();
        }
             gl.glFinish();
             glContext.release();

             if (proxySurface != null) {
               proxySurface.enableUpstreamSurfaceHookLifecycle(false);
             }

             try {
               glDrawble.setRealized(false);
               // New GLDrawable
               glDrawble = factory.createGLDrawable(surface);
               glDrawble.setRealized(true);

               joglDrawable.setGLDrawable(glDrawble);
             }
             finally {
               if (proxySurface != null) {
                 proxySurface.enableUpstreamSurfaceHookLifecycle(true);
               }
             }

             glContext.setGLDrawable(glDrawble, true); // re-association

             // make current last current context
             if (currentContext != null) {
               currentContext.makeCurrent();
             }
      }
    }
    finally {
      surface.unlockSurface();
View Full Code Here

            boolean offScreen) {
        if (VERBOSE) System.err.println("JoglPipeline.createNewContext()");

        checkAppContext();
      GLDrawable  glDrawable   = null;
      GLContext   glContext  = null;

      if (offScreen) {
        glDrawable = drawable(cv.drawable); // cv.drawable != null, set in 'createOffScreenBuffer'
      glContext = glDrawable.createContext(context(shareCtx));
        }
      else {
        // determined in 'getBestConfiguration'
      GraphicsConfigInfo gcInf0 = Canvas3D.graphicsConfigTable.get(cv.graphicsConfiguration);
      AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)gcInf0.getPrivateData();

        // JAWTWindow
      JAWTWindow nativeWindow = (JAWTWindow)NativeWindowFactory.getNativeWindow(cv, awtConfig);
      nativeWindow.lockSurface();
        try {
          glDrawable = GLDrawableFactory.getFactory(profile).createGLDrawable(nativeWindow);
          glContext = glDrawable.createContext(context(shareCtx));
        }
        finally {
          nativeWindow.unlockSurface();
        }

        cv.drawable = new JoglDrawable(glDrawable, nativeWindow);
        }

        // assuming that this only gets called after addNotify has been called
      glDrawable.setRealized(true);

      // Apparently we are supposed to make the context current at this point
        // and set up a bunch of properties

        // Work around for some low end graphics driver bug, such as Intel Chipset.
        // Issue 324 : Lockup J3D program and throw exception using JOGL renderer
        boolean failed = false;
        int failCount = 0;
        int MAX_FAIL_COUNT = 5;
        do {
            failed = false;
            int res = glContext.makeCurrent();
            if (res == GLContext.CONTEXT_NOT_CURRENT) {
                // System.err.println("makeCurrent fail : " + failCount);
                failed = true;
                ++failCount;
                try {
                    Thread.sleep(100);
                }
                catch (InterruptedException e) {
                }
            }
        } while (failed && (failCount < MAX_FAIL_COUNT));

        if (failCount == MAX_FAIL_COUNT) {
            throw new IllegalRenderingStateException("Unable to make new context current after " + failCount + "tries");
        }

        GL2 gl = glContext.getGL().getGL2();

        JoglContext ctx = new JoglContext(glContext);

        try {
            if (!getPropertiesFromCurrentContext(ctx, gl)) {
                throw new IllegalRenderingStateException("Unable to fetch properties from current OpenGL context");
            }

            if(!isSharedCtx){
                // Set up fields in Canvas3D
                setupCanvasProperties(cv, ctx, gl);
            }

            // Enable rescale normal
            gl.glEnable(GL2.GL_RESCALE_NORMAL);

            gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE);
            gl.glDepthFunc(GL.GL_LEQUAL);
            gl.glEnable(GL2.GL_COLOR_MATERIAL);

            /*
            OpenGL specs:
               glReadBuffer specifies a color buffer as the source for subsequent glReadPixels.
               This source mode is initially GL_FRONT in single-buffered and GL_BACK in double-buffered configurations.

            We leave this mode unchanged in on-screen rendering and adjust it in off-screen rendering. See below.
            */
//          gl.glReadBuffer(GL_FRONT);     // off window, default for single-buffered non-stereo window

            // Issue 417: JOGL: Mip-mapped NPOT textures rendered incorrectly
            // J3D images are aligned to 1 byte
            gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

            // Workaround for issue 400: Enable separate specular by default
            gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL, GL2.GL_SEPARATE_SPECULAR_COLOR);


            // Mac OS X / JRE 7 : onscreen rendering = offscreen rendering
            // bind FBO
            if (!offScreen && glDrawable instanceof GLFBODrawable) {
              GLFBODrawable fboDrawable = (GLFBODrawable)glDrawable;
              // bind GLFBODrawable's drawing FBObject
              // GL_BACK returns the correct FBOObject for single/double buffering, incl. multisampling
              fboDrawable.getFBObject( GL.GL_BACK ).bind(gl);
            }


            // FBO or pbuffer
            if (offScreen) {

              // Final caps
              GLCapabilitiesImmutable chosenCaps = glDrawable.getChosenGLCapabilities();

              // FBO
              if (glDrawable instanceof GLFBODrawable) {
                  GLFBODrawable fboDrawable = (GLFBODrawable)glDrawable;
                  // bind GLFBODrawable's drawing FBObject
                  // GL_BACK returns the correct FBOObject for single/double buffering, incl. multisampling
                  fboDrawable.getFBObject( GL.GL_BACK ).bind(gl);
              }
              // pbuffer
              else {
                // Double buffering: read from back buffer, as we don't swap
          // Even this setting is identical to the initially mode it is set explicitly
          if (chosenCaps.getDoubleBuffered()) {
            gl.glReadBuffer(GL.GL_BACK);
          }
          else {
            gl.glReadBuffer(GL.GL_FRONT);
          }
              }
            }
        }
        finally {
       glContext.release();
        }

        return ctx;
    }
View Full Code Here

           GLDrawable glDrawable = drawable(offDrawable);

          glDrawable.setRealized(true);

        GLContext glContext = glDrawable.createContext(null);
            glContext.makeCurrent();

            JoglContext ctx = new JoglContext(glContext);

            GL2 gl = glContext.getGL().getGL2();

            // get current context properties
            getPropertiesFromCurrentContext(ctx, gl);
            // Set up fields in Canvas3D
            setupCanvasProperties(cv, ctx, gl);

            // Done !

            glContext.release();
        glContext.destroy();
        glDrawable.setRealized(false);
      }
        else {

          // TODO can't find an implementation which avoids the use of QueryCanvas
View Full Code Here

    @Override
    void destroyContext(Drawable drawable, Context ctx) {
        if (VERBOSE) System.err.println("JoglPipeline.destroyContext()");

        JoglDrawable joglDrawable =  (JoglDrawable)drawable;
        GLContext  context  = context(ctx);

        if (GLContext.getCurrent() == context) {
            context.release();
        }
        context.destroy();

        // assuming this is the right point at which to make this call
        joglDrawable.getGLDrawable().setRealized(false);

        joglDrawable.destroyNativeWindow();
View Full Code Here

    // The native method that sets this ctx to be the current one
    @Override
    boolean useCtx(Context ctx, Drawable drawable) {
        if (VERBOSE) System.err.println("JoglPipeline.useCtx()");
        GLContext context = context(ctx);
        int res = context.makeCurrent();
        return (res != GLContext.CONTEXT_NOT_CURRENT);
    }
View Full Code Here

    // Optionally release the context. Returns true if the context was released.
    @Override
    boolean releaseCtx(Context ctx) {
        if (VERBOSE) System.err.println("JoglPipeline.releaseCtx()");
        GLContext context = context(ctx);
        context.release();
        return true;
    }
View Full Code Here

TOP

Related Classes of javax.media.opengl.GLContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.