graphicsThreadingModel.I 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // Filename: graphicsThreadingModel.I
  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. // Function: GraphicsThreadingModel::Copy Constructor
  16. // Access: Published
  17. // Description:
  18. ////////////////////////////////////////////////////////////////////
  19. INLINE GraphicsThreadingModel::
  20. GraphicsThreadingModel(const GraphicsThreadingModel &copy) :
  21. _cull_name(copy._cull_name),
  22. _cull_stage(copy._cull_stage),
  23. _draw_name(copy._draw_name),
  24. _draw_stage(copy._draw_stage),
  25. _cull_sorting(copy._cull_sorting)
  26. {
  27. }
  28. ////////////////////////////////////////////////////////////////////
  29. // Function: GraphicsThreadingModel::Copy Assignment Operator
  30. // Access: Published
  31. // Description:
  32. ////////////////////////////////////////////////////////////////////
  33. INLINE void GraphicsThreadingModel::
  34. operator = (const GraphicsThreadingModel &copy) {
  35. _cull_name = copy._cull_name;
  36. _cull_stage = copy._cull_stage;
  37. _draw_name = copy._draw_name;
  38. _draw_stage = copy._draw_stage;
  39. _cull_sorting = copy._cull_sorting;
  40. }
  41. ////////////////////////////////////////////////////////////////////
  42. // Function: GraphicsThreadingModel::get_cull_name
  43. // Access: Published
  44. // Description: Returns the name of the thread that will handle
  45. // culling in this model.
  46. ////////////////////////////////////////////////////////////////////
  47. INLINE const string &GraphicsThreadingModel::
  48. get_cull_name() const {
  49. return _cull_name;
  50. }
  51. ////////////////////////////////////////////////////////////////////
  52. // Function: GraphicsThreadingModel::set_cull_name
  53. // Access: Published
  54. // Description: Changes the name of the thread that will handle
  55. // culling in this model. This won't change any windows
  56. // that were already created with this model; this only
  57. // has an effect on newly-opened windows.
  58. ////////////////////////////////////////////////////////////////////
  59. INLINE void GraphicsThreadingModel::
  60. set_cull_name(const string &cull_name) {
  61. _cull_name = cull_name;
  62. update_stages();
  63. }
  64. ////////////////////////////////////////////////////////////////////
  65. // Function: GraphicsThreadingModel::get_cull_stage
  66. // Access: Published
  67. // Description: Returns the pipeline stage from which the cull thread
  68. // should access data. This will be 0 if the cull is
  69. // run in the same thread as app, or 1 if it is its own
  70. // thread.
  71. ////////////////////////////////////////////////////////////////////
  72. INLINE int GraphicsThreadingModel::
  73. get_cull_stage() const {
  74. return _cull_stage;
  75. }
  76. ////////////////////////////////////////////////////////////////////
  77. // Function: GraphicsThreadingModel::get_draw_name
  78. // Access: Published
  79. // Description: Returns the name of the thread that will handle
  80. // sending the actual graphics primitives to the
  81. // graphics API in this model.
  82. ////////////////////////////////////////////////////////////////////
  83. INLINE const string &GraphicsThreadingModel::
  84. get_draw_name() const {
  85. return _draw_name;
  86. }
  87. ////////////////////////////////////////////////////////////////////
  88. // Function: GraphicsThreadingModel::set_draw_name
  89. // Access: Published
  90. // Description: Changes the name of the thread that will handle
  91. // drawing in this model. This won't change any windows
  92. // that were already created with this model; this only
  93. // has an effect on newly-opened windows.
  94. ////////////////////////////////////////////////////////////////////
  95. INLINE void GraphicsThreadingModel::
  96. set_draw_name(const string &draw_name) {
  97. _draw_name = draw_name;
  98. update_stages();
  99. }
  100. ////////////////////////////////////////////////////////////////////
  101. // Function: GraphicsThreadingModel::get_draw_stage
  102. // Access: Published
  103. // Description: Returns the pipeline stage from which the draw thread
  104. // should access data. This will be the same value as
  105. // get_cull_stage() if cull and draw are run in the same
  106. // thread, or one more than that value if draw should be
  107. // in its own thread.
  108. ////////////////////////////////////////////////////////////////////
  109. INLINE int GraphicsThreadingModel::
  110. get_draw_stage() const {
  111. return _draw_stage;
  112. }
  113. ////////////////////////////////////////////////////////////////////
  114. // Function: GraphicsThreadingModel::get_cull_sorting
  115. // Access: Published
  116. // Description: Returns true if the model involves a separate cull
  117. // pass, or false if culling happens implicitly, at the
  118. // same time as draw.
  119. ////////////////////////////////////////////////////////////////////
  120. INLINE bool GraphicsThreadingModel::
  121. get_cull_sorting() const {
  122. return _cull_sorting;
  123. }
  124. ////////////////////////////////////////////////////////////////////
  125. // Function: GraphicsThreadingModel::set_cull_sorting
  126. // Access: Published
  127. // Description: Changes the flag that indicates whether the threading
  128. // model involves a separate cull pass. This won't
  129. // change any windows that were already created with
  130. // this model; this only has an effect on newly-opened
  131. // windows.
  132. ////////////////////////////////////////////////////////////////////
  133. INLINE void GraphicsThreadingModel::
  134. set_cull_sorting(bool cull_sorting) {
  135. _cull_sorting = cull_sorting;
  136. update_stages();
  137. }
  138. ////////////////////////////////////////////////////////////////////
  139. // Function: GraphicsThreadingModel::is_single_threaded
  140. // Access: Published
  141. // Description: Returns true if the threading model is a
  142. // single-threaded model, or false if it involves
  143. // threads.
  144. ////////////////////////////////////////////////////////////////////
  145. INLINE bool GraphicsThreadingModel::
  146. is_single_threaded() const {
  147. return _cull_name.empty() && _draw_name.empty();
  148. }
  149. ////////////////////////////////////////////////////////////////////
  150. // Function: GraphicsThreadingModel::is_default
  151. // Access: Published
  152. // Description: Returns true if the threading model is the default,
  153. // cull-then-draw single-threaded model, or false
  154. // otherwise.
  155. ////////////////////////////////////////////////////////////////////
  156. INLINE bool GraphicsThreadingModel::
  157. is_default() const {
  158. return is_single_threaded() && _cull_sorting;
  159. }
  160. ////////////////////////////////////////////////////////////////////
  161. // Function: GraphicsThreadingModel::output
  162. // Access: Published
  163. // Description:
  164. ////////////////////////////////////////////////////////////////////
  165. INLINE void GraphicsThreadingModel::
  166. output(ostream &out) const {
  167. out << get_model();
  168. }
  169. INLINE ostream &
  170. operator << (ostream &out, const GraphicsThreadingModel &threading_model) {
  171. threading_model.output(out);
  172. return out;
  173. }