Panda3D
graphicsThreadingModel.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file graphicsThreadingModel.cxx
10  * @author drose
11  * @date 2003-01-27
12  */
13 
14 #include "graphicsThreadingModel.h"
15 
16 using std::string;
17 
18 /**
19  * The threading model accepts a string representing the names of the two
20  * threads that will process cull and draw for the given window, separated by
21  * a slash. The names are completely arbitrary and are used only to
22  * differentiate threads. The two names may be the same, meaning the same
23  * thread, or each may be the empty string, which represents the previous
24  * thread.
25  *
26  * Thus, for example, "cull/draw" indicates that the window will be culled in
27  * a thread called "cull", and drawn in a separate thread called "draw".
28  * "draw/draw" or simply "draw" indicates the window will be culled and drawn
29  * in the same thread, "draw". On the other hand, "/draw" indicates the thread
30  * will be culled in the main, or app thread, and drawn in a separate thread
31  * named "draw". The empty string, "" or "/", indicates the thread will be
32  * culled and drawn in the main thread; that is to say, a single-process
33  * model.
34  *
35  * Finally, if the threading model begins with a "-" character, then cull and
36  * draw are run simultaneously, in the same thread, with no binning or state
37  * sorting. It simplifies the cull process but it forces the scene to render
38  * in scene graph order; state sorting and alpha sorting is lost.
39  */
41 GraphicsThreadingModel(const string &model) {
42  _cull_sorting = true;
43  size_t start = 0;
44  if (!model.empty() && model[0] == '-') {
45  start = 1;
46  _cull_sorting = false;
47  }
48 
49  size_t slash = model.find('/', start);
50  if (slash == string::npos) {
51  _cull_name = model.substr(start);
52  } else {
53  _cull_name = model.substr(start, slash - start);
54  _draw_name = model.substr(slash + 1);
55  }
56 
57  update_stages();
58 }
59 
60 /**
61  * Returns the string that describes the threading model. See the
62  * constructor.
63  */
65 get_model() const {
66  if (get_cull_sorting()) {
67  return get_cull_name() + "/" + get_draw_name();
68  } else {
69  return string("-") + get_cull_name();
70  }
71 }
72 
73 /**
74  * Called internally to recompute _cull_stage and _draw_stage after either
75  * name has been changed.
76  */
77 void GraphicsThreadingModel::
78 update_stages() {
79  if (_cull_name.empty()) {
80  _cull_stage = 0;
81  } else {
82  _cull_stage = 1;
83  }
84  if (!_cull_sorting || _draw_name.empty()) {
85  _draw_name = _cull_name;
86  }
87 
88  if (_draw_name == _cull_name) {
89  _draw_stage = _cull_stage;
90  } else {
91  _draw_stage = _cull_stage + 1;
92  }
93 }
bool get_cull_sorting() const
Returns true if the model involves a separate cull pass, or false if culling happens implicitly,...
std::string get_model() const
Returns the string that describes the threading model.
const std::string & get_cull_name() const
Returns the name of the thread that will handle culling in this model.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const std::string & get_draw_name() const
Returns the name of the thread that will handle sending the actual graphics primitives to the graphic...
GraphicsThreadingModel(const std::string &model=std::string())
The threading model accepts a string representing the names of the two threads that will process cull...