
//
// ASURA_PlatformAdObject.cpp
//
// Created by DWW 27/06/06
// 
// Copyright (C) 2006 Strangelite, All Rights Reserved.
//

#include "Core/Asura.h" 
#include "Core/Asura_TextureManagement.h"
#include "AdEngine/asura_adobject.h"
#include "Rendering/Asura_Direct3D.h"
#include "Core/Memory/Asura_Mem.h"

extern Direct3D_Texture* TextureStorage[];

// bool Asura_AdObject::Platform_RenderToTexture(void *pBits, int iWidth, int iHeight, int iByteSize, int iBytesPerPixel)
//
// Creation Date:		27/06/2006
// Author:				DWW 
//
// Description: add platform specific render to texture code here
//
//
bool Asura_AdObject::Platform_RenderToTexture(void *pBits, int iWidth, int iHeight, int iByteSize, int iBytesPerPixel)
{
	// make sure texture as been loaded and it is an add texture
	if (Asura_Texture_Management::IsTextureLoaded(m_iTextureID) && Asura_Texture_Management::IsTextureAd(m_iTextureID)) 
	{

	
		// PLATFORM SPECIFIC CODE HERE (PC)
		{
			// lock the texture
			D3DLOCKED_RECT rect;

			if(TextureStorage[m_iTextureID]->LockRect(0,&rect,NULL,D3DLOCK_DISCARD) == D3D_OK)
			{		
				// copy bits
				Asura_Mem::Copy(rect.pBits, pBits, rect.Pitch * iHeight);
//DeadCode AMM 04/09/2006 				memcpy(rect.pBits, pBits, rect.Pitch * iHeight);
					
				// unlock texture
				TextureStorage[m_iTextureID]->UnlockRect(0);

			} 
		}
		// END PLATFORM SPECIFIC CODE

		return true;

	}

	return false;
}

// bool Asura_AdObject::Platform_CreateAdTexture(const int iWidth, const int iHeight, const int iWidth, const int iHeight, const ASURA_AD_IMAGEFORMAT xImageFormat)
//
// Creation Date:		27/06/2006
// Author:				DWW 
//
// Description: Creates a platform specific texture
//
//
bool Asura_AdObject::Platform_CreateAdTexture(const int iWidth, const int iHeight, const ASURA_AD_IMAGEFORMAT xImageFormat)
{
	if (Asura_Texture_Management::IsTextureLoaded(m_iTextureID)) // make sure texture as been loaded
	{
		// check to see if it is as been flagged to be used by ads
		if (Asura_Texture_Management::IsTextureAd(m_iTextureID))
		{
			// PLATFORM SPECIFIC CODE HERE (PC)
			{
				if (TextureStorage[m_iTextureID])
				{
					TextureStorage[m_iTextureID]->Release();
				}

				D3DFORMAT d3dFormat = D3DFMT_X8R8G8B8;

				Asura_Direct3D::D3DDevice->CreateTexture(iWidth,iHeight,1,0,d3dFormat,D3DPOOL_MANAGED,&TextureStorage[m_iTextureID],0);
			}
			// END PLATFORM SPECIFIC CODE
			return true;
		}
	}
	
	return false;
}

bool Asura_AdObject::Platform_Initialise(void)
{
	return true;
}

bool Asura_AdObject::Platform_Shutdown(void)
{
	return true;
}

bool Asura_AdObject::Platform_Update(const float fFrameTime)
{
	return true;
}