@Override
 public void init(GLAutoDrawable drawable) {
   defAutoSwapMode = drawable.getAutoSwapBufferMode();
   swapBuffersBeforeRead =
       GLDrawableUtil.swapBuffersBeforeRead(drawable.getChosenGLCapabilities());
   drawable.setAutoSwapBufferMode(!swapBuffersBeforeRead);
 }
 @Override
 public void destroyGLAutoDrawable(final GLAutoDrawable glad)
     throws InterruptedException, InvocationTargetException {
   if (glad.getChosenGLCapabilities().isOnscreen()) {
     final Frame frame = AWTMisc.getFrame((Component) glad);
     javax.swing.SwingUtilities.invokeAndWait(
         new Runnable() {
           public void run() {
             final Frame _frame = frame;
             _frame.dispose();
           }
         });
   } else {
     glad.destroy();
   }
 }
Пример #3
0
 public void printScreen(
     int renderModes, GLAutoDrawable drawable, String dir, String objName, boolean exportAlpha)
     throws GLException, IOException {
   final String modeS = Region.getRenderModeString(renderModes);
   final String bname =
       String.format(
           "%s-msaa%02d-fontsz%02.1f-%03dx%03d-%s%04d",
           objName,
           drawable.getChosenGLCapabilities().getNumSamples(),
           TestTextRendererNEWT00.fontSizeFixed,
           drawable.getWidth(),
           drawable.getHeight(),
           modeS,
           vbaaSampleCount[0]);
   final String filename = dir + bname + ".png";
   if (screenshot.readPixels(drawable.getGL(), false)) {
     screenshot.write(new File(filename));
   }
 }
Пример #4
0
    @Override
    public void display(GLAutoDrawable drawable) {
      final GL2ES2 gl = drawable.getGL().getGL2ES2();

      gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

      final GLAnimatorControl anim = drawable.getAnimator();
      final float lfps = null != anim ? anim.getLastFPS() : 0f;
      final float tfps = null != anim ? anim.getTotalFPS() : 0f;

      // Note: MODELVIEW is from [ 0 .. height ]

      final long t1 = Platform.currentTimeMillis();

      // final float fontSize = TestTextRendererNEWT00.fontSize;

      fontSizeAnim += fontSizeDelta;
      if (fontSizeMin >= fontSizeAnim || fontSizeAnim >= fontSizeMax) {
        fontSizeDelta *= -1f;
      }

      final float pixelSize = font.getPixelSize(fontSizeFixed, dpiH);
      final float pixelSizeAnim = font.getPixelSize(fontSizeAnim, dpiH);

      final String modeS = Region.getRenderModeString(renderModes);

      if (false) {
        // renderString(drawable, font, pixelSize, "I - / H P 7 0", 0, 0, 0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, "A M > } ] ", 0, 0, 0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, "M", 0, 0, 0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, "0 6 9 a b O Q A M > } ] ", 0, 0, 0, 0, -1000f,
        // true);
        // renderString(drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000,
        // true);
        // renderString(drawable, font, pixelSize, textX2,        0, 0,   0, 0, -1000f, true);
        // renderString(drawable, font, pixelSize, text1,         0,    0, 0, -1000f, regionFPS); //
        // no-cache
        final String text1 =
            lfps
                + " / "
                + tfps
                + " fps, vsync "
                + gl.getSwapInterval()
                + ", elapsed "
                + (t1 - t0) / 1000.0
                + " s, fontSize "
                + fontSizeFixed
                + ", msaa "
                + drawable.getChosenGLCapabilities().getNumSamples()
                + ", "
                + modeS
                + "-samples "
                + vbaaSampleCount[0];
        renderString(drawable, font, pixelSize, text1, 0, 0, 0, 0, -1000, regionFPS); // no-cache
      } else {
        final String text1 =
            String.format(
                "%03.1f/%03.1f fps, vsync %d, elapsed %4.1f s, fontSize %2.2f, msaa %d, %s-samples %d",
                lfps,
                tfps,
                gl.getSwapInterval(),
                (t1 - t0) / 1000.0,
                fontSizeFixed,
                drawable.getChosenGLCapabilities().getNumSamples(),
                modeS,
                vbaaSampleCount[0]);
        renderString(drawable, font, pixelSize, getFontInfo(), 0, 0, 0, 0, -1000, true);
        renderString(
            drawable, font, pixelSize, "012345678901234567890123456789", 0, 0, 0, -1000, true);
        renderString(
            drawable, font, pixelSize, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "4567890123456", 4, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "I like JogAmp", 4, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, "Hello World", 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, textX2, 0, 0, 0, -1000, true);
        renderString(drawable, font, pixelSize, text1, 0, 0, 0, -1000, regionFPS); // no-cache
        if (TextAnim) {
          renderString(
              drawable, font, pixelSizeAnim, text1, 0, 0, 0, -1000, regionFPSAnim); // no-cache
        }
      }
    }
Пример #5
0
  void doTest(
      final boolean onscreen, final GLEventListener demo, final GLProfile glp, final int msaaCount)
      throws IOException {
    final GLCapabilities caps = new GLCapabilities(glp);
    caps.setDoubleBuffered(onscreen);
    if (msaaCount > 0) {
      caps.setSampleBuffers(true);
      caps.setNumSamples(msaaCount);
    }

    final int maxTileSize = 256;
    final GLAutoDrawable glad;
    if (onscreen) {
      final GLWindow glWin = GLWindow.create(caps);
      glWin.setSize(maxTileSize, maxTileSize);
      glWin.setVisible(true);
      glad = glWin;
    } else {
      final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp);
      glad = factory.createOffscreenAutoDrawable(null, caps, null, maxTileSize, maxTileSize);
    }

    glad.addGLEventListener(demo);

    // Fix the image size for now
    final int imageWidth = glad.getSurfaceWidth() * 6;
    final int imageHeight = glad.getSurfaceHeight() * 4;

    final String filename =
        this.getSnapshotFilename(
            0,
            "-tile",
            glad.getChosenGLCapabilities(),
            imageWidth,
            imageHeight,
            false,
            TextureIO.PNG,
            null);
    final File file = new File(filename);

    // Initialize the tile rendering library
    final TileRenderer renderer = new TileRenderer();
    renderer.setImageSize(imageWidth, imageHeight);
    renderer.setTileSize(glad.getSurfaceWidth(), glad.getSurfaceHeight(), 0);
    renderer.attachAutoDrawable(glad);

    final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider =
        GLPixelBuffer.defaultProviderWithRowStride;
    final boolean[] flipVertically = {false};

    final GLEventListener preTileGLEL =
        new GLEventListener() {
          @Override
          public void init(final GLAutoDrawable drawable) {
            final GL gl = drawable.getGL();
            final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
            final GLPixelBuffer pixelBuffer =
                pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
            renderer.setImageBuffer(pixelBuffer);
            if (drawable.isGLOriented()) {
              flipVertically[0] = false;
            } else {
              flipVertically[0] = true;
            }
          }

          @Override
          public void dispose(final GLAutoDrawable drawable) {}

          @Override
          public void display(final GLAutoDrawable drawable) {}

          @Override
          public void reshape(
              final GLAutoDrawable drawable,
              final int x,
              final int y,
              final int width,
              final int height) {}
        };
    renderer.setGLEventListener(preTileGLEL, null);

    while (!renderer.eot()) {
      renderer.display();
    }

    renderer.detachAutoDrawable();

    // Restore viewport and Gear's PMV matrix
    // .. even though we close the demo, this is for documentation!
    glad.invoke(
        true,
        new GLRunnable() {
          @Override
          public boolean run(final GLAutoDrawable drawable) {
            drawable
                .getGL()
                .glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
            demo.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
            return false;
          }
        });

    final GLPixelBuffer imageBuffer = renderer.getImageBuffer();
    final TextureData textureData =
        new TextureData(
            caps.getGLProfile(),
            0 /* internalFormat */,
            imageWidth,
            imageHeight,
            0,
            imageBuffer.pixelAttributes,
            false,
            false,
            flipVertically[0],
            imageBuffer.buffer,
            null /* Flusher */);

    TextureIO.write(textureData, file);

    glad.destroy();
  }
Пример #6
0
  @Override
  public void init(final GLAutoDrawable glad) {
    System.err.println(
        Thread.currentThread() + " RedSquareES2.init: tileRendererInUse " + tileRendererInUse);
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    System.err.println("RedSquareES2 init on " + Thread.currentThread());
    System.err.println("Chosen GLCapabilities: " + glad.getChosenGLCapabilities());
    System.err.println("INIT GL IS: " + gl.getClass().getName());
    System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
    if (!gl.hasGLSL()) {
      System.err.println("No GLSL available, no rendering.");
      return;
    }
    st = new ShaderState();
    st.setVerbose(true);
    final ShaderCode vp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            "RedSquareShader",
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            "RedSquareShader",
            true);
    vp0.defaultShaderCustomization(gl, true, true);
    fp0.defaultShaderCustomization(gl, true, true);
    final ShaderProgram sp0 = new ShaderProgram();
    sp0.add(gl, vp0, System.err);
    sp0.add(gl, fp0, System.err);
    st.attachShaderProgram(gl, sp0, true);

    // setup mgl_PMVMatrix
    pmvMatrix = new PMVMatrix();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrixUniform =
        new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
    st.ownUniform(pmvMatrixUniform);
    st.uniform(gl, pmvMatrixUniform);

    // Allocate Vertex Array
    vertices =
        GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    vertices.putf(-2);
    vertices.putf(2);
    vertices.putf(0);
    vertices.putf(2);
    vertices.putf(2);
    vertices.putf(0);
    vertices.putf(-2);
    vertices.putf(-2);
    vertices.putf(0);
    vertices.putf(2);
    vertices.putf(-2);
    vertices.putf(0);
    vertices.seal(gl, true);
    st.ownAttribute(vertices, true);
    vertices.enableBuffer(gl, false);

    // Allocate Color Array
    colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(1);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.seal(gl, true);
    st.ownAttribute(colors, true);
    colors.enableBuffer(gl, false);

    // OpenGL Render Settings
    gl.glEnable(GL.GL_DEPTH_TEST);
    st.useProgram(gl, false);

    t0 = System.currentTimeMillis();
    System.err.println(Thread.currentThread() + " RedSquareES2.init FIN");
  }
Пример #7
0
  public void init(GLAutoDrawable glad) {
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    System.err.println();
    System.err.println("req. msaa: " + multisample);
    System.err.println(
        "Requested: "
            + glad.getNativeSurface().getGraphicsConfiguration().getRequestedCapabilities());
    multisample = multisample & glad.getChosenGLCapabilities().getNumSamples() > 0;
    System.err.println("Chosen   : " + glad.getChosenGLCapabilities());
    System.err.println("has  msaa: " + multisample);
    System.err.println();

    final ShaderCode vp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            MultisampleDemoES2.class,
            "shader",
            "shader/bin",
            "mgl_default_xxx",
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            MultisampleDemoES2.class,
            "shader",
            "shader/bin",
            "mgl_default_xxx",
            true);
    vp0.defaultShaderCustomization(gl, true, true);
    fp0.defaultShaderCustomization(gl, true, true);

    sp0 = new ShaderProgram();
    sp0.add(gl, vp0, System.err);
    sp0.add(gl, fp0, System.err);
    st.attachShaderProgram(gl, sp0, true);

    pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
    st.ownUniform(pmvMatrixUniform);
    st.uniform(gl, pmvMatrixUniform);

    // Using predef array names, see
    //    GLPointerFuncUtil.getPredefinedArrayIndexName(glArrayIndex);
    immModeSink =
        ImmModeSink.createGLSL(
            40,
            3,
            GL.GL_FLOAT, // vertex
            4,
            GL.GL_FLOAT, // color
            0,
            GL.GL_FLOAT, // normal
            0,
            GL.GL_FLOAT, // texCoords
            GL.GL_STATIC_DRAW,
            st);
    final int numSteps = 20;
    final double increment = Math.PI / numSteps;
    final double radius = 1;
    immModeSink.glBegin(GL.GL_LINES);
    for (int i = numSteps - 1; i >= 0; i--) {
      immModeSink.glVertex3f(
          (float) (radius * Math.cos(i * increment)),
          (float) (radius * Math.sin(i * increment)),
          0f);
      immModeSink.glColor4f(1f, 1f, 1f, 1f);
      immModeSink.glVertex3f(
          (float) (-1.0 * radius * Math.cos(i * increment)),
          (float) (-1.0 * radius * Math.sin(i * increment)),
          0f);
      immModeSink.glColor4f(1f, 1f, 1f, 1f);
    }
    immModeSink.glEnd(gl, false);

    st.useProgram(gl, false);
  }