llvolumemgr.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file llvolumemgr.h
  3. * @brief LLVolumeMgr class.
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVOLUMEMGR_H
  33. #define LL_LLVOLUMEMGR_H
  34. #include <map>
  35. #include "llmutex.h"
  36. #include "llpointer.h"
  37. #include "llthread.h"
  38. #include "llvolume.h"
  39. class LLVolumeParams;
  40. class LLVolumeLODGroup;
  41. class LLVolumeLODGroup
  42. {
  43. protected:
  44. LOG_CLASS(LLVolumeLODGroup);
  45. public:
  46. enum
  47. {
  48. NUM_LODS = 4
  49. };
  50. LLVolumeLODGroup(const LLVolumeParams& params);
  51. ~LLVolumeLODGroup();
  52. bool cleanupRefs();
  53. static S32 getDetailFromTan(F32 tan_angle);
  54. static void getDetailProximity(F32 tan_angle, F32& to_lower,
  55. F32& to_higher);
  56. static F32 getVolumeScaleFromDetail(S32 detail);
  57. static S32 getVolumeDetailFromScale(F32 scale);
  58. LLVolume* refLOD(S32 detail);
  59. bool derefLOD(LLVolume* volumep);
  60. LL_INLINE S32 getNumRefs() const { return mRefs; }
  61. LL_INLINE const LLVolumeParams* getVolumeParams() const { return &mVolumeParams; }
  62. F32 dump();
  63. friend std::ostream& operator<<(std::ostream& s,
  64. const LLVolumeLODGroup& volgroup);
  65. protected:
  66. LLVolumeParams mVolumeParams;
  67. S32 mRefs;
  68. S32 mAccessCount[NUM_LODS];
  69. S32 mLODRefs[NUM_LODS];
  70. LLPointer<LLVolume> mVolumeLODs[NUM_LODS];
  71. static F32 sDetailThresholds[NUM_LODS];
  72. static F32 sDetailScales[NUM_LODS];
  73. };
  74. class LLVolumeMgr
  75. {
  76. protected:
  77. LOG_CLASS(LLVolumeMgr);
  78. public:
  79. static void initClass();
  80. static void cleanupClass();
  81. LLVolumeLODGroup* getGroup(const LLVolumeParams& vparams);
  82. // Whatever calls getVolume() never owns the LLVolume* and cannot keep
  83. // references for long since it may be deleted later. For best results hold
  84. // it in an LLPointer<LLVolume>.
  85. LLVolume* refVolume(const LLVolumeParams& volume_params, S32 detail);
  86. void unrefVolume(LLVolume* volumep);
  87. void dump();
  88. friend std::ostream& operator<<(std::ostream& s,
  89. const LLVolumeMgr& volume_mgr);
  90. private:
  91. // Use initclass() and cleanupClass()
  92. LLVolumeMgr() = default;
  93. ~LLVolumeMgr();
  94. void insertGroup(LLVolumeLODGroup* volgroup);
  95. LLVolumeLODGroup* createNewGroup(const LLVolumeParams& vparams);
  96. private:
  97. typedef std::map<const LLVolumeParams*, LLVolumeLODGroup*,
  98. LLVolumeParams::compare> volume_lod_group_map_t;
  99. volume_lod_group_map_t mVolumeLODGroups;
  100. LLMutex mDataMutex;
  101. };
  102. extern LLVolumeMgr* gVolumeMgrp;
  103. #endif // LL_LLVOLUMEMGR_H