PageRenderTime 70ms CodeModel.GetById 30ms app.highlight 4ms RepoModel.GetById 19ms app.codeStats 1ms

/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
27#ifndef LL_LLWORLDMIPMAP_H
28#define LL_LLWORLDMIPMAP_H
29
30#include <map>
31
32#include "llmemory.h"			// LLPointer
33#include "indra_constants.h"	// REGION_WIDTH_UNITS
34#include "llregionhandle.h"		// to_region_handle()
35
36class LLViewerFetchedTexture;
37
38// LLWorldMipmap : Mipmap handling of all the tiles used to render the world at any resolution.
39// This class provides a clean structured access to the hierarchy of tiles stored in the 
40// Amazon S3 repository and abstracts its directory/file structure.
41// The interface of this class though still assumes that the caller knows the general level/tiles
42// structure (at least, that it exists...) but doesn't requite the caller to know the details of it.
43// IOW, you need to know that rendering levels exists as well as grid coordinates for regions, 
44// but you can ignore where those tiles are located, how to get them, etc...
45// The class API gives you back LLPointer<LLViewerFetchedTexture> per tile.
46
47// See llworldmipmapview.cpp for the implementation of a class who knows how to render an LLWorldMipmap.
48
49// Implementation notes:
50// - On the S3 servers, the tiles are rendered in 2 flavors: Objects and Terrain.
51// - For the moment, LLWorldMipmap implements access only to the Objects tiles.
52class LLWorldMipmap
53{
54public:
55	// Parameters of the mipmap
56	static const S32 MAP_LEVELS = 8;		// Number of subresolution levels computed by the mapserver
57	static const S32 MAP_TILE_SIZE = 256;	// Width in pixels of the tiles computed by the mapserver
58
59	LLWorldMipmap();
60	~LLWorldMipmap();
61
62	// Clear up the maps and release all image handles
63	void	reset();
64	// Manage the boost levels between loops (typically draw() loops)
65	void	equalizeBoostLevels();
66	// Drop the boost levels to none (used when hiding the map)
67	void	dropBoostLevels();
68	// Get the tile smart pointer, does the loading if necessary
69	LLPointer<LLViewerFetchedTexture> getObjectsTile(U32 grid_x, U32 grid_y, S32 level, bool load = true);
70
71	// Helper functions: those are here as they depend solely on the topology of the mipmap though they don't access it
72	// Convert sim scale (given in sim width in display pixels) into a mipmap level
73	static S32  scaleToLevel(F32 scale);
74	// Convert world coordinates to mipmap grid coordinates at a given level
75	static void globalToMipmap(F64 global_x, F64 global_y, S32 level, U32* grid_x, U32* grid_y);
76
77private:
78	// Get a handle (key) from grid coordinates
79	U64		convertGridToHandle(U32 grid_x, U32 grid_y) { return to_region_handle(grid_x * REGION_WIDTH_UNITS, grid_y * REGION_WIDTH_UNITS); }
80	// Load the relevant tile from S3
81	LLPointer<LLViewerFetchedTexture> loadObjectsTile(U32 grid_x, U32 grid_y, S32 level);
82	// Clear a level from its "missing" tiles
83	void cleanMissedTilesFromLevel(S32 level);
84
85	// The mipmap is organized by resolution level (MAP_LEVELS of them). Each resolution level is an std::map
86	// using a region_handle as a key and storing a smart pointer to the image as a value.
87	typedef std::map<U64, LLPointer<LLViewerFetchedTexture> > sublevel_tiles_t;
88	sublevel_tiles_t mWorldObjectsMipMap[MAP_LEVELS];
89//	sublevel_tiles_t mWorldTerrainMipMap[MAP_LEVELS];
90
91	S32 mCurrentLevel;		// The level last accessed by a getObjectsTile()
92};
93
94#endif // LL_LLWORLDMIPMAP_H