Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

glsl_hatching.C

Go to the documentation of this file.
00001 /*****************************************************************
00002  * glsl_hatching.C
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  * GLSLHatching:
00019  *
00020  *   Draws evenly spaced 2D lines that vary width and pressure,
00021  *   rendered with paper effect. Looks like pencil.
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    // tone map variables
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    // set the color from the VIEW background color:
00073    GL_COL(VIEW::peek()->color(), alpha());    // GL_CURRENT_BIT
00074 }
00075 
00076 bool
00077 GLSLHatching::set_uniform_variables() const
00078 {
00079    GLSLPaperShader::set_uniform_variables();
00080 
00081    VIEWptr view = VIEW::peek();
00082 
00083    //tone map variables
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    // Tells the caller that we want to use a TexMemRefImage
00097    return ref_img_t(REF_IMG_TEX_MEM);
00098 }
00099 
00100 int 
00101 GLSLHatching::draw_tex_mem_ref()
00102 {
00103    // Draw the reference image for tone.
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 // end of file glsl_hatching.C

Generated on Mon Sep 18 11:39:31 2006 for jot by  doxygen 1.4.4