View Full Version : load aunknown number of textures to opengl.

Özgür Özön
03-14-2012, 03:22 AM
I want to load unknown number of textures to opengl. First i thought to create my own variable and it led me to linked list. But i could'n come with a solution. That's why i need your help.

Thanks in advance.

03-15-2012, 04:14 AM
I am not sure what language you using but soon as you said linked list it implies it has pointers. So I am going to guess it is either C or C++.

I am not much of C programer but if you can count the number of meshes during run-time you can make an array at run-time the exact size you need. If you need to swap meshes around a-lot in memory a linked is good for swapping items but has overhead for random access. Also if you are receiving meshes from a source randomly over time a dynamic list structure made from linked lists would be good. If a-lot of this is new to you I recommenced reading up on basic Data Structure and Algorithm design.

If you are using C++ I would recommend using the standard library containers instead of a plain linked list since that would be safer, less prone to memory leaks and likely to perform better. A list of some of the STL's standard containers are the vector, list, queue, dequeue, stack, map, and set. Each of these has there advantages and use. I do not know what your doing with these meshes exactly so I can't say what you need. I would suggest you read up on these basic data structures and there advantages and disadvantages. Also what they are commonly used for to decide what you need. These standardized dynamic containers will most likely perform pretty well. All though I will say its most likely you just need a vector or list.

I will say, but unless you have concrete evidence showing the need to do so just ignore this. If what your are doing is extremely process intensive and your getting too much overhead from the standard containers which is unlikely again very unlikely because these containers are generally optimized very well. You can use the STL's allocator classes to allocate pools of raw memory, and manage memory yourself. The allocator class is used as the base for the STL's standard containers. Also an other reason to use this is if you require a really strange non-standardized data structure, but need better performance than playing with a normal linked lists which can be prone to memory fragmentation.