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

basic_texture.C

Go to the documentation of this file.
00001 /**********************************************************************
00002  * basic_texture.C
00003  **********************************************************************/
00004 #include "geom/texturegl.H"
00005 #include "mesh/ioblock.H"
00006 #include "mesh/lmesh.H"
00007 #include "std/config.H"
00008 
00009 #include "basic_texture.H"
00010 #include "color_id_texture.H"
00011 #include "control_line.H"
00012 #include "creases_texture.H"
00013 #include "curvature_texture.H"
00014 #include "line_drawing.H"
00015 #include "fader_texture.H"
00016 #include "flat_shade.H"
00017 #include "hidden_line.H"
00018 #include "key_line.H"
00019 #include "normals_texture.H"
00020 #include "ref_image.H"
00021 #include "sil_frame.H"
00022 #include "smooth_shade.H"
00023 #include "solid_color.H"
00024 #include "tri_strips_texture.H"
00025 #include "wireframe.H"
00026 #include "zxsil_frame.H"
00027 #include "toon_texture_1D.H"
00028 #include "glsl_shader.H"
00029 #include "halftone_shader.H"
00030 #include "halftone_shader_ex.H"
00031 #include "glsl_xtoon.H"
00032 #include "glsl_toon.H"
00033 #include "glsl_halo.H"
00034 #include "glsl_toon_halo.H"
00035 #include "dots.H"
00036 #include "dots_ex.H"
00037 #include "glsl_hatching.H"
00038 #include "glsl_marble.H"
00039 #include "msld.H"
00040 
00041 // make sure textures can be looked up via DECODER mechanism
00042 class DecoderAdds {
00043  public:
00044   DecoderAdds() {
00045     DECODER_ADD(ColorIDTexture);
00046     DECODER_ADD(ControlFrameTexture);
00047     DECODER_ADD(ControlLineTexture);
00048     DECODER_ADD(CreasesTexture);
00049     DECODER_ADD(CurvatureTexture);
00050     DECODER_ADD(FlatShadeTexture);
00051     DECODER_ADD(HiddenLineTexture);
00052     DECODER_ADD(KeyLineTexture);
00053     DECODER_ADD(LineDrawingTexture);
00054     DECODER_ADD(NormalsTexture);
00055     DECODER_ADD(SilFrameTexture);
00056     DECODER_ADD(SmoothShadeTexture);
00057     DECODER_ADD(SolidColorTexture);
00058     DECODER_ADD(TriStripsTexture);
00059     DECODER_ADD(VertColorTexture);
00060     DECODER_ADD(WireframeTexture);
00061     DECODER_ADD(ZcrossFrameTexture);   
00062     DECODER_ADD(ToonTexture_1D);
00063     DECODER_ADD(GLSLShader);
00064     DECODER_ADD(GLSLLightingShader);
00065     DECODER_ADD(HalftoneShader);
00066    DECODER_ADD(HalftoneShaderEx);
00067     DECODER_ADD(GLSLXToonShader);
00068     DECODER_ADD(GLSLToonShader);
00069    DECODER_ADD(GLSLHaloShader);
00070    DECODER_ADD(GLSLToonShaderHalo);
00071     DECODER_ADD(DotsShader);
00072    DECODER_ADD(DotsShader_EX);
00073     DECODER_ADD(GLSLHatching);
00074    DECODER_ADD(GLSLMarbleShader);
00075    DECODER_ADD(MSLDShader);
00076   }
00077 } DecoderAdds_static;
00078 
00079 class SetupGL {
00080  public:
00081    SetupGL() {
00082 
00083       // Use VisRefImage's for visibility reference images
00084       VisRefImage::init();
00085    }
00086 } SetupGL_static;
00087 
00088 // XXX casey 3/18
00089 // XXX enable stencilling; disable all else; just draw to stencil buffer
00090 
00091 int OGLTexture::draw_stencil() {
00092    
00093    if (_patch == NULL) return -1;
00094    // push/pop attribs instead
00095    glColorMask(0, 0, 0, 0);
00096    glDisable(GL_DEPTH_TEST);
00097    //glStencilFunc(GL_ALWAYS, _patch->stencil_id(), 0xFF); 
00098    glStencilFunc(GL_ALWAYS, 1, 0xFF);
00099    glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
00100    //glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
00101    // just need the simplest kind- just uses GlVertex()
00102    GLStripCB cb; 
00103    _patch->draw_tri_strips(&cb);
00104    
00105    glColorMask(1, 1, 1, 1);
00106    glEnable(GL_DEPTH_TEST);
00107    
00108    return 1;
00109 }
00110 
00111 bool
00112 OGLTexture::set_face_culling() const 
00113 {
00114    // affects GL_ENABLE_BIT
00115 
00116    static bool no_cull = Config::get_var_bool("JOT_NO_FACE_CULLING",false);
00117 
00118    // If it's not VERBOTEN, and there's a reason to cull, then do:
00119    BMESH* m = get_cur_mesh(mesh());
00120    bool ret = (!no_cull && m && m->is_closed_surface());
00121    if (ret) glEnable (GL_CULL_FACE);        
00122    else     glDisable(GL_CULL_FACE);
00123    return ret;
00124 }
00125 
00126 int  
00127 OGLTexture::draw_vis_ref() 
00128 {
00129    // draw for visibility
00130    GTexture *tex = _patch->get_tex(ColorIDTexture::static_name());
00131 
00132    // Draw simple, filled ID-colored triangles.
00133    // Some derived GTextures like Wireframe should override this and
00134    // draw wireframe ID-colored triangles (e.g.).
00135    return tex ? tex->draw(VIEW::peek()) : 0;
00136 } 
00137 
00138 int  
00139 OGLTexture::draw_id_ref() 
00140 { 
00141    ColorIDTexture *tex = (ColorIDTexture*)
00142       _patch->get_tex(ColorIDTexture::static_name());
00143 
00144    if (tex) {
00145       // If the GTexture is requesting the ID reference image,
00146       // draw simple, filled ID-colored triangles. That ought to
00147       // be good enough for most GTextures, and any fancier ones
00148       // can override this and draw it their own special way.
00149       return (
00150          (use_ref_image() & REF_IMG_ID) ?
00151          tex->draw(VIEW::peek()) :
00152          tex->draw_black(VIEW::peek())
00153          );
00154    }
00155 
00156    return 0;
00157 } 
00158 
00159 int  
00160 OGLTexture::draw_id_sils(bool omit_concave_sils, GLfloat width) 
00161 {
00162    // This is here for convenience because several GTextures use it.
00163    //
00164    // Draw silhouettes into the ID reference image, optionally
00165    // omitting the concave ones. This is useful in conjunction with
00166    // drawing filled triangles (black or ID colored) with polygon
00167    // offset, since the "backfacing" (concave) silhouette edges, which
00168    // should not be visible, show up incorrectly during rasterization,
00169    // which really sucks.
00170 
00171    // get the silhouette edges
00172    EdgeStrip& sils = _patch->cur_sils();
00173 
00174    if (omit_concave_sils) {
00175       // get an edge strip that omits the concave sil edges
00176       static EdgeStrip convex_sil_edges = sils.get_filtered(ConvexEdgeFilter());
00177       ColorIDTexture::draw_edges(&convex_sil_edges, width);
00178    } else {
00179       ColorIDTexture::draw_edges(&sils, width);
00180    }
00181 
00182    return 0;
00183 }
00184    
00185 int  
00186 OGLTexture::draw_id_triangles(bool   use_polygon_offset, 
00187                               bool   draw_id_colors,
00188                               double offset_factor,
00189                               double offset_units) 
00190 {
00191    // Another convenience method ... works well with the previous one.
00192 
00193    // draw triangles with ID colors, or black
00194    ColorIDTexture *tex = (ColorIDTexture*)
00195       _patch->get_tex(ColorIDTexture::static_name());
00196    if (tex) {
00197       if (use_polygon_offset)
00198          GL_VIEW::init_polygon_offset((float)offset_factor,
00199                                       (float)offset_units);
00200       if (draw_id_colors) tex->draw(VIEW::peek());
00201       else                tex->draw_black(VIEW::peek());
00202       if (use_polygon_offset)
00203          GL_VIEW::end_polygon_offset();
00204    } else
00205       err_msg( "OGLTexture::draw_id_triangles: warning -- no ColorIDTexture");
00206 
00207    return _patch->num_faces();
00208 }
00209 
00210 int
00211 OGLTexture::draw_id_creases(GLfloat width) 
00212 {
00213    // Yet another convenience method, for drawing crease id's this time.
00214 
00215    // get the crease edges
00216    EdgeStrip* creases = _patch->cur_creases();
00217 
00218    ColorIDTexture::draw_edges(creases, width);
00219 
00220    return 0;
00221 }
00222 
00223 void 
00224 OGLTexture::draw_vert_and_edge_strips(
00225    bool disable_lights,
00226    GLfloat line_width,
00227    GLfloat point_size,
00228    bool set_color,
00229    CCOLOR& color
00230    ) const 
00231 {
00232    // most textures need to check for vertex and edge strips, and draw
00233    // them if needed, and most do so in the same way, so this is here
00234    // for convenience.
00235 
00236    // edge strips
00237    if (_patch->num_edge_strips() > 0) {
00238       if (disable_lights) {
00239          glDisable(GL_LIGHTING);  // GL_ENABLE_BIT
00240          disable_lights = 0;
00241       }
00242       if (set_color) {
00243          glColor3dv(color.data());
00244          set_color = 0;
00245       }
00246       glLineWidth(line_width);
00247       _patch->draw_edge_strips(_cb);
00248       glLineWidth(1.0); // restore default
00249    }
00250 
00251    // vertex strips
00252    if (_patch->num_vert_strips() > 0) {
00253       if (disable_lights)
00254          glDisable(GL_LIGHTING);  // GL_ENABLE_BIT
00255       if (set_color)
00256          glColor3dv(color.data());
00257       glPointSize(point_size);
00258       _patch->draw_vert_strips(_cb);
00259       glPointSize(1.0); // restore default
00260    }
00261 }
00262 
00263 void 
00264 OGLTexture::check_patch_texture_map()
00265 {
00266    // XXX - only exists as a hack
00267    //
00268    // patches can read in the name of a texture file
00269    // to be used for the texture map associated with the
00270    // the patch. but patches can't know about the TEXTUREgl
00271    // class since lib mesh isn't supposed to know about
00272    // lib geom (tho it does, for now). anyway, this checks
00273    // whether the patch got assigned a texture file name
00274    // and if so it turns it into a TEXTUREgl that it assigns
00275    // to the patch.
00276 
00277    if (!_patch || _patch->has_texture())
00278       return;
00279 
00280    Cstr_ptr& n = _patch->texture_file();
00281 
00282    if (n && n != NULL_STR) {
00283       TEXTUREptr tex = new TEXTUREgl(n);
00284 
00285       if (tex->load_texture()) {
00286          _patch->set_texture(tex);
00287       }
00288 
00289       _patch->set_texture_file(NULL_STR);
00290    }
00291 }
00292 
00293 /**********************************************************************
00294  * BasicTexture:
00295  **********************************************************************/
00296 int
00297 BasicTexture::draw(CVIEWptr &v)
00298 {
00299    // okay to draw if the display list time stamp
00300    // is more recent than the patch's time stamp
00301 
00302    int ret = dl_valid(v);
00303    
00304    if (ret==1) glCallList(_dl.dl(v));
00305 
00306    return ret;
00307 }
00308 
00309 int
00310 BasicTexture::dl_valid(CVIEWptr &v)
00311 {
00312    // okay to draw if the display list time stamp
00313    // is more recent than the patch's time stamp
00314    if (_dl.valid(v, (int) _patch->stamp())) {
00315       return 1;
00316    } else {
00317       return 0;
00318    }
00319 }
00320 
00321 // end of file basic_texture.C

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