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

dots.C

Go to the documentation of this file.
00001 /*****************************************************************
00002  * dots.C
00003  *****************************************************************/
00004 #include "mesh/mi.H"
00005 #include "dots.H"
00006 #include "gtex/glsl_toon.H"
00007 #include "gtex/ref_image.H"
00008 
00009 static bool debug = Config::get_var_bool("DEBUG_DOTS", false);
00010 
00011 inline GTexture*
00012 get_toon_shader(Patch* p)
00013 {
00014    GLSLToonShader* ret = new GLSLToonShader(p);
00015    ret->set_tex(Config::JOT_ROOT() + "nprdata/toon_textures/clear-black.png");
00016    return ret;
00017 }
00018 
00019 /*****************************************************************
00020  * DotsShader:
00021  *
00022  *   Does dot-based halftoning
00023  *****************************************************************/
00024 GLuint  DotsShader::_program(0);
00025 bool    DotsShader::_did_init(false);
00026 GLint   DotsShader::_origin_loc(-1);
00027 GLint   DotsShader::_u_vec_loc(-1);
00028 GLint   DotsShader::_v_vec_loc(-1);
00029 GLint   DotsShader::_st_loc(-1);
00030 GLint   DotsShader::_style_loc(-1);
00031 GLint   DotsShader::_tone_tex_loc(-1);
00032 GLint   DotsShader::_width_loc(-1);
00033 GLint   DotsShader::_height_loc(-1);
00034 
00035 DotsShader::DotsShader(Patch* p) :
00036    GLSLShader(p),
00037    _tone_shader(0),
00038    _style(0)
00039 {
00040    set_tone_shader(get_toon_shader(p));
00041 }
00042 
00043 DotsShader::~DotsShader() 
00044 {
00045    gtextures().delete_all(); 
00046 }
00047 
00048 void
00049 DotsShader::set_tone_shader(GTexture* g)
00050 {
00051    if (g == _tone_shader)
00052       return;
00053    delete _tone_shader;
00054    _tone_shader = g;
00055    changed();
00056 }
00057 
00058 bool 
00059 DotsShader::get_variable_locs()
00060 {
00061    get_uniform_loc("origin", _origin_loc);
00062    get_uniform_loc("u_vec",  _u_vec_loc);
00063    get_uniform_loc("v_vec",  _v_vec_loc);
00064    get_uniform_loc("st",     _st_loc);
00065    get_uniform_loc("style",  _style_loc);
00066 
00067    // tone map variables
00068    get_uniform_loc("tone_map", _tone_tex_loc);
00069    get_uniform_loc("width",  _width_loc);
00070    get_uniform_loc("height", _height_loc);
00071 
00072    return true;
00073 }
00074 
00075 bool
00076 DotsShader::set_uniform_variables() const
00077 {
00078    assert(_patch);   
00079 
00080    //tone map variables
00081    glUniform1i(_tone_tex_loc, TexMemRefImage::lookup_tex_unit() - GL_TEXTURE0);
00082    glUniform1i(_width_loc,  VIEW::peek()->width());
00083    glUniform1i(_height_loc, VIEW::peek()->height());
00084 
00085    _patch->update_dynamic_samples();
00086    glUniform2fv(_origin_loc, 1, float2(_patch->sample_origin()));
00087    glUniform1i (_style_loc, _style);
00088 
00089    if (_patch->get_do_lod()) {
00090       glUniform1f (_st_loc, float(_patch->lod_t()));
00091       glUniform2fv(_u_vec_loc,  1, float2(_patch->lod_u()));
00092       glUniform2fv(_v_vec_loc,  1, float2(_patch->lod_v()));
00093    } else {
00094       glUniform1f (_st_loc, float(0));
00095       glUniform2fv(_u_vec_loc,  1, float2(_patch->sample_u_vec()));
00096       glUniform2fv(_v_vec_loc,  1, float2(_patch->sample_v_vec()));
00097    }
00098 
00099    return true;
00100 }
00101 
00102 GTexture_list 
00103 DotsShader::gtextures() const
00104 {
00105    return GTexture_list(_tone_shader);
00106 }
00107 
00108 void
00109 DotsShader::set_gl_state(GLbitfield mask) const
00110 {
00111    GLSLShader::set_gl_state(mask);
00112    // set the color from the VIEW background color:
00113    GL_COL(VIEW::peek()->color(), alpha());    // GL_CURRENT_BIT
00114 }
00115 
00116 RefImageClient::ref_img_t 
00117 DotsShader::use_ref_image()
00118 {
00119    // Tells the caller that we want to use a TexMemRefImage
00120    return ref_img_t(REF_IMG_TEX_MEM);
00121 }
00122 
00123 int 
00124 DotsShader::draw_tex_mem_ref()
00125 {
00126    // Draw the reference image for tone.
00127    return _tone_shader->draw(VIEW::peek());
00128 }
00129 
00130 // end of file dots.C

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