Esempio n. 1
0
	bool OnDistorting()
	{
		if (g_backgroundTexture == NULL)
		{
			((EffekseerRendererDX9::Renderer*)g_renderer)->SetBackground(NULL);
			return false;
		}

		CopyRenderTargetToBackground();
		((EffekseerRendererDX9::Renderer*)g_renderer)->SetBackground(g_backgroundTexture);
		return true;
	}
static void Effekseer_Distort()
{
	LPDIRECT3DDEVICE9 dx9_device = (LPDIRECT3DDEVICE9)GetUseDirect3DDevice9();
	ID3D11Device* dx11_device = (ID3D11Device*)GetUseDirect3D11Device();
	ID3D11DeviceContext* dx11_device_context = (ID3D11DeviceContext*)GetUseDirect3D11DeviceContext();

	if (dx9_device != nullptr)
	{
		if (GetUseDirect3DDevice9() == NULL) return;
		auto renderer2d = (EffekseerRendererDX9::Renderer*)g_renderer2d;
		auto renderer3d = (EffekseerRendererDX9::Renderer*)g_renderer3d;

		if (g_dx9_backgroundTexture == NULL)
		{
			renderer2d->SetBackground(NULL);
			renderer3d->SetBackground(NULL);
			return;
		}

		CopyRenderTargetToBackground();
		renderer2d->SetBackground(g_dx9_backgroundTexture);
		renderer3d->SetBackground(g_dx9_backgroundTexture);
	}

	if (dx11_device != nullptr)
	{
		auto renderer2d = (EffekseerRendererDX11::Renderer*)g_renderer2d;
		auto renderer3d = (EffekseerRendererDX11::Renderer*)g_renderer3d;

		if (g_dx11_backGroundTexture == nullptr)
		{
			renderer2d->SetBackground(NULL);
			renderer3d->SetBackground(NULL);
			return;
		}

		HRESULT hr = S_OK;

		ID3D11RenderTargetView* renderTargetView = nullptr;
		ID3D11Texture2D* renderTexture = nullptr;

		dx11_device_context->OMGetRenderTargets(1, &renderTargetView, nullptr);
		renderTargetView->GetResource(reinterpret_cast<ID3D11Resource**>(&renderTexture));

		// レンダーターゲット情報を取得
		D3D11_TEXTURE2D_DESC renderTextureDesc;
		renderTexture->GetDesc(&renderTextureDesc);

		// シザリング範囲を取得
		UINT numScissorRects = 1;
		D3D11_RECT scissorRect;
		dx11_device_context->RSGetScissorRects(&numScissorRects, &scissorRect);

		// 描画範囲を計算
		uint32_t width = g_backgroundWidth;
		uint32_t height = g_backgroundHeight;

		if (width == renderTextureDesc.Width &&
			height == renderTextureDesc.Height)
		{
			// 背景テクスチャへコピー
			dx11_device_context->CopyResource(g_dx11_backGroundTexture, renderTexture);
		}
		else
		{
			// 背景テクスチャへ部分的コピー
			D3D11_BOX srcBox;
			srcBox.left = scissorRect.left;
			srcBox.top = scissorRect.top;
			srcBox.right = scissorRect.right;
			srcBox.bottom = scissorRect.bottom;
			srcBox.front = 0;
			srcBox.back = 1;
			dx11_device_context->CopySubresourceRegion(g_dx11_backGroundTexture, 0, 0, 0, 0, renderTexture, 0, &srcBox);
		}

		// 取得したリソースの参照カウンタを下げる
		ES_SAFE_RELEASE(renderTexture);
		ES_SAFE_RELEASE(renderTargetView);

		renderer2d->SetBackground(g_dx11_backGroundTextureSRV);
		renderer3d->SetBackground(g_dx11_backGroundTextureSRV);
	}

}