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

你可能感兴趣的:(DirectX9 进入缓存内存)