From 693d43b693aa33dcc697727dfd60d6a7b826cb3d Mon Sep 17 00:00:00 2001 From: wang-bin Date: Thu, 17 Apr 2014 17:40:21 +0800 Subject: [PATCH] gl: try 10bit yuv planar. wrong color now --- src/GLWidgetRenderer.cpp | 19 +++++++++++++++---- src/shaders/yuv_rgb.f.glsl | 12 ++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/GLWidgetRenderer.cpp b/src/GLWidgetRenderer.cpp index 38cc3963..c2b311f6 100644 --- a/src/GLWidgetRenderer.cpp +++ b/src/GLWidgetRenderer.cpp @@ -342,6 +342,9 @@ bool GLWidgetRendererPrivate::prepareShaderProgram(const VideoFormat &fmt) } if (frag.isEmpty()) return false; + if (!fmt.isRGB() && fmt.isPlanar() && fmt.bitsPerPixel(0) == 10) { + frag.prepend("#define P010 1\n"); + } #if NO_QGL_SHADER program = createProgram(kVertexShader, frag.toUtf8().constData()); if (!program) { @@ -449,12 +452,19 @@ bool GLWidgetRendererPrivate::initTextures(const VideoFormat &fmt) if (fmt.planeCount() == 2) { internal_format[1] = data_format[1] = GL_LUMINANCE_ALPHA; } else { - internal_format[1] = data_format[1] = GL_LUMINANCE; //vec4(L,L,L,0) - internal_format[2] = data_format[2] = GL_ALPHA;//GL_ALPHA; + if (fmt.bytesPerPixel(1) == 2) { + // read 16 bits and compute in shader + internal_format[0] = data_format[0] = GL_LUMINANCE_ALPHA; //or GL_RED for GL + internal_format[1] = data_format[1] = GL_LUMINANCE_ALPHA; //vec4(L,L,L,A) + internal_format[2] = data_format[2] = GL_LUMINANCE_ALPHA; + } else { + internal_format[1] = data_format[1] = GL_LUMINANCE; //vec4(L,L,L,1) + internal_format[2] = data_format[2] = GL_ALPHA;//GL_ALPHA; + } } for (int i = 0; i < internal_format.size(); ++i) { // xbmc use bpp not bpp(plane) - internal_format[i] = GetGLInternalFormat(data_format[i], fmt.bytesPerPixel(i)); + //internal_format[i] = GetGLInternalFormat(data_format[i], fmt.bytesPerPixel(i)); //data_format[i] = internal_format[i]; } } else { @@ -462,8 +472,9 @@ bool GLWidgetRendererPrivate::initTextures(const VideoFormat &fmt) // TODO: if no alpha, data_fmt is not GL_BGRA. align at every upload? } for (int i = 0; i < fmt.planeCount(); ++i) { + //qDebug("format: %#x GL_LUMINANCE_ALPHA=%#x", data_format[i], GL_LUMINANCE_ALPHA); if (fmt.bytesPerPixel(i) == 2 && fmt.planeCount() == 3) { - data_type[i] = GL_UNSIGNED_SHORT; + //data_type[i] = GL_UNSIGNED_SHORT; } int bpp_gl = bytesOfGLFormat(data_format[i], data_type[i]); int pad = qCeil((qreal)(texture_size[i].width() - effective_tex_width[i])/(qreal)bpp_gl); diff --git a/src/shaders/yuv_rgb.f.glsl b/src/shaders/yuv_rgb.f.glsl index 0c958679..72b31fbc 100644 --- a/src/shaders/yuv_rgb.f.glsl +++ b/src/shaders/yuv_rgb.f.glsl @@ -27,12 +27,24 @@ const mat4 yuv2rgbMatrix = mat4(1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, -0.5, -0.5, 1); + +// 10, 16bit: http://msdn.microsoft.com/en-us/library/windows/desktop/bb970578%28v=vs.85%29.aspx void main() { +#if P010 + // yyyyyyyy yy000000 => (L, L, L, A) + gl_FragColor = clamp(u_colorMatrix*yuv2rgbMatrix* vec4( + (texture2D(u_Texture0, v_TexCoords).r*4.0 + texture2D(u_Texture0, v_TexCoords).a/64.0)*255.0/1023.0, + (texture2D(u_Texture1, v_TexCoords).r*4.0 + texture2D(u_Texture1, v_TexCoords).a/64.0)*255.0/1023.0, + (texture2D(u_Texture2, v_TexCoords).r*4.0 + texture2D(u_Texture2, v_TexCoords).a/64.0)*255.0/1023.0, + 1) + , 0.0, 1.0); +#else // use r, g, a to work for both yv12 and nv12 gl_FragColor = clamp(u_colorMatrix*yuv2rgbMatrix* vec4(texture2D(u_Texture0, v_TexCoords).r, texture2D(u_Texture1, v_TexCoords).g, texture2D(u_Texture2, v_TexCoords).a, 1) , 0.0, 1.0); +#endif }