<p>From the same <a href="https://www.khronos.org/opengl/wiki/Image_Load_Store" rel="nofollow noreferrer">wiki</a></p>

<blockquote>
  <p>Image variables can be declared with a format qualifier; this
  specifies the format for any read operations done on the image.
  <strong>Therefore, a format qualifier is required if you do not declare the
  variable with the writeonly memory qualifier. Write-only variables
  cannot be used as in any reading operations; this includes calling
  load and atomic (read/modify/write) functions. So if you want to read
  from an image, you must declare the format.</strong></p>
  
  <p>The format defines how the shader interprets the bits of data that it
  reads from the image. It also defines how it converts the data passed
  for write operations when it writes it into the image. This allows the
  actual Image Format of the image to differ between what the shader
  sees and what is stored in the image, sometimes substantially.</p>
</blockquote>

CC BY-SA 3.0
2018-02-12T11:49:27.387Z
2018-02-12T11:49:27.387Z
gallickgunner
<p>I had the exact same question until I learned about Compute shaders &amp; was playing around with it. I think Compute shader is one possible use case where you read/write into an image. This is where specifying these formats is important. </p>

CC BY-SA 3.0
2018-02-13T06:52:56.020Z
2018-02-13T06:52:56.020Z
TheOrestes
<p>The OpenGL <a href="https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Image_formats" rel="nofollow noreferrer">wiki entry</a> for layout qualifiers says:</p>

<blockquote>
  <p>Image uniform variables have qualifiers that define the format that all reading operations will convert the data into...</p>
</blockquote>

<p>When is it a good idea to declare the image format in a shader?</p>

<p>i.e. <code>layout (binding = 0, r32f) readonly uniform image2D input_image</code></p>

<p>Wouldn't this shader work just as well if I did not specify the <code>r32f</code>?</p>

<opengl><glsl>
Why would I specify image format in a shader layout qualifier?
Startec
# Why would I specify image format in a shader layout qualifier?

(Asked by: username_0 on 2018-02-12)

The OpenGL [wiki entry](https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Image_formats) for layout qualifiers says:

> Image uniform variables have qualifiers that define the format that all reading operations will convert the data into...

When is it a good idea to declare the image format in a shader?

i.e. `layout (binding = 0, r32f) readonly uniform image2D input_image`

Wouldn't this shader work just as well if I did not specify the `r32f`?

**Tags:** opengl, glsl


---

## 2 answers

### Answer by username_1 on 2018-02-12. Score: 1 | Accepted answer

From the same [wiki](https://www.khronos.org/opengl/wiki/Image_Load_Store)

> Image variables can be declared with a format qualifier; this
> specifies the format for any read operations done on the image.
> **Therefore, a format qualifier is required if you do not declare the
> variable with the writeonly memory qualifier. Write-only variables
> cannot be used as in any reading operations; this includes calling
> load and atomic (read/modify/write) functions. So if you want to read
> from an image, you must declare the format.**
>
> The format defines how the shader interprets the bits of data that it
> reads from the image. It also defines how it converts the data passed
> for write operations when it writes it into the image. This allows the
> actual Image Format of the image to differ between what the shader
> sees and what is stored in the image, sometimes substantially.


---

### Answer by username_2 on 2018-02-13. Score: -1

I had the exact same question until I learned about Compute shaders & was playing around with it. I think Compute shader is one possible use case where you read/write into an image. This is where specifying these formats is important.


---

