Exemplo n.º 1
0
HTEXTURE CALL HGE_Impl::Texture_Create(int width, int height)
{
    LPDIRECT3DTEXTURE8 pTex;

#ifdef UNDER_CE
    int w, h;
    for(w = 256; w < width; w <<= 1);
    for(h = 2; h < height; h <<= 1);
    if( FAILED( D3DXCreateTexture( pD3DDevice, w, h,
                                        1,                  // Mip levels
                                        D3DMUSAGE_DYNAMIC | D3DMUSAGE_LOCKABLE, // Usage
                                        D3DFMT_A8R8G8B8,    // Format
                                        D3DMPOOL_VIDEOMEM,  // Memory pool
                                        &pTex ) ) )
#else
    if( FAILED( D3DXCreateTexture( pD3DDevice, width, height,
                                        1,                  // Mip levels
                                        0,                  // Usage
                                        D3DFMT_A8R8G8B8,    // Format
                                        D3DPOOL_MANAGED,    // Memory pool
                                        &pTex ) ) )
#endif
    {   
        _PostError("Can't create texture");
        return NULL;
    }

    return (HTEXTURE)pTex;
}
Exemplo n.º 2
0
//	生成
void CMglTexture::Create( int x, int y, BOOL bRenderTarget )
{
	_MGL_DEBUGLOG( "+ CMglTexture::Create()" );

	InitCheck();	//	初期化チェック

	//	二回目以降の呼び出しを考慮し一端Release
	Release();

	if ( x <= 0 )	x = m_myudg->GetDispX();
	if ( y <= 0 )	y = m_myudg->GetDispY();
	/*m_nBmpSizeX = x;
	m_nBmpSizeY = y;*/

	//	2008/06/28  m_imgInfoも設定してあ・げ・る。
	m_imgInfo.Width = x;
	m_imgInfo.Height = y;

	/*int i;
	ZeroMemory( m_vertices, sizeof(MYU_VERTEX)*4 );*/

	//	m_myudg->backBufferDesc.Format
	if ( bRenderTarget == TRUE ) {
		MyuAssert( D3DXCreateTexture( d3d, x, y, D3DX_DEFAULT, D3DUSAGE_RENDERTARGET, m_myudg->GetFormat(), D3DPOOL_DEFAULT, &m_pTexture ), D3D_OK,
			"CMglTexture::Create()  D3DXCreateTexture(VRAM)に失敗" );
	}
	else {
		MyuAssert( D3DXCreateTexture( d3d, x, y, D3DX_DEFAULT, 0, m_myudg->GetFormat(), D3DPOOL_MANAGED, &m_pTexture ), D3D_OK,
			"CMglTexture::Create()  D3DXCreateTexture(SYSMEM)に失敗" );
	}

	//	記憶しておく
	m_bRenderTarget = bRenderTarget;

	/*
	//SetGradation();

	//	テクスチャのサーフェスを取得する
	MyuAssert( m_pTexture->GetSurfaceLevel(0, &m_pSurface), D3D_OK,
		"CMglTexture::Create()  GetSurfaceLevel()に失敗" );

	//	スプライト作成
	MyuAssert( D3DXCreateSprite( d3d, &this->m_pSprite ), D3D_OK,
		"CMglTexture::Init  D3DXCreateSprite()に失敗" );

	//	クリアする
	//Clear();

	createFlg = TRUE;
	*/

	//	SetRenderとかで必要なのでサーフェス取得しておく
	_GetSurface();

	//	2008/06/30 なんでクリアしないんだろうかー?
	//Clear();
	Clear(0);	//	0にしないとカラーキー+白に勝手にされてしまう・・・

	_MGL_DEBUGLOG( "- CMglTexture::Create()" );
}
void TransitionCircleScan::doAfterSetScene()
{
    D3DXCreateTexture(Graphics::getInstance()->getDevice(), SCWIDTH, SCHEIGHT, D3DX_DEFAULT,
        D3DUSAGE_RENDERTARGET, D3DFMT_A8B8G8R8, D3DPOOL_DEFAULT, &texture0);

    D3DXCreateTexture(Graphics::getInstance()->getDevice(), SCWIDTH, SCHEIGHT, D3DX_DEFAULT,
        D3DUSAGE_RENDERTARGET, D3DFMT_A8B8G8R8, D3DPOOL_DEFAULT, &texture1);
    Graphics::getInstance()->isAllowPresent = false;

    IDirect3DSurface9 *surface, *backsurface;
    this->sceneDest->render();
    texture1->GetSurfaceLevel(0, &surface);
    Graphics::getInstance()->getDevice()->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backsurface);

    D3DXLoadSurfaceFromSurface(surface, NULL, NULL, backsurface, NULL, NULL, D3DX_FILTER_NONE, 0);
    surface->Release();
    surface = nullptr;

    this->sceneSource->render();
    texture0->GetSurfaceLevel(0, &surface);
    D3DXLoadSurfaceFromSurface(surface, NULL, NULL, backsurface, NULL, NULL, D3DX_FILTER_NONE, 0);
    surface->Release();

    Graphics::getInstance()->isAllowPresent = true;
}
Exemplo n.º 4
0
Bloom::Bloom()
: m_rt1(0), m_rt2(0), m_fx(0)
{
	f32 width = gEngine.device->getWidth();
	f32 height = gEngine.device->getHeight();

	if(FAILED(D3DXCreateTexture(gEngine.device->getDev(), width/2, height/2, 1,	D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_rt1))
	|| FAILED(D3DXCreateTexture(gEngine.device->getDev(), width/2, height/2, 1,	D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_rt2)))
	{
		gEngine.kernel->log->prnEx(LT_ERROR, "Bloom", "Creating textures failed");
		return;
	}

	VertexTransformedTextured* data;

	gEngine.device->getDev()->CreateVertexBuffer(4 * sizeof(VertexTransformedTextured), D3DUSAGE_WRITEONLY, VertexTransformedTextured_FVF,
		D3DPOOL_MANAGED, &m_vbHalf, 0);
	m_vbHalf->Lock(0, 0, (void**)&data, 0);
	data[0].p = D3DXVECTOR4(-0.5f, height/2-0.5f, 0.0f, 1.0f);
	data[0].u = 0.0f;
	data[0].v = 1.0f;
	data[1].p = D3DXVECTOR4(width/2-0.5f, height/2-0.5f, 0.0f, 1.0f);
	data[1].u = 1.0f;
	data[1].v = 1.0f;
	data[2].p = D3DXVECTOR4(-0.5f, -0.5f, 0.0f, 1.0f);
	data[2].u = 0.0f;
	data[2].v = 0.0f;
	data[3].p = D3DXVECTOR4(width/2-0.5f, -0.5f, 0.0f, 1.0f);
	data[3].u = 1.0f;
	data[3].v = 0.0f;
	m_vbHalf->Unlock();

	m_fx = gEngine.shaderMgr->load("Bloom.fx");
}
Exemplo n.º 5
0
HRESULT CShimmer::Init(void)
{
	Window* window = Window::Instance();
	LPDIRECT3DDEVICE9 Device = window->Device();

	//シェーダーを作成
	LPD3DXBUFFER pError = NULL;
	if (FAILED(D3DXCreateEffectFromFile(Device,"data/shaders/ShimmerShader.fx",NULL,NULL,D3DXSHADER_SKIPVALIDATION,NULL,&Effect,&pError)))
	{
		MessageBox(nullptr,"陽炎シェーダーの生成に失敗しました","ERROR",MB_OK | MB_ICONERROR);
		OutputDebugStringA((LPCSTR)pError->GetBufferPointer());
		pError->Release();
		pError = nullptr;
		return E_FAIL;
	}

	//陽炎マップ用テクスチャを作成、サーフェイスにセット
	D3DXCreateTexture(Device,(UINT)window->WindowSize().x,(UINT)window->WindowSize().y,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&Texture);
	Texture->GetSurfaceLevel(0,&Surface);

	for (int cnt = 0;cnt < 2;cnt++)
	{
		D3DXCreateTexture(Device,(UINT)window->WindowSize().x,(UINT)window->WindowSize().y,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&BlurTex[cnt]);
		BlurTex[cnt]->GetSurfaceLevel(0,&Blur[cnt]);
	}

	//結果用テクスチャを作成、サーフェイスにセット
	D3DXCreateTexture(Device,(UINT)window->WindowSize().x,(UINT)window->WindowSize().y,1,D3DUSAGE_RENDERTARGET,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&Result);
	Result->GetSurfaceLevel(0,&ResultSurface);

	D3DXMATRIX Projection = D3DXMATRIX(
		2.0f,0,0,0,
		0,-2.0f,0,0,
		0,0,1.0f,0,
		0,0,0,1.0f);
	Effect->SetMatrix("Projection",&Projection);
	D3DXVECTOR2 texel = D3DXVECTOR2(1.0f / window->WindowSize().x,1.0f / window->WindowSize().y);
	float U[5];
	float V[5];
	for (int cnt = 0;cnt < 5;cnt++)
	{
		U[cnt] = texel.x * (cnt + 1);
		V[cnt] = texel.y * (cnt + 1);
	}
	Effect->SetFloatArray("TexelU",U,5);
	Effect->SetFloatArray("TexelV",V,5);

	for (int cnt = 0;cnt < PARAM_MAX;cnt++)
	{
		Param[cnt] = Effect->GetParameterByName(NULL,ParamName[cnt]);
	}

	Effect->SetTechnique("Shimmer");

	return S_OK;
}
Exemplo n.º 6
0
bool TextureDX9Imp::acquireResource()
{
    if( NULL != textureDX9_ ) return true;

    LPDIRECT3DTEXTURE9 newTexDX9;
    if( isFromFile() )
    {
        const HRESULT hr = D3DXCreateTextureFromFileEx( getD3D9Device(), filename_.c_str(),
            D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
            D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
            0, NULL, NULL, & newTexDX9 );
        RETURN_FALSE_IF_FAILED( hr, L"TextureDX9Imp::acquireResource" );
    }
    else
    {
        const HRESULT hr = D3DXCreateTexture( getD3D9Device(),
            requiredWidth_, requiredHeight_, requiredMipLevels_, requiredUsage_,
            requiredFormat_, requiredPool_, & newTexDX9 );
        RETURN_FALSE_IF_FAILED( hr, L"TextureDX9Imp::acquireResource" );
    }

    textureDX9_ = IDirect3DTexture9Ptr( newTexDX9, ComReleaser< IDirect3DTexture9 >() );

    MY_FOR_EACH( Surfaces, iter, surfaces_ )
        acquireSurface( iter->level );
    return true;
}
Exemplo n.º 7
0
// interface functions
void MFTexture_CreatePlatformSpecific(MFTexture *pTexture, bool generateMipChain)
{
	MFCALLSTACK;

	HRESULT hr;
	MFTextureTemplateData *pTemplate = pTexture->pTemplateData;

	// create texture
	D3DFORMAT platformFormat = (D3DFORMAT)MFTexture_GetPlatformFormatID(pTemplate->imageFormat, MFDD_D3D9);
	hr = D3DXCreateTexture(pd3dDevice, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, generateMipChain ? 0 : 1, 0, platformFormat, D3DPOOL_MANAGED, (IDirect3DTexture9**)&pTexture->pInternalData);

	MFDebug_Assert(hr != D3DERR_NOTAVAILABLE, MFStr("LoadTexture failed: D3DERR_NOTAVAILABLE, 0x%08X", hr));
	MFDebug_Assert(hr != D3DERR_OUTOFVIDEOMEMORY, MFStr("LoadTexture failed: D3DERR_OUTOFVIDEOMEMORY, 0x%08X", hr));
	MFDebug_Assert(hr != D3DERR_INVALIDCALL, MFStr("LoadTexture failed: D3DERR_INVALIDCALL, 0x%08X", hr));
	MFDebug_Assert(hr != D3DXERR_INVALIDDATA, MFStr("LoadTexture failed: D3DXERR_INVALIDDATA, 0x%08X", hr));

	MFDebug_Assert(hr == D3D_OK, MFStr("Failed to create texture '%s'.", pTexture->name));

	IDirect3DTexture9 *pTex = (IDirect3DTexture9*)pTexture->pInternalData;

	// copy image data
	D3DLOCKED_RECT rect;
	pTex->LockRect(0, &rect, NULL, 0);
	MFCopyMemory(rect.pBits, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].bufferLength);
	pTex->UnlockRect(0);

	// filter mip levels
	if(generateMipChain)
		D3DXFilterTexture(pTex, NULL, 0, D3DX_DEFAULT);
}
Exemplo n.º 8
0
ImagePtr D3D9VideoBufferManager::CreateImage(int iWidth, int iHeight, FORMAT Format)
{
    IDirect3DTexture9 * texture;
    HRESULT hr = D3DXCreateTexture(mD3D9Device, 
                                   iWidth,
                                   iHeight,
                                   1,
                                   0,
                                   D3D9Mapping::GetD3DFormat(Format),
                                   D3DPOOL_SYSTEMMEM,
                                   &texture);

    D3DErrorExceptionFunction(D3DXCreateTexture, hr);

    IDirect3DSurface9 * surface;
    texture->GetSurfaceLevel(0, &surface);
    D3DSURFACE_DESC desc;
    surface->GetDesc(&desc);

    D3D9Image * image = new D3D9Image();

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

    surface->Release();

    return ImagePtr(image);
}
Exemplo n.º 9
0
ENGINE_NAMESPACE_BEGIN_ENGINE
//-------------------------------------------------------------------------------------------------
sdMemoryTexture::sdMemoryTexture(uint uiWidth, uint uiHeight, uint uiLevel, D3DFORMAT eFormat)
{
	// 获取渲染设备
	NiDX9Renderer* spRenderer = NiDX9Renderer::GetRenderer();
	NIASSERT(spRenderer);

	LPDIRECT3DDEVICE9 spD3DDevice = spRenderer->GetD3DDevice();
	NIASSERT(spD3DDevice);

	//
	m_uiWidth = uiWidth;
	m_uiHeight = uiHeight;
	m_uiLevel = uiLevel;
	m_eFormat = eFormat;

	// 创建D3D纹理
	HRESULT hr = D3DXCreateTexture(spD3DDevice, 
		m_uiWidth, m_uiHeight, uiLevel, 
		0,
		eFormat,
		D3DPOOL_SYSTEMMEM,
		&m_spD3DTexture);
	if (FAILED(hr))	
	{
		NIASSERT(0);
		return;
	}
	m_spD3DTexture->AddRef();

	// 创建GB纹理对象
	m_spTexture = spRenderer->CreateNiTextureFromD3DTexture(m_spD3DTexture);
	NIASSERT(m_spTexture);
}
Exemplo n.º 10
0
	void SPTexture::CreateRenderTarget( int setWidth, int setHeight, D3DXCOLOR setColor )
	{
		SPGameManager::GetSingleton()->GetGame()->LockDrawing();

		// Create texture from memory.
		HRESULT hr = D3DXCreateTexture(
			SPDevice::GetSingleton()->GetD3DDevice(),
			setWidth, setHeight,
			1, D3DUSAGE_RENDERTARGET,
			D3DFMT_A8R8G8B8,
			D3DPOOL_DEFAULT,
			&texture);

		if (FAILED(hr))
		{
			texture = NULL;
			return;
		}

		height = setHeight;
		width = setWidth;
		format = D3DFMT_A8R8G8B8;
		isRenderTarget = true;
		backgroundColor = setColor;

		//Fill(0x00000000);

		SPGameManager::GetSingleton()->GetGame()->UnlockDrawing();
	}
Exemplo n.º 11
0
	void SPTexture::CreateBlank( int setWidth, int setHeight )
	{
		SPGameManager::GetSingleton()->GetGame()->LockDrawing();

		// Create texture from memory.
		HRESULT hr = D3DXCreateTexture(
			SPDevice::GetSingleton()->GetD3DDevice(),
			setWidth, setHeight,
			0,	0,
			D3DFMT_A8R8G8B8,
			D3DPOOL_MANAGED,
			&texture);

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

		if (FAILED(hr))
		{
			texture = NULL;
			return;
		}

		height = setHeight;
		width = setWidth;
		format = D3DFMT_A8R8G8B8;
	}
Exemplo n.º 12
0
void	cTexBuf::Create( int nWidthSize, int nHeightSize )
{
	m_nWidth	=	nWidthSize;
	m_nHeight	=	nHeightSize;

	
	D3DXCreateTexture( DXUTGetD3D9Device()
		, m_nWidth
		, m_nHeight
		, 1
		, D3DUSAGE_RENDERTARGET
		, D3DFMT_A8R8G8B8
		, D3DPOOL_DEFAULT
		, &m_pTexture );

	m_pTexture->GetSurfaceLevel( 0, &m_pRenderTarget );

	DXUTGetD3D9Device()->GetRenderTarget( 0, &m_pOriRenderTarget );
	DXUTGetD3D9Device()->GetDepthStencilSurface( &m_pOriDepthSurface );

	D3DSURFACE_DESC dsc;
	m_pOriDepthSurface->GetDesc( &dsc );

	DXUTGetD3D9Device()->CreateDepthStencilSurface(
		  m_nWidth
		, m_nHeight
		, dsc.Format
		, D3DMULTISAMPLE_NONE
		, 0
		, true
		, &m_pDepthSurface
		, NULL );
}
Exemplo n.º 13
0
BOOL dx9vid_init()
{
	d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface
	D3DCAPS9 d3dCaps;
	d3d->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps );
	d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );

	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed               = TRUE;
	d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat       = d3ddm.Format;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
	d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;

	d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hwnd,
						D3DCREATE_SOFTWARE_VERTEXPROCESSING,
						&d3dpp, &d3ddev );

	// Create the screen texture
	D3DXCreateTexture( d3ddev, 256, 256, D3DX_FILTER_NONE, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &g_screenTex);

	// Create the screen sprite (ignores 3d perspective)
	D3DXCreateSprite( d3ddev, &g_screenSprite );

	// Scale our matrix to match the screen
	D3DXMatrixIdentity( &pTransform );
	spritePos = D3DXVECTOR2( 0.f, 0.f );
	rotCenter = D3DXVECTOR2( 0.f, 0.f);
	D3DXVECTOR2 vscale = D3DXVECTOR2( float(3.0f), float(3.0f));
	D3DXMatrixTransformation2D( &pTransform, NULL, 0.0f, &vscale, &rotCenter, 0.f, &spritePos );
	g_screenSprite->SetTransform(&pTransform);

	return TRUE;
}
Exemplo n.º 14
0
void TERRAIN::CalculateAlphaMaps()
{
	Progress("Creating Alpha Map", 0.0f);

	//Clear old alpha maps
	if(m_pAlphaMap != NULL)
		m_pAlphaMap->Release();

	//Create new alpha map
	D3DXCreateTexture(m_pDevice, 128, 128, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pAlphaMap);

	//Lock the texture
	D3DLOCKED_RECT sRect;
	m_pAlphaMap->LockRect(0, &sRect, NULL, NULL);
	BYTE *bytes = (BYTE*)sRect.pBits;
	memset(bytes, 0, 128*sRect.Pitch);		//Clear texture to black

	for(int i=0;i<(int)m_diffuseMaps.size();i++)
		for(int y=0;y<sRect.Pitch / 4;y++)
			for(int x=0;x<sRect.Pitch / 4;x++)
			{
				int terrain_x = (int)(m_size.x * (x / (float)(sRect.Pitch / 4.0f)));
				int terrain_y = (int)(m_size.y * (y / (float)(sRect.Pitch / 4.0f)));
				MAPTILE *tile = GetTile(terrain_x, terrain_y);

				if(tile != NULL && tile->m_type == i)
					bytes[y * sRect.Pitch + x * 4 + i] = 255;
			}

	//Unlock the texture
	m_pAlphaMap->UnlockRect(0);
	
	//D3DXSaveTextureToFile("alpha.bmp", D3DXIFF_BMP, m_pAlphaMap, NULL);
}
Exemplo n.º 15
0
////////////////////////////////////////////////////////////////
//
// CWebBrowserItem::CreateUnderlyingData
//
//
//
////////////////////////////////////////////////////////////////
void CWebBrowserItem::CreateUnderlyingData()
{
    assert(!m_pD3DRenderTargetSurface);
    assert(!m_pD3DTexture);

    D3DXCreateTexture(m_pDevice, m_uiSizeX, m_uiSizeY, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, (IDirect3DTexture9**)&m_pD3DTexture);

    // Check texture created
    if (!m_pD3DTexture)
        return;

    // D3DXCreateTexture sets width and height to 1 if the argument value was 0
    // See: https://docs.microsoft.com/en-us/windows/desktop/direct3d9/d3dxcreatetexture
    if (m_uiSizeX == 0)
        m_uiSizeX = 1;

    if (m_uiSizeY == 0)
        m_uiSizeY = 1;

    // Get the render target surface here for convenience
    ((IDirect3DTexture9*)m_pD3DTexture)->GetSurfaceLevel(0, &m_pD3DRenderTargetSurface);

    // Update surface size, although it probably will be unchanged | Todo: Remove this
    D3DSURFACE_DESC desc;
    m_pD3DRenderTargetSurface->GetDesc(&desc);
    m_uiSurfaceSizeX = desc.Width;
    m_uiSurfaceSizeY = desc.Height;

    m_iMemoryKBUsed = CRenderItemManager::CalcD3DResourceMemoryKBUsage(m_pD3DRenderTargetSurface);
}
Exemplo n.º 16
0
    RenderTargetTexture2D::RenderTargetTexture2D(GraphicsDevice* graphicsDevice, int width, int height)
        : Texture2D(graphicsDevice, width, height, width, height, A8R8G8B8Pixels),
          d3dSurface(nullptr)
    {
        BBAssert(GetGraphicsDevice()->GetD3DDevice() != nullptr);

        IDirect3DTexture9* newD3DTexture = nullptr;
        HRESULT result = D3DXCreateTexture(GetGraphicsDevice()->GetD3DDevice(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newD3DTexture);
        if (result == D3D_OK)
        {
            D3DSURFACE_DESC surfaceDesc;
            if (newD3DTexture->GetLevelDesc(0, &surfaceDesc) == D3D_OK)
                Setup(newD3DTexture, width, height, static_cast<int>(surfaceDesc.Width), static_cast<int>(surfaceDesc.Height), A8R8G8B8Pixels);
            else
                Setup(newD3DTexture, width, height, width, height, A8R8G8B8Pixels);

            newD3DTexture->GetSurfaceLevel(0, &d3dSurface);
            
            IncreaseRevision();
            SetStatus(CompletedStatus);
        }
        else
        {
            IncreaseRevision();
            SetStatus(FaultStatus);
        }
    }
Exemplo n.º 17
0
INT TcolorMap::OnLostDevice()
{
	HRESULT hr;
	PDSF	pSrc =m_pSf;
	PDSF	pDst;

	hr = D3DXCreateTexture(m_pDev, m_iW, m_iH, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_pTxT);

	if(FAILED(hr))
		return -1;

	hr = m_pTxT->GetSurfaceLevel(0,&pDst);

	if(FAILED(hr))
		return -1;

	hr = D3DXLoadSurfaceFromSurface(pDst, NULL, NULL, m_pSf, NULL, NULL, D3DX_FILTER_NONE, 0x0);

	if(FAILED(hr))
		return -1;

	SAFE_RELEASE(	pDst	);


	SAFE_RELEASE(m_pSf);
	SAFE_RELEASE(m_pTx);

	SAFE_RELEASE(m_pBckC);
	SAFE_RELEASE(m_pBckD);

	return 0;
}
Exemplo n.º 18
0
void DX9RenderTarget::createTexture()
{
   // create the texture
   D3DFORMAT texFormat = m_renderer.getOptimalTextureFormat( m_renderTarget.getUsage() );
   unsigned int width = m_renderTarget.getWidth();
   unsigned int height = m_renderTarget.getHeight();

   IDirect3DDevice9& d3Device = m_renderer.getD3Device();

   HRESULT res = D3DXCreateTexture( &d3Device,
      width, height,          // dimensions
      1,                      // MIP levels
      D3DUSAGE_RENDERTARGET,  // usage
      texFormat,              // format
      D3DPOOL_DEFAULT,        // memory pool
      &m_dxTexture);


   if ( FAILED(res) || m_dxTexture == NULL )
   {
      std::string errMsg = translateDxError( "Can't create a render target", res );
      ASSERT_MSG( false, errMsg.c_str() );
   }

   // tell the render target that it needs to be refilled with data, 'cause it's just been created
   m_renderTarget.markNotFresh( m_renderer );
}
Exemplo n.º 19
0
	LPDIRECT3DTEXTURE9 DX9RenderSystem::GetTextureCache( Texture* tex )
	{
		TextureRC*& rc = (TextureRC*&)tex->mCache;
		if( !rc )
			rc = new TextureRC( );

		if( tex->IsDirty( ) )
		{
			if( mCacheCount >= DX9MAXFRAMECACHE )
				return 0;
			mCacheCount++;

			if( FAILED(D3DXCreateTexture( mDevice, tex->GetWidth( ), tex->GetHeight( ), 1, D3DUSAGE_DYNAMIC, (D3DFORMAT)tex->GetFormat( ), D3DPOOL_DEFAULT, &rc->mData )) )
			{
				printf( "Failed to create Texture Cache :: Couldn't create surface\n" );
				return 0;
			}

			LPDIRECT3DSURFACE9 surf;
			rc->mData->GetSurfaceLevel( 0, &surf );
			D3DLOCKED_RECT rect;
			surf->LockRect( &rect, 0, 0 );
			char* data = (char*)rect.pBits;
			memcpy( data, tex->GetBuffer( ), tex->GetBufferSize( ) );
			surf->UnlockRect( );

			D3DXSaveTextureToFile( "c:\\texdebug.png", D3DXIFF_PNG, rc->mData, 0 );

			tex->SetDirty( false );
		}
		return rc->mData;
	};
Exemplo n.º 20
0
	void ReadyResource()
	{
		g_d3dDev->GetRenderTarget(0, &backBuf);
		g_d3dDev->GetDepthStencilSurface(&backDepthBuf);

		D3DXCreateTexture(
			g_d3dDev,
			512,
			512,
			1,
			D3DUSAGE_RENDERTARGET,
			D3DFMT_A8R8G8B8,
			D3DPOOL_DEFAULT,
			&gameScr);
		if (FAILED(gameScr->GetSurfaceLevel(0, &scrBuf)))
		{
			throw Error("サーフェイスの取得に失敗");
		}

		g_d3dDev->CreateDepthStencilSurface(
			512,
			512,
			D3DFMT_D16,
			D3DMULTISAMPLE_NONE,
			0,
			TRUE,
			&scrDepthBuf,
			NULL);

		Image::AllRestore();
		return;
	}
Exemplo n.º 21
0
int RendererD3D::InitializeTextureFromBits(byte* pImageBits, int width, int height)
{
	HRESULT result;

	LPDIRECT3DSURFACE9 surface=NULL;
	LPDIRECT3DTEXTURE9 texture = NULL;
	
	result = D3DXCreateTexture( m_pd3dDevice, width, height, D3DX_DEFAULT, 0, D3DFMT_R8G8B8,D3DPOOL_MANAGED, &texture);

	texture->GetSurfaceLevel(0, &surface);

	RECT rect;
	rect.top = 0;
	rect.left = 0;
	rect.bottom = height;
	rect.right = width;

	result = D3DXLoadSurfaceFromMemory(surface,NULL,NULL,pImageBits,D3DFMT_R8G8B8, width*3*sizeof(byte),NULL,&rect,D3DX_DEFAULT,0);

	surface->Release();

	assert(result == D3D_OK);

	m_textureList.push_back(texture);
	return (m_textureList.size()-1);
}	
Exemplo n.º 22
0
void CD3DWater::FetchSurfaces()
{
	// 创建反射纹理并获得其渲染表面
	D3DXCreateTexture(m_pDevice, m_pD3PP.BackBufferWidth, m_pD3PP.BackBufferWidth,
		1, D3DUSAGE_RENDERTARGET,
		D3DFMT_A8R8G8B8,
		D3DPOOL_DEFAULT,
		&m_pReflectTexture);
	m_pReflectTexture->GetSurfaceLevel(0, &m_pReflectSurface);

	// 创建折射纹理并获得其渲染表面
	D3DXCreateTexture(m_pDevice, m_pD3PP.BackBufferWidth, m_pD3PP.BackBufferHeight, 1,
		D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pRefractTexture);

	m_pRefractTexture->GetSurfaceLevel(0, &m_pRefractSurface);
}
Exemplo n.º 23
0
//================================================================================
void ATHRenderTarget::Create( IDirect3DDevice9* _pDevice, UINT _width, UINT _height, D3DFORMAT _format )
{
    m_pDevice = _pDevice;
    D3DXCreateTexture( m_pDevice, _width, _height, 1, D3DUSAGE_RENDERTARGET,
                       _format, D3DPOOL_DEFAULT, &m_pTargetTexture );
    m_pTargetTexture->GetSurfaceLevel( 0, &m_pRenderSurface );
}
Exemplo n.º 24
0
void TextureImpl_DirectX9::CreateColor(const iSize &size, const cColorRGBA &color)
{
    if (LPDIRECT3DDEVICE9 device = DrawManager::GetDeviceHandle())
    {
        _format = D3DFMT_A8R8G8B8;
        if (D3DXCreateTexture(device, size.width, size.height, 0, D3DUSAGE_DYNAMIC, _format, D3DPOOL_DEFAULT, &_texture)==S_OK)
        {
            D3DLOCKED_RECT lockedRect;
            if (_texture->LockRect(0, &lockedRect, 0, 0) == S_OK)
            {
                cColorRGBA *ptr = (cColorRGBA *)lockedRect.pBits;
                for(int32 y=0;y<size.height;y++)
                {
                    for(int32 x=0;x<size.width;x++)
                    {
                        ptr[x] = color;
                    }
                    ptr = (cColorRGBA*)((BYTE*)ptr + lockedRect.Pitch);
                }
                _texture->UnlockRect(0);
            }
        }
        else
        {
            _format = D3DFMT_UNKNOWN;
        }
    }
    _size = size;
}
Exemplo n.º 25
0
bool TextureImpl_DirectX9::Create(const iSize &size, TEXTURE_COLOR_FORMAT format, uint32 usage, uint32 mipLevels)
{
    if (_texture) _texture->Release(); _texture = NULL;

    if (LPDIRECT3DDEVICE9 device = DrawManager::GetDeviceHandle())
    {
        _format = convertFormat(format);
        _usage = convertUsage(usage);
        if (D3DXCreateTexture(device, size.width, size.height, 0, _usage, _format, D3DPOOL_DEFAULT, &_texture)==S_OK)
        {
            _size = size;

            // MakeDepthSurface
            if(usage & TEXTURE_USAGE_RENDERTARGET) {
                if(device->CreateDepthStencilSurface(size.width, size.height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, TRUE, &_depthSurface, NULL) != S_OK) {
                    _texture->Release();
                    _texture = NULL;
                    return false;
                }
            }
            return true;
        }
        else
        {
            _format = D3DFMT_UNKNOWN;
        }
    }
    return false;
}
Exemplo n.º 26
0
//=================================================================================================
void Terrain::CreateSplatTexture()
{
	DWORD usage = D3DUSAGE_AUTOGENMIPMAP;

	HRESULT hr = D3DXCreateTexture(device, tex_size, tex_size, 1, usage, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texSplat);
	if(FAILED(hr))
		throw Format("Failed to create terrain texture with size '%d' (%d)!", tex_size, hr);
}
Exemplo n.º 27
0
HRESULT InitD3D( HWND hWnd )
{
	// Create the D3D object.
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
		return E_FAIL;

	// Set up the structure used to create the D3DDevice
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory( &d3dpp, sizeof( d3dpp ) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	// Create the D3DDevice
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		return E_FAIL;
	}

	g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
	g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);

	// Create a dynamic texture
	if( FAILED( D3DXCreateTexture(g_pd3dDevice,g_ogg.width(),g_ogg.height(),1,D3DUSAGE_DYNAMIC,D3DFMT_X8B8G8R8,D3DPOOL_DEFAULT,&g_pTexture)))
	{
		return E_FAIL;
	}

	float x1 = 0;
	float y1 = 0;
	float x2 = g_ogg.width();
	float y2 = g_ogg.height();
	// Initialize three vertices for rendering a quad
	CUSTOMVERTEX vertices[] =
	{   // x, y, z, color, tu, tv
		{  x1,  y1, 0.0f, 1.0f, 0xffffffff, 0.0f, 0.0f }, 
		{  x2,  y1, 0.0f, 1.0f, 0xffffffff, 1.0f, 0.0f },
		{  x2,  y2, 0.0f, 1.0f, 0xffffffff, 1.0f, 1.0f },
		{  x1,  y2, 0.0f, 1.0f, 0xffffffff, 0.0f, 1.0f },
	};

	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4 * sizeof( CUSTOMVERTEX ),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
	{
		return E_FAIL;
	}

	VOID* pVertices;
	if( FAILED( g_pVB->Lock( 0, sizeof( vertices ), ( void** )&pVertices, 0 ) ) )
		return E_FAIL;
	memcpy( pVertices, vertices, sizeof( vertices ) );
	g_pVB->Unlock();

	return S_OK;
}
Exemplo n.º 28
0
////////////////////////////////////////////////////////////////
//
// CFileTextureItem::CreateUnderlyingData
//
// Blank sized
//
////////////////////////////////////////////////////////////////
void CFileTextureItem::CreateUnderlyingData(bool bMipMaps, uint uiSizeX, uint uiSizeY, ERenderFormat format, ETextureType textureType, uint uiVolumeDepth)
{
    assert(!m_pD3DTexture);

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

    m_uiSizeX = uiSizeX;
    m_uiSizeY = uiSizeY;
    m_uiSurfaceSizeX = uiSizeX;
    m_uiSurfaceSizeY = uiSizeY;

    if (textureType == D3DRTYPE_VOLUMETEXTURE)
    {
        if (FAILED(D3DXCreateVolumeTexture(m_pDevice,                  //__in   LPDIRECT3DDEVICE9 pDevice,
                                           uiSizeX,                    //__in   UINT Width,
                                           uiSizeY,                    //__in   UINT Height,
                                           uiVolumeDepth,              //__in   UINT Depth,
                                           iMipMaps,                   //__in   UINT MipLevels,
                                           0,                          //__in   DWORD Usage,
                                           D3DFormat,                  //__in   D3DFORMAT Format,
                                           D3DPOOL_MANAGED,            //__in   D3DPOOL Pool,
                                           (IDirect3DVolumeTexture9**)&m_pD3DTexture)))
            return;
    }
    else if (textureType == D3DRTYPE_CUBETEXTURE)
    {
        if (FAILED(D3DXCreateCubeTexture(m_pDevice,                  //__in   LPDIRECT3DDEVICE9 pDevice,
                                         uiSizeX,                    //__in   UINT Width,
                                         iMipMaps,                   //__in   UINT MipLevels,
                                         0,                          //__in   DWORD Usage,
                                         D3DFormat,                  //__in   D3DFORMAT Format,
                                         D3DPOOL_MANAGED,            //__in   D3DPOOL Pool,
                                         (IDirect3DCubeTexture9**)&m_pD3DTexture)))
            return;
    }
    else
    {
        if (FAILED(D3DXCreateTexture(m_pDevice,                  //__in   LPDIRECT3DDEVICE9 pDevice,
                                     uiSizeX,                    //__in   UINT Width,
                                     uiSizeY,                    //__in   UINT Height,
                                     iMipMaps,                   //__in   UINT MipLevels,
                                     0,                          //__in   DWORD Usage,
                                     D3DFormat,                  //__in   D3DFORMAT Format,
                                     D3DPOOL_MANAGED,            //__in   D3DPOOL Pool,
                                     (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);
}
Exemplo n.º 29
0
bool TextureClass::setEmpty(int width, int height)
{
	if (_Texture != nullptr)
		textureClear();
	HRESULT hr = D3DXCreateTexture(_Device, width, height, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &_Texture);
	if (FAILED(hr))
		return false;
	return true;
}
Exemplo n.º 30
0
LPDIRECT3DTEXTURE9 D3D9::CreateTexture(int texWidth, int texHeight, D3DCOLOR color)
{
	LPDIRECT3DTEXTURE9 pTexture;

	HRESULT hr = D3DXCreateTexture(d3ddevice_, 
		texWidth, 
		texHeight, 
		0, 
		0, 
		D3DFMT_A8R8G8B8,  // 4 bytes for a pixel 
		D3DPOOL_MANAGED, 
		&pTexture);

	if (FAILED(hr))
	{
		MessageBox(NULL, L"Create texture failed", L"Error", 0);
	}

	// Lock the texture and fill in color
	D3DLOCKED_RECT lockedRect;
	hr = pTexture->LockRect(0, &lockedRect, NULL, 0);
	if (FAILED(hr))
	{
		MessageBox(NULL, L"Lock texture failed!", L"Error", 0);
	}

	DWORD sideColor = 0xff000000; // the side line color

	int side_width = 10;

	// Calculate number of rows in the locked Rect
	int rowCount = (texWidth * texHeight * 4 ) / lockedRect.Pitch;

	for (int i = 0; i < texWidth; ++i)
	{
		for (int j = 0; j < texHeight; ++j)
		{
			int index = i * rowCount + j;

			int* pData = (int*)lockedRect.pBits;

			if (i <= side_width || i >= texWidth - side_width 
				|| j <= side_width || j >= texHeight - side_width)
			{
				memcpy(&pData[index], &sideColor, 4);
			}
			else
			{
				memcpy(&pData[index], &color, 4);
			}
		}
	}

	pTexture->UnlockRect(0);

	return pTexture;
}