]> git.vomp.tv Git - vompclient-marten.git/blob - glyuv444shader.cc
Add missing files + compile error for wheezy
[vompclient-marten.git] / glyuv444shader.cc
1 /*\r
2     Copyright 2012 Marten Richter\r
3 \r
4     This file is part of VOMP.\r
5 \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
10 \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
15 \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
19 */\r
20 #include "glyuv444shader.h"\r
21 \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
26                 "void main()\n"\r
27                 "{\n"\r
28                 " gl_Position=vec_pos;\n"\r
29                 " out_texCoord=tex_coord;\n"\r
30                 "}\n";\r
31 \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
50                 "void main()\n"\r
51                 "{\n"\r
52                 " vec3 help;\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
56                 "}\n";\r
57 \r
58 GLYuv444Shader::GLYuv444Shader(): GLShader("GLYuv444Shader")\r
59 {\r
60 \r
61 }\r
62 \r
63 GLYuv444Shader::~GLYuv444Shader()\r
64 {\r
65         //parent does everything\r
66 }\r
67 \r
68 int GLYuv444Shader::init() {\r
69         if (!initShaders(generic_vertex_shader, frame_frag_shader)) {\r
70                 return 0;\r
71         }\r
72         frame_sampler_locYUV = glGetUniformLocation(shad_program, "textureYUV");\r
73         return 1;\r
74 \r
75 }\r
76 \r
77 int GLYuv444Shader::deinit()\r
78 {\r
79         return deinitShaders();\r
80 }\r
81 \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
85 \r
86 \r
87 \r
88 \r
89 \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
96 \r
97         return 1;\r
98 \r
99 }\r
100 \r
101 int GLYuv444Shader::BindAttributes()\r
102 {\r
103         glBindAttribLocation(shad_program,0,"vec_pos");\r
104         glBindAttribLocation(shad_program,1,"tex_coord");\r
105         return 1;\r
106 }\r