]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
3b86a9c6d17d4af1af0ae0f1596eb67246799733
[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 <GL/gl.h>
14 #include <msp/datafile/loader.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         virtual ~Program();
51
52         void attach_shader(Shader &shader);
53         void detach_shader(Shader &shader);
54         const std::list<Shader *> &get_shaders() const { return shaders; }
55         void set_del_shaders(bool);
56         void bind_attribute(uint, const std::string &);
57         void link();
58         int get_param(GLenum param) const;
59         bool get_linked() const { return linked; }
60         std::string get_info_log() const;
61         void bind();
62         int get_uniform_location(const std::string &) const;
63
64         static void unbind();
65
66 private:
67         void maybe_bind();
68 };
69
70 } // namespace GL
71 } // namespace Msp
72
73 #endif