texture_manager.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. Copyright (C) 2004 Michael Liebscher
  3. Copyright (C) 1997-2001 Id Software, Inc.
  4. Copyright (C) 1995 Spencer Kimball and Peter Mattis.
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. * texture_manager.c: Texture manager.
  19. *
  20. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  21. * Date: 2004
  22. *
  23. * Acknowledgement:
  24. * Portion of this code was derived from
  25. * The GIMP (an image manipulation program) and was originally
  26. * written by Spencer Kimball and Peter Mattis.
  27. *
  28. * Portion of this code was derived from Quake II, and was originally
  29. * written by Id Software, Inc.
  30. *
  31. */
  32. #ifndef __TEXTURE_MANAGER_H__
  33. #define __TEXTURE_MANAGER_H__
  34. #define MAX_TEXTURES 1024
  35. typedef enum
  36. {
  37. TT_Sprite,
  38. TT_Wall,
  39. TT_Pic,
  40. TextureTypeCount
  41. } texturetype_t;
  42. typedef enum
  43. {
  44. Repeat = 0,
  45. Clamp,
  46. WrapModeCount // Number of Wrap modes
  47. } TWrapMode;
  48. typedef enum
  49. {
  50. Auto = 0,
  51. RGBA8888,
  52. RGBA4444,
  53. RGBA5551,
  54. RGB888,
  55. RGB565,
  56. DXTC1,
  57. DXTC1Alpha,
  58. DXTC3,
  59. DXTC5,
  60. Luminance,
  61. Alpha,
  62. AlphaLuminance,
  63. DsDt,
  64. UpImageFormatCount // Number of Upload formats
  65. } TTexFormat;
  66. typedef enum
  67. {
  68. Nearest = 0,
  69. Linear,
  70. MagFilterCount // Number of Magnification filters
  71. } TMagFilter;
  72. typedef enum
  73. {
  74. NearestMipMapOff = 0,
  75. NearestMipMapNearest,
  76. NearestMipMapLinear,
  77. LinearMipMapOff,
  78. LinearMipMapNearest,
  79. LinearMipMapLinear,
  80. MinFilterCount // Number of Min filters
  81. } TMinFilter;
  82. // this is the header from the pre-digested binary files with sprite bounds
  83. typedef struct {
  84. int hasAlpha;
  85. int srcWidth;
  86. int srcHeight;
  87. int uploadWidth;
  88. int uploadHeight;
  89. int numBounds;
  90. int bounds[2][2][2];
  91. } picHeader_t;
  92. typedef struct texture_s
  93. {
  94. _boolean MipMap;
  95. _boolean isTextureCube;
  96. TTexFormat UploadFormat;
  97. TWrapMode WrapS;
  98. TWrapMode WrapT;
  99. TWrapMode WrapR;
  100. TMinFilter MinFilter;
  101. TMagFilter MagFilter;
  102. W32 registration_sequence; // 0 = free
  103. W16 width, height;
  104. W16 upload_width, upload_height;
  105. unsigned int texnum;
  106. W16 bytes;
  107. texturetype_t type;
  108. char name[ MAX_GAMEPATH ]; // game path, including extension
  109. picHeader_t header;
  110. } texture_t;
  111. typedef enum
  112. {
  113. INTERPOLATION_NONE, /* None (Fastest) */
  114. INTERPOLATION_LINEAR, /* Linear */
  115. INTERPOLATION_CUBIC /* Cubic (Best) */
  116. } InterpolationType;
  117. extern W32 texture_registration_sequence;
  118. extern void TM_Init( void );
  119. extern void TM_Shutdown( void );
  120. extern _boolean TM_MipMap( PW8 in, W16 *width, W16 *height, W16 bytes );
  121. extern texture_t *wallTextures[1000];
  122. extern texture_t *spriteTextures[1000];
  123. extern texture_t *TM_FindTexture( const char *name, texturetype_t type );
  124. extern void TM_GetTextureSize( SW32 *width, SW32 *height, const char *name );
  125. extern void TM_ResampleTexture( PW8 in, int inwidth, int inheight, PW8 out, int outwidth, int outheight, W8 bytes, InterpolationType interpolation );
  126. extern void TM_FreeUnusedTextures( void );
  127. #endif /* __TEXTURE_MANAGER_H__ */