2 Copyright 2012 Marten Richter
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 #include "glyuv444shader.h"
\r
22 const GLchar generic_vertex_shader[] =
\r
23 "attribute vec4 vec_pos;\n"
\r
24 "attribute vec2 tex_coord;\n"
\r
25 "varying vec2 out_texCoord;\n"
\r
28 " gl_Position=vec_pos;\n"
\r
29 " out_texCoord=tex_coord;\n"
\r
32 const GLchar frame_frag_shader[] =
\r
33 "precision mediump float;\n"
\r
34 "uniform sampler2D textureYUV;\n"
\r
35 "const float uv_corr=0.5;\n"
\r
36 "const float y_corr=0.0625;\n"
\r
37 "const mat3 yuvtransform= mat3( 1.164 ,0.0 ,1.596 ,\n"
\r
38 " 1.164 ,-0.391,-0.813 ,\n"
\r
39 " 1.164,2.018 , 0.0 );\n"
\r
40 // "const mat3 yuvtransform= mat3( 1. ,1. ,1. ,\n"
\r
41 // " 0.0 ,-0.3960,2.029 ,\n"
\r
42 // " 1.140,-0.581 , 0.0 );\n"
\r
43 // "const mat3 yuvtransform= mat3( 1. ,0 ,0. ,\n"
\r
44 // " 0.0 ,1.,0. ,\n"
\r
45 // " 0.,0. , 1.0 );\n"
\r
46 // "const mat3 yuvtransform= mat3( 1. ,1. ,1. ,\n"
\r
47 // " 0.0 ,-0.03960,0.2029 ,\n"
\r
48 // " 0.1140,-0.0581 , 0.0 );\n"
\r
49 "varying vec2 out_texCoord;\n"
\r
53 "help=texture2D(textureYUV,out_texCoord).rgb-vec3(y_corr,uv_corr,uv_corr);\n"
\r
54 "gl_FragColor.rgb=help*yuvtransform;\n"
\r
55 "gl_FragColor.a=1.;\n"
\r
58 GLYuv444Shader::GLYuv444Shader(): GLShader("GLYuv444Shader")
\r
63 GLYuv444Shader::~GLYuv444Shader()
\r
65 //parent does everything
\r
68 int GLYuv444Shader::init() {
\r
69 if (!initShaders(generic_vertex_shader, frame_frag_shader)) {
\r
72 frame_sampler_locYUV = glGetUniformLocation(shad_program, "textureYUV");
\r
77 int GLYuv444Shader::deinit()
\r
79 return deinitShaders();
\r
82 int GLYuv444Shader::PrepareRendering(GLuint yuv_tex) { // This Function setups the rendering pipeline according to the shaders standards
\r
83 glUseProgram(shad_program);
\r
84 //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());
\r
90 glActiveTexture( GL_TEXTURE0);
\r
91 glBindTexture(GL_TEXTURE_2D, yuv_tex);
\r
92 //Log::getInstance()->log("OSD", Log::WARN, "mark3 glerror %x %x",glGetError(),yuv_tex);
\r
93 glUniform1i(frame_sampler_locYUV, 0);
\r
94 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
\r
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
\r
101 int GLYuv444Shader::BindAttributes()
\r
103 glBindAttribLocation(shad_program,0,"vec_pos");
\r
104 glBindAttribLocation(shad_program,1,"tex_coord");
\r