SceneRenderQueue.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SCENE_RENDER_QUEUE_H_
  23. #define _SCENE_RENDER_QUEUE_H_
  24. #ifndef _SCENE_RENDER_REQUEST_H_
  25. #include "2d/scene/SceneRenderRequest.h"
  26. #endif
  27. // Debug Profiling.
  28. #include "debug/profiler.h"
  29. //-----------------------------------------------------------------------------
  30. class SceneRenderQueue : public IFactoryObjectReset
  31. {
  32. public:
  33. typedef Vector<SceneRenderRequest*> typeRenderRequestVector;
  34. // Scene Render Request Sort.
  35. enum RenderSort
  36. {
  37. RENDER_SORT_INVALID,
  38. ///---
  39. RENDER_SORT_OFF,
  40. RENDER_SORT_NEWEST,
  41. RENDER_SORT_OLDEST,
  42. RENDER_SORT_BATCH,
  43. RENDER_SORT_GROUP,
  44. RENDER_SORT_XAXIS,
  45. RENDER_SORT_YAXIS,
  46. RENDER_SORT_ZAXIS,
  47. RENDER_SORT_INVERSE_XAXIS,
  48. RENDER_SORT_INVERSE_YAXIS,
  49. RENDER_SORT_INVERSE_ZAXIS,
  50. };
  51. private:
  52. typeRenderRequestVector mRenderRequests;
  53. RenderSort mSortMode;
  54. bool mStrictOrderMode;
  55. private:
  56. static S32 QSORT_CALLBACK layeredNewFrontSort(const void* a, const void* b);
  57. static S32 QSORT_CALLBACK layeredOldFrontSort(const void* a, const void* b);
  58. static S32 QSORT_CALLBACK layeredDepthSort(const void* a, const void* b);
  59. static S32 QSORT_CALLBACK layeredInverseDepthSort(const void* a, const void* b);
  60. static S32 QSORT_CALLBACK layerBatchOrderSort(const void* a, const void* b);
  61. static S32 QSORT_CALLBACK layerGroupOrderSort(const void* a, const void* b);
  62. static S32 QSORT_CALLBACK layeredXSortPointSort(const void* a, const void* b);
  63. static S32 QSORT_CALLBACK layeredYSortPointSort(const void* a, const void* b);
  64. static S32 QSORT_CALLBACK layeredInverseXSortPointSort(const void* a, const void* b);
  65. static S32 QSORT_CALLBACK layeredInverseYSortPointSort(const void* a, const void* b);
  66. public:
  67. SceneRenderQueue()
  68. {
  69. resetState();
  70. }
  71. virtual ~SceneRenderQueue()
  72. {
  73. resetState();
  74. }
  75. virtual void resetState( void )
  76. {
  77. // Debug Profiling.
  78. PROFILE_SCOPE(SceneRenderQueue_ResetState);
  79. // Cache request.
  80. for( typeRenderRequestVector::iterator itr = mRenderRequests.begin(); itr != mRenderRequests.end(); ++itr )
  81. {
  82. SceneRenderRequestFactory.cacheObject( *itr );
  83. }
  84. mRenderRequests.clear();
  85. // Reset sort mode.
  86. mSortMode = RENDER_SORT_NEWEST;
  87. // Set strict order mode.
  88. mStrictOrderMode = true;
  89. }
  90. inline SceneRenderRequest* createRenderRequest( void )
  91. {
  92. // Debug Profiling.
  93. PROFILE_SCOPE(SceneRenderQueue_CreateRenderRequest);
  94. // Create scene render request.
  95. SceneRenderRequest* pSceneRenderRequest = SceneRenderRequestFactory.createObject();
  96. // Queue render request.
  97. mRenderRequests.push_back( pSceneRenderRequest );
  98. return pSceneRenderRequest;
  99. }
  100. inline typeRenderRequestVector& getRenderRequests( void ) { return mRenderRequests; }
  101. inline void setSortMode( RenderSort sortMode ) { mSortMode = sortMode; }
  102. inline RenderSort getSortMode( void ) const { return mSortMode; }
  103. inline void setStrictOrderMode( const bool strictOrderMode ) { mStrictOrderMode = strictOrderMode; }
  104. inline bool getStrictOrderMode( void ) const { return mStrictOrderMode; }
  105. void sort( void )
  106. {
  107. // Sort layer appropriately.
  108. switch( mSortMode )
  109. {
  110. case RENDER_SORT_NEWEST:
  111. {
  112. // Debug Profiling.
  113. PROFILE_SCOPE(SceneRenderQueue_SortNewest);
  114. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredNewFrontSort );
  115. return;
  116. }
  117. case RENDER_SORT_OLDEST:
  118. {
  119. // Debug Profiling.
  120. PROFILE_SCOPE(SceneRenderQueue_SortOldest);
  121. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredOldFrontSort );
  122. return;
  123. }
  124. case RENDER_SORT_BATCH:
  125. {
  126. // Debug Profiling.
  127. PROFILE_SCOPE(SceneRenderQueue_SortBatch);
  128. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layerBatchOrderSort );
  129. // Batching means we don't need strict order.
  130. mStrictOrderMode = false;
  131. return;
  132. }
  133. case RENDER_SORT_GROUP:
  134. {
  135. // Debug Profiling.
  136. PROFILE_SCOPE(SceneRenderQueue_SortGroup);
  137. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layerGroupOrderSort );
  138. return;
  139. }
  140. case RENDER_SORT_XAXIS:
  141. {
  142. // Debug Profiling.
  143. PROFILE_SCOPE(SceneRenderQueue_SortXAxis);
  144. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredXSortPointSort);
  145. return;
  146. }
  147. case RENDER_SORT_YAXIS:
  148. {
  149. // Debug Profiling.
  150. PROFILE_SCOPE(SceneRenderQueue_SortYAxis);
  151. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredYSortPointSort );
  152. return;
  153. }
  154. case RENDER_SORT_ZAXIS:
  155. {
  156. // Debug Profiling.
  157. PROFILE_SCOPE(SceneRenderQueue_SortZAxis);
  158. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredDepthSort );
  159. return;
  160. }
  161. case RENDER_SORT_INVERSE_XAXIS:
  162. {
  163. // Debug Profiling.
  164. PROFILE_SCOPE(SceneRenderQueue_SortInverseXAxis);
  165. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredInverseXSortPointSort );
  166. return;
  167. }
  168. case RENDER_SORT_INVERSE_YAXIS:
  169. {
  170. // Debug Profiling.
  171. PROFILE_SCOPE(SceneRenderQueue_SortInverseYAxis);
  172. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredInverseYSortPointSort );
  173. return;
  174. }
  175. case RENDER_SORT_INVERSE_ZAXIS:
  176. {
  177. // Debug Profiling.
  178. PROFILE_SCOPE(SceneRenderQueue_SortInverseZAxis);
  179. dQsort( mRenderRequests.address(), mRenderRequests.size(), sizeof(SceneRenderRequest*), layeredInverseDepthSort );
  180. return;
  181. }
  182. case RENDER_SORT_OFF:
  183. {
  184. return;
  185. }
  186. default:
  187. break;
  188. };
  189. }
  190. static RenderSort getRenderSortEnum(const char* label);
  191. static const char* getRenderSortDescription( const RenderSort& sortMode );
  192. static EnumTable renderSortTable;
  193. };
  194. #endif // _SCENE_RENDER_QUEUE_H_