00001 // Filename: graphicsThreadingModel.cxx 00002 // Created by: drose (27Jan03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "graphicsThreadingModel.h" 00016 00017 //////////////////////////////////////////////////////////////////// 00018 // Function: GraphicsThreadingModel::Constructor 00019 // Access: Published 00020 // Description: The threading model accepts a string representing the 00021 // names of the two threads that will process cull and 00022 // draw for the given window, separated by a slash. The 00023 // names are completely arbitrary and are used only to 00024 // differentiate threads. The two names may be the 00025 // same, meaning the same thread, or each may be the 00026 // empty string, which represents the previous thread. 00027 // 00028 // Thus, for example, "cull/draw" indicates that the 00029 // window will be culled in a thread called "cull", and 00030 // drawn in a separate thread called "draw". 00031 // "draw/draw" or simply "draw" indicates the window 00032 // will be culled and drawn in the same thread, "draw". 00033 // On the other hand, "/draw" indicates the thread will 00034 // be culled in the main, or app thread, and drawn in a 00035 // separate thread named "draw". The empty string, "" 00036 // or "/", indicates the thread will be culled and drawn 00037 // in the main thread; that is to say, a single-process 00038 // model. 00039 // 00040 // Finally, if the threading model begins with a "-" 00041 // character, then cull and draw are run simultaneously, 00042 // in the same thread, with no binning or state sorting. 00043 // It simplifies the cull process but it forces the 00044 // scene to render in scene graph order; state sorting 00045 // and alpha sorting is lost. 00046 //////////////////////////////////////////////////////////////////// 00047 GraphicsThreadingModel:: 00048 GraphicsThreadingModel(const string &model) { 00049 _cull_sorting = true; 00050 size_t start = 0; 00051 if (!model.empty() && model[0] == '-') { 00052 start = 1; 00053 _cull_sorting = false; 00054 } 00055 00056 size_t slash = model.find('/', start); 00057 if (slash == string::npos) { 00058 _cull_name = model.substr(start); 00059 } else { 00060 _cull_name = model.substr(start, slash - start); 00061 _draw_name = model.substr(slash + 1); 00062 } 00063 00064 update_stages(); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: GraphicsThreadingModel::get_model 00069 // Access: Published 00070 // Description: Returns the string that describes the threading 00071 // model. See the constructor. 00072 //////////////////////////////////////////////////////////////////// 00073 string GraphicsThreadingModel:: 00074 get_model() const { 00075 if (get_cull_sorting()) { 00076 return get_cull_name() + "/" + get_draw_name(); 00077 } else { 00078 return string("-") + get_cull_name(); 00079 } 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: GraphicsThreadingModel::update_stages 00084 // Access: Private 00085 // Description: Called internally to recompute _cull_stage and 00086 // _draw_stage after either name has been changed. 00087 //////////////////////////////////////////////////////////////////// 00088 void GraphicsThreadingModel:: 00089 update_stages() { 00090 if (_cull_name.empty()) { 00091 _cull_stage = 0; 00092 } else { 00093 _cull_stage = 1; 00094 } 00095 if (!_cull_sorting || _draw_name.empty()) { 00096 _draw_name = _cull_name; 00097 } 00098 00099 if (_draw_name == _cull_name) { 00100 _draw_stage = _cull_stage; 00101 } else { 00102 _draw_stage = _cull_stage + 1; 00103 } 00104 } 00105