Luminance Histogram Calculation In Gpu-android Opengl Es 3.0
For Luminace histogram calculation I have used the code from the project GPU image ios by Brad Larson. He has used blending for Histogram calculation. Attaching the Vertex and Fr
Solution 1:
I'm using C and desktop GL, but here's the gist of it :
Vertex shader
#version 330
layout (location = 0) in vec2 inPosition;
voidmain()
{
int x = compute the bin (0 to 255) from inPosition;
gl_Position = vec4(
-1.0 + ((x + 0.5) / 128.0),
0.5,
0.0,
1.0
);
}
Fragment shader
#version 330
out vec4 outputColor;
voidmain()
{
outputColor = vec4(1.0, 1.0, 1.0, 1.0);
}
Init:
glGenTextures(1, &tex);
glGenFramebuffers(1, &fbo);
glActiveTexture(GL_TEXTURE0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32F, 256, 1);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
Drawing :
/* Upload data */
glBufferData(GL_ARRAY_BUFFER, num_input_data * 2 * sizeof(float), input_data_ptr, GL_STREAM_DRAW);
/* Clear buffer */constfloat zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
glClearBufferfv(GL_COLOR, 0, zero);
/* Init viewport */
glViewport(0, 0, 256, 1);
/* Draw */
glDrawArrays(GL_POINTS, 0, num_input_data);
For brievety I only put the init code for the resulting buffer, all the VBO/VAO init/binding has been skipped
Post a Comment for "Luminance Histogram Calculation In Gpu-android Opengl Es 3.0"