Jump to content
  • Advertisement
Sign in to follow this  
wswqwps

A problem about the Lock() function

This topic is 4116 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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!