00001 /********************************************************************** 00002 * dots.H: 00003 **********************************************************************/ 00004 #ifndef DOTS_H_IS_INCLUDED 00005 #define DOTS_H_IS_INCLUDED 00006 00007 #include "glsl_shader.H" 00008 00009 /********************************************************************** 00010 * DotsShader: 00011 * 00012 * Halftone shader based on dots 00013 * 00014 **********************************************************************/ 00015 class DotsShader : public GLSLShader { 00016 public: 00017 //******** MANAGERS ******** 00018 DotsShader(Patch* patch = 0); 00019 00020 virtual ~DotsShader(); 00021 00022 //******** RUN-TIME TYPE ID ******** 00023 DEFINE_RTTI_METHODS3("Dots", DotsShader*, GLSLShader, CDATA_ITEM*); 00024 00025 //******** ACCESSORS ******** 00026 void set_style(int s) { _style = s; } 00027 00028 void set_tone_shader(GTexture* g); 00029 00030 //******** GLSLShader VIRTUAL METHODS ******** 00031 00032 // base classes can over-ride this to maintain their own program 00033 // variable, e.g. to share a single program among all instances of 00034 // the derived class: 00035 virtual GLuint& program() { return _program; } 00036 virtual bool& did_init() { return _did_init; } 00037 00038 // lookup uniform and attribute variable "locations": 00039 virtual bool get_variable_locs(); 00040 00041 // send values to uniform variables: 00042 virtual bool set_uniform_variables() const; 00043 00044 // Calls glPushAttrib() and sets some OpenGL state: 00045 virtual void set_gl_state(GLbitfield mask=0) const; 00046 00047 // Returns a list of the slave gtextures of this class 00048 virtual GTexture_list gtextures() const; 00049 00050 // ******** GTexture VIRTUAL METHODS ******** 00051 virtual ref_img_t use_ref_image(); 00052 virtual int draw_tex_mem_ref(); 00053 00054 //******** DATA_ITEM VIRTUAL METHODS ******** 00055 virtual DATA_ITEM *dup() const { return new DotsShader; } 00056 00057 protected: 00058 //******** Member Variables ******** 00059 // shader used to draw the tone reference image: 00060 GTexture* _tone_shader; 00061 00062 // integer encoding what style parameters to use: 00063 int _style; 00064 00065 static GLuint _program; // shared by all DotsShader instances 00066 static bool _did_init; // tells whether initialization attempt was made 00067 00068 // dynamic 2D pattern variables: 00069 static GLint _origin_loc; 00070 static GLint _u_vec_loc; 00071 static GLint _v_vec_loc; 00072 static GLint _st_loc; 00073 00074 // tone map variables: 00075 static GLint _tone_tex_loc; 00076 static GLint _width_loc; 00077 static GLint _height_loc; 00078 00079 static GLint _style_loc; 00080 00081 //******** VIRTUAL METHODS ******** 00082 00083 // use the same vertex program as hatching shader: 00084 virtual str_ptr vp_filename() { return vp_name("hatching"); } 00085 00086 // GLSL fragment shader name 00087 virtual str_ptr fp_filename() { return fp_name("halftone-dots"); } 00088 }; 00089 00090 #endif // DOTS_H_IS_INCLUDED 00091 00092 // end of file dots.H