//////////////////////////////////////////////////////////////////////////////
//
// Asura_Platform_MovieToTextureStream.h
//
// Copyright (c) 2002 Rebellion. All rights reserved.
//
// Description:
//
//     Class for streaming in MPEG data. Provides all functionality necessary
//     for uploading each frame's texture data.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_PLATFORM_MOVIETOTEXTURESTREAM_H___
#define ___ASURA_PLATFORM_MOVIETOTEXTURESTREAM_H___ 1

#include "Core/Asura_PlatformBasics.h"


// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////
union Asura_PS2_QW;

// C L A S S E S /////////////////////////////////////////////////////////////

#if defined(ASURA_PS2_SUPPORT_BINK) && defined(ASURA_SUPPORT_FMV_TEXTURES)

#include "BinkPS2/bink.h"
#include "BinkPS2/rad_iop.h"

class Asura_Platform_MovieToTextureStream
{
	friend class Asura_MovieToTexture_System;

	public:

		u_int GetDmaChainCallAddr( u_int uBfr )	const;
		void  GetTex0( u_long *pulTex0, u_int uTBP ) const;
		u_int GetDataSize( void ) const;
	
	private:
	
		Asura_Platform_MovieToTextureStream(const int iTextureIndex, const char* pxMovieName, bool* pbOK);
		~Asura_Platform_MovieToTextureStream();

		void Update(void);
        int GetTextureIndex( void ) { return m_iTextureIndex; }
		

		// internal use function
		bool WriteDMAChain( Asura_PS2_QW* pxOut, u_int uBuffer ) const;

		// static funtions - public so movie player can access
	public:
		static u_int GetNumQWsForDMAChain( u_int uWidth, u_int uHeight );
		static bool WriteUploadDmaDataForOneLevel( u_int uWidth, u_int uHeight,
			Asura_PS2_QW** ppxOut, u_int uMipLevel, u_int uTBP, const u_long128* 
			puImgData, bool bNeedEOP );
		
	private:
		
		HBINK					m_pxBinkHandle;
		int						m_iTextureIndex;
		char*					m_pcTextureBuffer;
		mutable Asura_PS2_QW*	m_apxDMAChains[2];
		mutable u_int			m_uLastUsedFrame;
		u_char					m_ucTBW;	// width / 64
		u_char					m_ucTW;		// width = 2^tw
		u_char					m_ucTH;		// height = 2^th
};
#else
#include "Core/Asura_Handle.h"
class Asura_Platform_MovieToTextureStream
{

    public:

        // M E T H O D S /////////////////////////////////////////////////////

        void Update( void );

			   u_int GetDmaChainCallAddr( u_int uDestBfrBase )	const;
			   void	 GetTex0( u_long *pulTex0, u_int uTBP )		const;
		inline int	 GetFileHandle( void )						const { return m_xFileHandle;	}
        inline int	 GetTextureIndex( void )					const { return m_iTextureIdx;	}
		inline u_int GetFileLength( void )						const { return m_uFileLength;	}
		

    private:
        // F R I E N D S /////////////////////////////////////////////////////

        friend class Asura_MovieToTexture_System;

        // C O N S T R U C T O R S   /   D E S T R U C T O R S ///////////////

        Asura_Platform_MovieToTextureStream( const int iTextureIndex, const char* pxMovieName, bool* pbOK, bool bLooping, bool bHoldAtEnd );
        ~Asura_Platform_MovieToTextureStream( void );

		bool IsReadyToBeDestroyed() const {return false;}
        // S T A T E /////////////////////////////////////////////////////////

        int				m_iTextureIdx;
        Asura_Handle	m_xFileHandle;
        int				m_iMpegHandle;
		u_int			m_uFileLength;
};
// End class Asura_Platform_MovieToTextureStream.
#endif

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_PLATFORM_MOVIETOTEXTURESTREAM_H___
