/*****************************************************************************
 * $Id: eng_tex.hh,v 1.20 2006/11/19 00:52:55 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Texture code.
 *//*
 * LEGAL:	COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#ifndef ENG_TEX_HH
#define ENG_TEX_HH 1

// Texcoord8 is for texturing the front/back of one quad.
// TexBiquad reuses the same Texcoord8 twice for two quads.
// 8 floats for 4 (x,y) coordinates of each corner of quad.
typedef Array<8,fp> Texcoord8;

////////////////////////////////////////////////////////////////////////////////
/// @brief One quad textured front/back.
///
class TexQuad
{
PREVENT_COPYING(TexQuad)
private:	enum { VERTEX_CNT = 4 };

// Set() assigns all members except the public mWorldVertexs[]
// which user can do directly for speed.

// Methods:
public:					TexQuad( void );
public:					~TexQuad();
public:		void		Set( Texture2PtrConst texture, const Texcoord8& texcoords, const RGBA rgba );
public:		void		Draw( eGpBlend blend1 = GP_SRC_ALPHA, eGpBlend blend2 = GP_DST_ALPHA, eDepthTest = eDepthTest_ENABLE );
public:		uint		GetVertexCnt( void ) { return VERTEX_CNT; }

// Data (minimize to save memory):
public:		WorldVertex			mWorldVertexs[VERTEX_CNT];	// TexQuad::Draw() will transform world to eye
private:	Texture2Ptr			mTexture;
private:	const Texcoord8*	mTexcoords;			// shared
private:	RGBA				mRgba;
};

////////////////////////////////////////////////////////////////////////////////
/// @brief Two orthogonal quads textured front/back.
/// @remarks A textured bi-quad is two intersecting quads forming an extruded cross.
/// Useful for small objects that exist in multitudes (eg trees).
/// The same texture is applied to both quads.
/// If center is specified, the world vertexs will be calculated.
/// Otherwise, the caller must pass them to Draw().
/// @verbatim
///       +Z                      +Z
///        0                       4        
///        |                       |         
/// -X  1--+--3  bottom     -X  5--+--7  top
///        |                       |         
///        2                       6
/// @endverbatim
///
class TexBiquad
{
PREVENT_COPYING(TexBiquad)
private:	enum { VERTEX_CNT = 8, TEXCOORD_CNT = 4*2 };	// same texture is reused twice

public:							TexBiquad( void );
public:							~TexBiquad();
private:	void				Init( void );

// Long Set()/constructor and Draw(void) are paired (world vertexs calculated from center position)
// Short Set()/constructor and Draw(WorldVertex) are paired (caller specifies world vertexs)

//------------------------------------------------------------------------------
// Variants to calculate world vertexs from a given position,width,height.
public:		TexBiquad( const Position& center,
                       const fp width,
                       const fp height,
                       Texture2PtrConst texture,
                       const Texcoord8& texcoords,
                       const RGBA rgba )
			{
				Init();
				Set( center, width, height, texture, texcoords, rgba );
			}
public:		void Set( const Position& center,
                      const fp width,
                      const fp height,
                      Texture2PtrConst texture,
                      const Texcoord8& texcoords,
                      const RGBA rgba );
public:		void Draw( eDepthTest depthTest = eDepthTest_ENABLE );

// -----------------------------------------------------------------------------
// Variants for when caller will pass WorldVertex array to Draw().
public:		TexBiquad( Texture2PtrConst texture,
                       const Texcoord8& texcoords,
                       const RGBA rgba )
			{
				Init();
				Set( texture, texcoords, rgba );
			}
public:		void Set( Texture2PtrConst texture,
                      const Texcoord8& texcoords,
                      const RGBA rgba );
public:		void Draw( const WorldVertex wv[8], eDepthTest depthTest = eDepthTest_ENABLE );

// -----------------------------------------------------------------------------
// This is a common object (eg used for Trees), so minimize it to save memory.
// Use the Engine's SharedVal<RGBA> to maximize sharing RGBAs.
private:	WorldVertex*		mWorldVertexs;
private:	Texture2Ptr			mTexture;
private:	const Texcoord8*	mTexcoords;			// shared
private:	RGBA				mRgba;
};

#endif // ENG_TEX_HH
