本文整理汇总了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;
}
示例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));
}