lightingInterfaces.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 _SG_SYSTEM_INTERFACE_H
  23. #define _SG_SYSTEM_INTERFACE_H
  24. #ifndef _SGSCENEPERSIST_H_
  25. #include "lighting/common/scenePersist.h"
  26. #endif
  27. #ifndef _SCENELIGHTING_H_
  28. #include "lighting/common/sceneLighting.h"
  29. #endif
  30. class ObjectProxy;
  31. class ObjectProxyList;
  32. class SceneLightingInterface;
  33. template <class T> class Vector;
  34. typedef Vector<SceneLightingInterface*> SceneLightingInterfaces;
  35. // List of available "systems" that the lighting kit can use
  36. class AvailableSLInterfaces
  37. {
  38. protected:
  39. bool mDirty;
  40. public:
  41. AvailableSLInterfaces()
  42. : mAvailableObjectTypes( 0 ),
  43. mClippingMask( 0 ),
  44. mZoneLightSkipMask( 0 ),
  45. mDirty( true )
  46. {
  47. VECTOR_SET_ASSOCIATION( mAvailableSystemInterfaces );
  48. }
  49. // Register a system
  50. void registerSystem(SceneLightingInterface* si);
  51. // Init the interfaces
  52. void initInterfaces();
  53. // The actual list of SceneLightingInterfaces
  54. SceneLightingInterfaces mAvailableSystemInterfaces;
  55. // Object types that are registered with the system
  56. U32 mAvailableObjectTypes;
  57. // Clipping typemask
  58. U32 mClippingMask;
  59. // Object types that we should skip zone lighting for
  60. U32 mZoneLightSkipMask;
  61. };
  62. // This object is responsible for returning PersistChunk and ObjectProxy classes for the lighting system to use
  63. // We may want to eventually split this into scene lighting vs. dynamic lighting. getColorFromRayInfo is a dynamic
  64. // lighting thing.
  65. class SceneLightingInterface
  66. {
  67. public:
  68. SceneLightingInterface()
  69. {
  70. }
  71. virtual ~SceneLightingInterface() { }
  72. virtual void init() { }
  73. //
  74. // Scene lighting methods
  75. //
  76. // Creates an object proxy for obj
  77. virtual SceneLighting::ObjectProxy* createObjectProxy(SceneObject* obj, SceneLighting::ObjectProxyList* sceneObjects) = 0;
  78. // Creates a PersistChunk based on the chunkType flag
  79. virtual PersistInfo::PersistChunk* createPersistChunk(const U32 chunkType) = 0;
  80. // Creates a PersistChunk if needed for a proxy, returns true if it's "handled" by the system and ret contains the PersistChunk if needed.
  81. virtual bool createPersistChunkFromProxy(SceneLighting::ObjectProxy* proxy, PersistInfo::PersistChunk** ret) = 0;
  82. // Returns which object type flag this system supports (used to query scene graph for objects to light)
  83. virtual U32 addObjectType() = 0;
  84. // Add an object type flag to the "allow clipping mask" (used for blob shadows)
  85. virtual U32 addToClippingMask() { return 0; }
  86. // Add an object type flag to skip zone lighting
  87. virtual U32 addToZoneLightSkipMask() { return 0; }
  88. // Allows for processing/validating of the scene list after loading cached persistant info, return false if a relight is required or true if the data looks good.
  89. virtual bool postProcessLoad(PersistInfo* pi, SceneLighting::ObjectProxyList* sceneObjects) { return true; }
  90. virtual void processLightingBegin() { }
  91. virtual void processLightingCompleted(bool success) { }
  92. //
  93. // Runtime / dynamic methods
  94. //
  95. // Given a ray, this will return the color from the lightmap of this object, return true if handled
  96. virtual bool getColorFromRayInfo(const RayInfo & collision, LinearColorF& result) const { return false; }
  97. };
  98. #endif