@Test
 public void test01_DefaultNorm()
     throws AWTException, InterruptedException, InvocationTargetException {
   final GLProfile glp;
   if (forceGL3) {
     glp = GLProfile.get(GLProfile.GL3);
   } else if (forceES3) {
     glp = GLProfile.get(GLProfile.GLES3);
   } else if (forceES2) {
     glp = GLProfile.get(GLProfile.GLES2);
   } else if (forceGLFFP) {
     glp = GLProfile.getMaxFixedFunc(true);
   } else {
     glp = GLProfile.getDefault();
   }
   final GLCapabilities caps = new GLCapabilities(glp);
   if (useMSAA) {
     caps.setNumSamples(msaaNumSamples);
     caps.setSampleBuffers(true);
   }
   if (shallUsePBuffer) {
     caps.setPBuffer(true);
   }
   if (shallUseBitmap) {
     caps.setBitmap(true);
   }
   runTestGL(caps);
 }
 @Test
 public void test02_DefaultMsaa()
     throws AWTException, InterruptedException, InvocationTargetException {
   if (manualTest) {
     return;
   }
   final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
   caps.setNumSamples(4);
   caps.setSampleBuffers(true);
   runTestGL(caps);
 }
Exemple #3
0
 /** Returns the default, desired OpenGL capabilities needed for this component. */
 public static GLCapabilities getDefaultCapabalities() {
   GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES1());
   caps.setRedBits(8);
   caps.setGreenBits(8);
   caps.setBlueBits(8);
   caps.setAlphaBits(8);
   caps.setDoubleBuffered(true);
   caps.setHardwareAccelerated(true);
   caps.setNumSamples(4);
   caps.setBackgroundOpaque(false);
   caps.setSampleBuffers(true);
   return caps;
 }
Exemple #4
0
 public void setSmooth(int level) {
   pgl.reqNumSamples = level;
   GLCapabilities caps = new GLCapabilities(profile);
   caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
   caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
   caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
   caps.setSampleBuffers(true);
   caps.setNumSamples(pgl.reqNumSamples);
   caps.setBackgroundOpaque(true);
   caps.setOnscreen(true);
   NativeSurface target = window.getNativeSurface();
   MutableGraphicsConfiguration config =
       (MutableGraphicsConfiguration) target.getGraphicsConfiguration();
   config.setChosenCapabilities(caps);
 }
Exemple #5
0
  protected void initGL() {
    //  System.out.println("*******************************");
    if (profile == null) {
      if (PJOGL.profile == 2) {
        try {
          profile = GLProfile.getGL2ES2();
        } catch (GLException ex) {
          profile = GLProfile.getMaxProgrammable(true);
        }
      } else if (PJOGL.profile == 3) {
        try {
          profile = GLProfile.getGL2GL3();
        } catch (GLException ex) {
          profile = GLProfile.getMaxProgrammable(true);
        }
        if (!profile.isGL3()) {
          PGraphics.showWarning("Requested profile GL3 but is not available, got: " + profile);
        }
      } else if (PJOGL.profile == 4) {
        try {
          profile = GLProfile.getGL4ES3();
        } catch (GLException ex) {
          profile = GLProfile.getMaxProgrammable(true);
        }
        if (!profile.isGL4()) {
          PGraphics.showWarning("Requested profile GL4 but is not available, got: " + profile);
        }
      } else throw new RuntimeException(PGL.UNSUPPORTED_GLPROF_ERROR);
    }

    // Setting up the desired capabilities;
    GLCapabilities caps = new GLCapabilities(profile);
    caps.setAlphaBits(PGL.REQUESTED_ALPHA_BITS);
    caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
    caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);

    //  caps.setPBuffer(false);
    //  caps.setFBO(false);

    pgl.reqNumSamples = PGL.smoothToSamples(graphics.smooth);
    caps.setSampleBuffers(true);
    caps.setNumSamples(pgl.reqNumSamples);
    caps.setBackgroundOpaque(true);
    caps.setOnscreen(true);
    pgl.capabilities = caps;
  }
  protected void initGLCanvas() {
    loadNatives();

    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

    // FIXME use the settings to know whether to use the max programmable profile
    // then call GLProfile.getMaxProgrammable(true);
    GLCapabilities caps = new GLCapabilities(GLProfile.getMaxFixedFunc(true));
    caps.setHardwareAccelerated(true);
    caps.setDoubleBuffered(true);
    caps.setStencilBits(settings.getStencilBits());
    caps.setDepthBits(settings.getDepthBits());

    if (settings.getSamples() > 1) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(settings.getSamples());
    }

    canvas =
        new GLCanvas(caps) {
          @Override
          public void addNotify() {
            super.addNotify();
            onCanvasAdded();
          }

          @Override
          public void removeNotify() {
            onCanvasRemoved();
            super.removeNotify();
          }
        };
    canvas.invoke(
        false,
        new GLRunnable() {
          public boolean run(GLAutoDrawable glad) {
            canvas.getGL().setSwapInterval(settings.isVSync() ? 1 : 0);
            return true;
          }
        });
    canvas.setFocusable(true);
    canvas.requestFocus();
    canvas.setSize(settings.getWidth(), settings.getHeight());
    canvas.setIgnoreRepaint(true);
    canvas.addGLEventListener(this);

    // FIXME not sure it is the best place to do that
    renderable.set(true);

    // TODO remove this block once for all when the unified renderer is stable
    /*if (settings.getBoolean("GraphicsDebug")) {
        canvas.invoke(false, new GLRunnable() {
            public boolean run(GLAutoDrawable glad) {
                GL gl = glad.getGL();
                if (gl.isGLES()) {
                    if (gl.isGLES1()) {
                        glad.setGL(new DebugGLES1(gl.getGLES1()));
                    } else {
                        if (gl.isGLES2()) {
                            glad.setGL(new DebugGLES2(gl.getGLES2()));
                        } else {
                            if (gl.isGLES3()) {
                            	glad.setGL(new DebugGLES3(gl.getGLES3()));
                            }
                        }
                    }
                } else {
                    if (gl.isGL4bc()) {
                        glad.setGL(new DebugGL4bc(gl.getGL4bc()));
                    } else {
                        if (gl.isGL4()) {
                            glad.setGL(new DebugGL4(gl.getGL4()));
                        } else {
                            if (gl.isGL3bc()) {
                                glad.setGL(new DebugGL3bc(gl.getGL3bc()));
                            } else {
                                if (gl.isGL3()) {
                                    glad.setGL(new DebugGL3(gl.getGL3()));
                                } else {
                                    if (gl.isGL2()) {
                                        glad.setGL(new DebugGL2(gl.getGL2()));
                                    }
                                }
                            }
                        }
                    }
                }
                return true;
            }
        });
    }

    renderer = new JoglRenderer();

    canvas.invoke(false, new GLRunnable() {
        public boolean run(GLAutoDrawable glad) {
            renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
            return true;
        }
    });*/
  }
  public void testImpl() throws InterruptedException {
    final JFrame frame = new JFrame(this.getSimpleTestName("."));

    //
    // GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.get(GLProfile.GL2));
    // GLContext sharedContext = factory.getOrCreateSharedContext(factory.getDefaultDevice());
    //
    final GLCapabilities glCapabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2));
    glCapabilities.setSampleBuffers(true);
    glCapabilities.setNumSamples(4);

    final GearsES2 eventListener1 = new GearsES2(0);
    final GearsES2 eventListener2 = new GearsES2(1);

    final Component openGLComponent1;
    final Component openGLComponent2;
    final GLAutoDrawable openGLAutoDrawable1;
    final GLAutoDrawable openGLAutoDrawable2;

    final GLWindow glWindow1 = GLWindow.create(glCapabilities);
    final NewtCanvasAWT newtCanvasAWT1 = new NewtCanvasAWT(glWindow1);
    newtCanvasAWT1.setPreferredSize(new Dimension(640, 480));
    glWindow1.addGLEventListener(eventListener1);
    //
    final GLWindow glWindow2 = GLWindow.create(glCapabilities);
    final NewtCanvasAWT newtCanvasAWT2 = new NewtCanvasAWT(glWindow2);
    newtCanvasAWT2.setPreferredSize(new Dimension(640, 480));
    glWindow2.addGLEventListener(eventListener2);

    openGLComponent1 = newtCanvasAWT1;
    openGLComponent2 = newtCanvasAWT2;
    openGLAutoDrawable1 = glWindow1;
    openGLAutoDrawable2 = glWindow2;

    // group both OpenGL canvases / windows into a horizontal panel
    final JPanel openGLPanel = new JPanel();
    openGLPanel.setLayout(new BoxLayout(openGLPanel, BoxLayout.LINE_AXIS));
    openGLPanel.add(openGLComponent1);
    openGLPanel.add(Box.createHorizontalStrut(5));
    openGLPanel.add(openGLComponent2);

    final JPanel mainPanel = (JPanel) frame.getContentPane();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.LINE_AXIS));
    mainPanel.add(Box.createHorizontalGlue());
    mainPanel.add(openGLPanel);
    mainPanel.add(Box.createHorizontalGlue());

    final Animator animator = new Animator(Thread.currentThread().getThreadGroup());
    animator.setUpdateFPSFrames(1, null);
    animator.add(openGLAutoDrawable1);
    animator.add(openGLAutoDrawable2);

    // make the window visible using the EDT
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            frame.pack();
            frame.setVisible(true);
          }
        });

    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, true));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, true));

    animator.start();

    // sleep for test duration, then request the window to close, wait for the window to close,s and
    // stop the animation
    while (animator.isAnimating() && animator.getTotalFPSDuration() < durationPerTest) {
      Thread.sleep(100);
    }

    animator.stop();

    // ask the EDT to dispose of the frame;
    // if using newt, explicitly dispose of the canvases because otherwise it seems our destroy
    // methods are not called
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            newtCanvasAWT1.destroy(); // removeNotify does not destroy GLWindow
            newtCanvasAWT2.destroy(); // removeNotify does not destroy GLWindow
            frame.dispose();
          }
        });
    Assert.assertEquals(true, AWTRobotUtil.waitForVisible(frame, false));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent1, false));
    Assert.assertEquals(true, AWTRobotUtil.waitForRealized(openGLComponent2, false));
  }