MegaTexture.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. class idTextureTile {
  21. public:
  22. int x, y;
  23. };
  24. static const int TILE_PER_LEVEL = 4;
  25. static const int MAX_MEGA_CHANNELS = 3; // normal, diffuse, specular
  26. static const int MAX_LEVELS = 12;
  27. static const int MAX_LEVEL_WIDTH = 512;
  28. static const int TILE_SIZE = MAX_LEVEL_WIDTH / TILE_PER_LEVEL;
  29. class idMegaTexture;
  30. class idTextureLevel {
  31. public:
  32. idMegaTexture *mega;
  33. int tileOffset;
  34. int tilesWide;
  35. int tilesHigh;
  36. idImage *image;
  37. idTextureTile tileMap[TILE_PER_LEVEL][TILE_PER_LEVEL];
  38. float parms[4];
  39. void UpdateForCenter( float center[2] );
  40. void UpdateTile( int localX, int localY, int globalX, int globalY );
  41. void Invalidate();
  42. };
  43. typedef struct {
  44. int tileSize;
  45. int tilesWide;
  46. int tilesHigh;
  47. } megaTextureHeader_t;
  48. class idMegaTexture {
  49. public:
  50. bool InitFromMegaFile( const char *fileBase );
  51. void SetMappingForSurface( const srfTriangles_t *tri ); // analyzes xyz and st to create a mapping
  52. void BindForViewOrigin( const idVec3 origin ); // binds images and sets program parameters
  53. void Unbind(); // removes texture bindings
  54. static void MakeMegaTexture_f( const idCmdArgs &args );
  55. private:
  56. friend class idTextureLevel;
  57. void SetViewOrigin( const idVec3 origin );
  58. static void GenerateMegaMipMaps( megaTextureHeader_t *header, idFile *file );
  59. static void GenerateMegaPreview( const char *fileName );
  60. idFile *fileHandle;
  61. const srfTriangles_t *currentTriMapping;
  62. idVec3 currentViewOrigin;
  63. float localViewToTextureCenter[2][4];
  64. int numLevels;
  65. idTextureLevel levels[MAX_LEVELS]; // 0 is the highest resolution
  66. megaTextureHeader_t header;
  67. static idCVar r_megaTextureLevel;
  68. static idCVar r_showMegaTexture;
  69. static idCVar r_showMegaTextureLabels;
  70. static idCVar r_skipMegaTexture;
  71. static idCVar r_terrainScale;
  72. };