游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2647|回复: 3

DrawIndexedPrimitive的用法

[复制链接]

14

主题

25

帖子

25

积分

注册会员

Rank: 2

积分
25
发表于 2007-12-16 13:32:00 | 显示全部楼层 |阅读模式
这个函数的第二个参数是什么意思啊

0

主题

4

帖子

10

积分

新手上路

Rank: 1

积分
10
发表于 2007-12-16 15:11:00 | 显示全部楼层

Re:DrawIndexedPrimitive的用法

看看DirectX9的帮助文档吧,介绍的比较详细。

IDirect3DDevice9:rawIndexedPrimitive Method

--------------------------------------------------------------------------------


Renders the specified geometric primitive, based on indexing into an array of vertices.


Syntax

HRESULT DrawIndexedPrimitive(          D3DPRIMITIVETYPE Type,
    INT BaseVertexIndex,
    UINT MinIndex,
    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 index buffer to the first vertex index.
MinIndex
[in] Minimum vertex index for vertices used during this call.
NumVertices
[in] Number of vertices used during this call, starting from BaseVertexIndex + MinIndex
StartIndex
[in] Location in the index array to start reading vertices.
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.
Return Value


If the method succeeds, the return value is D3D_OK.

If the method fails, the return value can be


D3DERR_INVALIDCALL The method call is invalid. For example, a method's parameter may have an invalid value.



Remarks

This method draws indexed primitives from the current set of data input streams.

MinIndex and all the indices in the index stream are relative to the BaseVertexIndex.

The MinIndex and NumVertices parameters specify the range of vertex indices used for each IDirect3DDevice9::DrawIndexedPrimitive call. These are used to optimize vertex processing of indexed primitives by processing a sequential range of vertices prior to indexing into these vertices. It is invalid for any indices used during this call to reference any vertices outside of this range.

IDirect3DDevice9::DrawIndexedPrimitive fails if no index array is set.

The D3DPT_POINTLIST member of the D3DPRIMITIVETYPE enumerated type is not supported and is not a valid type for this method.

When converting a fixed function legacy application to Microsoft® DirectX® 9.0, you must add a call to IDirect3DDevice9::SetFVF before you make any Draw calls.

See Also

IDirect3DDevice9::DrawPrimitive, IDirect3DDevice9::SetStreamSource, Rendering Primitives

--------------------------------------------------------------------------------

© 2002 Microsoft Corporation. All rights reserved.

8

主题

390

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-12-16 18:33:00 | 显示全部楼层

Re:DrawIndexedPrimitive的用法

这个DrawIndexedPrimitive确实比较麻烦。。。
举个例子,有个vertexbuffer,你按顺序存储了v0,v1,v2,v3,v4,v5,六个顶点,然后你再有个index buffer顺序存储0,1,2,3,4,5六个index。

然后:
情况1:SetStreamSource时,第三个参数OffsetInBytes 用0,然后你DrawIndexedPrimitive(D3DPT_TRIANGLELIST,3,0,3,0,1),此时显示的是,v3,v4,v5组成的三角形,这个BaseVertexIndex就相当于,你的dip是每个index buffer中的值加上了BaseVertexIndex;

情况2:SetStreamSource时,第三个参数OffsetInBytes 用2×sizeof(your vertex),然后你DrawIndexedPrimitive(D3DPT_TRIANGLELIST,1,0,3,0,1),此时显示的还是是,v3,v4,v5组成的三角形。

理解了不,这玩意自己写个小程序,测试下就知道了,很奇怪的。特别是你使用1-2mb的大buffer,将不同stride的vertex进行混合(已达到减少dp次数),很容易参数设置错误。。。

//修改
瞧,这不是我又搞错了么了上面的dip的MinIndex是最小的vertex索引,debug 模式下检查严格一定要设置正确。这个值无需做修正。

8

主题

390

帖子

390

积分

中级会员

Rank: 3Rank: 3

积分
390
发表于 2007-12-16 18:48:00 | 显示全部楼层

Re:DrawIndexedPrimitive的用法

dx sdk--Scenario 4: Drawing One Triangle with Offset Indexing写了这个东西。不过还是比较容易出错的是,第二个参数不为0,那么第三个参数怎么办的问题。理论上BaseVertexIndex不是0了,那么MinVerterIndex也得修正,实际确不用,dx底层自己做了修正吧。。。。唉。。。微软总是被人骂,再加上SetStreamSource又加了个offset,两者一混合,不花个一上午,问题就不会清晰。。。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-17 15:50

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表