Exemplo n.º 1
0
  /** Writes GL version info to the log. */
  public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
      int[] values = new int[1];
      GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
      int majorVersion = values[0];
      GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
      int minorVersion = values[0];
      if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
        Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
      }
    }
  }
Exemplo n.º 2
0
  private void flush() {
    DrawEnv d = mDraw;

    mVertBuf.flip();
    GLES30.glBufferSubData(GL_ARRAY_BUFFER, 0, mVertBuf.remaining(), mVertBuf);
    mVertBuf.clear();

    if (mActiveIndexer == null) {
      GLES30.glDrawArrays(mActiveMode, 0, mActivePos);
    } else {
      mIndBuf.flip();
      GLES30.glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, mIndBuf.remaining(), mIndBuf);
      GLES30.glDrawElements(mActiveMode, mActiveIndexer.count(), GL_UNSIGNED_INT, 0);
      mIndBuf.clear();
    }
    mActivePos = 0;
  }
Exemplo n.º 3
0
  private static boolean compileShader(final GLShader _shader) {
    _shader.id[0] = GLES30.glCreateShader(_shader.type);
    GLES30.glShaderSource(_shader.id[0], _shader.source[0]);
    GLES30.glCompileShader(_shader.id[0]);

    final int[] response = new int[] {0};
    GLES30.glGetShaderiv(_shader.id[0], GLES30.GL_COMPILE_STATUS, response, 0);
    if (response[0] == GLES30.GL_FALSE) {
      System.out.println(
          "Error compiling shader: "
              + _shader.file
              + "\n"
              + GLES30.glGetShaderInfoLog(_shader.id[0]));
      return false;
    }

    return true;
  }
Exemplo n.º 4
0
  public static boolean buildProgram(final GLProgram _program) {
    _program.id[0] = GLES30.glCreateProgram();
    if (_program.id[0] < 1) {
      System.out.println("Failed to create program..");
      return false;
    }

    for (final GLShader shader : _program.shaders) {
      // Attach only successfully compiled shaders
      if (compileShader(shader) == true) {
        GLES30.glAttachShader(_program.id[0], shader.id[0]);
      }
    }

    final List<String> swivel = _program.swivel;
    final int size = swivel.size();

    for (int i = 0; i < size; i++) {
      GLES30.glBindAttribLocation(_program.id[0], _program.inAttributes[i], swivel.get(i));
    }

    GLES30.glLinkProgram(_program.id[0]);

    _program.inMVPMatrix = GLES30.glGetUniformLocation(_program.id[0], "inMVPMatrix");

    // Once all of the shaders have been compiled
    // and linked, we can then detach the shader sources
    // and delete the shaders from memory.
    for (final GLShader shader : _program.shaders) {
      GLES30.glDetachShader(_program.id[0], shader.id[0]);
      GLES30.glDeleteShader(shader.id[0]);
    }
    _program.shaders.clear();

    final int[] response = new int[] {0};
    GLES30.glGetProgramiv(_program.id[0], GLES30.GL_LINK_STATUS, response, 0);
    if (response[0] == GLES30.GL_FALSE) {
      System.out.println("Error linking program: " + GLES30.glGetProgramInfoLog(_program.id[0]));
      return false;
    }

    return true;
  }
Exemplo n.º 5
0
  public Floor() {
    // make a floor
    ByteBuffer bbFloorVertices = ByteBuffer.allocateDirect(FLOOR_COORDS.length * 4);
    bbFloorVertices.order(ByteOrder.nativeOrder());
    floorVertices = bbFloorVertices.asFloatBuffer();
    floorVertices.put(FLOOR_COORDS);
    floorVertices.position(0);

    ByteBuffer bbFloorNormals = ByteBuffer.allocateDirect(FLOOR_NORMALS.length * 4);
    bbFloorNormals.order(ByteOrder.nativeOrder());
    floorNormals = bbFloorNormals.asFloatBuffer();
    floorNormals.put(FLOOR_NORMALS);
    floorNormals.position(0);

    ByteBuffer bbFloorColors = ByteBuffer.allocateDirect(FLOOR_COLORS.length * 4);
    bbFloorColors.order(ByteOrder.nativeOrder());
    floorColors = bbFloorColors.asFloatBuffer();
    floorColors.put(FLOOR_COLORS);
    floorColors.position(0);

    // now setup the shaders and program object
    int vertexShader = myStereoRenderer.LoadShader(GLES30.GL_VERTEX_SHADER, light_vertex);
    int gridShader = myStereoRenderer.LoadShader(GLES30.GL_FRAGMENT_SHADER, grid_fragment);
    int programObject;
    int[] linked = new int[1];

    // Create the program object
    programObject = GLES30.glCreateProgram();

    if (programObject == 0) {
      Log.e(TAG, "So some kind of error, but what?");
      return;
    }

    GLES30.glAttachShader(programObject, vertexShader);
    GLES30.glAttachShader(programObject, gridShader);

    // Link the program
    GLES30.glLinkProgram(programObject);

    // Check the link status
    GLES30.glGetProgramiv(programObject, GLES30.GL_LINK_STATUS, linked, 0);

    if (linked[0] == 0) {
      Log.e(TAG, "Error linking program:");
      Log.e(TAG, GLES30.glGetProgramInfoLog(programObject));
      GLES30.glDeleteProgram(programObject);
      return;
    }

    // Store the program object
    mProgramObject = programObject;
  }
Exemplo n.º 6
0
 public void end() {
   if (mActiveWriter == null) {
     return;
   }
   if (mActivePos > 0) {
     flush();
   }
   if (mActiveIndexer != null) {
     GLES30.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
     mActiveIndexer = null;
   }
   mActiveWriter.mVao.unbind(mDraw);
   mActiveWriter.mProgram.unbind(mDraw);
   DrawUtil.checkErr();
 }
Exemplo n.º 7
0
  public static int getSupportedMaxPictureSize() {
    int[] array = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, array, 0);

    try {
      if (array[0] == 0) {
        GLES11.glGetIntegerv(GLES11.GL_MAX_TEXTURE_SIZE, array, 0);

        if (array[0] == 0) {
          GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, array, 0);

          if (array[0] == 0) {
            GLES30.glGetIntegerv(GLES30.GL_MAX_TEXTURE_SIZE, array, 0);
          }
        }
      }
    } catch (NoClassDefFoundError e) {
      // Ignore the exception
    }

    return array[0] != 0 ? array[0] : 2048;
  }
Exemplo n.º 8
0
 public static void deleteProgram(final GLProgram _program) {
   // During the build process a programs
   // shaders list has already been detached
   // and destroyed.
   GLES30.glDeleteProgram(_program.id[0]);
 }
Exemplo n.º 9
0
  /**
   * Draw the floor.
   *
   * <p>This feeds in data for the floor into the shader. Note that this doesn't feed in data about
   * position of the light, so if we rewrite our code to draw the floor first, the lighting might
   * look strange.
   */
  public void drawFloor(
      float[] modelViewProjection,
      float[] modelFloor,
      float[] modelView,
      float[] lightPosInEyeSpace) {
    GLES30.glUseProgram(mProgramObject);
    floorModelParam = GLES30.glGetUniformLocation(mProgramObject, "u_Model");
    floorModelViewParam = GLES30.glGetUniformLocation(mProgramObject, "u_MVMatrix");
    floorModelViewProjectionParam = GLES30.glGetUniformLocation(mProgramObject, "u_MVP");
    floorLightPosParam = GLES30.glGetUniformLocation(mProgramObject, "u_LightPos");

    floorPositionParam = GLES30.glGetAttribLocation(mProgramObject, "a_Position");
    floorNormalParam = GLES30.glGetAttribLocation(mProgramObject, "a_Normal");
    floorColorParam = GLES30.glGetAttribLocation(mProgramObject, "a_Color");

    GLES30.glEnableVertexAttribArray(floorPositionParam);
    GLES30.glEnableVertexAttribArray(floorNormalParam);
    GLES30.glEnableVertexAttribArray(floorColorParam);

    // Set ModelView, MVP, position, normals, and color.
    GLES30.glUniform3fv(floorLightPosParam, 1, lightPosInEyeSpace, 0);
    GLES30.glUniformMatrix4fv(floorModelParam, 1, false, modelFloor, 0);
    GLES30.glUniformMatrix4fv(floorModelViewParam, 1, false, modelView, 0);
    GLES30.glUniformMatrix4fv(floorModelViewProjectionParam, 1, false, modelViewProjection, 0);
    GLES30.glVertexAttribPointer(
        floorPositionParam, COORDS_PER_VERTEX, GLES30.GL_FLOAT, false, 0, floorVertices);
    GLES30.glVertexAttribPointer(floorNormalParam, 3, GLES30.GL_FLOAT, false, 0, floorNormals);
    GLES30.glVertexAttribPointer(floorColorParam, 4, GLES30.GL_FLOAT, false, 0, floorColors);

    GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, 6);
  }