简体   繁体   中英

Is setting the texture parameters for each binding of GL_TEXTURE_2D neccessary?

I was going through some basic opengl tutorials, and want to know if this code could be made better.

My question is in c++, but I believe this would carry over to any other opengl implementation in different languages.

Here is the code:

glGenTextures(1, &texture1);
glBindTexture(GL_TEXTURE_2D, texture1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//load the data for the texture, apply it, the free the data

glGenTextures(1, &texture2);
glBindTexture(GL_TEXTURE_2D, texture2);
//Now the question.

After binding texture2 , is it then neccessary to repeat the glTexParameteri lines, if I want the same effect on both images?

Texture parameters are part of the state of a texture object. When you set texture parameters, you're setting state in that object. So your question is roughly equivalent to "if I do xv = 5; , does that mean yv is also 5 if x and y are the same type?"

When you bind an object to the context and then call a state setting function on that bind point, you are setting state in the object, just as surely as xv = 5 sets state into the object x . OpenGL simply has an unusual spelling for this notion (and sometimes, it's difficult to know without looking it up if a function sets state into an object or the context), but it's the same thing either way.

So no, setting state on one object will not transfer that state to another that just so happens to be bound to that binding point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM