Let's say that I have a function where I want the user to be able to select the appropriate texture with a safe type. Therefore, instead of using GLenum GL_TEXTUREX, I define the method as follows.
void activate_enable_bind(uint32_t texture_num) { const uint32_t max_textures = GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - GL_TEXTURE0; const uint32_t actual_texture = (GL_TEXTURE0 + texture_num); if (texture_num > max_textures) { throw std::runtime_error("ERROR: texture::activate_enable_bind()"); } glActiveTexture(actual_texture); glEnable(target_type); glBindTexture(target_type, texture_id_); }
Is it guaranteed that it works in all implementations based on the opengl specification, or are developers allowed to have
`GL_TEXTURE0 - GL_TEXTURE(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS -1)`
certain non-contiguous way?
I modified my code here too, in what I have:
void activate_enable_bind(uint32_t texture_num = 0) { GLint max_textures = 0; glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_textures); if (static_cast<GLint>(texture_num) > max_textures - 1) { throw std::runtime_error("ERROR: texture::activate_enable_bind()"); } const uint32_t actual_texture = (GL_TEXTURE0 + texture_num); glActiveTexture(actual_texture); glEnable(target_type); glBindTexture(target_type, texture_id_); }
source share