]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/renderer/MegaTexture.h
hello world
[icculus/iodoom3.git] / neo / renderer / MegaTexture.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code 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
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 class idTextureTile {
30 public:
31         int             x, y;
32 };
33
34 static const int TILE_PER_LEVEL = 4;
35 static const int MAX_MEGA_CHANNELS = 3;         // normal, diffuse, specular
36 static const int MAX_LEVELS = 12;
37 static const int MAX_LEVEL_WIDTH = 512;
38 static const int TILE_SIZE = MAX_LEVEL_WIDTH / TILE_PER_LEVEL;
39
40 class   idMegaTexture;
41
42 class idTextureLevel {
43 public:
44         idMegaTexture   *mega;
45
46         int                             tileOffset;
47         int                             tilesWide;
48         int                             tilesHigh;
49
50         idImage                 *image;
51         idTextureTile   tileMap[TILE_PER_LEVEL][TILE_PER_LEVEL];
52
53         float                   parms[4];
54
55         void                    UpdateForCenter( float center[2] );
56         void                    UpdateTile( int localX, int localY, int globalX, int globalY );
57         void                    Invalidate();
58 };
59
60 typedef struct {
61         int             tileSize;
62         int             tilesWide;
63         int             tilesHigh;
64 } megaTextureHeader_t;
65
66
67 class idMegaTexture {
68 public:
69         bool    InitFromMegaFile( const char *fileBase );
70         void    SetMappingForSurface( const srfTriangles_t *tri );      // analyzes xyz and st to create a mapping
71         void    BindForViewOrigin( const idVec3 origin );       // binds images and sets program parameters
72         void    Unbind();                                                               // removes texture bindings
73
74         static  void MakeMegaTexture_f( const idCmdArgs &args );
75 private:
76 friend class idTextureLevel;
77         void    SetViewOrigin( const idVec3 origin );
78         static void     GenerateMegaMipMaps( megaTextureHeader_t *header, idFile *file );
79         static void     GenerateMegaPreview( const char *fileName );
80
81         idFile                  *fileHandle;
82
83         const srfTriangles_t *currentTriMapping;
84
85         idVec3                  currentViewOrigin;
86
87         float                   localViewToTextureCenter[2][4];
88
89         int                             numLevels;
90         idTextureLevel  levels[MAX_LEVELS];                             // 0 is the highest resolution
91         megaTextureHeader_t     header;
92
93         static idCVar   r_megaTextureLevel;
94         static idCVar   r_showMegaTexture;
95         static idCVar   r_showMegaTextureLabels;
96         static idCVar   r_skipMegaTexture;
97         static idCVar   r_terrainScale;
98 };
99