【问题标题】:OpenGL sampler object not updating bound textureOpenGL采样器对象不更新绑定纹理
【发布时间】:2014-01-10 12:02:04
【问题描述】:

我目前正在将采样器对象绑定到纹理单元(具体为 GL_TEXTURE12)

glBindSampler(12, sampler)

与纹理本身的设置相比,初始设置非常明显。但是当我用

更改采样器参数时

glSamplerParameteri(sampler, GL_TEXTURE_***_FILTER, filter);

绑定到纹理单元的纹理过滤器与之前一样,从任何角度来看都没有明显变化。

我已经尝试在参数更改后再次将采样器重新绑定到纹理单元,但我很确定这不是必需的。

我可以进行哪些更改才能使其正常工作?

【问题讨论】:

  • 您不将纹理绑定到采样器,它们始终绑定到纹理图像单元。采样器对象唯一改变的是,当非零采样器对象绑定到纹理图像单元时,它们将采样器状态与纹理对象分开。为了更清楚一点,GL_TEXTURE12纹理图像单元的名称...纹理对象和采样器对象的绑定点。我知道这听起来像是很多迂腐的废话,但您的部分问题可能是对术语的误解。
  • 我完全理解。您刚刚告诉我一堆我已经知道的无用信息:P 谢谢,我编辑了问题以反映您指出的问题。
  • 你能显示更多的代码吗?特别是,将纹理对象绑定到纹理单元 12 的代码。即使在更新问题之后,声明:“我已尝试将纹理单元再次绑定到采样器 [...]”的措辞令人困惑。
  • 如果您觉得我的措辞令人困惑,那么我认为您无法帮助我;不过,我想我的意思是说我将采样器绑定到纹理。纹理通过我所有网格的循环绑定到单元,如下所示:gl::ActiveTexture(gl::TEXTURE12);gl::BindTexture(gl::TEXTURE_2D, textures[meshes[x]->current_texture]);

标签: c opengl texture-mapping


【解决方案1】:

因为我无法解释为什么会这样说:“我已经尝试在参数更改后再次将纹理单元重新绑定到采样器,但我很确定这不是必需的。” 在 cmets 中没有意义,请考虑以下 C 伪代码。

/* Thin state wrapper */
struct SamplerObject {
  SamplerState sampler_state;
};

/* Subsumes SamplerObject */
struct TextureObject {
  ImageData*   image_data;
  ...
  SamplerState sampler_state;
};

/* Binding point: GL4.x gives you at least 80 of these (16 per-shader stage) */
struct TextureImageUnit {
  TextureObject* bound_texture; /* Default = NULL */
  SamplerObject* bound_sampler; /* Default = NULL */
} TextureUnits [16 * 5];


vec4 texture2D ( GLuint n,
                 vec2   tex_coords )
{
  /* By default, sampler state is sourced from the bound texture object */
  SamplerState* sampler_state = &TextureUnits [n]->bound_texture->sampler_state;

  /* If there is a sampler object bound to texture unit N, use its state instead
       of the sampler state built-in to the bound texture object. */
  if (TextureUnits [n]->bound_sampler != NULL)
    sampler_state = &TextureUnits [n]->bound_sampler->sampler_state;

  ...
}

我认为混淆的根源在于,在 GLSL 中,用于识别从哪个纹理图像单元(以及如何)采样的制服称为 sampler[...]。希望这能消除一些困惑,让我们都在同一个页面上。

【讨论】:

  • 那么您就无法将纹理单元绑定到采样器。唯一有意义的情况是,如果您将 GLSL 采样器与采样器对象混淆了。
  • 我不明白你的论点,除非你将它绑定到纹理单元,否则采样器对象将毫无用处。
  • @CoffeeandCode:这正是我的观点,您不会将纹理单元绑定到采样器对象。您将采样器对象绑定到纹理单元。我认为伪代码很清楚:-\
  • 我已经在上面的评论中澄清了这一点:“我想我的意思是说我将采样器绑定到纹理单元,但是”
  • @CoffeeandCode:对不起,我不知道你的意思,因为你说的是​​“纹理”而不是“纹理单元”。 "Texture" 本身通常意味着纹理对象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 2017-12-27
  • 1970-01-01
  • 1970-01-01
  • 2015-09-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多