00001
00002
00003
00004
00005
00006
00007
00008 #include "std/support.H"
00009 #include "glew/glew.H"
00010
00011 #include "dlhandler.H"
00012 #include "std/config.H"
00013
00014
00015 static bool dl_per_view = Config::get_var_bool("JOT_MULTITHREAD",false,true) ||
00016 Config::get_var_bool("JOT_DL_PER_VIEW",false,true);
00017
00018 static bool debug_threads = Config::get_var_bool("JOT_DEBUG_THREADS",false,true);
00019
00020
00021
00022
00023
00024
00025 DLhandler::DLhandler()
00026 {
00027 int size = dl_per_view ? VIEW::num_views() : 1;
00028 make_dl_big_enough (size);
00029 make_dl_stamp_big_enough(size);
00030 }
00031
00032
00033
00034
00035
00036
00037
00038 int
00039 DLhandler::dl(CVIEWptr &v) const
00040 {
00041 const int view_id = dl_per_view ? v->view_id() : 0;
00042 return _dl_array[view_id];
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052 bool
00053 DLhandler::valid(CVIEWptr &v, int cmp_stamp) const
00054 {
00055 const int view_id = dl_per_view ? v->view_id() : 0;
00056 ((DLhandler *) this)->make_dl_stamp_big_enough(view_id);
00057 return ((_dl_stamp_array[view_id] != -1) &&
00058 (_dl_stamp_array[view_id] >= cmp_stamp));
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068 void
00069 DLhandler::invalidate()
00070 {
00071 for (int i = 0; i< _dl_stamp_array.num(); i++) {
00072 _dl_stamp_array[i] = -1;
00073 }
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 int
00085 DLhandler::get_dl(CVIEWptr &v, int num_dls, int set_stamp)
00086 {
00087 const int view_id = dl_per_view ? v->view_id() : 0;
00088
00089
00090 if (valid(v, set_stamp))
00091 return _dl_array[view_id];
00092
00093
00094 make_dl_big_enough(view_id);
00095 if (_dl_array[view_id] == 0) {
00096 _dl_array[view_id] = glGenLists(num_dls);
00097 }
00098
00099 make_dl_stamp_big_enough(view_id);
00100 _dl_stamp_array[view_id] = _dl_array[view_id] == 0 ? 0 : set_stamp;
00101 return _dl_array[view_id];
00102 }
00103
00104
00105
00106
00107
00108
00109
00110 void
00111 DLhandler::close_dl(CVIEWptr &)
00112 {
00113 glEndList();
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123 void
00124 DLhandler::delete_dl(CVIEWptr &v)
00125 {
00126 const int view_id = dl_per_view ? v->view_id() : 0;
00127 if (_dl_array.valid_index(view_id)) {
00128 if (_dl_array[view_id]) {
00129 glDeleteLists(_dl_array[view_id], 1);
00130 _dl_array[view_id] = 0;
00131 }
00132 _dl_stamp_array[view_id] = -1;
00133 }
00134 return;
00135 }
00136
00137 void
00138 DLhandler::delete_all_dl()
00139 {
00140 for (int i = 0; i< _dl_array.num(); i++) {
00141 if (_dl_array[i]) {
00142 glDeleteLists(_dl_array[i], 1);
00143 _dl_array[i] = 0;
00144 }
00145 _dl_stamp_array[i] = -1;
00146 }
00147 }
00148
00149
00150 void
00151 DLhandler::make_dl_big_enough(int i)
00152 {
00153 CriticalSection cs(&_dl_mutex);
00154 while (!_dl_array.valid_index(i)) {
00155 if (dl_per_view && debug_threads) {
00156 cerr << "Adding _dl_array entry" << endl;
00157 }
00158 _dl_array += 0;
00159 }
00160 }
00161
00162 void
00163 DLhandler::make_dl_stamp_big_enough(int i)
00164 {
00165 CriticalSection cs(&_dl_stamp_mutex);
00166 while (!_dl_stamp_array.valid_index(i)) {
00167 if (dl_per_view && debug_threads) {
00168 cerr << "Adding _dl_stamp_array entry" << endl;
00169 }
00170 _dl_stamp_array += -1;
00171 }
00172 }