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