Source browser
examples/shaders/image_to_buffer.cpp
Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.
File fingerprint
1// End an image pipeline with an SSBO, ready for another stage or host readback.
2#ifdef __cplusplus // Expose host declarations only when a C++ compiler reads this shader.
3#include "shdr.h" // Include shdr.h declarations.
4#endif // Finish this conditional compilation branch.
5
6layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; // Cover a 8 by 8 group of output coordinates.
7layout(r32f, binding = 0) readonly uniform highp image2D input_image; // Read the r32f image at this image binding.
8layout(std430, binding = 0) writeonly buffer Storage_output_values { // Write this stage's output elements through buffer binding 0.
9 float output_values[]; // Store this stage's output elements.
10}; // Finish this declaration.
11
12void main() { // Copy one image pixel into its row-major buffer element.
13 ivec2 position = ivec2(gl_GlobalInvocationID.xy); // Address the pixel assigned to this two-dimensional invocation.
14 ivec2 dimensions = imageSize(input_image); // Read the bound image extent before accessing its pixels.
15 if (position.x < dimensions.x && position.y < dimensions.y) { // Guard invocations outside the image in the partial final tile.
16 uint i = uint(position.y * dimensions.x + position.x); // Flatten the pixel coordinate into the output buffer index.
17 output_values[i] = imageLoad(input_image, position).x; // Copy the r32f red component into the corresponding buffer element.
18 } // End this block.
19} // End this block.