如何解决以下任务:某些应用需要
即。有时(每帧/秒/分钟一次)我需要以不同的格式写入字节(void *
)( argb , bgra , rgb , 888 , 565 )到现有纹理的某个子矩形。
在openGL中,解决方案非常简单 - glTexImage2D
。但是这里不熟悉的平台功能让我完全糊涂了。
对dx9和dx11的解决方案感兴趣。
答案 0 :(得分:4)
要更新纹理,请确保在D3DPOOL_MANAGED内存池中创建纹理。
D3DXCreateTexture( device, size.x, size.y, numMipMaps,usage, textureFormat, D3DPOOL_MANAGED, &texture );
然后调用LockRect更新数据
RECT rect = {x,y,z,w}; // the dimensions you want to lock
D3DLOCKED_RECT lockedRect = {0}; // "out" parameter from LockRect function below
texture->LockRect(0, &lockedRect, &rect, 0);
// copy the memory into lockedRect.pBits
// make sure you increment each row by "Pitch"
unsigned char* bits = ( unsigned char* )lockedRect.pBits;
for( int row = 0; row < numRows; row++ )
{
// copy one row of data into "bits", e.g. memcpy( bits, srcData, size )
...
// move to the next row
bits += lockedRect.Pitch;
}
// unlock when done
texture->UnlockRect(0);