For a project I've been working on developing a C++ library for (mmal) camera communication, including PWM/flash synchronisation and OpenGL support (https://github.com/HesselM/flashcam).
Currently everything is running fine, but in my project I need to apply different shaders consecutively with some magic in between. I'm able to process Mode-5 images at 10fps, but it should be possible to increase this speed.
In sobel.c I found this comment:
Code: Select all
/* Example Sobel edge detct shader. The texture format for
* EGL_IMAGE_BRCM_MULTIMEDIA_Y is a one byte per pixel greyscale GL_LUMINANCE.
* If the output is to be fed into another image processing shader then it may
* be worth changing this code to take 4 input Y pixels and pack the result
* into a 32bpp RGBA pixel.
*/The process of texture creation/mapping in my library is as follows:
- Videoport is set to use the OPAQUE parameter
- The callback processes frame updates by calling mmalbuf2TextureOES with the OPAQUE frame-data
- `mmalbuf2TextureOES` creates a `EGLImageKHR` in the same way as is done in RaspiTex (using `EGL_IMAGE_BRCM_MULTIMEDIA_Y`).
- Once created, the image is then pushed to a user defined callback
- In this callback I translate the EGLImageKHR image into an `RGBA` texture using the shader:
Code: Select all
#define SRC_FSHADER_OES2RGB \ "#extension GL_OES_EGL_image_external : require\n" \ "uniform samplerExternalOES tex;\n" \ "varying vec2 texcoord;\n" \ "void main(void) {\n" \ " gl_FragColor = texture2D(tex, texcoord);\n" \ "}\n"
A different approach would be to update the shader and define a secondary `eglCreatePbufferSurface` and context with width/4, such that I could create an 2D-RGBA texture to which I sample the original EGLImageKHR-linked texture. A shader could then roughly look something like:
Code: Select all
void main(void) {
vec4 color = vec4(0);
color.r = texture2D(tex, texcoord ).r;
color.g = texture2D(tex, texcoord + 1/pixelwidth).r;
color.b = texture2D(tex, texcoord + 2/pixelwidth).r;
color.a = texture2D(tex, texcoord + 3/pixelwidth).r;
gl_FragColor = color;
}
Has anyone some thoughts or experience on this? What would be the `best` way to go?
Many thanks is advance for pointers and/or help!