<blockquote>
<pre><code>glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);
</code></pre>
</blockquote>

<p>This is not an <a href="https://www.opengl.org/wiki/Image_Format#Color_formats" rel="nofollow">integer image format</a>. It's an unsigned, normalized, fixed-point image format. For those, you use floating-point image/sampler variables. So for a 3D texture, you would use <code>image3D</code>, not <code>iimage3D</code>.</p>

<p>If you want a <em>true</em> signed integer format, you would do this:</p>

<pre><code>glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32I, width, height, depth, 0, GL_RGBA_INTEGER, GL_INT, NULL);
</code></pre>

<p>Note two changes. First, the internal format is <code>GL_RGBA32I</code>, which specifies a 32-bit-per-channel signed integer format. The second is the use of <code>GL_RGBA_INTEGER</code> for the <a href="https://www.opengl.org/wiki/Pixel_Transfer#Pixel_format" rel="nofollow">pixel transfer format</a>. Even though you're not actually performing a pixel transfer (since you're passing NULL), you still must use an appropriate format and type. And the <code>_INTEGER</code> formats must be used if you're transferring to/from a texture with an integer format.</p>

<p>When you do this, you must of course use the <code>iimage3D</code> and <code>isampler3D</code> types in your shaders.</p>

CC BY-SA 3.0
2016-11-01T11:40:31.747Z
Thanks for hints. I corrected glTexImage3D function as you pointed but the problem seem to persist. What I noticed is that when I setup texture as RGBA32F, RGBA, GL_FLOAT and then bind it as RGBA32I image and use iimage in shader it works. But if I setup texture as RGBA32I, RGBA_INTEGER, GL_INT is is empty. So it is something with texture setup still. But it *is* correct and glGetError returns 0... I updated my nvidia drivers but this is not driver fault.
mdkdy
CC BY-SA 3.0
2016-10-31T18:03:40.033Z
2016-10-31T18:03:40.033Z
Nicol Bolas
<p>Instead of sampler3D, you should use isampler3D to sample integer formats as described in the <a href="https://www.opengl.org/wiki/Sampler_(GLSL)" rel="nofollow">GLSL documentation</a>.</p>

CC BY-SA 3.0
2016-10-30T04:01:22.353Z
2016-10-30T04:01:22.353Z
JarkkoL
<p><strong>When I set up a texture as float it works (color is written -  BTW I'm doing voxelization):</strong></p>

<pre><code>glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, width, height, depth, 0, GL_RGBA,GL_FLOAT,NULL);
</code></pre>

<p>then setting filtering...</p>

<p>then binding:</p>

<pre><code>glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);
</code></pre>

<p>writing:</p>

<pre><code>layout(rgba32f ,binding = 0) uniform image3D geometryGrid;
...
imageStore(geometryGrid, index, ivec4(1.0)); //ivec4 or vec4, it works
</code></pre>

<p>reading:</p>

<pre><code>uniform sampler3D geometryTexture;
...
vec4 g = texture(geometryTexture, geomCoords);
</code></pre>

<p><strong>But I want to use an integer texture (so in future I can do binary voxelization and bitwise operations - each bit = slice in z direction). I set it up like that:</strong></p>

<pre><code>glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);
</code></pre>

<p>then setting filtering...</p>

<p>then binding:</p>

<pre><code>glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32I);
</code></pre>

<p>writing:</p>

<pre><code>layout(rgba32i ,binding = 0) uniform iimage3D geometryGrid;
...
imageStore(geometryGrid, index, ivec4(1.0));
</code></pre>

<p>reading (same as float):</p>

<pre><code>uniform sampler3D geometryTexture;
...
vec4 g = texture(geometryTexture, geomCoords);
</code></pre>

<p>Then it's black. Whats wrong with that? There is sparse documentation about it. BTW The info that <code>iimage</code> is for integer texture, <code>uimage</code> is for unsigned int is actually nowhere to be found.</p>

CC BY-SA 3.0
2016-10-29T15:45:29.803Z
Does `glGetError()` return any errors during the process?
user1118321
CC BY-SA 3.0
2016-10-29T18:27:31.640Z
No, it returns 0 after each step.
mdkdy
CC BY-SA 4.0
2020-06-11T08:29:09.300Z
For future readers this issue was continued at: https://computergraphics.stackexchange.com/questions/4269/setting-up-integer-texture-and-binding-as-image-pt-2
James Griffin
<opengl><texture>
Setting up integer texture and binding as image
mdkdy
# Setting up integer texture and binding as image

(Asked by: username_0 on 2016-10-29)

**When I set up a texture as float it works (color is written - BTW I'm doing voxelization):**

```
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, width, height, depth, 0, GL_RGBA,GL_FLOAT,NULL);

```

then setting filtering...

then binding:

```
glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);

```

writing:

```
layout(rgba32f ,binding = 0) uniform image3D geometryGrid;
...
imageStore(geometryGrid, index, ivec4(1.0)); //ivec4 or vec4, it works

```

reading:

```
uniform sampler3D geometryTexture;
...
vec4 g = texture(geometryTexture, geomCoords);

```

**But I want to use an integer texture (so in future I can do binary voxelization and bitwise operations - each bit = slice in z direction). I set it up like that:**

```
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);

```

then setting filtering...

then binding:

```
glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32I);

```

writing:

```
layout(rgba32i ,binding = 0) uniform iimage3D geometryGrid;
...
imageStore(geometryGrid, index, ivec4(1.0));

```

reading (same as float):

```
uniform sampler3D geometryTexture;
...
vec4 g = texture(geometryTexture, geomCoords);

```

Then it's black. Whats wrong with that? There is sparse documentation about it. BTW The info that `iimage` is for integer texture, `uimage` is for unsigned int is actually nowhere to be found.

**Tags:** opengl, texture

> **Comments:**
> **username_1**: Does `glGetError()` return any errors during the process?  
> **username_0**: No, it returns 0 after each step.  
> **username_2**: For future readers this issue was continued at: https://computergraphics.stackexchange.com/questions/4269/setting-up-integer-texture-and-binding-as-image-pt-2  

---

## 2 answers

### Answer by username_3 on 2016-10-31. Score: 3 | Accepted answer

> ```
> glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);
>
> ```

This is not an [integer image format](https://www.opengl.org/wiki/Image_Format#Color_formats). It's an unsigned, normalized, fixed-point image format. For those, you use floating-point image/sampler variables. So for a 3D texture, you would use `image3D`, not `iimage3D`.

If you want a *true* signed integer format, you would do this:

```
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32I, width, height, depth, 0, GL_RGBA_INTEGER, GL_INT, NULL);

```

Note two changes. First, the internal format is `GL_RGBA32I`, which specifies a 32-bit-per-channel signed integer format. The second is the use of `GL_RGBA_INTEGER` for the [pixel transfer format](https://www.opengl.org/wiki/Pixel_Transfer#Pixel_format). Even though you're not actually performing a pixel transfer (since you're passing NULL), you still must use an appropriate format and type. And the `_INTEGER` formats must be used if you're transferring to/from a texture with an integer format.

When you do this, you must of course use the `iimage3D` and `isampler3D` types in your shaders.

> **Comments:**
> **username_0**: Thanks for hints. I corrected glTexImage3D function as you pointed but the problem seem to persist. What I noticed is that when I setup texture as RGBA32F, RGBA, GL_FLOAT and then bind it as RGBA32I image and use iimage in shader it works. But if I setup texture as RGBA32I, RGBA_INTEGER, GL_INT is is empty. So it is something with texture setup still. But it *is* correct and glGetError returns 0... I updated my nvidia drivers but this is not driver fault.  

---

### Answer by username_4 on 2016-10-30. Score: 1

Instead of sampler3D, you should use isampler3D to sample integer formats as described in the [GLSL documentation](https://www.opengl.org/wiki/Sampler_(GLSL)).


---

