I want to do image processing on a bitmap I have loaded. I am afraid it will take too long to do anything in normal android on the cpu, and have read that allowing the gpu to do stuff may speed things up substantially. I feel if I could turn the image from rgb to hsv in opengl I could figure out how to do everything I need.
I want to do work in the fragment shader(since that is about pixel color), and since I don't want to transform the image at all I feel the vertex shader is useless for my needs. Do I still need the vertex shader? Read something about a passthrough vertex shader. I read some implementations don't need both. My main points of confusion definitely lie in how opengl works. I have gathered how to form a texture and a framebuffer object. I don't understand the GLUtils.texSubImage2D. what is the diff between that and texImage2d. In any case, per this site (Site 1) and this code (Site 2) they loaded the bitmap using texSubImage2D.
I get how to load a vertex shader and fragment shader. I don't understand what happens after glUseProgram(). Does it run to completion? Do you continually supply it with information to process? how to stop it?
I think you pass in a texture using a uniform sampler2D -- I mean I think this is how to use the texture in the fragment shader.I guess it gets placed into the fragment shader automatically. How all this works is a mystery. I plan on using glReadPixels to get back my bitmap from the texture. when would I call this? the callback functions discussed in android doc only deal with a surfaceview afaik
I plan on using the information from this site (Site3) minus their vertex shader to convert it. I just need to put it all together.
Sorry if this is not enough to go on. BTW I don't want to use any libraries.
I have tried reading about opengl and specifically opengl es 2.0. They all talk about either using a surfaceview ( which I don't want ) or working on many triangles. I do get that I am using opengl for a purpose that opengl was not exactly made for.
This is some code from Site3
So I think tex would be the texture passed via texSubImage2D
hue, no clue.
texture2D() gets the pixel I guess, but where vTextureCoord comes from is a mystery. If I want, say the 3x3 matrix around the pixel do I just subtract and add to vTextureCoord values and keep calling texture2D(). and how to set a pixel a certain color.what is gl_FragColor
uniform sampler2D tex;
uniform vec3 hue;
// Add the two methods here (rgb2hsv and hsv2rgb are at Site 3)
void main() {
vec4 textureColor = texture2D(tex, vTextureCoord);
vec3 fragRGB = textureColor.rgb;
vec3 fragHSV = rgb2hsv(fragRGB).xyz;
fragHSV.x += hue.x;
fragHSV.yz *= hue.yz;
fragHSV.xyz = mod(fragHSV.xyz, 1.0);
fragRGB = hsv2rgb(fragHSV);
gl_FragColor = vec4(fragRGB, textureColor.w);
}