view LightClone/Source/ResourceManager.cpp @ 25:eae13b04b06f

Working on Gui drag and drop
author koryspansel <koryspansel@bendbroadband.com>
date Fri, 16 Sep 2011 13:11:35 -0700
parents 968341ab1fb2
children 3a63df04f3c0
line wrap: on
line source

/*
 * ResourceManager
 */

#include "ResourceManager.h"

/*
 * ResourceManager
 */
ResourceManager::ResourceManager()
{
}

/*
 * Initialize
 */
ErrorCode ResourceManager::Initialize(GraphicsDevice* pDevice)
{
	return pGraphicsDevice = pDevice, Error_Success;
}

/* 
 * Terminate
 */
void ResourceManager::Terminate()
{
	pGraphicsDevice = NULL;
}

/*
 * CreateTextureFromFile
 */
ErrorCode ResourceManager::CreateTextureFromFile(const char* pName, IDirect3DTexture9** pTexture)
{
	ErrorCode eCode = Error_Fail;

	if(pGraphicsDevice)
	{
		const uint32 nSizeX		= D3DX_DEFAULT_NONPOW2;
		const uint32 nSizeY		= D3DX_DEFAULT_NONPOW2;
		const uint32 nFilter	= D3DX_DEFAULT;
		const uint32 nFilterMip	= D3DX_DEFAULT;

		HRESULT hResult = D3DXCreateTextureFromFileExA(*pGraphicsDevice, pName, nSizeX, nSizeY, 0, 0, D3DFMT_FROM_FILE, D3DPOOL_MANAGED, nFilter, nFilterMip, 0, NULL, NULL, pTexture);
		if(SUCCEEDED(hResult))
		{
			eCode = Error_Success;
		}
	}

	return eCode;
}

/*
 * CreateEffectFromFile
 */
ErrorCode ResourceManager::CreateEffectFromFile(const char* pName, ID3DXEffect** pEffect)
{
	ErrorCode eCode = Error_Fail;

	if(pGraphicsDevice)
	{
		ID3DXBuffer* pBuffer = NULL;

		HRESULT hResult = D3DXCreateEffectFromFileA(*pGraphicsDevice, pName, NULL, NULL, 0, NULL, pEffect, &pBuffer);
		if(SUCCEEDED(hResult))
		{
			eCode = Error_Success;
		}
	}

	return eCode;
}

/*
 * CreateVertexBuffer
 */
ErrorCode ResourceManager::CreateVertexBuffer(uint32 nSize, uint32 nUsage, uint32 nPool, IDirect3DVertexBuffer9** pBuffer)
{
	ErrorCode eCode = Error_Fail;

	if(pGraphicsDevice)
	{
		//HRESULT hResult = ((IDirect3DDevice9*)*pGraphicsDevice)->CreateVertexBuffer(nSize, nUsage, 0, (D3DPOOL)nPool, pBuffer, NULL);
		HRESULT hResult = static_cast<IDirect3DDevice9*>(*pGraphicsDevice)->CreateVertexBuffer(nSize, nUsage, 0, (D3DPOOL)nPool, pBuffer, NULL);
		if(SUCCEEDED(hResult))
		{
			eCode = Error_Success;
		}
	}

	return eCode;
}

/*
 * CreateFontFromName
 */
ErrorCode ResourceManager::CreateFontFromName(const char* pName, uint32 nSize, uint32 nWeight, ID3DXFont** pFont)
{
	ErrorCode eCode = Error_Fail;

	if(pGraphicsDevice)
	{
		HRESULT hResult = D3DXCreateFontA(*pGraphicsDevice, nSize, 0, nWeight, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, pName, pFont);
		if(SUCCEEDED(hResult))
		{
			eCode = Error_Success;
		}
	}

	return eCode;
}