Skip to main content
gamedev.net
🔒 Locked

Texture Management

Started by zxc 6 replies 750+ views
Original Post
zxc
zxc
I''m trying to write a simple texture manager for my OpenGL engine. The main thing I want it to do is avoid loading the same texture more than once, even if it''s being used by several objects. Now my question is how do I store the texture information in the manager and how can I quickly verify if a texture is already loaded? Comparing the name of the file i''m trying to load with all the loaded filenames would be much too slow. I''ve seen a couple of posts in the forums here about this but they didn''t answer my questions. Anyone ever implemented this kind of manager in an efficient way? thanks zxc
zedzeek
zedzeek
>>Now my question is how do I store the texture information in the manager and how can I quickly verify if a texture is already loaded? Comparing the name of the file i''m trying to load with all the loaded filenames would be much too slow<<

why not i do this (plus i also check other stuff than filename eg mipmaps etc) but its not gonna yake long cause youre not gonna be using millions of different textures in your scene

http://uk.geocities.com/sloppyturds/gotterdammerung.html
alargeduck
alargeduck
What zedzeek is true, youre probably not going to have more than a handful of textures. I dont think a typical Quake3 level uses more than about 40 textures.

I dont like the idea of repeatedly searching through a list of strings to find the right textures either. So I only do it once... I do this:

IMAGE * image = R_FindImage("texture.tga");

If the texture isnt loaded, it gets loaded. I get a pointer to its structure that I can use. Now I dont do it every frame, only when initializing.

Even if you do this every frame, it shouldnt take too much time. Maybe to speed it up, you could classify textures into groups, ie R_FindWorldImage, R_FindGUIImage, so on. Then there is a smaller subset of textures to check.

An idea I just had: (little offtopic)

For every texture, store an int that counts how many times its been accessed. That is, every time some part of the program does R_FindImage, increment that counter. Then when that part of te program is done with it - it will call UnloadTexture() or something - decrement the counter. Now if the counter reaches 0, it can be unloaded.
_the_phantom_
_the_phantom_
there is a section in Game Programming Gems on singletons which covers the idea above for texture loading I belive.

Implementing a singleton using the above system is prefect for this job I belive.
Now, all we need is some kinda access counter and a way to force textures onto the onboard V-RAM which are used lots and we''d be away.. roll on OGL2.0
psijgo
psijgo
i''m planning on writing a texture manager class myself.
unless you dont want to use classes, i could send it to you when finished (or at least, working.).

- jeffrey
zxc
zxc
psijgo: Actually my manager was already (almost) finished when I asked this question and I was already using stl::map like siaspete suggested, I just had the impression that the string compares would slow things down a bit if textures had to be loaded while rendering. But I'd still be interested in seeing how you did it, might give me a few good ideas! Just e-mail me if you want when it's done.

I used a singleton class with refcounts for each texture to they get unloaded automatically. I also used a STL map to store the info since the STL map uses a hash table internally (right?) and this should be faster, the only problem is that it forces me to use a fixed array length for filenames (I can't just do map[char*, unsigned int], this would only compare the pointers).

zedzeek: Any chance I could see your implementation, keeping the mipmaping info and all seems like a good idea.

Thanks!

[edited by - zxc on May 25, 2002 12:21:13 PM]
psijgo
psijgo
quote:
Original post by zxc
psijgo: Actually my manager was already (almost) finished when I asked this question and I was already using stl::map like siaspete suggested, I just had the impression that the string compares would slow things down a bit if textures had to be loaded while rendering. But I''d still be interested in seeing how you did it, might give me a few good ideas! Just e-mail me if you want when it''s done.


sure np, although i''m not sure if my way can teach you anything, seeing it''s really my first attempt to write a texman as well.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.