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

glsl_marble.C

Go to the documentation of this file.
00001 /*****************************************************************
00002 * glsl_marble.C
00003 *****************************************************************/
00004 #include "gtex/gl_extensions.H"
00005 #include "glsl_marble.H"
00006 
00007 static bool debug = Config::get_var_bool("DEBUG_GLSL_MARBLE", false);
00008 
00009 /**********************************************************************
00010 * Utilities
00011 **********************************************************************/
00012 inline str_ptr 
00013 tex_path()
00014 {
00015    return Config::JOT_ROOT() + "nprdata/toon_textures/"; 
00016 }
00017 
00018 inline str_ptr
00019 toon_name(Cstr_ptr& name)
00020 {
00021    return tex_path() + name;
00022 }
00023 
00024 /**********************************************************************
00025 * GLSLMarbleShader:
00026 *
00027 *   Does 1D Toon shading in GLSL.
00028 **********************************************************************/
00029 GLSLMarbleShader::GLSLMarbleShader(Patch* p) :
00030 GLSLShader(p, new VertNormStripCB)
00031 {
00032    set_tex(toon_name(
00033       Config::get_var_str("GLSL_TOON_FILENAME","clear-black.png")
00034       )); 
00035    
00036    _perlin=0;
00037    _perlin_generator= Perlin::get_instance();
00038    if (!_perlin_generator)
00039       _perlin_generator= new Perlin();
00040 }
00041 
00042 void 
00043 GLSLMarbleShader::set_tex(Cstr_ptr& filename)
00044 {
00045    // Set the name of the texture to use
00046 
00047    if (_tex) {
00048       _tex->set_texture(filename);
00049    } else {
00050       _tex = new TEXTUREgl(filename);
00051 
00052       // set parameters
00053       _tex->set_wrap_s(GL_CLAMP_TO_EDGE);
00054       _tex->set_wrap_t(GL_CLAMP_TO_EDGE);
00055       assert(_tex);
00056    }
00057 
00058 
00059 }
00060 
00061 void
00062 GLSLMarbleShader::init_textures()
00063 {
00064    // no-op after the first time:
00065 
00066 
00067 
00068     _perlin = _perlin_generator->create_perlin_texture3();
00069 
00070    if (!load_texture(_tex))
00071       return;
00072 }
00073 
00074 void
00075 GLSLMarbleShader::activate_textures()
00076 {
00077    activate_texture(_tex);      // GL_ENABLE_BIT
00078    if(_perlin)
00079       activate_texture(_perlin);
00080 
00081 }
00082 
00083 bool 
00084 GLSLMarbleShader::get_variable_locs()
00085 {
00086    get_uniform_loc("toon_tex", _tex_loc);
00087    get_uniform_loc("sampler3D_perlin", _perlin_loc);
00088   
00089 
00090    // other variables here as needed...
00091 
00092    return true;
00093 }
00094 
00095 bool
00096 GLSLMarbleShader::set_uniform_variables() const
00097 {
00098    // send uniform variable values to the program
00099 
00100    glUniform1i(_tex_loc, _tex->get_tex_unit() - GL_TEXTURE0);
00101    if(_perlin)
00102       glUniform1i(_perlin_loc, _perlin->get_tex_unit() - GL_TEXTURE0);
00103 
00104 
00105    return true;
00106 }
00107 
00108 // end of file glsl_marble.C

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