Ejemplo n.º 1
0
 @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);
 }
 static GLCapabilities getCaps(final String profile) {
   if (!GLProfile.isAvailable(profile)) {
     System.err.println("Profile " + profile + " n/a");
     return null;
   }
   return new GLCapabilities(GLProfile.get(profile));
 }
Ejemplo n.º 3
0
 @BeforeClass
 public static void initClass() {
   if (GLProfile.isAvailable(GLProfile.GL2ES2)) {
     glp = GLProfile.get(GLProfile.GL2ES2);
     Assert.assertNotNull(glp);
     caps = new GLCapabilities(glp);
     Assert.assertNotNull(caps);
     width = 256;
     height = 256;
   } else {
     setTestSupported(false);
   }
 }
Ejemplo n.º 4
0
  @Test
  public void test40_GL3() throws AWTException, InterruptedException, InvocationTargetException {
    if (manualTest) {
      return;
    }

    if (!GLProfile.isAvailable(GLProfile.GL3)) {
      System.err.println("GL3 n/a");
      return;
    }
    final GLProfile glp = GLProfile.get(GLProfile.GL3);
    final GLCapabilities caps = new GLCapabilities(glp);
    runTestGL(caps);
  }
Ejemplo n.º 5
0
  /** Default constructor for the window */
  public ExampleJOGL() {
    super("JOGL Example");

    // setup the JFrame
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create the size of the window
    Dimension size = new Dimension(800, 600);

    // setup OpenGL capabilities
    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
    caps.setDoubleBuffered(true);
    caps.setHardwareAccelerated(true);

    // create a canvas to paint to
    this.canvas = new GLCanvas(caps);
    this.canvas.setPreferredSize(size);
    this.canvas.setMinimumSize(size);
    this.canvas.setMaximumSize(size);
    this.canvas.setIgnoreRepaint(true);
    this.canvas.addGLEventListener(this);

    // add the canvas to the JFrame
    this.add(this.canvas);

    // make the JFrame not resizable
    // (this way I dont have to worry about resize events)
    this.setResizable(false);

    // size everything
    this.pack();

    // setup the world
    this.initializeWorld();
  }
Ejemplo n.º 6
0
  public static void main(String[] args) {

    Display display = NewtFactory.createDisplay(null);
    Screen screen = NewtFactory.createScreen(display, 0);
    GLProfile glProfile = GLProfile.get(GLProfile.GL3);
    GLCapabilities glCapabilities = new GLCapabilities(glProfile);
    glWindow = GLWindow.create(screen, glCapabilities);

    glWindow.setSize(1024, 768);
    glWindow.setPosition(50, 50);
    glWindow.setUndecorated(false);
    glWindow.setAlwaysOnTop(false);
    glWindow.setFullscreen(false);
    glWindow.setPointerVisible(true);
    glWindow.confinePointer(false);
    glWindow.setTitle("Hello Triangle");

    glWindow.setVisible(true);

    HelloTriangle helloTriangle = new HelloTriangle();
    glWindow.addGLEventListener(helloTriangle);
    glWindow.addKeyListener(helloTriangle);

    animator = new Animator(glWindow);
    animator.start();
  }
 protected void loadTexture() {
   try {
     BufferedImage image = ImageIO.read(new File("images/raindrop.png"));
     texture = AWTTextureIO.newTexture(GLProfile.getDefault(), image, true);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 8
0
  public static void main(String[] args) {
    GLProfile.initSingleton();

    EventQueue.invokeLater(
        () -> {
          MyFrame f = new MyFrame();
          f.setVisible(true);
        });
  }
Ejemplo n.º 9
0
 @Test
 public void test05_BitmapNorm()
     throws AWTException, InterruptedException, InvocationTargetException {
   if (manualTest) {
     return;
   }
   final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
   caps.setBitmap(true);
   runTestGL(caps);
 }
Ejemplo n.º 10
0
 @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);
 }
Ejemplo n.º 11
0
  @Test
  public void test99_PixelScale1_DefaultNorm()
      throws AWTException, InterruptedException, InvocationTargetException {
    if (manualTest) {
      return;
    }
    reqSurfacePixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
    reqSurfacePixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;

    final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
    runTestGL(caps);
  }
Ejemplo n.º 12
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;
 }
Ejemplo n.º 13
0
  public MyFrame() {
    glprof_ = GLProfile.getDefault();
    glcap_ = new GLCapabilities(glprof_);

    camera_ = new Camera();
    light_ = new Light();

    terrain_ = new Terrain();

    input_ = new Input();

    initUI();
  }
Ejemplo n.º 14
0
Archivo: Main.java Proyecto: io7m/r2
  /**
   * Main program.
   *
   * @param args Command line arguments
   * @throws Exception On errors
   */
  public static void main(final String[] args) throws Exception {
    if (args.length != 3 && args.length != 4) {
      Main.LOG.info("usage: root file.vert [file.geom] file.frag");
      System.exit(1);
    }

    final File root = new File(args[0]);

    final R2ShaderPreprocessorType p = R2ShaderPreprocessor.newPreprocessor(root);

    List<String> vs = null;
    Optional<List<String>> gs = null;
    List<String> fs = null;

    try {
      if (args.length == 4) {
        vs = p.preprocessFile(args[1]);
        gs = Optional.of(p.preprocessFile(args[2]));
        fs = p.preprocessFile(args[3]);
      } else {
        vs = p.preprocessFile(args[1]);
        gs = Optional.empty();
        fs = p.preprocessFile(args[2]);
      }
    } catch (final Exception e) {
      Main.LOG.error("Preprocessing failure: ", e);
      System.exit(1);
    }

    final GLProfile pro = GLProfile.get(GLProfile.GL3);
    final GLCapabilities caps = new GLCapabilities(pro);
    final GLDrawableFactory f = GLDrawableFactory.getFactory(pro);
    final GLOffscreenAutoDrawable drawable =
        f.createOffscreenAutoDrawable(null, caps, null, 32, 32);
    drawable.display();
    final GLContext ctx = drawable.getContext();
    ctx.makeCurrent();

    try {
      final JCGLImplementationJOGLType i = JCGLImplementationJOGL.getInstance();
      final JCGLContextType jc = i.newContextFrom(ctx, "offscreen");
      final JCGLInterfaceGL33Type gi = jc.contextGetGL33();
      final R2ShaderCheckerType ch = R2ShaderChecker.newChecker(gi.getShaders());

      ch.check(vs, gs, fs);
    } finally {
      ctx.release();
      drawable.destroy();
    }
  }
Ejemplo n.º 15
0
  @Override
  public void run() {
    // // Necessary to load the native libraries correctly (see
    // //
    // http://forum.jogamp.org/Return-of-the-quot-java-lang-UnsatisfiedLinkError-Can-t-load-library-System-Library-Frameworks-glueg-td4034549.html)
    JarUtil.setResolver(
        new JarUtil.Resolver() {

          @Override
          public URL resolve(final URL url) {
            try {
              final URL urlUnescaped = FileLocator.resolve(url);
              final URL urlEscaped =
                  new URI(urlUnescaped.getProtocol(), urlUnescaped.getPath(), null).toURL();
              return urlEscaped;
            } catch (final IOException ioexception) {
              return url;
            } catch (final URISyntaxException urisyntaxexception) {
              return url;
            }
          }
        });

    // Necessary to initialize very early because initializing it
    // while opening a Java2D view before leads to a deadlock
    GLProfile.initSingleton();
    while (!GLProfile.isInitialized()) {
      try {
        Thread.sleep(100);
      } catch (final InterruptedException e) {
        e.printStackTrace();
      }
    }

    isInitialized = true;
  }
Ejemplo n.º 16
0
  void test01GLDebug01EnableDisable(final boolean enable) throws InterruptedException {
    final GLProfile glp = GLProfile.getDefault();

    final WindowContext winctx = createWindow(glp, enable);
    final String glDebugExt = winctx.context.getGLDebugMessageExtension();
    System.err.println("glDebug extension: " + glDebugExt);
    System.err.println("glDebug enabled: " + winctx.context.isGLDebugMessageEnabled());
    System.err.println("glDebug sync: " + winctx.context.isGLDebugSynchronous());
    System.err.println("context version: " + winctx.context.getGLVersion());

    Assert.assertEquals(
        (null == glDebugExt) ? false : enable, winctx.context.isGLDebugMessageEnabled());

    destroyWindow(winctx);
  }
Ejemplo n.º 17
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;
  }
Ejemplo n.º 18
0
 public FirstStepNewtLast() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   GLWindow glWindow = GLWindow.create(caps);
   glWindow.setTitle("First demo (Newt)");
   glWindow.setSize(300, 300);
   glWindow.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowDestroyed(WindowEvent arg0) {
           System.exit(0);
         }
       });
   glWindow.addGLEventListener(this);
   FPSAnimator animator = new FPSAnimator(10); // (2)
   animator.add(glWindow);
   animator.start();
   glWindow.setVisible(true);
 }
Ejemplo n.º 19
0
  public static void main(String[] args) {
    GLProfile glp = GLProfile.getDefault();
    GLCapabilities caps = new GLCapabilities(glp);
    GLCanvas canvas = new GLCanvas(caps);
    cube unCube = new cube();
    canvas.addGLEventListener(unCube);
    Frame frame = new Frame("AWT Window Test");
    FPSAnimator anim = new FPSAnimator(canvas, 60);
    anim.start();
    frame.setSize(400, 400);
    frame.add(canvas);
    frame.setVisible(true);

    frame.addKeyListener(
        new KeyListener() {

          @Override
          public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
            int keyCode = e.getKeyCode();
            unCube.handleKeyPress(keyCode); // Here is the handleKeyPress function's call
            frame.add(canvas);
          }

          @Override
          public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub

          }

          @Override
          public void keyTyped(KeyEvent e) {
            // TODO Auto-generated method stub

          }
        });

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
  public static void main(String[] args) {
    GLProfile glprofile = GLProfile.getDefault();
    GLCapabilities glcapabilities = new GLCapabilities(glprofile);
    final GLCanvas glcanvas = new GLCanvas(glcapabilities);

    glcanvas.addGLEventListener(
        new GLEventListener() {

          @Override
          public void reshape(GLAutoDrawable glautodrawable, int x, int y, int width, int height) {
            OneTriangle.setup(glautodrawable.getGL().getGL2(), width, height);
          }

          @Override
          public void init(GLAutoDrawable glautodrawable) {}

          @Override
          public void dispose(GLAutoDrawable glautodrawable) {}

          @Override
          public void display(GLAutoDrawable glautodrawable) {
            OneTriangle.render(
                glautodrawable.getGL().getGL2(),
                glautodrawable.getSurfaceWidth(),
                glautodrawable.getSurfaceHeight());
          }
        });

    // "One Triangle Swing GLCanvas JWindow"
    final JWindow jwindow = new JWindow();
    jwindow.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent windowevent) {
            jwindow.dispose();
            System.exit(0);
          }
        });

    jwindow.getContentPane().add(glcanvas, BorderLayout.CENTER);
    jwindow.setSize(640, 480);
    jwindow.setVisible(true);
  }
 public CubeSample6InvalidNormal() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   glu = new GLU();
   GLWindow glWindow = GLWindow.create(caps);
   glWindow.setTitle("Cube demo (Newt)");
   glWindow.setSize(300, 300);
   glWindow.addWindowListener(
       new WindowAdapter() {
         @Override
         public void windowDestroyed(WindowEvent arg0) {
           System.exit(0);
         }
       });
   glWindow.addGLEventListener(this);
   glWindow.addMouseListener(this);
   animator = new FPSAnimator(30);
   animator.add(glWindow);
   animator.start();
   animator.pause();
   glWindow.setVisible(true);
 }
Ejemplo n.º 22
0
  @Test
  public void test02GLDebugError() throws InterruptedException {
    final GLProfile glp = GLProfile.getDefault();

    final WindowContext winctx = createWindow(glp, true);

    final MyGLDebugListener myGLDebugListener =
        new MyGLDebugListener(
            GL2ES2.GL_DEBUG_SOURCE_API, GL2ES2.GL_DEBUG_TYPE_ERROR, GL2ES2.GL_DEBUG_SEVERITY_HIGH);
    winctx.context.addGLDebugListener(myGLDebugListener);

    final GL gl = winctx.context.getGL();

    gl.glBindFramebuffer(-1, -1); // ERROR !

    if (winctx.context.isGLDebugMessageEnabled()) {
      Assert.assertEquals(true, myGLDebugListener.received());
    }

    destroyWindow(winctx);
  }
Ejemplo n.º 23
0
  @Test
  public void test03GLDebugInsert() throws InterruptedException {
    final GLProfile glp = GLProfile.getDefault();
    final WindowContext winctx = createWindow(glp, true);
    final MyGLDebugListener myGLDebugListener = new MyGLDebugListener(dbgTstMsg0, dbgTstId0);
    winctx.context.addGLDebugListener(myGLDebugListener);

    final String glDebugExt = winctx.context.getGLDebugMessageExtension();
    Assert.assertEquals(
        (null == glDebugExt) ? false : true, winctx.context.isGLDebugMessageEnabled());

    if (winctx.context.isGLDebugMessageEnabled()) {
      winctx.context.glDebugMessageInsert(
          GL2ES2.GL_DEBUG_SOURCE_APPLICATION,
          GL2ES2.GL_DEBUG_TYPE_OTHER,
          dbgTstId0,
          GL2ES2.GL_DEBUG_SEVERITY_MEDIUM,
          dbgTstMsg0);
      Assert.assertEquals(true, myGLDebugListener.received());
    }

    destroyWindow(winctx);
  }
Ejemplo n.º 24
0
    @Override
    public SharedResourceRunner.Resource createSharedResource(
        final AbstractGraphicsDevice adevice) {
      final X11GraphicsDevice device =
          new X11GraphicsDevice(
              X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */);
      GLContextImpl context = null;
      boolean contextIsCurrent = false;
      device.lock();
      try {
        final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());

        GLXUtil.initGLXClientDataSingleton(device);
        final String glXServerVendorName =
            GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_VENDOR);
        final boolean glXServerMultisampleAvailable =
            GLXUtil.isMultisampleAvailable(
                GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_EXTENSIONS));

        final GLProfile glp = GLProfile.get(device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
        if (null == glp) {
          throw new GLException("Couldn't get default GLProfile for device: " + device);
        }

        final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
        final GLDrawableImpl drawable =
            createOnscreenDrawableImpl(
                createDummySurfaceImpl(device, false, caps, caps, null, 64, 64));
        drawable.setRealized(true);
        final X11GLCapabilities chosenCaps = (X11GLCapabilities) drawable.getChosenGLCapabilities();
        final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
        final VersionNumber glXServerVersion;
        if (glxForcedOneOne) {
          glXServerVersion = versionOneOne;
        } else {
          glXServerVersion = GLXUtil.getGLXServerVersionNumber(device);
        }
        context = (GLContextImpl) drawable.createContext(null);
        if (null == context) {
          throw new GLException("Couldn't create shared context for drawable: " + drawable);
        }
        contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent();

        final boolean allowsSurfacelessCtx;
        if (contextIsCurrent && context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0) {
          allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */);
        } else {
          setNoSurfacelessCtxQuirk(context);
          allowsSurfacelessCtx = false;
        }

        if (context.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) {
          X11Util.markAllDisplaysUnclosable();
        }
        if (DEBUG_SHAREDCTX) {
          System.err.println("SharedDevice:  " + device);
          System.err.println("SharedScreen:  " + screen);
          System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent);
          System.err.println("  allowsSurfacelessCtx " + allowsSurfacelessCtx);
          System.err.println("GLX Server Vendor:      " + glXServerVendorName);
          System.err.println(
              "GLX Server Version:     " + glXServerVersion + ", forced " + glxForcedOneOne);
          System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
          System.err.println("GLX Client Vendor:      " + GLXUtil.getClientVendorName());
          System.err.println("GLX Client Version:     " + GLXUtil.getClientVersionNumber());
          System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
        }
        return new SharedResource(
            device,
            screen,
            drawable,
            context,
            glXServerVersion,
            glXServerVendorName,
            glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
      } catch (final Throwable t) {
        throw new GLException(
            "X11GLXDrawableFactory - Could not initialize shared resources for " + adevice, t);
      } finally {
        if (contextIsCurrent) {
          context.release();
        }
        device.unlock();
      }
    }
  protected void runJOGLTasks(
      final int animThreadCount,
      final int frameCount,
      final int reszThreadCount,
      final int resizeCount)
      throws InterruptedException {
    final GLWindow glWindow = GLWindow.create(new GLCapabilities(GLProfile.getDefault()));
    final MyEventCounter myEventCounter = new MyEventCounter();

    glWindow.addGLEventListener(new GearsES2(0));
    glWindow.addGLEventListener(myEventCounter);
    glWindow.setSize(demoSize, demoSize);
    glWindow.setVisible(true);

    final String currentThreadName = Thread.currentThread().getName();
    final Object sync = new Object();
    final MyRunnable[] animTasks = new MyRunnable[animThreadCount];
    final MyRunnable[] resizeTasks = new MyRunnable[animThreadCount];
    final Thread[] animThreads = new Thread[reszThreadCount];
    final Thread[] resizeThreads = new Thread[reszThreadCount];

    System.err.println("animThreadCount " + animThreadCount + ", frameCount " + frameCount);
    System.err.println("reszThreadCount " + reszThreadCount + ", resizeCount " + resizeCount);
    System.err.println(
        "tasks "
            + (animTasks.length + resizeTasks.length)
            + ", threads "
            + (animThreads.length + resizeThreads.length));

    for (int i = 0; i < animThreadCount; i++) {
      System.err.println("create anim task/thread " + i);
      animTasks[i] = new RudeAnimator(glWindow, frameCount, sync, i);
      animThreads[i] = new Thread(animTasks[i], currentThreadName + "-anim" + i);
    }
    for (int i = 0; i < reszThreadCount; i++) {
      System.err.println("create resz task/thread " + i);
      resizeTasks[i] = new RudeResizer(glWindow, resizeCount, sync, i);
      resizeThreads[i] = new Thread(resizeTasks[i], currentThreadName + "-resz" + i);
    }

    myEventCounter.reset();

    int j = 0, k = 0;
    for (int i = 0; i < reszThreadCount + animThreadCount; i++) {
      if (0 == i % 2) {
        System.err.println("start resize thread " + j);
        resizeThreads[j++].start();
      } else {
        System.err.println("start anim thread " + k);
        animThreads[k++].start();
      }
    }
    synchronized (sync) {
      while (!done(resizeTasks) || !done(animTasks)) {
        try {
          sync.wait();
        } catch (final InterruptedException e) {
          throw new RuntimeException(e);
        }
      }
    }
    int i = 0;
    while (i < 30 && !isDead(animThreads) && !isDead(resizeThreads)) {
      Thread.sleep(100);
      i++;
    }

    glWindow.destroy();
  }
Ejemplo n.º 26
0
 @BeforeClass
 public static void initClass() {
   if (!GLProfile.isAvailable(GLProfile.GL2ES2)) {
     setTestSupported(false);
   }
 }
Ejemplo n.º 27
0
 public Triangle() {
   super(new GLCapabilities(GLProfile.get("GL3")));
   setSize(800, 800);
   addGLEventListener(this);
 }
Ejemplo n.º 28
0
  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));
  }
 static {
   // setting this true causes window events not to get sent on Linux if you run from inside
   // Eclipse
   GLProfile.initSingleton();
 }
  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;
        }
    });*/
  }