Пример #1
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;
  }
Пример #2
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;
  }