Пример #1
0
HRESULT IDX8PixelShaderImp::Initialize(Material *mtl, INode *node)
{
	HRESULT hr = S_OK;

	if (map->GetInitPS()) {

		TCHAR *cubeMapPath = FindMapFile(map->GetCubeMapFile());
		
		if(!cubeMapPath)
			hr = E_FAIL;
		else
		{
			SAFE_RELEASE(pCubeTexture);
			hr = D3DXCreateCubeTextureFromFileEx(pd3dDevice,
				cubeMapPath,
				D3DX_DEFAULT,
				1,
				0,
				D3DFMT_UNKNOWN,
				D3DPOOL_MANAGED,
				D3DX_FILTER_LINEAR,
				D3DX_FILTER_LINEAR,
				0,
				NULL,
				NULL,
				&pCubeTexture);
		}
		
		map->SetInitPS(false);
	}

	return hr;
}
Пример #2
0
	IDirect3DCubeTexture9 * TextureCache::_addCubeTex( const char * srcFile, uint _usage )
	{
		uint pool = D3DPOOL_MANAGED;
		if ( _usage & D3DUSAGE_RENDERTARGET ) // The resource will be a render target. D3DUSAGE_RENDERTARGET can only be used with D3DPOOL_DEFAULT. 
			pool = D3DPOOL_DEFAULT;
		uint usage = _usage; // | D3DUSAGE_AUTOGENMIPMAP;
		printf( "%s %s\n", __FUNCTION__, srcFile );

        IDirect3DCubeTexture9 * pTexture = 0;

		uint mipLevels = 0;
        D3DXIMAGE_INFO imgInfo;
        HRESULT hr = D3DXCreateCubeTextureFromFileEx(
            device,						//LPDIRECT3DDEVICE9 pDevice,
            srcFile,						//LPCTSTR pSrcFile,
            D3DX_DEFAULT,		//UINT Size,
            mipLevels,				//UINT MipLevels,
            usage,//_usage &  (D3DUSAGE_DYNAMIC | D3DUSAGE_RENDERTARGET),					// DWORD Usage,
            D3DFMT_FROM_FILE, //_format, // D3DFORMAT Format,
			(D3DPOOL) pool,						//D3DPOOL Pool,
            D3DX_DEFAULT ,		//DWORD Filter,
            D3DX_DEFAULT ,		//DWORD MipFilter,
            0,								//D3DCOLOR ColorKey,
            & imgInfo,				// D3DXIMAGE_INFO
            0,								//PALETTEENTRY *pPalette,
            & pTexture				//LPDIRECT3DCUBETEXTURE9 *ppCubeTexture
        );
        E_TRACE(hr);
        if ( FAILED( hr ) )
		{
			return 0;
		}

		return pTexture;
	}
Пример #3
0
// テクスチャの読み込み
bool CubeTexture::Load(std::string path, Color4 color, U_INT mipLevel, DWORD filter)
{

	if( FAILED( D3DXCreateCubeTextureFromFileEx(
				Device::GetDevice(),
				path.c_str(),
				0,
				mipLevel,
				0,
				D3DFMT_A8R8G8B8,
				D3DPOOL_MANAGED,
				filter,
				filter,
				color,
				0,
				0,
				&texture
		) ))
	{
		//	テクスチャの読み込みに失敗
		return false;
	}

	//	読み込み成功
	return true;
}
////////////////////////////////////////////////////////////////
//
// CFileTextureItem::CreateUnderlyingData
//
// From file
//
////////////////////////////////////////////////////////////////
void CFileTextureItem::CreateUnderlyingData(const SString& strFilename, bool bMipMaps, uint uiSizeX, uint uiSizeY, ERenderFormat format)
{
    assert(!m_pD3DTexture);

    D3DXIMAGE_INFO imageInfo;
    if (FAILED(D3DXGetImageInfoFromFile(strFilename, &imageInfo)))
        return;

    D3DFORMAT D3DFormat = (D3DFORMAT)format;
    int       iMipMaps = bMipMaps ? D3DX_DEFAULT : 1;
    if (uiSizeX != D3DX_DEFAULT)
        imageInfo.Width = uiSizeX;
    if (uiSizeY != D3DX_DEFAULT)
        imageInfo.Height = uiSizeY;

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

    if (imageInfo.ResourceType == D3DRTYPE_VOLUMETEXTURE)
    {
        // It's a volume texture!
        if (FAILED(D3DXCreateVolumeTextureFromFileEx(m_pDevice, strFilename, uiSizeX, uiSizeY, D3DX_DEFAULT, iMipMaps, 0, D3DFormat, D3DPOOL_MANAGED,
                                                     D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, (IDirect3DVolumeTexture9**)&m_pD3DTexture)))
            return;
    }
    else if (imageInfo.ResourceType == D3DRTYPE_CUBETEXTURE)
    {
        // It's a cubemap texture!
        if (FAILED(D3DXCreateCubeTextureFromFileEx(m_pDevice, strFilename, uiSizeX, iMipMaps, 0, D3DFormat, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                                   NULL, NULL, (IDirect3DCubeTexture9**)&m_pD3DTexture)))
            return;
    }
    else
    {
        // It's none of the above!

        // If size not specified, try to use exact image size to prevent blurring
        if (uiSizeX == D3DX_DEFAULT)
            uiSizeX = D3DX_DEFAULT_NONPOW2;
        if (uiSizeY == D3DX_DEFAULT)
            uiSizeY = D3DX_DEFAULT_NONPOW2;

        if (FAILED(D3DXCreateTextureFromFileEx(m_pDevice, strFilename, uiSizeX, uiSizeY, iMipMaps, 0, D3DFormat, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0,
                                               NULL, NULL, (IDirect3DTexture9**)&m_pD3DTexture)))
            return;

        // 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);
}
Пример #5
0
//-----------------------------------------------------------------------------
// Name: ResourceDatabase::AddTextureCube
//-----------------------------------------------------------------------------
TextureCube* ResourceDatabase::AddTextureCube(  CONST CHAR* strFilename, 
                                                DWORD Size, D3DFORMAT Format, DWORD Filter,
                                                DWORD MipLevels, DWORD MipFilter )
{
    WCHAR wszConvertedFilename[ _MAX_PATH ];
    TextureCube *pTexture = NULL;
    Resource *pResource = NULL;
    
    const CHAR* strFileOnly = strrchr( strFilename, '\\' );
    if( strFileOnly == NULL )
    {
        strFileOnly = strFilename;
    }
    else
    {
        strFileOnly++;
    }

    MultiByteToWideChar( CP_ACP, 0, strFileOnly, strlen( strFileOnly ) + 1, wszConvertedFilename, MAX_PATH );
    _wcslwr_s( wszConvertedFilename );

    pResource = FindResource( wszConvertedFilename );
    if ( pResource )
    {
        // $ERROR: report error of duplicate name
        assert( pResource->IsDerivedFrom( TextureCube::TypeID ) );
        return (TextureCube*)pResource;            
    }

    LPDIRECT3DCUBETEXTURE9 pD3DTexture;

    HRESULT hr = D3DXCreateCubeTextureFromFileEx( g_pd3dDevice, 
                                              strFilename, 
                                              Size, MipLevels,
                                              0,
                                              Format,
                                              D3DPOOL_MANAGED,//D3DPOOL_DEFAULT,
                                              Filter, MipFilter, 0, NULL, NULL, 
                                              &pD3DTexture );
    if ( FAILED( hr ) )
    {
        ATG::DebugSpew( "Could not load cubemap texture %s.\n", strFilename );
        return NULL;
    }
    
    pTexture = new TextureCube;
    pTexture->SetName( wszConvertedFilename );
    pTexture->SetD3DTexture( pD3DTexture );
    pD3DTexture->Release();
    
    AddResource( pTexture );
    return pTexture;
}
Пример #6
0
//-----------------------------------------------------------------------------
HRESULT CSkybox::OnCreateDevice( LPDIRECT3DDEVICE9 pd3dDevice, float fSize, WCHAR* strCubeMapFile,
                                 WCHAR* strEffectFileName )
{
    HRESULT hr;

    WCHAR strPath[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( strPath, MAX_PATH, strCubeMapFile ) );

    IDirect3DCubeTexture9* pCubeTexture = NULL;
    V_RETURN( D3DXCreateCubeTextureFromFileEx( pd3dDevice, strPath, D3DX_DEFAULT, 1, 0, D3DFMT_A16B16G16R16F,
                                               D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, NULL,
                                               NULL, &pCubeTexture ) );

    return OnCreateDevice( pd3dDevice, fSize, pCubeTexture, strEffectFileName );
}
Пример #7
0
HRESULT CSky::InitialSky( IDirect3DDevice9* D3DDevice )
{
	void *pBV;
	void *pBI;
	if ( !D3DDevice )
	{
		Log( "error init sky " );
		return E_FAIL;
	}
	m_pD3DDevice = D3DDevice;
	m_pVerBufSky   = 0; // указатель на буфер вершин
	m_pBufIndexSky = 0; // указатель на буфер вершин

	CVertexFVF SkyVershin[4];

	SkyVershin[0] = CVertexFVF(  1.0f, -1.0f, 0.0f, 0.0f,  0.0f, -1.0f, 1.0f, 1.0f ); // 0
	SkyVershin[1] = CVertexFVF( -1.0f, -1.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f, 1.0f ); // 1	
	SkyVershin[2] = CVertexFVF( -1.0f,  1.0f, 0.0f, 0.0f,  0.0f, -1.0f, 0.0f, 0.0f ); // 2		
	SkyVershin[3] = CVertexFVF(  1.0f,  1.0f, 0.0f, 0.0f,  0.0f, -1.0f, 1.0f, 0.0f ); // 3
	// X        Y     Z    nx    ny    nz     tu    tv

	const unsigned short SkyIndex[] =
	{
		0,1,2,    2,3,0,		
	};
	if ( FAILED( m_pD3DDevice -> CreateVertexBuffer( 4 * sizeof( CVertexFVF ), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVerBufSky, 0 ) ) ) // создаЄм буфер вершин		
		return E_FAIL;
	if ( FAILED( m_pVerBufSky -> Lock( 0, sizeof( SkyVershin ), ( void** )&pBV, 0 ) ) ) // Ѕлокирование
		return E_FAIL; 
	memcpy( pBV, SkyVershin, sizeof( SkyVershin ) ); // копирование данных о вершинах в буфер вершин
	m_pVerBufSky -> Unlock(); // разблокирование

	if ( FAILED( m_pD3DDevice -> CreateIndexBuffer( 6 * sizeof( short ), 0, D3DFMT_INDEX16,         // создаЄм буфер вершин
		D3DPOOL_DEFAULT, &m_pBufIndexSky, 0 ) ) )
		return E_FAIL;
	if ( FAILED( m_pBufIndexSky -> Lock( 0, sizeof( SkyIndex ), ( void** )&pBI, 0 ) ) ) // Ѕлокирование
		return E_FAIL; 
	memcpy( pBI, SkyIndex, sizeof( SkyIndex ) ); // копирование данных о вершинах в буфер вершин
	m_pBufIndexSky -> Unlock(); // разблокирование	

	m_CubeTexture = 0;
	if ( FAILED( D3DXCreateCubeTextureFromFileEx( m_pD3DDevice, "model\\sky_cube_mipmap.dds", D3DX_DEFAULT, D3DX_FROM_FILE, 0, 
		D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 0, 0, &m_CubeTexture )))
		Log( "error load sky texture" );
	Log( "Init Sky " );
	return S_OK;
}
Пример #8
0
TSRPlatformTexture* TSRD3D9GraphicsFactory::CreateInternalCubeTexture( const char* _pFileName )
{
    TSRD3D9Texture* pNewDXTexture = new TSRD3D9Texture();
    D3DXIMAGE_INFO imageInfo;
	HRESULT hr = D3DXCreateCubeTextureFromFileEx( g_pD3DDevice, _pFileName, D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0x00, &imageInfo, NULL, ( LPDIRECT3DCUBETEXTURE9 * )&pNewDXTexture->m_pD3D9Texture );
    pNewDXTexture->m_Info.m_uiWidth  = imageInfo.Width;
    pNewDXTexture->m_Info.m_uiHeight = imageInfo.Height;
    pNewDXTexture->m_Info.m_uiDepth = imageInfo.Depth;
    pNewDXTexture->m_Info.m_eFormat = TextureFormatFromD3D9TextureFormat( imageInfo.Format );
    pNewDXTexture->m_Info.m_eDimension = TWISTER_TEXTUREDIMENSION_CUBE;
    pNewDXTexture->m_Info.m_uiMipCount = imageInfo.MipLevels;
    pNewDXTexture->m_Info.m_uiArraySize = 1;

    if ( FAILED( hr ) )
    {
        pNewDXTexture->m_pD3D9Texture = NULL;
    }
    return pNewDXTexture;
} 
bool eae6320::cTextureBuilder::Build( const std::vector<std::string>& )
{
	bool wereThereErrors = false;

	if ( !Initialize( m_path_source ) )
	{
		wereThereErrors = true;
		goto OnExit;
	}

	// Get information about the source image
	D3DXIMAGE_INFO imageInfo_source;
	{
		if ( FAILED( D3DXGetImageInfoFromFile( m_path_source, &imageInfo_source ) ) )
		{
			wereThereErrors = true;
			OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
			goto OnExit;
		}
	}
	// Load the source image and do any necessary processing (compress, generate MIP maps, change resolution, etc.)
	{
		// Try to match the original image's format as closely as possible
		D3DFORMAT format = D3DFMT_UNKNOWN;
		{
			if ( imageInfo_source.ImageFileFormat == D3DXIFF_DDS )
			{
				// DDS files will remain unchanged
				// (this could cause problems in the simplistic OpenGL texture loading code that I provide)
				format = imageInfo_source.Format;
			}
			else
			{
				// The decision of which DXT format to use is simplistic:
				//	* If it can easily be determined that the source image doesn't have an alpha channel then DXT1 is used
				//	* DXT5 is used for everything else
				const D3DFORMAT format_original = imageInfo_source.Format;
				const bool isAlphaChannelUnnecessary = ( format_original == D3DFMT_R8G8B8 ) || ( format_original == D3DFMT_X8R8G8B8 )
					|| ( format_original == D3DFMT_R5G6B5 ) || ( format_original == D3DFMT_X1R5G5B5 )
					|| ( format_original == D3DFMT_X4R4G4B4  ) || ( format_original == D3DFMT_X8B8G8R8 );
				if ( isAlphaChannelUnnecessary )
				{
					format = D3DFMT_DXT1;
				}
				else
				{
					format = D3DFMT_DXT5;
				}
			}
		}
		// The source width and height could be used, but ensuring that the dimensions are always a power-of-2 is more compatible
		// (and the image will probably end up taking the same amount of space anyway because of alignment issues)
		const unsigned int roundUpToAPowerOf2 = D3DX_DEFAULT;
		unsigned int requestedMipMapCount;
		{
			const bool doMipMapsExist = imageInfo_source.MipLevels > 1;
			if ( doMipMapsExist )
			{
				requestedMipMapCount = D3DX_FROM_FILE;
			}
			else
			{
				// This will generate all of the potential MIP map levels (down to the smallest 1x1)
				requestedMipMapCount = D3DX_DEFAULT;
			}
		}
		const DWORD staticTexture = 0;
		const D3DPOOL letD3dManageMemory = D3DPOOL_MANAGED;
		const DWORD useDefaultFiltering = D3DX_DEFAULT;
		const D3DCOLOR noColorKey = 0;
		PALETTEENTRY* noColorPalette = NULL;
		switch( imageInfo_source.ResourceType )
		{
		case D3DRTYPE_TEXTURE:
			{
				const HRESULT result = D3DXCreateTextureFromFileEx( s_direct3dDevice, m_path_source, 
					roundUpToAPowerOf2, roundUpToAPowerOf2, requestedMipMapCount,
					staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, 
					&imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DTexture9**>( &s_texture ) );
				if ( FAILED( result ) )
				{
					wereThereErrors = true;
					OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
					goto OnExit;
				}
			}
			break;
		case D3DRTYPE_CUBETEXTURE:
			{
				const HRESULT result = D3DXCreateCubeTextureFromFileEx( s_direct3dDevice, m_path_source, 
					roundUpToAPowerOf2, requestedMipMapCount,
					staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, 
					&imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DCubeTexture9**>( &s_texture ) );
				if ( FAILED( result ) )
				{
					wereThereErrors = true;
					OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
					goto OnExit;
				}
			}
			break;
		case D3DRTYPE_VOLUMETEXTURE:
			{
				const HRESULT result = D3DXCreateVolumeTextureFromFileEx( s_direct3dDevice, m_path_source, 
					roundUpToAPowerOf2, roundUpToAPowerOf2, imageInfo_source.Depth, requestedMipMapCount,
					staticTexture, format, letD3dManageMemory, useDefaultFiltering, useDefaultFiltering, noColorKey, 
					&imageInfo_source, noColorPalette, reinterpret_cast<IDirect3DVolumeTexture9**>( &s_texture ) );
				if ( FAILED( result ) )
				{
					wereThereErrors = true;
					OutputErrorMessage( "DirectX failed to get image info for the source image", m_path_source );
					goto OnExit;
				}
			}
			break;
		default:
			{
				wereThereErrors = true;
				std::stringstream errorMessage;
				errorMessage << "Unsupported texture resource type " << imageInfo_source.ResourceType;
				OutputErrorMessage( errorMessage.str().c_str(), m_path_source );
				goto OnExit;
			}
		}
	}
	// Save the texture
	{
		const D3DXIMAGE_FILEFORMAT ddsFormat = D3DXIFF_DDS;
		PALETTEENTRY* noColorPalette = NULL;
		HRESULT result = D3DXSaveTextureToFile( m_path_target, ddsFormat, s_texture, noColorPalette );
		if ( FAILED( result ) )
		{
			wereThereErrors = true;
			OutputErrorMessage( "DirectX failed to save the texture", m_path_target );
			goto OnExit;
		}
	}

OnExit:

	if ( !ShutDown() )
	{
		wereThereErrors = true;
	}

	return !wereThereErrors;
}
Пример #10
0
BOOL CDxtexDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
    LPDIRECT3DDEVICE9 pd3ddev = PDxtexApp()->Pd3ddev();
    D3DXIMAGE_INFO imageinfo;
    D3DXIMAGE_INFO imageinfo2;

    if( FAILED( D3DXGetImageInfoFromFile( lpszPathName, &imageinfo ) ) )
    {
        AfxMessageBox(ID_ERROR_COULDNTLOADFILE);
        return FALSE;
    }

    switch( imageinfo.ResourceType )
    {
    case D3DRTYPE_TEXTURE:
        if( FAILED( D3DXCreateTextureFromFileEx( pd3ddev, lpszPathName, 
            imageinfo.Width, imageinfo.Height, imageinfo.MipLevels, 0,
            imageinfo.Format, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, 
            &imageinfo2, NULL, (LPDIRECT3DTEXTURE9*)&m_ptexOrig ) ) )
        {
            AfxMessageBox(ID_ERROR_COULDNTLOADFILE);
            return FALSE;
        }
        m_dwWidth = imageinfo2.Width;
        m_dwHeight = imageinfo2.Height;
        m_dwDepth = 0;
        m_numMips = imageinfo2.MipLevels;

        if( imageinfo.ImageFileFormat == D3DXIFF_BMP )
        {
            // Look for "foo_a.bmp" for alpha channel
            CString strPath = lpszPathName;
            int i = strPath.ReverseFind('.');
            HRESULT hr;
            strPath = strPath.Left(i) + "_a.bmp";
            CFileStatus status;
            if (CFile::GetStatus(strPath, status))
            {
                // Make sure there's an alpha channel to load alpha image into
                if (FAILED(EnsureAlpha(&m_ptexOrig)))
                    return FALSE;

                LPDIRECT3DSURFACE9 psurf;

                hr = ((LPDIRECT3DTEXTURE9)m_ptexOrig)->GetSurfaceLevel(0, &psurf);
                if (FAILED(hr))
                    return FALSE;

                hr = LoadAlphaIntoSurface(strPath, psurf);
                ReleasePpo(&psurf);
                if (FAILED(hr))
                    return FALSE;

            }
        }
        break;

    case D3DRTYPE_VOLUMETEXTURE:
        if( FAILED( D3DXCreateVolumeTextureFromFileEx( pd3ddev, lpszPathName, 
            imageinfo.Width, imageinfo.Height, imageinfo.Depth, imageinfo.MipLevels,
            0, imageinfo.Format, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE,
            0, &imageinfo2, NULL, (LPDIRECT3DVOLUMETEXTURE9*)&m_ptexOrig ) ) )
        {
            AfxMessageBox(ID_ERROR_COULDNTLOADFILE);
            return FALSE;
        }
        m_dwWidth = imageinfo2.Width;
        m_dwHeight = imageinfo2.Height;
        m_dwDepth = imageinfo2.Depth;
        m_numMips = imageinfo2.MipLevels;
        break;

    case D3DRTYPE_CUBETEXTURE:
        if( FAILED( D3DXCreateCubeTextureFromFileEx( pd3ddev, lpszPathName, 
            imageinfo.Width, imageinfo.MipLevels, 0, imageinfo.Format, 
            D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 
            0, &imageinfo2, NULL, (LPDIRECT3DCUBETEXTURE9*)&m_ptexOrig ) ) )
        {
            AfxMessageBox(ID_ERROR_COULDNTLOADFILE);
            return FALSE;
        }
        m_dwWidth = imageinfo2.Width;
        m_dwHeight = imageinfo2.Height;
        m_dwDepth = 0;
        m_numMips = imageinfo2.MipLevels;
        m_dwCubeMapFlags = DDS_CUBEMAP_ALLFACES;
        break;

    default:
        AfxMessageBox(ID_ERROR_COULDNTLOADFILE);
        return FALSE;
    }

    return TRUE;
}