]> git.mxchange.org Git - simgear.git/blob - simgear/screen/shader.h
Add a new node "float-property" to be used in float comparision in effect predicates
[simgear.git] / simgear / screen / shader.h
1 /* Shader
2  *
3  * Copyright (C) 2003-2005, Alexander Zaprjagaev <frustum@frustum.org>
4  *                          Roman Grigoriev <grigoriev@gosniias.ru>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #ifndef __SHADER_H__
22 #define __SHADER_H__
23
24 #include <simgear/compiler.h>
25 #include <simgear/screen/extensions.hxx>
26
27 #include <vector>
28
29 #include <map>
30 #include <string>
31
32 using std::map;
33 using std::vector;
34 using std::string;
35
36 class Shader {
37 public:
38         
39         Shader(const char *name,const char *vertex = NULL,const char *fragment = NULL);
40         ~Shader();
41         
42         void bindNames(const char *name,...);
43         
44         void enable();
45         void disable();
46         void bind();
47         void bind(const float *value,...);
48         
49         void setLocalParameter(int location,const float *value);
50         void setEnvParameter(int location,const float *value);
51         
52         void setParameter(const char *name,const float *value);
53         void setParameters(const float *value,...);
54         
55         static void Init(void);
56         inline static bool is_VP_supported(void) {return VP_supported;}
57         inline static bool is_FP_supported(void) {return FP_supported;}
58         inline static bool is_GLSL_supported(void) {return GLSL_supported;}
59         inline static bool is_NVFP_supported(void) {return NVFP_supported;}
60         inline static int get_nb_texture_units(void) {return nb_texture_unit;}
61
62 protected:
63         
64         struct Parameter {
65                 GLuint location;
66                 int length;
67         };
68         
69         const char *get_error(char *data,int pos);
70         const char *get_glsl_error();
71         
72         void getParameter(const char *name,Parameter *parameter);
73         
74         GLhandleARB program;
75         
76         GLuint vertex_target;
77         GLuint vertex_id;
78         
79         GLuint fragment_target;
80         GLuint fragment_id;
81         
82         std::vector<Parameter> parameters;
83         typedef map<string, struct Parameter> arb_parameter_list;
84         arb_parameter_list arb_parameters;
85
86         static bool VP_supported, FP_supported, GLSL_supported, NVFP_supported;
87         static GLint nb_texture_unit;
88 };
89
90 #endif /* __SHADER_H__ */