[.net] [SlimDX]Sorting textures

Started by
2 comments, last by De Cowboy 16 years, 6 months ago
While trying to create a sprite rendering class, I found that grouping the sprites based on texture gained a nice speed improvement. However, I am currently sorting the sprites on an ID given to them when I load them, which isn't very practical. How can I sort them on the internal texture pointer they have? I tried modifying slimdx to make the internal pointer public, but I couldn't see it since I don't reference the directx sdk in my game.
Advertisement
You can't, really, without building some machinery yourself.

One option is to maintain a Dictionary<int,Texture> mapping the IDs you already give your sprite to textures they use. Another option is to map from texture file name to Texture object.

The internal pointer is intentional not exposed; you can't usefully do anything with it, as you discovered. There is some talk of possibily exposing underlying pointers as a CLI compatible IntPtr type, but I don't know what the status of that is.
Quote:Original post by jpetrie
There is some talk of possibily exposing underlying pointers as a CLI compatible IntPtr type, but I don't know what the status of that is.
We've decided to do it, it just hasn't been done yet. By exposing an IntPtr, you're able to at least compare it, pass it to other libraries, etc. You can do more with unsafe code, but it's a lot of work. Anyway, it will look like this:
property IntPtr NativePointer{    IntPtr get() { return IntPtr( m_Pointer ); }}
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Thanks, comparing the IntPtr's is a nice solution!

This will also work with textures that aren't loaded from a file, so I think it's the cleanest. The only ugly part is having to convert the pointers to a int, but that's how the framework is set up, I suppose..

This topic is closed to new replies.

Advertisement