/indra/newview/llworldmipmap.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 94 lines · 29 code · 14 blank · 51 comment · 0 complexity · dc5d7b21e86ea25e967e243866c1ecb6 MD5 · raw file

  1. /**
  2. * @file llworldmipmap.h
  3. * @brief Data storage for the S3 mipmap of the entire world.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLWORLDMIPMAP_H
  27. #define LL_LLWORLDMIPMAP_H
  28. #include <map>
  29. #include "llmemory.h" // LLPointer
  30. #include "indra_constants.h" // REGION_WIDTH_UNITS
  31. #include "llregionhandle.h" // to_region_handle()
  32. class LLViewerFetchedTexture;
  33. // LLWorldMipmap : Mipmap handling of all the tiles used to render the world at any resolution.
  34. // This class provides a clean structured access to the hierarchy of tiles stored in the
  35. // Amazon S3 repository and abstracts its directory/file structure.
  36. // The interface of this class though still assumes that the caller knows the general level/tiles
  37. // structure (at least, that it exists...) but doesn't requite the caller to know the details of it.
  38. // IOW, you need to know that rendering levels exists as well as grid coordinates for regions,
  39. // but you can ignore where those tiles are located, how to get them, etc...
  40. // The class API gives you back LLPointer<LLViewerFetchedTexture> per tile.
  41. // See llworldmipmapview.cpp for the implementation of a class who knows how to render an LLWorldMipmap.
  42. // Implementation notes:
  43. // - On the S3 servers, the tiles are rendered in 2 flavors: Objects and Terrain.
  44. // - For the moment, LLWorldMipmap implements access only to the Objects tiles.
  45. class LLWorldMipmap
  46. {
  47. public:
  48. // Parameters of the mipmap
  49. static const S32 MAP_LEVELS = 8; // Number of subresolution levels computed by the mapserver
  50. static const S32 MAP_TILE_SIZE = 256; // Width in pixels of the tiles computed by the mapserver
  51. LLWorldMipmap();
  52. ~LLWorldMipmap();
  53. // Clear up the maps and release all image handles
  54. void reset();
  55. // Manage the boost levels between loops (typically draw() loops)
  56. void equalizeBoostLevels();
  57. // Drop the boost levels to none (used when hiding the map)
  58. void dropBoostLevels();
  59. // Get the tile smart pointer, does the loading if necessary
  60. LLPointer<LLViewerFetchedTexture> getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load = true);
  61. // Helper functions: those are here as they depend solely on the topology of the mipmap though they don't access it
  62. // Convert sim scale (given in sim width in display pixels) into a mipmap level
  63. static S32 scaleToLevel(F32 scale);
  64. // Convert world coordinates to mipmap grid coordinates at a given level
  65. static void globalToMipmap(F64 global_x, F64 global_y, S32 level, U32* grid_x, U32* grid_y);
  66. private:
  67. // Get a handle (key) from grid coordinates
  68. U64 convertGridToHandle(U32 grid_x, U32 grid_y) { return to_region_handle(grid_x * REGION_WIDTH_UNITS, grid_y * REGION_WIDTH_UNITS); }
  69. // Load the relevant tile from S3
  70. LLPointer<LLViewerFetchedTexture> loadObjectsTile(U32 grid_x, U32 grid_y, S32 level);
  71. // Clear a level from its "missing" tiles
  72. void cleanMissedTilesFromLevel(S32 level);
  73. // The mipmap is organized by resolution level (MAP_LEVELS of them). Each resolution level is an std::map
  74. // using a region_handle as a key and storing a smart pointer to the image as a value.
  75. typedef std::map<U64, LLPointer<LLViewerFetchedTexture> > sublevel_tiles_t;
  76. sublevel_tiles_t mWorldObjectsMipMap[MAP_LEVELS];
  77. // sublevel_tiles_t mWorldTerrainMipMap[MAP_LEVELS];
  78. S32 mCurrentLevel; // The level last accessed by a getObjectsTile()
  79. };
  80. #endif // LL_LLWORLDMIPMAP_H