当前位置: 首页>>代码示例>>C++>>正文


C++ TexturePtr::LockRect方法代码示例

本文整理汇总了C++中TexturePtr::LockRect方法的典型用法代码示例。如果您正苦于以下问题:C++ TexturePtr::LockRect方法的具体用法?C++ TexturePtr::LockRect怎么用?C++ TexturePtr::LockRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TexturePtr的用法示例。


在下文中一共展示了TexturePtr::LockRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateTextureFromBitmap

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;
}
开发者ID:RikoudoX,项目名称:Play-,代码行数:30,代码来源:PixelBufferView.cpp

示例2:

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));
}
开发者ID:AbandonedCart,项目名称:Play-,代码行数:22,代码来源:GSH_Direct3D9.cpp


注:本文中的TexturePtr::LockRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。