]> git.tdb.fi Git - libs/gl.git/blob - source/shader.cpp
Add shaders
[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 {
18         id=glCreateShader(t);
19 }
20
21 Shader::~Shader()
22 {
23         glDeleteShader(id);
24 }
25
26 void Shader::source(sizei count, const char **str, const int *len)
27 {
28         glShaderSource(id, count, str, len);
29 }
30
31 void Shader::source(const string &str)
32 {
33         source(str.data(), str.size());
34 }
35
36 void Shader::source(const char *str, int len)
37 {
38         source(1, &str, &len);
39 }
40
41 bool Shader::compile()
42 {
43         glCompileShader(id);
44         compiled=get_param(GL_COMPILE_STATUS);
45         return compiled;
46 }
47
48 int Shader::get_param(GLenum param) const
49 {
50         int value;
51         glGetShaderiv(id, param, &value);
52         return value;
53 }
54
55 string Shader::get_info_log() const
56 {
57         sizei len=get_param(GL_INFO_LOG_LENGTH);
58         char log[len+1];
59         glGetShaderInfoLog(id, len+1, reinterpret_cast<GLsizei *>(&len), log);
60         return string(log, len);
61 }
62
63 } // namespace GL
64 } // namespace Msp