DirectX9 进入缓存内存

C++ 进入缓存内存

We obtain a pointer to its contents by using theLockmethod. It is important to unlock the buffer when we are done accessing it.

HRESULT IDirect3DVertexBuffer9::Lock(
UINT OffsetToLock,
UINT SizeToLock,
BYTE** ppbData,
DWORD Flags
);


HRESULT IDirect3DIndexBuffer9::Lock(
UINT OffsetToLock,
UINT SizeToLock,
BYTE** ppbData,
DWORD Flags
);


OffsetToLock—Offset, in bytes, from the start of the buffer to the location to begin the lock. See Figure 3.1.

SizeToLock—Number of bytes to lock

ppbData—A pointer to the start of the locked memory.Specifying zero for both of these parameters is a
shortcut to lock the entire buffer.

Flags—Flags describing how the lock is done. This can be zero or a combination of one or more of the following flags:

  D3DLOCK_DISCARD—This flag is used only for dynamic buffers. It instructs the hardware to discard the buffer and return a pointer to a newly allocated buffer. This is useful because it allows the hardware to continue rendering from the discarded buffer while we access the newly allocated buffer. This prevents the hardware from stalling.

  D3DLOCK_NOOVERWRITE—This flag is used only for dynamic buffers. It states that you are only going to append data to a buffer. That is, you will not overwrite any memory that is currently being rendered. This is beneficial because it allows the hardware to continue rendering at the same time you add new data to the buffer.

  D3DLOCK_READONLY—This flag states that you are locking the buffer only to read data and that you won’t be writing to it. This allows for some internal optimizations.

The following example shows how theLockmethod is commonly used. Note how we call the Unlockmethod when we are done.

Vertex* vertices;
_vb->Lock(0, 0, (void**)&vertices, 0); // lock the entire buffer
vertices[0] = Vertex(-1.0f, 0.0f, 2.0f); // write vertices to
vertices[1] = Vertex( 0.0f, 1.0f, 2.0f); // the buffer
vertices[2] = Vertex( 1.0f, 0.0f, 2.0f);
_vb->Unlock(); // unlock when you’re done accessing the buffer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值