Correct lock for the job in hand.

Started by
1 comment, last by Dark_Light 19 years, 4 months ago
Hi all, This post is not so much after an answer but more towards advice on this subject. Vertex, Index, Texture and Attribute locking. I know about each lock type (well as much as you can know from the SDK) but I want to ask for advice from more experienced people about what locks I should use and when. If you could read over each Scenario and let me know what you think. Scenario 1 (Just wanting to read the data but don’t plan to update or return it) Use Lock.None Do I need to unlock after?? Scenario 2 (Just writing data into the buffer. We don’t care what data use to be in it, Ie we never read it) Use Lock.Discard Scenario 3 (Reading the data that’s in the buffer and changing it) Use Lock.Discard That’s is. Please comment as much as you like, I want to know details about what each lock REALY douse and If I am using the correct lock flags. Thanks
Advertisement
When you lock data, you are taking control of data owned by the video driver. If the data is using in a waiting render, then the driver will wait for that render to complete before returning from the lock to avoid you messing it all up (or it may have to convert the data from another format or something). The flags override this by telling the driver that you are not going to mess up anything it's using, or not going to read the contents etc.

So,
1) (Why do you need to do this? It's better not to) Use Readonly and Nooverwrite to tell it you aren't going to change anything.

2) Discard only if you are overwriting everything (which the driver will probably optimise anyway and not wait for a render), but you might just want to add stuff (like a circular buffer), in which case use Nooverwrite.

3) Don't use discard because the data won't be valid to read from. There are no specific flags here as it's the worst option to use.

Thanks, that is very helpfull

This topic is closed to new replies.

Advertisement