Direct3D VertexBuffer Lock() and Unlock() function

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

the IDirect3DVertexBuffer9 has that methods

STDMETHOD(Lock)(THIS_ UINT OffsetToLock,UINT SizeToLock,void** ppbData,DWORD Flags) PURE
STDMETHOD(Unlock)(THIS) PURE

I don't know the internal implementation of these functions. I do expect next.

  1. The 'Lock' method maps a VertexBuffer's video memory to ppbData. it gains much fater performance.

  2. The 'Lock' method is allocs a system-mem and make ppbData to point it. And the 'UnLock' method is copy that memory to real video memory. this approach by placing a abstraction layer in hardware eliminates differences.

i guess that : in 'D3DPOOL_SYSTEMMEM' mode, it implemented by way 2. in 'D3DPOOL_DEFAULT' mode, it implemented by way 1.

/* Pool types */
typedef enum _D3DPOOL {
    D3DPOOL_DEFAULT                 = 0,
    D3DPOOL_MANAGED                 = 1,
    D3DPOOL_SYSTEMMEM               = 2,
    D3DPOOL_SCRATCH                 = 3,

    D3DPOOL_FORCE_DWORD             = 0x7fffffff
} D3DPOOL;

but i don't know how implemented in every D3DPOOL mode. help me~~

share | improve this question
  add comment

1 Answer

In D3DPOOL_DEFAULT, buffer contents are lost when fullscreen device loses focus and device is "lost" (D3DERR_DEVICENOTRESET or D3DERR_DEVICELOST). In this case, data within buffer is expected to be stored in video memory.

In D3DPOOL_MANAGED, a copy of data (that is stored within video memory) is stored in system memory, and as a result driver will restore it when device is lost.

D3DPOOL_SCRATCH is unsupported for vertex buffers.

D3DPOOL_SYSTEMMEM, will not guarantee better performance, because you'll be transferring data - frequently - from system memory to video memory in order to use this vertex buffer. For better performance on buffers that are frequently updated there are dynamic vertex buffers (see D3DUSAGE_DYNAMIC, D3DLOCK_DISACRD, D3DLOCK_NOOVERWRITE), which are located in D3DPOOL_DEFAULT. Also, Direct3D9 documentation says that resources created in system memory are normally not accessible for D3D9 device. For rendering from system memory there are DrawIndexedPrimitiveUP and DrawPrimitiveUP which are bound to cause problems on pure D3D9 device.

Also, there's absolutely no guarantee that either flag makes device work as you think. If common sense tells you it should work this way, but this is not documented in specification, according to Murphy's law, it probably doesn't work the way it should. For all practical purposes, driver implementation could be written by insane lunatic, as long as it conforms to Direct3D specification.

Another thing is that those functions are documented. DirectX SDK comes with several help files - *.chm that can be read on any windows system, .HxI/.HxS that integrate into visual studio, plus there's online help on MSDN, which includes explanation for D3DPOOL. If you're asking questions like this, you haven't done the homework and did not read documentation. So go ahead and read it. If Direct3D9 documentation is no longer included into latest SDK, then simply get older version of it (summer of 2004).

share | improve this answer
  add comment
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值