PDA

View Full Version : Sharing Textures Between Classes



flan
03-30-2007, 06:26 PM
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.
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?

I understand passing objects to classes, but I don't know how to refer to a texture other than by it's textureID.

zeoverlord
03-31-2007, 01:21 PM
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.

flan
04-02-2007, 06:11 PM
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.)

Vaticanfox
04-02-2007, 08:16 PM
Use a singleton.

Vaticanfox
04-02-2007, 08:33 PM
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.

flan
04-03-2007, 10:01 AM
What's a singleton?

Vaticanfox
04-03-2007, 11:01 AM
http://en.wikipedia.org/wiki/Singleton_pattern