コード例 #1
0
ファイル: GSH_Direct3D9.cpp プロジェクト: AbandonedCart/Play-
void CGSH_Direct3D9::CopyRenderTargetToBitmap(Framework::CBitmap& outputBitmap, const TexturePtr& renderTarget, uint32 renderTargetWidth, uint32 renderTargetHeight, uint32 width, uint32 height)
{
	HRESULT result = S_OK;

	SurfacePtr offscreenSurface, renderTargetSurface;

	result = renderTarget->GetSurfaceLevel(0, &renderTargetSurface);
	assert(SUCCEEDED(result));

	result = m_device->CreateOffscreenPlainSurface(renderTargetWidth, renderTargetHeight, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &offscreenSurface, nullptr);
	assert(SUCCEEDED(result));

	result = m_device->GetRenderTargetData(renderTargetSurface, offscreenSurface);
	assert(SUCCEEDED(result));

	outputBitmap = Framework::CBitmap(width, height, 32);

	D3DLOCKED_RECT lockedRect = {};
	result = offscreenSurface->LockRect(&lockedRect, nullptr, D3DLOCK_READONLY);
	assert(SUCCEEDED(result));

	uint8* srcPtr = reinterpret_cast<uint8*>(lockedRect.pBits);
	uint8* dstPtr = reinterpret_cast<uint8*>(outputBitmap.GetPixels());
	uint32 copyWidth = std::min<uint32>(renderTargetWidth, width);
	uint32 copyHeight = std::min<uint32>(renderTargetHeight, height);
	for(unsigned int y = 0; y < copyHeight; y++)
	{
		memcpy(dstPtr, srcPtr, copyWidth * 4);
		dstPtr += outputBitmap.GetPitch();
		srcPtr += lockedRect.Pitch;
	}

	result = offscreenSurface->UnlockRect();
	assert(SUCCEEDED(result));
}
コード例 #2
0
	void DisplayRenderTarget::SetRTOverride(DisplayTexturePtr _RTOverride)
	{
		if (m_pRTOverrideTex != _RTOverride)
		{
			if (NULL != m_pRTOverrideSurf)
			{
				m_pRTOverrideSurf->Release();
				m_pRTOverrideSurf = NULL;
			}
			m_pRTOverrideTex = _RTOverride;
			if (NULL != m_pRTOverrideTex)
			{
				TexturePtr pTexture = static_cast<TexturePtr>(m_pRTOverrideTex->GetBase());
				pTexture->GetSurfaceLevel(0, &m_pRTOverrideSurf);
			}
		}
	}
コード例 #3
0
	bool DisplayRenderTarget::Create(const boost::any& _rConfig)
	{
		CreateInfo* pInfo = boost::any_cast<CreateInfo*>(_rConfig);
		bool bResult = (NULL != pInfo);

		if (false != bResult)
		{
			Release();

			m_strName = pInfo->m_strName;
			m_uRTIndex = pInfo->m_uIndex;
			m_bImmediateWrite = pInfo->m_bImmediateWrite;
			m_eRenderState = ERenderState_UNKNOWN;
			m_eMode = ERenderMode_UNKNOWNPROCESS;
			m_pCurrentBufferTex = NULL;
			m_uCurrentBuffer = 0;

			string strSemanticName = boost::str(boost::format("RT2D0%1%") % m_uRTIndex);
			m_uRTSemanticNameKey = MakeKey(strSemanticName);
			strSemanticName = boost::str(boost::format("ORT2D0%1%") % m_uRTIndex);
			m_uORTSemanticNameKey = MakeKey(strSemanticName);

			for (UInt i = 0 ; c_uBufferCount > i ; ++i)
			{
				string strTexName = boost::str(boost::format("%1%_%2%") % m_strName % i);
				bResult = m_rDisplay.GetTextureManager()->New(strTexName, pInfo->m_uWidth, pInfo->m_uHeight, pInfo->m_uFormat, false, DisplayTexture::EType_2D, DisplayTexture::EUsage_RENDERTARGET);
				if (false == bResult)
				{
					vsoutput(__FUNCTION__" : %s, could not create texture\n", strTexName.c_str());
					break;
				}
				m_pDoubleBufferTex[i] = m_rDisplay.GetTextureManager()->Get(strTexName);
				TexturePtr pTexture = static_cast<TexturePtr>(m_pDoubleBufferTex[i]->GetBase());
				pTexture->GetSurfaceLevel(0, &m_pDoubleBufferSurf[i]);
			}
		}

		return bResult;
	}