]> git.tdb.fi Git - libs/gl.git/blob - source/shader.cpp
Add mult_matrix functions
[libs/gl.git] / source / shader.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #define GL_GLEXT_PROTOTYPES
9 #include "shader.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GL {
15
16 Shader::Shader(ShaderType t):
17         id(glCreateShader(t)),
18         compiled(false)
19 { }
20
21 Shader::Shader(ShaderType t, const string &src):
22         id(glCreateShader(t)),
23         compiled(false)
24 {
25         source(src);
26         compile();
27 }
28
29 Shader::~Shader()
30 {
31         glDeleteShader(id);
32 }
33
34 void Shader::source(sizei count, const char **str, const int *len)
35 {
36         glShaderSource(id, count, str, len);
37 }
38
39 void Shader::source(const string &str)
40 {
41         source(str.data(), str.size());
42 }
43
44 void Shader::source(const char *str, int len)
45 {
46         source(1, &str, &len);
47 }
48
49 bool Shader::compile()
50 {
51         glCompileShader(id);
52         compiled=get_param(GL_COMPILE_STATUS);
53         return compiled;
54 }
55
56 int Shader::get_param(GLenum param) const
57 {
58         int value;
59         glGetShaderiv(id, param, &value);
60         return value;
61 }
62
63 string Shader::get_info_log() const
64 {
65         sizei len=get_param(GL_INFO_LOG_LENGTH);
66         char log[len+1];
67         glGetShaderInfoLog(id, len+1, reinterpret_cast<GLsizei *>(&len), log);
68         return string(log, len);
69 }
70
71 } // namespace GL
72 } // namespace Msp