ipak.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. Copyright (C) 2009-2011 id Software LLC, a ZeniMax Media company.
  3. Copyright (C) 2009 Id Software, Inc.
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. //============================================================
  17. //
  18. // In-file structures
  19. //
  20. // These stuctures are in the mapped data file, and shared
  21. // between the app and utility.
  22. //
  23. // Type headers are stored separately from the bulk data to minimize the
  24. // number of active pages.
  25. //
  26. // The full hash of the name is stored in nameHash, and nameHash&(PK_HASH_BUCKETS-1) is
  27. // used to chain structures of a particular type together.
  28. //
  29. //============================================================
  30. #define MAX_PK_NAME 64
  31. typedef struct {
  32. int nameHash; // PK_HashName( name )
  33. int nextOnHashChain; // -1 = end of chain
  34. char name[MAX_PK_NAME]; // in canonical form: backslashes to slashes and lowercase
  35. } pkName_t;
  36. #define PK_HASH_CHAINS 256
  37. typedef struct {
  38. int tableOfs; // // &firstStruct = (byte *)dfHeader + tableOfs
  39. int count;
  40. int structSize; // sizeof( pkWavData_t ), etc
  41. int hashChains[PK_HASH_CHAINS]; // -1 = end of chain
  42. } pkType_t;
  43. // dfWavData holds everything necessary to fully create an OpenAL sample buffer
  44. typedef struct {
  45. pkName_t name;
  46. int wavDataOfs;
  47. int wavChannels; // 1 or 2
  48. int wavChannelBytes; // 1 or 2
  49. int wavRate; // 22050, etc
  50. int wavNumSamples; // each sample holds all the channels
  51. // we may want looping information here later
  52. } pkWavData_t;
  53. // iPhone does not natively support palettized textures, but we
  54. // might conceivably want to support luminance and intensity textures
  55. // in the future.
  56. typedef enum {
  57. TF_565,
  58. TF_5551,
  59. TF_4444,
  60. TF_8888,
  61. TF_LA,
  62. TF_PVR4,
  63. TF_PVR4A,
  64. TF_PVR2,
  65. TF_PVR2A,
  66. } textureFormat_t;
  67. // dfImageData_t holds everything necessary to fully create an OpenGL texture object
  68. typedef struct {
  69. pkName_t name;
  70. int picDataOfs; // the raw bits to pass to gl, mipmaps appended
  71. // for PVR formats, the minimum size of each level is 32 bytes
  72. int format;
  73. int uploadWidth;
  74. int uploadHeight;
  75. int numLevels; // 1 for non mipmapped, otherwise log2( largest dimension )
  76. // glTexParameters
  77. int wrapS;
  78. int wrapT;
  79. int minFilter;
  80. int magFilter;
  81. int aniso;
  82. // The upload sizes can be larger than the source sizes for
  83. // non power of two sources, or for non square sources in the
  84. // case of PVR compression.
  85. int srcWidth;
  86. int srcHeight;
  87. float maxS; // srcWidth / uploadWidth
  88. float maxT;
  89. // Track the outlines of up to two boxes of non-transparent pixels
  90. // to allow optimized drawing of sprites with large empty areas.
  91. // The reason for two boxes is that the common lights have something
  92. // at the top and something at the bottom, with nothing inbetween.
  93. // These are inclusive bounds of the rows / columns in
  94. // uploadWidth / uploadHeight with non-0 alpha
  95. int numBounds;
  96. int bounds[2][2][2];
  97. } pkTextureData_t;
  98. typedef struct {
  99. pkName_t name;
  100. int rawDataOfs; // (byte *)pkHeader + dataOfs
  101. int rawDataLen; // there will always be a 0 byte appended to terminate strings
  102. // that is not counted in this length
  103. } pkRawData_t;
  104. #define PKFILE_VERSION 0x12340002
  105. typedef struct {
  106. int version;
  107. pkType_t textures;
  108. pkType_t wavs;
  109. pkType_t raws;
  110. } pkHeader_t;
  111. //============================================================
  112. //
  113. // In-memory, writable structures
  114. //
  115. //============================================================
  116. typedef struct {
  117. unsigned glTexNum;
  118. const pkTextureData_t *textureData;
  119. // we will need to add LRU links if texture caching is needed
  120. } pkTexture_t;
  121. typedef struct {
  122. unsigned alBufferNum; // created with the staticBuffer extension directly in the mapped memory
  123. const pkWavData_t *wavData;
  124. } pkWav_t;
  125. void PK_Init( const char *pakFileName );
  126. const pkName_t *PK_FindType( const char *rawName, const pkType_t *type, int *index );
  127. const byte * PK_FindRaw( const char *rawName, int *len ); // len can be NULL if you don't need it
  128. pkTexture_t * PK_FindTexture( const char *imageName );
  129. pkWav_t * PK_FindWav( const char *soundName );
  130. // The name will be converted to canonical name (backslashes converted to slashes and lowercase)
  131. // before generating a hash.
  132. int PK_HashName( const char *name, char canonical[MAX_PK_NAME] );
  133. void PK_BindTexture( pkTexture_t *tex );
  134. void PK_DrawTexture( pkTexture_t *tex, int x, int y );
  135. void PK_StretchTexture( pkTexture_t *tex, float x, float y, float w, float h );
  136. extern pkHeader_t * pkHeader;
  137. extern int pkSize;
  138. // images and wavs have writable state, so they need separate
  139. // structs that also point to the source in the pak file
  140. extern pkTexture_t *pkTextures;
  141. extern pkWav_t * pkWavs;