1 #if (USE_POLYMOST == 0)
2 #error Polymost not enabled.
3 #endif
4 #if (USE_OPENGL == 0)
5 #error OpenGL not enabled.
6 #endif
7 
8 #ifndef POLYMOSTTEX_PRIV_H
9 #define POLYMOSTTEX_PRIV_H
10 
11 enum {
12 	PTH_CLAMPED = 1,
13 	PTH_HIGHTILE = 2,
14 	PTH_SKYBOX = 4,
15 	PTH_HASALPHA = 8,		// NOTE: only seen in PTMHead.flags, not in PTHead.flags
16 	PTH_NOCOMPRESS = 16,	// prevents texture compression from being used
17 	PTH_NOMIPLEVEL = 32,	// prevents gltexmiplevel from being applied
18 	PTH_DIRTY = 128,		// NOTE: only seen in PTMHead.flags, not in PTHead.flags
19 };
20 
21 // indices of PTHead.pic[]
22 enum {
23 	PTHPIC_BASE = 0,
24 	PTHPIC_GLOW = 1,
25 	PTHPIC_DETAIL = 2,
26 	PTHPIC_SIZE = 6,
27 };
28 
29 
30 /** PolymostTex texture manager header */
31 struct PTMHead_typ {
32 	GLuint glpic;
33 
34 	int flags;
35 	int sizx, sizy;		// padded texture dimensions
36 	int tsizx, tsizy;		// true texture dimensions
37 };
38 
39 typedef struct PTMHead_typ PTMHead;
40 
41 /** identifying information for a PolymostTex texture manager entry */
42 struct PTMIdent_typ {
43     int type;       //see PTMIDENT_* constants
44     int flags;
45     int palnum;
46     int picnum;
47     int layer;      //see PTHPIC_* constants
48 	int effects;    //see HICEFFECT_* constants
49 	char filename[BMAX_PATH];
50 };
51 
52 typedef struct PTMIdent_typ PTMIdent;
53 
54 enum {
55     PTMIDENT_ART = 0,
56     PTMIDENT_HIGHTILE = 1,
57     PTMIDENT_MDSKIN = 2,
58 };
59 
60 /** PolymostTex texture header */
61 struct PTHead_typ {
62 	PTMHead *pic[PTHPIC_SIZE];	// when (flags & PTH_SKYBOX), each is a face of the cube
63 					// when !(flags & PTH_SKYBOX), see PTHPIC_* constants
64 	int picnum;
65 	int palnum;
66 	unsigned short flags;
67 
68 	hicreplctyp *repldef;
69 
70 	float scalex, scaley;		// scale factor between texture and ART tile dimensions
71 };
72 
73 typedef struct PTHead_typ PTHead;
74 
75 enum {
76 	PTITER_PICNUM = 1,
77 	PTITER_PALNUM = 2,
78 	PTITER_FLAGS  = 4,
79 };
80 
81 struct PTIter_typ;	// an opaque iterator type for walking the internal hash
82 typedef struct PTIter_typ * PTIter;
83 
84 extern int polymosttexverbosity;	// 0 = none, 1 = errors (default), 2 = all
85 
86 /**
87  * Prepare for priming by sweeping through the textures and marking them as all unused
88  */
89 void PTBeginPriming(void);
90 
91 /**
92  * Flag a texture as required for priming
93  */
94 void PTMarkPrime(int picnum, int palnum, unsigned short flags);
95 
96 /**
97  * Runs a cycle of the priming process. Call until nonzero is returned.
98  * @param done receives the number of textures primed so far
99  * @param total receives the total number of textures to be primed
100  * @return 0 when priming is complete
101  */
102 int PTDoPrime(int* done, int* total);
103 
104 /**
105  * Resets the texture hash but leaves the headers in memory
106  */
107 void PTReset(void);
108 
109 /**
110  * Clears the texture hash of all content
111  */
112 void PTClear(void);
113 
114 /**
115  * Creates a new iterator for walking the header hash looking for particular
116  * parameters that match.
117  * @param match PTITER_* flags indicating which parameters to test
118  * @param picnum when (match&PTITER_PICNUM), specifies the picnum
119  * @param palnum when (match&PTITER_PALNUM), specifies the palnum
120  * @param flagsmask when (match&PTITER_FLAGS), specifies the mask to apply to flags
121  * @param flags when (match&PTITER_FLAGS), specifies the flags to test
122  * @return an iterator
123  */
124 PTIter PTIterNewMatch(int match, int picnum, int palnum, unsigned short flagsmask, unsigned short flags);
125 
126 /**
127  * Creates a new iterator for walking the entire header hash
128  * @return an iterator
129  */
130 PTIter PTIterNew(void);
131 
132 /**
133  * Gets the next matching header from an iterator
134  * @param iter the iterator
135  * @return the next header, or null if at the end
136  */
137 PTHead * PTIterNext(PTIter iter);
138 
139 /**
140  * Frees an iterator
141  * @param iter the iterator
142  */
143 void PTIterFree(PTIter iter);
144 
145 
146 
147 /**
148  * Fetches a texture header. This also means loading the texture from
149  * disk if need be (if peek!=0).
150  * @param picnum
151  * @param palnum
152  * @param flags
153  * @param peek if !0, does not try and create a header if none exists
154  * @return pointer to the header, or null if peek!=0 and none exists
155  *
156  * Shared method for polymost.c to call.
157  */
158 PTHead * PT_GetHead(int picnum, int palnum, unsigned short flags, int peek);
159 
160 
161 /**
162  * Initialise a PTMIdent structure from a PTHead
163  * @param id the PTMIdent to initialise from...
164  * @param pth the PTHead structure
165  */
166 void PTM_InitIdent(PTMIdent *id, PTHead *pth);
167 
168 /**
169  * Returns a PTMHead pointer for the given texture id
170  * @param id the texture identifier struct
171  * @return the PTMHead item, or null if it couldn't be created
172  *
173  * Shared method for polymost.c and mdsprite.c to call.
174  */
175 PTMHead * PTM_GetHead(const PTMIdent *id);
176 
177 /**
178  * Loads a texture file into OpenGL
179  * @param filename the texture filename
180  * @param ptmh the PTMHead structure to receive the texture details
181  * @param flags PTH_* flags to tune the load process
182  * @param effects HICEFFECT_* effects to apply
183  * @return 0 on success, <0 on error
184  *
185  * Shared method for mdsprite.c to call.
186  */
187 int PTM_LoadTextureFile(const char* filename, PTMHead* ptmh, int flags, int effects);
188 
189 /**
190  * Returns a string describing the error returned by PTM_LoadTextureFile
191  * @param err the error code
192  * @return the error string
193  *
194  * Shared method for mdsprite.c to call.
195  */
196 const char * PTM_GetLoadTextureFileErrorString(int err);
197 
198 #endif
199