コード例 #1
0
  private void prepareBuffers(GLCanvas canvas) {
    mBufferNames = new int[3];
    GL11 gl = canvas.getGLInstance();
    GLId.glGenBuffers(3, mBufferNames, 0);

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBufferNames[0]);
    gl.glBufferData(
        GL11.GL_ARRAY_BUFFER,
        mXyBuffer.capacity() * (Float.SIZE / Byte.SIZE),
        mXyBuffer,
        GL11.GL_STATIC_DRAW);

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBufferNames[1]);
    gl.glBufferData(
        GL11.GL_ARRAY_BUFFER,
        mUvBuffer.capacity() * (Float.SIZE / Byte.SIZE),
        mUvBuffer,
        GL11.GL_STATIC_DRAW);

    gl.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mBufferNames[2]);
    gl.glBufferData(
        GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer.capacity(), mIndexBuffer, GL11.GL_STATIC_DRAW);

    // These buffers are never used again.
    mXyBuffer = null;
    mUvBuffer = null;
    mIndexBuffer = null;
  }
コード例 #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 プロジェクト: 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;
      }
    }
  }
コード例 #4
0
  private void initialize() {
    GL11 gl = mGL;

    // First create an nio buffer, then create a VBO from it.
    int size = BOX_COORDINATES.length * Float.SIZE / Byte.SIZE;
    FloatBuffer xyBuffer = allocateDirectNativeOrderBuffer(size).asFloatBuffer();
    xyBuffer.put(BOX_COORDINATES, 0, BOX_COORDINATES.length).position(0);

    int[] name = new int[1];
    GLId.glGenBuffers(1, name, 0);
    mBoxCoords = name[0];

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    gl.glBufferData(
        GL11.GL_ARRAY_BUFFER,
        xyBuffer.capacity() * (Float.SIZE / Byte.SIZE),
        xyBuffer,
        GL11.GL_STATIC_DRAW);

    gl.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    // Enable the texture coordinate array for Texture 1
    gl.glClientActiveTexture(GL11.GL_TEXTURE1);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
    gl.glClientActiveTexture(GL11.GL_TEXTURE0);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // mMatrixValues and mAlpha will be initialized in setSize()
  }
コード例 #5
0
ファイル: VBOVertices3.java プロジェクト: guykirs/MrNom
  public void setVertices(float[] vertices, int offset, int length) {
    super.setVertices(vertices, offset, length);

    GL11 gl = (GL11) glGraphics.getGL();
    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, vboHandle);
    gl.glBufferData(
        GL11.GL_ARRAY_BUFFER, this.vertices.limit() * 4, this.vertices, GL11.GL_STATIC_DRAW);
    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);
  }
コード例 #6
0
  public IndexBuffer(GLManager glManager, MQOIndexBuffer ib) {
    setGLManager(glManager);
    indices = getGLManager().genVBO();

    bind();
    {
      short[] buf = ib.getIndices();
      ShortBuffer sb =
          ByteBuffer.allocateDirect(buf.length * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
      sb.put(buf);
      sb.position(0);
      indices_length = buf.length;

      GL11 gl = getGLManager().getGL();
      gl.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, sb.capacity() * 2, sb, GL11.GL_STATIC_DRAW);
    }
    unbind();
  }
コード例 #7
0
  public void selectOnHardware(final GL11 pGL11) {
    final int hardwareBufferID = this.mHardwareBufferID;
    if (hardwareBufferID == -1) {
      return;
    }

    GLHelper.bindBuffer(
        pGL11,
        hardwareBufferID); // TODO Does this always need to be binded, or are just for buffers of
                           // the same 'type'(texture/vertex)?

    if (this.mHardwareBufferNeedsUpdate) {
      //			Debug.d("BufferObject.updating: ID = "  + this.mHardwareBufferID);
      this.mHardwareBufferNeedsUpdate = false;
      // BufferUtils.copy(mBufferData, mFloatBuffer, mFloatBuffer.capacity(), 0);
      pGL11.glBufferData(
          GL11.GL_ARRAY_BUFFER, mFloatBuffer.capacity() * 4, mFloatBuffer, mDrawType);
    }
  }
コード例 #8
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()));
      }
    }
  }
コード例 #9
0
 @Override
 public void glBufferData(int target, int size, Buffer data, int usage) {
   gl.glBufferData(target, size, data, usage);
 }
コード例 #10
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);
  }
コード例 #11
0
ファイル: GLHelper.java プロジェクト: ghd214/Sketchy-Truck
 public static void bufferData(final GL11 pGL11, final ByteBuffer pByteBuffer, final int pUsage) {
   pGL11.glBufferData(GL11.GL_ARRAY_BUFFER, pByteBuffer.capacity(), pByteBuffer, pUsage);
 }