简体   繁体   中英

C# Efficient way to compare Texture2D textures?

In my program I have numerous Entity classes with a Texture2D attribute that are added to a List<> container to iterate through their draw functions. I want to group Entities with identical textures together so that they can be batched efficiently in my SpriteBatch without it flushing out whenever the previous textures differ.

What is an efficient way to compare the Texture2D classes with each other for my sorting method? I only need a boolean result as to whether or not it is the same texture. I was thinking of using getData() to compare pixels, but that seems brutally inefficient. Is there a better way?

How about using a SortedList with a custom IComparer considering the texture member being used (eg by Name )? That way you should be able to sort all your objects by texture upon adding them to the list. Just don't forget that you might want to draw specific entities in front of others and strict sorting might not be the best option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM