예제 #1
0
  private void draw(GL2ES2 gl) {
    // gl.glClearColor(0.5f, 0.1f, 0.1f, 1);
    // gl.glClear(GL2ES2.GL_COLOR_BUFFER_BIT);

    shaderState.useProgram(gl, true);

    time.setData((System.currentTimeMillis() - millisOffset) / 1000.0f);
    shaderState.uniform(gl, time);
    vertices.enableBuffer(gl, true);
    gl.glDrawArrays(GL2ES2.GL_TRIANGLE_STRIP, 0, 4);
    vertices.enableBuffer(gl, false);

    shaderState.useProgram(gl, false);

    // Compute current framerate and printout.
    frameCount++;
    fcount += 1;
    int m = (int) (System.currentTimeMillis() - millisOffset);
    if (m - lastm > 1000 * fint) {
      frameRate = (float) (fcount) / fint;
      fcount = 0;
      lastm = m;
    }
    if (frameCount % TARGET_FPS == 0) {
      System.out.println("FrameCount: " + frameCount + " - " + "FrameRate: " + frameRate);
    }
  }
예제 #2
0
  public void init(GLAutoDrawable drawable) {
    drawable.setAutoSwapBufferMode(false);

    GL2ES2 gl = drawable.getGL().getGL2ES2();
    System.err.println("Entering initialization");
    System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
    System.err.println("GL_EXTENSIONS:");
    System.err.println("  " + gl.glGetString(gl.GL_EXTENSIONS));

    pmvMatrix = new PMVMatrix();

    pmod.initShaderState(gl);
    st = ShaderState.getCurrent();

    // Push the 1st uniform down the path
    st.glUseProgram(gl, true);

    pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();

    if (!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) {
      throw new GLException("Error setting PMVMatrix in shader: " + st);
    }

    // OpenGL Render Settings
    gl.glClearColor(0, 0, 0, 1);
    gl.glEnable(GL2ES2.GL_DEPTH_TEST);

    st.glUseProgram(gl, false);

    // Let's show the completed shader state ..
    System.out.println(st);
  }
예제 #3
0
  public final void enableState(GL gl, boolean enable, Object ext) {
    final GL2ES2 glsl = gl.getGL2ES2();
    final ShaderState st = (ShaderState) ext;

    if (enable) {
      st.enableVertexAttribArray(glsl, ad);
    } else {
      st.disableVertexAttribArray(glsl, ad);
    }
  }
예제 #4
0
  // Unused routines
  public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
    System.err.println("reshape ..");
    final GL2ES2 gl = glad.getGL().getGL2ES2();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    // pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
    pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();

    st.useProgram(gl, true);
    st.uniform(gl, pmvMatrixUniform);
    st.useProgram(gl, false);
  }
예제 #5
0
  public void display(GLAutoDrawable glad) {
    final GL2ES2 gl = glad.getGL().getGL2ES2();
    if (multisample) {
      gl.glEnable(GL.GL_MULTISAMPLE);
    }
    gl.glClearColor(0, 0, 0, 0);
    //      gl.glEnable(GL.GL_DEPTH_TEST);
    //      gl.glDepthFunc(GL.GL_LESS);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    st.useProgram(gl, true);

    immModeSink.draw(gl, true);

    st.useProgram(gl, false);
  }
예제 #6
0
  private void initShader(final GL2ES2 gl, final boolean use_program) {
    // Create & Compile the shader objects
    final ShaderCode rsVp =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            shaderBasename,
            true);
    final ShaderCode rsFp =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            shaderBasename,
            true);
    rsVp.defaultShaderCustomization(gl, true, true);
    rsFp.defaultShaderCustomization(gl, true, true);

    // Create & Link the shader program
    final ShaderProgram sp = new ShaderProgram();
    sp.add(rsVp);
    sp.add(rsFp);
    if (!sp.link(gl, System.err)) {
      throw new GLException("Couldn't link program: " + sp);
    }

    // Let's manage all our states using ShaderState.
    st = new ShaderState();
    st.attachShaderProgram(gl, sp, use_program);
  }
예제 #7
0
  public final void syncData(GL gl, boolean enable, boolean force, Object ext) {
    if (enable) {
      final GL2ES2 glsl = gl.getGL2ES2();
      final ShaderState st = (ShaderState) ext;

      st.vertexAttribPointer(glsl, ad);
      /**
       * Due to probable application VBO switching, this might not make any sense ..
       *
       * <p>if(force) { st.vertexAttribPointer(glsl, ad); } else if(st.getAttribLocation(glsl, ad)
       * >= 0) { final int[] qi = new int[1]; glsl.glGetVertexAttribiv(ad.getLocation(),
       * GL2ES2.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, qi, 0); if(ad.getVBOName() != qi[0]) {
       * System.err.println("XXX1: "+ad.getName()+", vbo ad "+ad.getVBOName()+", gl "+qi[0]+",
       * "+ad); st.vertexAttribPointer(glsl, ad); } else { System.err.println("XXX0:
       * "+ad.getName()+", vbo ad "+ad.getVBOName()+", gl "+qi[0]+", "+ad); } }
       */
    }
  }
예제 #8
0
  public RenderStateImpl(
      ShaderState st, Vertex.Factory<? extends Vertex> pointFactory, PMVMatrix pmvMatrix) {
    this.st = st;
    this.pointFactory = pointFactory;
    this.pmvMatrix = pmvMatrix;
    this.gcu_PMVMatrix =
        new GLUniformData(UniformNames.gcu_PMVMatrix, 4, 4, pmvMatrix.glGetPMvMatrixf());
    st.ownUniform(gcu_PMVMatrix);

    gcu_Sharpness = new GLUniformData(UniformNames.gcu_P1Y, 0.5f);
    st.ownUniform(gcu_PMVMatrix);
    gcu_Alpha = new GLUniformData(UniformNames.gcu_Alpha, 1.0f);
    st.ownUniform(gcu_Alpha);
    gcu_ColorStatic = new GLUniformData(UniformNames.gcu_ColorStatic, 3, FloatBuffer.allocate(3));
    st.ownUniform(gcu_ColorStatic);
    gcu_Strength = new GLUniformData(UniformNames.gcu_Strength, 3.0f);
    st.ownUniform(gcu_Strength);
  }
예제 #9
0
  public void dispose(GLAutoDrawable drawable) {
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    st.destroy(gl);
    st = null;
    pmvMatrix.destroy();
    pmvMatrix = null;
    quit = true;
  }
예제 #10
0
  @Override
  public void reshape(
      final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    // Clear background to white
    gl.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
    if (null != st) {
      pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
      pmvMatrix.glLoadIdentity();
      pmvMatrix.glOrthof(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);

      pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
      pmvMatrix.glLoadIdentity();

      st.useProgram(gl, true);
      st.uniform(gl, pmvMatrixUniform);
      st.useProgram(gl, false);
    }
  }
예제 #11
0
  public StringBuilder toString(StringBuilder sb) {
    if (null == sb) {
      sb = new StringBuilder();
    }

    sb.append("RenderState[");
    st.toString(sb).append(Platform.getNewline());
    sb.append("]");

    return sb;
  }
예제 #12
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    st.glUseProgram(gl, true);

    // Set location in front of camera
    pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glOrthof(0f, 1.0f, 0.0f, 1.0f, 1.0f, 100.0f);

    pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glTranslatef(0, 0, -10);

    GLUniformData ud = st.getUniform("mgl_PMVMatrix");
    if (null != ud) {
      // same data object
      st.glUniform(gl, ud);
    }

    st.glUseProgram(gl, false);
  }
예제 #13
0
  @Override
  public void display(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    st.useProgram(gl, true);
    interleavedVBO.enableBuffer(gl, true);
    if (!keepTextureBound && null != texture) {
      gl.glActiveTexture(GL.GL_TEXTURE0 + textureUnit);
      texture.enable(gl);
      texture.bind(gl);
    }

    gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);

    if (!keepTextureBound && null != texture) {
      texture.disable(gl);
    }
    interleavedVBO.enableBuffer(gl, false);
    st.useProgram(gl, false);
  }
예제 #14
0
 @Override
 public void dispose(final GLAutoDrawable glad) {
   System.err.println(
       Thread.currentThread() + " RedSquareES2.dispose: tileRendererInUse " + tileRendererInUse);
   final GL2ES2 gl = glad.getGL().getGL2ES2();
   if (!gl.hasGLSL()) {
     return;
   }
   st.destroy(gl);
   st = null;
   pmvMatrix = null;
   System.err.println(Thread.currentThread() + " RedSquareES2.dispose FIN");
 }
예제 #15
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;
  }
예제 #16
0
  @Override
  public void display(final GLAutoDrawable glad) {
    final long t1 = System.currentTimeMillis();

    final GL2ES2 gl = glad.getGL().getGL2ES2();
    if (clearBuffers) {
      if (null != tileRendererInUse) {
        gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
      } else {
        gl.glClearColor(0, 0, 0, 0);
      }
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    }
    if (!gl.hasGLSL()) {
      return;
    }
    st.useProgram(gl, true);
    // One rotation every four seconds
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glTranslatef(0, 0, -10);
    if (doRotate) {
      final float ang = ((t1 - t0) * 360.0F) / 4000.0F;
      pmvMatrix.glRotatef(ang, 0, 0, 1);
      pmvMatrix.glRotatef(ang, 0, 1, 0);
    }
    st.uniform(gl, pmvMatrixUniform);

    // Draw a square
    vertices.enableBuffer(gl, true);
    colors.enableBuffer(gl, true);
    gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
    vertices.enableBuffer(gl, false);
    colors.enableBuffer(gl, false);
    st.useProgram(gl, false);
  }
예제 #17
0
  @Override
  public void dispose(final GLAutoDrawable drawable) {
    final GL2ES2 gl = drawable.getGL().getGL2ES2();
    if (null != texture) {
      texture.disable(gl);
      texture.destroy(gl);
    }
    if (null != textureData) {
      textureData.destroy();
    }

    pmvMatrixUniform = null;
    pmvMatrix = null;
    st.destroy(gl);
    st = null;
  }
  @Override
  public void init(GLAutoDrawable drawable) {
    drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));
    GL2 gl = drawable.getGL().getGL2();

    gl.glClearColor(0, 0, 0, 1); // Black Background
    gl.glClearDepth(1); // Depth Buffer Setup
    gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
    gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do

    gl.glEnable(GL2.GL_LIGHTING);
    gl.glEnable(GL2.GL_LIGHT0);
    gl.glEnable(GL2.GL_NORMALIZE); // normalize normals before lighting

    // Setup perFragmentLighting shader
    String shaderNamePerFragment = "perFragmentLighting";
    ShaderCode vsCodePerFragment =
        ShaderCode.create(
            gl,
            GL2.GL_VERTEX_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNamePerFragment,
            false);
    ShaderCode fsCodePerFragment =
        ShaderCode.create(
            gl,
            GL2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNamePerFragment,
            false);
    ShaderProgram programPerFragment = new ShaderProgram();
    programPerFragment.add(vsCodePerFragment);
    programPerFragment.add(fsCodePerFragment);
    if (!programPerFragment.link(gl, System.err)) {
      throw new GLException("Couldn't link program: " + programPerFragment);
    }
    statePerFragment.attachShaderProgram(gl, programPerFragment, false);

    // Setup perVertexLighting shader
    String shaderNameCheckerboard = "checkerboard";
    ShaderCode vsCodeCheckerboard =
        ShaderCode.create(
            gl,
            GL2.GL_VERTEX_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNameCheckerboard,
            false);
    ShaderCode fsCodeCheckerboard =
        ShaderCode.create(
            gl,
            GL2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNameCheckerboard,
            false);
    ShaderProgram programCheckerboard = new ShaderProgram();
    programCheckerboard.add(vsCodeCheckerboard);
    programCheckerboard.add(fsCodeCheckerboard);
    if (!programCheckerboard.link(gl, System.err)) {
      throw new GLException("Couldn't link program: " + programCheckerboard);
    }
    stateCheckerboard.attachShaderProgram(gl, programCheckerboard, false);

    // Setup woodcut shader
    String shaderNameWoodcut = "woodcut";
    ShaderCode vsCodeWoodcut =
        ShaderCode.create(
            gl,
            GL2.GL_VERTEX_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNameWoodcut,
            false);
    ShaderCode fsCodeWoodcut =
        ShaderCode.create(
            gl,
            GL2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNameWoodcut,
            false);
    ShaderProgram programWoodcut = new ShaderProgram();
    programWoodcut.add(vsCodeWoodcut);
    programWoodcut.add(fsCodeWoodcut);
    if (!programWoodcut.link(gl, System.err)) {
      throw new GLException("Couldn't link program: " + programWoodcut);
    }
    stateWoodcut.attachShaderProgram(gl, programWoodcut, false);

    // Setup toon shader
    String shaderNameToon = "toon";
    ShaderCode vsCodeToon =
        ShaderCode.create(
            gl,
            GL2.GL_VERTEX_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNameToon,
            false);
    ShaderCode fsCodeToon =
        ShaderCode.create(
            gl,
            GL2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shaders",
            "shader/bin",
            shaderNameToon,
            false);
    ShaderProgram programToon = new ShaderProgram();
    programToon.add(vsCodeToon);
    programToon.add(fsCodeToon);
    if (!programToon.link(gl, System.err)) {
      throw new GLException("Couldn't link program: " + programToon);
    }
    stateToon.attachShaderProgram(gl, programToon, false);
  }
예제 #19
0
 public void destroy(GL2ES2 gl) {
   st.destroy(gl);
 }
예제 #20
0
  @Override
  public void init(final GLAutoDrawable glad) {
    if (null != textureData) {
      texture = TextureIO.newTexture(glad.getGL(), textureData);
    }
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    initShader(gl, 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);
    if (!st.uniform(gl, pmvMatrixUniform)) {
      throw new GLException("Error setting PMVMatrix in shader: " + st);
    }
    if (!st.uniform(gl, new GLUniformData("mgl_ActiveTexture", textureUnit))) {
      throw new GLException("Error setting mgl_ActiveTexture in shader: " + st);
    }

    if (null != texture) {
      // fetch the flipped texture coordinates
      texture.getImageTexCoords().getST_LB_RB_LT_RT(s_quadTexCoords, 0, 1f, 1f);
    }

    interleavedVBO =
        GLArrayDataServer.createGLSLInterleaved(
            3 + 4 + 2, GL.GL_FLOAT, false, 3 * 4, GL.GL_STATIC_DRAW);
    {
      interleavedVBO.addGLSLSubArray("mgl_Vertex", 3, GL.GL_ARRAY_BUFFER);
      interleavedVBO.addGLSLSubArray("mgl_Color", 4, GL.GL_ARRAY_BUFFER);
      // interleavedVBO.addGLSLSubArray("mgl_Normal",        3, GL.GL_ARRAY_BUFFER);
      interleavedVBO.addGLSLSubArray("mgl_MultiTexCoord", 2, GL.GL_ARRAY_BUFFER);

      final FloatBuffer ib = (FloatBuffer) interleavedVBO.getBuffer();

      for (int i = 0; i < 4; i++) {
        ib.put(s_quadVertices, i * 3, 3);
        ib.put(s_quadColors, i * 4, 4);
        // ib.put(s_cubeNormals,   i*3, 3);
        ib.put(s_quadTexCoords, i * 2, 2);
      }
    }
    interleavedVBO.seal(gl, true);
    interleavedVBO.enableBuffer(gl, false);
    st.ownAttribute(interleavedVBO, true);

    // OpenGL Render Settings
    gl.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
    gl.glEnable(GL.GL_DEPTH_TEST);

    if (keepTextureBound && null != texture) {
      gl.glActiveTexture(GL.GL_TEXTURE0 + textureUnit);
      texture.enable(gl);
      texture.bind(gl);
    }
    st.useProgram(gl, false);
  }
예제 #21
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");
  }
예제 #22
0
 public void dispose(GLAutoDrawable glad) {
   final GL2ES2 gl = glad.getGL().getGL2ES2();
   immModeSink.destroy(gl);
   immModeSink = null;
   st.destroy(gl);
 }
  @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);
  }
예제 #24
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);
  }
예제 #25
0
 public MultisampleDemoES2(boolean multisample) {
   this.multisample = multisample;
   st = new ShaderState();
   st.setVerbose(true);
   pmvMatrix = new PMVMatrix();
 }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    gl.glShadeModel(GL2.GL_SMOOTH); // Enable Smooth Shading (Gouraud)

    // Display the scene according to the current trackball orientation, scale the scene to fit
    // better
    tbc.prepareForDisplay(drawable);
    gl.glScaled(3, 3, 3);

    // Add a light
    int lightNumber = 0;
    float[] position = {lightPos.x, lightPos.y, lightPos.z, 1};
    float[] colour = {
      lightColR.getFloatValue(), lightColG.getFloatValue(), lightColB.getFloatValue(), 1
    };
    float[] acolour = {
      colour[0] * ambient.getFloatValue(),
      colour[1] * ambient.getFloatValue(),
      colour[2] * ambient.getFloatValue()
    };
    gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_SPECULAR, colour, 0);
    gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_DIFFUSE, colour, 0);
    gl.glLightfv(GL2.GL_LIGHT0 + lightNumber, GL2.GL_AMBIENT, acolour, 0);
    gl.glLightfv(
        GL2.GL_LIGHT0 + lightNumber,
        GL2.GL_POSITION,
        position,
        0); // transformed by the modelview matrix when glLight is called
    gl.glEnable(GL2.GL_LIGHT0 + lightNumber);

    // Determine which shader to display the scene with

    ShaderState customShader = null;

    if (viewingMode == 1) {
      stateCheckerboard.useProgram(gl, false);
      stateWoodcut.useProgram(gl, false);
      stateToon.useProgram(gl, false);
      statePerFragment.useProgram(gl, usePerFragment);
      if (usePerFragment) customShader = statePerFragment;
      else customShader = null;
    } else if (viewingMode == 2) {
      statePerFragment.useProgram(gl, false);
      stateWoodcut.useProgram(gl, false);
      stateToon.useProgram(gl, false);
      stateCheckerboard.useProgram(gl, useCheckerboard);
      if (useCheckerboard) customShader = stateCheckerboard;
      else customShader = null;
    } else if (viewingMode == 3) {
      statePerFragment.useProgram(gl, false);
      stateCheckerboard.useProgram(gl, false);
      stateToon.useProgram(gl, false);
      stateWoodcut.useProgram(gl, useWoodcut);
      if (useWoodcut) customShader = stateWoodcut;
      else customShader = null;
    } else if (viewingMode == 4) {
      statePerFragment.useProgram(gl, false);
      stateCheckerboard.useProgram(gl, false);
      stateWoodcut.useProgram(gl, false);
      stateToon.useProgram(gl, useToon);
      if (useToon) customShader = stateToon;
      else customShader = null;
    }

    // Setup the uniform values that may be used within the current shader
    if (customShader != null) {
      // Blinn-Phong uniforms
      int specExponentUniformLocation = customShader.getUniformLocation(gl, "shininess");
      gl.glUniform1f(specExponentUniformLocation, shininess.getFloatValue());
      int ambientUniformLocation = customShader.getUniformLocation(gl, "ambient");
      gl.glUniform1f(ambientUniformLocation, ambient.getFloatValue());

      // Checkerboard uniforms
      int colour1UniformLocation = customShader.getUniformLocation(gl, "Color1");
      float[] colour1 = {col1R.getFloatValue(), col1G.getFloatValue(), col1B.getFloatValue()};
      gl.glUniform3fv(colour1UniformLocation, 1, colour1, 0);
      int colour2UniformLocation = customShader.getUniformLocation(gl, "Color2");
      float[] colour2 = {col2R.getFloatValue(), col2G.getFloatValue(), col2B.getFloatValue()};
      gl.glUniform3fv(colour2UniformLocation, 1, colour2, 0);
      int avgColourUniformLocation = customShader.getUniformLocation(gl, "AvgColor");
      float[] avgColour = {
        (colour1[0] + colour2[0]) / 2, (colour1[1] + colour2[1]) / 2, (colour1[2] + colour2[2]) / 2
      };
      gl.glUniform3fv(avgColourUniformLocation, 1, avgColour, 0);
      int frequencyUniformLocation = customShader.getUniformLocation(gl, "Frequency");
      double frequencyValue = frequency.getValue();
      frequencyValue = useIntFrequency.getValue() ? Math.round(frequencyValue) : frequencyValue;
      gl.glUniform1f(frequencyUniformLocation, (float) frequencyValue);
      int useAveragingUniformLocation = customShader.getUniformLocation(gl, "UseAveraging");
      gl.glUniform1i(useAveragingUniformLocation, useAveraging.getValue() ? 1 : 0);
      int useSmoothStepUniformLocation = customShader.getUniformLocation(gl, "UseSmoothStep");
      gl.glUniform1i(useSmoothStepUniformLocation, useSmoothStep.getValue() ? 1 : 0);

      // Woodcut uniforms
      int timeUniformLocation = customShader.getUniformLocation(gl, "Time");
      gl.glUniform1f(timeUniformLocation, time.getFloatValue());
      int lightPositionUniformLocation = customShader.getUniformLocation(gl, "LightPosition");
      float[] lightPosition = {lightPos.x, lightPos.y, lightPos.z};
      gl.glUniform3fv(lightPositionUniformLocation, 1, lightPosition, 0);

      // Toon uniforms
      int threshHighUniformLocation = customShader.getUniformLocation(gl, "ThresholdHigh");
      gl.glUniform1f(threshHighUniformLocation, thresholdHigh.getFloatValue());
      int threshMedUniformLocation = customShader.getUniformLocation(gl, "ThresholdMedium");
      gl.glUniform1f(threshMedUniformLocation, thresholdMedium.getFloatValue());
      int threshLowUniformLocation = customShader.getUniformLocation(gl, "ThresholdLow");
      gl.glUniform1f(threshLowUniformLocation, thresholdLow.getFloatValue());
    }

    // Draw teapot
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, new float[] {1, 1, 0, 1}, 0);
    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, new float[] {1, 1, 1, 1}, 0);
    gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 50);
    glut.glutSolidTeapot(1);

    // Draw table
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, new float[] {0, 1, 1, 1}, 0);
    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, new float[] {1, 1, 1, 1}, 0);
    gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 50);
    gl.glPushMatrix();
    gl.glTranslated(0, -0.8, 0);
    gl.glBegin(GL2.GL_TRIANGLE_FAN);
    gl.glNormal3d(0, 1, 0);
    gl.glTexCoord2d(0, 0);
    gl.glVertex3d(-10, 0, -10);
    gl.glTexCoord2d(0, 1);
    gl.glVertex3d(-10, 0, 10);
    gl.glTexCoord2d(1, 1);
    gl.glVertex3d(10, 0, 10);
    gl.glTexCoord2d(1, 0);
    gl.glVertex3d(10, 0, -10);
    gl.glEnd();
    gl.glPopMatrix();
  }
  @Test
  public void testShaderState01Validation() throws InterruptedException {
    // preset ..
    final NEWTGLContext.WindowContext winctx =
        NEWTGLContext.createOnscreenWindow(GLProfile.getGL2ES2(), 480, 480, true);
    final GLDrawable drawable = winctx.context.getGLDrawable();
    final GL2ES2 gl = winctx.context.getGL().getGL2ES2();
    System.err.println(winctx.context);

    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();
    Assert.assertTrue(0 > sp.program());

    sp.add(gl, rsVp, System.err);
    sp.add(gl, rsFp, System.err);

    Assert.assertTrue(0 <= sp.program());
    Assert.assertTrue(!sp.inUse());
    Assert.assertTrue(!sp.linked());
    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    st.attachShaderProgram(gl, sp);

    // Allocate Vertex Array0
    final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, st, vertices0_loc);
    System.err.println("vertices0: " + vertices0);
    vertices0.enableBuffer(gl, false);
    Assert.assertEquals(vertices0_loc, vertices0.getLocation());
    st.ownAttribute(vertices0, true);

    // Allocate Color Array0
    final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, st, colors0_loc);
    System.err.println("colors0: " + colors0);
    colors0.enableBuffer(gl, false);
    Assert.assertEquals(colors0_loc, colors0.getLocation());
    st.ownAttribute(colors0, true);

    Assert.assertTrue(sp.link(gl, System.err));
    Assert.assertTrue(sp.linked());
    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    Assert.assertEquals(vertices0_loc, vertices0.getLocation());
    GLSLMiscHelper.validateGLArrayDataServerState(gl, st, vertices0);

    Assert.assertEquals(colors0_loc, colors0.getLocation());
    GLSLMiscHelper.validateGLArrayDataServerState(gl, st, colors0);

    Assert.assertEquals(null, ShaderState.getShaderState(gl));
    st.useProgram(gl, true);
    Assert.assertTrue(sp.inUse());
    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
    Assert.assertEquals(st, ShaderState.getShaderState(gl));

    // setup mgl_PMVMatrix
    final PMVMatrix pmvMatrix = new PMVMatrix();
    final GLUniformData pmvMatrixUniform =
        new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
    st.ownUniform(pmvMatrixUniform);

    st.uniform(gl, pmvMatrixUniform);
    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());
    Assert.assertEquals(pmvMatrixUniform, st.getUniform("mgl_PMVMatrix"));

    // Allocate Vertex Array1
    final GLArrayDataServer vertices1 = GLSLMiscHelper.createRSVertices1(gl, st);
    System.err.println("vertices1: " + vertices1);
    vertices1.enableBuffer(gl, false);
    GLSLMiscHelper.validateGLArrayDataServerState(gl, st, vertices1);
    st.ownAttribute(vertices1, true);

    // Allocate Color Array1
    final GLArrayDataServer colors1 = GLSLMiscHelper.createRSColors1(gl, st);
    System.err.println("colors1: " + colors1);
    colors1.enableBuffer(gl, false);
    GLSLMiscHelper.validateGLArrayDataServerState(gl, st, colors1);
    st.ownAttribute(colors0, true);

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

    // 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());
    Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError());

    // display #1 vertices0 / colors0 (post-disable)
    GLSLMiscHelper.displayVCArrays(
        drawable, gl, st, true, vertices0, colors0, true, 1, durationPerTest);

    // display #2 #1 vertices1 / colors1 (post-disable)
    GLSLMiscHelper.displayVCArrays(
        drawable, gl, st, true, vertices1, colors1, true, 2, durationPerTest);

    // display #3 vertices0 / colors0 (post-disable)
    GLSLMiscHelper.displayVCArrays(
        drawable, gl, st, true, vertices0, colors0, true, 3, durationPerTest);

    // cleanup
    st.destroy(gl);

    NEWTGLContext.destroyWindow(winctx);
  }
예제 #28
0
  void reshapeImpl(
      final GL2ES2 gl,
      final int tileX,
      final int tileY,
      final int tileWidth,
      final int tileHeight,
      final int imageWidth,
      final int imageHeight) {
    System.err.println(
        Thread.currentThread()
            + " RedSquareES2.reshape "
            + tileX
            + "/"
            + tileY
            + " "
            + tileWidth
            + "x"
            + tileHeight
            + " of "
            + imageWidth
            + "x"
            + imageHeight
            + ", swapInterval "
            + swapInterval
            + ", drawable 0x"
            + Long.toHexString(gl.getContext().getGLDrawable().getHandle())
            + ", tileRendererInUse "
            + tileRendererInUse);
    // Thread.dumpStack();
    if (!gl.hasGLSL()) {
      return;
    }

    st.useProgram(gl, true);
    // Set location in front of camera
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();

    // compute projection parameters 'normal' perspective
    final float fovy = 45f;
    final float aspect2 = ((float) imageWidth / (float) imageHeight) / aspect;
    final float zNear = 1f;
    final float zFar = 100f;

    // compute projection parameters 'normal' frustum
    final float top = (float) Math.tan(fovy * ((float) Math.PI) / 360.0f) * zNear;
    final float bottom = -1.0f * top;
    final float left = aspect2 * bottom;
    final float right = aspect2 * top;
    final float w = right - left;
    final float h = top - bottom;

    // compute projection parameters 'tiled'
    final float l = left + tileX * w / imageWidth;
    final float r = l + tileWidth * w / imageWidth;
    final float b = bottom + tileY * h / imageHeight;
    final float t = b + tileHeight * h / imageHeight;

    pmvMatrix.glFrustumf(l, r, b, t, zNear, zFar);
    // pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
    st.uniform(gl, pmvMatrixUniform);
    st.useProgram(gl, false);

    System.err.println(Thread.currentThread() + " RedSquareES2.reshape FIN");
  }