示例#1
0
 protected GLCapabilities createCapabilities() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   caps.setStencilBits(1);
   caps.setDoubleBuffered(true);
   caps.setAlphaBits(8);
   return caps;
 }
  @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);
    }
  }