DrawIndexedPrimitive()

HRESULT DrawIndexedPrimitive(  
  
     D3DPRIMITIVETYPE Type,                 //基本图元类型  
  
     INT BaseVertexIndex,                   //顶点缓冲区的起始位置  
  
     UINT MinIndex,                         //相对于BaseVertexIndex的最小索引  
  
     UINT NumVertices,                      //绘制的顶点数目,第一个顶点的位置  
  
     UINT StartIndex,                       //索引缓冲区的起始位置  
  
  
  
     UINT PrimitiveCount                   //绘制的基本图元数量  
    );  

Parameters

Type
[in] Member of the D3DPRIMITIVETYPE enumerated type, describing the type of primitive to render. D3DPT_POINTLIST is not supported with this method. See Remarks.
BaseVertexIndex
[in] Offset from the start of the vertex buffer to the first vertex index. An index of 0 in the index buffer refers to this location in the vertex buffer.
MinIndex
[in] Minimum vertex index for vertices used during this call. This is a zero based index relative to BaseVertexIndex.
NumVertices
[in] Number of vertices used during this call. The first vertex is located at index: BaseVertexIndex + MinIndex.
StartIndex
[in] Index of the first index to use when accesssing the vertex buffer. Beginning at StartIndex to index vertices from the vertex buffer.
PrimitiveCount
[in] Number of primitives to render. The number of vertices used is a function of the primitive count and the primitive type. The maximum number of primitives allowed is determined by checking the MaxPrimitiveCount member of the D3DCAPS9 structure.

 

Type——不用过多解释的参数,就是图元类型,像是线段、三角形等等。

BaseVertexIndex——这个用作偏移量,比如我们在索引缓冲中的顶点是Vx=10(Vx表示顶点在顶点数组中的下标,下同),那么Vx实际上传递到显卡是Vx+BaseVertexIndex,为什么要加上这个参数呢?他的好处在于,如果我一次性在一个顶点缓冲中加上了别的几个顶点缓冲,那么我再用一个索引缓冲去定位顶点的话就会有问题,比如原先有个缓冲A,其中某个顶点Vx=10,那么现在我把这个缓冲附到了某个缓冲B后面,这个时候顶点的索引依旧是Vx=10,但是下标为10的这个顶点已经不是原来那个了,因为前面加上了缓冲B。对于老版的DX8,我们可以通过修改索引缓冲达到相应的效果,然而这项操作的时间复杂度是O(n),现在我们就用不到了,只要交给DX自己处理。

MinVertexIndex——顶点的最小下标,顾名思义,就是在本次绘图过程中用到的顶点的最小下标。(估计给D3D做优化用,参考下一个参数的说明)

NumVertices——这恐怕是最坑爹的参数,网上给出的说法都是:用到的顶点数,但实际上呢?如果尝试用用到的顶点数去做参数的话,在PIX中调试程序,会出现各种错误,像是Index Out Of Range(索引超越边界),严重的导致PIX崩溃。在查阅了大量资料后,终于知道了这个参数的含义:一次绘图中顶点缓冲的跨度(即Vmax-Vmin+1),只是跨度而不一定是顶点数目,也就是说可以包含一些没有用到的顶点……这么说来,用作优化还真是很有道理的,因为在知道MinVertexIndex以后,D3D就可以把MinVertexIndex----(MinVertexIndex+NumVertices-1 )这段的数据提取出来用于渲染,省去了不必要的内存开销……,如你用到点缓冲中的3,4,6,8,23,那么你的MinVertexIndex=3,NumVertices=21,

StartIndex——这个函数很简单,表示索引缓冲中开始的那个下标

PrimitiveCount——绘制的图元个数,配合StartIndex和D3DPT 来定位索引缓冲 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值