Sign in to follow this  

A problem about the Lock() function

This topic is 3869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to lock a vertex buffer,and I found in DXSDK document the description was: [To lock the entire vertex buffer, specify 0 for both parameters, SizeToLock and OffsetToLock.] I don't know why.I thought the parameter [SizeToLock] should be sizeof(vb),and if [SizeToLock] was 0,the size locked would be 0. Could anyone help me,please?

Share this post


Link to post
Share on other sites
What's the problem, exactly?

Specifying 0 for both parameters will lock the entire vertex buffer. You can't lock zero bytes, because then how would D3D give you a pointer to the locked data?

Share this post


Link to post
Share on other sites
I am sorry for forgetting define the var vb.It should be:

LPDIRECT3DVERTEXBUFFER9 vb;

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
What's the problem, exactly?

Specifying 0 for both parameters will lock the entire vertex buffer. You can't lock zero bytes, because then how would D3D give you a pointer to the locked data?


I am sorry my English is poor.
I mean if I set the parameter [SizeToLock] to 0 ,I can lock the entire vertex buffer.And if I set it to [sizeof(*vb)] like this:


LPDIRECT3DVERTEXBUFFER9 vb;
vb->Lock(0, sizeof(*vb)/* Not 0 */, (BYTE**)&pVertices, 0 ) ) ) ;


Can I lock the entire vertex buffer?




Share this post


Link to post
Share on other sites
It's just a convention. Besides why would anybody want to lock zero bytes of a buffer? On the other hand, locking an entire buffer is very common which is just made easier by not requiring the size to be computed and passed.

Share this post


Link to post
Share on other sites
sizeof(*vb) would be equal to the size of a IDirect3DVertexBuffer9 object, not how much vertex data you have allocated when you created it. Using that as your LockSize argument would probably only lock part of your vertex buffer. Other than that, it makes no logical sense to use it.

Share this post


Link to post
Share on other sites

This topic is 3869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this