コード例 #1
0
  /** Disposes of all resources this VertexBufferObject uses. */
  @Override
  public void dispose() {
    if (App.getGL20() != null) {
      tmpHandle.clear();
      tmpHandle.put(bufferHandle);
      tmpHandle.flip();

      GL20 gl = App.getGL20();
      gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
      gl.glDeleteBuffers(1, tmpHandle);
      bufferHandle = 0;
    }
    //		BufferUtils.disposeUnsafeByteBuffer(byteBuffer);
  }
コード例 #2
0
  /** {@inheritDoc} */
  @Override
  public void setVertices(float[] vertices, int offset, int count) {
    isDirty = true;
    BufferUtils.copy(vertices, buffer, count, offset);
    buffer.position(0);
    buffer.limit(count);

    if (isBound) {
      if (App.getGL20() != null) {
        GL20 gl = App.getGL20();
        gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);
      }
      isDirty = false;
    }
  }
コード例 #3
0
 @Override
 public void unbind(final ShaderProgram shader, final int[] locations) {
   final GL20 gl = App.getGL20();
   final int numAttributes = attributes.size();
   if (locations == null) {
     for (int i = 0; i < numAttributes; i++) {
       shader.disableVertexAttribute(attributes.get(i).alias);
     }
   } else {
     for (int i = 0; i < numAttributes; i++) {
       final int location = locations[i];
       if (location >= 0) shader.disableVertexAttribute(location);
     }
   }
   gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);
   isBound = false;
 }
コード例 #4
0
  @Override
  public void bind(ShaderProgram shader, int[] locations) {

    if (bufferHandle == 0) throw new GLViewRuntimeException("No buffer allocated!");

    final GL20 gl = App.getGL20();

    gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);
    if (isDirty) {
      byteBuffer.limit(buffer.limit() * 4);
      gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);
      isDirty = false;
    }

    final int numAttributes = attributes.size();
    if (locations == null) {
      for (int i = 0; i < numAttributes; i++) {
        final VertexAttribute attribute = attributes.get(i);
        final int location = shader.getAttributeLocation(attribute.alias);
        if (location < 0) continue;
        shader.enableVertexAttribute(location);

        if (attribute.usage == Usage.ColorPacked)
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_UNSIGNED_BYTE,
              true,
              attributes.vertexSize,
              attribute.offset);
        else
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_FLOAT,
              false,
              attributes.vertexSize,
              attribute.offset);
      }
    } else {
      for (int i = 0; i < numAttributes; i++) {
        final VertexAttribute attribute = attributes.get(i);
        final int location = locations[i];
        if (location < 0) continue;
        shader.enableVertexAttribute(location);

        if (attribute.usage == Usage.ColorPacked)
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_UNSIGNED_BYTE,
              true,
              attributes.vertexSize,
              attribute.offset);
        else
          shader.setVertexAttribute(
              location,
              attribute.numComponents,
              GL20.GL_FLOAT,
              false,
              attributes.vertexSize,
              attribute.offset);
      }
    }
    isBound = true;
  }