【问题标题】:OpenGL usampler1D texelFetch is always returning 0OpenGL usampler1D texelFetch 总是返回 0
【发布时间】:2014-03-18 20:35:18
【问题描述】:

我不知道我做错了什么。这是我的 pyopengl 代码的相关部分。

首先,我初始化所有内容,包括采样器和纹理。 bind_context 是我创建的一个上下文管理器,它调用 gl.glUseProgram(self.program_index)

    with self.bind_context():
        # Create sampler.
        self.sampler_object = glGenSamplers(1)

        # Create texture.
        self.texture = gl.glGenTextures(1)

        # Bind sampler to texture unit, and set parameters.
        gl.glActiveTexture(gl.GL_TEXTURE0 + self.texture_unit)
        gl.glBindSampler(self.texture_unit, self.sampler_object)
        gl.glSamplerParameteri(self.sampler_object,
                               gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
        gl.glSamplerParameteri(self.sampler_object,
                               gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glSamplerParameteri(self.sampler_object,
                               gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)

        # Set uniform with texture unit.
        self.obs_index_to_height(self, self.texture_unit)

我时不时需要更新纹理,所以我会这样做:

def update_texture(self, data):
    # Bind texture to texture unit, set paramters and upload texture.
    # ActiveTexture must precede TexParameter, BindTexture,
    # and TexImage.
    print("Setting", data, data.shape[0])
    gl.glActiveTexture(gl.GL_TEXTURE0 + self.texture_unit)
    gl.glBindTexture(gl.GL_TEXTURE_1D, self.texture)
    gl.glTexImage1D(gl.GL_TEXTURE_1D,
                    0,
                    0x8236,  # gl.GL_R32UI,
                    data.shape[0],
                    0,
                    gl.GL_RED_INTEGER,
                    gl.GL_UNSIGNED_INT,
                    data)

打印出来:

Setting [      0       1       2       3       4       5       6       7       8       9      10      11       0       0       0       0] 16

我的顶点着色器是

#version 330

uniform mat4 view;
uniform mat4 projection;

uniform vec2 dimensions;
uniform uint obs_index_base;
uniform usampler1D obs_index_to_height;

uniform vec4 color;

in float time;
in uint obs_index;

void main()
{
    float height = int(obs_index + obs_index_base);
    height = texelFetch(
            obs_index_to_height,
            //int(obs_index + obs_index_base),
            int(5),
            0).r;
    gl_Position = projection * view * vec4(time, -height, 0.0, 1.0);
}

从视觉输出中可以清楚地看出,提取的纹素不是所需的 5,而是 0。

【问题讨论】:

    标签: opengl textures opengl-3 vertex-shader


    【解决方案1】:

    知道了。我的 glGenSamplers 返回一个列表,我将结果解释为一个值。我猜采样器没有被绑定。不知道为什么这不会引发错误,或者我会如何发现错误。

    【讨论】:

      猜你喜欢
      • 2015-09-27
      • 2014-03-20
      • 2013-04-13
      • 2013-03-30
      • 2016-07-13
      • 2023-04-09
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多