//
// Tools_PS3_Texture_Writer.h
//
// Created by KJFL - 28 June 2005
//
// Copyright (C) 2005 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __TOOLS_PS3_TEXTURE_WRITER_H__
#define __TOOLS_PS3_TEXTURE_WRITER_H__

// in middleware.
#include "NVidia/DDS_Utilities/dxtlib.h"

#include "../PS3/Rendering/Asura_PS3_TextureHeader.h"

// storage for 1 mipmap level
class Tools_PS3_ImageData
{
	public:
		Tools_PS3_ImageData()
		{
			m_puPixelData=0;
			m_uWidth=0;
			m_uHeight=0;
			m_uImageSizeInBytes = 0;
		}

		~Tools_PS3_ImageData()
		{
			delete [] m_puPixelData;
		}

		void Reset(void)
		{
			delete [] m_puPixelData;

			m_puPixelData=0;
			m_uWidth=0;
			m_uHeight=0;
			m_uImageSizeInBytes = 0;
		}
		
		u_int*	m_puPixelData;
		u_int	m_uWidth;
		u_int	m_uHeight;
		u_int	m_uImageSizeInBytes;
};

class Tools_PS3_Texture_Writer
{
    public:

        // 12 images allows for 2048x2048 to 1x1, which fits in with current texture assets
        enum { MAXIMUM_NUMBER_OF_IMAGES = 12 };

        Tools_PS3_Texture_Writer( const u_int uWidth, const u_int uHeight,
                                  const u_int uPitch, const void* pPixels,
								  const struct TextureConversionData* pxConvertData,
								  nvTextureFormats eTextureFormat,
								  bool& bTextureWriterSucess,
                                  const u_int uMaxMipMapDrops = MAXIMUM_NUMBER_OF_IMAGES,
								  bool bAlphaOnly = false );
		Tools_PS3_Texture_Writer( const u_int uWidth, const u_int uHeight, //cubemaps
			const u_int uPitch,
			const void* pPixels0,
			const void* pPixels1,
			const void* pPixels2,
			const void* pPixels3,
			const void* pPixels4,
			const void* pPixels5,
			const struct TextureConversionData* pxConvertData,
			nvTextureFormats eTextureFormat,
			bool& bTextureWriterSucess,
			const u_int uMaxMipMapDrops = MAXIMUM_NUMBER_OF_IMAGES,
			bool bAlphaOnly = false );
        ~Tools_PS3_Texture_Writer();

        bool WriteOutFile(const char* szOutputFilename);
        
    private:

		static NV_ERROR_CODE MipMapCallback(const void* pPixelData, size_t uCount, const MIPMapData* pxMipMapData, void* pUserData);
        static Tools_PS3_Texture_Writer* s_pxCurTextureWriter;

		bool GetImages( const nvTextureFormats eTextureFormat, const u_int uWidth, const u_int uHeight, const u_int uPitch, const void* pPixels, const struct TextureConversionData* pxConvertData );

        Asura_PS3_TextureHeader m_xHeader;
        u_int                   m_uMaxResultingMipmaps;
		bool					m_bDropExtraMipLevel;
		u_int					m_uMaximumTextureSize;

        Tools_PS3_ImageData     m_axImage[MAXIMUM_NUMBER_OF_IMAGES];
		Tools_PS3_ImageData     m_axImages[ 6 ][MAXIMUM_NUMBER_OF_IMAGES];
        u_int                   m_uNumberOfImages;

};



#endif//__TOOLS_PS3_TEXTURE_WRITER_H__
