ユーザーがタイプ セーフな方法で適切なテクスチャを選択できるようにする関数があるとします。したがって、GL_TEXTUREX の GLenum を使用する代わりに、次のようにメソッドを定義します。
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_);
}
これは、opengl 仕様に基づくすべての実装で動作することが保証されていますか、それとも実装者は許可されていますか?
`GL_TEXTURE0 - GL_TEXTURE(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS -1)`
不連続な方法で定義されていますか?
私が持っているもので、ここでもコードを変更していました:
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_);
}