游戏开发论坛

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

请教DrawIndexedPrimitive参数问题

[复制链接]

4

主题

12

帖子

18

积分

新手上路

Rank: 1

积分
18
发表于 2006-12-29 16:13:00 | 显示全部楼层 |阅读模式
我用以下几种方法调用这个函数
m_lpD3DDevice9->DrawIndexedPrimitive(D3DPT_LINELIST,0,0,0,0,3);
m_lpD3DDevice9->DrawIndexedPrimitive(D3DPT_LINELIST,0,2,2,0,3);
m_lpD3DDevice9->DrawIndexedPrimitive(D3DPT_LINELIST,0,10000,1111,0,3);
都能画出一样的图形来

我的VertexBuffer有3个顶点,IndexBuffer有6个索引

而DirectX9.chm上说
The MinIndex and NumVertices parameters specify the range of vertex indices used for each IDirect3DDevice9:rawIndexedPrimitive 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.

很明显我的m_lpD3DDevice9->DrawIndexedPrimitive(D3DPT_LINELIST,0,10000,1111,0,3);
引用的顶点操出了范围,为什么还能正常显示图形呢?

另外m_lpD3DDevice9->DrawIndexedPrimitive(D3DPT_POINTLIST,0,1000,11112,0,6); 也能正常画点
而DirectX9.chm上说
The D3DPT_POINTLIST member of the D3DPRIMITIVETYPE enumerated type is not supported and is not a valid type for this method.

为什么DirectX9.chm说的这两点和我实际的情况不一样呢?

4

主题

12

帖子

18

积分

新手上路

Rank: 1

积分
18
 楼主| 发表于 2006-12-29 16:26:00 | 显示全部楼层

Re:请教DrawIndexedPrimitive参数问题

下面是我的部分代码


IDirect3DVertexBuffer9 *pVertexBuffer;
        PVERTEX pVertex;
        m_lpD3DDevice9->CreateVertexBuffer(4*sizeof(VERTEX),0,m_dwFVF,D3DPOOL_DEFAULT,&pVertexBuffer,NULL);
        pVertexBuffer->Lock(0,0,(LPVOID*)&pVertex,0);
        ZeroMemory(&pVertex[0],sizeof(VERTEX));
        ZeroMemory(&pVertex[1],sizeof(VERTEX));
        ZeroMemory(&pVertex[2],sizeof(VERTEX));
        ZeroMemory(&pVertex[3],sizeof(VERTEX));
        pVertex[0].x = 200;
        pVertex[0].y = 200;
        pVertex[0].diffuse = D3DCOLOR_ARGB(255,255,0,0);
        pVertex[1].x = 400;
        pVertex[1].y = 200;
        pVertex[1].diffuse = D3DCOLOR_ARGB(255,0,255,0);
        pVertex[2].x = 300;
        pVertex[2].y = 370;
        pVertex[2].diffuse = D3DCOLOR_ARGB(255,0,0,255);
        pVertex[3].x = 200;
        pVertex[3].y = 200;
        pVertex[3].diffuse = D3DCOLOR_ARGB(255,0,0,255);
        pVertexBuffer->Unlock();
        m_lpD3DDevice9->SetStreamSource(0,pVertexBuffer,0,sizeof(VERTEX));

IDirect3DIndexBuffer9 *pIndexBuffer;
        LPWORD pIndex;
        m_lpD3DDevice9->CreateIndexBuffer(6*sizeof(WORD),0,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&pIndexBuffer,NULL);
        pIndexBuffer->Lock(0,0,(LPVOID*)&pIndex,0);
        pIndex[0] = 0;
        pIndex[1] = 1;
        pIndex[2] = 0;
        pIndex[3] = 2;
        pIndex[4] = 1;
        pIndex[5] = 2;
        pIndexBuffer->Unlock();
        m_lpD3DDevice9->SetIndices(pIndexBuffer);
        m_lpD3DDevice9->DrawIndexedPrimitive(D3DPT_LINELIST,0,10000,1111,0,3);

        pVertexBuffer->Release();
        pIndexBuffer->Release();

36

主题

1047

帖子

1147

积分

金牌会员

Rank: 6Rank: 6

积分
1147
发表于 2006-12-29 18:02:00 | 显示全部楼层

Re:请教DrawIndexedPrimitive参数问题

无效指的是结果未定义,就像你使用了一个野指针一样,有可能错误,也有可能不错,当你的场景复杂的时候,基本上绘制错误。

8

主题

553

帖子

560

积分

高级会员

Rank: 4

积分
560
发表于 2006-12-29 19:32:00 | 显示全部楼层

Re:请教DrawIndexedPrimitive参数问题

关于minindex和range超出范围得问题,深究下去有点意思。
其实对于目前HW的接口来说,是没有所谓minindex和maxindex的,HW需要的只是vb和ib的指针(硬件地址,下同),HW每读一个index,就从vb里抓一笔vertex data(大小试vertex decl决定),当然这里面有pre cache和post cache机制,大家都知道我也不必说。假如index超过vb的范围,那么只要最后算出得物理地址是HW能抓到的,那快地址上是什么数据抓回来就是什么数据。假如HW不能访问此物理地址,天知道会发生什么,HW可能会翘,要看硬件的设计。

所以说DIP这个函数有的参数硬件用不上:-)

可driver要这辆个参数还是有用滴,driver要做优化,还有的IGP上没有HW VS。典型的优化如:driver先吧每个顶点的position都算一遍,做一遍culling,然后生成新的ib(新的ib肯定笔原来的小拉),在送给HW,这样可以省些hw时间。用CPU算这些顶点的position,我想大家都知道可以利用上minindex和range了吧,还可以很容易用上SIMD指令优化。谁也不想读一个index,访问一个vertex data。。。又不能SIMD。当然那些没有HW VS的就不必说了。

其实这是个历史遗留问题,因为在pre dx7时代,TnL是由runtime帮你做的,这两个参数的用途同上:-)

看看DX10,还有没有这两个令人讨厌的参数?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-26 04:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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