00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __SHADER_H__
00022 #define __SHADER_H__
00023
00024 #include <simgear/compiler.h>
00025 #include <simgear/screen/extensions.hxx>
00026
00027 #include <vector>
00028
00029 #include <map>
00030 #include <string>
00031
00032 using std::map;
00033 using std::vector;
00034 using std::string;
00035
00036 class Shader {
00037 public:
00038
00039 Shader(const char *name,const char *vertex = NULL,const char *fragment = NULL);
00040 ~Shader();
00041
00042 void bindNames(const char *name,...);
00043
00044 void enable();
00045 void disable();
00046 void bind();
00047 void bind(const float *value,...);
00048
00049 void setLocalParameter(int location,const float *value);
00050 void setEnvParameter(int location,const float *value);
00051
00052 void setParameter(const char *name,const float *value);
00053 void setParameters(const float *value,...);
00054
00055 static void Init(void);
00056 inline static bool is_VP_supported(void) {return VP_supported;}
00057 inline static bool is_FP_supported(void) {return FP_supported;}
00058 inline static bool is_GLSL_supported(void) {return GLSL_supported;}
00059 inline static bool is_NVFP_supported(void) {return NVFP_supported;}
00060 inline static int get_nb_texture_units(void) {return nb_texture_unit;}
00061
00062 protected:
00063
00064 struct Parameter {
00065 GLuint location;
00066 int length;
00067 };
00068
00069 const char *get_error(char *data,int pos);
00070 const char *get_glsl_error();
00071
00072 void getParameter(const char *name,Parameter *parameter);
00073
00074 GLhandleARB program;
00075
00076 GLuint vertex_target;
00077 GLuint vertex_id;
00078
00079 GLuint fragment_target;
00080 GLuint fragment_id;
00081
00082 std::vector<Parameter> parameters;
00083 typedef map<string, struct Parameter> arb_parameter_list;
00084 arb_parameter_list arb_parameters;
00085
00086 static bool VP_supported, FP_supported, GLSL_supported, NVFP_supported;
00087 static GLint nb_texture_unit;
00088 };
00089
00090 #endif