1
$\begingroup$

The OpenGL wiki entry 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?

$\endgroup$
1
$\begingroup$

From the same wiki

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.

$\endgroup$
-1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.