コード例 #1
0
ファイル: Grid.java プロジェクト: tipusarowar/RapidBall_VBO
  /**
   * Allocates hardware buffers on the graphics card and fills them with data if a buffer has not
   * already been previously allocated. Note that this function uses the GL_OES_vertex_buffer_object
   * extension, which is not guaranteed to be supported on every device.
   *
   * @param gl A pointer to the OpenGL ES context.
   */
  public void generateHardwareBuffers(GL10 gl) {
    if (!mUseHardwareBuffers) {
      if (gl instanceof GL11) {
        GL11 gl11 = (GL11) gl;
        int[] buffer = new int[1];

        // Allocate and fill the vertex buffer.
        gl11.glGenBuffers(1, buffer, 0);
        mVertBufferIndex = buffer[0];
        gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex);
        final int vertexSize = mVertexBuffer.capacity() * mCoordinateSize;
        gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertexSize, mVertexBuffer, GL11.GL_STATIC_DRAW);

        // Allocate and fill the texture coordinate buffer.
        gl11.glGenBuffers(1, buffer, 0);
        mTextureCoordBufferIndex = buffer[0];
        gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mTextureCoordBufferIndex);
        final int texCoordSize = mTexCoordBuffer.capacity() * mCoordinateSize;
        gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoordSize, mTexCoordBuffer, GL11.GL_STATIC_DRAW);

        // Allocate and fill the color buffer.
        gl11.glGenBuffers(1, buffer, 0);
        mColorBufferIndex = buffer[0];
        gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mColorBufferIndex);
        final int colorSize = mColorBuffer.capacity() * mCoordinateSize;
        gl11.glBufferData(GL11.GL_ARRAY_BUFFER, colorSize, mColorBuffer, GL11.GL_STATIC_DRAW);

        // Unbind the array buffer.
        gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);

        // Allocate and fill the index buffer.
        gl11.glGenBuffers(1, buffer, 0);
        mIndexBufferIndex = buffer[0];
        gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferIndex);
        // A char is 2 bytes.
        final int indexSize = mIndexBuffer.capacity() * 2;
        gl11.glBufferData(
            GL11.GL_ELEMENT_ARRAY_BUFFER, indexSize, mIndexBuffer, GL11.GL_STATIC_DRAW);

        // Unbind the element array buffer.
        gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);

        mUseHardwareBuffers = true;

        assert mVertBufferIndex != 0;
        assert mTextureCoordBufferIndex != 0;
        assert mIndexBufferIndex != 0;
        assert gl11.glGetError() == 0;
      }
    }
  }
コード例 #2
0
    public void createBufferObjects(GL gl) {
      checkGLError(gl);
      // Generate a the vertex and element buffer IDs
      int[] vboIds = new int[2];
      GL11 gl11 = (GL11) gl;
      gl11.glGenBuffers(2, vboIds, 0);
      mVertexBufferObjectId = vboIds[0];
      mElementBufferObjectId = vboIds[1];

      // Upload the vertex data
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertexBufferObjectId);
      mVertexByteBuffer.position(0);
      gl11.glBufferData(
          GL11.GL_ARRAY_BUFFER,
          mVertexByteBuffer.capacity(),
          mVertexByteBuffer,
          GL11.GL_STATIC_DRAW);

      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mElementBufferObjectId);
      mIndexBuffer.position(0);
      gl11.glBufferData(
          GL11.GL_ELEMENT_ARRAY_BUFFER,
          mIndexBuffer.capacity() * CHAR_SIZE,
          mIndexBuffer,
          GL11.GL_STATIC_DRAW);

      // We don't need the in-memory data any more
      mVertexBuffer = null;
      mVertexByteBuffer = null;
      mIndexBuffer = null;
      checkGLError(gl);
    }
コード例 #3
0
ファイル: Grid.java プロジェクト: ksaua/mousekiller
  public void generateBuffers(GL10 gl) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
    vbb.order(ByteOrder.nativeOrder());
    FloatBuffer vertexBuffer = vbb.asFloatBuffer();
    vertexBuffer.put(vertices);
    vertexBuffer.position(0);

    // Set up Indexbuffer
    ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
    ibb.order(ByteOrder.nativeOrder());
    ShortBuffer indexBuffer = ibb.asShortBuffer();
    indexBuffer.put(indices);
    indexBuffer.position(0);

    // Set up Texturebuffer
    ByteBuffer tbb = ByteBuffer.allocateDirect(textureCoords.length * 4);
    tbb.order(ByteOrder.nativeOrder());
    FloatBuffer textureBuffer = tbb.asFloatBuffer();
    textureBuffer.put(textureCoords);
    textureBuffer.position(0);

    // Initialize gl buffers
    if (gl instanceof GL11) {
      GL11 gl11 = (GL11) gl;
      int[] buffer = new int[1];

      // Allocate and fill the vertex buffer.
      gl11.glGenBuffers(1, buffer, 0);
      vertexbufferId = buffer[0];
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, vertexbufferId);
      final int vertexSize = vertexBuffer.capacity() * 4;
      gl11.glBufferData(GL11.GL_ARRAY_BUFFER, vertexSize, vertexBuffer, GL11.GL_STATIC_DRAW);

      // Allocate and fill the texture coordinate buffer.
      gl11.glGenBuffers(1, buffer, 0);
      texturebufferId = buffer[0];
      gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, texturebufferId);
      final int texCoordSize = textureBuffer.capacity() * 4;
      gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoordSize, textureBuffer, GL11.GL_STATIC_DRAW);

      // Allocate and fill the index buffer.
      gl11.glGenBuffers(1, buffer, 0);
      indexbufferId = buffer[0];
      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, indexbufferId);
      // A short is 2 bytes.
      final int indexSize = indexBuffer.capacity() * 2;
      gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, indexSize, indexBuffer, GL11.GL_STATIC_DRAW);

      // Unbind the element array buffer.
      gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, 0);

      if (vertexbufferId == 0
          || texturebufferId == 0
          || indexbufferId == 0
          || gl.glGetError() != 0) {
        Log.e(
            "Grid",
            "VBO Not available: " + gl.glGetError() + ", " + gl.glGetString(gl.glGetError()));
      }
    }
  }
コード例 #4
0
  private int generateHardwareBufferID(final GL11 pGL11) {
    pGL11.glGenBuffers(1, HARDWAREBUFFERID_FETCHER, 0);

    return HARDWAREBUFFERID_FETCHER[0];
  }
コード例 #5
0
ファイル: VBOVertices3.java プロジェクト: guykirs/MrNom
 public void createHandle() {
   int[] tmp = new int[1];
   GL11 gl = (GL11) glGraphics.getGL();
   gl.glGenBuffers(1, tmp, 0);
   vboHandle = tmp[0];
 }
コード例 #6
0
 @Override
 public void glGenBuffers(int n, IntBuffer buffers) {
   gl.glGenBuffers(n, buffers);
 }
コード例 #7
0
 @Override
 public void glGenBuffers(int n, int[] buffers, int offset) {
   gl.glGenBuffers(n, buffers, offset);
 }
コード例 #8
0
  private void createQuadBuffer(GL10 gl10) {

    GL11 gl = (GL11) gl10;

    //
    // quad = ([vertex x, vertex y, texture x, texture y, red, green, blue, alpha] * 4) = 8 * 4 *
    // (float=4bytes) = 128 bytes
    //
    quads = new float[32 * maxParticles];
    indices = new short[maxParticles * 6];
    particles = new Particle[maxParticles];

    for (int i = 0; i < maxParticles; i++) {
      indices[i * 6 + 0] = (short) (i * 4 + 0);
      indices[i * 6 + 1] = (short) (i * 4 + 1);
      indices[i * 6 + 2] = (short) (i * 4 + 2);

      indices[i * 6 + 3] = (short) (i * 4 + 2);
      indices[i * 6 + 4] = (short) (i * 4 + 3);
      indices[i * 6 + 5] = (short) (i * 4 + 0);
    }

    // initialize texture.x, texture.y
    for (int i = 0; i < maxParticles; i++) {
      int vi = i * 32;

      quads[vi + 0] = 0; // vertex  x
      quads[vi + 1] = 0; // vertex  y

      quads[vi + 2] = 0 + getTexelHalfX(); // texture x
      quads[vi + 3] = getTexture().getMaxT() + getTexelHalfY(); // texture y

      quads[vi + 4] = 0; // red
      quads[vi + 5] = 0; // green
      quads[vi + 6] = 0; // blue
      quads[vi + 7] = 0; // alpha

      // -----------------------------
      quads[vi + 8] = 0; // vertex  x
      quads[vi + 9] = 1; // vertex  y

      quads[vi + 10] = 0 + getTexelHalfX();
      quads[vi + 11] = 0 - getTexelHalfY();

      quads[vi + 12] = 0; // red
      quads[vi + 13] = 0; // green
      quads[vi + 14] = 0; // blue
      quads[vi + 15] = 0; // alpha

      // -----------------------------
      quads[vi + 16] = 1; // vertex  x
      quads[vi + 17] = 1; // vertex  y

      quads[vi + 18] = getTexture().getMaxS() - getTexelHalfX();
      quads[vi + 19] = 0 - getTexelHalfY();

      quads[vi + 20] = 0; // red
      quads[vi + 21] = 0; // green
      quads[vi + 22] = 0; // blue
      quads[vi + 23] = 0; // alpha

      // -----------------------------
      quads[vi + 24] = 1; // vertex  x
      quads[vi + 25] = 0; // vertex  y

      quads[vi + 26] = getTexture().getMaxS() - getTexelHalfX();
      quads[vi + 27] = getTexture().getMaxT() + getTexelHalfY();

      quads[vi + 28] = 0; // red
      quads[vi + 29] = 0; // green
      quads[vi + 30] = 0; // blue
      quads[vi + 31] = 0; // alpha
    }

    quadsBuffer = GLHelper.createFloatBuffer(quads);

    // Generate the vertices VBO
    gl.glGenBuffers(1, verticesID, 0);
    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, verticesID[0]);
    gl.glBufferData(GL11.GL_ARRAY_BUFFER, 128 * maxParticles, quadsBuffer, GL11.GL_DYNAMIC_DRAW);
    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);

    // By default the particle emitter is active when created
    active = true;

    // Set the particle count to zero
    particleCount = 0;

    // Reset the elapsed time
    elapsedTime = 0;

    indicesBuffer = GLHelper.createShortBuffer(indices);
  }