使用所有语义类型创建 Direct3D 顶点是否会降低性能?

发布于 2024-09-26 03:27:57 字数 528 浏览 1 评论 0原文

在 Direct3D 中,您可以创建您喜欢的任何类型的顶点。您可以拥有一个仅包含位置信息的简单顶点,也可以添加颜色信息、纹理信息等。 创建输入布局时,您定义已实现的顶点的哪些部分:

D3D10_INPUT_ELEMENT_DESC layout[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};

我的问题是,我应该使用所有输入类型(位置、颜色、纹理等)定义顶点结构。或者我应该创建多个顶点结构,每个顶点结构具有不同类型的输入。

使用多个类的缺点是您必须创建和维护多个类,并且了解要使用哪种类型的顶点可能会令人困惑。 1 个顶点结构有哪些缺点?

In Direct3D, you can create any type of Vertex you like. You can have a simple Vertex with just positional information, or you could add colour info, texture info, etc etc.
When creating your input layout, you define what parts of a Vertex you've implemented:

D3D10_INPUT_ELEMENT_DESC layout[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};

My question is, should I define a vertex structure with all of the input types (position, colour, texture etc etc). Or should I create several vertex structures, each with different types of input.

The downsides to using multiple classes is that you have to create and maintain several classes, and it could be confusing knowing which type of vertex to use.
What are the downsides of having 1 vertex structure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我还不会笑 2024-10-03 03:27:57

您会将未使用的顶点数据上传到 3d 加速器,这会占用一些带宽。除非你正在做一些顶级的视频游戏,否则这应该没什么关系(你几乎肯定会在其他地方遇到瓶颈)。

You will upload unused vertex data to the 3d accelerator, and it will eat some bandwidth. It shouldn't matter much unless you are doing some top notch video game (you'll almost certainly have a bottleneck somewhere else).

云巢 2024-10-03 03:27:57

不要这样做,使用专门的结构。将顶点数据上传到 GPU 会消耗大量带宽,并很快成为瓶颈(考虑到这个问题很容易解决——将 Vertexbuffer 包装在自定义类中以自动处理到最有效输入布局的转换)。

这也是不切实际的 - 例如,蒙皮需要大量每个顶点的额外数据。您是否真的希望应用程序中的每个顶点都携带它,即使根本不需要它?

不过,我确实建议为顶点组件在数据结构中出现的顺序建立某种约定。这将帮助您编写着色器,因为它们最终与顶点输入布局耦合。

Don't do that, use specialized structures. Uploading vertex data to the GPU consumes a lot of your bandwidth and quickly becomes a bottleneck (given that the problem is trivial to solve -- wrap a Vertexbuffer in a custom class to handle the conversion to the most efficient input layout automatically).

It's also unpractical - Skinning, for example, needs a lot of per-vertex extra data. Do you really want every single vertex in your application to carry it as well, even though it is not needed at all?

I do, however, recommend to establish some kind of convention for the order in which the vertex components appear in the data structure. That'll help you at writing your shaders, because these are ultimatively coupled to vertex input layout.

神也荒唐 2024-10-03 03:27:57

我通过在堆上生成一块内存并只用所需的元素填充它来解决这个问题。代码可在此处获取:

http ://code.google.com/p/woof/source/browse/trunk/Libraries/WOOF3D/Direct3D10Vertices.cpp?r=24

I solved it by generating a chunk of memory on the heap and only filling it with the required elements. The code is available here:

http://code.google.com/p/woof/source/browse/trunk/Libraries/WOOF3D/Direct3D10Vertices.cpp?r=24

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文