Index: ddraw/TextureManager.c |
— | — | @@ -1,596 +0,0 @@ |
2 | | -// DXGL
|
3 | | -// Copyright (C) 2012-2014 William Feely
|
4 | | -
|
5 | | -// This library is free software; you can redistribute it and/or
|
6 | | -// modify it under the terms of the GNU Lesser General Public
|
7 | | -// License as published by the Free Software Foundation; either
|
8 | | -// version 2.1 of the License, or (at your option) any later version.
|
9 | | -
|
10 | | -// This library 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 GNU
|
13 | | -// Lesser General Public License for more details.
|
14 | | -
|
15 | | -// You should have received a copy of the GNU Lesser General Public
|
16 | | -// License along with this library; if not, write to the Free Software
|
17 | | -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | | -
|
19 | | -#include "common.h"
|
20 | | -#include "BufferObject.h"
|
21 | | -#include "TextureManager.h"
|
22 | | -#include <math.h>
|
23 | | -
|
24 | | -// Use EXACTLY one line per entry. Don't change layout of the list.
|
25 | | -static const int START_TEXFORMATS = __LINE__;
|
26 | | -const DDPIXELFORMAT texformats[] =
|
27 | | -{ // Size Flags FOURCC bits R/Ymask G/U/Zmask B/V/STmask A/Zmask
|
28 | | - {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0},
|
29 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0},
|
30 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0},
|
31 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x7E0, 0x1F, 0},
|
32 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0xFF0000, 0xFF00, 0xFF, 0},
|
33 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0},
|
34 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0},
|
35 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xE0, 0x1C, 0x3, 0xFF00},
|
36 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xF00, 0xF0, 0xF, 0xF000},
|
37 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0x7c00, 0x3E0, 0x1F, 0x8000},
|
38 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000},
|
39 | | - {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF, 0, 0, 0},
|
40 | | - {sizeof(DDPIXELFORMAT), DDPF_ALPHA, 0, 8, 0, 0, 0, 0},
|
41 | | - {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE|DDPF_ALPHAPIXELS,0, 16, 0xFF, 0, 0, 0xFF00},
|
42 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 16, 0, 0xFFFF, 0, 0},
|
43 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 24, 0, 0xFFFFFF00, 0, 0},
|
44 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0},
|
45 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0},
|
46 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0},
|
47 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}
|
48 | | -};
|
49 | | -static const int END_TEXFORMATS = __LINE__ - 4;
|
50 | | -int numtexformats;
|
51 | | -
|
52 | | -void ClearError()
|
53 | | -{
|
54 | | - do
|
55 | | - {
|
56 | | - if (glGetError() == GL_NO_ERROR) break;
|
57 | | - } while (1);
|
58 | | -}
|
59 | | -
|
60 | | -DWORD CalculateMipLevels(DWORD width, DWORD height)
|
61 | | -{
|
62 | | - DWORD x, y;
|
63 | | - DWORD levels = 1;
|
64 | | - if ((!width) || (!height)) return 0;
|
65 | | - if ((width == 1) || (height == 1)) return 1;
|
66 | | - x = width;
|
67 | | - y = height;
|
68 | | -miploop:
|
69 | | - x = max(1,(DWORD)floorf((float)x / 2.0f));
|
70 | | - y = max(1,(DWORD)floorf((float)y / 2.0f));
|
71 | | - levels++;
|
72 | | - if ((x == 1) || (y == 1)) return levels;
|
73 | | - else goto miploop;
|
74 | | -}
|
75 | | -
|
76 | | -void ShrinkMip(DWORD *x, DWORD *y)
|
77 | | -{
|
78 | | - *x = max(1, (DWORD)floorf((float)*x / 2.0f));
|
79 | | - *y = max(1, (DWORD)floorf((float)*y / 2.0f));
|
80 | | -}
|
81 | | -
|
82 | | -TextureManager *TextureManager_Create(glExtensions *glext)
|
83 | | -{
|
84 | | - TextureManager *newtex;
|
85 | | - numtexformats = END_TEXFORMATS - START_TEXFORMATS;
|
86 | | - newtex = (TextureManager*)malloc(sizeof(TextureManager));
|
87 | | - if (!newtex) return 0;
|
88 | | - ZeroMemory(newtex, sizeof(TextureManager));
|
89 | | - newtex->ext = glext;
|
90 | | - newtex->texlevel = 0;
|
91 | | - ZeroMemory(newtex->textures, 16 * sizeof(GLuint));
|
92 | | - return newtex;
|
93 | | -}
|
94 | | -
|
95 | | -void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height)
|
96 | | -{
|
97 | | - TextureManager_CreateTextureClassic(This, texture, width, height);
|
98 | | -}
|
99 | | -void TextureManager__DeleteTexture(TextureManager *This, TEXTURE *texture)
|
100 | | -{
|
101 | | - TextureManager_DeleteTexture(This, texture);
|
102 | | -}
|
103 | | -void TextureManager__UploadTexture(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc)
|
104 | | -{
|
105 | | - TextureManager_UploadTextureClassic(This, texture, level, data, width, height, checkerror, realloc);
|
106 | | -}
|
107 | | -void TextureManager__DownloadTexture(TextureManager *This, TEXTURE *texture, int level, void *data)
|
108 | | -{
|
109 | | - TextureManager_DownloadTextureClassic(This, texture, level, data);
|
110 | | -}
|
111 | | -
|
112 | | -void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height)
|
113 | | -{
|
114 | | - int texformat = -1;
|
115 | | - int i;
|
116 | | - int x, y;
|
117 | | - GLenum error;
|
118 | | - if (!texture->miplevel) texture->miplevel = 1;
|
119 | | - texture->pixelformat.dwSize = sizeof(DDPIXELFORMAT);
|
120 | | - for(i = 0; i < numtexformats; i++)
|
121 | | - {
|
122 | | - if(!memcmp(&texformats[i],&texture->pixelformat,sizeof(DDPIXELFORMAT)))
|
123 | | - {
|
124 | | - texformat = i;
|
125 | | - break;
|
126 | | - }
|
127 | | - }
|
128 | | - ZeroMemory(texture->internalformats, 8 * sizeof(GLint));
|
129 | | - switch(texformat)
|
130 | | - {
|
131 | | - case -1:
|
132 | | - case 0: // 8-bit palette
|
133 | | - if(This->ext->glver_major >= 3)
|
134 | | - {
|
135 | | - texture->internalformats[0] = GL_R8;
|
136 | | - texture->format = GL_RED;
|
137 | | - }
|
138 | | - else
|
139 | | - {
|
140 | | - texture->internalformats[0] = GL_RGBA8;
|
141 | | - texture->format = GL_LUMINANCE;
|
142 | | - }
|
143 | | - texture->type = GL_UNSIGNED_BYTE;
|
144 | | - texture->colororder = 4;
|
145 | | - texture->colorsizes[0] = 255;
|
146 | | - texture->colorsizes[1] = 255;
|
147 | | - texture->colorsizes[2] = 255;
|
148 | | - texture->colorsizes[3] = 255;
|
149 | | - texture->colorbits[0] = 8;
|
150 | | - texture->colorbits[1] = 0;
|
151 | | - texture->colorbits[2] = 0;
|
152 | | - texture->colorbits[3] = 0;
|
153 | | - break;
|
154 | | - case 1: // 8-bit RGB332
|
155 | | - texture->internalformats[0] = GL_R3_G3_B2;
|
156 | | - texture->internalformats[1] = GL_RGB8;
|
157 | | - texture->internalformats[2] = GL_RGBA8;
|
158 | | - texture->format = GL_RGB;
|
159 | | - texture->type = GL_UNSIGNED_BYTE_3_3_2;
|
160 | | - texture->colororder = 1;
|
161 | | - texture->colorsizes[0] = 7;
|
162 | | - texture->colorsizes[1] = 7;
|
163 | | - texture->colorsizes[2] = 3;
|
164 | | - texture->colorsizes[3] = 1;
|
165 | | - texture->colorbits[0] = 3;
|
166 | | - texture->colorbits[1] = 3;
|
167 | | - texture->colorbits[2] = 2;
|
168 | | - texture->colorbits[3] = 0;
|
169 | | - break;
|
170 | | - case 2: // 16-bit RGB555
|
171 | | - texture->internalformats[0] = GL_RGB5_A1;
|
172 | | - texture->internalformats[1] = GL_RGBA8;
|
173 | | - texture->format = GL_BGRA;
|
174 | | - texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
175 | | - texture->colororder = 1;
|
176 | | - texture->colorsizes[0] = 31;
|
177 | | - texture->colorsizes[1] = 31;
|
178 | | - texture->colorsizes[2] = 31;
|
179 | | - texture->colorsizes[3] = 1;
|
180 | | - texture->colorbits[0] = 5;
|
181 | | - texture->colorbits[1] = 5;
|
182 | | - texture->colorbits[2] = 5;
|
183 | | - texture->colorbits[3] = 1;
|
184 | | - break;
|
185 | | - case 3: // 16-bit RGB565
|
186 | | - texture->internalformats[0] = GL_RGB565;
|
187 | | - texture->internalformats[1] = GL_RGB8;
|
188 | | - texture->internalformats[2] = GL_RGBA8;
|
189 | | - texture->format = GL_RGB;
|
190 | | - texture->type = GL_UNSIGNED_SHORT_5_6_5;
|
191 | | - texture->colororder = 1;
|
192 | | - texture->colorsizes[0] = 31;
|
193 | | - texture->colorsizes[1] = 63;
|
194 | | - texture->colorsizes[2] = 31;
|
195 | | - texture->colorsizes[3] = 1;
|
196 | | - texture->colorbits[0] = 5;
|
197 | | - texture->colorbits[1] = 6;
|
198 | | - texture->colorbits[2] = 5;
|
199 | | - texture->colorbits[3] = 0;
|
200 | | - break;
|
201 | | - case 4: // 24-bit RGB888
|
202 | | - texture->internalformats[0] = GL_RGB8;
|
203 | | - texture->internalformats[1] = GL_RGBA8;
|
204 | | - texture->format = GL_BGR;
|
205 | | - texture->type = GL_UNSIGNED_BYTE;
|
206 | | - texture->colororder = 1;
|
207 | | - texture->colorsizes[0] = 255;
|
208 | | - texture->colorsizes[1] = 255;
|
209 | | - texture->colorsizes[2] = 255;
|
210 | | - texture->colorsizes[3] = 1;
|
211 | | - texture->colorbits[0] = 8;
|
212 | | - texture->colorbits[1] = 8;
|
213 | | - texture->colorbits[2] = 8;
|
214 | | - texture->colorbits[3] = 0;
|
215 | | - break;
|
216 | | - case 5: // 32-bit RGB888
|
217 | | - texture->internalformats[0] = GL_RGBA8;
|
218 | | - texture->format = GL_BGRA;
|
219 | | - texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
220 | | - texture->colororder = 1;
|
221 | | - texture->colorsizes[0] = 255;
|
222 | | - texture->colorsizes[1] = 255;
|
223 | | - texture->colorsizes[2] = 255;
|
224 | | - texture->colorsizes[3] = 1;
|
225 | | - texture->colorbits[0] = 8;
|
226 | | - texture->colorbits[1] = 8;
|
227 | | - texture->colorbits[2] = 8;
|
228 | | - texture->colorbits[3] = 0;
|
229 | | - break;
|
230 | | - case 6: // 32-bit BGR888
|
231 | | - texture->internalformats[0] = GL_RGBA8;
|
232 | | - texture->format = GL_RGBA;
|
233 | | - texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
234 | | - texture->colororder = 0;
|
235 | | - texture->colorsizes[0] = 255;
|
236 | | - texture->colorsizes[1] = 255;
|
237 | | - texture->colorsizes[2] = 255;
|
238 | | - texture->colorsizes[3] = 1;
|
239 | | - texture->colorbits[0] = 8;
|
240 | | - texture->colorbits[1] = 8;
|
241 | | - texture->colorbits[2] = 8;
|
242 | | - texture->colorbits[3] = 0;
|
243 | | - break;
|
244 | | - case 7: // 16-bit RGBA8332
|
245 | | - FIXME("Unusual texture format RGBA8332 not supported");
|
246 | | - texture->colororder = 1;
|
247 | | - texture->colorsizes[0] = 7;
|
248 | | - texture->colorsizes[1] = 7;
|
249 | | - texture->colorsizes[2] = 3;
|
250 | | - texture->colorsizes[3] = 255;
|
251 | | - texture->colorbits[0] = 3;
|
252 | | - texture->colorbits[1] = 3;
|
253 | | - texture->colorbits[2] = 2;
|
254 | | - texture->colorbits[3] = 8;
|
255 | | - break;
|
256 | | - case 8: // 16-bit RGBA4444
|
257 | | - texture->internalformats[0] = GL_RGBA4;
|
258 | | - texture->internalformats[1] = GL_RGBA8;
|
259 | | - texture->format = GL_BGRA;
|
260 | | - texture->type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
261 | | - texture->colororder = 1;
|
262 | | - texture->colorsizes[0] = 15;
|
263 | | - texture->colorsizes[1] = 15;
|
264 | | - texture->colorsizes[2] = 15;
|
265 | | - texture->colorsizes[3] = 15;
|
266 | | - texture->colorbits[0] = 4;
|
267 | | - texture->colorbits[1] = 4;
|
268 | | - texture->colorbits[2] = 4;
|
269 | | - texture->colorbits[3] = 4;
|
270 | | - break;
|
271 | | - case 9: // 16-bit RGBA1555
|
272 | | - texture->internalformats[0] = GL_RGB5_A1;
|
273 | | - texture->internalformats[1] = GL_RGBA8;
|
274 | | - texture->format = GL_BGRA;
|
275 | | - texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
276 | | - texture->colorbits[0] = 5;
|
277 | | - texture->colorbits[1] = 5;
|
278 | | - texture->colorbits[2] = 5;
|
279 | | - texture->colorbits[3] = 1;
|
280 | | - break;
|
281 | | - case 10: // 32-bit RGBA8888
|
282 | | - texture->internalformats[0] = GL_RGBA8;
|
283 | | - texture->format = GL_BGRA;
|
284 | | - texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
285 | | - texture->colororder = 1;
|
286 | | - texture->colorsizes[0] = 255;
|
287 | | - texture->colorsizes[1] = 255;
|
288 | | - texture->colorsizes[2] = 255;
|
289 | | - texture->colorsizes[3] = 255;
|
290 | | - texture->colorbits[0] = 8;
|
291 | | - texture->colorbits[1] = 8;
|
292 | | - texture->colorbits[2] = 8;
|
293 | | - texture->colorbits[3] = 8;
|
294 | | - break;
|
295 | | - case 11: // 8-bit Luminance
|
296 | | - texture->internalformats[0] = GL_LUMINANCE8;
|
297 | | - texture->internalformats[1] = GL_RGB8;
|
298 | | - texture->internalformats[2] = GL_RGBA8;
|
299 | | - texture->format = GL_LUMINANCE;
|
300 | | - texture->type = GL_UNSIGNED_BYTE;
|
301 | | - texture->colororder = 5;
|
302 | | - texture->colorsizes[0] = 255;
|
303 | | - texture->colorsizes[1] = 255;
|
304 | | - texture->colorsizes[2] = 255;
|
305 | | - texture->colorsizes[3] = 255;
|
306 | | - texture->colorbits[0] = 8;
|
307 | | - texture->colorbits[1] = 0;
|
308 | | - texture->colorbits[2] = 0;
|
309 | | - texture->colorbits[3] = 0;
|
310 | | - break;
|
311 | | - case 12: // 8-bit Alpha
|
312 | | - texture->internalformats[0] = GL_ALPHA8;
|
313 | | - texture->format = GL_ALPHA;
|
314 | | - texture->type = GL_UNSIGNED_BYTE;
|
315 | | - texture->colororder = 6;
|
316 | | - texture->colorsizes[0] = 255;
|
317 | | - texture->colorsizes[1] = 255;
|
318 | | - texture->colorsizes[2] = 255;
|
319 | | - texture->colorsizes[3] = 255;
|
320 | | - texture->colorbits[0] = 0;
|
321 | | - texture->colorbits[1] = 0;
|
322 | | - texture->colorbits[2] = 0;
|
323 | | - texture->colorbits[3] = 8;
|
324 | | - break;
|
325 | | - case 13: // 16-bit Luminance Alpha
|
326 | | - texture->internalformats[0] = GL_LUMINANCE8_ALPHA8;
|
327 | | - texture->internalformats[1] = GL_RGBA8;
|
328 | | - texture->format = GL_LUMINANCE_ALPHA;
|
329 | | - texture->type = GL_UNSIGNED_BYTE;
|
330 | | - texture->colororder = 7;
|
331 | | - texture->colorsizes[0] = 255;
|
332 | | - texture->colorsizes[1] = 255;
|
333 | | - texture->colorsizes[2] = 255;
|
334 | | - texture->colorsizes[3] = 255;
|
335 | | - texture->colorbits[0] = 8;
|
336 | | - texture->colorbits[1] = 0;
|
337 | | - texture->colorbits[2] = 0;
|
338 | | - texture->colorbits[3] = 8;
|
339 | | - break;
|
340 | | - case 14: // 16-bit Z buffer
|
341 | | - texture->internalformats[0] = GL_DEPTH_COMPONENT16;
|
342 | | - texture->format = GL_DEPTH_COMPONENT;
|
343 | | - texture->type = GL_UNSIGNED_SHORT;
|
344 | | - texture->colororder = 4;
|
345 | | - texture->colorsizes[0] = 65535;
|
346 | | - texture->colorsizes[1] = 65535;
|
347 | | - texture->colorsizes[2] = 65535;
|
348 | | - texture->colorsizes[3] = 65535;
|
349 | | - texture->colorbits[0] = 16;
|
350 | | - texture->colorbits[1] = 0;
|
351 | | - texture->colorbits[2] = 0;
|
352 | | - texture->colorbits[3] = 0;
|
353 | | - break;
|
354 | | - case 15: // 24-bit Z buffer
|
355 | | - texture->internalformats[0] = GL_DEPTH_COMPONENT24;
|
356 | | - texture->format = GL_DEPTH_COMPONENT;
|
357 | | - texture->type = GL_UNSIGNED_INT;
|
358 | | - texture->colororder = 4;
|
359 | | - texture->colorsizes[0] = 16777215;
|
360 | | - texture->colorsizes[1] = 16777215;
|
361 | | - texture->colorsizes[2] = 16777215;
|
362 | | - texture->colorsizes[3] = 16777215;
|
363 | | - texture->colorbits[0] = 24;
|
364 | | - texture->colorbits[1] = 0;
|
365 | | - texture->colorbits[2] = 0;
|
366 | | - texture->colorbits[3] = 0;
|
367 | | - break;
|
368 | | - case 16: // 32/24 bit Z buffer
|
369 | | - texture->internalformats[0] = GL_DEPTH_COMPONENT24;
|
370 | | - texture->format = GL_DEPTH_COMPONENT;
|
371 | | - texture->type = GL_UNSIGNED_INT;
|
372 | | - texture->colororder = 4;
|
373 | | - texture->colorsizes[0] = 16777215;
|
374 | | - texture->colorsizes[1] = 16777215;
|
375 | | - texture->colorsizes[2] = 16777215;
|
376 | | - texture->colorsizes[3] = 16777215;
|
377 | | - texture->colorbits[0] = 24;
|
378 | | - texture->colorbits[1] = 0;
|
379 | | - texture->colorbits[2] = 0;
|
380 | | - texture->colorbits[3] = 0;
|
381 | | - break;
|
382 | | - case 17: // 32-bit Z buffer
|
383 | | - texture->internalformats[0] = GL_DEPTH_COMPONENT32;
|
384 | | - texture->format = GL_DEPTH_COMPONENT;
|
385 | | - texture->type = GL_UNSIGNED_INT;
|
386 | | - texture->colororder = 4;
|
387 | | - texture->colorsizes[0] = 4294967295;
|
388 | | - texture->colorsizes[1] = 4294967295;
|
389 | | - texture->colorsizes[2] = 4294967295;
|
390 | | - texture->colorsizes[3] = 4294967295;
|
391 | | - texture->colorbits[0] = 32;
|
392 | | - texture->colorbits[1] = 0;
|
393 | | - texture->colorbits[2] = 0;
|
394 | | - texture->colorbits[3] = 0;
|
395 | | - break;
|
396 | | - case 18: // 32-bit Z/Stencil buffer, depth LSB
|
397 | | - texture->internalformats[0] = GL_DEPTH24_STENCIL8;
|
398 | | - texture->format = GL_DEPTH_STENCIL;
|
399 | | - texture->type = GL_UNSIGNED_INT_24_8;
|
400 | | - texture->colororder = 7;
|
401 | | - texture->colorsizes[0] = 16777215;
|
402 | | - texture->colorsizes[1] = 16777215;
|
403 | | - texture->colorsizes[2] = 16777215;
|
404 | | - texture->colorsizes[3] = 255;
|
405 | | - texture->colorbits[0] = 24;
|
406 | | - texture->colorbits[1] = 0;
|
407 | | - texture->colorbits[2] = 0;
|
408 | | - texture->colorbits[3] = 8;
|
409 | | - break;
|
410 | | - case 19: // 32-bit Z/Stencil buffer, depth MSB
|
411 | | - texture->internalformats[0] = GL_DEPTH24_STENCIL8;
|
412 | | - texture->format = GL_DEPTH_STENCIL;
|
413 | | - texture->type = GL_UNSIGNED_INT_24_8;
|
414 | | - texture->colororder = 7;
|
415 | | - texture->colorsizes[0] = 16777215;
|
416 | | - texture->colorsizes[1] = 16777215;
|
417 | | - texture->colorsizes[2] = 16777215;
|
418 | | - texture->colorsizes[3] = 255;
|
419 | | - texture->colorbits[0] = 24;
|
420 | | - texture->colorbits[1] = 0;
|
421 | | - texture->colorbits[2] = 0;
|
422 | | - texture->colorbits[3] = 8;
|
423 | | - break;
|
424 | | - }
|
425 | | - texture->width = width;
|
426 | | - texture->height = height;
|
427 | | - glGenTextures(1,&texture->id);
|
428 | | - TextureManager_SetTexture(This,0,texture);
|
429 | | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->minfilter);
|
430 | | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->magfilter);
|
431 | | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wraps);
|
432 | | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrapt);
|
433 | | - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture->miplevel - 1);
|
434 | | - x = texture->width;
|
435 | | - y = texture->height;
|
436 | | - for (i = 0; i < texture->miplevel; i++)
|
437 | | - {
|
438 | | - do
|
439 | | - {
|
440 | | - ClearError();
|
441 | | - glTexImage2D(GL_TEXTURE_2D, i, texture->internalformats[0], x, y, 0, texture->format, texture->type, NULL);
|
442 | | - ShrinkMip(&x, &y);
|
443 | | - error = glGetError();
|
444 | | - if (error != GL_NO_ERROR)
|
445 | | - {
|
446 | | - if (texture->internalformats[1] == 0)
|
447 | | - {
|
448 | | - FIXME("Failed to create texture, cannot find internal format");
|
449 | | - break;
|
450 | | - }
|
451 | | - memmove(&texture->internalformats[0], &texture->internalformats[1], 7 * sizeof(GLint));
|
452 | | - texture->internalformats[7] = 0;
|
453 | | - }
|
454 | | - else break;
|
455 | | - } while (1);
|
456 | | - }
|
457 | | -}
|
458 | | -
|
459 | | -void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture)
|
460 | | -{
|
461 | | - glDeleteTextures(1,&texture->id);
|
462 | | - texture->bordercolor = texture->format = texture->type = texture->width =
|
463 | | - texture->height = texture->magfilter = texture->minfilter =
|
464 | | - texture->miplevel = texture->wraps = texture->wrapt =
|
465 | | - texture->id = 0;
|
466 | | - texture->pboPack = texture->pboUnpack = NULL;
|
467 | | - ZeroMemory(texture->internalformats, 8 * sizeof(GLint));
|
468 | | -}
|
469 | | -
|
470 | | -void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc)
|
471 | | -{
|
472 | | - GLenum error;
|
473 | | - texture->width = width;
|
474 | | - texture->height = height;
|
475 | | - if (checkerror)
|
476 | | - {
|
477 | | - do
|
478 | | - {
|
479 | | - ClearError();
|
480 | | - if (This->ext->GLEXT_EXT_direct_state_access)
|
481 | | - {
|
482 | | - if (realloc)This->ext->glTextureImage2DEXT(texture->id, GL_TEXTURE_2D, level, texture->internalformats[0],
|
483 | | - width, height, 0, texture->format, texture->type, data);
|
484 | | - else This->ext->glTextureSubImage2DEXT(texture->id, GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
485 | | - }
|
486 | | - else
|
487 | | - {
|
488 | | - TextureManager_SetActiveTexture(This, 0);
|
489 | | - TextureManager_SetTexture(This, 0, texture);
|
490 | | - if (realloc)glTexImage2D(GL_TEXTURE_2D, level, texture->internalformats[0], width, height, 0, texture->format, texture->type, data);
|
491 | | - else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
492 | | - }
|
493 | | - error = glGetError();
|
494 | | - if (error != GL_NO_ERROR)
|
495 | | - {
|
496 | | - if (texture->internalformats[1] == 0)
|
497 | | - {
|
498 | | - FIXME("Failed to update texture, cannot find internal format");
|
499 | | - break;
|
500 | | - }
|
501 | | - memmove(&texture->internalformats[0], &texture->internalformats[1], 7 * sizeof(GLint));
|
502 | | - texture->internalformats[7] = 0;
|
503 | | - }
|
504 | | - else break;
|
505 | | - } while (1);
|
506 | | - }
|
507 | | - else
|
508 | | - {
|
509 | | - if (This->ext->GLEXT_EXT_direct_state_access)
|
510 | | - {
|
511 | | - if (realloc)This->ext->glTextureImage2DEXT(texture->id, GL_TEXTURE_2D, level, texture->internalformats[0],
|
512 | | - width, height, 0, texture->format, texture->type, data);
|
513 | | - else This->ext->glTextureSubImage2DEXT(texture->id, GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
514 | | - }
|
515 | | - else
|
516 | | - {
|
517 | | - TextureManager_SetActiveTexture(This, 0);
|
518 | | - TextureManager_SetTexture(This, 0, texture);
|
519 | | - if (realloc)glTexImage2D(GL_TEXTURE_2D, level, texture->internalformats[0], width, height, 0, texture->format, texture->type, data);
|
520 | | - else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
521 | | - }
|
522 | | - }
|
523 | | -}
|
524 | | -
|
525 | | -void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data)
|
526 | | -{
|
527 | | - if(This->ext->GLEXT_EXT_direct_state_access) This->ext->glGetTextureImageEXT(texture->id,GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
528 | | - else
|
529 | | - {
|
530 | | - TextureManager_SetActiveTexture(This, 0);
|
531 | | - TextureManager_SetTexture(This, 0,texture);
|
532 | | - glGetTexImage(GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
533 | | - }
|
534 | | -}
|
535 | | -
|
536 | | -void TextureManager_SetActiveTexture(TextureManager *This, int level)
|
537 | | -{
|
538 | | - if(level != This->texlevel)
|
539 | | - {
|
540 | | - This->texlevel = level;
|
541 | | - This->ext->glActiveTexture(GL_TEXTURE0+level);
|
542 | | - }
|
543 | | -}
|
544 | | -
|
545 | | -
|
546 | | -void TextureManager_SetTexture(TextureManager *This, unsigned int level, TEXTURE *texture)
|
547 | | -{
|
548 | | - GLuint texname;
|
549 | | - if (level >= 16) return;
|
550 | | - if(!texture) texname = 0;
|
551 | | - else texname=texture->id;
|
552 | | - if(texname != This->textures[level])
|
553 | | - {
|
554 | | - TextureManager_SetActiveTexture(This, level);
|
555 | | - glBindTexture(GL_TEXTURE_2D,texname);
|
556 | | - }
|
557 | | -}
|
558 | | -
|
559 | | -BOOL TextureManager_FixTexture(TextureManager *This, TEXTURE *texture, void *data, DWORD *dirty, GLint level)
|
560 | | -{
|
561 | | - // data should be null to create uninitialized texture or be pointer to top-level
|
562 | | - // buffer to retain texture data
|
563 | | - TEXTURE newtexture;
|
564 | | - GLenum error;
|
565 | | - memcpy(&newtexture, texture, sizeof(TEXTURE));
|
566 | | - if (texture->internalformats[1] == 0) return FALSE;
|
567 | | - glGenTextures(1, &newtexture.id);
|
568 | | - TextureManager_SetActiveTexture(This, 0);
|
569 | | - if (data)
|
570 | | - {
|
571 | | - TextureManager_SetTexture(This, 0, texture);
|
572 | | - glGetTexImage(GL_TEXTURE_2D, level, texture->format, texture->type, data);
|
573 | | - if (dirty) *dirty |= 2;
|
574 | | - }
|
575 | | - TextureManager_SetTexture(This, 0, &newtexture);
|
576 | | - do
|
577 | | - {
|
578 | | - memmove(&newtexture.internalformats[0], &newtexture.internalformats[1], 7 * sizeof(GLint));
|
579 | | - newtexture.internalformats[7] = 0;
|
580 | | - ClearError();
|
581 | | - glTexImage2D(GL_TEXTURE_2D, level, newtexture.internalformats[0], newtexture.width, newtexture.height,
|
582 | | - 0, newtexture.format, newtexture.type, data);
|
583 | | - error = glGetError();
|
584 | | - if (error != GL_NO_ERROR)
|
585 | | - {
|
586 | | - if (newtexture.internalformats[1] == 0)
|
587 | | - {
|
588 | | - FIXME("Failed to repair texture, cannot find internal format");
|
589 | | - break;
|
590 | | - }
|
591 | | - }
|
592 | | - else break;
|
593 | | - } while (1);
|
594 | | - TextureManager__DeleteTexture(This, texture);
|
595 | | - memcpy(texture, &newtexture, sizeof(TEXTURE));
|
596 | | - return TRUE;
|
597 | | -} |
\ No newline at end of file |
Index: ddraw/TextureManager.cpp |
— | — | @@ -0,0 +1,576 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2012-2014 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library 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 GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#include "common.h"
|
| 20 | +#include "BufferObject.h"
|
| 21 | +#include "TextureManager.h"
|
| 22 | +#include "glUtil.h"
|
| 23 | +#include <math.h>
|
| 24 | +
|
| 25 | +extern "C" {
|
| 26 | +
|
| 27 | +// Use EXACTLY one line per entry. Don't change layout of the list.
|
| 28 | +static const int START_TEXFORMATS = __LINE__;
|
| 29 | +const DDPIXELFORMAT texformats[] =
|
| 30 | +{ // Size Flags FOURCC bits R/Ymask G/U/Zmask B/V/STmask A/Zmask
|
| 31 | + {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0},
|
| 32 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0},
|
| 33 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0},
|
| 34 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x7E0, 0x1F, 0},
|
| 35 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0xFF0000, 0xFF00, 0xFF, 0},
|
| 36 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0},
|
| 37 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0},
|
| 38 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xE0, 0x1C, 0x3, 0xFF00},
|
| 39 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xF00, 0xF0, 0xF, 0xF000},
|
| 40 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0x7c00, 0x3E0, 0x1F, 0x8000},
|
| 41 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000},
|
| 42 | + {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF, 0, 0, 0},
|
| 43 | + {sizeof(DDPIXELFORMAT), DDPF_ALPHA, 0, 8, 0, 0, 0, 0},
|
| 44 | + {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE|DDPF_ALPHAPIXELS,0, 16, 0xFF, 0, 0, 0xFF00},
|
| 45 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 16, 0, 0xFFFF, 0, 0},
|
| 46 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 24, 0, 0xFFFFFF00, 0, 0},
|
| 47 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0},
|
| 48 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0},
|
| 49 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0},
|
| 50 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}
|
| 51 | +};
|
| 52 | +static const int END_TEXFORMATS = __LINE__ - 4;
|
| 53 | +int numtexformats;
|
| 54 | +
|
| 55 | +void ClearError()
|
| 56 | +{
|
| 57 | + do
|
| 58 | + {
|
| 59 | + if (glGetError() == GL_NO_ERROR) break;
|
| 60 | + } while (1);
|
| 61 | +}
|
| 62 | +
|
| 63 | +DWORD CalculateMipLevels(DWORD width, DWORD height)
|
| 64 | +{
|
| 65 | + DWORD x, y;
|
| 66 | + DWORD levels = 1;
|
| 67 | + if ((!width) || (!height)) return 0;
|
| 68 | + if ((width == 1) || (height == 1)) return 1;
|
| 69 | + x = width;
|
| 70 | + y = height;
|
| 71 | +miploop:
|
| 72 | + x = max(1,(DWORD)floorf((float)x / 2.0f));
|
| 73 | + y = max(1,(DWORD)floorf((float)y / 2.0f));
|
| 74 | + levels++;
|
| 75 | + if ((x == 1) || (y == 1)) return levels;
|
| 76 | + else goto miploop;
|
| 77 | +}
|
| 78 | +
|
| 79 | +void ShrinkMip(DWORD *x, DWORD *y)
|
| 80 | +{
|
| 81 | + *x = max(1, (DWORD)floorf((float)*x / 2.0f));
|
| 82 | + *y = max(1, (DWORD)floorf((float)*y / 2.0f));
|
| 83 | +}
|
| 84 | +
|
| 85 | +TextureManager *TextureManager_Create(glExtensions *glext)
|
| 86 | +{
|
| 87 | + TextureManager *newtex;
|
| 88 | + numtexformats = END_TEXFORMATS - START_TEXFORMATS;
|
| 89 | + newtex = (TextureManager*)malloc(sizeof(TextureManager));
|
| 90 | + if (!newtex) return 0;
|
| 91 | + ZeroMemory(newtex, sizeof(TextureManager));
|
| 92 | + newtex->ext = glext;
|
| 93 | + return newtex;
|
| 94 | +}
|
| 95 | +
|
| 96 | +void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height, glUtil *util)
|
| 97 | +{
|
| 98 | + TextureManager_CreateTextureClassic(This, texture, width, height, util);
|
| 99 | +}
|
| 100 | +void TextureManager__DeleteTexture(TextureManager *This, TEXTURE *texture)
|
| 101 | +{
|
| 102 | + TextureManager_DeleteTexture(This, texture);
|
| 103 | +}
|
| 104 | +void TextureManager__UploadTexture(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc, glUtil *util)
|
| 105 | +{
|
| 106 | + TextureManager_UploadTextureClassic(This, texture, level, data, width, height, checkerror, realloc, util);
|
| 107 | +}
|
| 108 | +void TextureManager__DownloadTexture(TextureManager *This, TEXTURE *texture, int level, void *data, glUtil *util)
|
| 109 | +{
|
| 110 | + TextureManager_DownloadTextureClassic(This, texture, level, data, util);
|
| 111 | +}
|
| 112 | +
|
| 113 | +void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height, glUtil *util)
|
| 114 | +{
|
| 115 | + int texformat = -1;
|
| 116 | + int i;
|
| 117 | + DWORD x, y;
|
| 118 | + GLenum error;
|
| 119 | + if (!texture->miplevel) texture->miplevel = 1;
|
| 120 | + texture->pixelformat.dwSize = sizeof(DDPIXELFORMAT);
|
| 121 | + for(i = 0; i < numtexformats; i++)
|
| 122 | + {
|
| 123 | + if(!memcmp(&texformats[i],&texture->pixelformat,sizeof(DDPIXELFORMAT)))
|
| 124 | + {
|
| 125 | + texformat = i;
|
| 126 | + break;
|
| 127 | + }
|
| 128 | + }
|
| 129 | + ZeroMemory(texture->internalformats, 8 * sizeof(GLint));
|
| 130 | + switch(texformat)
|
| 131 | + {
|
| 132 | + case -1:
|
| 133 | + case 0: // 8-bit palette
|
| 134 | + if(This->ext->glver_major >= 3)
|
| 135 | + {
|
| 136 | + texture->internalformats[0] = GL_R8;
|
| 137 | + texture->format = GL_RED;
|
| 138 | + }
|
| 139 | + else
|
| 140 | + {
|
| 141 | + texture->internalformats[0] = GL_RGBA8;
|
| 142 | + texture->format = GL_LUMINANCE;
|
| 143 | + }
|
| 144 | + texture->type = GL_UNSIGNED_BYTE;
|
| 145 | + texture->colororder = 4;
|
| 146 | + texture->colorsizes[0] = 255;
|
| 147 | + texture->colorsizes[1] = 255;
|
| 148 | + texture->colorsizes[2] = 255;
|
| 149 | + texture->colorsizes[3] = 255;
|
| 150 | + texture->colorbits[0] = 8;
|
| 151 | + texture->colorbits[1] = 0;
|
| 152 | + texture->colorbits[2] = 0;
|
| 153 | + texture->colorbits[3] = 0;
|
| 154 | + break;
|
| 155 | + case 1: // 8-bit RGB332
|
| 156 | + texture->internalformats[0] = GL_R3_G3_B2;
|
| 157 | + texture->internalformats[1] = GL_RGB8;
|
| 158 | + texture->internalformats[2] = GL_RGBA8;
|
| 159 | + texture->format = GL_RGB;
|
| 160 | + texture->type = GL_UNSIGNED_BYTE_3_3_2;
|
| 161 | + texture->colororder = 1;
|
| 162 | + texture->colorsizes[0] = 7;
|
| 163 | + texture->colorsizes[1] = 7;
|
| 164 | + texture->colorsizes[2] = 3;
|
| 165 | + texture->colorsizes[3] = 1;
|
| 166 | + texture->colorbits[0] = 3;
|
| 167 | + texture->colorbits[1] = 3;
|
| 168 | + texture->colorbits[2] = 2;
|
| 169 | + texture->colorbits[3] = 0;
|
| 170 | + break;
|
| 171 | + case 2: // 16-bit RGB555
|
| 172 | + texture->internalformats[0] = GL_RGB5_A1;
|
| 173 | + texture->internalformats[1] = GL_RGBA8;
|
| 174 | + texture->format = GL_BGRA;
|
| 175 | + texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| 176 | + texture->colororder = 1;
|
| 177 | + texture->colorsizes[0] = 31;
|
| 178 | + texture->colorsizes[1] = 31;
|
| 179 | + texture->colorsizes[2] = 31;
|
| 180 | + texture->colorsizes[3] = 1;
|
| 181 | + texture->colorbits[0] = 5;
|
| 182 | + texture->colorbits[1] = 5;
|
| 183 | + texture->colorbits[2] = 5;
|
| 184 | + texture->colorbits[3] = 1;
|
| 185 | + break;
|
| 186 | + case 3: // 16-bit RGB565
|
| 187 | + texture->internalformats[0] = GL_RGB565;
|
| 188 | + texture->internalformats[1] = GL_RGB8;
|
| 189 | + texture->internalformats[2] = GL_RGBA8;
|
| 190 | + texture->format = GL_RGB;
|
| 191 | + texture->type = GL_UNSIGNED_SHORT_5_6_5;
|
| 192 | + texture->colororder = 1;
|
| 193 | + texture->colorsizes[0] = 31;
|
| 194 | + texture->colorsizes[1] = 63;
|
| 195 | + texture->colorsizes[2] = 31;
|
| 196 | + texture->colorsizes[3] = 1;
|
| 197 | + texture->colorbits[0] = 5;
|
| 198 | + texture->colorbits[1] = 6;
|
| 199 | + texture->colorbits[2] = 5;
|
| 200 | + texture->colorbits[3] = 0;
|
| 201 | + break;
|
| 202 | + case 4: // 24-bit RGB888
|
| 203 | + texture->internalformats[0] = GL_RGB8;
|
| 204 | + texture->internalformats[1] = GL_RGBA8;
|
| 205 | + texture->format = GL_BGR;
|
| 206 | + texture->type = GL_UNSIGNED_BYTE;
|
| 207 | + texture->colororder = 1;
|
| 208 | + texture->colorsizes[0] = 255;
|
| 209 | + texture->colorsizes[1] = 255;
|
| 210 | + texture->colorsizes[2] = 255;
|
| 211 | + texture->colorsizes[3] = 1;
|
| 212 | + texture->colorbits[0] = 8;
|
| 213 | + texture->colorbits[1] = 8;
|
| 214 | + texture->colorbits[2] = 8;
|
| 215 | + texture->colorbits[3] = 0;
|
| 216 | + break;
|
| 217 | + case 5: // 32-bit RGB888
|
| 218 | + texture->internalformats[0] = GL_RGBA8;
|
| 219 | + texture->format = GL_BGRA;
|
| 220 | + texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 221 | + texture->colororder = 1;
|
| 222 | + texture->colorsizes[0] = 255;
|
| 223 | + texture->colorsizes[1] = 255;
|
| 224 | + texture->colorsizes[2] = 255;
|
| 225 | + texture->colorsizes[3] = 1;
|
| 226 | + texture->colorbits[0] = 8;
|
| 227 | + texture->colorbits[1] = 8;
|
| 228 | + texture->colorbits[2] = 8;
|
| 229 | + texture->colorbits[3] = 0;
|
| 230 | + break;
|
| 231 | + case 6: // 32-bit BGR888
|
| 232 | + texture->internalformats[0] = GL_RGBA8;
|
| 233 | + texture->format = GL_RGBA;
|
| 234 | + texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 235 | + texture->colororder = 0;
|
| 236 | + texture->colorsizes[0] = 255;
|
| 237 | + texture->colorsizes[1] = 255;
|
| 238 | + texture->colorsizes[2] = 255;
|
| 239 | + texture->colorsizes[3] = 1;
|
| 240 | + texture->colorbits[0] = 8;
|
| 241 | + texture->colorbits[1] = 8;
|
| 242 | + texture->colorbits[2] = 8;
|
| 243 | + texture->colorbits[3] = 0;
|
| 244 | + break;
|
| 245 | + case 7: // 16-bit RGBA8332
|
| 246 | + FIXME("Unusual texture format RGBA8332 not supported");
|
| 247 | + texture->colororder = 1;
|
| 248 | + texture->colorsizes[0] = 7;
|
| 249 | + texture->colorsizes[1] = 7;
|
| 250 | + texture->colorsizes[2] = 3;
|
| 251 | + texture->colorsizes[3] = 255;
|
| 252 | + texture->colorbits[0] = 3;
|
| 253 | + texture->colorbits[1] = 3;
|
| 254 | + texture->colorbits[2] = 2;
|
| 255 | + texture->colorbits[3] = 8;
|
| 256 | + break;
|
| 257 | + case 8: // 16-bit RGBA4444
|
| 258 | + texture->internalformats[0] = GL_RGBA4;
|
| 259 | + texture->internalformats[1] = GL_RGBA8;
|
| 260 | + texture->format = GL_BGRA;
|
| 261 | + texture->type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
| 262 | + texture->colororder = 1;
|
| 263 | + texture->colorsizes[0] = 15;
|
| 264 | + texture->colorsizes[1] = 15;
|
| 265 | + texture->colorsizes[2] = 15;
|
| 266 | + texture->colorsizes[3] = 15;
|
| 267 | + texture->colorbits[0] = 4;
|
| 268 | + texture->colorbits[1] = 4;
|
| 269 | + texture->colorbits[2] = 4;
|
| 270 | + texture->colorbits[3] = 4;
|
| 271 | + break;
|
| 272 | + case 9: // 16-bit RGBA1555
|
| 273 | + texture->internalformats[0] = GL_RGB5_A1;
|
| 274 | + texture->internalformats[1] = GL_RGBA8;
|
| 275 | + texture->format = GL_BGRA;
|
| 276 | + texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| 277 | + texture->colorbits[0] = 5;
|
| 278 | + texture->colorbits[1] = 5;
|
| 279 | + texture->colorbits[2] = 5;
|
| 280 | + texture->colorbits[3] = 1;
|
| 281 | + break;
|
| 282 | + case 10: // 32-bit RGBA8888
|
| 283 | + texture->internalformats[0] = GL_RGBA8;
|
| 284 | + texture->format = GL_BGRA;
|
| 285 | + texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 286 | + texture->colororder = 1;
|
| 287 | + texture->colorsizes[0] = 255;
|
| 288 | + texture->colorsizes[1] = 255;
|
| 289 | + texture->colorsizes[2] = 255;
|
| 290 | + texture->colorsizes[3] = 255;
|
| 291 | + texture->colorbits[0] = 8;
|
| 292 | + texture->colorbits[1] = 8;
|
| 293 | + texture->colorbits[2] = 8;
|
| 294 | + texture->colorbits[3] = 8;
|
| 295 | + break;
|
| 296 | + case 11: // 8-bit Luminance
|
| 297 | + texture->internalformats[0] = GL_LUMINANCE8;
|
| 298 | + texture->internalformats[1] = GL_RGB8;
|
| 299 | + texture->internalformats[2] = GL_RGBA8;
|
| 300 | + texture->format = GL_LUMINANCE;
|
| 301 | + texture->type = GL_UNSIGNED_BYTE;
|
| 302 | + texture->colororder = 5;
|
| 303 | + texture->colorsizes[0] = 255;
|
| 304 | + texture->colorsizes[1] = 255;
|
| 305 | + texture->colorsizes[2] = 255;
|
| 306 | + texture->colorsizes[3] = 255;
|
| 307 | + texture->colorbits[0] = 8;
|
| 308 | + texture->colorbits[1] = 0;
|
| 309 | + texture->colorbits[2] = 0;
|
| 310 | + texture->colorbits[3] = 0;
|
| 311 | + break;
|
| 312 | + case 12: // 8-bit Alpha
|
| 313 | + texture->internalformats[0] = GL_ALPHA8;
|
| 314 | + texture->format = GL_ALPHA;
|
| 315 | + texture->type = GL_UNSIGNED_BYTE;
|
| 316 | + texture->colororder = 6;
|
| 317 | + texture->colorsizes[0] = 255;
|
| 318 | + texture->colorsizes[1] = 255;
|
| 319 | + texture->colorsizes[2] = 255;
|
| 320 | + texture->colorsizes[3] = 255;
|
| 321 | + texture->colorbits[0] = 0;
|
| 322 | + texture->colorbits[1] = 0;
|
| 323 | + texture->colorbits[2] = 0;
|
| 324 | + texture->colorbits[3] = 8;
|
| 325 | + break;
|
| 326 | + case 13: // 16-bit Luminance Alpha
|
| 327 | + texture->internalformats[0] = GL_LUMINANCE8_ALPHA8;
|
| 328 | + texture->internalformats[1] = GL_RGBA8;
|
| 329 | + texture->format = GL_LUMINANCE_ALPHA;
|
| 330 | + texture->type = GL_UNSIGNED_BYTE;
|
| 331 | + texture->colororder = 7;
|
| 332 | + texture->colorsizes[0] = 255;
|
| 333 | + texture->colorsizes[1] = 255;
|
| 334 | + texture->colorsizes[2] = 255;
|
| 335 | + texture->colorsizes[3] = 255;
|
| 336 | + texture->colorbits[0] = 8;
|
| 337 | + texture->colorbits[1] = 0;
|
| 338 | + texture->colorbits[2] = 0;
|
| 339 | + texture->colorbits[3] = 8;
|
| 340 | + break;
|
| 341 | + case 14: // 16-bit Z buffer
|
| 342 | + texture->internalformats[0] = GL_DEPTH_COMPONENT16;
|
| 343 | + texture->format = GL_DEPTH_COMPONENT;
|
| 344 | + texture->type = GL_UNSIGNED_SHORT;
|
| 345 | + texture->colororder = 4;
|
| 346 | + texture->colorsizes[0] = 65535;
|
| 347 | + texture->colorsizes[1] = 65535;
|
| 348 | + texture->colorsizes[2] = 65535;
|
| 349 | + texture->colorsizes[3] = 65535;
|
| 350 | + texture->colorbits[0] = 16;
|
| 351 | + texture->colorbits[1] = 0;
|
| 352 | + texture->colorbits[2] = 0;
|
| 353 | + texture->colorbits[3] = 0;
|
| 354 | + break;
|
| 355 | + case 15: // 24-bit Z buffer
|
| 356 | + texture->internalformats[0] = GL_DEPTH_COMPONENT24;
|
| 357 | + texture->format = GL_DEPTH_COMPONENT;
|
| 358 | + texture->type = GL_UNSIGNED_INT;
|
| 359 | + texture->colororder = 4;
|
| 360 | + texture->colorsizes[0] = 16777215;
|
| 361 | + texture->colorsizes[1] = 16777215;
|
| 362 | + texture->colorsizes[2] = 16777215;
|
| 363 | + texture->colorsizes[3] = 16777215;
|
| 364 | + texture->colorbits[0] = 24;
|
| 365 | + texture->colorbits[1] = 0;
|
| 366 | + texture->colorbits[2] = 0;
|
| 367 | + texture->colorbits[3] = 0;
|
| 368 | + break;
|
| 369 | + case 16: // 32/24 bit Z buffer
|
| 370 | + texture->internalformats[0] = GL_DEPTH_COMPONENT24;
|
| 371 | + texture->format = GL_DEPTH_COMPONENT;
|
| 372 | + texture->type = GL_UNSIGNED_INT;
|
| 373 | + texture->colororder = 4;
|
| 374 | + texture->colorsizes[0] = 16777215;
|
| 375 | + texture->colorsizes[1] = 16777215;
|
| 376 | + texture->colorsizes[2] = 16777215;
|
| 377 | + texture->colorsizes[3] = 16777215;
|
| 378 | + texture->colorbits[0] = 24;
|
| 379 | + texture->colorbits[1] = 0;
|
| 380 | + texture->colorbits[2] = 0;
|
| 381 | + texture->colorbits[3] = 0;
|
| 382 | + break;
|
| 383 | + case 17: // 32-bit Z buffer
|
| 384 | + texture->internalformats[0] = GL_DEPTH_COMPONENT32;
|
| 385 | + texture->format = GL_DEPTH_COMPONENT;
|
| 386 | + texture->type = GL_UNSIGNED_INT;
|
| 387 | + texture->colororder = 4;
|
| 388 | + texture->colorsizes[0] = 4294967295;
|
| 389 | + texture->colorsizes[1] = 4294967295;
|
| 390 | + texture->colorsizes[2] = 4294967295;
|
| 391 | + texture->colorsizes[3] = 4294967295;
|
| 392 | + texture->colorbits[0] = 32;
|
| 393 | + texture->colorbits[1] = 0;
|
| 394 | + texture->colorbits[2] = 0;
|
| 395 | + texture->colorbits[3] = 0;
|
| 396 | + break;
|
| 397 | + case 18: // 32-bit Z/Stencil buffer, depth LSB
|
| 398 | + texture->internalformats[0] = GL_DEPTH24_STENCIL8;
|
| 399 | + texture->format = GL_DEPTH_STENCIL;
|
| 400 | + texture->type = GL_UNSIGNED_INT_24_8;
|
| 401 | + texture->colororder = 7;
|
| 402 | + texture->colorsizes[0] = 16777215;
|
| 403 | + texture->colorsizes[1] = 16777215;
|
| 404 | + texture->colorsizes[2] = 16777215;
|
| 405 | + texture->colorsizes[3] = 255;
|
| 406 | + texture->colorbits[0] = 24;
|
| 407 | + texture->colorbits[1] = 0;
|
| 408 | + texture->colorbits[2] = 0;
|
| 409 | + texture->colorbits[3] = 8;
|
| 410 | + break;
|
| 411 | + case 19: // 32-bit Z/Stencil buffer, depth MSB
|
| 412 | + texture->internalformats[0] = GL_DEPTH24_STENCIL8;
|
| 413 | + texture->format = GL_DEPTH_STENCIL;
|
| 414 | + texture->type = GL_UNSIGNED_INT_24_8;
|
| 415 | + texture->colororder = 7;
|
| 416 | + texture->colorsizes[0] = 16777215;
|
| 417 | + texture->colorsizes[1] = 16777215;
|
| 418 | + texture->colorsizes[2] = 16777215;
|
| 419 | + texture->colorsizes[3] = 255;
|
| 420 | + texture->colorbits[0] = 24;
|
| 421 | + texture->colorbits[1] = 0;
|
| 422 | + texture->colorbits[2] = 0;
|
| 423 | + texture->colorbits[3] = 8;
|
| 424 | + break;
|
| 425 | + }
|
| 426 | + texture->width = width;
|
| 427 | + texture->height = height;
|
| 428 | + glGenTextures(1,&texture->id);
|
| 429 | + glUtil_SetTexture(util,0,texture);
|
| 430 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->minfilter);
|
| 431 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->magfilter);
|
| 432 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->wraps);
|
| 433 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->wrapt);
|
| 434 | + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture->miplevel - 1);
|
| 435 | + x = texture->width;
|
| 436 | + y = texture->height;
|
| 437 | + for (i = 0; i < texture->miplevel; i++)
|
| 438 | + {
|
| 439 | + do
|
| 440 | + {
|
| 441 | + ClearError();
|
| 442 | + glTexImage2D(GL_TEXTURE_2D, i, texture->internalformats[0], x, y, 0, texture->format, texture->type, NULL);
|
| 443 | + ShrinkMip(&x, &y);
|
| 444 | + error = glGetError();
|
| 445 | + if (error != GL_NO_ERROR)
|
| 446 | + {
|
| 447 | + if (texture->internalformats[1] == 0)
|
| 448 | + {
|
| 449 | + FIXME("Failed to create texture, cannot find internal format");
|
| 450 | + break;
|
| 451 | + }
|
| 452 | + memmove(&texture->internalformats[0], &texture->internalformats[1], 7 * sizeof(GLint));
|
| 453 | + texture->internalformats[7] = 0;
|
| 454 | + }
|
| 455 | + else break;
|
| 456 | + } while (1);
|
| 457 | + }
|
| 458 | +}
|
| 459 | +
|
| 460 | +void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture)
|
| 461 | +{
|
| 462 | + glDeleteTextures(1,&texture->id);
|
| 463 | + texture->bordercolor = texture->format = texture->type = texture->width =
|
| 464 | + texture->height = texture->magfilter = texture->minfilter =
|
| 465 | + texture->miplevel = texture->wraps = texture->wrapt =
|
| 466 | + texture->id = 0;
|
| 467 | + texture->pboPack = texture->pboUnpack = NULL;
|
| 468 | + ZeroMemory(texture->internalformats, 8 * sizeof(GLint));
|
| 469 | +}
|
| 470 | +
|
| 471 | +void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc, glUtil *util)
|
| 472 | +{
|
| 473 | + GLenum error;
|
| 474 | + texture->width = width;
|
| 475 | + texture->height = height;
|
| 476 | + if (checkerror)
|
| 477 | + {
|
| 478 | + do
|
| 479 | + {
|
| 480 | + ClearError();
|
| 481 | + if (This->ext->GLEXT_EXT_direct_state_access)
|
| 482 | + {
|
| 483 | + if (realloc)This->ext->glTextureImage2DEXT(texture->id, GL_TEXTURE_2D, level, texture->internalformats[0],
|
| 484 | + width, height, 0, texture->format, texture->type, data);
|
| 485 | + else This->ext->glTextureSubImage2DEXT(texture->id, GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
| 486 | + }
|
| 487 | + else
|
| 488 | + {
|
| 489 | + glUtil_SetActiveTexture(util, 0);
|
| 490 | + glUtil_SetTexture(util, 0, texture);
|
| 491 | + if (realloc)glTexImage2D(GL_TEXTURE_2D, level, texture->internalformats[0], width, height, 0, texture->format, texture->type, data);
|
| 492 | + else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
| 493 | + }
|
| 494 | + error = glGetError();
|
| 495 | + if (error != GL_NO_ERROR)
|
| 496 | + {
|
| 497 | + if (texture->internalformats[1] == 0)
|
| 498 | + {
|
| 499 | + FIXME("Failed to update texture, cannot find internal format");
|
| 500 | + break;
|
| 501 | + }
|
| 502 | + memmove(&texture->internalformats[0], &texture->internalformats[1], 7 * sizeof(GLint));
|
| 503 | + texture->internalformats[7] = 0;
|
| 504 | + }
|
| 505 | + else break;
|
| 506 | + } while (1);
|
| 507 | + }
|
| 508 | + else
|
| 509 | + {
|
| 510 | + if (This->ext->GLEXT_EXT_direct_state_access)
|
| 511 | + {
|
| 512 | + if (realloc)This->ext->glTextureImage2DEXT(texture->id, GL_TEXTURE_2D, level, texture->internalformats[0],
|
| 513 | + width, height, 0, texture->format, texture->type, data);
|
| 514 | + else This->ext->glTextureSubImage2DEXT(texture->id, GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
| 515 | + }
|
| 516 | + else
|
| 517 | + {
|
| 518 | + glUtil_SetActiveTexture(util, 0);
|
| 519 | + glUtil_SetTexture(util, 0, texture);
|
| 520 | + if (realloc)glTexImage2D(GL_TEXTURE_2D, level, texture->internalformats[0], width, height, 0, texture->format, texture->type, data);
|
| 521 | + else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, texture->format, texture->type, data);
|
| 522 | + }
|
| 523 | + }
|
| 524 | +}
|
| 525 | +
|
| 526 | +void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data, glUtil *util)
|
| 527 | +{
|
| 528 | + if(This->ext->GLEXT_EXT_direct_state_access) This->ext->glGetTextureImageEXT(texture->id,GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
| 529 | + else
|
| 530 | + {
|
| 531 | + glUtil_SetActiveTexture(util, 0);
|
| 532 | + glUtil_SetTexture(util, 0,texture);
|
| 533 | + glGetTexImage(GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
| 534 | + }
|
| 535 | +}
|
| 536 | +
|
| 537 | +BOOL TextureManager_FixTexture(TextureManager *This, TEXTURE *texture, void *data, DWORD *dirty, GLint level, glUtil *util)
|
| 538 | +{
|
| 539 | + // data should be null to create uninitialized texture or be pointer to top-level
|
| 540 | + // buffer to retain texture data
|
| 541 | + TEXTURE newtexture;
|
| 542 | + GLenum error;
|
| 543 | + memcpy(&newtexture, texture, sizeof(TEXTURE));
|
| 544 | + if (texture->internalformats[1] == 0) return FALSE;
|
| 545 | + glGenTextures(1, &newtexture.id);
|
| 546 | + glUtil_SetActiveTexture(util, 0);
|
| 547 | + if (data)
|
| 548 | + {
|
| 549 | + glUtil_SetTexture(util, 0, texture);
|
| 550 | + glGetTexImage(GL_TEXTURE_2D, level, texture->format, texture->type, data);
|
| 551 | + if (dirty) *dirty |= 2;
|
| 552 | + }
|
| 553 | + glUtil_SetTexture(util, 0, &newtexture);
|
| 554 | + do
|
| 555 | + {
|
| 556 | + memmove(&newtexture.internalformats[0], &newtexture.internalformats[1], 7 * sizeof(GLint));
|
| 557 | + newtexture.internalformats[7] = 0;
|
| 558 | + ClearError();
|
| 559 | + glTexImage2D(GL_TEXTURE_2D, level, newtexture.internalformats[0], newtexture.width, newtexture.height,
|
| 560 | + 0, newtexture.format, newtexture.type, data);
|
| 561 | + error = glGetError();
|
| 562 | + if (error != GL_NO_ERROR)
|
| 563 | + {
|
| 564 | + if (newtexture.internalformats[1] == 0)
|
| 565 | + {
|
| 566 | + FIXME("Failed to repair texture, cannot find internal format");
|
| 567 | + break;
|
| 568 | + }
|
| 569 | + }
|
| 570 | + else break;
|
| 571 | + } while (1);
|
| 572 | + TextureManager__DeleteTexture(This, texture);
|
| 573 | + memcpy(texture, &newtexture, sizeof(TEXTURE));
|
| 574 | + return TRUE;
|
| 575 | +}
|
| 576 | +
|
| 577 | +} |
\ No newline at end of file |
Index: ddraw/TextureManager.h |
— | — | @@ -61,27 +61,25 @@ |
62 | 62 | extern const DDPIXELFORMAT texformats[];
|
63 | 63 | extern int numtexformats;
|
64 | 64 |
|
| 65 | +struct glUtil;
|
| 66 | +
|
65 | 67 | typedef struct TextureManager
|
66 | 68 | {
|
67 | 69 | glExtensions *ext;
|
68 | | - GLint texlevel;
|
69 | | - GLuint textures[16];
|
70 | 70 | } TextureManager;
|
71 | 71 |
|
72 | 72 | DWORD CalculateMipLevels(DWORD width, DWORD height);
|
73 | 73 |
|
74 | 74 | TextureManager *TextureManager_Create(glExtensions *glext);
|
75 | | -void TextureManager_SetActiveTexture(TextureManager *This, int level);
|
76 | | -void TextureManager_SetTexture(TextureManager *This, unsigned int level, TEXTURE *texture);
|
77 | | -void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height);
|
| 75 | +void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height, glUtil *util);
|
78 | 76 | void TextureManager__DeleteTexture(TextureManager *This, TEXTURE *texture);
|
79 | | -void TextureManager__UploadTexture(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc);
|
80 | | -void TextureManager__DownloadTexture(TextureManager *This, TEXTURE *texture, int level, void *data);
|
81 | | -void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height);
|
| 77 | +void TextureManager__UploadTexture(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc, glUtil *util);
|
| 78 | +void TextureManager__DownloadTexture(TextureManager *This, TEXTURE *texture, int level, void *data, glUtil *util);
|
| 79 | +void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height, glUtil *util);
|
82 | 80 | void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture);
|
83 | | -void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc);
|
84 | | -void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data);
|
85 | | -BOOL TextureManager_FixTexture(TextureManager *This, TEXTURE *texture, void *data, DWORD *dirty, GLint level);
|
| 81 | +void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height, BOOL checkerror, BOOL realloc, glUtil *util);
|
| 82 | +void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data, glUtil *util);
|
| 83 | +BOOL TextureManager_FixTexture(TextureManager *This, TEXTURE *texture, void *data, DWORD *dirty, GLint level, glUtil *util);
|
86 | 84 |
|
87 | 85 | #ifdef __cplusplus
|
88 | 86 | }
|
Index: ddraw/ddraw.vcxproj |
— | — | @@ -419,7 +419,7 @@ |
420 | 420 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
421 | 421 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
|
422 | 422 | </ClCompile>
|
423 | | - <ClCompile Include="TextureManager.c">
|
| 423 | + <ClCompile Include="TextureManager.cpp">
|
424 | 424 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
425 | 425 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
426 | 426 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
Index: ddraw/ddraw.vcxproj.filters |
— | — | @@ -220,9 +220,6 @@ |
221 | 221 | <ClCompile Include="glDirectDrawPalette.c">
|
222 | 222 | <Filter>Source Files</Filter>
|
223 | 223 | </ClCompile>
|
224 | | - <ClCompile Include="TextureManager.c">
|
225 | | - <Filter>Source Files</Filter>
|
226 | | - </ClCompile>
|
227 | 224 | <ClCompile Include="util.c">
|
228 | 225 | <Filter>Source Files</Filter>
|
229 | 226 | </ClCompile>
|
— | — | @@ -253,6 +250,9 @@ |
254 | 251 | <ClCompile Include="BufferObject.cpp">
|
255 | 252 | <Filter>Source Files</Filter>
|
256 | 253 | </ClCompile>
|
| 254 | + <ClCompile Include="TextureManager.cpp">
|
| 255 | + <Filter>Source Files</Filter>
|
| 256 | + </ClCompile>
|
257 | 257 | </ItemGroup>
|
258 | 258 | <ItemGroup>
|
259 | 259 | <ResourceCompile Include="ddraw.rc">
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -1702,7 +1702,7 @@ |
1703 | 1703 | if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
|
1704 | 1704 | TRACE_RET(HRESULT,23,Unlock((LPRECT)lpSurfaceData));
|
1705 | 1705 | }
|
1706 | | -void glDirectDrawSurface7::SetFilter(int level, GLint mag, GLint min, glExtensions *ext, glUtil *util, TextureManager *texman)
|
| 1706 | +void glDirectDrawSurface7::SetFilter(int level, GLint mag, GLint min, glExtensions *ext, glUtil *util)
|
1707 | 1707 | {
|
1708 | 1708 | TRACE_ENTER(4,14,this,11,level,11,mag,11,min);
|
1709 | 1709 | switch(dxglcfg.texfilter)
|
— | — | @@ -1751,7 +1751,7 @@ |
1752 | 1752 | }
|
1753 | 1753 | else
|
1754 | 1754 | {
|
1755 | | - TextureManager_SetTexture(texman,level,texture);
|
| 1755 | + glUtil_SetTexture(util,level,texture);
|
1756 | 1756 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
|
1757 | 1757 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
|
1758 | 1758 | }
|
Index: ddraw/glDirectDrawSurface.h |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | ULONG WINAPI ReleaseGamma();
|
112 | 112 | ULONG WINAPI AddRefColor();
|
113 | 113 | ULONG WINAPI ReleaseColor();
|
114 | | - void SetFilter(int level, GLint mag, GLint min, glExtensions *ext, glUtil *util, TextureManager *texman);
|
| 114 | + void SetFilter(int level, GLint mag, GLint min, glExtensions *ext, glUtil *util);
|
115 | 115 | TEXTURE *GetTexture(){
|
116 | 116 | return texture;
|
117 | 117 | }
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | if(bpp == 15) bpp = 16;
|
110 | 110 | if((x == bigx && y == bigy) || !bigbuffer)
|
111 | 111 | {
|
112 | | - TextureManager__UploadTexture(This->texman, texture, miplevel, buffer, x, y, FALSE, FALSE);
|
| 112 | + TextureManager__UploadTexture(This->texman, texture, miplevel, buffer, x, y, FALSE, FALSE, This->util);
|
113 | 113 | }
|
114 | 114 | else
|
115 | 115 | {
|
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | break;
|
130 | 130 | break;
|
131 | 131 | }
|
132 | | - TextureManager__UploadTexture(This->texman, texture, miplevel, bigbuffer, bigx, bigy, FALSE, FALSE);
|
| 132 | + TextureManager__UploadTexture(This->texman, texture, miplevel, bigbuffer, bigx, bigy, FALSE, FALSE, This->util);
|
133 | 133 | }
|
134 | 134 | }
|
135 | 135 |
|
— | — | @@ -161,11 +161,11 @@ |
162 | 162 | {
|
163 | 163 | if((bigx == x && bigy == y) || !bigbuffer)
|
164 | 164 | {
|
165 | | - TextureManager__DownloadTexture(This->texman,texture,miplevel,buffer);
|
| 165 | + TextureManager__DownloadTexture(This->texman,texture,miplevel,buffer,This->util);
|
166 | 166 | }
|
167 | 167 | else
|
168 | 168 | {
|
169 | | - TextureManager__DownloadTexture(This->texman,texture,miplevel,bigbuffer);
|
| 169 | + TextureManager__DownloadTexture(This->texman,texture,miplevel,bigbuffer,This->util);
|
170 | 170 | switch(bpp)
|
171 | 171 | {
|
172 | 172 | case 8:
|
— | — | @@ -1123,7 +1123,7 @@ |
1124 | 1124 | glEnable(GL_CULL_FACE);
|
1125 | 1125 | SwapBuffers(This->hDC);
|
1126 | 1126 | This->texman = TextureManager_Create(This->ext);
|
1127 | | - TextureManager_SetActiveTexture(This->texman,0);
|
| 1127 | + glUtil_SetActiveTexture(This->util,0);
|
1128 | 1128 | glRenderer__SetFogColor(This,0);
|
1129 | 1129 | glRenderer__SetFogStart(This,0);
|
1130 | 1130 | glRenderer__SetFogEnd(This,1);
|
— | — | @@ -1393,7 +1393,7 @@ |
1394 | 1394 | {
|
1395 | 1395 | if (glUtil_SetFBOSurface(This->util, dest) == GL_FRAMEBUFFER_COMPLETE) break;
|
1396 | 1396 | if (!dest->texture->internalformats[1]) break;
|
1397 | | - TextureManager_FixTexture(This->texman, dest->texture, (dest->bigbuffer ? dest->bigbuffer : dest->buffer), &dest->dirty, dest->miplevel);
|
| 1397 | + TextureManager_FixTexture(This->texman, dest->texture, (dest->bigbuffer ? dest->bigbuffer : dest->buffer), &dest->dirty, dest->miplevel, This->util);
|
1398 | 1398 | glUtil_SetFBO(This->util, NULL);
|
1399 | 1399 | dest->fbo.fbcolor = NULL;
|
1400 | 1400 | dest->fbo.fbz = NULL;
|
— | — | @@ -1461,19 +1461,19 @@ |
1462 | 1462 | }
|
1463 | 1463 | if (usedest && (shader->shader.uniforms[2] != -1))
|
1464 | 1464 | {
|
1465 | | - TextureManager_SetTexture(This->texman, 1, This->backbuffer);
|
| 1465 | + glUtil_SetTexture(This->util, 1, This->backbuffer);
|
1466 | 1466 | This->ext->glUniform1i(shader->shader.uniforms[2], 1);
|
1467 | 1467 | }
|
1468 | 1468 | if (usepattern && (shader->shader.uniforms[3] != -1))
|
1469 | 1469 | {
|
1470 | 1470 | glDirectDrawSurface7 *pattern = (glDirectDrawSurface7*)lpDDBltFx->lpDDSPattern;
|
1471 | | - TextureManager_SetTexture(This->texman, 2, pattern->texture);
|
| 1471 | + glUtil_SetTexture(This->util, 2, pattern->texture);
|
1472 | 1472 | This->ext->glUniform1i(shader->shader.uniforms[3], 2);
|
1473 | 1473 | This->ext->glUniform2i(shader->shader.uniforms[9], pattern->texture->width, pattern->texture->height);
|
1474 | 1474 | }
|
1475 | 1475 | if (dwFlags & 0x10000000) // Use clipper
|
1476 | 1476 | {
|
1477 | | - TextureManager_SetTexture(This->texman, 3, dest->stencil);
|
| 1477 | + glUtil_SetTexture(This->util, 3, dest->stencil);
|
1478 | 1478 | This->ext->glUniform1i(shader->shader.uniforms[4],3);
|
1479 | 1479 | glUtil_EnableArray(This->util, shader->shader.attribs[5], TRUE);
|
1480 | 1480 | This->ext->glVertexAttribPointer(shader->shader.attribs[5], 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &This->bltvertices[0].stencils);
|
— | — | @@ -1480,15 +1480,15 @@ |
1481 | 1481 | }
|
1482 | 1482 | if(src)
|
1483 | 1483 | {
|
1484 | | - TextureManager_SetTexture(This->texman,0,src->GetTexture());
|
| 1484 | + glUtil_SetTexture(This->util,0,src->GetTexture());
|
1485 | 1485 | if(This->ext->GLEXT_ARB_sampler_objects)
|
1486 | 1486 | {
|
1487 | 1487 | if((dxglcfg.scalingfilter == 0) || (This->ddInterface->GetBPP() == 8))
|
1488 | | - src->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
|
1489 | | - else src->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util,This->texman);
|
| 1488 | + src->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util);
|
| 1489 | + else src->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util);
|
1490 | 1490 | }
|
1491 | 1491 | }
|
1492 | | - else TextureManager_SetTexture(This->texman,0,NULL);
|
| 1492 | + else glUtil_SetTexture(This->util,0,NULL);
|
1493 | 1493 | This->ext->glUniform4f(shader->shader.uniforms[0],0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
|
1494 | 1494 | if(src) This->ext->glUniform4i(shader->shader.uniforms[10], src->texture->colorsizes[0], src->texture->colorsizes[1],
|
1495 | 1495 | src->texture->colorsizes[2], src->texture->colorsizes[3]);
|
— | — | @@ -1522,13 +1522,13 @@ |
1523 | 1523 |
|
1524 | 1524 | void glRenderer__MakeTexture(glRenderer *This, TEXTURE *texture, DWORD width, DWORD height)
|
1525 | 1525 | {
|
1526 | | - TextureManager__CreateTexture(This->texman,texture,width,height);
|
| 1526 | + TextureManager__CreateTexture(This->texman,texture,width,height,This->util);
|
1527 | 1527 | }
|
1528 | 1528 |
|
1529 | 1529 | void glRenderer__DrawBackbuffer(glRenderer *This, TEXTURE **texture, int x, int y, int progtype)
|
1530 | 1530 | {
|
1531 | 1531 | GLfloat view[4];
|
1532 | | - TextureManager_SetActiveTexture(This->texman,0);
|
| 1532 | + glUtil_SetActiveTexture(This->util,0);
|
1533 | 1533 | if(!This->backbuffer)
|
1534 | 1534 | {
|
1535 | 1535 | This->backbuffer = (TEXTURE*)malloc(sizeof(TEXTURE));
|
— | — | @@ -1540,13 +1540,13 @@ |
1541 | 1541 | This->backbuffer->pixelformat.dwGBitMask = 0xFF00;
|
1542 | 1542 | This->backbuffer->pixelformat.dwRBitMask = 0xFF0000;
|
1543 | 1543 | This->backbuffer->pixelformat.dwRGBBitCount = 32;
|
1544 | | - TextureManager__CreateTexture(This->texman,This->backbuffer,x,y);
|
| 1544 | + TextureManager__CreateTexture(This->texman,This->backbuffer,x,y,This->util);
|
1545 | 1545 | This->backx = x;
|
1546 | 1546 | This->backy = y;
|
1547 | 1547 | }
|
1548 | 1548 | if((This->backx != x) || (This->backy != y))
|
1549 | 1549 | {
|
1550 | | - TextureManager__UploadTexture(This->texman,This->backbuffer,0,NULL,x,y, FALSE, TRUE);
|
| 1550 | + TextureManager__UploadTexture(This->texman, This->backbuffer, 0, NULL, x, y, FALSE, TRUE, This->util);
|
1551 | 1551 | This->backx = x;
|
1552 | 1552 | This->backy = y;
|
1553 | 1553 | }
|
— | — | @@ -1556,9 +1556,9 @@ |
1557 | 1557 | view[3] = (GLfloat)y;
|
1558 | 1558 | glUtil_SetViewport(This->util,0,0,x,y);
|
1559 | 1559 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
1560 | | - TextureManager_SetTexture(This->texman,0,*texture);
|
| 1560 | + glUtil_SetTexture(This->util,0,*texture);
|
1561 | 1561 | *texture = This->backbuffer;
|
1562 | | - if(This->ext->GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util,This->texman);
|
| 1562 | + if(This->ext->GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util);
|
1563 | 1563 | This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
|
1564 | 1564 | This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
|
1565 | 1565 | This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
|
— | — | @@ -1580,7 +1580,7 @@ |
1581 | 1581 | GLfloat view[4];
|
1582 | 1582 | int x = srcrect.right - srcrect.left;
|
1583 | 1583 | int y = srcrect.bottom - srcrect.top;
|
1584 | | - TextureManager_SetActiveTexture(This->texman, 0);
|
| 1584 | + glUtil_SetActiveTexture(This->util, 0);
|
1585 | 1585 | if (!This->backbuffer)
|
1586 | 1586 | {
|
1587 | 1587 | This->backbuffer = (TEXTURE*)malloc(sizeof(TEXTURE));
|
— | — | @@ -1592,7 +1592,7 @@ |
1593 | 1593 | This->backbuffer->pixelformat.dwGBitMask = 0xFF00;
|
1594 | 1594 | This->backbuffer->pixelformat.dwRBitMask = 0xFF0000;
|
1595 | 1595 | This->backbuffer->pixelformat.dwRGBBitCount = 32;
|
1596 | | - TextureManager__CreateTexture(This->texman, This->backbuffer, x, y);
|
| 1596 | + TextureManager__CreateTexture(This->texman, This->backbuffer, x, y, This->util);
|
1597 | 1597 | This->backx = x;
|
1598 | 1598 | This->backy = y;
|
1599 | 1599 | }
|
— | — | @@ -1600,7 +1600,7 @@ |
1601 | 1601 | {
|
1602 | 1602 | if (This->backx > x) x = This->backx;
|
1603 | 1603 | if (This->backx > y) y = This->backx;
|
1604 | | - TextureManager__UploadTexture(This->texman, This->backbuffer, 0, NULL, x, y, FALSE, TRUE);
|
| 1604 | + TextureManager__UploadTexture(This->texman, This->backbuffer, 0, NULL, x, y, FALSE, TRUE, This->util);
|
1605 | 1605 | This->backx = x;
|
1606 | 1606 | This->backy = y;
|
1607 | 1607 | }
|
— | — | @@ -1612,7 +1612,7 @@ |
1613 | 1613 | glUtil_SetScissor(This->util, TRUE, 0, 0, This->backx, This->backy);
|
1614 | 1614 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
1615 | 1615 | glUtil_SetScissor(This->util, FALSE, 0, 0, 0, 0);
|
1616 | | - TextureManager_SetTexture(This->texman, 0, texture);
|
| 1616 | + glUtil_SetTexture(This->util, 0, texture);
|
1617 | 1617 | This->ext->glUniform4f(This->shaders->shaders[progtype].view, view[0], view[1], view[2], view[3]);
|
1618 | 1618 | This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)texture->width;
|
1619 | 1619 | This->bltvertices[0].s = This->bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)texture->width;
|
— | — | @@ -1697,23 +1697,23 @@ |
1698 | 1698 | {
|
1699 | 1699 | ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,0);
|
1700 | 1700 | progtype = PROG_PAL256;
|
1701 | | - TextureManager__UploadTexture(This->texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1,FALSE,FALSE);
|
| 1701 | + TextureManager__UploadTexture(This->texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1,FALSE,FALSE,This->util);
|
1702 | 1702 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
1703 | 1703 | This->ext->glUniform1i(This->shaders->shaders[progtype].pal,1);
|
1704 | | - TextureManager_SetTexture(This->texman,0,texture);
|
1705 | | - TextureManager_SetTexture(This->texman,1,paltex);
|
| 1704 | + glUtil_SetTexture(This->util,0,texture);
|
| 1705 | + glUtil_SetTexture(This->util,1,paltex);
|
1706 | 1706 | if(dxglcfg.scalingfilter)
|
1707 | 1707 | {
|
1708 | 1708 | glRenderer__DrawBackbuffer(This,&texture,dest->fakex,dest->fakey,progtype);
|
1709 | 1709 | ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
|
1710 | 1710 | progtype = PROG_TEXTURE;
|
1711 | | - TextureManager_SetTexture(This->texman,0,texture);
|
| 1711 | + glUtil_SetTexture(This->util,0,texture);
|
1712 | 1712 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
1713 | 1713 | }
|
1714 | 1714 | if(This->ext->GLEXT_ARB_sampler_objects)
|
1715 | 1715 | {
|
1716 | | - ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
|
1717 | | - ((glDirectDrawSurface7*)NULL)->SetFilter(1,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
|
| 1716 | + ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util);
|
| 1717 | + ((glDirectDrawSurface7*)NULL)->SetFilter(1,GL_NEAREST,GL_NEAREST,This->ext,This->util);
|
1718 | 1718 | }
|
1719 | 1719 | }
|
1720 | 1720 | else
|
— | — | @@ -1720,13 +1720,13 @@ |
1721 | 1721 | {
|
1722 | 1722 | ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
|
1723 | 1723 | progtype = PROG_TEXTURE;
|
1724 | | - TextureManager_SetTexture(This->texman,0,texture);
|
| 1724 | + glUtil_SetTexture(This->util,0,texture);
|
1725 | 1725 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
1726 | 1726 | }
|
1727 | 1727 | if(dxglcfg.scalingfilter && This->ext->GLEXT_ARB_sampler_objects)
|
1728 | | - ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util,This->texman);
|
| 1728 | + ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util);
|
1729 | 1729 | else if(This->ext->GLEXT_ARB_sampler_objects)
|
1730 | | - ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
|
| 1730 | + ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util);
|
1731 | 1731 | glUtil_SetViewport(This->util,viewport[0],viewport[1],viewport[2],viewport[3]);
|
1732 | 1732 | This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
|
1733 | 1733 | if(This->ddInterface->GetFullscreen())
|
— | — | @@ -1928,7 +1928,7 @@ |
1929 | 1929 | {
|
1930 | 1930 | if (glUtil_SetFBOSurface(This->util, target) == GL_FRAMEBUFFER_COMPLETE) break;
|
1931 | 1931 | if (!target->texture->internalformats[1]) break;
|
1932 | | - TextureManager_FixTexture(This->texman, target->texture, (target->bigbuffer ? target->bigbuffer : target->buffer), &target->dirty, target->miplevel);
|
| 1932 | + TextureManager_FixTexture(This->texman, target->texture, (target->bigbuffer ? target->bigbuffer : target->buffer), &target->dirty, target->miplevel,This->util);
|
1933 | 1933 | glUtil_SetFBO(This->util, NULL);
|
1934 | 1934 | target->fbo.fbcolor = NULL;
|
1935 | 1935 | target->fbo.fbz = NULL;
|
— | — | @@ -2303,12 +2303,12 @@ |
2304 | 2304 | This->texstages[i].texture->dirty &= ~1;
|
2305 | 2305 | }
|
2306 | 2306 | if(This->texstages[i].texture)
|
2307 | | - This->texstages[i].texture->SetFilter(i,This->texstages[i].glmagfilter,This->texstages[i].glminfilter,This->ext,This->util,This->texman);
|
2308 | | - TextureManager_SetTexture(This->texman,i,This->texstages[i].texture->texture);
|
2309 | | - glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu, This->texman);
|
2310 | | - glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv, This->texman);
|
| 2307 | + This->texstages[i].texture->SetFilter(i,This->texstages[i].glmagfilter,This->texstages[i].glminfilter,This->ext,This->util);
|
| 2308 | + glUtil_SetTexture(This->util,i,This->texstages[i].texture->texture);
|
| 2309 | + glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu);
|
| 2310 | + glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv);
|
2311 | 2311 | }
|
2312 | | - TextureManager_SetTexture(This->texman,i,0);
|
| 2312 | + glUtil_SetTexture(This->util,i,0);
|
2313 | 2313 | This->ext->glUniform1i(prog->uniforms[128+i],i);
|
2314 | 2314 | if(This->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && This->texstages[i].texture && (prog->uniforms[142+i] != -1))
|
2315 | 2315 | {
|
— | — | @@ -2335,7 +2335,7 @@ |
2336 | 2336 | if (glUtil_SetFBOSurface(This->util, device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
|
2337 | 2337 | if (!device->glDDS7->texture->internalformats[1]) break;
|
2338 | 2338 | TextureManager_FixTexture(This->texman, device->glDDS7->texture,
|
2339 | | - (device->glDDS7->bigbuffer ? device->glDDS7->bigbuffer : device->glDDS7->buffer), &device->glDDS7->dirty, device->glDDS7->miplevel);
|
| 2339 | + (device->glDDS7->bigbuffer ? device->glDDS7->bigbuffer : device->glDDS7->buffer), &device->glDDS7->dirty, device->glDDS7->miplevel,This->util);
|
2340 | 2340 | glUtil_SetFBO(This->util, NULL);
|
2341 | 2341 | device->glDDS7->fbo.fbcolor = NULL;
|
2342 | 2342 | device->glDDS7->fbo.fbz = NULL;
|
— | — | @@ -2386,12 +2386,12 @@ |
2387 | 2387 | surface->stencil->pixelformat.dwRBitMask = 0xF00;
|
2388 | 2388 | surface->stencil->pixelformat.dwZBitMask = 0xF000;
|
2389 | 2389 | surface->stencil->pixelformat.dwRGBBitCount = 16;
|
2390 | | - TextureManager__CreateTexture(This->texman, surface->stencil, surface->ddsd.dwWidth, surface->ddsd.dwHeight);
|
| 2390 | + TextureManager__CreateTexture(This->texman, surface->stencil, surface->ddsd.dwWidth, surface->ddsd.dwHeight, This->util);
|
2391 | 2391 | }
|
2392 | 2392 | if ((surface->ddsd.dwWidth != surface->stencil->width) ||
|
2393 | 2393 | (surface->ddsd.dwHeight != surface->stencil->height))
|
2394 | 2394 | TextureManager__UploadTexture(This->texman, surface->stencil, 0, NULL,
|
2395 | | - surface->ddsd.dwWidth, surface->ddsd.dwHeight, FALSE, TRUE);
|
| 2395 | + surface->ddsd.dwWidth, surface->ddsd.dwHeight, FALSE, TRUE, This->util);
|
2396 | 2396 | glUtil_SetFBOTextures(This->util, &surface->stencilfbo, surface->stencil, 0, FALSE);
|
2397 | 2397 | view[0] = view[2] = 0;
|
2398 | 2398 | view[1] = (GLfloat)surface->ddsd.dwWidth;
|
— | — | @@ -2433,7 +2433,7 @@ |
2434 | 2434 | if (!dest->attachparent->texture->internalformats[1]) break;
|
2435 | 2435 | TextureManager_FixTexture(This->texman, dest->attachparent->texture,
|
2436 | 2436 | (dest->attachparent->bigbuffer ? dest->attachparent->bigbuffer : dest->attachparent->buffer),
|
2437 | | - &dest->attachparent->dirty, dest->attachparent->miplevel);
|
| 2437 | + &dest->attachparent->dirty, dest->attachparent->miplevel, This->util);
|
2438 | 2438 | glUtil_SetFBO(This->util, NULL);
|
2439 | 2439 | dest->attachparent->fbo.fbcolor = NULL;
|
2440 | 2440 | dest->attachparent->fbo.fbz = NULL;
|
— | — | @@ -2453,12 +2453,12 @@ |
2454 | 2454 | dest->dummycolor->pixelformat.dwRBitMask = 0xF00;
|
2455 | 2455 | dest->dummycolor->pixelformat.dwZBitMask = 0xF000;
|
2456 | 2456 | dest->dummycolor->pixelformat.dwRGBBitCount = 16;
|
2457 | | - TextureManager__CreateTexture(This->texman, dest->dummycolor, dest->ddsd.dwWidth, dest->ddsd.dwHeight);
|
| 2457 | + TextureManager__CreateTexture(This->texman, dest->dummycolor, dest->ddsd.dwWidth, dest->ddsd.dwHeight, This->util);
|
2458 | 2458 | }
|
2459 | 2459 | if ((dest->ddsd.dwWidth != dest->dummycolor->width) ||
|
2460 | 2460 | (dest->ddsd.dwHeight != dest->dummycolor->height))
|
2461 | 2461 | TextureManager__UploadTexture(This->texman, dest->dummycolor, 0, NULL,
|
2462 | | - dest->ddsd.dwWidth, dest->ddsd.dwHeight, FALSE, TRUE);
|
| 2462 | + dest->ddsd.dwWidth, dest->ddsd.dwHeight, FALSE, TRUE, This->util);
|
2463 | 2463 | glUtil_SetFBOTextures(This->util, &dest->zfbo, dest->dummycolor, dest->texture, FALSE);
|
2464 | 2464 | }
|
2465 | 2465 | glUtil_SetViewport(This->util, 0, 0, dest->ddsd.dwWidth, dest->ddsd.dwHeight);
|
Index: ddraw/glUtil.cpp |
— | — | @@ -85,7 +85,8 @@ |
86 | 86 | glext->glSamplerParameteri(util->samplers[i].id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
87 | 87 | }
|
88 | 88 | }
|
89 | | -
|
| 89 | + util->texlevel = 0;
|
| 90 | + ZeroMemory(util->textures, 16 * sizeof(GLuint));
|
90 | 91 | }
|
91 | 92 |
|
92 | 93 | void glUtil_AddRef(glUtil *This)
|
— | — | @@ -254,7 +255,7 @@ |
255 | 256 | else return fbo->status;
|
256 | 257 | }
|
257 | 258 |
|
258 | | -void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address, TextureManager *texman)
|
| 259 | +void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address)
|
259 | 260 | {
|
260 | 261 | if(level == -1)
|
261 | 262 | {
|
— | — | @@ -308,7 +309,7 @@ |
309 | 310 | }
|
310 | 311 | else
|
311 | 312 | {
|
312 | | - TextureManager_SetActiveTexture(texman,level);
|
| 313 | + glUtil_SetActiveTexture(This,level);
|
313 | 314 | if(coord) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapmode);
|
314 | 315 | else glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrapmode);
|
315 | 316 | }
|
— | — | @@ -616,4 +617,27 @@ |
617 | 618 | This->LastBoundBuffer = NULL;
|
618 | 619 | }
|
619 | 620 |
|
| 621 | +void glUtil_SetActiveTexture(glUtil *This, int level)
|
| 622 | +{
|
| 623 | + if (level != This->texlevel)
|
| 624 | + {
|
| 625 | + This->texlevel = level;
|
| 626 | + This->ext->glActiveTexture(GL_TEXTURE0 + level);
|
| 627 | + }
|
| 628 | +}
|
| 629 | +
|
| 630 | +
|
| 631 | +void glUtil_SetTexture(glUtil *This, unsigned int level, TEXTURE *texture)
|
| 632 | +{
|
| 633 | + GLuint texname;
|
| 634 | + if (level >= 16) return;
|
| 635 | + if (!texture) texname = 0;
|
| 636 | + else texname = texture->id;
|
| 637 | + if (texname != This->textures[level])
|
| 638 | + {
|
| 639 | + glUtil_SetActiveTexture(This, level);
|
| 640 | + glBindTexture(GL_TEXTURE_2D, texname);
|
| 641 | + }
|
| 642 | +}
|
| 643 | +
|
620 | 644 | }; |
\ No newline at end of file |
Index: ddraw/glUtil.h |
— | — | @@ -104,6 +104,8 @@ |
105 | 105 | D3DSHADEMODE shademode;
|
106 | 106 | BufferObject *LastBoundBuffer;
|
107 | 107 | SAMPLER samplers[8];
|
| 108 | + GLint texlevel;
|
| 109 | + GLuint textures[16];
|
108 | 110 | } glUtil;
|
109 | 111 |
|
110 | 112 | void glUtil_Create(glExtensions *glext, glUtil **out);
|
— | — | @@ -112,7 +114,7 @@ |
113 | 115 | void glUtil_InitFBO(glUtil *This, FBO *fbo);
|
114 | 116 | void glUtil_DeleteFBO(glUtil *This, FBO *fbo);
|
115 | 117 | void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, TEXTURE *color, TEXTURE *z, BOOL stencil);
|
116 | | -void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address, TextureManager *texman);
|
| 118 | +void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address);
|
117 | 119 | GLenum glUtil_SetFBOSurface(glUtil *This, glDirectDrawSurface7 *surface);
|
118 | 120 | GLenum glUtil_SetFBO(glUtil *This, FBO *fbo);
|
119 | 121 | GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, TEXTURE *color, TEXTURE *z, BOOL stencil);
|
— | — | @@ -137,6 +139,8 @@ |
138 | 140 | void glUtil_SetShadeMode(glUtil *This, D3DSHADEMODE mode);
|
139 | 141 | void glUtil_BindBuffer(glUtil *This, BufferObject *buffer, GLenum target);
|
140 | 142 | void glUtil_UndoBindBuffer(glUtil *This, GLenum target);
|
| 143 | +void glUtil_SetActiveTexture(glUtil *This, int level);
|
| 144 | +void glUtil_SetTexture(glUtil *This, unsigned int level, TEXTURE *texture);
|
141 | 145 |
|
142 | 146 | #ifdef __cplusplus
|
143 | 147 | }
|