Пример #1
0
  private void setup(GL2ES2 gl) {
    if (60 < TARGET_FPS) {
      // Disables vsync
      gl.setSwapInterval(0);
    }
    glu = new GLU();

    vertShader =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            LandscapeES2.class,
            "shader",
            "shader/bin",
            "landscape",
            true);
    fragShader =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            LandscapeES2.class,
            "shader",
            "shader/bin",
            "landscape",
            true);
    vertShader.defaultShaderCustomization(gl, true, true);
    fragShader.defaultShaderCustomization(gl, true, true);
    shaderProg = new ShaderProgram();
    shaderProg.add(gl, vertShader, System.err);
    shaderProg.add(gl, fragShader, System.err);

    shaderState = new ShaderState();
    shaderState.attachShaderProgram(gl, shaderProg, true);

    resolution =
        new GLUniformData("iResolution", 3, FloatBuffer.wrap(new float[] {width, height, 0}));
    shaderState.ownUniform(resolution);
    shaderState.uniform(gl, resolution);

    time = new GLUniformData("iGlobalTime", 0.0f);
    shaderState.ownUniform(time);

    vertices =
        GLArrayDataServer.createGLSL("inVertex", 2, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    vertices.putf(-1.0f);
    vertices.putf(-1.0f);
    vertices.putf(+1.0f);
    vertices.putf(-1.0f);
    vertices.putf(-1.0f);
    vertices.putf(+1.0f);
    vertices.putf(+1.0f);
    vertices.putf(+1.0f);
    vertices.seal(gl, true);
    shaderState.ownAttribute(vertices, true);
    shaderState.useProgram(gl, false);

    doneSetup = true;
  }
Пример #2
0
 @Override
 public void reshape(
     final GLAutoDrawable glad, final int x, final int y, final int width, final int height) {
   final GL2ES2 gl = glad.getGL().getGL2ES2();
   if (-1 != swapInterval) {
     gl.setSwapInterval(swapInterval);
   }
   reshapeImpl(gl, x, y, width, height, width, height);
 }
Пример #3
0
 @Override
 public void reshapeTile(
     final TileRendererBase tr,
     final int tileX,
     final int tileY,
     final int tileWidth,
     final int tileHeight,
     final int imageWidth,
     final int imageHeight) {
   final GL2ES2 gl = tr.getAttachedDrawable().getGL().getGL2ES2();
   gl.setSwapInterval(0);
   reshapeImpl(gl, tileX, tileY, tileWidth, tileHeight, imageWidth, imageHeight);
 }
  @Test(timeout = 120000)
  public void testShaderState01PerformanceDouble() throws InterruptedException {
    // preset ..
    final NEWTGLContext.WindowContext winctx =
        NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, false);
    final GLDrawable drawable = winctx.context.getGLDrawable();
    final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
    System.err.println(winctx.context);
    gl.setSwapInterval(0);

    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    // test code ..
    final ShaderState st = new ShaderState();

    final ShaderCode rsVp =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            1,
            RedSquare0.class,
            "shader",
            "shader/bin",
            "RedSquareShader");
    final ShaderCode rsFp =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            1,
            RedSquare0.class,
            "shader",
            "shader/bin",
            "RedSquareShader");

    final ShaderProgram sp = new ShaderProgram();
    sp.add(rsVp);
    sp.add(rsFp);

    sp.init(gl);
    Assert.assertTrue(sp.link(gl, System.err));

    st.attachShaderProgram(gl, sp);
    st.useProgram(gl, true);

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

    // Allocate Vertex Array0
    final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, st, -1);
    st.ownAttribute(vertices0, true);
    vertices0.enableBuffer(gl, false);

    // Allocate Vertex Array1
    final GLArrayDataServer vertices1 = GLSLMiscHelper.createRSVertices1(gl, st);
    st.ownAttribute(vertices1, true);
    vertices1.enableBuffer(gl, false);

    // Allocate Color Array0
    final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, st, -1);
    st.ownAttribute(colors0, true);
    colors0.enableBuffer(gl, false);

    // Allocate Color Array1
    final GLArrayDataServer colors1 = GLSLMiscHelper.createRSColors1(gl, st);
    st.ownAttribute(colors1, true);
    colors1.enableBuffer(gl, false);

    // misc GL setup
    gl.glClearColor(0, 0, 0, 1);
    gl.glEnable(GL2ES2.GL_DEPTH_TEST);

    // reshape
    pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.gluPerspective(
        45.0F, (float) drawable.getWidth() / (float) drawable.getHeight(), 1.0F, 100.0F);
    pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glTranslatef(0, 0, -10);
    st.uniform(gl, pmvMatrixUniform);
    gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());

    gl.setSwapInterval(0);

    // validation ..
    GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, 0);
    GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, 0);

    // warmup ..
    for (int frames = 0; frames < GLSLMiscHelper.frames_warmup; frames += 2) {
      GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices0, colors0, true);
      GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices1, colors1, true);
    }

    // measure ..
    long t0 = System.currentTimeMillis();
    int frames;

    for (frames = 0; frames < GLSLMiscHelper.frames_perftest; frames += 2) {
      GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices0, colors0, true);
      GLSLMiscHelper.displayVCArraysNoChecks(drawable, gl, true, vertices1, colors1, true);
    }
    final long t1 = System.currentTimeMillis();
    final long dt = t1 - t0;
    final double fps = (frames * 1000.0) / (double) dt;
    final String fpsS = String.valueOf(fps);
    final int fpsSp = fpsS.indexOf('.');
    System.err.println(
        "testShaderState01PerformanceDouble: "
            + dt / 1000.0
            + "s: "
            + frames
            + "f, "
            + fpsS.substring(0, fpsSp + 2)
            + " fps, "
            + dt / frames
            + " ms/f");

    // cleanup
    st.destroy(gl);

    NEWTGLContext.destroyWindow(winctx);
  }