3 个索引缓冲区 [英] 3 index buffers

查看:46
本文介绍了3 个索引缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在 D3D 和 OpenGL 中,都可以从索引缓冲区中进行绘制.

然而,OBJ 文件格式有些奇怪.它指定了一堆顶点,如:

<前>v -21.499660 6.424470 4.069845v -25.117170 6.418100 4.068025v -21.663851 8.282170 4.069585v -21.651890 6.420180 4.068675v -25.128481 8.281520 4.069585

然后它指定了一堆法线,比如..

<前>vn 0.196004 0.558984 0.805680vn -0.009523 0.210194 -0.977613vn -0.147787 0.380832 -0.912757vn 0.822108 0.567581 0.044617vn 0.597037 0.057507 -0.800150vn 0.809312 -0.045432 0.585619

然后它指定一堆 tex 坐标,如

<前>0.1225 0.56360.6221 0.11110.4865 0.88880.2862 0.25860.5865 0.25680.1862 0.2166

然后它在模型上指定面",例如:

<前>f 1/2/5 2/3/7 8/2/6f 5/9/7 6/3/8 5/2/1

我们在哪里v/t/n第一个数字是顶点数组的索引,第二个数字是 tex 坐标数组的索引,第三个是法线数组的索引.

因此,在尝试使用顶点缓冲区渲染时,

在 OpenGL 中,我可以使用 glVertexPointerglNormalPointerglTexCoordPointer 分别设置指向每个顶点、法线和纹理坐标数组的指针.. 但是当涉及到使用 glDrawElements 进行绘图时,我只能指定 ONE 组索引,即访问顶点时应该使用的索引.

好的,然后呢?我还有 3 组索引要访问.

在 d3d 中它大致相同 - 我可以设置 3 个流:一个用于顶点,一个用于 texcoords,一个用于法线,但是在使用 IDirect3DDevice9::DrawIndexedPrimitive 时,我仍然只能指定 ONE 索引缓冲区,它将索引到顶点数组中.

那么,是否可能为每个顶点、texcoord 和普通缓冲区(无论是 d3d 还是 opengl!)使用不同的索引数组从顶点缓冲区中进行绘制,还是必须创建一个交错的阵列然后访问 IT?

解决方案

OBJ 并非旨在映射到 OpenGL 或 DirectX.

你说的一切都是真的,不,不能使用每个属性的索引.

您必须将 OBJ 表示转换为每个顶点仅使用单个索引的内容(可能会在此过程中复制一些顶点数据).

So, in both D3D and OpenGL there's ability to draw from an index buffer.

The OBJ file format however does something weird. It specifies a bunch of vertices like:

v -21.499660 6.424470 4.069845
v -25.117170 6.418100 4.068025
v -21.663851 8.282170 4.069585
v -21.651890 6.420180 4.068675
v -25.128481 8.281520 4.069585

Then it specifies a bunch of normals like..

vn 0.196004 0.558984 0.805680
vn -0.009523 0.210194 -0.977613
vn -0.147787 0.380832 -0.912757
vn 0.822108 0.567581 0.044617
vn 0.597037 0.057507 -0.800150
vn 0.809312 -0.045432 0.585619

Then it specifies a bunch of tex coords like

vt 0.1225 0.5636
vt 0.6221 0.1111
vt 0.4865 0.8888
vt 0.2862 0.2586
vt 0.5865 0.2568
vt 0.1862 0.2166

THEN it specifies "faces" on the model like:

f 1/2/5 2/3/7 8/2/6
f 5/9/7 6/3/8 5/2/1

Where we're v/t/n the first number is an index into the vertices array, the second an index into the tex coord array, the third, into the normals array.

So, in trying to render this with vertex buffers,

In OpenGL I can use glVertexPointer, glNormalPointer and glTexCoordPointer to set pointers to each of the vertex, normal and texture coordinate arrays respectively.. but when it comes down to drawing with glDrawElements, I can only specify ONE set of indices, namely the indices it should use when visiting the vertices.

Ok, then what? I still have 3 sets of indices to visit.

In d3d its much the same - I can set up 3 streams: one for vertices, one for texcoords, and one for normals, but when it comes to using IDirect3DDevice9::DrawIndexedPrimitive, I can still only specify ONE index buffer, which will index into the vertices array.

So, is it possible to draw from vertex buffers using different index arrays for each of the vertex, texcoord, and normal buffers (EITHER d3d or opengl!), or must I create a single interleaved array and then visit IT?

解决方案

OBJ was not designed to map to OpenGL or DirectX.

Everything you said is true, and no, it's not possible to use per-attribute indices.

You have to convert the OBJ representation to something that only uses a single index per vertex (possibly duplicating some vertex data along the way).

这篇关于3 个索引缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆