]> git.tdb.fi Git - libs/gl.git/blob - source/program.h
80ddf15ca33e282ff71a17cd79695db4fd324972
[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/objectloader.h>
14 #include "bindable.h"
15 #include "gl.h"
16
17 namespace Msp {
18 namespace GL {
19
20 class Shader;
21
22 class Program: public Bindable<Program>
23 {
24 public:
25         class Loader: public DataFile::ObjectLoader<Program>
26         {
27         public:
28                 Loader(Program &);
29
30         private:
31                 virtual void finish();
32
33                 void attribute(unsigned, const std::string &);
34                 void fragment_shader(const std::string &);
35                 void standard();
36                 void vertex_shader(const std::string &);
37         };
38
39         struct StandardFeatures
40         {
41                 class Loader: public DataFile::ObjectLoader<StandardFeatures>
42                 {
43                 public:
44                         Loader(StandardFeatures &);
45                 };
46
47                 bool texture;
48                 bool material;
49                 bool lighting;
50                 bool specular;
51                 bool normalmap;
52                 bool shadow;
53
54                 StandardFeatures();
55
56                 std::string create_flags() const;
57         };
58
59         struct UniformInfo
60         {
61                 std::string name;
62                 int location;
63                 int size;
64                 GLenum type;
65         };
66
67 private:
68         unsigned id;
69         std::list<Shader *> shaders;
70         bool del_shaders;
71         bool linked;
72         std::map<std::string, UniformInfo> uniforms;
73
74 public:
75         Program();
76         Program(const StandardFeatures &);
77         Program(const std::string &, const std::string &);
78 private:
79         void init();
80 public:
81         virtual ~Program();
82
83         void attach_shader(Shader &shader);
84         void detach_shader(Shader &shader);
85         void add_standard_shaders(const StandardFeatures &);
86 private:
87         static std::string process_standard_source(const char **, const std::string &);
88 public:
89         const std::list<Shader *> &get_shaders() const { return shaders; }
90         void set_del_shaders(bool);
91         void bind_attribute(unsigned, const std::string &);
92         void link();
93         bool is_linked() const { return linked; }
94         std::string get_info_log() const;
95         void bind() const;
96         int get_uniform_location(const std::string &) const;
97
98         static void unbind();
99 };
100
101 } // namespace GL
102 } // namespace Msp
103
104 #endif