Drawable.pkg 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. $#include "Drawable.h"
  2. static const unsigned DRAWABLE_GEOMETRY;
  3. static const unsigned DRAWABLE_LIGHT;
  4. static const unsigned DRAWABLE_ZONE;
  5. static const unsigned DRAWABLE_ANY;
  6. static const unsigned DEFAULT_VIEWMASK;
  7. static const unsigned DEFAULT_LIGHTMASK;
  8. static const unsigned DEFAULT_SHADOWMASK;
  9. static const unsigned DEFAULT_ZONEMASK;
  10. static const int DRAWABLES_PER_WORK_ITEM;
  11. static const int MAX_VERTEX_LIGHTS;
  12. static const float ANIMATION_LOD_BASESCALE;
  13. /// Base class for visible components.
  14. class Drawable : public Component
  15. {
  16. public:
  17. /// Set draw distance.
  18. void SetDrawDistance(float distance);
  19. /// Set shadow draw distance.
  20. void SetShadowDistance(float distance);
  21. /// Set LOD bias.
  22. void SetLodBias(float bias);
  23. /// Set view mask. Is and'ed with camera's view mask to see if the object should be rendered.
  24. void SetViewMask(unsigned mask);
  25. /// Set light mask. Is and'ed with light's and zone's light mask to see if the object should be lit.
  26. void SetLightMask(unsigned mask);
  27. /// Set shadow mask. Is and'ed with light's light mask and zone's shadow mask to see if the object should be rendered to a shadow map.
  28. void SetShadowMask(unsigned mask);
  29. /// Set zone mask. Is and'ed with zone's zone mask to see if the object should belong to the zone.
  30. void SetZoneMask(unsigned mask);
  31. /// Set maximum number of per-pixel lights. Default 0 is unlimited.
  32. void SetMaxLights(unsigned num);
  33. /// Set shadowcaster flag.
  34. void SetCastShadows(bool enable);
  35. /// Set occlusion flag.
  36. void SetOccluder(bool enable);
  37. /// Set occludee flag.
  38. void SetOccludee(bool enable);
  39. /// Mark for update before octree reinsertion.
  40. void MarkForUpdate();
  41. /// Return world-space bounding box.
  42. const BoundingBox& GetWorldBoundingBox();
  43. /// Return drawable flags.
  44. unsigned char GetDrawableFlags() const { return drawableFlags_; }
  45. /// Return draw distance.
  46. float GetDrawDistance() const { return drawDistance_; }
  47. /// Return shadow draw distance.
  48. float GetShadowDistance() const { return shadowDistance_; }
  49. /// Return LOD bias.
  50. float GetLodBias() const { return lodBias_; }
  51. /// Return view mask.
  52. unsigned GetViewMask() const { return viewMask_; }
  53. /// Return light mask.
  54. unsigned GetLightMask() const { return lightMask_; }
  55. /// Return shadow mask.
  56. unsigned GetShadowMask() const { return shadowMask_; }
  57. /// Return zone mask.
  58. unsigned GetZoneMask() const { return zoneMask_; }
  59. /// Return maximum number of per-pixel lights.
  60. unsigned GetMaxLights() const { return maxLights_; }
  61. /// Return shadowcaster flag.
  62. bool GetCastShadows() const { return castShadows_; }
  63. /// Return occluder flag.
  64. bool IsOccluder() const { return occluder_; }
  65. /// Return occludee flag.
  66. bool IsOccludee() const { return occludee_; }
  67. /// Set new zone.
  68. void SetZone(Zone* zone, bool temporary = false);
  69. /// Set sorting value.
  70. void SetSortValue(float value);
  71. /// Set view-space depth bounds.
  72. void SetMinMaxZ(float minZ, float maxZ);
  73. /// Mark in view (either the main camera, or a shadow camera view) this frame.
  74. void MarkInView(const FrameInfo& frame, bool mainView = true);
  75. /// Clear lights and base pass flags for a new frame.
  76. void ClearLights();
  77. /// Add a per-pixel light.
  78. void AddLight(Light* light);
  79. /// Add a per-vertex light.
  80. void AddVertexLight(Light* light);
  81. /// Sort and limit per-pixel lights to maximum allowed. Convert extra lights into vertex lights.
  82. void LimitLights();
  83. /// Sort and limit per-vertex lights to maximum allowed.
  84. void LimitVertexLights();
  85. /// Set base pass flag for a batch.
  86. void SetBasePass(unsigned batchIndex) { basePassFlags_ |= (1 << batchIndex); }
  87. /// Return octree octant.
  88. Octant* GetOctant() const { return octant_; }
  89. /// Return current zone.
  90. Zone* GetZone() const;
  91. /// Return previous zone.
  92. Zone* GetLastZone() const;
  93. /// Return if zone assignment needs re-evaluation.
  94. bool IsZoneDirty() const { return zoneDirty_; }
  95. /// Return distance from camera.
  96. float GetDistance() const { return distance_; }
  97. /// Return LOD scaled distance from camera.
  98. float GetLodDistance() const { return lodDistance_; }
  99. /// Return sorting value.
  100. float GetSortValue() const { return sortValue_; }
  101. /// Return whether is in view this frame.
  102. bool IsInView(unsigned frameNumber) const { return viewFrameNumber_ == frameNumber; }
  103. /// Return whether is visible in a specific view this frame.
  104. bool IsInView(const FrameInfo& frame, bool mainView = true) const { return viewFrameNumber_ == frame.frameNumber_ && viewFrame_ == &frame && (!mainView || viewCamera_ == frame.camera_); }
  105. /// Return whether has a base pass.
  106. bool HasBasePass(unsigned batchIndex) const { return (basePassFlags_ & (1 << batchIndex)) != 0; }
  107. /// Return the first added per-pixel light.
  108. Light* GetFirstLight() const { return firstLight_; }
  109. /// Return the minimum view-space depth.
  110. float GetMinZ() const { return minZ_; }
  111. /// Return the maximum view-space depth.
  112. float GetMaxZ() const { return maxZ_; }
  113. };