PDA

View Full Version : glActiveTexture(), shader vs. pre-shader



sam_thedancer
06-09-2013, 01:26 AM
Greetings:
I see in a GL 2.1 shaderless program using two textures that they are bound


glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri()...
glTexImage2D()...

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri()...
glTexImage2D()...

Particularly, no glActiveTexture() command, which I guess means by default glActiveTexture(GL_TEXTURE0).

However, a similar GL4.3 program using shaders clearly requires
glActiveTexture(GL_TEXTURE0) before binding the first texture and then
glActiveTexture(GL_TEXTURE1) before binding the next.

Why the apparent difference in treatment between GL 2.1 and 4.3?
Thanks in advance,
Sam

Alfonse Reinheart
06-09-2013, 05:31 AM
They're doing different things.

The point in the 2.1 code where you're seeing those bind texture calls is doing texture setup work. They're not rendering with them yet. You'll see similar code in 4.3 code.

The place where you're seeing active-texture calls before binding is for rendering. And you'll see that same code for any non-shader program that uses more than one texture on an object.

sam_thedancer
06-09-2013, 11:06 PM
Thanks, Alfonse. But I must be missing something. There is no glActiveTexture(GL_TEXTURE1) call anywhere in the non-shader program though it applies two 2D textures to the scene drawn. In fact, there is no glActiveTexture() call at all anywhere in the code. Shouldn't there be?

(Btw, there's a typo in my first post: that should be glBindTexture(GL_TEXTURE_2D, texture[1]) in the second statement block).

Dan Bartlett
06-10-2013, 03:40 AM
It's probably using some multi-pass technique, as opposed to a multi-texturing approach. If you check closer, you'll probably see it draws the same object multiple times, applying one texture at a time and using blending to add to what already exists in the frame buffer, rather than applying multiple textures to the object in one go.

sam_thedancer
06-11-2013, 01:02 PM
Thanks, Dan.