访问 SlimDX Texture2D 对象中的数据
如何访问Texture2D对象中的数据?许多 XNA 帖子建议使用函数 Texture2D.GetData,但在 Texture2D 的 SlimDX 版本中似乎缺少该函数。我需要处理图像来计算场景的整体亮度,并且不想在像素着色器中运行 300 次访问(即每帧 300 次访问 * num_pixels),而我可以每帧执行一次。
我需要做的就是访问纹理的颜色(R32G32B32A32)。
啊,我想我已经找到了它,这要归功于 SlimDX SDK。 Texture2D.ToStream() 方法将纹理数据发送到内存流,然后我只需解析字节即可获取数据。如果它对我有用,我会提交它作为答案。
How do I access the data in a Texture2D object? Lots of XNA posts suggest using the function Texture2D.GetData but that appears to be missing in the SlimDX version of a Texture2D. I need to process my image to calculate overall luminance of the scene and don't want to be running 300 accesses in a pixel shader (i.e. 300 access * num_pixels per frame) when I could be doing it once per frame.
All I need to be able to do is access the colour (R32G32B32A32) of the texture.
Ah I reckon I've found it thanks to the SlimDX SDK. The Texture2D.ToStream() method sends the texture data to a memory stream, then I simply have to parse the bytes to get at my data. I'll submit this as an answer if it works for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,ToStream() 工作得很好,这要归功于 SlimDX SDK。 Texture2D.ToStream() 方法将纹理数据发送到内存流,然后我只需解析字节即可获取数据。
Yep, ToStream() works fine, thanks to the SlimDX SDK. The Texture2D.ToStream() method sends the texture data to a memory stream, then I simply have to parse the bytes to get at my data.