00001
00002
00003 #include "geom/gl_view.H"
00004 #include "aux_ref_image.H"
00005
00006
00007
00008
00009
00010
00011 HASH AuxRefImage::_hash(16);
00012
00013 AuxRefImage*
00014 AuxRefImage::lookup(CVIEWptr& v)
00015 {
00016 if (!v) {
00017 err_msg( "AuxRefImage::lookup: error -- view is nil");
00018 return 0;
00019 }
00020 if (!v->impl()) {
00021 err_msg( "AuxRefImage::lookup: error -- view->impl() is nil");
00022 return 0;
00023 }
00024
00025
00026 long key = (long)v->impl();
00027 AuxRefImage* ret = (AuxRefImage*) _hash.find(key);
00028 if (!ret && (ret = new AuxRefImage(v)))
00029 _hash.add(key, (void *)ret);
00030 return ret;
00031 }
00032
00033 bool
00034 AuxRefImage::needs_update()
00035 {
00036 for (int i=0; i < _list.num(); i++)
00037 if (_list[i]->needs_update())
00038 return true;
00039
00040 return false;
00041 }
00042
00043
00044 void
00045 AuxRefImage::update()
00046 {
00047 if (!needs_update()) return;
00048
00049 int w,h;
00050 _view->get_size(w,h);
00051
00052
00053
00054 CAMptr view_cam = _view->cam();
00055
00056
00057 assert(_cam && _view->cam());
00058 *_cam = *view_cam;
00059
00060
00061
00062 _view->use_cam(_cam);
00063
00064 for (int i=0; i < _list.num(); i++) {
00065 if (_list[i]->needs_update()) {
00066
00067 AUX_JOBptr j = _list[i];
00068
00069 resize(j->width(),j->height());
00070
00071
00072
00073 _view->set_size(_width,_height,0,0);
00074
00075
00076 glDrawBuffer(GL_BACK);
00077 glReadBuffer(GL_BACK);
00078 _view->setup_lights();
00079 glLineWidth(1.0);
00080 glDepthMask(GL_TRUE);
00081 glDepthFunc(GL_LESS);
00082 glEnable(GL_DEPTH_TEST);
00083 glDisable(GL_NORMALIZE);
00084 glDisable(GL_BLEND);
00085 glEnable(GL_COLOR_MATERIAL);
00086 glEnable(GL_CULL_FACE);
00087 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
00088 glShadeModel(GL_SMOOTH);
00089
00090 CCOLOR &c = _view->color();
00091
00092 glClearColor((float)c[0],(float)c[1],(float)c[2],1);
00093 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00094
00095
00096 draw_objects(j->list());
00097
00098 glReadPixels(0,0,_width,_height,_format,_type,_values);
00099 copy_rgb(j->image());
00100 j->updated();
00101 }
00102 }
00103
00104
00105 _view->set_size(w,h,0,0);
00106
00107
00108
00109 _view->use_cam(view_cam);
00110 }
00111
00112 void
00113 AuxRefImage::draw_objects(CGELlist& drawn) const
00114 {
00115 VIEWptr view = VIEW::peek();
00116
00117 glMatrixMode(GL_PROJECTION);
00118 glLoadMatrixd(view->ndc_proj().transpose().matrix());
00119
00120 for (int i=0; i < drawn.num(); i++) {
00121 glMatrixMode(GL_MODELVIEW);
00122 glLoadIdentity();
00123 drawn[i]->draw(view);
00124 }
00125 }
00126
00127 AuxRefImage::AuxRefImage(CVIEWptr& v) :
00128 RefImage(v),
00129 _cam(new CAM("AuxRefImage cam"))
00130 {
00131 }
00132
00133