qt5_qml_Opengl_shader 第三弹-----------------------纹理贴图(YUV)

Opengl_under_qml第三弹----------------------纹理贴图(YUV)

本文接上文

Opengl_under_qml第三弹----------------------纹理贴图(YUV

主要通过程序将yuv数据送给shader,通过gpu来转成rgb进而渲染。

 

与上文主要不同的地方还是paint函数,为了容易看懂,没有将其写成多个函数的形式,也没有加测试代码,

 

voidSquircleRenderer::paint()

{

   //initializeGLFunctions();

    initializeOpenGLFunctions();

    if(!m_program){

        m_program=newQOpenGLShaderProgram();

 

 

        m_program->addShaderFromSourceCode(QOpenGLShader::Vertex,

                                          "attributehighpvec4vertexIn;"

                                          "attributehighpvec2textureIn;"

                                          "varyingvec2textureOut;"

                                          "voidmain(void){"

                                          "gl_Position=vertexIn;"

                                          "textureOut=textureIn;}");

 

        m_program->addShaderFromSourceCode(QOpenGLShader::Fragment,

                                          "varyingvec2textureOut;"

                                          "uniformsampler2Dtex_y;"

                                          "uniformsampler2Dtex_u;"

                                          "uniformsampler2Dtex_v;"

                                           "voidmain(void){"

                                          "vec3yuv;"

                                          "vec3rgb;"

                                          "yuv.x=texture2D(tex_y,textureOut).r;"

                                          "yuv.y=texture2D(tex_u,textureOut).r-0.5;"

                                          "yuv.z=texture2D(tex_v,textureOut).r-0.5;"

                                          "rgb=mat3(1,      1,        1,"

                                          "0,      -0.39465,  2.03211,"

你可能感兴趣的:(qml,qml,opengles,qt,qt5,yuv)