<p>These:</p>
<blockquote>
<pre><code>glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, this-&gt;index_tbo);
</code></pre>
</blockquote>
<blockquote>
<pre><code>uniform samplerBuffer index_tex;
</code></pre>
</blockquote>
<p>Do not match. If the texture is a signed integer texture, then the sampler type needs to match. It should be <code>isamplerBuffer</code>, and you won't need to do the cast.</p>

CC BY-SA 4.0
2020-07-25T20:25:23.607Z
2020-07-25T20:25:23.607Z
Nicol Bolas
<p>I want to send a series of integer to the geometry shader,
while the data will be modified every frame.</p>
<p>But when I try to retrive the sampleBuffer in geometry shader, it seems to keep output zero.</p>
<p>Am I using Texture Buffer wrong, or the TBO itself just can't be used as GL_DYNAMIC_DRAW?</p>
<p><strong>Init Texture Buffer</strong></p>
<pre><code>void InitialTBO() {
    int index_tbo_reserved_size = 5000;
    glGenBuffers(1, &amp;index_tbo);
    glBindBuffer(GL_TEXTURE_BUFFER, index_tbo);
    glBufferData(GL_TEXTURE_BUFFER, index_tbo_reserved_size * sizeof(GLint), NULL, GL_DYNAMIC_DRAW);
    glGenTextures(1, &amp;index_tbo_tex);
}
</code></pre>
<p><strong>Render</strong></p>
<pre><code>void RenderChunkDataCone(Primitive* primitive) {
    Program* shaders = primitive-&gt;shaders;

    shaders-&gt;use();

    glActiveTexture(GL_TEXTURE0);   
    glBindBuffer(GL_TEXTURE_BUFFER, this-&gt;index_tbo);
    glBufferSubData(GL_TEXTURE_BUFFER, 0, sizeof(GLint)*index_tbo_data.size(), index_tbo_data.data());
    glBindTexture(GL_TEXTURE_BUFFER, this-&gt;index_tbo_tex);
    glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, this-&gt;index_tbo);
    shaders-&gt;setUniform(&quot;index_tex&quot;, 0);

    glBindVertexArray(primitive-&gt;vao);
    glDrawElements(primitive-&gt;drawType, primitive-&gt;drawCount * primitive-&gt;drawCount_Inner, GL_UNSIGNED_INT, 0);

    glBindVertexArray(0);
    shaders-&gt;stopUsing();
}
</code></pre>
<p><strong>Geometry Shader</strong></p>
<pre><code>#version 460 core
uniform samplerBuffer index_tex;
vec3 render_primitive(vec3 position){
    int status = int(texelFetch(index_tex, 0).r);
    if(status==0)
        return vec3(0,10,10);
    else if(status==1)
        return vec3(10,0,0);
    else if(status==2)
        return vec3(0,0,10);
}

void main() {
    vec4 position =gl_in[0].gl_Position;
    vec3 returnedValue = render_primitive(position.xyz);
}
</code></pre>
<p>I've confirmed the index_tbo[0] is 1,
But the returnedValue outputed by shader will always be (0,10,10) as the value index_tex[0] received seems to be 0.</p>

<opengl><geometry-shader>
Is it possible to send Texture Buffer to shader dynamically?
Hanakuru
# Is it possible to send Texture Buffer to shader dynamically?

(Asked by: username_0 on 2020-07-25)

I want to send a series of integer to the geometry shader,
while the data will be modified every frame.

But when I try to retrive the sampleBuffer in geometry shader, it seems to keep output zero.

Am I using Texture Buffer wrong, or the TBO itself just can't be used as GL\_DYNAMIC\_DRAW?

**Init Texture Buffer**

```
void InitialTBO() {
    int index_tbo_reserved_size = 5000;
    glGenBuffers(1, &index_tbo);
    glBindBuffer(GL_TEXTURE_BUFFER, index_tbo);
    glBufferData(GL_TEXTURE_BUFFER, index_tbo_reserved_size * sizeof(GLint), NULL, GL_DYNAMIC_DRAW);
    glGenTextures(1, &index_tbo_tex);
}

```

**Render**

```
void RenderChunkDataCone(Primitive* primitive) {
    Program* shaders = primitive->shaders;

    shaders->use();

    glActiveTexture(GL_TEXTURE0);   
    glBindBuffer(GL_TEXTURE_BUFFER, this->index_tbo);
    glBufferSubData(GL_TEXTURE_BUFFER, 0, sizeof(GLint)*index_tbo_data.size(), index_tbo_data.data());
    glBindTexture(GL_TEXTURE_BUFFER, this->index_tbo_tex);
    glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, this->index_tbo);
    shaders->setUniform("index_tex", 0);

    glBindVertexArray(primitive->vao);
    glDrawElements(primitive->drawType, primitive->drawCount * primitive->drawCount_Inner, GL_UNSIGNED_INT, 0);

    glBindVertexArray(0);
    shaders->stopUsing();
}

```

**Geometry Shader**

```
#version 460 core
uniform samplerBuffer index_tex;
vec3 render_primitive(vec3 position){
    int status = int(texelFetch(index_tex, 0).r);
    if(status==0)
        return vec3(0,10,10);
    else if(status==1)
        return vec3(10,0,0);
    else if(status==2)
        return vec3(0,0,10);
}

void main() {
    vec4 position =gl_in[0].gl_Position;
    vec3 returnedValue = render_primitive(position.xyz);
}

```

I've confirmed the index\_tbo[0] is 1,
But the returnedValue outputed by shader will always be (0,10,10) as the value index\_tex[0] received seems to be 0.

**Tags:** opengl, geometry-shader


---

## 1 answers

### Answer by username_1 on 2020-07-25. Score: 2 | Accepted answer

These:

> ```
> glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, this->index_tbo);
>
> ```

> ```
> uniform samplerBuffer index_tex;
>
> ```

Do not match. If the texture is a signed integer texture, then the sampler type needs to match. It should be `isamplerBuffer`, and you won't need to do the cast.


---

