00001 /********************************************************************** 00002 * glsl_toon.H: 00003 **********************************************************************/ 00004 #ifndef GLSL_TOON_H_IS_INCLUDED 00005 #define GLSL_TOON_H_IS_INCLUDED 00006 00007 #include "glsl_shader.H" 00008 00009 /********************************************************************** 00010 * GLSLToonShader: 00011 * 00012 * GLSL version of a 1D toon shader. 00013 00014 * Note: Current version uses GL_TEXTURE2D, but works fine 00015 * if you load an image of size 1 x n. 00016 * 00017 **********************************************************************/ 00018 class GLSLToonShader : public GLSLShader { 00019 public: 00020 //******** MANAGERS ******** 00021 GLSLToonShader(Patch* patch = 0); 00022 00023 //******** RUN-TIME TYPE ID ******** 00024 DEFINE_RTTI_METHODS3("GLSL Toon", 00025 GLSLToonShader*, BasicTexture, CDATA_ITEM*); 00026 00027 // Set the name of the texture to use (full path): 00028 void set_tex(Cstr_ptr& full_path_name); 00029 00030 // set the TEXTUREgl to use: 00031 void set_tex(CTEXTUREglptr& tex); 00032 00033 //******** STATICS ******** 00034 00035 static GLSLToonShader* get_instance(); 00036 00037 // static methods for running the toon shader program 00038 // without necessarily having a Patch of a BMESH; 00039 static void draw_start( 00040 TEXTUREglptr toon_tex, // the 1D toon texture 00041 CCOLOR& base_color, // base color for triangles 00042 double base_alpha = 1, // base alpha for triangles 00043 bool do_culling = false // enable backface culling 00044 ); 00045 00046 static void draw_end(); 00047 00048 //******** GLSLShader VIRTUAL METHODS ******** 00049 00050 // using a static variable for program, so all toon shader 00051 // instances share the same program: 00052 virtual GLuint& program() { return _program; } 00053 virtual bool& did_init() { return _did_init; } 00054 00055 // Called in init(); query and store the "locations" of 00056 // uniform and attribute variables here: 00057 virtual bool get_variable_locs(); 00058 00059 // Send values of uniform variables to the shader: 00060 virtual bool set_uniform_variables() const; 00061 00062 // Init the 1D toon texture by loading from file: 00063 virtual void init_textures(); 00064 00065 // Activate the 1D toon texture for drawing: 00066 virtual void activate_textures(); 00067 00068 //******** DATA_ITEM VIRTUAL METHODS ******** 00069 virtual DATA_ITEM *dup() const { return new GLSLToonShader; } 00070 00071 protected: 00072 //******** Member Variables ******** 00073 TEXTUREglptr _tex; // the 1D toon texture 00074 00075 static GLint _tex_loc; // "location" of sampler2D in the program 00076 static GLuint _program; // GLSL program shared by all toon instances 00077 static bool _did_init; // tells whether initialization attempt was made 00078 00079 static GLSLToonShader* _instance; 00080 00081 //******** VIRTUAL METHODS ******** 00082 00083 // Return the names of the toon GLSL shader programs: 00084 virtual str_ptr vp_filename() { return vp_name("toon"); } 00085 00086 // XXX - temporary, until we can figure out how to not use the 00087 // fragment shader: 00088 virtual str_ptr fp_filename() { return fp_name("toon"); } 00089 00090 // we're not using any fragment shader: 00091 // XXX - we have to figure out how to not use the fragment shader 00092 // virtual str_list fp_filenames() { return str_list(); } 00093 }; 00094 00095 #endif // GLSL_TOON_H_IS_INCLUDED 00096 00097 // end of file glsl_toon.H