00001 /********************************************************************** 00002 * glsl_toon.H: 00003 **********************************************************************/ 00004 #ifndef GLSL_PAPER_H_IS_INCLUDED 00005 #define GLSL_PAPER_H_IS_INCLUDED 00006 00007 #include "glsl_shader.H" 00008 00009 /********************************************************************** 00010 * GLSLPaperShader: 00011 * 00012 **********************************************************************/ 00013 class GLSLPaperShader : public GLSLShader { 00014 public: 00015 //******** MANAGERS ******** 00016 GLSLPaperShader(Patch* patch = 0); 00017 00018 //******** RUN-TIME TYPE ID ******** 00019 DEFINE_RTTI_METHODS3("GLSL paper", 00020 GLSLPaperShader*, BasicTexture, CDATA_ITEM*); 00021 00022 //******** Static ******** 00023 00024 static GLSLPaperShader* instance(); 00025 00026 // Use this to get the paper texture 00027 static TEXTUREglptr get_texture(); 00028 static str_ptr get_paper_filename() { return _paper_tex_filename; }; 00029 static void set_contrast(double c) { _contrast = c; } 00030 00031 // Set the name of the paper texture to use (full path): 00032 static void set_paper(Cstr_ptr& full_path_name); 00033 00034 // name of stroke texture (will be bound to tex unit 3): 00035 static void set_tex(Cstr_ptr& full_path_name); 00036 00037 static void begin_glsl_paper(Patch* p); 00038 static void end_glsl_paper(); 00039 00040 static void set_do_texture(bool v) { _do_texture = v; }; 00041 static bool get_do_texture() { return _do_texture; }; 00042 00043 //******** GLSLShader VIRTUAL METHODS ******** 00044 00045 // using a static variable for program, so all GLSLPaperShader 00046 // instances share the same program: 00047 virtual GLuint& program() { return _program; } 00048 virtual bool& did_init() { return _did_init; } 00049 00050 // called in init() to query and store the "locations" of 00051 // uniform and attribute variables: 00052 virtual bool get_variable_locs(); 00053 00054 // Send values of uniform variables to the shader: 00055 virtual bool set_uniform_variables() const; 00056 00057 virtual void init_textures(); 00058 00059 virtual void activate_textures(); 00060 00061 //******** DATA_ITEM VIRTUAL METHODS ******** 00062 virtual DATA_ITEM *dup() const { return new GLSLPaperShader; } 00063 00064 protected: 00065 //******** Member Variables ******** 00066 static GLSLPaperShader* _instance; 00067 static TEXTUREglptr _paper_tex; // the paper texture 00068 static str_ptr _paper_tex_name; // paper texture name 00069 static str_ptr _paper_tex_filename; // paper texture filename 00070 static TEXTUREglptr _tex; // the stroke texture 00071 static str_ptr _tex_name; // stroke texture name 00072 static double _contrast; 00073 static GLint _paper_tex_loc; 00074 static GLint _tex_loc; 00075 static GLint _sample_origin; 00076 static GLint _sample_u_vec; 00077 static GLint _sample_v_vec; 00078 static GLint _st_loc; 00079 static GLint _tex_width_loc; 00080 static GLint _tex_height_loc; 00081 static GLint _contrast_loc; 00082 00083 static bool _do_texture; 00084 00085 static GLuint _program; // GLSL program shared by all instances 00086 static bool _did_init; // tells whether initialization attempt was made 00087 00088 00089 //******** VIRTUAL METHODS ******** 00090 00091 // Return the names of the toon GLSL shader programs: 00092 virtual str_ptr vp_filename() { return vp_name("paper"); } 00093 00094 // XXX - temporary, until we can figure out how to not use the 00095 // fragment shader: 00096 virtual str_ptr fp_filename() { return fp_name("paper"); } 00097 }; 00098 00099 #endif // GLSL_PAPER_H_IS_INCLUDED 00100 00101 // end of file glsl_paper.H