SceneRenderRequest.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_REQUEST_H_
  23. #define _SCENE_RENDER_REQUEST_H_
  24. #ifndef _SCENE_RENDER_FACTORIES_H_
  25. #include "2d/scene/SceneRenderFactories.h"
  26. #endif
  27. #ifndef _VECTOR2_H_
  28. #include "2d/core/Vector2.h"
  29. #endif
  30. #ifndef _COLOR_H_
  31. #include "graphics/gColor.h"
  32. #endif
  33. // Debug Profiling.
  34. #include "debug/profiler.h"
  35. //-----------------------------------------------------------------------------
  36. class SceneRenderObject;
  37. class SceneRenderQueue;
  38. //-----------------------------------------------------------------------------
  39. class SceneRenderRequest : public IFactoryObjectReset
  40. {
  41. public:
  42. SceneRenderRequest() : mpIsolatedRenderQueue(NULL)
  43. {
  44. resetState();
  45. }
  46. ~SceneRenderRequest() {}
  47. /// Sets mandatory configuration.
  48. inline SceneRenderRequest* set(
  49. SceneRenderObject* pSceneRenderObject,
  50. const Vector2& worldPosition,
  51. const F32 depth,
  52. const Vector2& sortPoint = Vector2::getZero(),
  53. const S32 serialId = 0,
  54. StringTableEntry renderGroup = StringTable->EmptyString,
  55. void* pCustomData1 = NULL,
  56. void* pCustomData2 = NULL,
  57. S32 customDataKey1 = 0,
  58. S32 customDataKey2 = 0)
  59. {
  60. // Sanity!
  61. AssertFatal( pSceneRenderObject != NULL, "Cannot submit a NULL scene render object." );
  62. mpSceneRenderObject = pSceneRenderObject;
  63. mWorldPosition = worldPosition;
  64. mDepth = depth;
  65. mSortPoint = sortPoint;
  66. mSerialId = serialId;
  67. mRenderGroup = renderGroup;
  68. mpCustomData1 = pCustomData1;
  69. mpCustomData2 = pCustomData2;
  70. mCustomDataKey1 = customDataKey1;
  71. mCustomDataKey2 = customDataKey2;
  72. return this;
  73. }
  74. /// Reset request state.
  75. virtual void resetState( void )
  76. {
  77. // Debug Profiling.
  78. PROFILE_SCOPE(SceneRenderRequest_ResetState);
  79. mpSceneRenderObject = NULL;
  80. mWorldPosition.SetZero();
  81. mDepth = 0.0f;
  82. mSortPoint.SetZero();
  83. mSerialId = 0;
  84. mRenderGroup = StringTable->EmptyString;
  85. mBlendMode = true;
  86. mSrcBlendFactor = GL_SRC_ALPHA;
  87. mDstBlendFactor = GL_ONE_MINUS_SRC_ALPHA;
  88. mBlendColor = ColorF(1.0f,1.0f,1.0f,1.0f);
  89. mAlphaTest = -1.0f;
  90. mpCustomData1 = NULL;
  91. mpCustomData2 = NULL;
  92. mCustomDataKey1 = 0;
  93. mCustomDataKey2 = 0;
  94. if ( mpIsolatedRenderQueue != NULL )
  95. {
  96. SceneRenderQueueFactory.cacheObject( mpIsolatedRenderQueue );
  97. mpIsolatedRenderQueue = NULL;
  98. }
  99. }
  100. public:
  101. SceneRenderObject* mpSceneRenderObject;
  102. Vector2 mWorldPosition;
  103. F32 mDepth;
  104. Vector2 mSortPoint;
  105. S32 mSerialId;
  106. StringTableEntry mRenderGroup;
  107. bool mBlendMode;
  108. GLenum mSrcBlendFactor;
  109. GLenum mDstBlendFactor;
  110. ColorF mBlendColor;
  111. F32 mAlphaTest;
  112. void* mpCustomData1;
  113. void* mpCustomData2;
  114. S32 mCustomDataKey1;
  115. S32 mCustomDataKey2;
  116. SceneRenderQueue* mpIsolatedRenderQueue;
  117. };
  118. #endif // _SCENE_RENDER_REQUEST_H_