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 #2
0
	virtual void OnDistorting()
	{
		IDirect3DSurface9* targetSurface = nullptr;
		IDirect3DSurface9* texSurface = nullptr;
		HRESULT hr = S_OK;

		hr = texture->GetSurfaceLevel( 0, &texSurface );
		assert(SUCCEEDED(hr));

		hr = device->GetRenderTarget( 0, &targetSurface );
		assert(SUCCEEDED(hr));

		hr = device->StretchRect( targetSurface, NULL, texSurface, NULL, D3DTEXF_NONE);
		assert(SUCCEEDED(hr));
		
		ES_SAFE_RELEASE( texSurface );
		ES_SAFE_RELEASE( targetSurface );

		renderer->SetBackground( texture );
	}