]> git.vomp.tv Git - vompclient.git/blob - glosdshader.cc
OSDOpenVG: Render on demand: Fix backing out of a view render race
[vompclient.git] / glosdshader.cc
1 /*
2     Copyright 2012 Marten Richter
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20 #include "glosdshader.h"
21
22 const GLchar generic_vertex_shader[] =
23                 "attribute vec4 vec_pos;\n"
24                 "attribute vec2 tex_coord;\n"
25                 "varying vec2 out_texCoord;\n"
26                 "void main()\n"
27                 "{\n"
28                 " gl_Position=vec_pos;\n"
29                 " out_texCoord=tex_coord;\n"
30                 "}\n";
31
32 const GLchar osd_frag_shader[] =
33                 "precision mediump float;\n"
34                 "uniform sampler2D texture;\n"
35                 "varying vec2 out_texCoord;\n"
36                 "void main()\n"
37                 "{\n"
38                 " gl_FragColor=texture2D(texture,out_texCoord);\n"
39                 "}\n";
40
41 GLOsdShader::GLOsdShader(): GLShader("GLOsdShader")
42 {
43
44 }
45
46 GLOsdShader::~GLOsdShader()
47 {
48         //parent does everything
49 }
50
51 int GLOsdShader::init()
52 {
53         if (!initShaders(generic_vertex_shader,osd_frag_shader)) {
54                 return 0;
55         }
56         osd_sampler_loc=glGetUniformLocation(shad_program,"texture");
57         return 1;
58
59 }
60
61 int GLOsdShader::deinit()
62 {
63         return deinitShaders();
64 }
65
66 int GLOsdShader::PrepareRendering(GLuint osd_tex){ // This Function setups the rendering pipeline according to the shaders standards
67         glUseProgram(shad_program);
68
69         glActiveTexture(GL_TEXTURE0);
70         glBindTexture(GL_TEXTURE_2D,osd_tex);
71
72         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
73         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
74
75         glUniform1i(osd_sampler_loc,0);
76         return 1;
77
78 }
79
80 int GLOsdShader::BindAttributes()
81 {
82         glBindAttribLocation(shad_program,0,"vec_pos");
83         glBindAttribLocation(shad_program,1,"tex_coord");
84         return 1;
85 }