Example #1
0
 /**
  * If supported, queries the natively supported shader binary formats using {@link
  * GL2ES2#GL_NUM_SHADER_BINARY_FORMATS} and {@link GL2ES2#GL_SHADER_BINARY_FORMATS} via {@link
  * GL2ES2#glGetIntegerv(int, int[], int)}.
  */
 public static Set<Integer> getShaderBinaryFormats(final GL _gl) {
   final GL2ES2 gl = _gl.getGL2ES2();
   final ProfileInformation info = getProfileInformation(gl);
   if (null == info.shaderBinaryFormats) {
     info.shaderBinaryFormats = new HashSet<Integer>();
     if (gl.isGLES2Compatible()) {
       try {
         final int[] param = new int[1];
         gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0);
         final int err = gl.glGetError();
         final int numFormats = GL.GL_NO_ERROR == err ? param[0] : 0;
         if (numFormats > 0) {
           final int[] formats = new int[numFormats];
           gl.glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0);
           for (int i = 0; i < numFormats; i++) {
             info.shaderBinaryFormats.add(Integer.valueOf(formats[i]));
           }
         }
       } catch (final GLException gle) {
         System.err.println("Caught exception on thread " + Thread.currentThread().getName());
         gle.printStackTrace();
       }
     }
   }
   return info.shaderBinaryFormats;
 }
Example #2
0
 /** Returns true if a hader compiler is available, otherwise false. */
 public static boolean isShaderCompilerAvailable(final GL _gl) {
   final GL2ES2 gl = _gl.getGL2ES2();
   final ProfileInformation info = getProfileInformation(gl);
   if (null == info.shaderCompilerAvailable) {
     if (gl.isGLES2()) {
       boolean queryOK = false;
       try {
         final byte[] param = new byte[1];
         gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0);
         final int err = gl.glGetError();
         boolean v = GL.GL_NO_ERROR == err && param[0] != (byte) 0x00;
         if (!v) {
           final Set<Integer> bfs = getShaderBinaryFormats(gl);
           if (bfs.size() == 0) {
             // no supported binary formats, hence a compiler must be available!
             v = true;
           }
         }
         info.shaderCompilerAvailable = Boolean.valueOf(v);
         queryOK = true;
       } catch (final GLException gle) {
         System.err.println("Caught exception on thread " + Thread.currentThread().getName());
         gle.printStackTrace();
       }
       if (!queryOK) {
         info.shaderCompilerAvailable = Boolean.valueOf(true);
       }
     } else if (gl.isGL2ES2()) {
       info.shaderCompilerAvailable = new Boolean(true);
     } else {
       throw new GLException("Invalid OpenGL profile");
     }
   }
   return info.shaderCompilerAvailable.booleanValue();
 }
Example #3
0
  public void draw(GOut g) {
    if (screenshot && Config.sshot_noui) {
      visible = false;
    }
    super.draw(g);
    drawcmd(g, new Coord(20, 580));
    if (screenshot && (!Config.sshot_nonames || names_ready)) {
      visible = true;
      screenshot = false;
      try {
        Coord s = MainFrame.getInnerSize();
        String stamp = Utils.sessdate(System.currentTimeMillis());
        String ext = Config.sshot_compress ? ".jpg" : ".png";
        File f = new File("screenshots/SS_" + stamp + ext);
        f.mkdirs();
        Screenshot.writeToFile(f, s.x, s.y);
      } catch (GLException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    //	if(!afk && (System.currentTimeMillis() - ui.lastevent > 300000)) {
    //	    afk = true;
    //	    Widget slen = findchild(SlenHud.class);
    //	    if(slen != null)
    //		slen.wdgmsg("afk");
    //	} else if(afk && (System.currentTimeMillis() - ui.lastevent < 300000)) {
    //	    afk = false;
    //	}
  }
Example #4
0
 /**
  * Default implementation to destroys the drawable and context of this GLAutoDrawable:
  *
  * <ul>
  *   <li>issues the GLEventListener dispose call, if drawable and context are valid
  *   <li>destroys the GLContext, if valid
  *   <li>destroys the GLDrawable, if valid
  * </ul>
  *
  * <p>Method assumes the lock is being hold.
  *
  * <p>Override it to extend it to destroy your resources, i.e. the actual window. In such case
  * call <code>super.destroyImplInLock</code> first.
  */
 protected void destroyImplInLock() {
   if (preserveGLELSAtDestroy) {
     preserveGLStateAtDestroy(false);
     preserveGLEventListenerState();
   }
   if (null != context) {
     if (context.isCreated()) {
       // Catch dispose GLExceptions by GLEventListener, just 'print' them
       // so we can continue with the destruction.
       try {
         helper.disposeGL(this, context, true);
       } catch (GLException gle) {
         gle.printStackTrace();
       }
     }
     context = null;
   }
   if (null != drawable) {
     final AbstractGraphicsDevice device =
         drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice();
     drawable.setRealized(false);
     drawable = null;
     if (ownsDevice) {
       device.close();
     }
   }
 }
Example #5
0
    private void makeContextCurrent() {
      int MAX_CONTEXT_GRAB_ATTEMPTS = 10;

      if (context.isCurrent()) {
        notCurrent = false;
      } else {
        notCurrent = true;
        int value = GLContext.CONTEXT_NOT_CURRENT;
        int attempt = 0;
        do {
          try {
            value = context.makeCurrent();
            System.out.println("Made context current");
          } catch (final GLException gle) {
            gle.printStackTrace();
          } finally {
            attempt++;
            if (attempt == MAX_CONTEXT_GRAB_ATTEMPTS) {
              throw new RuntimeException("Failed to claim OpenGL context.");
            }
          }
          try {
            Thread.sleep(5);
          } catch (final InterruptedException e) {
            e.printStackTrace();
          }

        } while (value == GLContext.CONTEXT_NOT_CURRENT);
      }
    }
Example #6
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
   try {
     // Specify new projection for this window
     projection(drawable.getGL(), width, height);
   } catch (GLException e) {
     e.printStackTrace();
   }
 }
Example #7
0
 public void display(GLAutoDrawable drawable) {
   try {
     // Draw the contents of the window (abstract method)
     draw(drawable.getGL());
   } catch (GLException e) {
     e.printStackTrace();
   }
 }
Example #8
0
  /**
   * Called back immediately after the OpenGL context is initialized. Can be used to perform
   * one-time initialization. Run only once.
   */
  @Override
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
    glu = new GLU(); // get GL Utilities
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
    gl.glClearDepth(1.0f); // set clear depth value to farthest
    gl.glEnable(GL_DEPTH_TEST); // enables depth testing
    gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
    gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting

    // Load the texture image
    try {
      // Create a OpenGL Texture object from (URL, mipmap, file suffix)
      // Use URL so that can read from JAR and disk file.
      texture =
          TextureIO.newTexture(
              this.getClass().getResource(textureFileName), false, textureFileType);
    } catch (GLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Use linear filter for texture if image is larger than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // Use linear filter for texture if image is smaller than the original texture
    gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    // Texture image flips vertically. Shall use TextureCoords class to retrieve
    // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f.
    TextureCoords textureCoords = texture.getImageTexCoords();
    textureTop = textureCoords.top();
    textureBottom = textureCoords.bottom();
    //      textureLeft = textureCoords.left();
    //      textureRight = textureCoords.right();

    // Enable the texture
    texture.enable(gl);
    // gl.glEnable(GL_TEXTURE_2D);

    // we want back facing polygons to be filled completely and that we want front
    // facing polygons to be outlined only.
    gl.glPolygonMode(GL_BACK, GL_FILL); // Back Face Is Filled In
    gl.glPolygonMode(GL_FRONT, GL_LINE); // Front Face Is Drawn With Lines

    for (int x = 0; x < numPoints; x++) { // Loop Through The Y Plane
      for (int y = 0; y < numPoints; y++) {
        // Apply The Wave To Our Mesh
        // xmax is 45. Get 9 after dividing by 5. Subtract 4.5 to centralize.
        points[x][y][0] = (float) x / 5.0f - 4.5f;
        points[x][y][1] = (float) y / 5.0f - 4.5f;
        // Sine wave pattern
        points[x][y][2] = (float) (Math.sin(Math.toRadians(x / 5.0f * 40.0f)));
      }
    }
  }
Example #9
0
 private void releaseCurrentContext() {
   if (notCurrent) {
     try {
       context.release();
       System.out.println("Released context");
     } catch (final GLException gle) {
       gle.printStackTrace();
     }
   }
 }
Example #10
0
  // ------------------------------------------------------------
  // GLEventListener
  public void init(GLAutoDrawable drawable) {
    if (debugging) drawable.setGL(new DebugGL(drawable.getGL()));

    try {
      // Specify new projection for this window
      init(drawable.getGL());
    } catch (GLException e) {
      e.printStackTrace();
    }
  }
 public void uglyjoglhack() throws InterruptedException {
   try {
     rdr = true;
     display();
   } catch (GLException e) {
     if (e.getCause() instanceof InterruptedException) {
       throw ((InterruptedException) e.getCause());
     } else {
       e.printStackTrace();
       throw (e);
     }
   } finally {
     rdr = false;
   }
 }
Example #12
0
  private boolean mapAvailableEGLESConfig(
      AbstractGraphicsDevice adevice,
      int esProfile,
      boolean[] hasPBuffer,
      GLRendererQuirks[] rendererQuirks,
      int[] ctp) {
    final String profileString;
    switch (esProfile) {
      case 3:
        profileString = GLProfile.GLES3;
        break;
      case 2:
        profileString = GLProfile.GLES2;
        break;
      case 1:
        profileString = GLProfile.GLES1;
        break;
      default:
        throw new GLException("Invalid ES profile number " + esProfile);
    }
    if (!GLProfile.isAvailable(adevice, profileString)) {
      if (DEBUG) {
        System.err.println(
            "EGLDrawableFactory.mapAvailableEGLESConfig: " + profileString + " n/a on " + adevice);
      }
      return false;
    }
    final GLProfile glp = GLProfile.get(adevice, profileString);
    final GLDrawableFactoryImpl desktopFactory =
        (GLDrawableFactoryImpl) GLDrawableFactory.getDesktopFactory();
    final boolean mapsADeviceToDefaultDevice =
        !QUERY_EGL_ES_NATIVE_TK || null == desktopFactory || adevice instanceof EGLGraphicsDevice;
    if (DEBUG) {
      System.err.println(
          "EGLDrawableFactory.mapAvailableEGLESConfig: "
              + profileString
              + " ( "
              + esProfile
              + " ), "
              + "defaultSharedResourceSet "
              + (null != defaultSharedResource)
              + ", mapsADeviceToDefaultDevice "
              + mapsADeviceToDefaultDevice
              + " (QUERY_EGL_ES_NATIVE_TK "
              + QUERY_EGL_ES_NATIVE_TK
              + ", hasDesktopFactory "
              + (null != desktopFactory)
              + ", isEGLGraphicsDevice "
              + (adevice instanceof EGLGraphicsDevice)
              + ")");
    }

    EGLGraphicsDevice eglDevice = null;
    NativeSurface surface = null;
    ProxySurface upstreamSurface = null; // X11, GLX, ..
    boolean success = false;
    boolean deviceFromUpstreamSurface = false;
    try {
      final GLCapabilities reqCapsAny = new GLCapabilities(glp);
      reqCapsAny.setRedBits(5);
      reqCapsAny.setGreenBits(5);
      reqCapsAny.setBlueBits(5);
      reqCapsAny.setAlphaBits(0);
      reqCapsAny.setDoubleBuffered(false);

      if (mapsADeviceToDefaultDevice) {
        // In this branch, any non EGL device is mapped to EGL default shared resources (default
        // behavior).
        // Only one default shared resource instance is ever be created.
        final GLCapabilitiesImmutable reqCapsPBuffer =
            GLGraphicsConfigurationUtil.fixGLPBufferGLCapabilities(reqCapsAny);
        final List<GLCapabilitiesImmutable> availablePBufferCapsL =
            getAvailableEGLConfigs(defaultDevice, reqCapsPBuffer);
        hasPBuffer[0] = availablePBufferCapsL.size() > 0;

        // 1st case: adevice is not the EGL default device, map default shared resources
        if (adevice != defaultDevice) {
          if (null == defaultSharedResource) {
            return false;
          }
          switch (esProfile) {
            case 3:
              if (!defaultSharedResource.wasES3ContextCreated) {
                return false;
              }
              rendererQuirks[0] = defaultSharedResource.rendererQuirksES3ES2;
              ctp[0] = defaultSharedResource.ctpES3ES2;
              break;
            case 2:
              if (!defaultSharedResource.wasES2ContextCreated) {
                return false;
              }
              rendererQuirks[0] = defaultSharedResource.rendererQuirksES3ES2;
              ctp[0] = defaultSharedResource.ctpES3ES2;
              break;
            case 1:
              if (!defaultSharedResource.wasES1ContextCreated) {
                return false;
              }
              rendererQuirks[0] = defaultSharedResource.rendererQuirksES1;
              ctp[0] = defaultSharedResource.ctpES1;
              break;
          }
          EGLContext.mapStaticGLVersion(adevice, esProfile, 0, ctp[0]);
          return true;
        }

        // attempt to created the default shared resources ..

        eglDevice = defaultDevice; // reuse

        if (hasPBuffer[0]) {
          // 2nd case create defaultDevice shared resource using pbuffer surface
          surface =
              createDummySurfaceImpl(
                  eglDevice,
                  false,
                  reqCapsPBuffer,
                  reqCapsPBuffer,
                  null,
                  64,
                  64); // egl pbuffer offscreen
          upstreamSurface = (ProxySurface) surface;
          upstreamSurface.createNotify();
          deviceFromUpstreamSurface = false;
        } else {
          // 3rd case fake creation of defaultDevice shared resource, no pbuffer available
          final List<GLCapabilitiesImmutable> capsAnyL =
              getAvailableEGLConfigs(eglDevice, reqCapsAny);
          if (capsAnyL.size() > 0) {
            final GLCapabilitiesImmutable chosenCaps = capsAnyL.get(0);
            EGLContext.mapStaticGLESVersion(eglDevice, chosenCaps);
            success = true;
          }
          if (DEBUG) {
            System.err.println(
                "EGLDrawableFactory.mapAvailableEGLESConfig() no pbuffer config available, detected !pbuffer config: "
                    + success);
            EGLGraphicsConfigurationFactory.printCaps("!PBufferCaps", capsAnyL, System.err);
          }
        }
      } else {
        // 4th case always creates a true mapping of given device to EGL
        surface =
            desktopFactory.createDummySurface(
                adevice, reqCapsAny, null, 64, 64); // X11, WGL, .. dummy window
        upstreamSurface = (surface instanceof ProxySurface) ? (ProxySurface) surface : null;
        if (null != upstreamSurface) {
          upstreamSurface.createNotify();
        }
        eglDevice = EGLDisplayUtil.eglCreateEGLGraphicsDevice(surface);
        deviceFromUpstreamSurface = true;
        hasPBuffer[0] = true;
      }

      if (null != surface) {
        final EGLDrawable drawable =
            (EGLDrawable)
                createOnscreenDrawableImpl(
                    surface); // works w/ implicit pbuffer surface via proxy-hook
        drawable.setRealized(true);
        final EGLContext context = (EGLContext) drawable.createContext(null);
        if (null != context) {
          try {
            context.makeCurrent(); // could cause exception
            if (context.isCurrent()) {
              final String glVersion = context.getGL().glGetString(GL.GL_VERSION);
              if (null != glVersion) {
                context.mapCurrentAvailableGLVersion(eglDevice);
                if (eglDevice != adevice) {
                  context.mapCurrentAvailableGLVersion(adevice);
                }
                rendererQuirks[0] = context.getRendererQuirks();
                ctp[0] = context.getContextOptions();
                success = true;
              } else {
                // Oops .. something is wrong
                if (DEBUG) {
                  System.err.println(
                      "EGLDrawableFactory.mapAvailableEGLESConfig: "
                          + eglDevice
                          + ", "
                          + context.getGLVersion()
                          + " - VERSION is null, dropping availability!");
                }
              }
            }
          } catch (GLException gle) {
            if (DEBUG) {
              System.err.println(
                  "EGLDrawableFactory.mapAvailableEGLESConfig: INFO: context create/makeCurrent failed");
              gle.printStackTrace();
            }
          } finally {
            context.destroy();
          }
        }
        drawable.setRealized(false);
      }
    } catch (Throwable t) {
      if (DEBUG) {
        System.err.println("Catched Exception on thread " + getThreadName());
        t.printStackTrace();
      }
      success = false;
    } finally {
      if (eglDevice == defaultDevice) {
        if (null != upstreamSurface) {
          upstreamSurface.destroyNotify();
        }
      } else if (deviceFromUpstreamSurface) {
        if (null != eglDevice) {
          eglDevice.close();
        }
        if (null != upstreamSurface) {
          upstreamSurface.destroyNotify();
        }
      } else {
        if (null != upstreamSurface) {
          upstreamSurface.destroyNotify();
        }
        if (null != eglDevice) {
          eglDevice.close();
        }
      }
    }
    return success;
  }
Example #13
0
  public EGLDrawableFactory() {
    super();

    // Register our GraphicsConfigurationFactory implementations
    // The act of constructing them causes them to be registered
    EGLGraphicsConfigurationFactory.registerFactory();

    // Check for other underlying stuff ..
    if (NativeWindowFactory.TYPE_X11 == NativeWindowFactory.getNativeWindowType(true)) {
      hasX11 = true;
      try {
        ReflectionUtil.createInstance(
            "jogamp.opengl.x11.glx.X11GLXGraphicsConfigurationFactory",
            EGLDrawableFactory.class.getClassLoader());
      } catch (Exception jre) {
        /* n/a .. */
      }
    }

    // FIXME: Probably need to move EGL from a static model
    // to a dynamic one, where there can be 2 instances
    // for each ES profile with their own ProcAddressTable.

    synchronized (EGLDrawableFactory.class) {
      final boolean hasDesktopES2 = null != eglES2DynamicLookupHelper;

      if (!hasDesktopES2 && null == eglES1DynamicLookupHelper) {
        GLDynamicLookupHelper tmp = null;
        try {
          tmp = new GLDynamicLookupHelper(new EGLES1DynamicLibraryBundleInfo());
        } catch (GLException gle) {
          if (DEBUG) {
            gle.printStackTrace();
          }
        }
        if (null != tmp && tmp.isLibComplete()) {
          eglES1DynamicLookupHelper = tmp;
          EGL.resetProcAddressTable(eglES1DynamicLookupHelper);
          final boolean isANGLEES1 = isANGLE(eglES1DynamicLookupHelper);
          isANGLE |= isANGLEES1;
          if (DEBUG || GLProfile.DEBUG) {
            System.err.println("Info: EGLDrawableFactory: EGL ES1 - OK, isANGLE: " + isANGLEES1);
          }
        } else if (DEBUG || GLProfile.DEBUG) {
          System.err.println("Info: EGLDrawableFactory: EGL ES1 - NOPE (ES1 lib)");
        }
      }
      if (!hasDesktopES2 && null == eglES2DynamicLookupHelper) {
        GLDynamicLookupHelper tmp = null;
        try {
          tmp = new GLDynamicLookupHelper(new EGLES2DynamicLibraryBundleInfo());
        } catch (GLException gle) {
          if (DEBUG) {
            gle.printStackTrace();
          }
        }
        if (null != tmp && tmp.isLibComplete()) {
          eglES2DynamicLookupHelper = tmp;
          EGL.resetProcAddressTable(eglES2DynamicLookupHelper);
          final boolean includesES1 =
              null == eglES1DynamicLookupHelper && includesES1(eglES2DynamicLookupHelper);
          if (includesES1) {
            eglES1DynamicLookupHelper = tmp;
          }
          final boolean isANGLEES2 = isANGLE(eglES2DynamicLookupHelper);
          isANGLE |= isANGLEES2;
          if (DEBUG || GLProfile.DEBUG) {
            System.err.println(
                "Info: EGLDrawableFactory: EGL ES2 - OK (includesES1 "
                    + includesES1
                    + ", isANGLE: "
                    + isANGLEES2
                    + ")");
            if (includesES1) {
              System.err.println("Info: EGLDrawableFactory: EGL ES1 - OK (ES2 lib)");
            }
          }
        } else if (DEBUG || GLProfile.DEBUG) {
          System.err.println("Info: EGLDrawableFactory: EGL ES2 - NOPE");
        }
      }
      if (null != eglES2DynamicLookupHelper || null != eglES1DynamicLookupHelper) {
        if (isANGLE && !enableANGLE) {
          if (DEBUG || GLProfile.DEBUG) {
            System.err.println("Info: EGLDrawableFactory.init - EGL/ES2 ANGLE disabled");
          }
        } else {
          if (isANGLE && (DEBUG || GLProfile.DEBUG)) {
            System.err.println("Info: EGLDrawableFactory.init - EGL/ES2 ANGLE enabled");
          }
          sharedMap = new HashMap<String /*uniqueKey*/, SharedResource>();
          sharedMapCreateAttempt = new HashSet<String>();

          // FIXME: Following triggers eglInitialize(..) which crashed on Windows w/ Chrome/Angle,
          // FF/Angle!
          defaultDevice =
              EGLDisplayUtil.eglCreateEGLGraphicsDevice(
                  EGL.EGL_DEFAULT_DISPLAY,
                  AbstractGraphicsDevice.DEFAULT_CONNECTION,
                  AbstractGraphicsDevice.DEFAULT_UNIT);
        }
      }
    }
  }
  @Test
  public void compileShader() throws InterruptedException {
    GLProfile glp = GLProfile.get(GLProfile.GL2GL3);
    GLCapabilities caps = new GLCapabilities(glp);
    // commenting out this line makes it work
    caps.setStencilBits(8);

    // commenting in this line also makes it work
    // caps.setSampleBuffers(true);

    final Frame frame = new Frame("Bug 459 shader compilation test");
    Assert.assertNotNull(frame);

    final GLCanvas glCanvas = new GLCanvas(caps);
    Assert.assertNotNull(glCanvas);
    frame.add(glCanvas);

    glCanvas.addGLEventListener(
        new GLEventListener() {
          /* @Override */
          public void init(GLAutoDrawable drawable) {
            String code = "void main(void){gl_Position = vec4(0,0,0,1);}";

            GL2GL3 gl = drawable.getGL().getGL2GL3();
            int id = gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER);

            try {
              gl.glShaderSource(id, 1, new String[] {code}, (int[]) null, 0);
              gl.glCompileShader(id);

              int[] compiled = new int[1];
              gl.glGetShaderiv(id, GL2GL3.GL_COMPILE_STATUS, compiled, 0);
              if (compiled[0] == GL2GL3.GL_FALSE) {
                int[] logLength = new int[1];
                gl.glGetShaderiv(id, GL2GL3.GL_INFO_LOG_LENGTH, logLength, 0);

                byte[] log = new byte[logLength[0]];
                gl.glGetShaderInfoLog(id, logLength[0], (int[]) null, 0, log, 0);

                System.err.println("Error compiling the shader: " + new String(log));

                gl.glDeleteShader(id);
              } else {
                System.out.println("Shader compiled: id=" + id);
              }
            } catch (GLException e) {
              glexception = e;
            }
          }

          /* @Override */
          public void dispose(GLAutoDrawable drawable) {}

          /* @Override */
          public void display(GLAutoDrawable drawable) {}

          /* @Override */
          public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
        });

    Animator animator = new Animator(glCanvas);
    try {
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.setSize(512, 512);
              frame.setVisible(true);
            }
          });
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
    animator.setUpdateFPSFrames(1, null);
    animator.start();

    while (animator.isAnimating() && animator.getTotalFPSDuration() < duration) {
      Thread.sleep(100);
    }

    Assert.assertTrue(glexception != null ? glexception.getMessage() : "", glexception == null);
    Assert.assertNotNull(frame);
    Assert.assertNotNull(glCanvas);
    Assert.assertNotNull(animator);

    animator.stop();
    Assert.assertEquals(false, animator.isAnimating());
    try {
      javax.swing.SwingUtilities.invokeAndWait(
          new Runnable() {
            public void run() {
              frame.setVisible(false);
              frame.remove(glCanvas);
              frame.dispose();
            }
          });
    } catch (Throwable throwable) {
      throwable.printStackTrace();
      Assume.assumeNoException(throwable);
    }
  }
Example #15
0
  @Override
  protected boolean createImpl(GLContextImpl shareWith) throws GLException {
    final EGLGraphicsConfiguration config =
        (EGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration();
    final long eglDisplay = config.getScreen().getDevice().getHandle();
    final GLProfile glProfile = drawable.getGLProfile();
    final long eglConfig = config.getNativeConfig();
    long shareWithHandle = EGL.EGL_NO_CONTEXT;

    if (0 == eglDisplay) {
      throw new GLException(
          "Error: attempted to create an OpenGL context without a display connection");
    }
    if (0 == eglConfig) {
      throw new GLException(
          "Error: attempted to create an OpenGL context without a graphics configuration");
    }

    try {
      // might be unavailable on EGL < 1.2
      if (!EGL.eglBindAPI(EGL.EGL_OPENGL_ES_API)) {
        throw new GLException(
            "Catched: eglBindAPI to ES failed , error 0x" + Integer.toHexString(EGL.eglGetError()));
      }
    } catch (GLException glex) {
      if (DEBUG) {
        glex.printStackTrace();
      }
    }

    if (shareWith != null) {
      shareWithHandle = shareWith.getHandle();
      if (shareWithHandle == 0) {
        throw new GLException("GLContextShareSet returned an invalid OpenGL context");
      }
    }

    final IntBuffer contextAttrsNIO;
    {
      final int[] contextAttrs = new int[] {EGL.EGL_CONTEXT_CLIENT_VERSION, -1, EGL.EGL_NONE};
      if (glProfile.usesNativeGLES2()) {
        contextAttrs[1] = 2;
      } else if (glProfile.usesNativeGLES1()) {
        contextAttrs[1] = 1;
      } else {
        throw new GLException("Error creating OpenGL context - invalid GLProfile: " + glProfile);
      }
      contextAttrsNIO = Buffers.newDirectIntBuffer(contextAttrs);
    }
    contextHandle = EGL.eglCreateContext(eglDisplay, eglConfig, shareWithHandle, contextAttrsNIO);
    if (contextHandle == 0) {
      throw new GLException(
          "Error creating OpenGL context: eglDisplay "
              + toHexString(eglDisplay)
              + ", eglConfig "
              + config
              + ", "
              + glProfile
              + ", shareWith "
              + toHexString(shareWithHandle)
              + ", error "
              + toHexString(EGL.eglGetError()));
    }
    if (DEBUG) {
      System.err.println(
          getThreadName()
              + ": Created OpenGL context 0x"
              + Long.toHexString(contextHandle)
              + ",\n\twrite surface 0x"
              + Long.toHexString(drawable.getHandle())
              + ",\n\tread  surface 0x"
              + Long.toHexString(drawableRead.getHandle())
              + ",\n\t"
              + this
              + ",\n\tsharing with 0x"
              + Long.toHexString(shareWithHandle));
    }
    if (!EGL.eglMakeCurrent(
        eglDisplay, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) {
      throw new GLException(
          "Error making context "
              + toHexString(contextHandle)
              + " current: error code "
              + toHexString(EGL.eglGetError()));
    }
    setGLFunctionAvailability(true, glProfile.usesNativeGLES2() ? 2 : 1, 0, CTX_PROFILE_ES);
    return true;
  }