#ifndef n_glTextureTile_H
#define n_glTextureTile_H

/*
 *
 * nucleo/gl/texture/glTextureTile.H --
 *
 * Copyright (C) Nicolas Roussel
 *
 * See the file LICENSE for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
*/

#include <nucleo/image/Image.H>

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif

namespace nucleo {

  // ------------------------------------------------------------------

  class glTexture ;

  class glTextureTile {

  private:

    bool isStandard(Image *img) ;
    bool worksWithExtension(Image *img) ;
    void setup(Image *img, bool update) ;

    glTexture *master ;               // original image
 
    unsigned int x, y ;               // position of the upper-left
                                      // corner of the tile in the
							   // original image (0,0 is the
							   // upper-left corner of the
							   // image)

    unsigned int width, height ;      // dimensions of the tile

    GLuint texture ;
    unsigned int tWidth, tHeight ;    // dimensions of the texture
    GLint tAlignment, tInternalFormat ;
    GLenum tTarget, tFormat, tType ;

    Image memoryholder ;              // used to preserve texture data
							   // if direct memory access is
							   // turned on

    static int can_generate_mipmaps ;

  public:

    static int debugLevel ;

    // texture_rectangle extension policy
    typedef enum {FIRST_CHOICE=1, SECOND_CHOICE=2, DONT_USE=0} trePolicy ;

    glTextureTile(Image *img,
			   unsigned int x, unsigned int y, unsigned int w, unsigned int h,
			   glTexture *master) ;
    
    void update(Image *img) ;

    unsigned int getX(void) { return x ; }
    unsigned int getY(void) { return y ; }
    unsigned int getWidth(void) { return width ; }
    unsigned int getHeight(void) { return height ; }

    GLuint getTexture(void) { return texture ; }
    GLenum getTextureTarget(void) { return tTarget ; }
    unsigned int getTextureWidth(void) { return tWidth ; }
    unsigned int getTextureHeight(void) { return tHeight ; }   

    ~glTextureTile(void) ;

  } ;

  // ------------------------------------------------------------------
  
}

#endif
