2 Copyright 2012 Marten Richter
\r
4 This file is part of VOMP.
\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
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
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
20 #include "glshader.h"
\r
22 GLShader::GLShader(const char* name)
\r
28 GLShader::~GLShader()
\r
38 int GLShader::initShaders(const char * vertex_shad,const char *fragment_shad)
\r
40 vertex_shader=CreateShader(vertex_shad, GL_VERTEX_SHADER);
\r
41 frag_shader=CreateShader(fragment_shad, GL_FRAGMENT_SHADER);
\r
43 // Create the program for osd rendering
\r
44 shad_program=glCreateProgram();
\r
45 if (shad_program==0) {
\r
46 Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating glsl program failed!%d",objname,glGetError());
\r
49 glAttachShader(shad_program,vertex_shader);
\r
50 glAttachShader(shad_program,frag_shader);
\r
51 if (!BindAttributes()) {
\r
54 glLinkProgram(shad_program);
\r
58 glGetProgramiv(shad_program,GL_LINK_STATUS, &link_status);
\r
62 glGetProgramInfoLog(shad_program,1024,NULL,buffer);
\r
63 Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Programm failed!",objname);
\r
64 Log::getInstance()->log("GLShader", Log::WARN, "%s",buffer);
\r
65 glDeleteProgram(shad_program);
\r
71 GLuint GLShader::CreateShader(const GLchar * source, GLenum type)
\r
75 ret_shad=glCreateShader(type);
\r
77 Log::getInstance()->log("GLShader", Log::WARN, "%s: Creating Shader failed! %d",objname, glGetError());
\r
80 glShaderSource(ret_shad,1,&source,NULL);
\r
81 glCompileShader(ret_shad);
\r
83 glGetShaderiv(ret_shad,GL_COMPILE_STATUS, &comp_status);
\r
87 Log::getInstance()->log("GLShader", Log::WARN, "%s: Compiling Shader failed!",objname);
\r
88 glGetShaderInfoLog(ret_shad,1024,NULL,buffer);
\r
89 Log::getInstance()->log("GLShader", Log::WARN, "%s: %s",objname,buffer);
\r
90 glDeleteShader(ret_shad);
\r
96 int GLShader::deinitShaders()
\r
98 if (frag_shader!=0) glDeleteShader(frag_shader);
\r
100 if (vertex_shader!=0) glDeleteShader(vertex_shader);
\r
102 if (shad_program!=0) glDeleteProgram(shad_program);
\r