]> git.vomp.tv Git - vompclient.git/blob - glosdshader.cc
Preparations for dynamic mode switching
[vompclient.git] / glosdshader.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 "glosdshader.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 osd_frag_shader[] =\r
33                 "precision mediump float;\n"\r
34                 "uniform sampler2D texture;\n"\r
35                 "varying vec2 out_texCoord;\n"\r
36                 "void main()\n"\r
37                 "{\n"\r
38                 " gl_FragColor=texture2D(texture,out_texCoord);\n"\r
39                 "}\n";\r
40 \r
41 GLOsdShader::GLOsdShader(): GLShader("GLOsdShader")\r
42 {\r
43 \r
44 }\r
45 \r
46 GLOsdShader::~GLOsdShader()\r
47 {\r
48         //parent does everything\r
49 }\r
50 \r
51 int GLOsdShader::init()\r
52 {\r
53         if (!initShaders(generic_vertex_shader,osd_frag_shader)) {\r
54                 return 0;\r
55         }\r
56         osd_sampler_loc=glGetUniformLocation(shad_program,"texture");\r
57         return 1;\r
58 \r
59 }\r
60 \r
61 int GLOsdShader::deinit()\r
62 {\r
63         return deinitShaders();\r
64 }\r
65 \r
66 int GLOsdShader::PrepareRendering(GLuint osd_tex){ // This Function setups the rendering pipeline according to the shaders standards\r
67         glUseProgram(shad_program);\r
68 \r
69         glActiveTexture(GL_TEXTURE0);\r
70         glBindTexture(GL_TEXTURE_2D,osd_tex);\r
71 \r
72         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);\r
73         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);\r
74 \r
75         glUniform1i(osd_sampler_loc,0);\r
76         return 1;\r
77 \r
78 }\r
79 \r
80 int GLOsdShader::BindAttributes()\r
81 {\r
82         glBindAttribLocation(shad_program,0,"vec_pos");\r
83         glBindAttribLocation(shad_program,1,"tex_coord");\r
84         return 1;\r
85 }\r