]> git.vomp.tv Git - vompclient.git/blob - glshader.cc
Compile fixes for stretch
[vompclient.git] / glshader.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 "glshader.h"
21
22 GLShader::GLShader(const char* name)
23 {
24         initted=0;
25         objname=name;
26 }
27
28 GLShader::~GLShader()
29 {
30         if (initted) {
31                 deinitShaders();
32         }
33
34
35
36 }
37
38 int GLShader::initShaders(const char * vertex_shad,const char *fragment_shad)
39 {
40           vertex_shader=CreateShader(vertex_shad, GL_VERTEX_SHADER);
41           frag_shader=CreateShader(fragment_shad, GL_FRAGMENT_SHADER);
42
43           // Create the program for osd rendering
44           shad_program=glCreateProgram();
45           if (shad_program==0) {
46                   Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating glsl program failed!%d",objname,glGetError());
47               return 0;
48           }
49           glAttachShader(shad_program,vertex_shader);
50           glAttachShader(shad_program,frag_shader);
51           if (!BindAttributes()) {
52                   return 0;
53           }
54           glLinkProgram(shad_program);
55
56
57           GLint link_status;
58           glGetProgramiv(shad_program,GL_LINK_STATUS, &link_status);
59
60           if (!link_status) {
61                   char buffer[1024];
62                   glGetProgramInfoLog(shad_program,1024,NULL,buffer);
63                   Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Programm failed!",objname);
64                   Log::getInstance()->log("GLShader", Log::WARN, "%s",buffer);
65                   glDeleteProgram(shad_program);
66                   return 0;
67           }
68
69 }
70
71 GLuint GLShader::CreateShader(const GLchar * source, GLenum type)
72 {
73         GLuint ret_shad=0;
74
75         ret_shad=glCreateShader(type);
76         if (ret_shad==0 ) {
77                 Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating Shader failed! %d",objname, glGetError());
78                 return 0;
79         }
80         glShaderSource(ret_shad,1,&source,NULL);
81         glCompileShader(ret_shad);
82         GLint comp_status;
83         glGetShaderiv(ret_shad,GL_COMPILE_STATUS, &comp_status);
84
85         if (!comp_status) {
86                 char buffer[1024];
87                 Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Shader failed!",objname);
88                 glGetShaderInfoLog(ret_shad,1024,NULL,buffer);
89                 Log::getInstance()->log("GLShader", Log::WARN, "%s: %s",objname,buffer);
90                 glDeleteShader(ret_shad);
91                 return 0;
92         }
93         return ret_shad;
94 }
95
96 int GLShader::deinitShaders()
97 {
98          if (frag_shader!=0) glDeleteShader(frag_shader);
99          frag_shader=0;
100          if (vertex_shader!=0) glDeleteShader(vertex_shader);
101          vertex_shader=0;
102          if (shad_program!=0) glDeleteProgram(shad_program);
103          shad_program=0;
104          initted=0;
105          return 0;
106 }
107