Texture Objects and ID's
Okay, so I know in OpenGL you create a texture ID with glBindTexture(...)
A few questions..
Does this create an ID you tell it to create? If you bind a texture, you have to give it an ID yourself? Or does it have some kind of stack in the background so you don't ever repeat texture ID's?
I'm having issues in creating a generic bitmap texture object because I need to generate ID's for glBindTexture without repeating them..
I basically want to have a Bitmap class with a pointer to the bitmap data in memory in it as well as an ID..
So when I want to texture something (by way of my resource manager), I can do this easily because I can access any texture via the resource manager based on a texture string.
You don't create an ID with any OpenGL function. All glBindTexture does, is binds loaded texture data to an ID.
Variations can be made of this method to suit your needs. All your really doing, is passing the texture data, through and unsigned integer via glBindTexture(). The texture is initialized with glGenTextures().
GLuint CreateTexture(int texId)
GLuint texture = CreateTexture(0);
Texture creation is frairly straight forward, but if you have any questions (or, more likely, if this isn't what you mean/were looking for), just ask :)
Oh, so no matter what you have to input the texture ID yourself?
Well, the problem with creating a texture object, is that somewhere I need to keep track of texture ID's so I don't repeat them..
I can't just add 1 to the tex ID counter every time in the object, I have to do it somewhere else so I don't repeat them..
Somewhere I need to keep track of texture id's
Ok, so rather than take the textureID from a function arg, just increment the texture ID after each texture is created.
int texcount = 0;
GLuint CreateTexture() //new texture creation function
//do other texture stuff...
Good idea, but the thing is..
Hmm, how to explain this..
Okay, so we have an object
In bitmap texture, we have a tex ID gluint, we have a load function...
Now, to create a new texture, I'll be using my resource manager..
All I have to do is pass my resource manager a string, and it will automatically load a texture using a new bitmap texture object..
For every type T_ replace it with a Bitmap Texture object.. Now you understand how this works.. it returns a pointer resource observer, which I can use to access the tex ID inside the object.
Resource_Observer Request_Resource(const std::string & name)
Resource_Map::iterator it = mResources.find(name);
if (it == mResources.end())
Resource_Ptr Raw_Resource(new T_);
The beauty of this is that I will never repeat textures in memory, but I can still access them magnificently easy through ID's. Well, at this point we're accessing them through strings, but they have the ID's in them..
I can't make the load function manage ID's, it kinda has to get them from somewhere else, seeing as we'll have multiple instances of these objects.
So, what should I do? Should I keep a global GLuint of ID's, and increase that one, and then get that gluint and increase it for the ID's?
I just noticed you had texcount declared globally, guess that is what I'll do....