DirectFloatBuffer.java :  » Graphics-3D-2D-OpenGL » glscene » org » glscene » util » Android Open Source

Android Open Source » Graphics 3D 2D OpenGL » glscene 
glscene » org » glscene » util » DirectFloatBuffer.java
package org.glscene.util;

import java.io.IOException;
import java.io.Serializable;

import javax.microedition.khronos.opengles.GL10;

import org.glscene.geometry.Vectors2f;

public class DirectFloatBuffer extends DirectBuffer implements Serializable {
  
  public static final long serialVersionUID = 1L;
  
  public DirectFloatBuffer(Vectors2f vecCoords) {
    fGLSize = 2;
    
    if (vecCoords == null) {
      allocate(0);
    } else {
            allocate(vecCoords.size()*2*4);
            put(vecCoords);
    }
  }

  @Override
  public int GLType() { return GL10.GL_FLOAT; }
  
  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    if (fBuffer == null) {
      out.writeInt(0);
    } else {
      int n = fBuffer.capacity() >> 2;
      out.writeInt(n);
      for (int i=0; i<n; i++) {
        out.writeFloat(fBuffer.getFloat(i));
      }
    }
  }

  private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    int n = in.readInt();
    allocate(n);
    if (n > 0) {
      n >>= 2;
      for (int i=0; i<n; i++) {
        fBuffer.putFloat(i, in.readFloat());
      }
    }
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.