import java.awt.*;


public class Buffer {
  
  protected int width;
  protected int height;
  protected float z[];
  protected final static int ZBITS = 16 ;

  ///////////////////////// CONSTRUCTORS ///////////////////
  
  
  /**
   *  This constructor creates an uninitialized
   *  Buffer Object of a given size (w x h).
   */
  public Buffer(int w, int h) {
    width = w;
    height = h;
    z = new float[w*h];
    initZ();
  }
  

  ////////////////////////// METHODS //////////////////// 
  
  /**
   *  Returns the size of z-buffer
   */
  public final int getZSize( ) {
    return z.length;
  }
  
  /**
   *  Returns zMax
   */
  public final int getZmax( ) {
    return ((1<<ZBITS)-1);
  }
 
  /**
   *  Fills z  with zmax
   */
  public final void initZ() {
    int s = getZSize();
    float zMax = getZmax( );
    for (int i = 0; i < s; i++){	z[i] = zMax;}
  }
  

  
  /**
   *  Gets a z-value from z-buffer
   */
  public final float getZBuf(int x, int y) {
    return z[y*width+x];
  }

  
  /**
   *  Sets a z-locatio to a given value
   */
  public final void setZBuf(float zVal, int x, int y) {
    z[y*width+x] = zVal;
  }
  

  public final int getWidth() {
    return width;
  }

 public final int getHeight() {
    return height;
  }

  public final void printZBuf() {
    for( int y=0; y< height; y++ ) {
      for( int x=0; x< width; x++ ) {
	System.out.println( (y*width+x) + " z[ "+ x +", " + y +"]=" + z[y*width+x] );
      }
    }
  }



}//BUFFER

