Beispiel #1
0
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));
}
Beispiel #2
0
CPixelBufferView::TexturePtr CPixelBufferView::CreateTextureFromBitmap(const Framework::CBitmap& bitmap)
{
	TexturePtr texture;

	if(!bitmap.IsEmpty())
	{
		HRESULT result = S_OK;
		result = m_device->CreateTexture(bitmap.GetWidth(), bitmap.GetHeight(), 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, nullptr);
		assert(SUCCEEDED(result));

		D3DLOCKED_RECT lockedRect = {};

		result = texture->LockRect(0, &lockedRect, nullptr, 0);
		assert(SUCCEEDED(result));
		
		uint32* dstPtr = reinterpret_cast<uint32*>(lockedRect.pBits);
		uint32* srcPtr = reinterpret_cast<uint32*>(bitmap.GetPixels());
		for(unsigned int y = 0; y < bitmap.GetHeight(); y++)
		{
			memcpy(dstPtr, srcPtr, bitmap.GetWidth() * sizeof(uint32));
			dstPtr += lockedRect.Pitch / sizeof(uint32);
			srcPtr += bitmap.GetPitch() / sizeof(uint32);
		}

		result = texture->UnlockRect(0);
		assert(SUCCEEDED(result));
	}

	return texture;
}
Beispiel #3
0
void CGSH_Direct3D9::CopyTextureToBitmap(Framework::CBitmap& outputBitmap, const TexturePtr& texture, uint32 width, uint32 height)
{
	outputBitmap = Framework::CBitmap(width, height, 32);

	HRESULT result = S_OK;

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

	uint8* srcPtr = reinterpret_cast<uint8*>(lockedRect.pBits);
	uint8* dstPtr = reinterpret_cast<uint8*>(outputBitmap.GetPixels());
	for(unsigned int y = 0; y < height; y++)
	{
		memcpy(dstPtr, srcPtr, width * 4);
		dstPtr += outputBitmap.GetPitch();
		srcPtr += lockedRect.Pitch;
	}

	result = texture->UnlockRect(0);
	assert(SUCCEEDED(result));
}