与 Direct3D 10 的最佳 2D 集成?
到目前为止,我的应用程序主要是 DirectX 10 3D 图形。现在我们想要生成一些实时 2D 图像以显示在屏幕的一部分上。 2D 图形将通过使用来自外部硬件的原始数据生成 - 每个值将被转换为像素颜色和位置。
我已经研究过 Direct2D 集成选项,但我没有看到一种逐像素绘制到表面的直接方法,而只是常见的线条和形状。
我相信仅使用 Direct3D(不使用 Direct2D)也可以做到这一点,并且只需为每个像素设置一个简单的顶点并在正交视图中绘制它。
在生成实时 2D 图形时,使用 Direct2D 是否可以提高效率?我不想使用形状工具,所以这对我来说并不是真正的卖点。在 Direct3D 应用程序中生成 2D 图形是否还有其他更有效的常见做法?
任何指示将不胜感激。谢谢。
I have an application that, to this point, is mostly DirectX 10 3D graphics. Now we are wanting to generate some real-time 2D images to display on a portion of the screen. The 2D graphics will be generated by using raw data coming in from an external piece of hardware - each value will be translated into a pixel color and position.
I have looked at Direct2D integration options, but I don't see a straightforward way to draw to a surface pixel-by-pixel, but rather just common lines and shapes.
I believe it would also be possible to do this with just Direct3D (no use of Direct2D), and just have a simple vertex for each pixel and draw it in orthogonal view.
Does using Direct2D improve efficiency at all when generating real-time 2D graphics? I am not wanting to use the shape tools so that is not really a selling point for me. Are there any other common practices for generating 2D graphics within a Direct3D application that would work better?
Any pointers would be greatly appreciated. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 D3D 应用程序中绘制 2D 图形(UI 等)的常规方法是将所需的任何位图图像数据存储在纹理中,并绘制带纹理的 2D 四边形来显示它。这为您提供免费的缩放、旋转、过滤等硬件加速。
如果您希望以像素精确的方式再现源图像,则需要确保考虑屏幕分辨率并使用正确的顶点位置绘制四边形。这在 Direct3D 10 比 Direct3D 9。
The normal approach for drawing 2D graphics (UI etc.) in a D3D application is to store any bitmap image data you need in textures and draw textured 2D quads to display it. This gives you hardware acceleration of scaling, rotation, filtering, etc. for free.
If you want pixel accurate reproduction of your source images you'll need to ensure you take the screen resolution into account and draw your quads with the correct vertex positions. This is easier in Direct3D 10 than it was in Direct3D 9.
您问题的答案是纹理 2D 四边形
只需创建一个具有以下顶点的顶点着色器:
顶点布局
(位置 x、位置 y、位置 z、纹理坐标 x、纹理坐标 y)。
以及适当的索引缓冲区。
然后只需将适当的纹理绑定为着色器资源和矩阵即可根据需要平移/旋转/缩放四边形。在顶点着色器中使用矩阵变换顶点位置,在像素着色器中对包含纹理的着色器资源进行采样。
如果您想更新纹理,只需对其进行 Map(),更新您想要的任何像素,Unmap() 并将其再次绑定到像素着色器。
The answer to your question is Textured 2D quads
Simply create a vertex shader with the following vertices:
Vertex layout
(Position x, Position y, Position z, Texture Coord x, Texture Coord y).
And the appropriate index buffer.
Then simply bind the appropriate texture as a shader resource and a matrix to translate/rotate/scale the quad as you want. In the vertex shader transform the vertices position using the matrix and in the pixel shader sample the shader resource congaing the texture.
If you want to update the texture simply Map() it, update whatever pixels you want, Unmap() it and bind it again to the pixel shader.