]> git.vomp.tv Git - vompclient-marten.git/blob - glyuv400shader.cc
Last shader saves
[vompclient-marten.git] / glyuv400shader.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 "glyuv400shader.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 textureU;\n"\r
35                 "uniform sampler2D textureV;\n"\r
36                 "uniform sampler2D textureY;\n"\r
37                 "const float uv_corr=0.5;\n"\r
38                 "const float y_corr=0.0625;\n"\r
39                 "const mat3 yuvtransform= mat3( 1.164 ,0.0  ,1.596   ,\n"\r
40                 "                               1.164 ,-0.391,-0.813   ,\n"\r
41                 "                               1.164,2.018  , 0.0 );\n"\r
42 //              "const mat3 yuvtransform= mat3( 1. ,1.  ,1.   ,\n"\r
43 //              "                               0.0 ,-0.3960,2.029   ,\n"\r
44 //              "                               1.140,-0.581  , 0.0 );\n"\r
45 //              "const mat3 yuvtransform= mat3( 1. ,0  ,0.   ,\n"\r
46 //              "                               0.0 ,1.,0.   ,\n"\r
47 //              "                               0.,0.  , 1.0 );\n"\r
48 //              "const mat3 yuvtransform= mat3( 1. ,1.  ,1.   ,\n"\r
49 //              "                               0.0 ,-0.03960,0.2029   ,\n"\r
50 //              "                               0.1140,-0.0581  , 0.0 );\n"\r
51                 "varying vec2 out_texCoord;\n"\r
52                 "void main()\n"\r
53                 "{\n"\r
54                 " vec3 help;\n"\r
55                 "help.x=texture2D(textureY,out_texCoord).r-y_corr;\n"\r
56                 "help.y=texture2D(textureU,out_texCoord).r-uv_corr;\n"\r
57                 "help.z=texture2D(textureV,out_texCoord).r-uv_corr;\n" //-uv_corr;\n"\r
58                 "  gl_FragColor.rgb=help*yuvtransform;\n"\r
59                 " gl_FragColor.a=1.;\n"\r
60                 "}\n";\r
61 \r
62 GLYuv400Shader::GLYuv400Shader(): GLShader("GLYuv400Shader")\r
63 {\r
64 \r
65 }\r
66 \r
67 GLYuv400Shader::~GLYuv400Shader()\r
68 {\r
69         //parent does everything\r
70 }\r
71 \r
72 int GLYuv400Shader::init() {\r
73         if (!initShaders(generic_vertex_shader, frame_frag_shader)) {\r
74                 return 0;\r
75         }\r
76         frame_sampler_locY = glGetUniformLocation(shad_program, "textureY");\r
77         // Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locY,glGetError());\r
78         frame_sampler_locU = glGetUniformLocation(shad_program, "textureU");\r
79         //Log::getInstance()->log("OSD", Log::WARN, "uniform location %x %x",frame_sampler_locU,glGetError());\r
80         frame_sampler_locV = glGetUniformLocation(shad_program, "textureV");\r
81         return 1;\r
82 \r
83 }\r
84 \r
85 int GLYuv400Shader::deinit()\r
86 {\r
87         return deinitShaders();\r
88 }\r
89 \r
90 int GLYuv400Shader::PrepareRendering(GLuint y_tex, GLuint u_tex, GLuint v_tex) { // This Function setups the rendering pipeline according to the shaders standards\r
91         glUseProgram(shad_program);\r
92         //Log::getInstance()->log("OSD", Log::WARN, "mark1 glerror %x",glGetError());\r
93 \r
94 \r
95         //Log::getInstance()->log("OSD", Log::WARN, "mark2 glerror %x",glGetError());\r
96 \r
97 \r
98         glActiveTexture( GL_TEXTURE2);\r
99         glBindTexture(GL_TEXTURE_2D, v_tex);\r
100         glUniform1i(frame_sampler_locV, 2);\r
101         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
102         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
103 \r
104         glActiveTexture( GL_TEXTURE1);\r
105         glBindTexture(GL_TEXTURE_2D, u_tex);\r
106         glUniform1i(frame_sampler_locU, 1);\r
107         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
108         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
109 \r
110         glActiveTexture( GL_TEXTURE0);\r
111         glBindTexture(GL_TEXTURE_2D, y_tex);\r
112         glUniform1i(frame_sampler_locY, 0);\r
113         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
114         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);\r
115         return 1;\r
116 \r
117 }\r
118 \r
119 int GLYuv400Shader::BindAttributes()\r
120 {\r
121         glBindAttribLocation(shad_program,0,"vec_pos");\r
122         glBindAttribLocation(shad_program,1,"tex_coord");\r
123         return 1;\r
124 }\r