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

halftone_shader.C

Go to the documentation of this file.
00001 /**************************************************************************
00002  * haltone_shader.C
00003  *************************************************************************/
00004 
00005 #include "gtex/gl_extensions.H"
00006 #include "gtex/util.H"
00007 #include "gtex/glsl_toon.H"             // Temp for testing ref images.
00008 #include "gtex/ref_image.H"
00009 //#include "geom/gl_util.H"
00010 #include "mesh/patch.H"
00011 #include "halftone_shader.H"
00012 
00013 /**********************************************************************
00014  * HalftoneShader:
00015  *
00016  *   Doesn't do anything yet.
00017  **********************************************************************/
00018 HalftoneShader::HalftoneShader(Patch* patch) :
00019    GLSLShader(patch),
00020    m_toon_tone_shader(new GLSLToonShader(patch)),
00021    _style_loc(-1),
00022    _style(0)
00023 {
00024    // Specify the texture we'd like to use.
00025    str_ptr tex_name = "nprdata/toon_textures/clear-black.png";
00026    m_toon_tone_shader->set_tex(Config::JOT_ROOT() + tex_name);
00027 
00028    _perlin=0;
00029    _perlin_generator= Perlin::get_instance();
00030    if (!_perlin_generator)
00031       _perlin_generator= new Perlin();
00032 
00033 }
00034 
00035 bool 
00036 HalftoneShader::get_variable_locs()
00037 {
00038    get_uniform_loc("origin", m_origin_loc);
00039    
00040 
00041    get_uniform_loc("u_vec",  m_u_vec_loc);
00042    get_uniform_loc("v_vec",  m_v_vec_loc);
00043    get_uniform_loc("lod", _lod_loc);
00044    
00045    get_uniform_loc("tone_map", m_tex_loc);
00046    get_uniform_loc("width", m_width);
00047    get_uniform_loc("height", m_height);
00048    get_uniform_loc("sampler2D_perlin", _perlin_loc);
00049    get_uniform_loc("style", _style_loc);
00050 
00051    return true;
00052 }
00053 
00054 bool
00055 HalftoneShader::set_uniform_variables() const
00056 {
00057    assert(_patch);
00058    _patch->update_dynamic_samples();
00059 
00060    glUniform2fv(m_origin_loc, 1, float2(_patch->sample_origin()));
00061   
00062   if (_patch->get_do_lod()) {
00063       glUniform1f (_lod_loc, float(_patch->lod_t()));
00064       glUniform2fv(m_u_vec_loc,  1, float2(_patch->lod_u()));
00065       glUniform2fv(m_v_vec_loc,  1, float2(_patch->lod_v()));
00066    } else {
00067       glUniform1f (_lod_loc, float(0));
00068       glUniform2fv(m_u_vec_loc,  1, float2(_patch->sample_u_vec()));
00069       glUniform2fv(m_v_vec_loc,  1, float2(_patch->sample_v_vec()));
00070    }
00071 
00072 
00073    glUniform1i (m_tex_loc, m_texture->get_tex_unit() - GL_TEXTURE0);
00074    glUniform1i (m_width, VIEW::peek()->width());
00075    glUniform1i (m_height, VIEW::peek()->height());
00076      if(_perlin)
00077       glUniform1i(_perlin_loc, _perlin->get_tex_unit() - GL_TEXTURE0);
00078    
00079    glUniform1i(_style_loc, _style);
00080 
00081    return true;
00082 }
00083 
00084 // This may seem a little odd, but since the texture is in texture
00085 // memory, we need to look it up from the reference image.
00086 void 
00087 HalftoneShader::init_textures()
00088 {
00089    TexMemRefImage * ref_img = TexMemRefImage::lookup(VIEW::peek());
00090    m_texture = ref_img->get_texture();
00091    _perlin = _perlin_generator->create_perlin_texture2();
00092 }
00093 
00094 void
00095 HalftoneShader::activate_textures()
00096 {
00097    activate_texture(m_texture);      // GL_ENABLE_BIT
00098    if(_perlin)
00099       activate_texture(_perlin);
00100 
00101 }
00102 
00103 GTexture_list HalftoneShader::gtextures() const
00104 {
00105    return GTexture_list(m_toon_tone_shader);
00106 }
00107 
00108 void
00109 HalftoneShader::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 // ******** GTexture VIRTUAL METHODS ********
00117 
00118 RefImageClient::ref_img_t 
00119 HalftoneShader::use_ref_image()
00120 {
00121    // Tells the caller that we want to use a TexMemRefImage
00122    return ref_img_t(REF_IMG_TEX_MEM);
00123 }
00124 
00125 int 
00126 HalftoneShader::draw_tex_mem_ref()
00127 {
00128    // Draw the reference image for tone.
00129    return m_toon_tone_shader->draw(VIEW::peek());
00130 }
00131 
00132 // End of file halftone_shader.C

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