2

I'm currently working on a GPGPU project that uses OpenGL ES 2.0. I have a rendering pipeline that uses framebuffer objects (FBOs) as targets, i.e. the result of each rendering pass is saved in a texture which is attached to an FBO. So far, this works when using fragment shaders. For example I have to following rendering pipeline:

Preprocessing (downscaling, grayscale conversion)
-> Adaptive Thresholding Pass 1  -> Adapt. Thresh. Pass 2
-> Copy back to CPU

However, I wanted to extend this pipeline by adding a grayscale histogram calculation after the proprocessing step. With OpenGL ES 2.0 this only works with texture reads in the vertex shader, as far as I know [1]. I can confirm that my shaders work in a different program where the input is a "real" image, not a rendered texture that is attached to an FBO. Hence I think it is not possible to read texture data in a vertex shader if it comes from an FBO. Can anyone confirm this assumption or am I missing something? I'm using a Nexus 10 for my experiments.

[1]: It basically works by reading each pixel value from the texture in the vertex shader, then calculating of the histogram bin from it and "adding" it in the fragment shader by using alpha blending.

genpfault
  • 51,148
  • 11
  • 85
  • 139
IsaacKleiner
  • 425
  • 2
  • 13

1 Answers1

1

Texture reads within a vertex shader are not a required element in OpenGL ES 2.0, so you'll find some manufacturers supporting them and some not. In fact, there was a weird situation where iOS supported it on some devices for one version of iOS, but not the next (and it's now officially supported in iOS 7). That might be the source of the inconsistency you see here.

To work around this, I implemented a histogram calculation by instead feeding the colors from the FBO (or its attached texture) in as vertices and using a scattering operation similar to what you describe. This doesn't require a texture read of any kind in the vertex shader, but it does involve a round-trip from and to the GPU and potentially a lot of vertices. It works on all OpenGL ES 2.0 hardware, but it can be costly.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • I've seen your approach since I'm familiar with your great work over at the GPUImage project, but the problem is that I like to have a continuous rendering pipeline, which means that I try to avoid copying data back and forth from/to the GPU. I don't want to copy back GPU-preprocessed image to main memory, and then feed the colors as vertices back to the GPU. It's faster computing the histogram the traditional way then. However, it seems like with OpenGL ES 2.0 I can't get on :( Maybe some day the situation changes and we get some proper support for GPGPU on mobile devices (like OpenCL). – IsaacKleiner Feb 04 '14 at 15:17
  • Did you implement the histogram for iOS 7 and above that does all the calculation in vertex shader? I don't see one. – Deepak Sharma Jan 23 '18 at 08:49