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
SortedListwith a customIComparerconsidering the texture member being used (e.g. byName)? 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.