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

buffer_ref_image.C

Go to the documentation of this file.
00001 #include "buffer_ref_image.H"
00002 #include "geom/world.H"
00003 #include "geom/gl_view.H"
00004 
00005 /**********************************************************************
00006  * BufferRefImage:
00007  **********************************************************************/
00008 
00009 HASH    BufferRefImage::_hash(16);
00010 
00011 BufferRefImage* 
00012 BufferRefImage::lookup(CVIEWptr& v) 
00013 {
00014    if (!v) {
00015       err_msg( "BufferRefImage::lookup: error -- view is nil");
00016       return 0;
00017    }
00018    if (!v->impl()) {
00019       err_msg( "BufferImage::lookup: error -- view->impl() is nil");
00020       return 0;
00021    }
00022 
00023    // hash on the view implementation rather than the view itself
00024    long key = (long)v->impl();
00025    BufferRefImage* ret = (BufferRefImage*) _hash.find(key);
00026    if (!ret && (ret = new BufferRefImage(v)))
00027       _hash.add(key, (void *)ret);
00028    return ret;
00029 }
00030 
00031 int  
00032 BufferRefImage::need_update()  
00033 { 
00034 
00035    if (!is_observing())  {
00036       cerr << "BufferRefImage:need_update - Asked if update is needed --  "
00037            << "But we're not observing!\n";
00038       return false;
00039    }
00040    int w, h; 
00041    _view->get_size(w,h); 
00042    return (resize(w,h) || _dirty);
00043 }
00044 
00045 void
00046 BufferRefImage::update() 
00047 {
00048    if (!need_update())
00049       return;
00050 
00051    cerr << "BufferRefImage: Updated!\n";
00052 
00053    assert (_view != 0);
00054    VIEWimpl *impl = _view->impl();
00055    assert(impl != 0);
00056 
00057    _observing = false;
00058    impl->draw_setup();
00059    impl->draw_frame();
00060    _observing=true;
00061    
00062    glViewport(0,0,_width,_height);
00063    glReadPixels(0,0,_width,_height,_format,_type,_values);
00064 
00065    _dirty = 0;
00066   
00067 }
00068 
00069 BufferRefImage::BufferRefImage(CVIEWptr& v) : RefImage(v)  
00070 {
00071    _f = NULL;
00072    reset();
00073    _observing=false;
00074 
00075    // XXX - This should be in observe/unobserve, but it breaks it -- I
00076    // dunno why...
00077         
00078    WORLD::get_world()->schedule(this);
00079 
00080 }
00081 
00082 
00083 void 
00084 BufferRefImage::observe()  
00085 {
00086    _f = WORLD::lookup("fps");
00087    if (_f)
00088    {
00089       add(_f);
00090       WORLD::undisplay(_f, false);
00091    }
00092 
00093    reset();
00094    if (_view) {
00095       _observing = true;
00096       disp_obs();
00097       xform_obs();
00098       subscribe_all_mesh_notifications();
00099       _view->cam()->data()->add_cb(this);
00100       view_obs();
00101    }
00102 }
00103 
00104 void 
00105 BufferRefImage::unobserve()  
00106 {
00107    if (_f)
00108    {
00109       WORLD::display(_f, false);
00110       rem(_f);
00111       _f = NULL;
00112    }
00113 
00114    if (_list.num() > 0)  {
00115       cerr << "BufferRefImage::unobserve - Cannot comply, "
00116            << "the high priority list isn't empty!\n";
00117       return;
00118    }
00119 
00120    if (_view) {
00121       unobs_display();
00122       unobs_xform();
00123       unsubscribe_all_mesh_notifications();
00124       _view->cam()->data()->rem_cb(this);
00125       unobs_view();
00126       //WORLD::get_world()->unschedule(this);
00127    }
00128    _observing = false;
00129 }
00130 
00131 int
00132 BufferRefImage::tick() 
00133 {
00134    //XXX - This would be unnecessary if we unscheduled (but that breaks...)
00135    if (!is_observing()) return 1;
00136 
00137    if (_countup++ > COUNTUP && _dirty)
00138       update();
00139    return 1;
00140 }
00141 
00142 /* end of file buffer_ref_image.C */

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