Esempio n. 1
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);
  }
Esempio 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;
  }