]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
Use RAII checks for extensions and versions
[libs/gl.git] / source / program.h
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 #ifndef MSP_GL_PROGRAM_H_
9 #define MSP_GL_PROGRAM_H_
10
11 #include <list>
12 #include <string>
13 #include <msp/datafile/loader.h>
14 #include "gl.h"
15 #include "types.h"
16
17 namespace Msp {
18 namespace GL {
19
20 class Shader;
21
22 class Program
23 {
24 private:
25         uint id;
26         std::list<Shader *> shaders;
27         bool del_shaders;
28         bool linked;
29
30         static Program *cur_prog;
31
32 public:
33         class Loader: public DataFile::Loader
34         {
35         private:
36                 Program &prog;
37
38         public:
39                 Loader(Program &);
40
41         private:
42                 void vertex_shader(const std::string &);
43                 void fragment_shader(const std::string &);
44                 void attribute(uint, const std::string &);
45                 virtual void finish();
46         };
47
48         Program();
49         Program(const std::string &, const std::string &);
50 private:
51         void init();
52 public:
53         virtual ~Program();
54
55         void attach_shader(Shader &shader);
56         void detach_shader(Shader &shader);
57         const std::list<Shader *> &get_shaders() const { return shaders; }
58         void set_del_shaders(bool);
59         void bind_attribute(uint, const std::string &);
60         void link();
61         int get_param(GLenum param) const;
62         bool get_linked() const { return linked; }
63         std::string get_info_log() const;
64         void bind();
65         int get_uniform_location(const std::string &) const;
66
67         static void unbind();
68
69 private:
70         void maybe_bind();
71 };
72
73 } // namespace GL
74 } // namespace Msp
75
76 #endif