游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3198|回复: 6

对顶点缓冲和索引缓冲的问题

[复制链接]

9

主题

22

帖子

22

积分

注册会员

Rank: 2

积分
22
发表于 2009-10-30 11:07:00 | 显示全部楼层 |阅读模式
我用索引缓冲绘制一个长方体,运行之后可以正常显示,但是结束进程之后VS输出提示:
Direct3D9: (WARN) :Vertexbuffer created with POOL_DEFAULT but WRITEONLY not set. Performance penalty could be severe.
Direct3D9: (WARN) :Indexbuffer created with POOL_DEFAULT but WRITEONLY not set. Performance penalty could be severe.
请问为什么会出现上面的提示?下面是我的代码。 谢谢。

  1. HRESULT InitVBandIB()
  2. {
  3.         if( FAILED( pd3dDevice->CreateVertexBuffer ( 8*sizeof( CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &pVB, NULL)))
  4.                 return E_FAIL;
  5.        
  6.         CUSTOMVERTEX* vertices;
  7.         if( pVB->Lock ( 0, 0, ( void**)&vertices, 0))
  8.                 return E_FAIL;
  9.         vertices[0].position = D3DXVECTOR3((float)(-4), -0.5f, -4.0f);
  10.         vertices[1].position = D3DXVECTOR3(-4.0f,  0.5f, -4.0f);
  11.         vertices[2].position = D3DXVECTOR3( 4.0f,  0.5f, -4.0f);
  12.         vertices[3].position = D3DXVECTOR3( 4.0f, -0.5f, -4.0f);
  13.         vertices[4].position = D3DXVECTOR3(-4.0f, -0.5f,  4.0f);
  14.         vertices[5].position = D3DXVECTOR3(-4.0f,  0.5f,  4.0f);
  15.         vertices[6].position = D3DXVECTOR3( 4.0f,  0.5f,  4.0f);
  16.         vertices[7].position = D3DXVECTOR3( 4.0f, -0.5f,  4.0f);
  17.         pVB->Unlock ();

  18.         if( FAILED( pd3dDevice->CreateIndexBuffer ( 36*sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &pIB, 0)))
  19.                 return E_FAIL;
  20.        
  21.         WORD* indices = 0;
  22.         if( FAILED( pIB->Lock ( 0, 0, ( void**)&indices,0)))
  23.                 return E_FAIL;
  24.         indices[0]  = 0; indices[1]  = 1; indices[2]  = 2;
  25.         indices[3]  = 0; indices[4]  = 2; indices[5]  = 3;
  26.         indices[6]  = 4; indices[7]  = 6; indices[8]  = 5;
  27.         indices[9]  = 4; indices[10] = 7; indices[11] = 6;
  28.         indices[12] = 4; indices[13] = 5; indices[14] = 1;
  29.         indices[15] = 4; indices[16] = 1; indices[17] = 0;
  30.         indices[18] = 3; indices[19] = 2; indices[20] = 6;
  31.         indices[21] = 3; indices[22] = 6; indices[23] = 7;
  32.         indices[24] = 1; indices[25] = 5; indices[26] = 6;
  33.         indices[27] = 1; indices[28] = 6; indices[29] = 2;
  34.         indices[30] = 4; indices[31] = 0; indices[32] = 3;
  35.         indices[33] = 4; indices[34] = 3; indices[35] = 7;
  36.         pIB->Unlock ();

  37.         pd3dDevice->SetRenderState ( D3DRS_FILLMODE, D3DFILL_WIREFRAME);

  38.         return S_OK;
  39. }

  40. void Render()
  41. {
  42.         if( moveFlag)
  43.         {
  44.                 d3d::SetMoveWorldMatrix ( pd3dDevice);
  45.                 d3d::SetMoveViewMatrix ( pd3dDevice);
  46.         }
  47.         else
  48.         {
  49.                 d3d::SetWorldMatrix( pd3dDevice);
  50.                 d3d::SetBirdViewMatrix( pd3dDevice);
  51.         }
  52.         d3d::SetProjectionMatrix( width, height, pd3dDevice);
  53.         pd3dDevice->Clear ( 0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
  54.         if( SUCCEEDED( pd3dDevice->BeginScene ()))
  55.         {
  56.                 pd3dDevice->SetStreamSource ( 0, pVB, 0, sizeof( CUSTOMVERTEX));
  57.                 pd3dDevice->SetFVF ( D3DFVF_CUSTOMVERTEX);
  58.                 pd3dDevice->SetIndices ( pIB);
  59.                 pd3dDevice->DrawIndexedPrimitive ( D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

  60.                 //pd3dDevice->SetStreamSource ( 0, bVB, 0, sizeof( CUSTOMVERTEX));
  61.                 //pd3dDevice->SetFVF ( D3DFVF_CUSTOMVERTEX);
  62.                 //pd3dDevice->SetIndices ( bIB);
  63.                 //pd3dDevice->DrawIndexedPrimitive ( D3DPT_TRIANGLELIST, 0, 0, 49, 0, 3);

  64.                 pd3dDevice->EndScene ();
  65.         }

  66.         pd3dDevice->Present ( 0,0,0,0);
  67. }
复制代码

9

主题

22

帖子

22

积分

注册会员

Rank: 2

积分
22
 楼主| 发表于 2009-10-30 12:01:00 | 显示全部楼层

Re:对顶点缓冲和索引缓冲的问题

有人能来说点吗?

9

主题

22

帖子

22

积分

注册会员

Rank: 2

积分
22
 楼主| 发表于 2009-10-30 12:09:00 | 显示全部楼层

Re:对顶点缓冲和索引缓冲的问题

自己解决了

0

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2010-9-19 09:22:00 | 显示全部楼层

Re:对顶点缓冲和索引缓冲的问题

请问你怎么解决的,我也遇到了这种问题?

13

主题

63

帖子

79

积分

注册会员

Rank: 2

积分
79
发表于 2010-9-19 09:37:00 | 显示全部楼层

Re: 对顶点缓冲和索引缓冲的问题

这是对性能损失的警告,因为你把顶点和索引存在默认的显存当中,这时模式设置为只写模式可以提高性能。解决的话可以把CreateVertexBuffer和CreateIndexBuffer的Usage参数从0改为D3DUSAGE_WRITEONLY。

0

主题

2

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2010-9-20 09:47:00 | 显示全部楼层

Re:对顶点缓冲和索引缓冲的问题

谢谢,昨天解决了。我的主要问题是在循环中多次创建了顶点缓存和索引缓存,加上If判断只创建一次顶点和索引缓存,问题就解决了。

2

主题

10

帖子

16

积分

新手上路

Rank: 1

积分
16
发表于 2010-9-21 08:28:00 | 显示全部楼层

Re: 对顶点缓冲和索引缓冲的问题

不只是你说的那个问题,文档中说的很清楚Informs the system that the application writes only to the vertex buffer. Using this flag enables the driver to choose the best memory location for efficient write operations and rendering. Attempts to read from a vertex buffer that is created with this capability will fail. Buffers created with D3DPOOL_DEFAULT that do not specify D3DUSAGE_WRITEONLY might suffer a severe performance penalty.abc; Usage can be 0, which indicates no usage valueabc
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-6-4 23:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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