Example #1
0
RageSurface* RageDisplay_D3D::CreateScreenshot()
{
#if defined(XBOX)
	return NULL;
#else
	RageSurface * result = NULL;

	// Get the back buffer.
	IDirect3DSurface9* pSurface;
	if( SUCCEEDED( g_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface ) ) )
	{
		// Get the back buffer description.
		D3DSURFACE_DESC desc;
		pSurface->GetDesc( &desc );

		// Copy the back buffer into a surface of a type we support.
		IDirect3DSurface9* pCopy;
		if( SUCCEEDED( g_pd3dDevice->CreateOffscreenPlainSurface( desc.Width, desc.Height, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pCopy, NULL ) ) )
		{
			if( SUCCEEDED( D3DXLoadSurfaceFromSurface( pCopy, NULL, NULL, pSurface, NULL, NULL, D3DX_FILTER_NONE, 0) ) )
			{
				// Update desc from the copy.
				pCopy->GetDesc( &desc );

				D3DLOCKED_RECT lr;

				{
					RECT rect;
					rect.left = 0;
					rect.top = 0;
					rect.right = desc.Width;
					rect.bottom = desc.Height;

					pCopy->LockRect( &lr, &rect, D3DLOCK_READONLY );
				}

				RageSurface *surface = CreateSurfaceFromPixfmt( FMT_RGBA8, lr.pBits, desc.Width, desc.Height, lr.Pitch);
				ASSERT( surface != NULL );

				// We need to make a copy, since lr.pBits will go away when we call UnlockRect().
				result = 
					CreateSurface( surface->w, surface->h,
						surface->format->BitsPerPixel,
						surface->format->Rmask, surface->format->Gmask,
						surface->format->Bmask, surface->format->Amask );
				RageSurfaceUtils::CopySurface( surface, result );
				delete surface;

				pCopy->UnlockRect();
			}

			pCopy->Release();
		}

		pSurface->Release();
	}

	return result;
#endif
}
CDX9TextureManager::CDX9TextureManager(  )
: m_pDefaultRT( NULL )
, m_pDefaultDT( NULL )
, m_pNULLTexture( NULL )
{

	// Create the default render target 

	IDirect3DSurface9* pDefaultRT = NULL;
	CDX9Renderer::GetDevice( )->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pDefaultRT );

	D3DSURFACE_DESC RTDesc;
	pDefaultRT->GetDesc( &RTDesc );

	m_pDefaultRT = new CDX9Texture( pDefaultRT, CDX9Renderer::GetDevice( ) );

	// Create the default depth target

	IDirect3DSurface9* pDefaultDT = NULL;
	CDX9Renderer::GetDevice( )->GetDepthStencilSurface( &pDefaultDT );

	D3DSURFACE_DESC Desc;
	pDefaultDT->GetDesc( &Desc );


	m_pDefaultDT = new CDX9Texture( pDefaultDT, CDX9Renderer::GetDevice( ), true );

	// Create the null texture

	IDirect3DTexture9* p = NULL;
	m_pNULLTexture = new CDX9Texture( p, CDX9Renderer::GetDevice( ) );
}
Example #3
0
HRESULT CD3DUtils::ProgressiveBlt(IDirect3DSurface9 *pSurfIn, IDirect3DSurface9 *pSurfOut)
{
    if (!m_pVPDevice || !pSurfIn || !pSurfOut) return E_FAIL;

    DXVA2_VideoProcessBltParams blt = {0};
    DXVA2_VideoSample samples[2] = {0};
    RECT SrcRect = {0};
    RECT DstRect = {0};
    D3DSURFACE_DESC SrcDesc, DstDesc;
    IDirect3DSurface9 *pSrc = pSurfIn;
    IDirect3DSurface9 *pDst = pSurfOut;
    REFERENCE_TIME rtStart = 0;
    REFERENCE_TIME rtStop = 1;

    pSrc->GetDesc(&SrcDesc);
    pDst->GetDesc(&DstDesc);

    SrcRect.right = SrcDesc.Width;
    SrcRect.bottom = SrcDesc.Height;
    DstRect.right = DstDesc.Width;
    DstRect.bottom = DstDesc.Height;

    FillDefaultBltInfo(blt);

    blt.TargetFrame = rtStart;
    blt.TargetRect  = DstRect;

    // DXVA2_VideoProcess_Constriction
    blt.ConstrictionSize.cx = blt.TargetRect.right - blt.TargetRect.left;
    blt.ConstrictionSize.cy = blt.TargetRect.bottom - blt.TargetRect.top;

    //
    // Initialize main stream video sample.
    //
    samples[0].Start = rtStart;
    samples[0].End   = rtStop;

    FillDefaultDXVAFormat(samples[0].SampleFormat, DXVA2_SampleProgressiveFrame);

    samples[0].SrcSurface = pSrc;
    samples[0].SrcRect = SrcRect;
    samples[0].DstRect = DstRect;

    samples[0].PlanarAlpha = DXVA2_Fixed32OpaqueAlpha();

    HRESULT hr = m_pVPDevice->VideoProcessBlt(pDst, &blt, samples, 1, NULL);

    return hr;
}
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);
}
Example #5
0
HRESULT DS2Plugin::redirectSetRenderTarget(DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget) {
	// At this point, we can grab the z (RT1) and normal (RT0) RTs
	if(RenderTargetIndex == 1 && pRenderTarget == NULL && zBufferSurf == NULL) {
		SAFERELEASE(zBufferSurf);
		SAFERELEASE(normalSurf);
		d3ddev->GetRenderTarget(1, &zBufferSurf);
		d3ddev->GetRenderTarget(0, &normalSurf);
	}
	// If previous RT was D3DFMT_A16B16G16R16F, store RT
	else if(((doAO && ssao) || (doBloom && bloom)) && !aoDone && !hdrRT && RenderTargetIndex == 0 && zBufferSurf != NULL && defaultState != NULL) {
		IDirect3DSurface9* prevRT = NULL;
		d3ddev->GetRenderTarget(0, &prevRT);
		if(prevRT) {
			D3DSURFACE_DESC desc;
			prevRT->GetDesc(&desc);
			if(desc.Format == D3DFMT_A16B16G16R16F && (desc.Width == manager.getRenderWidth() || desc.Height == manager.getRenderHeight()) && !aoDone) {
				// store RT for later use
				hdrRT = prevRT;
			}
			else {
				SAFERELEASE(prevRT);
			}
		}
	}
	return GamePlugin::redirectSetRenderTarget(RenderTargetIndex, pRenderTarget);
}
Example #6
0
HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, bool& Minimised, int& Width, int& Height, D3DFORMAT Format)
{
    IDirect3DSurface9* RenderTarget = nullptr;
    IDirect3DSurface9* DestTarget = nullptr;
    HRESULT result = Device->GetRenderTarget(0, &RenderTarget);

    if (result == S_OK)
    {
        if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN)
        {
            D3DSURFACE_DESC descriptor = {};
            RenderTarget->GetDesc(&descriptor);
            Width = descriptor.Width;
            Height = descriptor.Height;
            Format = descriptor.Format;
        }

        HDC DC = nullptr;
        RenderTarget->GetDC(&DC);
        Minimised = IsIconic(WindowFromDC(DC));
        RenderTarget->ReleaseDC(DC);
        result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr);
        result = Device->GetRenderTargetData(RenderTarget, DestTarget);

        D3DLOCKED_RECT rect;
        DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY);
        memcpy(Buffer, rect.pBits, Width * Height * 4);
        DestTarget->UnlockRect();
    }

    SafeRelease(RenderTarget);
    SafeRelease(DestTarget);
    return result;
}
D3D9ProxySwapChain::D3D9ProxySwapChain(IDirect3DSwapChain9* pActualSwapChain, D3DProxyDevice* pWrappedOwningDevice, bool isAdditionalChain) : 
		BaseDirect3DSwapChain9(pActualSwapChain, pWrappedOwningDevice, isAdditionalChain),
		m_backBuffers()
{
	// Get creation parameters for backbuffers.
	D3DPRESENT_PARAMETERS params;
	pActualSwapChain->GetPresentParameters(&params);

	UINT bbCount = params.BackBufferCount;
	if (bbCount == 0)
		bbCount = 1;
	m_backBuffers.reserve(bbCount);

	IDirect3DSurface9* pTempActualBackBuffer;
	pActualSwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pTempActualBackBuffer);
		
	D3DSURFACE_DESC backDesc;
	pTempActualBackBuffer->GetDesc(&backDesc);
	pTempActualBackBuffer->Release();
	pTempActualBackBuffer = NULL;

	// Create stereo backbuffers to use in place of actual backbuffers
	for (UINT i = 0; i < bbCount; i++) {
		IDirect3DSurface9* pTemp;
		pWrappedOwningDevice->CreateRenderTarget(backDesc.Width, backDesc.Height, backDesc.Format, backDesc.MultiSampleType, backDesc.MultiSampleQuality, false, &pTemp, NULL, true);
		m_backBuffers.push_back(static_cast<D3D9ProxySurface*>(pTemp));
	}
}
Example #8
0
void RSManager::DoLimbo()
{
	if (!(mainRT && zSurf && doLimbo && limbo)) return;

	IDirect3DSurface9 *oldRenderTarget;
	d3ddev->GetRenderTarget(0, &oldRenderTarget);
	if (oldRenderTarget == mainRT) {
		// final renderbuffer has to be from texture, just making sure here
		if (IDirect3DTexture9* tex = getSurfTexture(oldRenderTarget)) {
			// check size just to make even more sure
			D3DSURFACE_DESC desc;
			oldRenderTarget->GetDesc(&desc);
			if (desc.Width == Settings::get().getRenderWidth() && desc.Height == Settings::get().getRenderHeight()) {
				IDirect3DTexture9 *zTex = getSurfTexture(zSurf);

				storeRenderState();
				d3ddev->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
				d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
				d3ddev->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_BLUE);

				/// Draw zbuffer
				limbo->go(zTex, oldRenderTarget, limboZNear, limboZFar);
				SDLOG(0, "ZNear: %g, ZFar: %g\n", limboZNear, limboZFar);
				//d3ddev->StretchRect(zSurf, NULL, oldRenderTarget, NULL, D3DTEXF_NONE);

				restoreRenderState();
				zTex->Release();
			}
			tex->Release();
		}
	}
	oldRenderTarget->Release();
}
Example #9
0
void RenderController::CreateDepthBuffers()
{
	IDirect3DSurface9 *pOldDS = NULL;
	D3DSURFACE_DESC desc;
	Renderer::theDevicePtr->GetDepthStencilSurface( &pOldDS );
	pOldDS->GetDesc(&desc);
	pOldDS->Release();

	Renderer::theDevicePtr->CreateDepthStencilSurface( thePointShadowSize, 
		thePointShadowSize, desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, 
		&m_pPointDSShadow, NULL );

	Renderer::theDevicePtr->CreateDepthStencilSurface( theDirectionalShadowSize, 
		theDirectionalShadowSize, desc.Format,D3DMULTISAMPLE_NONE, 0, TRUE, 
		&m_pDirectionalDSShadow, NULL );

	m_SpotDepths.Create(theSpotShadowSize, theSpotShadowSize);
	Renderer::theDevicePtr->CreateDepthStencilSurface( theSpotShadowSize, 
		theSpotShadowSize, desc.Format,D3DMULTISAMPLE_NONE, 0, TRUE, 
		&m_pSpotDSShadow, NULL );

	Renderer::theDevicePtr->CreateDepthStencilSurface(desc.Width,
		desc.Height, desc.Format,
		D3DMULTISAMPLE_NONE, 0, TRUE, &m_pDSGBuffers, NULL );
}
Example #10
0
bool CDVDCodecUtils::CopyDXVA2Picture(YV12Image* pImage, DVDVideoPicture *pSrc)
{
#ifdef HAS_DX
  // TODO: Optimize this later using shaders/swscale/etc.
  switch (pSrc->extended_format)
  {
    case MAKEFOURCC('N','V','1','2'):
      {
        IDirect3DSurface9* surface = (IDirect3DSurface9*)pSrc->data[3];

        D3DLOCKED_RECT rectangle;
        if (FAILED(surface->LockRect(&rectangle, NULL, 0)))
          return false;

        // Copy Y
        uint8_t* bits = (uint8_t*)(rectangle.pBits);
        uint8_t* d = pImage->plane[0];
        for (unsigned y = 0; y < pSrc->iHeight; y++)
        {
          memcpy(d, bits, pSrc->iWidth);
          bits += rectangle.Pitch;
          d += pImage->stride[0];
        }

        D3DSURFACE_DESC desc;
        if (FAILED(surface->GetDesc(&desc)))
          return false;
        
        // Copy packed UV
        uint8_t *s_uv = ((uint8_t*)(rectangle.pBits)) + desc.Height * rectangle.Pitch;
        uint8_t *d_uv = pImage->plane[1];
        for (unsigned y = 0; y < pSrc->iHeight >> 1; y++)
        {
          memcpy(d_uv, s_uv, pSrc->iWidth);
          s_uv += rectangle.Pitch;
          d_uv += pImage->stride[1];
        }

        if (FAILED(surface->UnlockRect()))
          return false;
      }
      return true;

    // Future...
    /*case MAKEFOURCC('Y','V','1','2'):
      return true;*/

    /*case MAKEFOURCC('Y','V','V','Y'):
      return true;*/

    default:
      CLog::Log(LOGWARNING, "CDVDCodecUtils::CopyDXVA2Picture colorspace not supported");
      return false;
  }
#endif
  return false;
}
Example #11
0
bool D3DFB::WipeStartScreen(int type)
{
	IDirect3DSurface9 *tsurf;
	D3DSURFACE_DESC desc;

	if (!Accel2D)
	{
		return Super::WipeStartScreen(type);
	}

	switch (type)
	{
	case wipe_Melt:
		ScreenWipe = new Wiper_Melt;
		break;

	case wipe_Burn:
		ScreenWipe = new Wiper_Burn(this);
		break;

	case wipe_Fade:
		ScreenWipe = new Wiper_Crossfade;
		break;

	default:
		return false;
	}

	InitialWipeScreen = GetCurrentScreen();

	// Create another texture to copy the final wipe screen to so
	// we can still gamma correct the wipe. Since this is just for
	// gamma correction, it's okay to fail (though not desirable.)
	if (PixelDoubling || (GammaFixerShader != NULL && Windowed))
	{
		if (SUCCEEDED(TempRenderTexture->GetSurfaceLevel(0, &tsurf)))
		{
			if (FAILED(tsurf->GetDesc(&desc)) ||
				FAILED(D3DDevice->CreateTexture(desc.Width, desc.Height,
					1, D3DUSAGE_RENDERTARGET, desc.Format, D3DPOOL_DEFAULT,
					&FinalWipeScreen, NULL)))
			{
				FinalWipeScreen = TempRenderTexture;
			}
			tsurf->Release();
		}
	}
	else
	{
		FinalWipeScreen = TempRenderTexture;
	}

	// Make even fullscreen model render to the TempRenderTexture, so
	// we can have a copy of the new screen readily available.
	GatheringWipeScreen = true;
	return true;
}
Example #12
0
//! Regenerates the mip map levels of the texture. Useful after locking and
//! modifying the texture
void CD3D9Texture::regenerateMipMapLevels(void* mipmapData)
{
	if (mipmapData)
	{
		core::dimension2du size = TextureSize;
		u32 level=0;
		do
		{
			if (size.Width>1)
				size.Width /=2;
			if (size.Height>1)
				size.Height /=2;
			++level;
			IDirect3DSurface9* mipSurface = 0;
			HRESULT hr = Texture->GetSurfaceLevel(level, &mipSurface);
			if (FAILED(hr) || !mipSurface)
			{
				os::Printer::log("Could not get mipmap level", ELL_WARNING);
				return;
			}
			D3DSURFACE_DESC mipDesc;
			mipSurface->GetDesc(&mipDesc);
			D3DLOCKED_RECT miplr;

			// lock mipmap surface
			if (FAILED(mipSurface->LockRect(&miplr, NULL, 0)))
			{
				mipSurface->Release();
				os::Printer::log("Could not lock texture", ELL_WARNING);
				return;
			}

			memcpy(miplr.pBits, mipmapData, size.getArea()*getPitch()/TextureSize.Width);
			mipmapData = (u8*)mipmapData+size.getArea()*getPitch()/TextureSize.Width;
			// unlock
			mipSurface->UnlockRect();
			// release
			mipSurface->Release();
		} while (size.Width != 1 || size.Height != 1);
	}
	else if (HasMipMaps)
	{
		// create mip maps.
#ifdef _IRR_USE_D3DXFilterTexture_
		// The D3DXFilterTexture function seems to get linked wrong when
		// compiling with both D3D8 and 9, causing it not to work in the D3D9 device.
		// So mipmapgeneration is replaced with my own bad generation
		HRESULT hr  = D3DXFilterTexture(Texture, NULL, D3DX_DEFAULT, D3DX_DEFAULT);
		if (FAILED(hr))
#endif
		createMipMaps();
	}
}
Example #13
0
void GFXPCD3D9TextureTarget::attachTexture( RenderSlot slot, GFXCubemap *tex, U32 face, U32 mipLevel/*=0*/ )
{
   GFXDEBUGEVENT_SCOPE( GFXPCD3D9TextureTarget_attachTexture_Cubemap, ColorI::RED );

   AssertFatal(slot < MaxRenderSlotId, "GFXPCD3D9TextureTarget::attachTexture - out of range slot.");

   // Mark state as dirty so device can know to update.
   invalidateState();

   // Release what we had, it's definitely going to change.
   mDevice->destroyD3DResource( mTargets[slot] ); // SAFE_RELEASE
   mTargets[slot] = NULL;
   mResolveTargets[slot] = NULL;

   // Cast the texture object to D3D...
   AssertFatal(!tex || dynamic_cast<GFXD3D9Cubemap*>(tex), 
      "GFXD3DTextureTarget::attachTexture - invalid cubemap object.");

   GFXD3D9Cubemap *cube = static_cast<GFXD3D9Cubemap*>(tex);

   if(slot == Color0)
   {
      mTargetSize = Point2I::Zero;
      mTargetFormat = GFXFormatR8G8B8A8;
   }

   // Are we clearing?
   if(!tex)
   {
      // Yup - just exit, it'll stay NULL.      
      return;
   }

   D3D9Assert(cube->mCubeTex->GetCubeMapSurface( (D3DCUBEMAP_FACES)face, mipLevel, &mTargets[slot] ),
      "GFXD3DTextureTarget::attachTexture - could not get surface level for the passed texture!");

   // Update surface size
   if(slot == Color0)
   {
      IDirect3DSurface9 *surface = mTargets[Color0];
      if ( surface )
      {
         D3DSURFACE_DESC sd;
         surface->GetDesc(&sd);
         mTargetSize = Point2I(sd.Width, sd.Height);

         S32 format = sd.Format;
         GFXREVERSE_LOOKUP( GFXD3D9TextureFormat, GFXFormat, format );
         mTargetFormat = (GFXFormat)format;
      }
   }
}
Example #14
0
void copy(IDirect3DDevice9 *device) {
    HRESULT hr;

    // A dummy copy over here.
    IDirect3DSurface9 *colorSurface = NULL;
    V(colorTex->GetSurfaceLevel(0, &colorSurface));
    D3DSURFACE_DESC desc;
    colorSurface->GetDesc(&desc);
    const D3DSURFACE_DESC *backbufferDesc = DXUTGetD3D9BackBufferSurfaceDesc();
    RECT rect = {0, 0, min(desc.Width, backbufferDesc->Width), min(desc.Height, backbufferDesc->Height)};
    V(device->StretchRect(colorSurface, &rect, backbufferSurface, &rect, D3DTEXF_POINT));
    SAFE_RELEASE(colorSurface);
}
			virtual void OnDistorting()
			{
				IDirect3DSurface9* targetSurface = nullptr;
				IDirect3DSurface9* texSurface = nullptr;
				HRESULT hr = S_OK;

				// レンダーターゲットを取得
				hr = g_D3d9Device->GetRenderTarget( 0, &targetSurface );
				if( FAILED( hr ) ){
					return;
				}
				
				// レンダーターゲットの情報を取得
				D3DSURFACE_DESC targetSurfaceDesc;
				targetSurface->GetDesc( &targetSurfaceDesc );
				
				// シザリング範囲を取得
				RECT scissorRect;
				g_D3d9Device->GetScissorRect( &scissorRect );
				
				// 描画範囲を計算
				uint32_t width = scissorRect.right - scissorRect.left;
				uint32_t height = scissorRect.bottom - scissorRect.top;

				// 保持テクスチャとフォーマットが異なればテクスチャを作り直す
				if( backGroundTexture == nullptr || 
					backGroundTextureWidth != width || 
					backGroundTextureHeight != height || 
					backGroundTextureFormat != targetSurfaceDesc.Format )
				{
					PrepareTexture( width, height, targetSurfaceDesc.Format );
				}
				
				// コピーするためのサーフェスを取得
				hr = backGroundTexture->GetSurfaceLevel( 0, &texSurface );
				if( FAILED( hr ) ){
					return;
				}
				
				// サーフェス間コピー
				hr = g_D3d9Device->StretchRect( targetSurface, &scissorRect, texSurface, NULL, D3DTEXF_NONE);
				if( FAILED( hr ) ){
					return;
				}
				
				// 取得したサーフェスの参照カウンタを下げる
				ES_SAFE_RELEASE( texSurface );
				ES_SAFE_RELEASE( targetSurface );

				renderer->SetBackground( backGroundTexture );
			}
Example #16
0
//! creates a surface from the file
Image* ImageLoaderX::LoadImageFromFile(FileReader* file)
{
	IDirect3DSurface9* pSurf = NULL;
	D3DXIMAGE_INFO info;
	D3DXGetImageInfoFromFileA(file->GetFileName(), &info);
	m_pID3DDevice->CreateOffscreenPlainSurface(info.Width, info.Height, info.Format, D3DPOOL_SCRATCH, &pSurf, NULL);
	D3DXLoadSurfaceFromFileA(pSurf, NULL, NULL, file->GetFileName(), NULL, D3DX_FILTER_NONE, 0, &info);

	Image* image = 0;

	if (pSurf)
	{
		// create surface
		D3DLOCKED_RECT lockRect;
		D3DSURFACE_DESC desc;
		switch (info.Format)
		{
		case D3DFMT_A8R8G8B8:
		case D3DFMT_X8R8G8B8:
			pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY);
			image = new Image(ECF_A8R8G8B8, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE);
			break;
		case D3DFMT_R8G8B8:
			pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY);
			pSurf->GetDesc(&desc);
			image = new Image(ECF_R8G8B8, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE);
			break;
		case D3DFMT_A1R5G5B5:
		case D3DFMT_X1R5G5B5:
			pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY);
			image = new Image(ECF_A1R5G5B5, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE);
			break;
		case D3DFMT_R5G6B5:
			pSurf->LockRect(&lockRect, NULL, D3DLOCK_READONLY);
			image = new Image(ECF_R5G6B5, dimension2d<s32>(info.Width, info.Height), lockRect.pBits, FALSE);
			break;
		default:
			Printer::Log("No matched image format", ELL_ERROR);
			break;
		}
	}
	else
	{
		Printer::Log("D3DXLoadSuface failed", ELL_ERROR);
		return NULL;
	}

	pSurf->Release();

	return image;
}
static bool CopyRenderTargetToBackground()
{
	bool ret = false;

	LPDIRECT3DDEVICE9 device = (LPDIRECT3DDEVICE9)GetUseDirect3DDevice9();
	if (device == NULL) return nullptr;

	HRESULT hr;
	IDirect3DSurface9* tempRender = nullptr;
	IDirect3DSurface9* tempDepth = nullptr;

	hr = device->GetRenderTarget(0, &tempRender);
	if (FAILED(hr))
	{
		goto Exit;
	}

	hr = device->GetDepthStencilSurface(&tempDepth);
	if (FAILED(hr))
	{
		goto Exit;
	}

	device->SetRenderTarget(0, g_dx9_backgroundSurface);
	device->SetDepthStencilSurface(nullptr);

	D3DSURFACE_DESC desc;
	tempRender->GetDesc(&desc);
	const bool isSame = (desc.Width == g_backgroundWidth && desc.Height == g_backgroundHeight);

	device->StretchRect(
		tempRender,
		nullptr,
		g_dx9_backgroundSurface,
		nullptr,
		(isSame ? D3DTEXF_POINT : D3DTEXF_LINEAR)
		);

	device->SetRenderTarget(0, tempRender);
	device->SetDepthStencilSurface(tempDepth);
	
	ret = true;

Exit:;
	ES_SAFE_RELEASE(tempRender);
	ES_SAFE_RELEASE(tempDepth);

	return ret;
}
Example #18
0
void CD3D9Texture::createRenderTarget()
{
	TextureSize.Width = getTextureSizeFromImageSize(TextureSize.Width);
	TextureSize.Height = getTextureSizeFromImageSize(TextureSize.Height);

	// get backbuffer format to create the render target in the
	// same format

	IDirect3DSurface9* bb;
	D3DFORMAT d3DFormat = D3DFMT_A8R8G8B8;

	if (!FAILED(Device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bb)))
	{
		D3DSURFACE_DESC desc;
		bb->GetDesc(&desc);
		d3DFormat = desc.Format;

		if (d3DFormat == D3DFMT_X8R8G8B8)
			d3DFormat = D3DFMT_A8R8G8B8;

		bb->Release();
	}
	else
	{
		os::Printer::log("Could not create RenderTarget texture: could not get BackBuffer.",
			ELL_WARNING);
		return;
	}

	// create texture
	HRESULT hr;

	hr = Device->CreateTexture(
		TextureSize.Width,
		TextureSize.Height,
		1, // mip map level count, we don't want mipmaps here
		D3DUSAGE_RENDERTARGET,
		d3DFormat,
		D3DPOOL_DEFAULT,
		&Texture,
		NULL);

	// get irrlicht format from D3D format
	ColorFormat = getColorFormatFromD3DFormat(d3DFormat);

	if (FAILED(hr))
		os::Printer::log("Could not create render target texture");
}
Example #19
0
HRESULT ccUnit::loadUnit()
{
	//
	// Create surfaces.
	//

	HRESULT hr;
	IDirect3DSurface9 *ppBackBuffer;
	if (SUCCEEDED(hr = m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &ppBackBuffer)))
	{
		D3DSURFACE_DESC d3dsDesc;
		ppBackBuffer->GetDesc(&d3dsDesc);		
				
		char fileName[] = "..//units//armbulldog.bmp";
		
		if (FAILED(hr = D3DXGetImageInfoFromFile(
			fileName,
			&m_srcInfo)))
			return hr;

		m_unitSize.cx = m_srcInfo.Width;
		m_unitSize.cy = m_srcInfo.Height;

		m_unitRect.right  += m_unitSize.cx;
		m_unitRect.bottom += m_unitSize.cy;
				
		if (FAILED(hr = m_pd3dDevice->CreateOffscreenPlainSurface(
			m_srcInfo.Width, m_srcInfo.Height, d3dsDesc.Format, D3DPOOL_DEFAULT, &m_pUnitImage, NULL)))
			return hr;				

		if (FAILED(hr = D3DXLoadSurfaceFromFile(          
			m_pUnitImage,
			NULL,
			NULL,
			fileName,
			NULL,
			D3DX_FILTER_NONE,
			0x7B97FF,
			&m_srcInfo
		)))
			return hr;
		
	}
	SAFE_RELEASE(ppBackBuffer);

	return S_OK;
}
Example #20
0
HRESULT ccTileMap::loadTileData(FILE *stream)
{
    if(fseek( stream, m_header.PTRTileGfx, SEEK_SET))
        return E_FAIL;

    int tileDataSize = m_header.Tiles*1024;
    unsigned char *tileLoadData = new unsigned char[tileDataSize];
    ZeroMemory(tileLoadData, tileDataSize );

    if(fread(tileLoadData, tileDataSize, 1, stream) == 0 || ferror( stream ))
        return E_FAIL;

    //
    // Create surfaces.
    //

    HRESULT hr;
    IDirect3DSurface9 *ppBackBuffer;
    if (SUCCEEDED(hr = m_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &ppBackBuffer)))
    {
        D3DSURFACE_DESC d3dsDesc;
        ppBackBuffer->GetDesc(&d3dsDesc);

        m_pTileSurface = new LPDIRECT3DSURFACE9[m_header.Tiles];

        RECT srcRect;
        srcRect.left   = srcRect.top	 = 0;
        srcRect.right  = m_tileWidth - 1;
        srcRect.bottom = m_tileHeight - 1;

        for(int i=0; i<m_header.Tiles; i++)
        {
            if (FAILED(hr = m_pd3dDevice->CreateOffscreenPlainSurface(
                                m_tileWidth, m_tileHeight, d3dsDesc.Format, D3DPOOL_DEFAULT, &m_pTileSurface[i], NULL)))
                return hr;

            if (FAILED(hr = D3DXLoadSurfaceFromMemory(
                                m_pTileSurface[i], NULL, NULL, (tileLoadData+(i*1024)), D3DFMT_P8, m_tileWidth, taPalette, &srcRect, D3DX_DEFAULT , 0)))
            {
                return hr;
            }
        }
    }

    SAFE_RELEASE(ppBackBuffer);
    return S_OK;
}
Example #21
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
static bool CopyRenderTargetToBackground()
{
	bool ret = false;

	HRESULT hr;
	IDirect3DSurface9* tempRender = nullptr;
	IDirect3DSurface9* tempDepth = nullptr;

	hr = g_d3d_device->GetRenderTarget(0, &tempRender);
	if (FAILED(hr))
	{
		goto Exit;
	}

	hr = g_d3d_device->GetDepthStencilSurface(&tempDepth);
	if (FAILED(hr))
	{
		goto Exit;
	}

	g_d3d_device->SetRenderTarget(0, g_backgroundSurface);
	g_d3d_device->SetDepthStencilSurface(nullptr);

	D3DSURFACE_DESC desc;
	tempRender->GetDesc(&desc);
	
	g_d3d_device->StretchRect(
		tempRender,
		nullptr,
		g_backgroundSurface,
		nullptr,
		D3DTEXF_POINT
		);

	g_d3d_device->SetRenderTarget(0, tempRender);
	g_d3d_device->SetDepthStencilSurface(tempDepth);
	
	ret = true;

Exit:;
	ES_SAFE_RELEASE(tempRender);
	ES_SAFE_RELEASE(tempDepth);

	return ret;
}
	void D3D9PixelBuffer::bind( uint32 face, uint32 mip, IDirect3DCubeTexture9* texTarget )
	{
		unbind();
		mMipIndex = mip;
		mCubeTarget = texTarget;
		switch(face)
		{
		case 0:
			mFaceIndex = D3DCUBEMAP_FACE_POSITIVE_X;
			break;
		case 1:
			mFaceIndex = D3DCUBEMAP_FACE_NEGATIVE_X;
			break;
		case 2:
			mFaceIndex = D3DCUBEMAP_FACE_POSITIVE_Y;
			break;
		case 3:
			mFaceIndex = D3DCUBEMAP_FACE_NEGATIVE_Y;
			break;
		case 4:
			mFaceIndex = D3DCUBEMAP_FACE_POSITIVE_Z;
			break;
		case 5:
			mFaceIndex = D3DCUBEMAP_FACE_NEGATIVE_Z;
			break;
		}
		IDirect3DSurface9* suf = NULL;
		if (FAILED(texTarget->GetCubeMapSurface(mFaceIndex,mip,&suf)))
		{
			unbind();
			return;
		}
		D3DSURFACE_DESC desc;
		suf->GetDesc(&desc);
		mWidth	= desc.Width;
		mHeight	= desc.Height;
		mDepth	= 1;
		mFormat	= D3D9Translator::getPixelFormat(desc.Format);
		mRowPitch = mWidth * DPixelFormatTool::getFormatBytes(mFormat);
		mSlicePitch = mHeight * mRowPitch;
		mByteSize	= mSlicePitch;
		ReleaseCOM(suf);
	}
Example #23
0
void AmjuGLDX9::GetScreenshot(unsigned char* buffer, int w, int h)
{
  AMJU_CALL_STACK;

  IDirect3DSurface9* pSurface = 0;

  dd->GetBackBuffer(
    0, // UINT  iSwapChain,
    0, // UINT BackBuffer,
    D3DBACKBUFFER_TYPE_MONO, // D3DBACKBUFFER_TYPE Type,
    &pSurface); //IDirect3DSurface9 ** ppBackBuffer

  D3DSURFACE_DESC desc;
  pSurface->GetDesc(&desc);

  D3DLOCKED_RECT lockedRect;
  HRESULT hr = pSurface->LockRect(&lockedRect, NULL, D3DLOCK_READONLY);
  if (SUCCEEDED(hr))
  {
    // Do we know if we are windowed or not ? We have to crop the window edges if so.

    // Copy surface into buffer. 
    // NB Buffer format is R8G8B8
    //h = MIN(h, desc.Height);
    //w = MIN(w, desc.Width);
    for (int i = 0; i < h; i++)
    {
      unsigned char* rowStart = (unsigned char*)lockedRect.pBits + i * lockedRect.Pitch;
      unsigned char* bufStart = buffer + i * w * 3;
      for (int j = 0; j < w; j++)
      {
        bufStart[0] = rowStart[0]; 
        bufStart[1] = rowStart[1]; 
        bufStart[2] = rowStart[2];
        bufStart += 3;
        rowStart += 4;
      }
    }
  }

  pSurface->UnlockRect(); // even if LockRect failed ?
  pSurface->Release(); // ?
}
Example #24
0
D3DSURFACE_DESC const
sge::d3d9::surfacefuncs::get_desc(
	IDirect3DSurface9 &_surface
)
{
	D3DSURFACE_DESC ret;

	if(
		_surface.GetDesc(
			&ret
		)
		!= D3D_OK
	)
		throw sge::renderer::exception(
			FCPPT_TEXT("Surface::GetDesc() failed!")
		);

	return ret;
}
void VideoBusWinD3D::init(UINT32 width, UINT32 height)
{
	release();

	if (this->videoOutputDevice != NULL) {
		FLOAT halfTexelWidth = (1.0 / width) * 0.5;
		FLOAT halfTexelHeight = (1.0 / height) * 0.5;

		videoOutputDevice->SetSamplerState(0,D3DSAMP_MINFILTER,D3DTEXF_POINT);
		videoOutputDevice->SetSamplerState(0,D3DSAMP_MAGFILTER,D3DTEXF_POINT);

		//obtain the surface we desire
		videoOutputDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8,
										 D3DPOOL_DEFAULT, &combinedTexture, NULL);

		combinedTexture->LockRect(0, &combinedBufferLock, NULL, D3DLOCK_DISCARD |  D3DLOCK_NOSYSLOCK);
		memset(combinedBufferLock.pBits, 0xFFFFFFFF, sizeof(UINT32) * width * height);
		combinedTexture->UnlockRect(0);

		//create our vertex buffer
		IDirect3DSurface9* bb;
		videoOutputDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &bb);
		D3DSURFACE_DESC desc;
		bb->GetDesc(&desc);
		videoOutputDevice->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &vertexBuffer, NULL);
		// x, y, z, rhw, tu, tv
		CUSTOMVERTEX vertices[] =
		{
			{   0.0f,                0.0f,              0.0f, 1.0f, 0.0f - halfTexelWidth, 0.0f - halfTexelHeight, },
			{   (FLOAT)desc.Width,   0.0f,              0.0f, 1.0f, 1.0f - halfTexelWidth, 0.0f - halfTexelHeight, },
			{   0.0f,               (FLOAT)desc.Height, 0.0f, 1.0f, 0.0f - halfTexelWidth, 1.0f - halfTexelHeight, },
			{   (FLOAT)desc.Width,  (FLOAT)desc.Height, 0.0f, 1.0f, 1.0f - halfTexelWidth, 1.0f - halfTexelHeight, },
		};
		bb->Release();
		void* pVertices;
		vertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0);
		memcpy(pVertices, vertices, sizeof(vertices));
		vertexBuffer->Unlock();
	}

	// initialize the pixelBuffer
	VideoBus::init(width, height);
}
static int
D3D9_get_resolution(IDirect3DDevice9 *pDevice) {
	HRESULT hr;
	D3DSURFACE_DESC desc;
	IDirect3DSurface9 *renderSurface;
	static int initialized = 0;
	//
	if(initialized > 0) {
		return 0;
	}
	// get current resolution
	hr = pDevice->GetRenderTarget(0, &renderSurface);
	if(!renderSurface || FAILED(hr))
		return -1;
	renderSurface->GetDesc(&desc);
	renderSurface->Release();
	//
	if(ga_hook_get_resolution(desc.Width, desc.Height) < 0)
		return -1;
	initialized = 1;
	return 0;
}
Example #27
0
void D3D9Sprite::GenerateBackup()
{
	if (m_pBackupTexture)
	{
		m_pBackupTexture->Release();
		m_pBackupTexture = NULL;
	}
	if (m_type == Sprite::T_NOT_LOADED)
		return;

	IDirect3DTexture9* pBackup = NULL;
	IDirect3DSurface9* pBackupSurf = NULL;

	IDirect3DTexture9* pActualTexture;
	try
	{
		pActualTexture = boost::any_cast<IDirect3DTexture9*>(m_texture->GetTextureObject());
	}
	catch (const boost::bad_any_cast &)
	{
		ShowMessage(L"D3D9Sprite::GenerateBackup Invalid texture pointer");
		return;
	}
	IDirect3DSurface9* pActualSurface = NULL;
	D3DSURFACE_DESC desc;

	pActualTexture->GetSurfaceLevel(0, &pActualSurface);
	pActualSurface->GetDesc(&desc);

	m_pDevice->CreateTexture(desc.Width, desc.Height,
		1, 0, desc.Format, D3DPOOL_SYSTEMMEM, &pBackup, NULL);
	pBackup->GetSurfaceLevel(0, &pBackupSurf);

	m_pDevice->GetRenderTargetData(pActualSurface, pBackupSurf);

	pActualSurface->Release();
	pBackupSurf->Release();
	m_pBackupTexture = pBackup;
}
Example #28
0
void DCRenderer::BeginRender()
{
    BMPostFXRenderer::GetInstance()->StoreBackBuffer();

    //set lighting rt
	IDirect3DSurface9* surface;
	HRESULT result = mLightingRT->GetSurfaceLevel(0, &surface);
	assert(SUCCEEDED(result));

	result = DEVICEPTR->SetRenderTarget(0, surface);
	assert(SUCCEEDED(result));

    DEVICEPTR->GetDepthStencilSurface(&surface);
    D3DSURFACE_DESC pDesc;
    surface->GetDesc(&pDesc);
    //std::string str("size");
    //str += (char)pDesc.Width;
    //str += (char)pDesc.Height;
    //LogToDebug(str.c_str());
    aa = pDesc.Width;
    bb = pDesc.Height;
}
Example #29
0
//------------------------------------------------------------------------------
// _createRenderTarget
//------------------------------------------------------------------------------
void cDirectX9Texture::_createRenderTarget()
{
	mkDimension.dx = (i2d)getPow2Dimension(mkDimension.dx);
	mkDimension.dy = (i2d)getPow2Dimension(mkDimension.dy);

	IDirect3DSurface9*	bbuff = 0;
	if( SUCCEEDED( gpkDirect3DDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &bbuff ) ) )
	{
		D3DSURFACE_DESC desc;
		bbuff->GetDesc(&desc);
		D3DFORMAT d3dformat = desc.Format;

		if ( d3dformat == D3DFMT_X8R8G8B8 )
			d3dformat = D3DFMT_A8R8G8B8;

		bbuff->Release();

		if( FAILED( gpkDirect3DDevice->CreateTexture(	mkDimension.dx, mkDimension.dy, 1, D3DUSAGE_RENDERTARGET,	d3dformat, D3DPOOL_DEFAULT, &mpkTexture, 0 ) ) )
			ReportBug( ERROR4, "_createRenderTarget" );
	}
	else
		ReportBug( ERROR5, "_createRenderTarget" );
}
Example #30
0
bool D3D9Texture::CreateRenderTarget(VideoWeakPtr video, const unsigned int width, const unsigned int height,
									 const GS_TARGET_FORMAT fmt)
{
	m_video = video;
	GetInternalData();
	IDirect3DTexture9 *pTexture = NULL;

	m_profile.mask = 0x0;
	m_profile.nMipMaps = 1;
	m_texType = TT_RENDER_TARGET;

	const DWORD dwUsage = D3DUSAGE_RENDERTARGET;
	if (width <= 0 || height <= 0)
	{
		std::wstringstream ss;
		ss << L"Couldn't create the render surface - D3D9Texture::LoadTexture" << std::endl;
		ShowMessage(ss, GSMT_ERROR);
		return false;
	}

	IDirect3DSurface9 *pBackBuffer = NULL;
	D3DSURFACE_DESC surfDesc;
	m_pDevice->GetRenderTarget(0, &pBackBuffer);
	pBackBuffer->GetDesc(&surfDesc);
	pBackBuffer->Release();

	m_pDevice->CreateTexture(width, height, 1,
						   dwUsage, (fmt == GSTF_ARGB) ? D3DFMT_A8R8G8B8 : surfDesc.Format,
						   D3DPOOL_DEFAULT, &pTexture, NULL);

	m_profile.width = width;
	m_profile.height = height;
	m_profile.originalWidth = m_profile.width;
	m_profile.originalHeight = m_profile.height;
	m_pTexture = pTexture;
	return true;
}