//----------------------------------------------------------------------------
// High-res OpenGL snapshot code
// (C) 1999,2004   Bill Baxter
//----------------------------------------------------------------------------
// Some parts of the code refer to the GLVU class library, which is available
// here:  http://www.cs.unc.edu/~walk/software/glvu
//----------------------------------------------------------------------------
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation.  Binaries may be compiled with
// this software without any royalties or restrictions.
//
// The University of North Carolina at Chapel Hill makes no representations 
// about the suitability of this software for any purpose. It is provided 
// "as is" without express or implied warranty.
//-----------------------------------------------------------------------------
#ifndef HIRES_SNAPSHOT_H
#define HIRES_SNAPSHOT_H
#include <string>
#include <camera.hpp>

class HiresSnapper
{
public:
  HiresSnapper();
  HiresSnapper(const Camera& cam, int tileXSize, int tileYSize, bool doAlpha=false);
  void setCam(const Camera& cam);
  void getCam(Camera& cam) const;
  void cameraSetup();
  void cameraSetup( Camera &cam );
  void snap();
  bool nextTile( );
  void setSnapshotCallback( void (*snapper)(const char* file) );

private:
  static void grabSnapshot(const char *file);
  static void grabSnapshotAlpha(const char *file);

private:  
  std::string m_filename;
  int m_tileNumX;
  int m_tileNumY;
  int m_gridW;
  int m_gridH;
  
  void (*m_snapshotCallback)(const char* file);
  Camera m_cam;
};

#define HIRES_SNAP_BEGIN(label,cam,w,h,alpha,flag) \
  HiresSnapper *_snapper_=0; \
  if (flag) { _snapper_ = new HiresSnapper(cam,w,h,alpha); \
  label : \
  _snapper_->cameraSetup(cam); } do {} while(0)
  
#define HIRES_SNAP_END(label,flag) \
  if (flag) { _snapper_->snap(); \
  if (_snapper_->nextTile()) goto label; } \
  flag = false



#endif

