Direct Buffer : Buffer « File « Android






Direct Buffer

 
//package org.glscene.util;

import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import javax.microedition.khronos.opengles.GL10;
interface DirectBufferable {
  public void putInto(ByteBuffer buffer);
}
abstract class DirectBuffer implements Serializable {

  public static final long serialVersionUID = 1L;

  protected transient ByteBuffer fBuffer;
  protected int fGLSize; 
  
  protected void allocate(int size) {
    if (size == 0) {
      fBuffer = null;
    } else {
      fBuffer = ByteBuffer.allocateDirect(size);
      fBuffer.order(ByteOrder.nativeOrder());
    }
  }
  
  protected void put(DirectBufferable aBufferable) {
    aBufferable.putInto(fBuffer);
        fBuffer.position(0);
  }
  
  abstract public int GLType();
  
  public boolean empty() {
    return (fBuffer != null);
  }
  
  public int size() {
    if (fBuffer == null) {
      return 0;
    } else {
      return (fBuffer.capacity() >> 2);
    }
  }
  
  public void glVertexPointer(GL10 gl) {
    gl.glVertexPointer(fGLSize, GLType(), 0, fBuffer);
  }
  public void glVertexPointer(GL10 gl, int size, int stride) {
    gl.glVertexPointer(size, GLType(), stride, fBuffer);
  }
  
  public void glNormalPointer(GL10 gl) {
    gl.glNormalPointer(GLType(), 0, fBuffer);
  }
  public void glNormalPointer(GL10 gl, int stride) {
    gl.glNormalPointer(GLType(), stride, fBuffer);
  }
  
  public void glColorPointer(GL10 gl) {
    gl.glColorPointer(fGLSize, GLType(), 0, fBuffer);
  }
  public void glColorPointer(GL10 gl, int size, int stride) {
    gl.glColorPointer(size, GLType(), stride, fBuffer);
  }
  
  public void glTexCoordPointer(GL10 gl) {
    gl.glTexCoordPointer(fGLSize, GLType(), 0, fBuffer);
  }
  public void glTexCoordPointer(GL10 gl, int size, int stride) {
    gl.glTexCoordPointer(size, GLType(), stride, fBuffer);
  }
  
}

   
  








Related examples in the same category

1.Fast Float Buffer
2.Demonstrate the Frame Buffer Object OpenGL ES extension.
3.Loads a file to a ByteBuffer.
4.Make a direct NIO FloatBuffer from an array of floats
5.Make a direct NIO ByteBuffer from an array of bytes
6.Make Float Buffer From Array
7.Creates a floatbuffer of the given size.
8.Make Float Buffer with ByteBuffer.allocateDirect
9.allocate Float Buffer
10.to Short Buffer
11.to Float Buffer Position Zero
12.allocate Short Buffer
13.allocate Int Buffer
14.Read InputStream with BufferedReader
15.To convert the InputStream to String we use the BufferedReader.readLine() method.
16.make Float Buffer
17.get Buffer From Array
18.Your own float buffer
19.create Buffer
20.Write String to File with BufferWriter
21.Byte Buffer Stack
22.Compute the SHA-1 hash of the bytes in the given buffer
23.An utility class for java.nio.Buffers