Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Comparing Texture Objects  (Read 4008 times)

0 Members and 1 Guest are viewing this topic.

Kalishir

  • Newbie
  • *
  • Posts: 4
    • View Profile
Comparing Texture Objects
« on: June 06, 2013, 06:20:33 pm »
Am I correct in thinking there is no way to compare two texture objects to determine if they were constructed from the same file?

I am attempting to create a content manager that will help me minimize the number of duplicate textures by returning one from a list if it already exists. However I cannot seem to build a predicate function that returns properly.

Taking a quick look at the source files I did see that Equals and GetHashCode for Textures has not been overridden; which is what I was initially using to compare the objects. (This will, of course, return false).

Has anyone else had any luck doing something similar to what I am attempting.
« Last Edit: June 06, 2013, 06:24:50 pm by Kalishir »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Comparing Texture Objects
« Reply #1 on: June 06, 2013, 07:01:04 pm »
You can use a Dictionary<TKey, TValue> to hold your textures. Make the TKey the path to the file and the TValue the texture. Then when you go to load/grab the texture you can use Dictionary<TKey, TValue>.ContainsKey(TKey) to determine of the file has already been loaded.

Here is the MSDN reference for Dictionary<TKey, TValue>.
« Last Edit: June 06, 2013, 07:04:22 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Kalishir

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Comparing Texture Objects
« Reply #2 on: June 06, 2013, 07:19:22 pm »
Yeah, I had considered that, but I was hoping to not have the overhead of a Dictionary. Not to mention its troubles when you have a lot of inserts/deletions.

If that's the best way though, so be it.
« Last Edit: June 06, 2013, 07:31:34 pm by Kalishir »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Comparing Texture Objects
« Reply #3 on: June 06, 2013, 08:08:08 pm »
Yeah, I had considered that, but I was hoping to not have the overhead of a Dictionary. Not to mention its troubles when you have a lot of inserts/deletions.

Be wary of premature optimizations  ;)

Because unless your storing a huge amount of textures you aren't going to even know about the Dictionaries overhead. And if you are storing that many textures I think you would run out of VRAM first  :D

If your concerned over the 22 or so bytes each KeyValuePair holds you probably should consider moving to C++ if your that concerned over memory. In fact for what you are trying to do is exactly what makes a Dictionary better than a List. Take a look at the following links.

http://stackoverflow.com/questions/2300859/dictionary-performance
http://social.msdn.microsoft.com/Forums/en-us/csharpgeneral/thread/3fc4c78d-7cd1-47a1-a23e-ab7b0786c192
http://www.dotnetperls.com/dictionary-time
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor