Theory of multitexturing with texture objects and samplers

I could not find any good theory articles on how to encode multitexturing only with texture objects or with texture objects plus samplers. I just don't know how to control the glActiveTexture function and what it exactly does.

glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0 + 0); // Number between 0 and GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img.getSize().x, img.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.getPixelsPtr()); // Not in sampler
glGenerateMipmap(GL_TEXTURE_2D); // Not in sampler

/* Values associated with the texture and not with sampler (sampler has priority over texture).
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);*/

glGenSamplers(1, &textureSampler);
glBindSampler(0, textureSampler);
glSamplerParameteri(textureSampler, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri(textureSampler, GL_TEXTURE_WRAP_T, GL_REPEAT);
glSamplerParameteri(textureSampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glSamplerParameteri(textureSampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

glUniform1i(glGetUniformLocation(colorShader->program, "textureSampler"), 0); // 0 pour GL_TEXTURE0

Am I a little confused if multitexturing is due to the presence of several samples in fragment code associated with several textures, or if it has only one sampler with several textures?

+3
source share
2 answers

, , , , , , , . , , .

(2D, 3D ..). , , . , :

glBindTexture(GL_TEXTURE_2D, texId1);
glBindTexture(GL_TEXTURE_3D, texId2);

texId1 texId2 , , .

, . . .

glGenTextures(), glBindTexture() .. :

  • .
  • , , , , glTexParameteri().

/ , .

OpenGL , . , , -. .

glActiveTexture() . , , . :

glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, texId);

texId 3. , ( 0) texId.

, OpenGL 3.3 . , . , , .

, , , , , ? , , , . , .

, . , LINEAR NEAREST . , ( ). Sampler .

, OpenGL 4.3. , , .

( ) , . . , , .

, , , . .

, , . . , "MyFirstTexture" - , , 3:

GLint loc = glGetUniformLocation(prog, "MyFirstTexture");
glUniform1i(loc, 3);

:

glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, texId);

. , (3), glActiveTexture() (GL_TEXTURE3). , API, .

, , , ( "-" ):

  • .
  • glUniform1i(), .
  • .

, 0 1:

glUseProgram(prog);

GLint loc = glGetUniformLocation(prog, "MyFirstTexture");
glUniform1i(loc, 0);
loc = glGetUniformLocation(prog, "MySecondTexture");
glUniform1i(loc, 1);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texId0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texId1);

, . . ( ), "" ( glActiveTexture()/ glBindTexture ( ) `.

, : . , ( ). ( ). , .

+11

, , . , glTexParameter.

0

Source: https://habr.com/ru/post/1626776/


All Articles