/*
 * $Id$
 */

#ifndef Q_GL_BITMAP_WIDGET__H
#define Q_GL_BITMAP_WIDGET__H

// whether to use exceptions at all
//#define _Q_GL_BITMAP_WIDGET_USE_EXCEPTION

#ifdef _Q_GL_BITMAP_WIDGET_USE_EXCEPTION
#include <stdexcept>
#endif

#include <string>

#include <qgl.h>

class QGLBitmapWidget :
  public QGLWidget
{
public:
#ifdef _Q_GL_BITMAP_WIDGET_USE_EXCEPTION
  class QGLBitmapWidgetError : public std::runtime_error {
  public:
    QGLBitmapWidgetError( const std::string& what_arg ) : std::runtime_error( what_arg ) {}
  };
#endif // _Q_GL_BITMAP_WIDGET_USE_EXCEPTION

  QGLBitmapWidget(QWidget* parent = 0, const char* name = 0,
		  const QGLWidget* shareWidget = 0, WFlags f = 0);

  virtual ~QGLBitmapWidget();
  void setBufferSize(int frameBufferWidth, int frameBufferHeight);
  void updateFrameBuffer(const unsigned char* frameBuffer);
  void cleanup();

protected:
  virtual void resizeGL(int w, int h);
  virtual void paintGL();

private:
  int roundUpToNextHigherPowerOfTwo(int number);

  unsigned int frameBufferTexture;
  bool frameBufferTextureExists;
  int textureWidth;
  int textureHeight;
  int frameBufferWidth;
  int frameBufferHeight;
};

#endif // Q_GL_BITMAP_WIDGET__H
