int
PatchIDTexture::draw(CVIEWptr& v)
{
   // filled triangles -- regular state
   // do backface culling for closed meshes
   glPushAttrib( GL_LIGHTING_BIT |       // shade model
                GL_CURRENT_BIT |        // current color
                GL_ENABLE_BIT);         // lighting, culling, blending

   glShadeModel(GL_FLAT);               // GL_LIGHTING_BIT
   glDisable(GL_LIGHTING);              // GL_ENABLE_BIT
   glDisable(GL_BLEND);                 // GL_ENABLE_BIT
   set_face_culling();                               // GL_ENABLE_BIT

   // draw triangles and/or polyline strips
   // use a display list if it's valid:

   _patch->draw_tri_strips(_cb); 

   // restore gl state:
   glPopAttrib();


   return _patch->num_faces();
}
int
ColorIDTexture::draw(CVIEWptr& v)
{
   switch (_polygon_mode) {
    case GL_FILL:
      // filled triangles -- regular state
      // do backface culling for closed meshes
      push_gl_state(0);
      set_face_culling();                               // GL_ENABLE_BIT
    brcase GL_LINE:
      // wireframe triangles
      push_gl_state(GL_LINE_BIT | GL_POLYGON_BIT);
      glLineWidth(_width);                              // GL_LINE_BIT
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);        // GL_POLYGON_BIT
      glDisable(GL_CULL_FACE);                          // GL_ENABLE_BIT
    brcase GL_POINT:
      // drawing points for some strange reason
      push_gl_state(GL_POINT_BIT | GL_POLYGON_BIT);
      glPointSize(_width);                              // GL_POINT_BIT
      glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);       // GL_POLYGON_BIT
      glDisable(GL_CULL_FACE);                          // GL_ENABLE_BIT
    brdefault:
      err_msg( "ColorIDTexture::draw: error: unknown mode: %d", _polygon_mode);
      push_gl_state(0);
   }

   // draw triangles and/or polyline strips
   // use a display list if it's valid:
   if (!BasicTexture::draw(v)) {

      int dl = _dl.get_dl(v, 1, _patch->stamp());
      if (dl)
         glNewList(dl, GL_COMPILE);

      _patch->draw_tri_strips(_cb); 

      // restore gl state:
      glPopAttrib();

      // end the display list here
      if (_dl.dl(v)) {
         _dl.close_dl(v);

         // the display list is built; now execute it
         BasicTexture::draw(v);
      }
   }

   return _patch->num_faces();
}
Example #3
0
void GLRenderer::renderMesh(RenderState& rstate, RenderData* render_data) {

    for (int curr_pass = 0; curr_pass < render_data->pass_count();
            ++curr_pass) {
        numberTriangles += render_data->mesh()->getNumTriangles();
        numberDrawCalls++;

        set_face_culling(render_data->pass(curr_pass)->cull_face());
        Material* curr_material = rstate.material_override;

        if (curr_material == nullptr)
            curr_material = render_data->pass(curr_pass)->material();
        if (curr_material != nullptr) {
            GL(renderMaterialShader(rstate, render_data, curr_material));
        }
    }
}
Example #4
0
int
FlatShadeTexture::draw(CVIEWptr& v)
{
   if (_ctrl)
      return _ctrl->draw(v);
   _cb->alpha = alpha();

   if (!_patch)
      return 0;

   // Don't draw w/ texture maps if there are no uv coords at all.
   // but don't check every frame whether there are uv coords:
   
   if (_check_uv_coords_stamp != _patch->stamp()) {
      _has_uv_coords = _patch->cur_faces().any_satisfy(HasUVFaceFilter());
      _check_uv_coords_stamp = _patch->stamp();
   }

   // Set gl state (lighting, shade model)
   glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT);
   glEnable(GL_LIGHTING);               // GL_ENABLE_BIT
   glShadeModel(GL_FLAT);               // GL_LIGHTING_BIT
   GL_COL(_patch->color(), alpha());    // GL_CURRENT_BIT
   
   if (debug_uv()) {

      //assign some texture coords if no tex_coord_gen is assigned
      if (!_patch->tex_coord_gen()) {
         _patch->set_tex_coord_gen(new GLSphirTexCoordGen);      
      }

      // decide what image file to use to show the uv-coords:
      str_ptr debug_uv_tex_name =
         Config::get_var_str("DEBUG_UV_TEX_MAP", "checkerboard.png",true);
      static str_ptr pre_path = Config::JOT_ROOT() + "nprdata/other_textures/";
      str_ptr path = pre_path + debug_uv_tex_name;

      // we only try a given pathname once. but if it fails
      // and they reset DEBUG_UV_TEX_MAP while running the
      // program we can pick up the change and try again.
      if (path != _debug_tex_path) {
         _debug_tex_path = path;
         TEXTUREglptr tex = new TEXTUREgl(_debug_tex_path);
         bool do_mipmap = Config::get_var_bool("DEBUG_TEX_USE_MIPMAP",false);
         tex->set_mipmap(do_mipmap);
         _debug_uv_tex = tex;
         _debug_uv_in_dl = false;

         if (debug) {
            cerr << "Loading debug uv texture " << **path << " ..." << endl;
         }

         if (!_debug_uv_tex->load_texture()) {
            cerr << "Can't load debug uv texture: "
                 << **_debug_tex_path
                 << endl
                 << "Set environment variable DEBUG_UV_TEX_MAP "
                 << "to an image file in "
                 << **pre_path
                 << " and try again."
                 << endl;
            _debug_uv_tex = 0;
         }
      }

      // Apply the texture if any faces have uv coordinates:
      if (_debug_uv_tex /*&& _has_uv_coords*/) //<- using auto UV
         _debug_uv_tex->apply_texture(); // GL_ENABLE_BIT

   } else {
      
      // XXX - dumb hack
      check_patch_texture_map();

      // if (_has_uv_coords)    <- using auto UV
      _patch->apply_texture(); // GL_ENABLE_BIT
   }

   // Set material parameters for OGL:
   GtexUtil::setup_material(_patch);

   // Try for the display list if it's valid
   if (!(_debug_uv == _debug_uv_in_dl && BasicTexture::draw(v))) {

      // Try to generate a display list
      int dl = _dl.get_dl(v, 1, _patch->stamp());
      if (dl) {
         glNewList(dl, GL_COMPILE);
         _debug_uv_in_dl = _debug_uv;
      }
      
      // Set up face culling for closed surfaces
      if (!set_face_culling()) 
         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);  // GL_LIGHTING_BIT
      
      FlatShadeStripCB *flat_cb = dynamic_cast<FlatShadeStripCB*>(_cb);
      if (flat_cb) {
         // send texture coordinates?
         if ((_debug_uv && _debug_uv_tex) ||
             (_has_uv_coords && _patch->has_texture())) {
            flat_cb->enable_texcoords();
         } else {
            flat_cb->disable_texcoords();
         }
      }
      err_adv(debug && _debug_uv, "  drawing uvs in flat shade");
      
      // draw the triangle strips
      _patch->draw_tri_strips(_cb);

      // end the display list here
      if (_dl.dl(v)) {
         _dl.close_dl(v);

         // the display list is built; now execute it
         BasicTexture::draw(v);
      }
   }

   // restore GL state
   glPopAttrib();

   // Have to move this outside the display list and gl push/pop attrib
   // or else it's all:
/*
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
*/
   if (_debug_uv) {

      // Build the edge strip at the current subdivision level
      Bedge_list edges = _patch->cur_edges();
      edges.clear_flags();

      // If secondary edges shouldn't be drawn, set their flags
      // so they won't be drawn:
      if (!BMESH::show_secondary_faces())
         edges.secondary_edges().set_flags(1);

      // Draw uv-discontinuity boundaries as yellow lines.
      // Construct filter that accepts unreached uv-discontinuous
      // edges of this patch:
      UnreachedSimplexFilter    unreached;
      UVDiscontinuousEdgeFilter uvdisc;
      PatchEdgeFilter           mine(_patch->cur_patch());
      EdgeStrip disc_edges(edges, unreached + uvdisc + mine);
      if (!disc_edges.empty()) {
         GtexUtil::draw_strip(disc_edges, 3, Color::yellow, 0.8);
      }
   }

   GL_VIEW::print_gl_errors("FlatShadeTexture::draw - End");

   return _patch->num_faces();
}
Example #5
0
int
SolidColorTexture::draw(CVIEWptr& v)
{
   if (_ctrl)
      return _ctrl->draw(v);

   bool show_weights = debug_patch_blend;
   if (show_weights) {
      if (!dynamic_cast<PatchBlendStripCB*>(cb())) {
         set_cb(new PatchBlendStripCB(patch()));
         assert(dynamic_cast<PatchBlendStripCB*>(cb()));
      }
   } else if (dynamic_cast<PatchBlendStripCB*>(cb())) {
      dynamic_cast<PatchBlendStripCB*>(cb())->set_patch(0);
   }

   // push GL state before changing things
   glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT);

   // Set the color
   COLOR  c = _color;
   double a = _alpha*alpha();
   if (_track_view_color)
      c = v->color();
   glColor4fv(float4(c,a));

   // try it with the display list:
   if (BasicTexture::draw(v))
      return _patch->num_faces();

   // ensure this never happens again! get a display list:
   int dl = _dl.get_dl(v, 1, _patch->stamp());
   if (dl)
      glNewList(dl, GL_COMPILE);

   glDisable(GL_LIGHTING);      // GL_ENABLE_BIT

   // set up face culling for closed surfaces
   set_face_culling();          // GL_ENABLE_BIT

   // draw the triangle strips
   PatchBlendStripCB* pbcb = dynamic_cast<PatchBlendStripCB*>(cb());
   if (show_weights) {
      glEnable(GL_BLEND);                                // GL_ENABLE_BIT
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT
      if (Config::get_var_bool("DEBUG_PATCH_BLEND_WEIGHTS",false)) {
         cerr << "SolidColorTexture::draw: patch "
              << mesh()->patches().get_index(patch())
              << ": drawing patch blend weights"
              << endl;
      }
      mesh()->update_patch_blend_weights();
      assert(pbcb);
      pbcb->set_patch(patch()->cur_patch());
      pbcb->set_color(c,a);
      _patch->draw_n_ring_triangles(
         mesh()->patch_blend_smooth_passes() + 1, pbcb, false
         );
      // draw the boundary w/ given line width and color:
      EdgeStrip bdry = patch()->cur_faces().get_boundary();
      GtexUtil::draw_strip(bdry, 2, Color::yellow);
   } else {
      if (pbcb)
         pbcb->set_patch(0);
      _patch->draw_tri_strips(_cb);
   }

   // restore gl state:
   glPopAttrib();

   // end the display list here
   if (_dl.dl(v)) {
      _dl.close_dl(v);

      // the display list is built; now execute it
      BasicTexture::draw(v);
   }

   return _patch->num_faces();
}