Building an Object Pool for Textures

Next, you should think about a problem that wasn't all that important when you were writing the Blockers game but could present itself as a problem now. What if you had three or four different objects that all used the same texture? In the Blockers game, you simply would have loaded the same texture three or four times, which does indeed work; however, I'm sure you can realize that the extra “wasted” space can't be a good thing. Instead of having a system like that, wouldn't it be so much nicer if you had a “cache” of textures so that whenever you created one, you would never re-create it again? That's what you should do now.

Building this object pool is actually pretty easy because you can use one of the ...

Get Beginning 3D Game Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.