title: How to Get Max Number of Multitextured Units
body: <p>Lets say I have a function where I want the user to be able to select the appropriate texture in a type safe manner. So instead of using a GLenum of GL_TEXTUREX I define a method as follows.</p>
  
  <pre><code>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 &gt; max_textures) {
      throw std::runtime_error("ERROR: texture::activate_enable_bind()");
    }
  
    glActiveTexture(actual_texture);
    glEnable(target_type);
    glBindTexture(target_type, texture_id_);
  }
  </code></pre>
  
  <p>Is this guaranteed to work under all implementations based on the opengl specification, or are implementers allowed to have </p>
  
  <pre><code>`GL_TEXTURE0 - GL_TEXTURE(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS -1)` 
  </code></pre>
  
  <p>defined in a non-contiguous manner?</p>
  
  <p>I was modifying my code aswell here in what I have:</p>
  
  <pre><code>void activate_enable_bind(uint32_t texture_num = 0)  {
    GLint max_textures = 0;
    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &amp;max_textures);
    if (static_cast&lt;GLint&gt;(texture_num) &gt; 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_);
  }
  </code></pre>