Sharing Textures Between Classes

I’m trying to reorganize my program, and I’m having a bit of difficulty. Currently all of my texture initializations and texture operations are in the main file, but that file is getting huge. I want to make a new class for some of the items and functions that go together. That way I can put those functions in their own file.(What I’m working with is a GPGPU simulation using particles and a grid. All of the computation operations are done with textures and fragment programs. I’m trying to break up some of the operations, like “moveParticles” into another file.)

What I’m confused about is how to share my textures between my created class and the main file. Like if I have a call to draw a textured polygon in a “particles” class.
[ul][li]If I initialize a texture in my “particles” class, how can I reference and use that texture in my main file?[]On the same note, how can I use a texture created in the main file in my “particles” class? How would I “pass” it?[]Or should I only create/initialize textures in the main file?[/ul][/li]
I understand passing objects to classes, but I don’t know how to refer to a texture other than by it’s textureID.

  1. a texture id is basically just a unsigned integer, if you can pass around objects, you can pass these around pretty simple.
    Just create a function in the class that returns it.

  2. I prefer managing all my textures in a globally available texture management class.
    Remember, statics are your firends.

Okay, that makes sense. I like the idea of the texture management class. I’m also using framebuffer objects, so maybe I can create a class for that, too. (Or actually, I think I’ve seen a class for FBOs. Maybe I can look at that to see how it works.)

Use a singleton.

You could use the same approach for a number of different things, such as VBOs and shader objects. If objects share common graphics resources, why create them again when you can share them! Doing stuff like this will make it easier if you plan to implement any kind of state sorting later on.

What’s a singleton?