예제 #1
0
	void GraphD3D9::init( HWND hwnd )
	{
		m_hwnd = hwnd;
		m_d3d9 = Direct3DCreate9( D3D_SDK_VERSION );

		D3DDISPLAYMODE dm;
		ZeroMemory(&dm, sizeof(dm));

		D3DPRESENT_PARAMETERS pp;
		ZeroMemory(&pp, sizeof(pp));

		DWORD		adapter				= D3DADAPTER_DEFAULT;
		D3DDEVTYPE	type				= D3DDEVTYPE_HAL;

		DWORD bb_max_width  = 2048;
		DWORD bb_max_height = 2048;

		check_result( m_d3d9->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &dm ) );
		
		pp.BackBufferWidth				= bb_max_width;
		pp.BackBufferHeight				= bb_max_height;
		pp.BackBufferFormat 			= dm.Format;
		pp.BackBufferCount				= 1;

		pp.MultiSampleType				= D3DMULTISAMPLE_NONE;
		pp.MultiSampleQuality			= 0;

		pp.SwapEffect					= D3DSWAPEFFECT_COPY;
		pp.hDeviceWindow				= hwnd;
		pp.Windowed						= TRUE;
		pp.EnableAutoDepthStencil		= TRUE;
		pp.AutoDepthStencilFormat		= D3DFMT_D24S8;
		pp.Flags						= 0;

		pp.FullScreen_RefreshRateInHz	= 0;
		pp.PresentationInterval			= D3DPRESENT_INTERVAL_IMMEDIATE;

		memcpy(&m_present_paramseters, &pp, sizeof(m_present_paramseters));

		DWORD flags						= D3DCREATE_HARDWARE_VERTEXPROCESSING;

		check_result(m_d3d9->CreateDevice(adapter, type, hwnd, flags, &pp, &m_device));

		check_result(D3DXCreateTextureFromFileInMemoryEx(
			m_device, g_background_png, sizeof(g_background_png), 
			D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 
			D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, 0, &m_tex_background));

		check_result(D3DXCreateTextureFromFileInMemoryEx(
			m_device, g_bar_png, sizeof(g_bar_png), 
			D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, 
			D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, 0, &m_tex_bar));

		set_render_states();
	}
예제 #2
0
// 
// BitmapSprite::VOnRestore - Chapter 10, page 322
//
HRESULT BitmapSprite::VOnRestore()
{
	if (FAILED (Sprite::VOnRestore() ) )
	{
		return E_FAIL;
	}

	SAFE_RELEASE(m_pTexture);

    D3DXIMAGE_INFO imageInfo;
	ZeroMemory(&imageInfo, sizeof(D3DXIMAGE_INFO));

	if (m_bInCache)
	{
		Resource resource(m_fileName.c_str());
		shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
		if ( FAILED ( D3DXCreateTextureFromFileInMemoryEx( 
			DXUTGetD3D9Device(), // device
			texture->Buffer(),		// source data
			texture->Size(),	// source data size
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}
	else
	{
		if ( FAILED ( D3DXCreateTextureFromFileExA ( 
			DXUTGetD3D9Device(), 
			m_fileName.c_str(),	// source file name
			D3DX_DEFAULT,		// width - get it from the file
			D3DX_DEFAULT,		// height - get it from the file
			D3DX_DEFAULT,		// miplevels - get it from the file
			0,					// useage - default (not a render target or dynamic)
			D3DFMT_UNKNOWN,		// format - get it from the file
			D3DPOOL_DEFAULT,	// pool - use default
			D3DX_FILTER_NONE,	// filter - don't use any filter
			D3DX_DEFAULT,		// mip filter - use default
			g_Transparent,		// color key - use our transparent color
			&imageInfo,			// grab the source info
			NULL,				// palleteindex - we don't need it
			&m_pTexture ) ) )	// the texture pointer
			return false;
	}

	m_TextureWidth = m_Width = imageInfo.Width;
	m_TextureHeight = m_Height = imageInfo.Height / m_NumFrames;
	GCC_ASSERT(m_Height * m_NumFrames == imageInfo.Height && _T("Sprite height error"));

	return true;
}
예제 #3
0
void CD3D9Texture::createTextureFromFileInMemory(void* pBuf, int nSize, int nLevels)
{
	D3DXIMAGE_INFO info;
	if (FAILED (D3DXCreateTextureFromFileInMemoryEx (DXUTGetD3DDevice(),
		pBuf,
		nSize,
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		nLevels,
		0,
		D3DFMT_UNKNOWN,
		D3DPOOL_MANAGED,
		D3DX_FILTER_LINEAR,
		D3DX_FILTER_LINEAR,
		0,
		&info,
		NULL,
		&m_pd3dTexture)))
	{
		//erro
		return;
	}
	m_nWidth = info.Width;
	m_nHeight = info.Height;
	//D3DXCreateTextureFromFileInMemory(DXUTGetD3DDevice(), pImageBits, Size, &m_pd3dTexture);

	//D3DXCreateTextureFromFileInMemoryEx(DXUTGetD3DDevice(),pImageBits,Size,Width,Height,
	//									D3DX_DEFAULT,0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, 
	//									D3DX_DEFAULT, D3DX_DEFAULT, 0, 
	//									NULL, NULL, &m_pd3dTexture);
}
예제 #4
0
// 생성자(로드)
CTexture::CTexture(LPDIRECT3DDEVICE9 device, wstring file, CArchiveLoader* archive)
	: Device(device), TextureW(0), TextureH(0), OriginalW(0), OriginalH(0), Texture(NULL)
{
	D3DXIMAGE_INFO info;
	if (archive) {
		ARCHIVE_ENTRY* e = archive->Find(file);
		if (e) {
			D3DXCreateTextureFromFileInMemoryEx(
				Device, e->Data, e->Size,
				D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
				0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
				D3DX_DEFAULT, D3DX_DEFAULT, 0,
				&info, NULL, &Texture);
		}
	}
	else {
		D3DXCreateTextureFromFileEx(
			device, file.c_str(),
			D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
			0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
			D3DX_DEFAULT, D3DX_DEFAULT, 0,
			&info, NULL, &Texture);
	}
	if (Texture) {
		D3DSURFACE_DESC desc;
		Texture->GetLevelDesc(0, &desc);
		TextureW = desc.Width;
		TextureH = desc.Height;
		OriginalW = info.Width;
		OriginalH = info.Height;
	}
}
예제 #5
0
LPDIRECT3DTEXTURE9 CTexture::TakeTexture(){

	LPDIRECT3DSURFACE9		pSurface = NULL;

/*	// 空のテクスチャー作成
	if( FAILED( m_D3DDevice->CreateTexture( m_TexInfo.Width, m_TexInfo.Height, 1, D3DUSAGE_RENDERTARGET,
		D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT, &pD3DTex ,NULL)))
		return FALSE ;

	// テクスチャーのサーフェス取得
	pD3DTex->GetSurfaceLevel( 0, &pSurface );

	if( D3D_OK != D3DXLoadSurfaceFromFileInMemory( pSurface, NULL, NULL, m_ImageData, m_ImageSize, NULL, D3DX_DEFAULT, m_ColorKey, NULL ) ){
//		delete m_ImageData;
		return FALSE;
	}
*/
	D3DXIMAGE_INFO info;
	if( D3D_OK != D3DXCreateTextureFromFileInMemoryEx( m_D3DDevice, m_ImageData, m_ImageSize, 0, 0, 0, 0, D3DFMT_A8R8G8B8,
											D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 
											m_ColorKey, NULL, NULL, &pD3DTex )){
		return FALSE;
	}

	return pD3DTex;
}
예제 #6
0
	void SPTexture::Load( SPString setPath )
	{
		D3DXIMAGE_INFO i;
		//PALETTEENTRY p; Don't know why we cannot make use of both palette and info.
		// Ether of them is used.

		// Open texture file.
		SPFilePtr file = SPFileManager::GetSingleton()->OpenFile(setPath);
		
		if (!file)
		{
			SPLogHelper::WriteLog(L"[SPGraphics] WARNING: Failed to open file: " + setPath);
			return;
		}

		// Read file data.
		LONGLONG length = file->GetFileLength();
		char* pData = new char[(unsigned int)length];
		
		if (!file->Read(pData, (DWORD)length))
		{
			SPLogHelper::WriteLog(L"[SPGraphics] WARNING: Failed to read file: " + setPath);
			return;
		}		

		SPGameManager::GetSingleton()->GetGame()->LockDrawing();

		// Create texture from memory.
		HRESULT hr = D3DXCreateTextureFromFileInMemoryEx(
			SPDevice::GetSingleton()->GetD3DDevice(), 
			pData, (UINT)length,
			D3DX_DEFAULT_NONPOW2,
			D3DX_DEFAULT_NONPOW2,
			D3DX_FROM_FILE,	0,
			D3DFMT_A8R8G8B8,
			D3DPOOL_MANAGED,
			D3DX_FILTER_TRIANGLE, 
			D3DX_FILTER_TRIANGLE,
			D3DCOLOR_RGBA(0,0,0,0),
			&i, NULL,
			&texture);

		SPGameManager::GetSingleton()->GetGame()->UnlockDrawing();

		// Close texture file.
		SPFileManager::GetSingleton()->CloseFile(setPath);
		delete [] pData;
		pData = NULL;
		if (FAILED(hr))
		{
			texture = NULL;
			return;
		}
	
		path = setPath;
		height = i.Height;
		width = i.Width;
		format = D3DFMT_A8R8G8B8;
	}
예제 #7
0
		bool KINRenderManager::LoadTextureInBytes(Texture& pTexture, void* pData, unsigned int pLenght, Common::KINSize pSize)
		{
			D3DXCreateTextureFromFileInMemoryEx(mpD3D_Device, pData, pLenght, pSize.mWidth, pSize.mHeight,
											1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,
											D3DX_DEFAULT, 0, NULL, NULL, &pTexture.mpTexture);
			pTexture.mSize = pSize;

			return true;
		}
예제 #8
0
TSRPlatformTexture* TSRD3D9GraphicsFactory::CreateInternalTexture( const char* _pFileName )
{
    TSRD3D9Texture* pNewDXTexture = new TSRD3D9Texture();
    D3DXIMAGE_INFO info;

	string fullsrcfilename = _pFileName;
	if ( TSRSystem()->m_pWorkingPath )
	{
		fullsrcfilename = TSRSystem()->m_pWorkingPath;
		fullsrcfilename += _pFileName;
	}

	if ( g_D3D9TextureLoadingBuffer.size() == 0 )
	{
		g_D3D9TextureLoadingBuffer.resize( 16 * 1024 * 1024 );
	}

	TSRFileStream* pFileStream = TSRFileSystem::OpenFileStream( _pFileName, "r+b" );
    if ( pFileStream == NULL )
    {
        TSRPrintln( "Texture %s not found ", _pFileName );
        return NULL;
    }
	size_t uiDataSize = pFileStream->GetSize();

	if ( uiDataSize > 16 * 1024 * 1024 )
	{
		assert( 0 && "Cannot load textures which are over 16 megabytes, consider increasing the loading buffer size" );
	}


	unsigned char* pData = &g_D3D9TextureLoadingBuffer[ 0 ];
	fread( pData, uiDataSize, 1, pFileStream );
	fclose( pFileStream );

	
    HRESULT hr = D3DXCreateTextureFromFileInMemoryEx( g_pD3DDevice, pData, uiDataSize, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT, 0, D3DFMT_FROM_FILE, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0x00, &info, NULL, ( LPDIRECT3DTEXTURE9 * )&pNewDXTexture->m_pD3D9Texture );
    if ( FAILED( hr ) )
    {
        pNewDXTexture->m_pD3D9Texture = NULL;
    }
    else
    {
        pNewDXTexture->m_Info.m_uiWidth  = info.Width;
        pNewDXTexture->m_Info.m_uiHeight = info.Height;
        pNewDXTexture->m_Info.m_uiMipCount = info.MipLevels;
        pNewDXTexture->m_Info.m_uiDepth = 1;
        pNewDXTexture->m_Info.m_uiArraySize = 1;
        pNewDXTexture->m_Info.m_eDimension = TWISTER_TEXTUREDIMENSION_2D;
        pNewDXTexture->m_Info.m_eFormat = TextureFormatFromD3D9TextureFormat( info.Format );
    }
    return pNewDXTexture;
}
예제 #9
0
bool Lighting::LoadAttenTexture(TSTR &Name, LPDIRECT3DDEVICE9 Device)
{		
	HRESULT			Hr;
	void			*Data;
	unsigned long	Size;
	TCHAR error[256];
	_stprintf(error,_T("%s"),GetString(IDS_ERROR));

	Hr = S_OK;

	SAFE_RELEASE(m_Atten);

	if(GetFileResource(MAKEINTRESOURCE(IDR_ATTENUATE),_T("RT_RCDATA"),
					   &Data,Size))
	{
		Hr = D3DXCreateTextureFromFileInMemoryEx(Device, 
												 Data,
												 Size,
												 D3DX_DEFAULT,
												 D3DX_DEFAULT,
												 1,
												 0,
												 D3DFMT_A8R8G8B8,
												 D3DPOOL_MANAGED,
												 D3DX_FILTER_NONE,
												 D3DX_FILTER_NONE,
												 0,
												 NULL,
												 NULL,
												 (IDirect3DTexture9 **)&m_Atten);

	}
	else
	{
		Hr = E_FAIL;
	}

	if(Hr != S_OK)
	{
		TSTR	Str;
		Str = TSTR(GetString(IDS_LOAD_FILES)) + Name + TSTR(GetString(IDS_CHECK_PATHS)) + 
			  TSTR(GetString(IDS_ERROR_CODE)) + TSTR(DXGetErrorString(Hr));

		MessageBox(NULL,Str,error,MB_OK | MB_ICONERROR | MB_SETFOREGROUND | 
				   MB_APPLMODAL);

		return(false);
	}


	return(true);
}
예제 #10
0
//------------------------------------------------------------------------------------------------
// Name:  obtainD3DTexture
// Desc:  Loads the image denoted by this class using the specified device
//------------------------------------------------------------------------------------------------
bool PackImage::obtainD3DTexture(LPDIRECT3DDEVICE9 pd3dDevice, DWORD options, LPDIRECT3DTEXTURE9* ppd3dTexture) const
{
    // Fail without a device or if something is wrong with the output pointer
    if (!pd3dDevice || !ppd3dTexture) return false;

    // Get the pack from which to load this image
    dc::dcTable<ResourcePack>::Element* packElement = ((PackImage*)this)->myResourcePack.getReferencedResource();
    if (!packElement) return false;
    ResourcePack* pack = packElement->getImplementation();
    if (!pack) return false;

    // Obtain the image in the pack
    dcBuffer buffer;
    if (APP_ERROR(!pack->openResource(myResourceIndex.getValue(), &buffer))
        ("Failed to open image %i in pack file", myResourceIndex))
        return false;

    // Obtain options flags
    bool managed = (options & D3DTEX_MANAGED) != 0;
    bool mipmap = (options & D3DTEX_MIPMAP) != 0;
    bool systemmem = (options & D3DTEX_SYSTEMMEM) != 0;
    D3DPOOL pool = systemmem ? D3DPOOL_SYSTEMMEM : (managed ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT);

    // Holds return codes
    HRESULT hr;

    // Save a NULL first (just in case something goes wrong)
    *ppd3dTexture = NULL;

    // The destination for the texture interface
    LPDIRECT3DTEXTURE9 pd3dTexture;

    // Load the texture
    hr = D3DXCreateTextureFromFileInMemoryEx(pd3dDevice, buffer.getDataPointer(),
                   buffer.getDataSize(), D3DX_DEFAULT, D3DX_DEFAULT,
                   mipmap ? D3DX_DEFAULT : 1, 0, D3DFMT_UNKNOWN, pool,
                   D3DX_DEFAULT, D3DX_FILTER_POINT, 0, NULL, NULL, &pd3dTexture);

    // TODO:
    // buffer.destroy();

    // If there is a problem, there's not much more we can do
    if (APP_WARNING(FAILED(hr))("Couldn't load PackImage %i", myResourceIndex))
        return false;

    // Assign the output texture
    *ppd3dTexture = pd3dTexture;

    // Success
    return true;
}
예제 #11
0
////////////////////////////////////////////////////////////////
//
// CFileTextureItem::CreateUnderlyingData
//
// From pixels
//
////////////////////////////////////////////////////////////////
void CFileTextureItem::CreateUnderlyingData(const CPixels* pInPixels, bool bMipMaps, ERenderFormat format)
{
    assert(!m_pD3DTexture);

    CPixelsManagerInterface* pPixelsManager = CCore::GetSingleton().GetGraphics()->GetPixelsManager();

    // Copy from plain
    const CPixels* pPixels = pInPixels;
    CPixels        pixelsTemp;
    if (pPixelsManager->GetPixelsFormat(*pPixels) == EPixelsFormat::PLAIN)
    {
        pPixelsManager->ChangePixelsFormat(*pPixels, pixelsTemp, EPixelsFormat::PNG);
        pPixels = &pixelsTemp;
    }

    D3DXIMAGE_INFO imageInfo;
    D3DFORMAT      D3DFormat = (D3DFORMAT)format;
    int            iMipMaps = bMipMaps ? D3DX_DEFAULT : 1;

    if (FAILED(D3DXCreateTextureFromFileInMemoryEx(m_pDevice,                     //__in     LPDIRECT3DDEVICE9 pDevice,
                                                   pPixels->GetData(),            //__in     LPCVOID pSrcData,
                                                   pPixels->GetSize(),            //__in     UINT SrcDataSize,
                                                   D3DX_DEFAULT,                  //__in     UINT Width,
                                                   D3DX_DEFAULT,                  //__in     UINT Height,
                                                   iMipMaps,                      //__in     UINT MipLevels,
                                                   0,                             //__in     DWORD Usage,
                                                   D3DFormat,                     //__in     D3DFORMAT Format,
                                                   D3DPOOL_MANAGED,               //__in     D3DPOOL Pool,
                                                   D3DX_DEFAULT,                  //__in     DWORD Filter,
                                                   D3DX_DEFAULT,                  //__in     DWORD MipFilter,
                                                   0,                             //__in     D3DCOLOR ColorKey,
                                                   &imageInfo,                    //__inout  D3DXIMAGE_INFO *pSrcInfo,
                                                   NULL,                          //__out    PALETTEENTRY *pPalette,
                                                   (IDirect3DTexture9**)&m_pD3DTexture)))
        return;

    m_uiSizeX = imageInfo.Width;
    m_uiSizeY = imageInfo.Height;
    m_uiSurfaceSizeX = imageInfo.Width;
    m_uiSurfaceSizeY = imageInfo.Height;

    // Update surface size if it's a normal texture
    D3DSURFACE_DESC desc;
    ((IDirect3DTexture9*)m_pD3DTexture)->GetLevelDesc(0, &desc);
    m_uiSurfaceSizeX = desc.Width;
    m_uiSurfaceSizeY = desc.Height;

    // Calc memory usage
    m_iMemoryKBUsed = CRenderItemManager::CalcD3DResourceMemoryKBUsage(m_pD3DTexture);
}
예제 #12
0
ErrorCode Texture::loadFromFileInMemory(const void* data, uint length, MipMaps mipmaps)
{
    if (tex != 0)
    {
        tex->Release();
        tex = 0;
    }

    flags = 0;

    HRESULT res = D3DXCreateTextureFromFileInMemoryEx(mamain->d3ddev, data, length, 0, 0, mipmaps == MipMapsGenerate ? 0 : (mipmaps == MipMapsFromFile ? D3DX_FROM_FILE : 1), 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, 0, &tex);

    if (FAILED(res))
        return ErrorHandleCritical(mamain->err, mamain->errCrit, ErrorCreateTexture, res);

    return ErrorOk;
}
예제 #13
0
ImagePtr D3D9VideoBufferManager::LoadImage_(const TString128 & source, IMAGE_FILTER filter)
{
    DataStreamPtr stream = ResourceManager::Instance()->OpenResource(source.c_str());

    if (stream == NULL)
    {
        LOG_PRINT_FORMAT("image '%s' can't find\n", source.c_str());
        return NULL;
    }

    D3DXIMAGE_INFO ImgInfo;

    IDirect3DTexture9 * texture;
    HRESULT hr = D3DXCreateTextureFromFileInMemoryEx(mD3D9Device,
                                                     stream->GetData(),
                                                     stream->Size(),
                                                     D3DX_DEFAULT,
                                                     D3DX_DEFAULT,
                                                     1,
                                                     0,
                                                     D3DFMT_UNKNOWN,
                                                     D3DPOOL_SCRATCH,
                                                     D3D9Mapping::GetD3DXFilter(filter),
                                                     D3DX_DEFAULT,
                                                     0,
                                                     &ImgInfo,
                                                     NULL,
                                                     &texture);

    D3DErrorExceptionFunction(D3DXCreateTextureFromInMemoryEx, hr);

    D3DSURFACE_DESC desc;
    texture->GetLevelDesc(0, &desc);

    D3D9Image * image = new D3D9Image();

    image->mWidth = desc.Width;
    image->mHeight = desc.Height;
    image->mSrcWidth = ImgInfo.Width;
    image->mSrcHeight = ImgInfo.Height;
    image->mFormat = D3D9Mapping::GetFormat(desc.Format);
    image->mMipmapLevel = texture->GetLevelCount();
    image->mD3D9Texture = texture;

    return ImagePtr(image);
}
예제 #14
0
int l_Image_Save( lua_State* L )
{
	ImageData* imgData = lua_checkimage( L, 1 );
	const char* fileName = lua_tostring( L, 2 );

	if( !imgData || !fileName )
	{
		lua_pushstring( L, "Wrong parameters to Image_Save functions" );
		lua_error( L );
		return 0;
	}

	LPDIRECT3DTEXTURE9 texture;
	D3DLOCKED_RECT rect;

	D3DFORMAT dxFormat = (D3DFORMAT)imgData->format->d3dformat;

	if( dxFormat == D3DFMT_DXT1 || dxFormat == D3DFMT_DXT3 || dxFormat == D3DFMT_DXT5 )
		dxFormat = D3DFMT_A8R8G8B8;

	g_pd3dDevice->CreateTexture( imgData->width, imgData->height, 1, 0, dxFormat, D3DPOOL_MANAGED, &texture, 0 );
	texture->LockRect(0, &rect, 0, 0 );
	memcpy( rect.pBits, imgData->imgData, imgData->width * imgData->height * imgData->format->bytesPerPixel );
	texture->UnlockRect( 0 );

	if( imgData->format->d3dformat == D3DFMT_DXT1 || imgData->format->d3dformat == D3DFMT_DXT3 || imgData->format->d3dformat == D3DFMT_DXT5 )
	{
		ID3DXBuffer* dxBuffer;
		LPDIRECT3DTEXTURE9 outTexture; 
		D3DXSaveTextureToFileInMemory( &dxBuffer, D3DXIFF_BMP, texture, 0 );
		D3DXCreateTextureFromFileInMemoryEx( g_pd3dDevice, dxBuffer->GetBufferPointer(), dxBuffer->GetBufferSize(), imgData->width, imgData->height, 0, 0, (D3DFORMAT)imgData->format->d3dformat, D3DPOOL_SCRATCH, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, 0, &outTexture );

		D3DXSaveTextureToFile( fileName, extToFormat(fileName), outTexture, 0 );
		outTexture->Release();
	}else
	{
		D3DXSaveTextureToFile( fileName, extToFormat(fileName), texture, 0 );
	}

	texture->Release();

	return 0;
}
예제 #15
0
파일: vutil.cpp 프로젝트: iceberry/flyffsf
HRESULT LoadTextureFromRes( 
	LPDIRECT3DDEVICE9 pDevice,
	LPCTSTR pFileName,
	UINT Width,
	UINT Height,
	UINT MipLevels,
	DWORD Usage,
	D3DFORMAT Format,
	D3DPOOL Pool,
	DWORD Filter,
	DWORD MipFilter,
	D3DCOLOR ColorKey,
	D3DXIMAGE_INFO *pSrcInfo,
	PALETTEENTRY *pPalette,
	LPDIRECT3DTEXTURE9 *ppTexture
	)
{
	HRESULT hr = E_FAIL;
	CResFile file;
	if( file.Open( pFileName, "rb" ) == FALSE )
	{
		LPCTSTR szErr = Error( "::LoadTextureFromRes : %s not found", pFileName );
		ADDERRORMSG( szErr );
		return E_FAIL;
	}
	
	int nSrcDataSize = file.GetLength();
	LPBYTE pSrcData = new BYTE[ nSrcDataSize ];
	if( file.Read( pSrcData, nSrcDataSize ) >= 1 )
	{
		hr = D3DXCreateTextureFromFileInMemoryEx( pDevice,
			   pSrcData, nSrcDataSize, Width, Height, MipLevels, Usage, Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, ppTexture );
		if( FAILED( hr ) )
		{
			LPCTSTR szErr = Error( "D3DXCreateTextureFromFileInMemoryEx %s %s", pFileName, DXGetErrorString9( hr ) );
			ADDERRORMSG( szErr );
		}
	}
	SAFE_DELETE_ARRAY( pSrcData );
	return hr;
}
LPDIRECT3DTEXTURE9 Renderer::LoadTexture( char* pFilename, bool bAutoResize )
{
	LPDIRECT3DTEXTURE9 pTexture = NULL;

	FILE* iS;
	iS = fopen( pFilename, "rb" );
	if ( iS != NULL )
	{
		fseek( iS, 0, SEEK_END );
		int iLength = ftell( iS );
		fseek( iS, 0, SEEK_SET );
		BYTE* pTextureInMem = new BYTE[ iLength ];
		int iReadLength = fread( pTextureInMem, 1, iLength, iS );
		fclose( iS );

		D3DXCreateTextureFromFileInMemoryEx(m_pD3DDevice,		// device
											pTextureInMem,		// SrcData
											iReadLength,		// SrcDataSize
											0,					// Width
											0,					// Height
											1,					// MipLevels
											0,					// Usage
											D3DFMT_UNKNOWN,		// Format
											D3DPOOL_DEFAULT,	// Pool
											bAutoResize ? D3DX_FILTER_POINT : D3DX_FILTER_NONE,	// Filter
											D3DX_FILTER_NONE,	// MipFilter
											0x00000000,			// ColorKey
											NULL,				// SrcInfo
											NULL,				// Palette
											&pTexture );		// DestTexture

		delete[] pTextureInMem;
	}

	if ( pTexture == NULL )
	{
		DebugConsole::Log( "Renderer: Failed to load texture: %s\n", pFilename );
	}

	return pTexture;
}
예제 #17
0
파일: CreateDX.cpp 프로젝트: 2asoft/xray
	ETOOLS_API HRESULT WINAPI
		D3DX_CreateTextureFromFileInMemoryEx(
		LPDIRECT3DDEVICE9         pDevice,
		LPCVOID                   pSrcData,
		UINT                      SrcDataSize,
		UINT                      Width,
		UINT                      Height,
		UINT                      MipLevels,
		DWORD                     Usage,
		D3DFORMAT                 Format,
		D3DPOOL                   Pool,
		DWORD                     Filter,
		DWORD                     MipFilter,
		D3DCOLOR                  ColorKey,
		D3DXIMAGE_INFO*           pSrcInfo,
		PALETTEENTRY*             pPalette,
		LPDIRECT3DTEXTURE9*       ppTexture)
	{
		return D3DXCreateTextureFromFileInMemoryEx(
			pDevice, pSrcData, SrcDataSize, Width, Height, MipLevels, Usage,
			Format, Pool, Filter, MipFilter, ColorKey, pSrcInfo, pPalette, 
			ppTexture);
	}
예제 #18
0
LcD3D_TextureLoadMemory(PDTX* pTexture, PDEV pDev, void* pData, UINT dSize
						, DWORD dColor
						, D3DXIMAGE_INFO* pSrcInf
						, DWORD Filter
						, DWORD MipFilter
						, D3DFORMAT d3Fmt
						, DWORD Pool)
{
	HRESULT hr;

	UINT uMip = D3DX_DEFAULT;

	if(D3DX_FILTER_NONE == Filter || D3DX_FILTER_NONE == MipFilter)
		uMip = 1;

	hr=D3DXCreateTextureFromFileInMemoryEx(pDev
			, pData
			, dSize
			, D3DX_DEFAULT
			, D3DX_DEFAULT
			, uMip
			, 0
			, d3Fmt
			, (D3DPOOL)Pool
			, Filter, MipFilter
			, dColor, pSrcInf
			, NULL
			, pTexture		);

	if(FAILED(hr))
	{
		pTexture = 0;
		return hr;
	}

	return 0;
}
예제 #19
0
// ******************************************************************
// Initialisierung aus virtuellen Dateien
tbResult tb2DSprite::Init(char* pcINIFile,
						  char* pcINISection,
						  tbVector2 (*converter)(tbVector2 vParam),	// = NULL
						  char* pcTextureFile)						// = NULL
{
	// vorsichtshalber alles vorher freigeben
	Exit();

	HRESULT		hResult;
	tbResult	tbRes;

	// Parameter prüfen und sicherstellen, dass tbDirect3D initialisiert wurde
	if(pcINIFile == NULL)				TB_ERROR_NULL_POINTER("pcINIFile", TB_ERROR);
	if(pcINISection == NULL)			TB_ERROR_NULL_POINTER("pcINISection", TB_ERROR);
	if(!tbDirect3D::IsInitialized())	TB_ERROR("Es muss zuerst eine tbDirect3D-Klasseninstanz erstellt werden!", TB_ERROR);

	
	// Informationsdatei vorbereiten
	tbINIReader* pINIReader;
	pINIReader = new tbINIReader; 	if(pINIReader == NULL) TB_ERROR_OUT_OF_MEMORY(TB_ERROR);
	pINIReader->SetFilePath(pcINIFile);

	// ColorKey laden
	tbColor ColorKey = pINIReader->ReadINIColor(pcINISection, "ColorKey");
	if(ColorKey == tbColor(12345678.0f, 12345678.0f, 12345678.0f, 12345678.0f)) ColorKey = tbColor(0.0f, 0.0f, 0.0f, 1.0f);

	// Wenn kein Parameter übergeben nach INI-Eintrag suchen
	char acTextur[256];
	ZeroMemory(acTextur, sizeof(acTextur));
	if(pcTextureFile == NULL)
	{
		// Texturname aus INI laden wenn möglich
		pINIReader->ReadINIString(pcINISection, "Texture", acTextur, 256);
	
		// Kein INI-Eintrag gefunden?
		if(!strcmp(acTextur, "[NOT FOUND]"))
		{
			TB_ERROR("Fehler beim Laden der Sprite-Textur, kein INI-Eintrag gefunden!", TB_ERROR);
		}
	}
	else
	{
		strncpy(acTextur, pcTextureFile, 256);
	}

	// Texturmanager benutzen, wenn er initialisiert ist
	if(tbTextureManager::IsInitialized())
	{
		// Texturmanager benutzen merken
		m_bTexturmanager = TRUE;

		m_pTexture = tbTextureManager::GetTexture(acTextur, 
						TRUE, D3DX_DEFAULT, D3DX_DEFAULT, 
						1, D3DFMT_UNKNOWN, 0, D3DPOOL_MANAGED, 
						D3DX_DEFAULT, D3DX_DEFAULT, ColorKey);
		// Fehler?
		if(m_pTexture == NULL) TB_ERROR("Fehler beim Laden der Textur mit dem Texturmanager!",TB_ERROR);

		// Bilddimensionen speichern
		D3DSURFACE_DESC Desc;
		m_pTexture->GetLevelDesc(0, &Desc);
		m_2DSpriteInfo.fTextureHeight = (float)Desc.Height;
		m_2DSpriteInfo.fTextureWidth = (float)Desc.Width;
	}
	else
	{
		// Texturmanager nicht benutzen merken
		m_bTexturmanager = FALSE;

		tbVFile*	pVFile;

		// Virtuelle Dateien erstellen
		pVFile = new tbVFile;	if(pVFile == NULL) TB_ERROR_OUT_OF_MEMORY(TB_ERROR);

		// Aus Datei laden
		if(pVFile->Init(acTextur)) TB_ERROR("Fehler beim Erstellen der virtuellen Datei!", TB_ERROR);

		// Textur laden
		D3DXIMAGE_INFO dinfo;
		ZeroMemory(&dinfo, sizeof(dinfo));
		if(FAILED(hResult = D3DXCreateTextureFromFileInMemoryEx(tbDirect3D::GetDevice(),
																(BYTE*)(pVFile->GetBuffer()) + pVFile->GetCursor(),
																pVFile->GetSize() - pVFile->GetCursor(),
																D3DX_DEFAULT, D3DX_DEFAULT, 1, 0,
																D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
																D3DX_DEFAULT, D3DX_DEFAULT,
																ColorKey, &dinfo, NULL, &m_pTexture)))
		{
			// Fehler!
			TB_ERROR_DIRECTX("D3DXCreateTextureFromFileInMemoryEx", hResult, TB_ERROR);
		}
		// Bilddimensionen speichern
		m_2DSpriteInfo.fTextureHeight = (float)dinfo.Height;
		m_2DSpriteInfo.fTextureWidth = (float)dinfo.Width;

		// Die virtuellen Dateien wieder freigeben
		TB_SAFE_DELETE(pVFile);
	}


	// Sprite-Informationen laden
	ReadINISpriteInfo(pINIReader,
					  pcINISection, 
					  "Sprite", 
					  &m_2DSpriteInfo,
					  converter);


	// Effektname aus INI laden
	char acEffect[256];
	ZeroMemory(acEffect, sizeof(acEffect));
	pINIReader->ReadINIString(pcINISection, "Effect", acEffect, 256);
	if(!strcmp(acEffect, "[NOT FOUND]")) TB_ERROR("Fehler beim Laden des Sprite-Effekts!", TB_ERROR);
	// Effekt laden
	m_pEffect = new tbEffect; if(m_pEffect == NULL) TB_ERROR_OUT_OF_MEMORY(TB_ERROR);
	if(TB_OK != (tbRes = m_pEffect->Init(acEffect))) TB_ERROR("Fehler beim Erstellen des Sprite-Effekts!", TB_ERROR);
	// Effekt setzen
	if(TB_OK != m_pEffect->SetTechnique())	TB_ERROR("Fehler beim Setzen des Sprite-Effekts!", TB_ERROR);

	// Textur setzen
	if(FAILED(hResult = m_pEffect->GetEffect()->SetTexture("Texture1", m_pTexture)))
	{
		// Fehler!
		TB_ERROR_DIRECTX("SetTexture", hResult, TB_ERROR);
	}


	// INIReader wieder freigeben
	TB_SAFE_DELETE(pINIReader);

	return TB_OK;
}
예제 #20
0
bool LoadaImgFromMem(char *mem,unsigned long size,unsigned int hn,unsigned int vn,unsigned int *delay,wchar_t *name)
{
	LPDIRECT3DTEXTURE9 tex_all;
	//获取图片信息
	D3DXIMAGE_INFO imageInfo;
	D3DXGetImageInfoFromFileInMemory(mem, size, &imageInfo);

	unsigned int width = imageInfo.Width;
	unsigned int height = imageInfo.Height;
	unsigned int h_width = width/hn;
	unsigned int v_height = height/vn;

	long bytenum = h_width*v_height*4;
	unsigned int all = hn*vn;
	byte **pixel_buf = new byte*[all];
	for(unsigned int i=0;i<all;i++)
	{
		pixel_buf[i] = new byte[bytenum];
	}

	if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_pd3dD,mem,size,imageInfo.Width,imageInfo.Height,imageInfo.MipLevels,0,D3DFMT_A8R8G8B8,
		D3DPOOL_SYSTEMMEM,D3DX_FILTER_NONE,D3DX_DEFAULT,0,NULL,NULL,&tex_all)))
	{
		MessageBox(0,name,TEXT("读取图片错误"),MB_OK);
		return 0;
	}
	else
	{
		//对tex进行处理
		D3DLOCKED_RECT locked_rect;
		tex_all->LockRect(0, &locked_rect, NULL, 0);


		BYTE *pByte = (BYTE *) locked_rect.pBits;
		int p1 = 0,p2 = 0,p2_base = 0;

		for(unsigned int n=0;n<all;n++)
		{
			p2_base = (n/hn)*locked_rect.Pitch*v_height+(n%hn)*h_width*4;
			for(unsigned int h=0;h<v_height;h++)
			{
				for(unsigned int w=0;w<h_width;w++)
				{
					pixel_buf[n][p1] = pByte[p2_base+p2];
					pixel_buf[n][p1+1] = pByte[p2_base+p2+1];
					pixel_buf[n][p1+2] = pByte[p2_base+p2+2];
					pixel_buf[n][p1+3] = pByte[p2_base+p2+3];
					p1+=4;
					p2+=4;
				}
				p2 = p2 + locked_rect.Pitch - h_width*4;
			}
			p1 = 0; p2 = 0;
		}

		tex_all->UnlockRect(0);
		tex_all->Release();

		///////////////////////////////////////////////////////
		frames *tempf = new frames;
		tempf->frame_number = all;
		frame *f = new frame[all];
		for(unsigned int i=0;i<all;i++)
		{
			if(delay)
				f[i].delay = delay[i];
			else
				f[i].delay = 0;

			f[i].tex = new mytex;
			if (g_pd3dD->CreateTexture(h_width, v_height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &f[i].tex->tex, NULL) == D3D_OK)
			{
				//对tex进行处理
				D3DLOCKED_RECT locked_rect;
				f[i].tex->tex->LockRect(0, &locked_rect, NULL, 0);

				//直接复制内存块
				CopyMemory(locked_rect.pBits,pixel_buf[i],bytenum);

				f[i].tex->tex->UnlockRect(0);
				f[i].tex->width = h_width;
				f[i].tex->height = v_height;
			}
			else
				return 0;
		}
		tempf->f = f;

		framelist *temp = new framelist;
		int namelen = wcslen(name);
		temp->name = new wchar_t[namelen];
		wcscpy(temp->name,name);

		temp->fs = tempf;
		temp->next = 0;

		unsigned int i = BKDRHash(name);

		if(!framelist_headp[i])
		{
			framelist_headp[i] = temp;
			framelist_nowp[i] = framelist_headp[i];
		}
		else
		{
			framelist_nowp[i]->next = temp;
			framelist_nowp[i] = temp;
		}

		return true;
	}
}
예제 #21
0
INT LcD3D_TextureLoadRscCustom(PDTX* pTexture, PDEV pDev, INT nResourceId, const char* sType
								, DWORD dColor
								, D3DXIMAGE_INFO* pSrcInf
								, DWORD Filter
								, DWORD MipFilter
								, D3DFORMAT d3Fmt
								, DWORD Pool)
{
	HINSTANCE	hInst	= NULL;
	HRSRC		hRsc	= NULL;
	DWORD		dwSize	= 0;
	HGLOBAL		hMem	= NULL;
	LPVOID		pMem	= NULL;

	HRESULT hr;

	UINT uMip = D3DX_DEFAULT;

	if(D3DX_FILTER_NONE == Filter || D3DX_FILTER_NONE == MipFilter)
		uMip = 1;


	hInst = GetModuleHandle(NULL);
	hRsc = FindResource( hInst, MAKEINTRESOURCE(nResourceId), sType);

	if(NULL == hRsc)
		return -1;

	dwSize = SizeofResource(hInst,hRsc);

	if(0==dwSize)
		return -1;

	hMem = LoadResource(hInst, hRsc);

	if(NULL == hMem)
		return -1;

	pMem = LockResource(hMem);

	// 이것은 안된다...
	//	HRESULT hr = D3DXCreateTextureFromResourceEx(
	//		pDev
	//		, NULL
	//		, MAKEINTRESOURCE(IDR_PNG1)
	//		, D3DX_DEFAULT
	//		, D3DX_DEFAULT
	//		, uMip
	//		, 0
	//		, d3Fmt
	//		, D3DPOOL_MANAGED
	//		, Filter, MipFilter
	//		, dColor, pSrcInf
	//		, NULL
	//		, &pTexture);



	// 이것으로 해야 한다.

	hr = D3DXCreateTextureFromFileInMemoryEx(
		pDev
		, pMem
		, dwSize
		, D3DX_DEFAULT
		, D3DX_DEFAULT
		, uMip
		, 0
		, d3Fmt
		, (D3DPOOL)Pool
		, Filter, MipFilter
		, dColor, pSrcInf
		, NULL
		, pTexture);

	UnlockResource(hMem);
	FreeResource(hMem);

	if(FAILED(hr))
		return -1;

	return 0;
}
/// \brief Loads a texture
/// \param file = the filename
bool CDX9TextureObject::LoadFromFile( const TCHAR * file )
{
	StdString szFilePath(file);
	szFilePath.MakeSafeFileName();

	DeInit();

	if (!m_Renderer)
		return false;

	LPDIRECT3DDEVICE9 pDevice = (LPDIRECT3DDEVICE9)m_Renderer->GetAPIDevice();
	if( !pDevice )
		return false;

	D3DXIMAGE_INFO srcInfo;
	LPDIRECT3DTEXTURE9 pTexture;
/*
	if( _tcsstr( file, _T(".hdr" ) )!= NULL )
	{
		bool retval = LoadHDRFile( (TCHAR*)file );
		return retval;
	}
*/
	LPVOID pFileData = NULL;
	UINT iFileDataSize = 0;
	if (!LoadFileIntoBuffer( szFilePath, pFileData, iFileDataSize, true ))
	{
		m_ToolBox->Log(LOGERROR, _T("Texture Object: %s failed to load\n"), szFilePath.c_str() );
		return false;
	}

	D3DFORMAT requestedFormat = EEDX9RequestedInternalFormatFromFileInMemory( pFileData, iFileDataSize );
	HRESULT hr = D3DXCreateTextureFromFileInMemoryEx( pDevice,
									pFileData, 
									iFileDataSize, 
									D3DX_DEFAULT, //width
									D3DX_DEFAULT, //height
									D3DX_DEFAULT, //number of mips
									0,	//usage - 0 unless for render targets
									requestedFormat,
									D3DPOOL_MANAGED,
									D3DX_DEFAULT,	//regular filter
									D3DX_DEFAULT,	//mip filter
									0, //color key, opaque black default
									&srcInfo,	//src info
									NULL, //palette
									&pTexture );
	SAFE_DELETE_ARRAY( pFileData );
	if( hr != D3D_OK )
	{
		m_ToolBox->Log(LOGERROR, _T("Texture Object: %s failed to load\n"), szFilePath.c_str() );
		return false;
	}

	D3DSURFACE_DESC textureDesc;
	pTexture->GetLevelDesc( 0, &textureDesc );
	m_Width = textureDesc.Width;
	m_Height = textureDesc.Height;
	m_Texture = pTexture;
	m_Filename = file;
	m_bRenderTarget = false;
	m_ColorDepth = EEDX9ColorBitsFromFormat( textureDesc.Format );
	m_Compressed = EEDX9IsCompressedFormat( textureDesc.Format );

	if( m_AutoGenMips )
	{
		pTexture->GenerateMipSubLevels();
	}

	return true;
}
예제 #23
0
// ******************************************************************
// Initialisierung aus virtuellen Dateien
tbResult tbFont::Init(tbVFile* pTGAFile,
					  tbVFile* pTBFFile)
{
	HRESULT hResult;

	// Parameter prüfen und sicherstellen, dass tbDirect3D initialisiert wurde
	if(pTGAFile == NULL)				TB_ERROR_NULL_POINTER("pTGAFile", TB_ERROR);
	if(pTBFFile == NULL)				TB_ERROR_NULL_POINTER("pTBFFile", TB_ERROR);
	if(!tbDirect3D::IsInitialized())	TB_ERROR("Es muss zuerst eine tbDirect3D-Klasseninstanz erstellt werden!", TB_ERROR);


	// Textur laden
	if(FAILED(hResult = D3DXCreateTextureFromFileInMemoryEx(tbDirect3D::GetDevice(),
		                                                    (BYTE*)(pTGAFile->GetBuffer()) + pTGAFile->GetCursor(),
															pTGAFile->GetSize() - pTGAFile->GetCursor(),
															D3DX_DEFAULT, D3DX_DEFAULT, 1, 0,
															D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
															D3DX_DEFAULT, D3DX_DEFAULT,
															0, NULL, NULL, &m_pTexture)))
	{
		// Fehler!
		TB_ERROR_DIRECTX("D3DXCreateTextureFromFileInMemoryEx", hResult, TB_ERROR);
	}

	// Informationen laden
	if(pTBFFile->Read(sizeof(tbFontInfo), &m_FontInfo))
	{
		// Fehler!
		TB_ERROR("Fehler beim Lesen der Schriftinformationen!", TB_ERROR);
	}

	// Effekt aus String erstellen
	m_pEffect = new tbEffect; if(m_pEffect == NULL) TB_ERROR_OUT_OF_MEMORY(TB_ERROR);
	if(m_pEffect->Init("TEXTURE Texture;\n"
		               "\n"
		               "TECHNIQUE T1\n"
		               "{\n"
					   "	PASS P1\n"
					   "	{\n"
					   "        Texture[0]          = <Texture>;\n"
					   "		ZEnable				= False;\n"
					   "		ZWriteEnable		= False;\n"
					   "		ColorOp[0]			= Modulate;\n"
					   "		ColorArg1[0]		= Texture;\n"
					   "		ColorArg2[0]		= Current;\n"
					   "		ColorOp[1]			= Disable;\n"
					   "		AlphaOp[0]			= Modulate;\n"
					   "		AlphaArg1[0]		= Texture;\n"
					   "		AlphaArg2[0]		= Current;\n"
					   "		AlphaOp[1]			= Disable;\n"
					   "		AlphaBlendEnable	= True;\n"
					   "		SrcBlend			= SrcAlpha;\n"
					   "		DestBlend			= InvSrcAlpha;\n"
					   "	}\n"
					   "}\n", -1))
	{
		// Fehler!
		TB_ERROR("Fehler beim Erstellen des Effekts!", TB_ERROR);
	}

	// Textur setzen
	m_pEffect->GetEffect()->SetTexture("Texture", m_pTexture);

	return TB_OK;
}
예제 #24
0
HRESULT ConvertMemoryBufferToBMPBuffer( MemoryBuffer &image_in, MemoryBuffer &image_out)
{
	// Check to ensure that our data has a valid length before proceeding
	if( image_in.GetDataLength() == 0 ) return S_FALSE;

	// Set up a timer class to profile our code
	ATG::Timer m_Timer;
	double timeStart, timeStop;

	// Begin Profiling our Texture Creation Code
	timeStart = m_Timer.GetAbsoluteTime();

	IDirect3DTexture9 * pTexture;
	HRESULT retVal = D3DXCreateTextureFromFileInMemoryEx(
		CFreestyleApp::getInstance().m_pd3dDevice,
		image_in.GetData(),
		image_in.GetDataLength(),
		D3DX_DEFAULT_NONPOW2,
		D3DX_DEFAULT_NONPOW2,
		1,
		D3DUSAGE_CPU_CACHED_MEMORY,
		D3DFMT_LIN_A8R8G8B8,
		D3DPOOL_DEFAULT,
		D3DX_FILTER_NONE,
		D3DX_FILTER_NONE,
		0,
		NULL,
		NULL,
		&pTexture
	);

	// End Profiling our Texture Creation Code
	timeStop = m_Timer.GetAbsoluteTime();
	DebugMsg("ConvertImageToBMP", "Texture Creation took %4.2f seconds to complete", (float)(timeStop - timeStart));

	// If our texture was created successfully, 
	if(retVal = D3D_OK) {

		//Begin Profiling our Data Manipulation Code
		timeStart = m_Timer.GetAbsoluteTime();

		// Get our level desc
		D3DSURFACE_DESC desc;
		pTexture->GetLevelDesc(0, &desc);

		// Now lock our data
		D3DLOCKED_RECT lock;
		RECT rect = {0, 0, desc.Width, desc.Height};
		pTexture->LockRect(0, &lock, &rect, D3DLOCK_READONLY);
	
		//Read our data
		DWORD headerSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		DWORD dataLen = lock.Pitch * desc.Height;
		DWORD * dataBuffer = (DWORD*)malloc( dataLen + headerSize );
		DWORD * address = (DWORD*)lock.pBits;

		// Create file our header
		BITMAPFILEHEADER* fHead = (BITMAPFILEHEADER*)dataBuffer;
		fHead->bfType = 0x424D; // "BM"
		fHead->bfSize = SwapDWORD(dataLen + headerSize);
		fHead->bfReserved1 = 0;
		fHead->bfReserved2 = 0;
		fHead->bfOffBits = SwapDWORD(headerSize);

		// Create our info header
		BITMAPINFOHEADER* iHead = (BITMAPINFOHEADER*)(fHead + 1);
		ZeroMemory(iHead, sizeof(BITMAPINFOHEADER));
		iHead->biSize = SwapDWORD(sizeof(BITMAPINFOHEADER));
		iHead->biWidth = SwapDWORD(desc.Width);
		iHead->biHeight = SwapDWORD(desc.Height);
		iHead->biPlanes = SwapWORD(1);
		iHead->biBitCount = SwapWORD(32);
		iHead->biSizeImage = SwapDWORD(dataLen);

		// Copy over our raw (BGRA)
		DWORD* rawPtr = (DWORD*)(iHead + 1);
		for(int y = desc.Height - 1; y >= 0; y--) {
			for(DWORD x = 0; x < desc.Width; x++) {

				DWORD cp = (y * lock.Pitch) + (x * 4);
				DWORD * temp = (DWORD*)(address + (cp / 4));
				*rawPtr = SwapDWORD(*temp);				
				rawPtr++;
			}
		}
		
		// Unlock our texture
		pTexture->UnlockRect(0);

		// End Profiling our Data Modification Code
		timeStop = m_Timer.GetAbsoluteTime();
		DebugMsg("ConvertImageToBMP", "Data Modification took %4.2f seconds to complete", (float)(timeStop - timeStart));

		// Begin Profiling our Memory Copy Code
		timeStart = m_Timer.GetAbsoluteTime();
		
		// Copy our completed data to our new buffer
		image_out.Add(dataBuffer, (headerSize + dataLen));

		// End Profiling our Memory Copy Code
		timeStop = m_Timer.GetAbsoluteTime();
		DebugMsg("ConvertImageToBMP", "Image Memory Copy took %4.2f seconds to complete", (float)(timeStop - timeStart));

	}
	else {
		DebugMsg("ConvertImageInMemoryToBMPBuffer", "Conversion To BMP From Memory Failed. [%X]", retVal);
	}

	return retVal;
}
예제 #25
0
void ConvertImageInMemoryToBMPBuffer(BYTE * fileBuffer, DWORD fileSize, LPBYTE* bytes, long* len)
{



	// Set our initial values
	*bytes = NULL;
	*len = 0;

	// Check file size
	if (fileSize == 0) {
		DebugMsg("ConvertToPNG", "Bailing since filesize is 0");
		return;
	}

	ATG::Timer m_Timer;

	double timeA = m_Timer.GetAbsoluteTime();

	IDirect3DTexture9 * pTexture;
	HRESULT retVal = D3DXCreateTextureFromFileInMemoryEx(
		CFreestyleApp::getInstance().m_pd3dDevice,
		fileBuffer,
		fileSize,
		D3DX_DEFAULT_NONPOW2,
		D3DX_DEFAULT_NONPOW2,
		1,
		D3DUSAGE_CPU_CACHED_MEMORY,
		D3DFMT_LIN_A8R8G8B8,
		D3DPOOL_DEFAULT,
		D3DX_FILTER_NONE,
		D3DX_FILTER_NONE,
		0,
		NULL,
		NULL,
		&pTexture
	);

	float timeB = m_Timer.GetAbsoluteTime();
	DebugMsg("Test", "Texture Creation:  %4.2f", (timeB- timeA));

	if(retVal == S_OK) {
		timeA = m_Timer.GetAbsoluteTime();

		// Get our level desc
		D3DSURFACE_DESC desc;
		pTexture->GetLevelDesc(0, &desc);

		// Now lock our data
		D3DLOCKED_RECT lock;
		RECT rect = {0, 0, desc.Width, desc.Height};
		pTexture->LockRect(0, &lock, &rect, D3DLOCK_READONLY);
	
		//Read our data
		DWORD headerSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		DWORD dataLen = lock.Pitch * desc.Height;
		DWORD * dataBuffer = (DWORD*)malloc( dataLen + headerSize );
		DWORD * address = (DWORD*)lock.pBits;

		// Create file our header
		BITMAPFILEHEADER* fHead = (BITMAPFILEHEADER*)dataBuffer;
		fHead->bfType = 0x424D; // "BM"
		fHead->bfSize = SwapDWORD(dataLen + headerSize);
		fHead->bfReserved1 = 0;
		fHead->bfReserved2 = 0;
		fHead->bfOffBits = SwapDWORD(headerSize);

		// Create our info header
		BITMAPINFOHEADER* iHead = (BITMAPINFOHEADER*)(fHead + 1);
		ZeroMemory(iHead, sizeof(BITMAPINFOHEADER));
		iHead->biSize = SwapDWORD(sizeof(BITMAPINFOHEADER));
		iHead->biWidth = SwapDWORD(desc.Width);
		iHead->biHeight = SwapDWORD(desc.Height);
		iHead->biPlanes = SwapWORD(1);
		iHead->biBitCount = SwapWORD(32);
		iHead->biSizeImage = SwapDWORD(dataLen);

		// Copy over our raw (BGRA)
		DWORD* rawPtr = (DWORD*)(iHead + 1);
		for(int y = desc.Height - 1; y >= 0; y--) {
			for(DWORD x = 0; x < desc.Width; x++) {

				DWORD cp = (y * lock.Pitch) + (x * 4);
				DWORD * temp = (DWORD*)(address + (cp / 4));
				*rawPtr = SwapDWORD(*temp);				
				rawPtr++;
			}
		}
		
		// Unlock our texture
		pTexture->UnlockRect(0);

		timeB = m_Timer.GetAbsoluteTime();
		DebugMsg("Test", "Texture Lock Time:  %4.2f", (timeB- timeA));
		
		*len = (headerSize + dataLen);
		*bytes = (BYTE*)dataBuffer;
	}else {
		DebugMsg("ConvertImageInMemoryToBMPBuffer", 
			"Conversion To BMP From Memory Failed. [%X]", retVal);		
	}

	// Release our Texture
	if(pTexture != NULL)
		pTexture->Release();
}
예제 #26
0
파일: devicedx8.cpp 프로젝트: skopp/rush
int JRenderServer::GetTextureID( const char* texName )
{
    if (!texName || !m_pDevice) return -1;
    for (int i = 0; i < m_Textures.size(); i++)
    {
        if (!stricmp( m_Textures[i].m_Name.c_str(), texName )) return i;
    }

    FInStream is;
    g_pFileServer->OpenMedia( texName, "", is );
    if (!is) return -1;

    int nBytes = is.GetTotalSize();
    BYTE* buf = new BYTE[nBytes];
    is.Read( buf, nBytes );
    
    D3DXIMAGE_INFO info;
    HRESULT hRes = D3DXGetImageInfoFromFileInMemory( buf, nBytes, &info );
    DXBaseTexture* pTex = NULL;


    TextureFile tex;
    tex.m_pDepthStencil = NULL;
    tex.m_Name          = texName;

    TextureProperties& tp = tex.m_Prop;

    if (info.ResourceType == D3DRTYPE_CUBETEXTURE)
    {
        IDirect3DCubeTexture8* pCubeTexture = NULL;
        hRes = D3DXCreateCubeTextureFromFileInMemoryEx( m_pDevice,
            buf, nBytes,
            D3DX_DEFAULT, 0,
            0, D3DFMT_UNKNOWN,
            D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
            0x00000000, NULL, NULL, &pCubeTexture );
        pTex = pCubeTexture;

        D3DSURFACE_DESC desc;
        pCubeTexture->GetLevelDesc( 0, &desc );
        tp.m_Format         = ConvertColorFormat( desc.Format );
        tp.m_Height         = desc.Height;
        tp.m_Width          = desc.Width;
        tp.m_PoolType       = ConvertPoolType( desc.Pool );
    }
    else
    {
        DXTexture* pTexture2D = NULL;
        hRes = D3DXCreateTextureFromFileInMemoryEx( m_pDevice,
            buf, nBytes,
            D3DX_DEFAULT, D3DX_DEFAULT, 0,
            0, D3DFMT_UNKNOWN,
            D3DPOOL_MANAGED , D3DX_DEFAULT, D3DX_DEFAULT,
            0x00000000, NULL, NULL, &pTexture2D );
        pTex = pTexture2D;

        D3DSURFACE_DESC desc;
        pTexture2D->GetLevelDesc( 0, &desc );
        tp.m_Format         = ConvertColorFormat( desc.Format );
        tp.m_Height         = desc.Height;
        tp.m_Width          = desc.Width;
        tp.m_PoolType       = ConvertPoolType( desc.Pool );
    }
    
    delete []buf;
    if (!pTex || hRes != S_OK) return -1;

    tp.m_bAutoGenMips   = false;
    tp.m_NMips          = pTex->GetLevelCount();
    strcpy( tp.m_Name, texName );

    tex.m_pTexture      = pTex;
    m_Textures.push_back( tex );
    return m_Textures.size() - 1;
} // JRenderServer::GetTextureID
예제 #27
0
bool DirectGraphicsSprite::LoadImage(char *Filename, int xs, int ys, int xfs, int yfs, 
														 int xfc,  int yfc)
{
	if(GameRunning == false) 
		return false;

	bool			fromrar;
	HRESULT			hresult;
	char			*pData; 
	char			Temp[256];
	unsigned long	Size; 

	// zuerst eine evtl benutzte Textur freigeben
	SafeRelease(itsTexture);

	fromrar = false;

	// Zuerst checken, ob sich die Grafik in einem MOD-Ordner befindet
	if (CommandLineParams.RunOwnLevelList == true)
	{
		sprintf_s(Temp, "levels/%s/%s", CommandLineParams.OwnLevelList, Filename);
		if (FileExists(Temp))
			goto loadfile;
	}

	// Dann checken, ob sich das File im Standard Ordner befindet
	sprintf_s(Temp, "data/%s", Filename);
	if (FileExists(Temp))
		goto loadfile;

	// Auch nicht? Dann ist es hoffentlich im RAR file
	if (urarlib_get(&pData, &Size, Filename, RARFILENAME, convertText(RARFILEPASSWORD)) == false)
	{		
		sprintf_s(Temp, "\n-> Error loading %s from Archive !\n", Filename);
		Protokoll.WriteText(Temp, true);
		return false;
	}
	else
		fromrar = true;

loadfile:

	// normal von Platte laden?
	if (fromrar == false)
	{
		// Textur laden
		hresult = D3DXCreateTextureFromFileEx(
				  lpD3DDevice,
				  Temp,
				  NULL, NULL,				  // x und y Grösse des Sprites (aus Datei übernehmen)
				  1,                          // Nur eine Version der Textur
				  0,                          // Immer 0 setzen
				  D3DFMT_UNKNOWN,			  // Format aus der Datei lesen
				  D3DPOOL_MANAGED,            // DX bestimmt wo die Textur gespeichert wird 
				  D3DX_FILTER_NONE,			  // Keine Filter verwenden
				  D3DX_FILTER_NONE,
				  0xFFFF00FF,                 // Colorkeyfarbe (Lila)
				  NULL,						  // Keine Image Info
				  NULL,						  // Keine Palette angeben
				  &itsTexture);
	}
	else
	{
		// Textur aus Speicher erzeugen
		hresult = D3DXCreateTextureFromFileInMemoryEx(
				  lpD3DDevice,
				  (LPVOID)pData,
				  Size, 
				  NULL, NULL,				  // x und y Grösse des Sprites (aus Datei übernehmen)
				  1,                          // Nur eine Version der Textur
				  0,                          // Immer 0 setzen
				  D3DFMT_UNKNOWN,			  // Format aus der Datei lesen
				  D3DPOOL_MANAGED,            // DX bestimmt wo die Textur gespeichert wird 
				  D3DX_FILTER_NONE,			  // Keine Filter verwenden
				  D3DX_FILTER_NONE,
				  0xFFFF00FF,                 // Colorkeyfarbe (Lila)
				  NULL,						  // Keine Image Info
				  NULL,						  // Keine Palette angeben
				  &itsTexture);

		free(pData);
	}

	// Fehler beim Laden ?
	if(hresult != D3D_OK)
	{
		strcpy_s(Temp, strlen("Fehler beim Laden von ") + 1, "Fehler beim Laden von ");
		strcat_s(Temp, strlen(Filename) + 1, Filename);
		strcat_s(Temp, 4, " !\n");
		Protokoll.WriteText(Temp, true);
		return false;
	}
	
	// Grösse der Textur anpassen
	D3DSURFACE_DESC desc;
	itsTexture->GetLevelDesc(0,&desc);	

	// Grösse setzen
	itsXSize		= (float)desc.Width;
	itsYSize		= (float)desc.Height;
	itsXFrameCount	= xfc;
	itsYFrameCount	= yfc;
	itsXFrameSize	= xfs;
	itsYFrameSize	= yfs;
	itsRect.left	= 0;
	itsRect.top		= 0;
	itsRect.right	= (int)itsXSize;
	itsRect.bottom	= (int)itsYSize;

	// Ausschnitte vorberechnen
	for (int i = 0; i < xfc * yfc; i++)
	{
		itsPreCalcedRects[i].top	= (i/itsXFrameCount) * itsYFrameSize;
		itsPreCalcedRects[i].left	= (i%itsXFrameCount) * itsXFrameSize;
		itsPreCalcedRects[i].right  = itsPreCalcedRects[i].left + itsXFrameSize;
		itsPreCalcedRects[i].bottom = itsPreCalcedRects[i].top  + itsYFrameSize;
	}

	itsRect = itsPreCalcedRects[0];

	// Bild korrekt geladen
	sprintf_s(Temp, "%s %s %s %s", TextArray [TEXT_LADE_BITMAP], Filename, TextArray [TEXT_LADEN_ERFOLGREICH], "\n");
	Protokoll.WriteText(Temp, false);			

	DisplayLoadInfo(Temp);

	LoadedTextures++;							// Anzahl der geladenen Texturen erhöhen
	//_itoa_s(LoadedTextures, Temp, 10);
//	Protokoll.WriteText(Temp, false);
//	Protokoll.WriteText(" Sprite Textur(en) geladen !\n", false);
	return true;
}
예제 #28
0
HRESULT KG3DGraphicsEngine::ScreenShotImpl()
{
    HRESULT hResult  = E_FAIL;
    HRESULT hRetCode = E_FAIL;

    IDirect3DSurface9* pFrameSurface = NULL;
    IDirect3DTexture9* pTextureSys = NULL;
    ID3DXBuffer* pBuffer = NULL;
    D3DVIEWPORT9 ViewPort;
    RECT RectView;

    ASSERT(m_eShotImageType != D3DXIFF_FORCE_DWORD);

    hRetCode = g_pd3dDevice->GetRenderTarget(0, &pFrameSurface);
    KG_COM_PROCESS_ERROR(hRetCode);

    g_pd3dDevice->GetViewport(&ViewPort);
    SetRect(&RectView, ViewPort.X, ViewPort.Y, ViewPort.X + ViewPort.Width, ViewPort.Y + ViewPort.Height);

    if (m_eShotImageType == D3DXIFF_JPG)
    {
        D3DSURFACE_DESC SurfaceDesc;
        D3DLOCKED_RECT LockRect;
        
        hRetCode = D3DXSaveSurfaceToFileInMemory(&pBuffer, D3DXIFF_BMP, pFrameSurface, NULL, &RectView);
        KG_COM_PROCESS_ERROR(hRetCode);

        hRetCode = D3DXCreateTextureFromFileInMemoryEx(g_pd3dDevice, 
            pBuffer->GetBufferPointer(), 
            pBuffer->GetBufferSize(),
            ViewPort.Width,
            ViewPort.Height,
            1,
            0,
            D3DFMT_A8R8G8B8,
            D3DPOOL_SCRATCH,
            D3DX_DEFAULT,
            D3DX_DEFAULT,
            0,
            NULL,
            NULL,
            &pTextureSys);
        KG_COM_PROCESS_ERROR(hRetCode);


        /*
        hRetCode = D3DXSaveSurfaceToFile(TEXT("__temp_shot.bmp"), D3DXIFF_BMP, pFrameSurface, NULL, &RectView);
        KG_COM_PROCESS_ERROR(hRetCode);

        hRetCode = D3DXCreateTextureFromFileEx(g_pd3dDevice, 
            TEXT("__temp_shot.bmp"), 
            ViewPort.Width,
            ViewPort.Height,
            1,
            0,
            D3DFMT_A8R8G8B8,
            D3DPOOL_SCRATCH,
            D3DX_DEFAULT,
            D3DX_DEFAULT,
            0,
            NULL,
            NULL,
            &pTextureSys);
        KG_COM_PROCESS_ERROR(hRetCode); */

        pTextureSys->GetLevelDesc(0, &SurfaceDesc);

        if (SUCCEEDED(pTextureSys->LockRect(0, &LockRect, NULL, D3DLOCK_NOSYSLOCK)))
        {
            struct _Rgba { BYTE r; BYTE g; BYTE b; BYTE a;};
            struct _Rgb  { BYTE b; BYTE g; BYTE r; };
            _Rgb* pRgb = new _Rgb[SurfaceDesc.Height * SurfaceDesc.Width];

            for (UINT v = 0; v < SurfaceDesc.Height; ++v)
            {
                _Rgba* pRgba = (_Rgba*)((BYTE*)LockRect.pBits + LockRect.Pitch * v);

                for (UINT u = 0; u < SurfaceDesc.Width; ++u)
                {
                    pRgb[v * SurfaceDesc.Width + u].r = pRgba[u].r;
                    pRgb[v * SurfaceDesc.Width + u].g = pRgba[u].g;
                    pRgb[v * SurfaceDesc.Width + u].b = pRgba[u].b;
                }
            }

            JpegFile::RGBToJpegFile(m_szShotPath, (BYTE*)pRgb, SurfaceDesc.Width, SurfaceDesc.Height, TRUE, m_nShotImageQuty);

            delete[] pRgb;
            pTextureSys->UnlockRect(0);
        }
        else
        {
            KG_PROCESS_ERROR(FALSE);
        }
    }
    else
    {
        hRetCode = D3DXSaveSurfaceToFile(m_szShotPath, m_eShotImageType, pFrameSurface, NULL, &RectView);
        KG_COM_PROCESS_ERROR(hRetCode);
    }

    hResult = S_OK;
Exit0 :
    SAFE_RELEASE(pBuffer);
    SAFE_RELEASE(pTextureSys);
    SAFE_RELEASE(pFrameSurface);
    return hResult;
}
예제 #29
0
HRESULT XuiTextureLoader(IXuiDevice *pDevice, LPCWSTR szFileName,
      XUIImageInfo *pImageInfo, IDirect3DTexture9 **ppTex)
{
   D3DXIMAGE_INFO pSrc;
   CONST BYTE  *pbTextureData      = 0;
   UINT         cbTextureData      = 0;
   HXUIRESOURCE hResource          = 0;
   BOOL         bIsMemoryResource  = FALSE;
   IDirect3DDevice9 * d3dDevice    = NULL;
   HRESULT      hr                 = 
      XuiResourceOpenNoLoc(szFileName, &hResource, &bIsMemoryResource);

   if (FAILED(hr))
      return hr; 

   if (bIsMemoryResource)
   {
      hr = XuiResourceGetBuffer(hResource, &pbTextureData);
      if (FAILED(hr))
         goto cleanup;
      cbTextureData = XuiResourceGetTotalSize(hResource);
   }
   else 
   {
      hr = XuiResourceRead(hResource, NULL, 0, &cbTextureData);
      if (FAILED(hr))
         goto cleanup;

      pbTextureData = (BYTE *)XuiAlloc(cbTextureData);
      if (pbTextureData == 0)
      {
         hr = E_OUTOFMEMORY;
         goto cleanup;
      }

      hr = XuiResourceRead(hResource,
            (BYTE*)pbTextureData, cbTextureData, &cbTextureData);
      if (FAILED(hr))
         goto cleanup;

      XuiResourceClose(hResource);
      hResource = 0;

   }

   /* Cast our d3d device into our IDirect3DDevice9* interface */
   d3dDevice = (IDirect3DDevice9*)pDevice->GetD3DDevice();
   if(!d3dDevice)
      goto cleanup;

   /* Create our texture based on our conditions */
   hr = D3DXCreateTextureFromFileInMemoryEx(
         d3dDevice,
         pbTextureData,  
         cbTextureData,
         D3DX_DEFAULT_NONPOW2, 
         D3DX_DEFAULT_NONPOW2,
         1,
         D3DUSAGE_CPU_CACHED_MEMORY,
         (D3DFORMAT)d3d9_get_argb8888_format(),
         D3DPOOL_DEFAULT,
         D3DX_FILTER_NONE,
         D3DX_FILTER_NONE,
         0,
         &pSrc,
         NULL,
         ppTex
         );

   if(hr != D3DXERR_INVALIDDATA )
   {
      pImageInfo->Depth           = pSrc.Depth;
      pImageInfo->Format          = pSrc.Format;
      pImageInfo->Height          = pSrc.Height;
      pImageInfo->ImageFileFormat = pSrc.ImageFileFormat;
      pImageInfo->MipLevels       = pSrc.MipLevels;
      pImageInfo->ResourceType    = pSrc.ResourceType;
      pImageInfo->Width           = pSrc.Width;
   }
   else
      RARCH_ERR("D3DXERR_INVALIDDATA Encountered\n");

cleanup:

   if (bIsMemoryResource && hResource != 0)
      XuiResourceReleaseBuffer(hResource, pbTextureData);
   else
      XuiFree((LPVOID)pbTextureData);

   if (hResource != 0)
      XuiResourceClose(hResource);
   return hr;
}
예제 #30
0
파일: Material.cpp 프로젝트: H-EAL/assimp
//-------------------------------------------------------------------------------
int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
{
    ai_assert(NULL != p_ppiOut);
    ai_assert(NULL != szPath);

    *p_ppiOut = NULL;

    const std::string s = szPath->data;
    TextureCache::iterator ff;
    if ((ff = sCachedTextures.find(s)) != sCachedTextures.end()) {
        *p_ppiOut = (*ff).second;
        (*p_ppiOut)->AddRef();
        return 1;
    }

    // first get a valid path to the texture
    if( 5 == FindValidPath(szPath))
    {
        // embedded file. Find its index
        unsigned int iIndex = atoi(szPath->data+1);
        if (iIndex < g_pcAsset->pcScene->mNumTextures)
        {
            if (0 == g_pcAsset->pcScene->mTextures[iIndex]->mHeight)
            {
                // it is an embedded file ... don't need the file format hint,
                // simply let D3DX load the file
                D3DXIMAGE_INFO info;
                if (FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice,
                    g_pcAsset->pcScene->mTextures[iIndex]->pcData,
                    g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
                    D3DX_DEFAULT,
                    D3DX_DEFAULT,
                    1,
                    D3DUSAGE_AUTOGENMIPMAP,
                    D3DFMT_UNKNOWN,
                    D3DPOOL_MANAGED,
                    D3DX_DEFAULT,
                    D3DX_DEFAULT,
                    0,
                    &info,
                    NULL,
                    p_ppiOut)))
                {
                    std::string sz = "[ERROR] Unable to load embedded texture (#1): ";
                    sz.append(szPath->data);
                    CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));

                    this->SetDefaultTexture(p_ppiOut);
                    return 1;
                }
            }
            else
            {
                // fill a new texture ...
                if(FAILED(g_piDevice->CreateTexture(
                    g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
                    g_pcAsset->pcScene->mTextures[iIndex]->mHeight,
                    0,D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,p_ppiOut,NULL)))
                {
                    std::string sz = "[ERROR] Unable to load embedded texture (#2): ";
                    sz.append(szPath->data);
                    CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));

                    this->SetDefaultTexture(p_ppiOut);
                    return 1;
                }

                // now copy the data to it ... (assume non pow2 to be supported)
                D3DLOCKED_RECT sLock;
                (*p_ppiOut)->LockRect(0,&sLock,NULL,0);

                const aiTexel* pcData = g_pcAsset->pcScene->mTextures[iIndex]->pcData;

                for (unsigned int y = 0; y < g_pcAsset->pcScene->mTextures[iIndex]->mHeight;++y)
                {
                    memcpy(sLock.pBits,pcData,g_pcAsset->pcScene->mTextures[iIndex]->
                        mWidth *sizeof(aiTexel));
                    sLock.pBits = (char*)sLock.pBits + sLock.Pitch;
                    pcData += g_pcAsset->pcScene->mTextures[iIndex]->mWidth;
                }
                (*p_ppiOut)->UnlockRect(0);
                (*p_ppiOut)->GenerateMipSubLevels();
            }
            sCachedTextures[s] = *p_ppiOut;
            (*p_ppiOut)->AddRef();
            return 1;
        }
        else
        {
            std::string sz = "[ERROR] Invalid index for embedded texture: ";
            sz.append(szPath->data);
            CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));

            SetDefaultTexture(p_ppiOut);
            return 1;
        }
    }

    // then call D3DX to load the texture
    if (FAILED(D3DXCreateTextureFromFileEx(
        g_piDevice,
        szPath->data,
        D3DX_DEFAULT,
        D3DX_DEFAULT,
        0,
        0,
        D3DFMT_A8R8G8B8,
        D3DPOOL_MANAGED,
        D3DX_DEFAULT,
        D3DX_DEFAULT,
        0,
        NULL,
        NULL,
        p_ppiOut)))
    {
        // error ... use the default texture instead
        std::string sz = "[ERROR] Unable to load texture: ";
        sz.append(szPath->data);
        CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));

        this->SetDefaultTexture(p_ppiOut);
    }
    sCachedTextures[s] = *p_ppiOut;
    (*p_ppiOut)->AddRef();

    return 1;
}