#include "StdAfx.h"

class Texture
{
public:
  Texture() :mOpenGLTex(0) {};

  GLuint mOpenGLTex;
  int mSizeX;
  int mSizeY;
  float mScaleX;
  float mScaleY;
  char	mName[256];
  SDL_Surface* mSurface; // nil if not asked by loading
} ;

class GLContext
{
public: 
	GLContext();
	~GLContext();

	// Start rendering to this context
	void StartRender();
	
	// End rendering to this context
	void StopRender();

private:
	HPBUFFERARB mHBuffer; // handle to the pixel buffer
};


// Load an image from file, gets the texture nr as a result.
int	CreateTextureFromFile(char* inFileName, bool inNeedSurface);
// Create a GLTexture from ARGB memory
int CreateTextureFromMem(unsigned int* inARGBmem, int inSizeX, int inSizeY, bool inNeedSurface);
int ReplaceTextureFromMem(int inTextureNr, unsigned int* inABGRmem, int inSizeX, int inSizeY, bool inNeedSurface);

// Get a loaded(existing) textures by nr
Texture* GetTexture(int inImageNr); // no ownership!
// Get loaded (existing) surfaces by nr
SDL_Surface* GetSDLSurface(int inSurfaceNr); // no ownership!

int LoadGLTextureBitPlane(SDL_Surface* inSurface, int inPlane, Texture& ioTex );
// Release all images
void FreeImages();

// Render to Texture

bool CreatePBuffer(int inSizeX, int inSizeY);
void ReleasePBuffer();

void StartRenderToTexture();
const Texture* EndRenderToTexture();