00001
00002
00003
00004 #include "glsl_hatching.H"
00005 #include "gtex/glsl_toon.H"
00006 #include "gtex/ref_image.H"
00007 static bool debug = Config::get_var_bool("DEBUG_GLSL_HATCHING", false);
00008
00009 inline GTexture*
00010 get_toon_shader(Patch* p)
00011 {
00012 GLSLToonShader* ret = new GLSLToonShader(p);
00013 ret->set_tex(Config::JOT_ROOT() + "nprdata/toon_textures/clear-black.png");
00014 return ret;
00015 }
00016
00017
00018
00019
00020
00021
00022
00023 GLuint GLSLHatching::_program(0);
00024 bool GLSLHatching::_did_init(false);
00025 GLint GLSLHatching::_tone_tex_loc(-1);
00026 GLint GLSLHatching::_width_loc(-1);
00027 GLint GLSLHatching::_height_loc(-1);
00028 GLint GLSLHatching::_style_loc(-1);
00029
00030 GLSLHatching::GLSLHatching(Patch* p) : GLSLPaperShader(p), _tone_shader(0)
00031 {
00032 _style[0] = 3;
00033 _style[1] = 0;
00034 _style[2] = 0;
00035 set_tone_shader(get_toon_shader(p));
00036 }
00037
00038 GLSLHatching::~GLSLHatching()
00039 {
00040 gtextures().delete_all();
00041 }
00042
00043 void
00044 GLSLHatching::set_tone_shader(GTexture* g)
00045 {
00046 if (g == _tone_shader)
00047 return;
00048 delete _tone_shader;
00049 _tone_shader = g;
00050 changed();
00051 }
00052
00053 bool
00054 GLSLHatching::get_variable_locs()
00055 {
00056 GLSLPaperShader::get_variable_locs();
00057 get_uniform_loc("style", _style_loc);
00058
00059
00060 get_uniform_loc("tone_map", _tone_tex_loc);
00061 get_uniform_loc("width", _width_loc);
00062 get_uniform_loc("height", _height_loc);
00063
00064 return true;
00065 }
00066
00067 void
00068 GLSLHatching::set_gl_state(GLbitfield mask) const
00069 {
00070 GLSLShader::set_gl_state(mask);
00071
00072
00073 GL_COL(VIEW::peek()->color(), alpha());
00074 }
00075
00076 bool
00077 GLSLHatching::set_uniform_variables() const
00078 {
00079 GLSLPaperShader::set_uniform_variables();
00080
00081 VIEWptr view = VIEW::peek();
00082
00083
00084 glUniform1i(_tone_tex_loc, TexMemRefImage::lookup_tex_unit() - GL_TEXTURE0);
00085 glUniform1i(_width_loc, view->width());
00086 glUniform1i(_height_loc, view->height());
00087
00088 glUniform3iv(_style_loc, 1, _style);
00089
00090 return true;
00091 }
00092
00093 RefImageClient::ref_img_t
00094 GLSLHatching::use_ref_image()
00095 {
00096
00097 return ref_img_t(REF_IMG_TEX_MEM);
00098 }
00099
00100 int
00101 GLSLHatching::draw_tex_mem_ref()
00102 {
00103
00104 return _tone_shader->draw(VIEW::peek());
00105 }
00106
00107 GTexture_list
00108 GLSLHatching::gtextures() const
00109 {
00110 return GTexture_list(_tone_shader);
00111 }
00112
00113
00114