gradient.cl (881B)
1 // This is the main function of the program. 2 // Runcl passes the following arguments to the program. 3 // - width: the width of the image in pixels 4 // - height: the height of the image in pixels 5 // - *out: the output of the program, formatted as an 3xwxh array of 6 // normalized rgb pixel colors 7 kernel void render(const int width, const int height, __global float *out) 8 { 9 // This gets the id of the particular instance. 10 const int i = get_global_id(0); 11 12 // Depending on the image size, some instances may be outside of the image 13 // bounds. Make sure to check for this! 14 if ( i < width * height ) 15 { 16 // This converts the instance ID into normalized image coordinates. 17 float x = (float)(i % width) / width; 18 float y = (float)(i / width) / height; 19 20 // Finally, output the rgb color to the output array. 21 out[3*i] = x; 22 out[3*i+1] = x; 23 out[3*i+2] = x; 24 } 25 }