summaryrefslogtreecommitdiff
path: root/src/qcam/viewfinder_gl.cpp
AgeCommit message (Collapse)Author
2021-06-30qcam: viewfinder_gl: Add support for RAW8 Bayer formatsAndrey Konovalov
This integrates the vertex and the fragment shaders by Morgan McGuire into qcam. Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-06-30qcam: viewfinder_gl: Set the vertex shader file name in selectFormat()Andrey Konovalov
In preparation to extend the supported formats, make it possible to use different vertex fragment files depending on the format. Make "identity.vert" the default choice. Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-06-30qcam: viewfinder_gl: Add support for RAW12 packed formatsAndrey Konovalov
All the four Bayer orders are supported. The 4 LS bits of the 12-bit colour values are dropped as the RGBA format we convert into has only 8 bits per colour. Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-06-30qcam: viewfinder_gl: Add shader to render packed RAW10 formatsAndrey Konovalov
The shader supports all 4 packed RAW10 variants. Simple bi-linear Bayer interpolation of nearest pixels is implemented. The 2 LS bits of the 10-bit colour values are dropped as the RGBA format we convert into has only 8 bits per colour. The texture coordinates passed to the fragment shader are adjusted to point to the nearest pixel in the image. This prevents artifacts when the image is scaled from the frame resolution to the window size. Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-06-30qcam: viewfinder_gl: Change uniform float tex_stepx to vec2 tex_stepAndrey Konovalov
In preparation to extend the supported formats, extend the tex_stepx uniform to cover the steps between texels in both horizontal and vertical directions. Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-11-07qcam: viewfinder_gl: Add support for RGB formatsLaurent Pinchart
Add support for 24-bit and 32-bit RGB formats. The fragment samples the texture and reorders the components, using a pattern set through the RGB_PATTERN macro. The pattern stores the shader vec4 element indices (named {r, g, b, a} by convention, for elements 0 to 3) to be extracted from the texture samples, when interpreted by OpenGL as RGBA. Note that, as textures are created with GL_UNSIGNED_BYTE, the RGBA order corresponds to bytes in memory, while the libcamera formats are named based on the components order in a 32-bit word stored in memory in little endian format. An alternative to manual reordering in the shader would be to set the texture swizzling mask. This is however not available in OpenGL ES before version 3.0, which we don't mandate at the moment. Only the BGR888 and RGB888 formats have been tested, with the vimc pipeline handler. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07qcam: viewfinder_gl: Store textures in an arrayLaurent Pinchart
In preparation for RGB formats support, store the three Y, U and V textures in an array. This makes the code more generic, and will avoid referring to an RGB texture as textureY_. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07qcam: viewfinder_gl: Rename yuvData_ to data_Laurent Pinchart
In preparation for RGB formats support, rename the pointer to image data from yuvData_ to data_. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07qcam: viewfinder_gl: Rename YUV.vert to identity.vertLaurent Pinchart
In preparation for RGB formats support, rename the identity vertex shader from YUV.vert to identity.vert. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07qcam: viewfinder_gl: Remove unneeded castsLaurent Pinchart
There's no need to cast the yuvData_ unsigned char pointer to a char pointer before performing pointer arithmetics. Drop the unneeded casts. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07qcam: viewfinder_gl: Keep fragment shader when format doesn't changeLaurent Pinchart
When ViewFinderGL::setFormat() is called, the fragment shader is deleted and recreated for the new format. This results in unnecessary shader recompilation if only the size is changed and the pixel format remains the same. Keep the existing shader in that case. The null test for fragmentShader_ can be removed, as if the shader program is linked, the fragment shader is guaranteed to exist. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-11-07qcam: viewfinder_gl: Fix fragment shader rebuild when setting formatLaurent Pinchart
When setting a new format, the existing fragment shader is deleted and a new shader should be created. However, the shader pointer isn't set to nullptr after deleting it, resulting in the deleter shader being reused. Fix it by managing shader pointers with std::unique_ptr<> to prevent similar bugs from happening in the future. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04qcam: viewfinder_gl: Add shader to render packed YUV formatsLaurent Pinchart
The shader supports all 4 packed 8-bit YUV variants. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04qcam: viewfinder_gl: Merge the semi-planar UV and VU shadersLaurent Pinchart
Use macros to select the U and V pattern, to avoid code duplication between the two semi-planar shaders. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04qcam: viewfinder_gl: Support #define in shadersLaurent Pinchart
Prepare the infrastructure to support defining preprocessor macros in shaders: - Rename the fragmentShaderSrc_ member to fragmentShaderFile_ to reflect better that it contains a file name, not shader source code - Add a new fragmentShaderDefines_ member to store preprocessor macros - Prepend the macros to the shader source before compiling it Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04qcam: viewfinder_gl: Rename shader filesLaurent Pinchart
Rename shader files to prepare for packed YUYV support: - The NV prefix isn't a good match for packed (or for 3-planar) formats, replace it with a YUV prefix - Use .frag and .vert extensions to differentiate between fragment and vertex shaders Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04qcam: viewfinder_gl: Hardcode the vertex shader file nameLaurent Pinchart
The GL renderer uses the same vertex shader for all formats. Hardcode the file name instead of storing it in a member variable. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-10-04qcam: viewfinder_gl: Don't store texture IDs in class membersLaurent Pinchart
The texture IDs can easily and cheaply be retrieved from the textures, there's no need to store them in class members. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-09-15qcam: Add ViewFinderGL class to accelerate the format conversionShow Liu
The viewfinderGL accelerates the format conversion by using OpenGL ES shader. The minimum Qt version is bumped to v5.4, as QOpenGLWidget wasn't available before that. Signed-off-by: Show Liu <show.liu@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>