使用图像的一部分创建directx9纹理
Create directx9 texture using a portion(s) of an image
我有一张图片(208x8),我想在不同的区域复制8x8的正方形,然后将所有的正方形连接起来创建一个IDirect3DTexture9*
取决于你到底想做什么IDirect3DDevice9:: updatessurface或IDirect3DDevice9::StretchRect可能会帮助你。
对于像你描述的非常小的纹理的简单操作,使用CPU(即使用IDirect3DTexture9::LockRect)操作它们可能是有利的。对于D3D9,这通常意味着纹理被重新上传到VRAM,所以它通常只对小的或不经常修改的纹理有用。但有时候,如果你是渲染受限的,并且你对在循环中更新纹理的位置很小心,那么就有可能隐藏像这样的操作成本,并"免费"获得它们。
为了避免VRAM上传,您可以使用POOL_MANAGED资源与适当的使用和锁定标志相结合,将资源定位在AGP孔径内,允许CPU和GPU的高速访问,参见:http://msdn.microsoft.com/en-us/library/windows/desktop/ee418784(v=vs.85).aspx
如果你在CPU上操作,要注意各种纹理格式的平铺和对齐限制。最好的信息在SDK附带的文档中(包括几个白皮书),在线文档是不完整的。
下面是一个基本的例子:
IDirect3DTexture9* m_tex = getYourTexture();
m_tex->LockRect(0, &outRect, d3dRect, D3DLOCK_DISCARD);
// Stride depends on your texture format - this is the number of bytes per texel.
// Note that this may be less than 1 for DXT1 textures in which case you'll need
// some bit swizzling logic. Can be inferred from Pitch and width.
int stride = 1;
int rowPitch = outRect.Pitch;
// Choose a pointer type that suits your stride.
unsigned char* pixels = (unsigned char*)outRect.pBits;
// Clear to black.
for (int y=0; y < d3dRect.height; ++y)
{
for (int x=0; x < d3dRect.width; ++x)
{
pixels[x + rowPitch * y] = 0x0;
}
}
m_tex->UnlockRect(0);
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 使用std::multimap迭代器创建std::list
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 使用CMake创建QML插件
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 试图在visual studio上用C++创建一个桌面应用程序
- std::threads可以从Windows DLL中的全局变量创建/销毁吗?
- 如何在C++20中创建模板别名的推导指南
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 链接到自行创建的dll失败
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++类内存结构中创建"spacer"?
- 终端不会为C++文件创建.exe文件吗
- 使用图像的一部分创建directx9纹理