Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad to set glTexParameteri() during render time?

I am facing issues with texture wrapping. which is causing artifacts. Since my codebase has grown huge the only way that I can think of is to perform certain checks to see if certain textures fall under the category which are causing artifacts and change the parameters before drawing onto the renderbuffer.

So is it generally ok? to set parameters like

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);

after glBindTexture during render loop? or would it effect FPS as it would increase operations during each render frame?

like image 549
Gamer Avatar asked Jul 30 '12 12:07

Gamer


Video Answer


2 Answers

Changing texture parameters usually doesn't have a too serious impact on performance, as it leaves caches intact and only changes the access pattern.

However in later versions of OpenGL for this very specific usage scenario "Sampler Objects" have been introduced. I think you might want to have a look at them.

like image 68
datenwolf Avatar answered Nov 15 '22 06:11

datenwolf


The general rule of thumb is this: do not change any state you don't have to.

If a texture has an intrinsic property that makes you use a mirrored-repeat wrapping mode, then it should always have that property. Therefore, the texture should have been originally set with that wrapping mode.

If it's something that you need to do at render time, then yes, you can do it. Whether it affects your performance adversely depends entirely on how CPU bound your rendering code is.

Note:

Since my codebase has grown huge

This is never a good reason to do anything. If you can't figure out a way to make your code do this the right way, then something bad has probably happened within your codebase. And you should fix that before trying to deal with this texture issue.

like image 38
Nicol Bolas Avatar answered Nov 15 '22 06:11

Nicol Bolas