00001 // Filename: graphicsThreadingModel.cxx 00002 // Created by: drose (27Jan03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "graphicsThreadingModel.h" 00020 00021 //////////////////////////////////////////////////////////////////// 00022 // Function: GraphicsThreadingModel::Constructor 00023 // Access: Published 00024 // Description: The threading model accepts a string representing the 00025 // names of the two threads that will process cull and 00026 // draw for the given window, separated by a slash. The 00027 // names are completely arbitrary and are used only to 00028 // differentiate threads. The two names may be the 00029 // same, meaning the same thread, or each may be the 00030 // empty string, which represents the previous thread. 00031 // 00032 // Thus, for example, "cull/draw" indicates that the 00033 // window will be culled in a thread called "cull", and 00034 // drawn in a separate thread called "draw". 00035 // "draw/draw" or simply "draw/" indicates the window 00036 // will be culled and drawn in the same thread, "draw". 00037 // On the other hand, "/draw" indicates the thread will 00038 // be culled in the main, or app thread, and drawn in a 00039 // separate thread named "draw". The empty string, "" 00040 // or "/", indicates the thread will be culled and drawn 00041 // in the main thread; that is to say, a single-process 00042 // model. 00043 // 00044 // Finally, if the threading model begins with a "-" 00045 // character, then cull and draw are run simultaneously, 00046 // in the same thread, with no binning or state sorting. 00047 // It simplifies the cull process but it forces the 00048 // scene to render in scene graph order; state sorting 00049 // and alpha sorting is lost. 00050 //////////////////////////////////////////////////////////////////// 00051 GraphicsThreadingModel:: 00052 GraphicsThreadingModel(const string &model) { 00053 _cull_sorting = true; 00054 size_t start = 0; 00055 if (!model.empty() && model[0] == '-') { 00056 start = 1; 00057 _cull_sorting = false; 00058 } 00059 00060 size_t slash = model.find('/', start); 00061 if (slash == string::npos) { 00062 _cull_name = model; 00063 } else { 00064 _cull_name = model.substr(start, slash - start); 00065 _draw_name = model.substr(slash + 1); 00066 } 00067 if (!_cull_sorting || _draw_name.empty()) { 00068 _draw_name = _cull_name; 00069 } 00070 } 00071 00072 00073 //////////////////////////////////////////////////////////////////// 00074 // Function: GraphicsThreadingModel::get_model 00075 // Access: Published 00076 // Description: Returns the string that describes the threading 00077 // model. See the constructor. 00078 //////////////////////////////////////////////////////////////////// 00079 string GraphicsThreadingModel:: 00080 get_model() const { 00081 if (get_cull_sorting()) { 00082 return get_cull_name() + "/" + get_draw_name(); 00083 } else { 00084 return string("-") + get_cull_name(); 00085 } 00086 }