How to pass only the needed portion of the data calculated in a fragment shader to another fragment shader?
I'm assuming that you don't know how many objects there will be or have any way to index them until the image processing operations are completed, i.e. you have some final pass that determines for each pixel &quot;do I want to put an object here, or no&quot;.
OpenGL ES 2.0 is pretty limiting. There may be no better way to do this than what you described: output from the fragment shader to a texture, pull it back to the CPU to extract the points, then put those into a uniform buffer for the second pass.
One thing you could attempt, though I'm unsure if it could be fully made to work in ES 2.0, is to do a parallel prefix sum over the output texture from the first pass. This would involve recursive fragment shader reduction passes (a little bit like generating mipmaps) that would first count up the number of objects within each region of the image, starting with 2×2 regions and doubling at each step until you've covered the full image, then go back down the mip chain and calculate the prefix sums, which are the number of objects &quot;before&quot; each region (using some defined ordering). At the end of that, you would have the exact index where to store each object into an output buffer.
FYI, in GL ES 3.1 and other more fully-featured APIs, there are shader atomic counters, which allow implementing an &quot;append buffer&quot;; your first fragment shader pass could output directly to this buffer, then turn around and use it for an input buffer, or for indirect draw parameters, on the next pass.