/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: include/domains/graphics/surface/sgxsurface.hpp

*/

#ifndef SGX_DOMAIN_GRAPHICS_SGXSURFACE_HPP
#define SGX_DOMAIN_GRAPHICS_SGXSURFACE_HPP	1

class sgxUV {
public:
	tREAL32 u1,v1;
	tREAL32 u2,v2;

	sgxUV() { u1=v1=0; u2=v2=1; }
	sgxUV(const tREAL32 u1_, const tREAL32 v1_, const tREAL32 u2_, const tREAL32 v2_) { u1=u1_;u2=u2_;v1=v1_;v2=v2_;}
};

class CSGXSurface {
public:
	typedef enum {
		eReasonDefault = 0,
		eReasonDynamic,
		eReasonVideo,
		eReasonRenderTarget,
	} tReason;

	typedef enum {
		eRepeatUV = 0,
		eRepeatUClampV,
		eRepeatVClampU,
		eClampUV,
		eClampURepeatV = eRepeatVClampU,
	} tWrapped;

	typedef enum {
		eBlendDefault = 0,
		eBlendDecal = eBlendDefault,
		eBlend,
		eBlendModulate,
		eBlendReplace,
	} tBlendMode;

	CSGXSurface(const CImageData &surface, const tReason reason=eReasonDefault);
	CSGXSurface(const tUINT32 width, const tUINT32 height, const CImageData::tFormat format, void *bitmap, const tReason reason);
	virtual ~CSGXSurface() {}

	virtual void	set() const;
	virtual void	setRegion(const tUINT32 region);
	virtual void	setRegion(const sgxUV &uv);	
	virtual void	setWrapped(const tWrapped wrapped);
	virtual void	setBlendMode(const tBlendMode mode);

	virtual void	*getDynamicBitmap();
	virtual tBOOL	getDynamicImageData(CImageData &data) const;
	virtual void	rebuild(void *pBitmap=NULL);

	virtual tBOOL	lock(CImageData &img);
	virtual tBOOL	unlock();

	virtual tUINT32	getWidth() const;
	virtual tUINT32	getHeight() const;
	// TODO: Resolve conflict/duplication with SGXSurface and ImageData - if any
	// TODO: should imageData have different format?
	static	tUINT32	getBytesPerPixel(const CImageData::tFormat f) { return CImageData::bpp(f); }

protected:
	tUINT32				m_iWidth, m_iHeight;
	CImageData::tFormat	m_iFormat;
	tReason				m_iReason;
	void				*m_pBitmap;		// A copy of the original data bits. Only kept if dynamic.
	CAtomicLock			m_Lock;
	tBlendMode			m_BlendMode;
	tWrapped 			m_Wrapped;
	
private:
	CSGXSurface()	{ sgxError("Invalid ctor"); }
};

#endif /* SGX_DOMAIN_GRAPHICS_SGXSURFACE_HPP */
