如何获得最大数量的多纹理单元 [英] How to Get Max Number of Multitextured Units

查看:339
本文介绍了如何获得最大数量的多纹理单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个功能,希望用户能够以类型安全的方式选择适当的纹理.因此,我定义了如下方法,而不是使用GL_TEXTUREX的GLenum.

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.

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规范的实现中使用,还是允许实现者拥有

Is this guaranteed to work under all implementations based on the opengl specification, or are implementers allowed to have

`GL_TEXTURE0 - GL_TEXTURE(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS -1)` 

以非连续方式定义?

我也在这里修改自己的代码:

I was modifying my code aswell here 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_);
}

推荐答案

我认为GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS本身并不是一个有用的值,而是您传递给

I think GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is not on its own a useful value, but is something that you pass to glGet to retrieve the actual value. To account for that, you'd retrieve it like this:

GLint max_combined_texture_image_units;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_combined_texture_image_units);
// and then maybe check for errors

关于添加到GL_TEXTURE0中,这是安全的; OpenGL 3.2核心规范的§ 3.8 表示:

As for adding to GL_TEXTURE0, that is safe; §3.8 of the OpenGL 3.2 Core specification says this:

如果指定了无效的纹理,则

ActiveTexture 会生成错误INVALID_­ENUM. texture 是形式为TEXTURE i 的符号常量,表示该纹理 i 单位将被修改.常数服从TEXTURE i = TEXTURE0+ i ( i 在 范围从0到 k − 1,其中 k MAX_­COMBINED_­TEXTURE_­IMAGE_­UNITS的值.)

Active­Texture generates the error INVALID_­ENUM if an invalid texture is specified. texture is a symbolic constant of the form TEXTUREi, indicating that texture unit i is to be modified. The constants obey TEXTUREi = TEXTURE0+i (i is in the range 0 to k − 1, where k is the value of MAX_­COMBINED_­TEXTURE_­IMAGE_­UNITS).

这篇关于如何获得最大数量的多纹理单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆