Пример #1
0
 protected GLCapabilities createCapabilities() {
   GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
   caps.setStencilBits(1);
   caps.setDoubleBuffered(true);
   caps.setAlphaBits(8);
   return caps;
 }
 static {
   caps = new GLCapabilities();
   caps.setDoubleBuffered(true);
   caps.setAlphaBits(8);
   caps.setRedBits(8);
   caps.setGreenBits(8);
   caps.setBlueBits(8);
 }
Пример #3
0
 private static GLCapabilities stdcaps() {
   GLProfile prof = GLProfile.getDefault();
   GLCapabilities cap = new GLCapabilities(prof);
   cap.setDoubleBuffered(true);
   cap.setAlphaBits(8);
   cap.setRedBits(8);
   cap.setGreenBits(8);
   cap.setBlueBits(8);
   cap.setSampleBuffers(true);
   cap.setNumSamples(4);
   return (cap);
 }
 GLFrame(JTextArea outputArea) {
   this.outputArea = outputArea;
   GLCapabilities caps = new GLCapabilities(Configuration.getMaxCompatibleGLProfile());
   caps.setAlphaBits(8);
   caps.setRedBits(8);
   caps.setGreenBits(8);
   caps.setBlueBits(8);
   GLCanvas glCanvas = new GLCanvas(caps);
   glCanvas.addGLEventListener(this);
   this.add(glCanvas);
   this.setSize(200, 200);
 }
Пример #5
0
  private void testMultiSampleAAImpl(
      final boolean useFBO, final boolean usePBuffer, final int reqSamples)
      throws InterruptedException {
    final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
    final GLProfile glp = GLProfile.getGL2ES2();
    final GLCapabilities caps = new GLCapabilities(glp);
    final GLCapabilitiesChooser chooser = new MultisampleChooser01();

    caps.setAlphaBits(1);
    caps.setFBO(useFBO);
    caps.setPBuffer(usePBuffer);

    if (reqSamples > 0) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(reqSamples);
    }

    final GLWindow window = GLWindow.create(caps);
    window.setCapabilitiesChooser(chooser);
    window.addGLEventListener(new MultisampleDemoES2(reqSamples > 0 ? true : false));
    window.addGLEventListener(
        new GLEventListener() {
          int displayCount = 0;

          public void init(final GLAutoDrawable drawable) {}

          public void dispose(final GLAutoDrawable drawable) {}

          public void display(final GLAutoDrawable drawable) {
            snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
          }

          public void reshape(
              final GLAutoDrawable drawable,
              final int x,
              final int y,
              final int width,
              final int height) {}
        });
    window.setSize(512, 512);
    window.setVisible(true);
    window.requestFocus();

    Thread.sleep(durationPerTest);

    window.destroy();
  }
Пример #6
0
  public static void main(String[] args) {
    GLProfile glp = GLProfile.getGL2ES2();
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(4);
    caps.setSampleBuffers(true);
    caps.setNumSamples(4);
    System.out.println("Requested: " + caps);

    final GLWindow window = GLWindow.create(caps);
    window.setPosition(10, 10);
    window.setSize(800, 400);
    window.setTitle("GPU UI Newt Demo 01");
    RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
    UIGLListener01 uiGLListener = new UIGLListener01(rs, DEBUG, TRACE);
    uiGLListener.attachInputListenerTo(window);
    window.addGLEventListener(uiGLListener);

    window.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
    window.setVisible(true);

    final Animator animator = new Animator();
    animator.setUpdateFPSFrames(FPSCounter.DEFAULT_FRAMES_PER_INTERVAL, System.err);
    animator.add(window);

    window.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_F4) {
              window.destroy();
            }
          }
        });
    window.addWindowListener(
        new WindowAdapter() {
          public void windowDestroyed(WindowEvent e) {
            animator.stop();
          }
        });

    animator.start();
  }
  public void testImpl(boolean useFFP, final InputStream istream)
      throws InterruptedException, IOException {
    final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
    GLProfile glp;
    if (useFFP && GLProfile.isAvailable(GLProfile.GL2)) {
      glp = GLProfile.getMaxFixedFunc(true);
    } else if (!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) {
      glp = GLProfile.getGL2ES2();
    } else {
      System.err.println(getSimpleTestName(".") + ": GLProfile n/a, useFFP: " + useFFP);
      return;
    }
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(1);

    final TextureData texData =
        TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.TGA);
    System.err.println("TextureData: " + texData);

    final GLWindow glad = GLWindow.create(caps);
    glad.setTitle("TestTGATextureGL2FromFileNEWT");
    // Size OpenGL to Video Surface
    glad.setSize(texData.getWidth(), texData.getHeight());

    // load texture from file inside current GL context to match the way
    // the bug submitter was doing it
    final GLEventListener gle =
        useFFP ? new TextureDraw01GL2Listener(texData) : new TextureDraw01ES2Listener(texData, 0);
    glad.addGLEventListener(gle);
    glad.addGLEventListener(
        new GLEventListener() {
          boolean shot = false;

          @Override
          public void init(GLAutoDrawable drawable) {}

          public void display(GLAutoDrawable drawable) {
            // 1 snapshot
            if (null != ((TextureDraw01Accessor) gle).getTexture() && !shot) {
              shot = true;
              snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
            }
          }

          @Override
          public void dispose(GLAutoDrawable drawable) {}

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

    Animator animator = new Animator(glad);
    animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
    QuitAdapter quitAdapter = new QuitAdapter();
    glad.addKeyListener(quitAdapter);
    glad.addWindowListener(quitAdapter);
    glad.setVisible(true);
    animator.start();

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

    animator.stop();
    glad.destroy();
  }
Пример #8
0
  public void testImpl(
      final int sceneMSAASamples, final int graphMSAASamples, final int graphVBAASamples)
      throws InterruptedException {
    GLProfile glp = GLProfile.get(GLProfile.GL2ES2);
    GLCapabilities caps = new GLCapabilities(glp);
    caps.setAlphaBits(4);
    if (0 < sceneMSAASamples) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(sceneMSAASamples);
    }
    System.err.println(
        "Requested: "
            + caps
            + ", graph[msaaSamples "
            + graphMSAASamples
            + ", vbaaSamples "
            + graphVBAASamples
            + "]");

    GLWindow window =
        createWindow(
            "text-gvbaa"
                + graphVBAASamples
                + "-gmsaa"
                + graphMSAASamples
                + "-smsaa"
                + sceneMSAASamples,
            caps,
            1024,
            640);
    window.display();
    System.err.println("Chosen: " + window.getChosenGLCapabilities());
    if (WaitStartEnd) {
      UITestCase.waitForKey("Start");
    }

    final RenderState rs = RenderState.createRenderState(SVertex.factory());
    final int renderModes, sampleCount;
    if (graphVBAASamples > 0) {
      renderModes = Region.VBAA_RENDERING_BIT;
      sampleCount = graphVBAASamples;
    } else if (graphMSAASamples > 0) {
      renderModes = Region.MSAA_RENDERING_BIT;
      sampleCount = graphMSAASamples;
    } else {
      renderModes = 0;
      sampleCount = 0;
    }
    final TextRendererGLEL textGLListener = new TextRendererGLEL(rs, renderModes, sampleCount);
    System.err.println(textGLListener.getFontInfo());

    window.addGLEventListener(textGLListener);

    Animator anim = new Animator();
    anim.add(window);
    anim.start();
    anim.setUpdateFPSFrames(60, null);
    sleep();
    window.invoke(
        true,
        new GLRunnable() {
          @Override
          public boolean run(GLAutoDrawable drawable) {
            try {
              textGLListener.printScreen(
                  renderModes,
                  drawable,
                  "./",
                  "TestTextRendererNEWT00-snap" + screenshot_num,
                  false);
              screenshot_num++;
            } catch (Exception e) {
              e.printStackTrace();
            }
            return true;
          }
        });
    anim.stop();
    if (WaitStartEnd) {
      UITestCase.waitForKey("Stop");
    }
    destroyWindow(window);
  }
Пример #9
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;
  }
Пример #10
0
  /**
   * Constructor for this class. Sets up the window and enables common features like anti-aliasing
   * and hardware acceleration.
   *
   * @param forceGL2ES2 Force GL2ES2 support (default on), currently Unused
   * @param inputHandler A predefined InputHandler that is added as event handler for input events.
   * @param glEventListener A predefined GLEventListener that is added as event handler for openGL
   *     events.
   * @param width The initial window width.
   * @param height The initial window height.
   * @param windowTitle The window title.
   */
  public ESightNewtWindow(
      boolean forceGL2ES2,
      InputHandler inputHandler,
      final GLEventListener glEventListener,
      int width,
      int height,
      String windowTitle) {
    final GLProfile glp;
    // if (forceGL2ES2) {
    // glp = GLProfile.get(GLProfile.GL2ES2);
    // } else {
    glp = GLProfile.get(GLProfile.GL3);
    // }

    // Set up the GL context
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setBackgroundOpaque(true);
    caps.setHardwareAccelerated(true);
    caps.setDoubleBuffered(true);

    // Add Anti-Aliasing
    caps.setSampleBuffers(true);
    caps.setAlphaBits(4);
    caps.setNumSamples(4);

    // Create the Newt Window
    Display dpy = NewtFactory.createDisplay(null);
    Screen screen = NewtFactory.createScreen(dpy, screenIdx);
    final GLWindow glWindow = GLWindow.create(screen, caps);

    glWindow.setTitle(windowTitle);

    // Add listeners
    glWindow.addMouseListener(inputHandler);
    glWindow.addKeyListener(inputHandler);
    // glWindow.setFullscreen(true);

    WindowListener[] listeners = glWindow.getWindowListeners();
    final WindowListener original = listeners[0];
    glWindow.addWindowListener(
        0,
        new WindowAdapter() {
          @Override
          public void windowDestroyNotify(WindowEvent arg0) {
            glWindow.getAnimator().stop();
            System.exit(0);
          }

          @Override
          public void windowDestroyed(WindowEvent arg0) {
            glWindow.getAnimator().stop();
            System.exit(0);
          }

          @Override
          public void windowGainedFocus(WindowEvent arg0) {
            original.windowGainedFocus(arg0);
          }

          @Override
          public void windowLostFocus(WindowEvent arg0) {
            original.windowLostFocus(arg0);
          }

          @Override
          public void windowMoved(WindowEvent arg0) {
            original.windowMoved(arg0);
          }

          @Override
          public void windowRepaint(WindowUpdateEvent arg0) {
            original.windowRepaint(arg0);
          }

          @Override
          public void windowResized(WindowEvent arg0) {
            original.windowResized(arg0);
          }
        });

    glWindow.addGLEventListener(glEventListener);

    // Create the Animator
    final Animator animator = new Animator();
    animator.add(glWindow);
    animator.start();

    glWindow.setSize(width, height);

    glWindow.setVisible(true);
  }