Add system message warning if a BIOS file could not be found
[pcsx_rearmed.git] / plugins / gpu-gles / gpuTexture.c
CommitLineData
ce879073 1/***************************************************************************\r
2 texture.c - description\r
3 -------------------\r
4 begin : Sun Mar 08 2009\r
5 copyright : (C) 1999-2009 by Pete Bernert\r
6 web : www.pbernert.com \r
7 ***************************************************************************/\r
8\r
9/***************************************************************************\r
10 * *\r
11 * This program is free software; you can redistribute it and/or modify *\r
12 * it under the terms of the GNU General Public License as published by *\r
13 * the Free Software Foundation; either version 2 of the License, or *\r
14 * (at your option) any later version. See also the license.txt file for *\r
15 * additional informations. *\r
16 * *\r
17 ***************************************************************************/\r
18\r
19//*************************************************************************// \r
20// History of changes:\r
21//\r
22// 2009/03/08 - Pete \r
23// - generic cleanup for the Peops release\r
24//\r
25//*************************************************************************// \r
26\r
27\r
28////////////////////////////////////////////////////////////////////////////////////\r
29// Texture related functions are here !\r
30//\r
31// The texture handling is heart and soul of this gpu. The plugin was developed\r
32// 1999, by this time no shaders were available. Since the psx gpu is making\r
33// heavy use of CLUT (="color lookup tables", aka palettized textures), it was \r
34// an interesting task to get those emulated at good speed on NV TNT cards \r
35// (which was my major goal when I created the first "gpuPeteTNT"). Later cards \r
36// (Geforce256) supported texture palettes by an OGL extension, but at some point\r
37// this support was dropped again by gfx card vendors.\r
38// Well, at least there is a certain advatage, if no texture palettes extension can\r
39// be used: it is possible to modify the textures in any way, allowing "hi-res" \r
40// textures and other tweaks.\r
41//\r
42// My main texture caching is kinda complex: the plugin is allocating "n" 256x256 textures,\r
43// and it places small psx texture parts inside them. The plugin keeps track what \r
44// part (with what palette) it had placed in which texture, so it can re-use this \r
45// part again. The more ogl textures it can use, the better (of course the managing/\r
46// searching will be slower, but everything is faster than uploading textures again\r
47// and again to a gfx card). My first card (TNT1) had 16 MB Vram, and it worked\r
48// well with many games, but I recommend nowadays 64 MB Vram to get a good speed.\r
49//\r
50// Sadly, there is also a second kind of texture cache needed, for "psx texture windows".\r
51// Those are "repeated" textures, so a psx "texture window" needs to be put in \r
52// a whole texture to use the GL_TEXTURE_WRAP_ features. This cache can get full very\r
53// fast in games which are having an heavy "texture window" usage, like RRT4. As an \r
54// alternative, this plugin can use the OGL "palette" extension on texture windows, \r
55// if available. Nowadays also a fragment shader can easily be used to emulate\r
56// texture wrapping in a texture atlas, so the main cache could hold the texture\r
57// windows as well (that's what I am doing in the OGL2 plugin). But currently the\r
58// OGL1 plugin is a "shader-free" zone, so heavy "texture window" games will cause\r
59// much texture uploads.\r
60//\r
61// Some final advice: take care if you change things in here. I've removed my ASM\r
62// handlers (they didn't cause much speed gain anyway) for readability/portability,\r
63// but still the functions/data structures used here are easy to mess up. I guess it\r
64// can be a pain in the ass to port the plugin to another byte order :)\r
65//\r
66////////////////////////////////////////////////////////////////////////////////////\r
67 \r
68#define _IN_TEXTURE\r
69\r
ce879073 70#include "gpuStdafx.h"\r
7eadbf88 71\r
ce879073 72#include "gpuDraw.h"\r
73//#include "plugins.h"\r
74#include "gpuExternals.h"\r
75#include "gpuTexture.h"\r
76#include "gpuPlugin.h"\r
77#include "gpuPrim.h"\r
13326d3e 78\r
ce879073 79#define CLUTCHK 0x00060000\r
80#define CLUTSHIFT 17\r
81\r
82////////////////////////////////////////////////////////////////////////\r
83// texture conversion buffer .. \r
84////////////////////////////////////////////////////////////////////////\r
85\r
86GLubyte ubPaletteBuffer[256][4];\r
87GLuint gTexMovieName=0;\r
88GLuint gTexBlurName=0;\r
89GLuint gTexFrameName=0;\r
90int iTexGarbageCollection=1;\r
91unsigned long dwTexPageComp=0;\r
92int iVRamSize=0;\r
ce879073 93int iClampType=GL_CLAMP_TO_EDGE;\r
ce879073 94int iFilter = GL_LINEAR;\r
95void (*LoadSubTexFn) (int,int,short,short);\r
96unsigned long (*PalTexturedColourFn) (unsigned long);\r
97\r
98////////////////////////////////////////////////////////////////////////\r
99// defines\r
100////////////////////////////////////////////////////////////////////////\r
101\r
102#define PALCOL(x) PalTexturedColourFn (x)\r
103\r
104#define CSUBSIZE 2048\r
105#define CSUBSIZEA 8192\r
106#define CSUBSIZES 4096\r
107\r
108#define OFFA 0\r
109#define OFFB 2048\r
110#define OFFC 4096\r
111#define OFFD 6144\r
112\r
113#define XOFFA 0\r
114#define XOFFB 512\r
115#define XOFFC 1024\r
116#define XOFFD 1536\r
117\r
118#define SOFFA 0\r
119#define SOFFB 1024\r
120#define SOFFC 2048\r
121#define SOFFD 3072\r
122\r
123#define MAXWNDTEXCACHE 128\r
124\r
125#define XCHECK(pos1,pos2) ((pos1.c[0]>=pos2.c[1])&&(pos1.c[1]<=pos2.c[0])&&(pos1.c[2]>=pos2.c[3])&&(pos1.c[3]<=pos2.c[2]))\r
126#define INCHECK(pos2,pos1) ((pos1.c[0]<=pos2.c[0]) && (pos1.c[1]>=pos2.c[1]) && (pos1.c[2]<=pos2.c[2]) && (pos1.c[3]>=pos2.c[3]))\r
127\r
128////////////////////////////////////////////////////////////////////////\r
129\r
677ea103 130unsigned char * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache);\r
ce879073 131void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);\r
132void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);\r
133void DefineSubTextureSort(void);\r
134\r
135////////////////////////////////////////////////////////////////////////\r
136// some globals\r
137////////////////////////////////////////////////////////////////////////\r
138\r
139long GlobalTexturePage;\r
140GLint XTexS;\r
141GLint YTexS;\r
142GLint DXTexS;\r
143GLint DYTexS;\r
144int iSortTexCnt=32;\r
145BOOL bUseFastMdec=FALSE;\r
146BOOL bUse15bitMdec=FALSE;\r
147int iFrameTexType=0;\r
148int iFrameReadType=0;\r
149\r
150unsigned long (*TCF[2]) (unsigned long);\r
151unsigned short (*PTCF[2]) (unsigned short);\r
152\r
153////////////////////////////////////////////////////////////////////////\r
154// texture cache implementation\r
155////////////////////////////////////////////////////////////////////////\r
156\r
ce879073 157// "texture window" cache entry\r
158\r
159typedef struct textureWndCacheEntryTag\r
160{\r
161 unsigned long ClutID;\r
162 short pageid;\r
163 short textureMode;\r
164 short Opaque;\r
165 short used;\r
166 EXLong pos;\r
167 GLuint texname;\r
168} textureWndCacheEntry;\r
169\r
170// "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)\r
171\r
172typedef struct textureSubCacheEntryTagS \r
173{\r
174 unsigned long ClutID;\r
175 EXLong pos;\r
677ea103 176 unsigned char posTX;\r
177 unsigned char posTY;\r
178 unsigned char cTexID;\r
179 unsigned char Opaque;\r
ce879073 180} textureSubCacheEntryS;\r
181\r
ce879073 182\r
183//---------------------------------------------\r
184\r
185#define MAXTPAGES_MAX 64\r
186#define MAXSORTTEX_MAX 196\r
187\r
188//---------------------------------------------\r
189\r
190textureWndCacheEntry wcWndtexStore[MAXWNDTEXCACHE];\r
191textureSubCacheEntryS * pscSubtexStore[3][MAXTPAGES_MAX];\r
192EXLong * pxSsubtexLeft [MAXSORTTEX_MAX];\r
193GLuint uiStexturePage[MAXSORTTEX_MAX];\r
194\r
195unsigned short usLRUTexPage=0;\r
196\r
197int iMaxTexWnds=0;\r
198int iTexWndTurn=0;\r
199int iTexWndLimit=MAXWNDTEXCACHE/2;\r
200\r
201GLubyte * texturepart=NULL;\r
202GLubyte * texturebuffer=NULL;\r
203unsigned long g_x1,g_y1,g_x2,g_y2;\r
677ea103 204unsigned char ubOpaqueDraw=0;\r
ce879073 205\r
206unsigned short MAXTPAGES = 32;\r
207unsigned short CLUTMASK = 0x7fff;\r
208unsigned short CLUTYMASK = 0x1ff;\r
209unsigned short MAXSORTTEX = 196;\r
210\r
211////////////////////////////////////////////////////////////////////////\r
212// Texture color conversions... all my ASM funcs are removed for easier\r
213// porting... and honestly: nowadays the speed gain would be pointless \r
214////////////////////////////////////////////////////////////////////////\r
215\r
216unsigned long XP8RGBA(unsigned long BGR)\r
217{\r
218 if(!(BGR&0xffff)) return 0x50000000;\r
219 if(DrawSemiTrans && !(BGR&0x8000)) \r
220 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
221 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
222}\r
223\r
224unsigned long XP8RGBAEx(unsigned long BGR)\r
225{\r
226 if(!(BGR&0xffff)) return 0x03000000;\r
227 if(DrawSemiTrans && !(BGR&0x8000)) \r
228 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
229 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
230}\r
231\r
232unsigned long CP8RGBA(unsigned long BGR)\r
233{\r
234 unsigned long l;\r
235 if(!(BGR&0xffff)) return 0x50000000;\r
236 if(DrawSemiTrans && !(BGR&0x8000)) \r
237 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
238 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
239 if(l==0xffffff00) l=0xff000000;\r
240 return l;\r
241}\r
242\r
243unsigned long CP8RGBAEx(unsigned long BGR)\r
244{\r
245 unsigned long l;\r
246 if(!(BGR&0xffff)) return 0x03000000;\r
247 if(DrawSemiTrans && !(BGR&0x8000)) \r
248 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
249 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
250 if(l==0xffffff00) l=0xff000000;\r
251 return l;\r
252}\r
253\r
254unsigned long XP8RGBA_0(unsigned long BGR)\r
255{\r
256 if(!(BGR&0xffff)) return 0x50000000;\r
257 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
258}\r
259\r
260unsigned long XP8RGBAEx_0(unsigned long BGR)\r
261{\r
262 if(!(BGR&0xffff)) return 0x03000000;\r
263 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
264}\r
265\r
266unsigned long XP8BGRA_0(unsigned long BGR)\r
267{\r
268 if(!(BGR&0xffff)) return 0x50000000;\r
269 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
270}\r
271\r
272unsigned long XP8BGRAEx_0(unsigned long BGR)\r
273{\r
274 if(!(BGR&0xffff)) return 0x03000000;\r
275 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
276}\r
277\r
278unsigned long CP8RGBA_0(unsigned long BGR)\r
279{\r
280 unsigned long l;\r
281\r
282 if(!(BGR&0xffff)) return 0x50000000;\r
283 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
284 if(l==0xfff8f800) l=0xff000000;\r
285 return l;\r
286}\r
287\r
288unsigned long CP8RGBAEx_0(unsigned long BGR)\r
289{\r
290 unsigned long l;\r
291\r
292 if(!(BGR&0xffff)) return 0x03000000;\r
293 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
294 if(l==0xfff8f800) l=0xff000000;\r
295 return l;\r
296}\r
297\r
298unsigned long CP8BGRA_0(unsigned long BGR)\r
299{\r
300 unsigned long l;\r
301\r
302 if(!(BGR&0xffff)) return 0x50000000;\r
303 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
304 if(l==0xff00f8f8) l=0xff000000;\r
305 return l;\r
306}\r
307\r
308unsigned long CP8BGRAEx_0(unsigned long BGR)\r
309{\r
310 unsigned long l;\r
311\r
312 if(!(BGR&0xffff)) return 0x03000000;\r
313 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
314 if(l==0xff00f8f8) l=0xff000000;\r
315 return l;\r
316}\r
317\r
318unsigned long XP8RGBA_1(unsigned long BGR)\r
319{\r
320 if(!(BGR&0xffff)) return 0x50000000;\r
321 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
322 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
323}\r
324\r
325unsigned long XP8RGBAEx_1(unsigned long BGR)\r
326{\r
327 if(!(BGR&0xffff)) return 0x03000000;\r
328 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
329 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
330}\r
331\r
332unsigned long XP8BGRA_1(unsigned long BGR)\r
333{\r
334 if(!(BGR&0xffff)) return 0x50000000;\r
335 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}\r
336 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
337}\r
338\r
339unsigned long XP8BGRAEx_1(unsigned long BGR)\r
340{\r
341 if(!(BGR&0xffff)) return 0x03000000;\r
342 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}\r
343 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
344}\r
345\r
346unsigned long P8RGBA(unsigned long BGR)\r
347{\r
348 if(!(BGR&0xffff)) return 0;\r
349 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
350}\r
351\r
352unsigned long P8BGRA(unsigned long BGR)\r
353{\r
354 if(!(BGR&0xffff)) return 0;\r
355 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
356}\r
357\r
358unsigned short XP5RGBA(unsigned short BGR)\r
359{\r
360 if(!BGR) return 0;\r
361 if(DrawSemiTrans && !(BGR&0x8000)) \r
362 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
363 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
364}\r
365\r
366unsigned short XP5RGBA_0 (unsigned short BGR)\r
367{\r
368 if(!BGR) return 0;\r
369\r
370 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
371}\r
372\r
373unsigned short CP5RGBA_0 (unsigned short BGR)\r
374{\r
375 unsigned short s;\r
376\r
377 if(!BGR) return 0;\r
378\r
379 s=((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
380 if(s==0x07ff) s=1;\r
381 return s;\r
382}\r
383\r
384unsigned short XP5RGBA_1(unsigned short BGR)\r
385{\r
386 if(!BGR) return 0;\r
387 if(!(BGR&0x8000)) \r
388 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
389 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
390}\r
391\r
392unsigned short P5RGBA(unsigned short BGR)\r
393{\r
394 if(!BGR) return 0;\r
395 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
396}\r
397\r
398unsigned short XP4RGBA(unsigned short BGR)\r
399{\r
400 if(!BGR) return 6;\r
401 if(DrawSemiTrans && !(BGR&0x8000)) \r
402 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
403 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
404}\r
405\r
406unsigned short XP4RGBA_0 (unsigned short BGR)\r
407{\r
408 if(!BGR) return 6;\r
409 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
410}\r
411\r
412unsigned short CP4RGBA_0 (unsigned short BGR)\r
413{\r
414 unsigned short s;\r
415 if(!BGR) return 6;\r
416 s=(((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
417 if(s==0x0fff) s=0x000f;\r
418 return s;\r
419}\r
420\r
421unsigned short XP4RGBA_1(unsigned short BGR)\r
422{\r
423 if(!BGR) return 6;\r
424 if(!(BGR&0x8000)) \r
425 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
426 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
427}\r
428\r
429unsigned short P4RGBA(unsigned short BGR)\r
430{\r
431 if(!BGR) return 0;\r
432 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
433}\r
434\r
435////////////////////////////////////////////////////////////////////////\r
436// CHECK TEXTURE MEM (on plugin startup)\r
437////////////////////////////////////////////////////////////////////////\r
438\r
439int iFTexA=512;\r
440int iFTexB=512;\r
441\r
442void CheckTextureMemory(void)\r
443{\r
444 GLboolean b;GLboolean * bDetail;\r
445 int i,iCnt,iRam=iVRamSize*1024*1024;\r
677ea103 446 int iTSize;char * p;\r
ce879073 447\r
448\r
449 if(iVRamSize)\r
450 {\r
451 int ts;\r
452\r
453 iRam-=(iResX*iResY*8);\r
454 iRam-=(iResX*iResY*(iZBufferDepth/8));\r
455\r
456 ts=4;\r
457 iSortTexCnt=iRam/(256*256*ts);\r
458\r
459 if(iSortTexCnt>MAXSORTTEX) \r
460 {\r
461 iSortTexCnt=MAXSORTTEX-min(1,0);\r
462 }\r
463 else\r
464 {\r
465 iSortTexCnt-=3+min(1,0);\r
466 if(iSortTexCnt<8) iSortTexCnt=8;\r
467 }\r
468\r
469 for(i=0;i<MAXSORTTEX;i++)\r
470 uiStexturePage[i]=0;\r
471 \r
472 return;\r
473 }\r
474\r
d2ec504b 475#if 1\r
476 iSortTexCnt=MAXSORTTEX;\r
477#else // below vram detector supposedly crashes some drivers\r
ce879073 478\r
479 iTSize=256;\r
677ea103 480 p=(char *)malloc(iTSize*iTSize*4);\r
ce879073 481\r
482 iCnt=0;\r
483 glGenTextures(MAXSORTTEX,uiStexturePage);\r
484 for(i=0;i<MAXSORTTEX;i++)\r
485 {\r
486 glBindTexture(GL_TEXTURE_2D,uiStexturePage[i]);\r
487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);\r
488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);\r
489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);\r
490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);\r
491 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTSize, iTSize, 0,GL_RGBA, GL_UNSIGNED_BYTE, p);\r
492 }\r
493 glBindTexture(GL_TEXTURE_2D,0);\r
494\r
495 free(p);\r
496\r
497 bDetail=(GLboolean*)malloc(MAXSORTTEX*sizeof(GLboolean));\r
498 memset(bDetail,0,MAXSORTTEX*sizeof(GLboolean));\r
499\r
500 glDeleteTextures(MAXSORTTEX,uiStexturePage);\r
501\r
502 for(i=0;i<MAXSORTTEX;i++)\r
503 {\r
504 if(bDetail[i]) iCnt++;\r
505 uiStexturePage[i]=0;\r
506 }\r
507\r
508 free(bDetail);\r
509\r
510 if(b) iSortTexCnt=MAXSORTTEX-min(1,0);\r
511 else iSortTexCnt=iCnt-3+min(1,0); // place for menu&texwnd\r
512\r
513 if(iSortTexCnt<8) iSortTexCnt=8;\r
d2ec504b 514#endif\r
ce879073 515} \r
516\r
517////////////////////////////////////////////////////////////////////////\r
518// Main init of textures\r
519////////////////////////////////////////////////////////////////////////\r
520\r
521void InitializeTextureStore() \r
522{\r
523 int i,j;\r
524\r
525 if(iGPUHeight==1024)\r
526 {\r
527 MAXTPAGES = 64;\r
528 CLUTMASK = 0xffff;\r
529 CLUTYMASK = 0x3ff;\r
530 MAXSORTTEX = 128;\r
531 iTexGarbageCollection=0;\r
532 }\r
533 else\r
534 {\r
535 MAXTPAGES = 32;\r
536 CLUTMASK = 0x7fff;\r
537 CLUTYMASK = 0x1ff;\r
538 MAXSORTTEX = 196;\r
539 }\r
540\r
541 memset(vertex,0,4*sizeof(OGLVertex)); // init vertices\r
542\r
543 gTexName=0; // init main tex name\r
544\r
545 iTexWndLimit=MAXWNDTEXCACHE;\r
546/* if(!iUsePalTextures) */iTexWndLimit/=2;\r
547\r
548 memset(wcWndtexStore,0,sizeof(textureWndCacheEntry)*\r
549 MAXWNDTEXCACHE);\r
550 texturepart=(GLubyte *)malloc(256*256*4);\r
551 memset(texturepart,0,256*256*4);\r
552 texturebuffer=NULL;\r
553\r
554 for(i=0;i<3;i++) // -> info for 32*3\r
555 for(j=0;j<MAXTPAGES;j++)\r
556 { \r
557 pscSubtexStore[i][j]=(textureSubCacheEntryS *)malloc(CSUBSIZES*sizeof(textureSubCacheEntryS));\r
558 memset(pscSubtexStore[i][j],0,CSUBSIZES*sizeof(textureSubCacheEntryS));\r
559 }\r
560 for(i=0;i<MAXSORTTEX;i++) // -> info 0..511\r
561 {\r
562 pxSsubtexLeft[i]=(EXLong *)malloc(CSUBSIZE*sizeof(EXLong));\r
563 memset(pxSsubtexLeft[i],0,CSUBSIZE*sizeof(EXLong));\r
564 uiStexturePage[i]=0;\r
565 }\r
566}\r
567\r
568////////////////////////////////////////////////////////////////////////\r
569// Clean up on exit\r
570////////////////////////////////////////////////////////////////////////\r
571\r
572void CleanupTextureStore() \r
573{\r
574 int i,j;textureWndCacheEntry * tsx;\r
575 //----------------------------------------------------//\r
576 glBindTexture(GL_TEXTURE_2D,0);\r
9f58cabb 577 glError();\r
ce879073 578 //----------------------------------------------------//\r
579 free(texturepart); // free tex part\r
580 texturepart=0;\r
581 if(texturebuffer)\r
582 {\r
583 free(texturebuffer);\r
584 texturebuffer=0;\r
585 }\r
586 //----------------------------------------------------//\r
587 tsx=wcWndtexStore; // loop tex window cache\r
588 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)\r
589 {\r
590 if(tsx->texname) // -> some tex?\r
591 glDeleteTextures(1,&tsx->texname); // --> delete it\r
9f58cabb 592 glError();\r
ce879073 593 }\r
594 iMaxTexWnds=0; // no more tex wnds\r
595 //----------------------------------------------------//\r
596 if(gTexMovieName!=0) // some movie tex?\r
597 glDeleteTextures(1, &gTexMovieName); // -> delete it\r
9f58cabb 598 glError();\r
ce879073 599 gTexMovieName=0; // no more movie tex\r
600 //----------------------------------------------------//\r
601 if(gTexFrameName!=0) // some 15bit framebuffer tex?\r
602 glDeleteTextures(1, &gTexFrameName); // -> delete it\r
9f58cabb 603 glError();\r
ce879073 604 gTexFrameName=0; // no more movie tex\r
605 //----------------------------------------------------//\r
606 if(gTexBlurName!=0) // some 15bit framebuffer tex?\r
607 glDeleteTextures(1, &gTexBlurName); // -> delete it\r
9f58cabb 608 glError();\r
ce879073 609 gTexBlurName=0; // no more movie tex\r
610 //----------------------------------------------------//\r
611 for(i=0;i<3;i++) // -> loop\r
612 for(j=0;j<MAXTPAGES;j++) // loop tex pages\r
613 {\r
614 free(pscSubtexStore[i][j]); // -> clean mem\r
2ea6b470 615 pscSubtexStore[i][j]=0;\r
ce879073 616 }\r
617 for(i=0;i<MAXSORTTEX;i++)\r
618 {\r
619 if(uiStexturePage[i]) // --> tex used ?\r
620 {\r
621 glDeleteTextures(1,&uiStexturePage[i]);\r
9f58cabb 622 glError();\r
ce879073 623 uiStexturePage[i]=0; // --> delete it\r
624 }\r
625 free(pxSsubtexLeft[i]); // -> clean mem\r
2ea6b470 626 pxSsubtexLeft[i]=0;\r
ce879073 627 }\r
628 //----------------------------------------------------//\r
629}\r
630\r
631////////////////////////////////////////////////////////////////////////\r
632// Reset textures in game...\r
633////////////////////////////////////////////////////////////////////////\r
634\r
635void ResetTextureArea(BOOL bDelTex)\r
636{\r
637 int i,j;textureSubCacheEntryS * tss;EXLong * lu;\r
638 textureWndCacheEntry * tsx;\r
639 //----------------------------------------------------//\r
640\r
641 dwTexPageComp=0;\r
642\r
643 //----------------------------------------------------//\r
9f58cabb 644 if(bDelTex) {glBindTexture(GL_TEXTURE_2D,0); glError();gTexName=0;}\r
ce879073 645 //----------------------------------------------------//\r
646 tsx=wcWndtexStore;\r
647 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)\r
648 {\r
649 tsx->used=0;\r
650 if(bDelTex && tsx->texname)\r
651 {\r
9f58cabb 652 glDeleteTextures(1,&tsx->texname); glError();\r
ce879073 653 tsx->texname=0;\r
654 }\r
655 }\r
656 iMaxTexWnds=0;\r
657 //----------------------------------------------------//\r
658\r
659 for(i=0;i<3;i++)\r
660 for(j=0;j<MAXTPAGES;j++)\r
661 {\r
662 tss=pscSubtexStore[i][j];\r
663 (tss+SOFFA)->pos.l=0;\r
664 (tss+SOFFB)->pos.l=0;\r
665 (tss+SOFFC)->pos.l=0;\r
666 (tss+SOFFD)->pos.l=0;\r
667 }\r
668\r
669 for(i=0;i<iSortTexCnt;i++)\r
670 {\r
671 lu=pxSsubtexLeft[i];\r
672 lu->l=0;\r
673 if(bDelTex && uiStexturePage[i])\r
9f58cabb 674 {glDeleteTextures(1,&uiStexturePage[i]); glError();uiStexturePage[i]=0;}\r
ce879073 675 }\r
676}\r
677\r
678\r
679////////////////////////////////////////////////////////////////////////\r
680// Invalidate tex windows\r
681////////////////////////////////////////////////////////////////////////\r
682\r
683void InvalidateWndTextureArea(long X,long Y,long W, long H)\r
684{\r
685 int i,px1,px2,py1,py2,iYM=1;\r
686 textureWndCacheEntry * tsw=wcWndtexStore;\r
687\r
688 W+=X-1; \r
689 H+=Y-1;\r
690 if(X<0) X=0;if(X>1023) X=1023;\r
691 if(W<0) W=0;if(W>1023) W=1023;\r
692 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;\r
693 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;\r
694 W++;H++;\r
695\r
696 if(iGPUHeight==1024) iYM=3;\r
697\r
698 py1=min(iYM,Y>>8);\r
699 py2=min(iYM,H>>8); // y: 0 or 1\r
700\r
701 px1=max(0,(X>>6));\r
702 px2=min(15,(W>>6));\r
703\r
704 if(py1==py2)\r
705 {\r
706 py1=py1<<4;px1+=py1;px2+=py1; // change to 0-31\r
707 for(i=0;i<iMaxTexWnds;i++,tsw++)\r
708 {\r
709 if(tsw->used)\r
710 {\r
711 if(tsw->pageid>=px1 && tsw->pageid<=px2)\r
712 {\r
713 tsw->used=0;\r
714 }\r
715 }\r
716 }\r
717 }\r
718 else\r
719 {\r
720 py1=px1+16;py2=px2+16;\r
721 for(i=0;i<iMaxTexWnds;i++,tsw++)\r
722 {\r
723 if(tsw->used)\r
724 {\r
725 if((tsw->pageid>=px1 && tsw->pageid<=px2) ||\r
726 (tsw->pageid>=py1 && tsw->pageid<=py2))\r
727 {\r
728 tsw->used=0;\r
729 }\r
730 }\r
731 }\r
732 }\r
733\r
734 // adjust tex window count\r
735 tsw=wcWndtexStore+iMaxTexWnds-1;\r
736 while(iMaxTexWnds && !tsw->used) {iMaxTexWnds--;tsw--;}\r
737}\r
738\r
739\r
740\r
741////////////////////////////////////////////////////////////////////////\r
742// same for sort textures\r
743////////////////////////////////////////////////////////////////////////\r
744\r
745void MarkFree(textureSubCacheEntryS * tsx)\r
746{\r
747 EXLong * ul, * uls;\r
677ea103 748 int j,iMax;unsigned char x1,y1,dx,dy;\r
ce879073 749\r
750 uls=pxSsubtexLeft[tsx->cTexID];\r
751 iMax=uls->l;ul=uls+1;\r
752\r
753 if(!iMax) return;\r
754\r
755 for(j=0;j<iMax;j++,ul++)\r
756 if(ul->l==0xffffffff) break;\r
757\r
758 if(j<CSUBSIZE-2)\r
759 {\r
760 if(j==iMax) uls->l=uls->l+1;\r
761\r
762 x1=tsx->posTX;dx=tsx->pos.c[2]-tsx->pos.c[3];\r
763 if(tsx->posTX) {x1--;dx+=3;}\r
764 y1=tsx->posTY;dy=tsx->pos.c[0]-tsx->pos.c[1];\r
765 if(tsx->posTY) {y1--;dy+=3;}\r
766\r
767 ul->c[3]=x1;\r
768 ul->c[2]=dx;\r
769 ul->c[1]=y1;\r
770 ul->c[0]=dy;\r
771 }\r
772}\r
773\r
774void InvalidateSubSTextureArea(long X,long Y,long W, long H)\r
775{\r
776 int i,j,k,iMax,px,py,px1,px2,py1,py2,iYM=1;\r
777 EXLong npos;textureSubCacheEntryS * tsb;\r
778 long x1,x2,y1,y2,xa,sw;\r
779\r
780 W+=X-1; \r
781 H+=Y-1;\r
782 if(X<0) X=0;if(X>1023) X=1023;\r
783 if(W<0) W=0;if(W>1023) W=1023;\r
784 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;\r
785 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;\r
786 W++;H++;\r
787\r
788 if(iGPUHeight==1024) iYM=3;\r
789\r
790 py1=min(iYM,Y>>8);\r
791 py2=min(iYM,H>>8); // y: 0 or 1\r
792 px1=max(0,(X>>6)-3); \r
793 px2=min(15,(W>>6)+3); // x: 0-15\r
794\r
795 for(py=py1;py<=py2;py++)\r
796 {\r
797 j=(py<<4)+px1; // get page\r
798\r
799 y1=py*256;y2=y1+255;\r
800\r
801 if(H<y1) continue;\r
802 if(Y>y2) continue;\r
803\r
804 if(Y>y1) y1=Y;\r
805 if(H<y2) y2=H;\r
806 if(y2<y1) {sw=y1;y1=y2;y2=sw;}\r
807 y1=((y1%256)<<8);\r
808 y2=(y2%256);\r
809\r
810 for(px=px1;px<=px2;px++,j++)\r
811 {\r
812 for(k=0;k<3;k++)\r
813 {\r
814 xa=x1=px<<6;\r
815 if(W<x1) continue;\r
816 x2=x1+(64<<k)-1;\r
817 if(X>x2) continue;\r
818\r
819 if(X>x1) x1=X;\r
820 if(W<x2) x2=W;\r
821 if(x2<x1) {sw=x1;x1=x2;x2=sw;}\r
822\r
823 if (dwGPUVersion == 2)\r
824 npos.l=0x00ff00ff;\r
825 else\r
826 npos.l=((x1-xa)<<(26-k))|((x2-xa)<<(18-k))|y1|y2;\r
827\r
828 {\r
829 tsb=pscSubtexStore[k][j]+SOFFA;iMax=tsb->pos.l;tsb++;\r
830 for(i=0;i<iMax;i++,tsb++)\r
831 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
832\r
833// if(npos.l & 0x00800000)\r
834 {\r
835 tsb=pscSubtexStore[k][j]+SOFFB;iMax=tsb->pos.l;tsb++;\r
836 for(i=0;i<iMax;i++,tsb++)\r
837 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
838 }\r
839\r
840// if(npos.l & 0x00000080)\r
841 {\r
842 tsb=pscSubtexStore[k][j]+SOFFC;iMax=tsb->pos.l;tsb++;\r
843 for(i=0;i<iMax;i++,tsb++)\r
844 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
845 }\r
846\r
847// if(npos.l & 0x00800080)\r
848 {\r
849 tsb=pscSubtexStore[k][j]+SOFFD;iMax=tsb->pos.l;tsb++;\r
850 for(i=0;i<iMax;i++,tsb++)\r
851 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
852 }\r
853 }\r
854 }\r
855 }\r
856 }\r
857}\r
858\r
859////////////////////////////////////////////////////////////////////////\r
860// Invalidate some parts of cache: main routine\r
861////////////////////////////////////////////////////////////////////////\r
862\r
863void InvalidateTextureAreaEx(void)\r
864{\r
865 short W=sxmax-sxmin;\r
866 short H=symax-symin;\r
867\r
868 if(W==0 && H==0) return;\r
869\r
870 if(iMaxTexWnds) \r
871 InvalidateWndTextureArea(sxmin,symin,W,H);\r
872\r
873 InvalidateSubSTextureArea(sxmin,symin,W,H);\r
874}\r
875\r
876////////////////////////////////////////////////////////////////////////\r
877\r
878void InvalidateTextureArea(long X,long Y,long W, long H)\r
879{\r
880 if(W==0 && H==0) return;\r
881\r
882 if(iMaxTexWnds) InvalidateWndTextureArea(X,Y,W,H); \r
883\r
884 InvalidateSubSTextureArea(X,Y,W,H);\r
885}\r
886\r
887\r
888////////////////////////////////////////////////////////////////////////\r
889// tex window: define\r
890////////////////////////////////////////////////////////////////////////\r
891\r
892void DefineTextureWnd(void)\r
893{\r
894 if(gTexName==0)\r
895 glGenTextures(1, &gTexName);\r
9f58cabb 896 glError();\r
ce879073 897 glBindTexture(GL_TEXTURE_2D, gTexName);\r
9f58cabb 898 glError();\r
ce879073 899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\r
900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\r
9f58cabb 901 glError(); \r
ce879073 902{\r
903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);\r
904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);\r
9f58cabb 905 glError();\r
ce879073 906 }\r
907\r
908 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, \r
909 TWin.Position.x1, \r
910 TWin.Position.y1, \r
911 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);\r
9f58cabb 912 glError();\r
913 //LOGE("DefineTextureWnd x:%d y:%d",TWin.Position.x1,TWin.Position.y1);\r
914\r
ce879073 915}\r
916\r
917////////////////////////////////////////////////////////////////////////\r
918// tex window: load packed stretch\r
919////////////////////////////////////////////////////////////////////////\r
920\r
921void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)\r
922{\r
923 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;\r
924 unsigned int palstart;\r
925 unsigned short *px,*pa,*ta;\r
677ea103 926 unsigned char *cSRCPtr,*cOSRCPtr;\r
ce879073 927 unsigned short *wSRCPtr,*wOSRCPtr;\r
928 unsigned long LineOffset;unsigned short s;\r
929 int pmult=pageid/16;\r
930 unsigned short (*LPTCOL)(unsigned short);\r
931\r
932 LPTCOL=PTCF[DrawSemiTrans];\r
933\r
934 ldxo=TWin.Position.x1-TWin.OPosition.x1;\r
935 ldy =TWin.Position.y1-TWin.OPosition.y1;\r
936\r
937 pa=px=(unsigned short *)ubPaletteBuffer;\r
938 ta=(unsigned short *)texturepart;\r
939 palstart=cx+(cy*1024);\r
940\r
941 ubOpaqueDraw=0;\r
942\r
943 switch(mode)\r
944 {\r
945 //--------------------------------------------------// \r
946 // 4bit texture load ..\r
947 case 0:\r
948 if(GlobalTextIL)\r
949 {\r
950 unsigned int TXV,TXU,n_xi,n_yi;\r
951\r
952 wSRCPtr=psxVuw+palstart;\r
953 for(row=0;row<16;row++)\r
954 *px++=LPTCOL(*wSRCPtr++);\r
955\r
956 column=g_y2-ldy;\r
957 for(TXV=g_y1;TXV<=column;TXV++)\r
958 {\r
959 ldx=ldxo;\r
960 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
961 {\r
962 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
963 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
964\r
965 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
966 *ta++=s;\r
967\r
968 if(ldx) {*ta++=s;ldx--;}\r
969 }\r
970\r
971 if(ldy) \r
972 {ldy--;\r
973 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
974 *ta++=*(ta-(g_x2-g_x1));\r
975 }\r
976 }\r
977\r
978 DefineTextureWnd();\r
979\r
980 break;\r
981 }\r
982\r
983\r
984 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
985\r
986 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
987\r
988 wSRCPtr=psxVuw+palstart;\r
989 for(row=0;row<16;row++)\r
990 *px++=LPTCOL(*wSRCPtr++);\r
991\r
992 sxm=g_x1&1;sxh=g_x1>>1;\r
993 if(sxm) j=g_x1+1; else j=g_x1;\r
994 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
995 for(column=g_y1;column<=g_y2;column++)\r
996 {\r
997 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
998 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
999 \r
1000 for(row=j;row<=g_x2-ldxo;row++)\r
1001 {\r
1002 s=*(pa+(*cSRCPtr & 0xF));\r
1003 *ta++=s;\r
1004 if(ldx) {*ta++=s;ldx--;}\r
1005 row++;\r
1006 if(row<=g_x2-ldxo) \r
1007 {\r
1008 s=*(pa+((*cSRCPtr >> 4) & 0xF));\r
1009 *ta++=s; \r
1010 if(ldx) {*ta++=s;ldx--;}\r
1011 }\r
1012 cSRCPtr++;\r
1013 }\r
1014\r
1015 if(ldy && column&1) \r
1016 {ldy--;cSRCPtr = cOSRCPtr;}\r
1017 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;\r
1018 }\r
1019\r
1020 DefineTextureWnd();\r
1021 break;\r
1022 //--------------------------------------------------// \r
1023 // 8bit texture load ..\r
1024 case 1:\r
1025 if(GlobalTextIL)\r
1026 {\r
1027 unsigned int TXV,TXU,n_xi,n_yi;\r
1028\r
1029 wSRCPtr=psxVuw+palstart;\r
1030 for(row=0;row<256;row++)\r
1031 *px++=LPTCOL(*wSRCPtr++);\r
1032\r
1033 column=g_y2-ldy;\r
1034 for(TXV=g_y1;TXV<=column;TXV++)\r
1035 {\r
1036 ldx=ldxo;\r
1037 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
1038 {\r
1039 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1040 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1041\r
1042 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1043\r
1044 *ta++=s;\r
1045 if(ldx) {*ta++=s;ldx--;}\r
1046 }\r
1047\r
1048 if(ldy) \r
1049 {ldy--;\r
1050 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1051 *ta++=*(ta-(g_x2-g_x1));\r
1052 }\r
1053\r
1054 }\r
1055\r
1056 DefineTextureWnd();\r
1057\r
1058 break;\r
1059 }\r
1060\r
1061 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1062\r
1063 // not using a lookup table here... speeds up smaller texture areas\r
1064 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1065 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo; \r
1066\r
1067 for(column=g_y1;column<=g_y2;column++)\r
1068 {\r
1069 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1070 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1071 {\r
1072 s=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1073 *ta++=s;\r
1074 if(ldx) {*ta++=s;ldx--;}\r
1075 }\r
1076 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}\r
1077 else cSRCPtr+=LineOffset;\r
1078 }\r
1079\r
1080 DefineTextureWnd();\r
1081 break;\r
1082 //--------------------------------------------------// \r
1083 // 16bit texture load ..\r
1084 case 2:\r
1085 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1086 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1087 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo; \r
1088 \r
1089 for(column=g_y1;column<=g_y2;column++)\r
1090 {\r
1091 wOSRCPtr=wSRCPtr;ldx=ldxo;\r
1092 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1093 {\r
1094 s=LPTCOL(*wSRCPtr++);\r
1095 *ta++=s;\r
1096 if(ldx) {*ta++=s;ldx--;}\r
1097 }\r
1098 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}\r
1099 else wSRCPtr+=LineOffset;\r
1100 }\r
1101\r
1102 DefineTextureWnd();\r
1103 break;\r
1104 //--------------------------------------------------// \r
1105 // others are not possible !\r
1106 }\r
1107}\r
1108\r
1109////////////////////////////////////////////////////////////////////////\r
1110// tex window: load stretched\r
1111////////////////////////////////////////////////////////////////////////\r
1112\r
1113void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)\r
1114{\r
1115 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo,s;\r
1116 unsigned int palstart;\r
1117 unsigned long *px,*pa,*ta;\r
677ea103 1118 unsigned char *cSRCPtr,*cOSRCPtr;\r
ce879073 1119 unsigned short *wSRCPtr,*wOSRCPtr;\r
1120 unsigned long LineOffset;\r
1121 int pmult=pageid/16;\r
1122 unsigned long (*LTCOL)(unsigned long);\r
1123 \r
1124 LTCOL=TCF[DrawSemiTrans];\r
1125\r
1126 ldxo=TWin.Position.x1-TWin.OPosition.x1;\r
1127 ldy =TWin.Position.y1-TWin.OPosition.y1;\r
1128\r
1129 pa=px=(unsigned long *)ubPaletteBuffer;\r
1130 ta=(unsigned long *)texturepart;\r
1131 palstart=cx+(cy*1024);\r
1132\r
1133 ubOpaqueDraw=0;\r
1134\r
1135 switch(mode)\r
1136 {\r
1137 //--------------------------------------------------// \r
1138 // 4bit texture load ..\r
1139 case 0:\r
1140 //------------------- ZN STUFF\r
1141\r
1142 if(GlobalTextIL)\r
1143 {\r
1144 unsigned int TXV,TXU,n_xi,n_yi;\r
1145\r
1146 wSRCPtr=psxVuw+palstart;\r
1147\r
1148 row=4;do\r
1149 {\r
1150 *px =LTCOL(*wSRCPtr);\r
1151 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1152 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1153 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1154 row--;px+=4;wSRCPtr+=4;\r
1155 }\r
1156 while (row);\r
1157\r
1158 column=g_y2-ldy;\r
1159 for(TXV=g_y1;TXV<=column;TXV++)\r
1160 {\r
1161 ldx=ldxo;\r
1162 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
1163 {\r
1164 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
1165 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
1166\r
1167 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
1168 *ta++=s;\r
1169\r
1170 if(ldx) {*ta++=s;ldx--;}\r
1171 }\r
1172\r
1173 if(ldy) \r
1174 {ldy--;\r
1175 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1176 *ta++=*(ta-(g_x2-g_x1));\r
1177 }\r
1178 }\r
1179\r
1180 DefineTextureWnd();\r
1181\r
1182 break;\r
1183 }\r
1184\r
1185 //-------------------\r
1186\r
1187 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1188 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
1189\r
1190 wSRCPtr=psxVuw+palstart;\r
1191 for(row=0;row<16;row++)\r
1192 *px++=LTCOL(*wSRCPtr++);\r
1193\r
1194 sxm=g_x1&1;sxh=g_x1>>1;\r
1195 if(sxm) j=g_x1+1; else j=g_x1;\r
1196 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1197 for(column=g_y1;column<=g_y2;column++)\r
1198 {\r
1199 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1200 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
1201 \r
1202 for(row=j;row<=g_x2-ldxo;row++)\r
1203 {\r
1204 s=*(pa+(*cSRCPtr & 0xF));\r
1205 *ta++=s;\r
1206 if(ldx) {*ta++=s;ldx--;}\r
1207 row++;\r
1208 if(row<=g_x2-ldxo) \r
1209 {\r
1210 s=*(pa+((*cSRCPtr >> 4) & 0xF));\r
1211 *ta++=s; \r
1212 if(ldx) {*ta++=s;ldx--;}\r
1213 }\r
1214 cSRCPtr++;\r
1215 }\r
1216 if(ldy && column&1) \r
1217 {ldy--;cSRCPtr = cOSRCPtr;}\r
1218 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;\r
1219 }\r
1220\r
1221 DefineTextureWnd();\r
1222 break;\r
1223 //--------------------------------------------------//\r
1224 // 8bit texture load ..\r
1225 case 1:\r
1226 //------------ ZN STUFF\r
1227 if(GlobalTextIL)\r
1228 {\r
1229 unsigned int TXV,TXU,n_xi,n_yi;\r
1230\r
1231 wSRCPtr=psxVuw+palstart;\r
1232\r
1233 row=64;do\r
1234 {\r
1235 *px =LTCOL(*wSRCPtr);\r
1236 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1237 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1238 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1239 row--;px+=4;wSRCPtr+=4;\r
1240 }\r
1241 while (row);\r
1242\r
1243 column=g_y2-ldy;\r
1244 for(TXV=g_y1;TXV<=column;TXV++)\r
1245 {\r
1246 ldx=ldxo;\r
1247 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
1248 {\r
1249 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1250 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1251\r
1252 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1253 *ta++=s;\r
1254 if(ldx) {*ta++=s;ldx--;}\r
1255 }\r
1256\r
1257 if(ldy) \r
1258 {ldy--;\r
1259 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1260 *ta++=*(ta-(g_x2-g_x1));\r
1261 }\r
1262\r
1263 }\r
1264\r
1265 DefineTextureWnd();\r
1266\r
1267 break;\r
1268 }\r
1269 //------------\r
1270\r
1271 start=((pageid-16*pmult)*128)+256*2048*pmult; \r
1272\r
1273 // not using a lookup table here... speeds up smaller texture areas\r
1274 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1275 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo; \r
1276\r
1277 for(column=g_y1;column<=g_y2;column++)\r
1278 {\r
1279 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1280 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1281 {\r
1282 s=LTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1283 *ta++=s;\r
1284 if(ldx) {*ta++=s;ldx--;}\r
1285 }\r
1286 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}\r
1287 else cSRCPtr+=LineOffset;\r
1288 }\r
1289\r
1290 DefineTextureWnd();\r
1291 break;\r
1292 //--------------------------------------------------// \r
1293 // 16bit texture load ..\r
1294 case 2:\r
1295 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1296\r
1297 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1298 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo; \r
1299\r
1300 for(column=g_y1;column<=g_y2;column++)\r
1301 {\r
1302 wOSRCPtr=wSRCPtr;ldx=ldxo;\r
1303 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1304 {\r
1305 s=LTCOL(*wSRCPtr++);\r
1306 *ta++=s;\r
1307 if(ldx) {*ta++=s;ldx--;}\r
1308 }\r
1309 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}\r
1310 else wSRCPtr+=LineOffset;\r
1311 }\r
1312\r
1313 DefineTextureWnd();\r
1314 break;\r
1315 //--------------------------------------------------// \r
1316 // others are not possible !\r
1317 }\r
1318}\r
1319\r
1320////////////////////////////////////////////////////////////////////////\r
1321// tex window: load packed simple\r
1322////////////////////////////////////////////////////////////////////////\r
1323\r
1324void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)\r
1325{\r
1326 unsigned long start,row,column,j,sxh,sxm;\r
1327 unsigned int palstart;\r
1328 unsigned short *px,*pa,*ta;\r
677ea103 1329 unsigned char *cSRCPtr;\r
ce879073 1330 unsigned short *wSRCPtr;\r
1331 unsigned long LineOffset;\r
1332 int pmult=pageid/16;\r
1333 unsigned short (*LPTCOL)(unsigned short);\r
1334\r
1335 LPTCOL=PTCF[DrawSemiTrans];\r
1336\r
1337 pa=px=(unsigned short *)ubPaletteBuffer;\r
1338 ta=(unsigned short *)texturepart;\r
1339 palstart=cx+(cy*1024);\r
1340\r
1341 ubOpaqueDraw=0;\r
1342\r
1343 switch(mode)\r
1344 {\r
1345 //--------------------------------------------------// \r
1346 // 4bit texture load ..\r
1347 case 0:\r
1348 if(GlobalTextIL)\r
1349 {\r
1350 unsigned int TXV,TXU,n_xi,n_yi;\r
1351\r
1352 wSRCPtr=psxVuw+palstart;\r
1353 for(row=0;row<16;row++)\r
1354 *px++=LPTCOL(*wSRCPtr++);\r
1355\r
1356 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1357 {\r
1358 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1359 {\r
1360 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
1361 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
1362\r
1363 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
1364 }\r
1365 }\r
1366\r
1367 DefineTextureWnd();\r
1368\r
1369 break;\r
1370 }\r
1371\r
1372 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1373\r
1374 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
1375\r
1376 wSRCPtr=psxVuw+palstart;\r
1377 for(row=0;row<16;row++)\r
1378 *px++=LPTCOL(*wSRCPtr++);\r
1379\r
1380 sxm=g_x1&1;sxh=g_x1>>1;\r
1381 if(sxm) j=g_x1+1; else j=g_x1;\r
1382 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1383 for(column=g_y1;column<=g_y2;column++)\r
1384 {\r
1385 cSRCPtr = psxVub + start + (2048*column) + sxh;\r
1386 \r
1387 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
1388 \r
1389 for(row=j;row<=g_x2;row++)\r
1390 {\r
1391 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;\r
1392 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
1393 cSRCPtr++;\r
1394 }\r
1395 }\r
1396\r
1397 DefineTextureWnd();\r
1398 break;\r
1399 //--------------------------------------------------// \r
1400 // 8bit texture load ..\r
1401 case 1:\r
1402 if(GlobalTextIL)\r
1403 {\r
1404 unsigned int TXV,TXU,n_xi,n_yi;\r
1405\r
1406 wSRCPtr=psxVuw+palstart;\r
1407 for(row=0;row<256;row++)\r
1408 *px++=LPTCOL(*wSRCPtr++);\r
1409\r
1410 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1411 {\r
1412 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1413 {\r
1414 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1415 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1416\r
1417 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1418 }\r
1419 }\r
1420\r
1421 DefineTextureWnd();\r
1422\r
1423 break;\r
1424 }\r
1425\r
1426 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1427\r
1428 // not using a lookup table here... speeds up smaller texture areas\r
1429 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1430 LineOffset = 2048 - (g_x2-g_x1+1); \r
1431\r
1432 for(column=g_y1;column<=g_y2;column++)\r
1433 {\r
1434 for(row=g_x1;row<=g_x2;row++)\r
1435 *ta++=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1436 cSRCPtr+=LineOffset;\r
1437 }\r
1438\r
1439 DefineTextureWnd();\r
1440 break;\r
1441 //--------------------------------------------------// \r
1442 // 16bit texture load ..\r
1443 case 2:\r
1444 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1445 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1446 LineOffset = 1024 - (g_x2-g_x1+1); \r
1447\r
1448 for(column=g_y1;column<=g_y2;column++)\r
1449 {\r
1450 for(row=g_x1;row<=g_x2;row++)\r
1451 *ta++=LPTCOL(*wSRCPtr++);\r
1452 wSRCPtr+=LineOffset;\r
1453 }\r
1454\r
1455 DefineTextureWnd();\r
1456 break;\r
1457 //--------------------------------------------------// \r
1458 // others are not possible !\r
1459 }\r
1460}\r
1461\r
1462////////////////////////////////////////////////////////////////////////\r
1463// tex window: load simple\r
1464////////////////////////////////////////////////////////////////////////\r
1465\r
1466void LoadWndTexturePage(int pageid, int mode, short cx, short cy)\r
1467{\r
1468 unsigned long start,row,column,j,sxh,sxm;\r
1469 unsigned int palstart;\r
1470 unsigned long *px,*pa,*ta;\r
677ea103 1471 unsigned char *cSRCPtr;\r
ce879073 1472 unsigned short *wSRCPtr;\r
1473 unsigned long LineOffset;\r
1474 int pmult=pageid/16;\r
1475 unsigned long (*LTCOL)(unsigned long);\r
1476 \r
1477 LTCOL=TCF[DrawSemiTrans];\r
1478\r
1479 pa=px=(unsigned long *)ubPaletteBuffer;\r
1480 ta=(unsigned long *)texturepart;\r
1481 palstart=cx+(cy*1024);\r
1482\r
1483 ubOpaqueDraw=0;\r
1484\r
1485 switch(mode)\r
1486 {\r
1487 //--------------------------------------------------// \r
1488 // 4bit texture load ..\r
1489 case 0:\r
1490 if(GlobalTextIL)\r
1491 {\r
1492 unsigned int TXV,TXU,n_xi,n_yi;\r
1493\r
1494 wSRCPtr=psxVuw+palstart;\r
1495\r
1496 row=4;do\r
1497 {\r
1498 *px =LTCOL(*wSRCPtr);\r
1499 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1500 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1501 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1502 row--;px+=4;wSRCPtr+=4;\r
1503 }\r
1504 while (row);\r
1505\r
1506 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1507 {\r
1508 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1509 {\r
1510 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
1511 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
1512\r
1513 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
1514 }\r
1515 }\r
1516\r
1517 DefineTextureWnd();\r
1518\r
1519 break;\r
1520 }\r
1521\r
1522 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1523\r
1524 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
1525\r
1526 wSRCPtr=psxVuw+palstart;\r
1527 for(row=0;row<16;row++)\r
1528 *px++=LTCOL(*wSRCPtr++);\r
1529\r
1530 sxm=g_x1&1;sxh=g_x1>>1;\r
1531 if(sxm) j=g_x1+1; else j=g_x1;\r
1532 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1533 for(column=g_y1;column<=g_y2;column++)\r
1534 {\r
1535 cSRCPtr = psxVub + start + (2048*column) + sxh;\r
1536 \r
1537 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
1538 \r
1539 for(row=j;row<=g_x2;row++)\r
1540 {\r
1541 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;\r
1542 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
1543 cSRCPtr++;\r
1544 }\r
1545 }\r
1546\r
1547 DefineTextureWnd();\r
1548 break;\r
1549 //--------------------------------------------------//\r
1550 // 8bit texture load ..\r
1551 case 1:\r
1552 if(GlobalTextIL)\r
1553 {\r
1554 unsigned int TXV,TXU,n_xi,n_yi;\r
1555\r
1556 wSRCPtr=psxVuw+palstart;\r
1557\r
1558 row=64;do\r
1559 {\r
1560 *px =LTCOL(*wSRCPtr);\r
1561 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1562 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1563 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1564 row--;px+=4;wSRCPtr+=4;\r
1565 }\r
1566 while (row);\r
1567\r
1568 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1569 {\r
1570 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1571 {\r
1572 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1573 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1574\r
1575 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1576 }\r
1577 }\r
1578\r
1579 DefineTextureWnd();\r
1580\r
1581 break;\r
1582 }\r
1583\r
1584 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1585\r
1586 // not using a lookup table here... speeds up smaller texture areas\r
1587 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1588 LineOffset = 2048 - (g_x2-g_x1+1); \r
1589\r
1590 for(column=g_y1;column<=g_y2;column++)\r
1591 {\r
1592 for(row=g_x1;row<=g_x2;row++)\r
1593 *ta++=LTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1594 cSRCPtr+=LineOffset;\r
1595 }\r
1596\r
1597 DefineTextureWnd();\r
1598 break;\r
1599 //--------------------------------------------------// \r
1600 // 16bit texture load ..\r
1601 case 2:\r
1602 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1603\r
1604 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1605 LineOffset = 1024 - (g_x2-g_x1+1); \r
1606\r
1607 for(column=g_y1;column<=g_y2;column++)\r
1608 {\r
1609 for(row=g_x1;row<=g_x2;row++)\r
1610 *ta++=LTCOL(*wSRCPtr++);\r
1611 wSRCPtr+=LineOffset;\r
1612 }\r
1613\r
1614 DefineTextureWnd();\r
1615 break;\r
1616 //--------------------------------------------------// \r
1617 // others are not possible !\r
1618 }\r
1619}\r
1620\r
1621////////////////////////////////////////////////////////////////////////\r
1622////////////////////////////////////////////////////////////////////////\r
1623////////////////////////////////////////////////////////////////////////\r
1624////////////////////////////////////////////////////////////////////////\r
1625\r
1626void UploadTexWndPal(int mode,short cx,short cy)\r
1627{\r
1628 unsigned int i,iSize;\r
1629 unsigned short * wSrcPtr;\r
1630 unsigned long * ta=(unsigned long *)texturepart;\r
1631\r
1632 wSrcPtr=psxVuw+cx+(cy*1024);\r
1633 if(mode==0) i=4; else i=64;\r
1634 iSize=i<<2;\r
1635 ubOpaqueDraw=0;\r
1636\r
1637 do\r
1638 {\r
1639 *ta =PALCOL(*wSrcPtr);\r
1640 *(ta+1)=PALCOL(*(wSrcPtr+1));\r
1641 *(ta+2)=PALCOL(*(wSrcPtr+2));\r
1642 *(ta+3)=PALCOL(*(wSrcPtr+3));\r
1643 ta+=4;wSrcPtr+=4;i--;\r
1644 }\r
1645 while(i);\r
1646\r
1647/* (*glColorTableEXTEx)(GL_TEXTURE_2D,GL_RGBA8,iSize,\r
1648 GL_RGBA,GL_UNSIGNED_BYTE,texturepart);\r
1649*/}\r
1650\r
1651////////////////////////////////////////////////////////////////////////\r
1652\r
1653void DefinePalTextureWnd(void)\r
1654{\r
1655 if(gTexName==0)\r
1656 glGenTextures(1, &gTexName);\r
9f58cabb 1657 glError();\r
ce879073 1658 glBindTexture(GL_TEXTURE_2D, gTexName);\r
9f58cabb 1659 glError();\r
ce879073 1660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\r
1661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\r
9f58cabb 1662 glError();\r
ce879073 1663{\r
1664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);\r
1665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);\r
1666 }\r
9f58cabb 1667 glError();\r
ce879073 1668 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, \r
1669 TWin.Position.x1, \r
1670 TWin.Position.y1, \r
1671 0, GL_RGBA, GL_UNSIGNED_BYTE,texturepart);\r
9f58cabb 1672 glError();\r
1673 //LOGE("DefinePalTextureWnd x:%d y:%d",TWin.Position.x1,TWin.Position.y1);\r
ce879073 1674}\r
1675\r
1676///////////////////////////////////////////////////////\r
1677\r
1678void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)\r
1679{\r
1680 unsigned long start,row,column,j,sxh,sxm;\r
677ea103 1681 unsigned char *ta;\r
1682 unsigned char *cSRCPtr;\r
ce879073 1683 unsigned long LineOffset;\r
1684 int pmult=pageid/16;\r
1685\r
677ea103 1686 ta=(unsigned char *)texturepart;\r
ce879073 1687\r
1688 switch(mode)\r
1689 {\r
1690 //--------------------------------------------------// \r
1691 // 4bit texture load ..\r
1692 case 0:\r
1693 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1694\r
1695 sxm=g_x1&1;sxh=g_x1>>1;\r
1696 if(sxm) j=g_x1+1; else j=g_x1;\r
1697 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1698 for(column=g_y1;column<=g_y2;column++)\r
1699 {\r
1700 cSRCPtr = psxVub + start + (2048*column) + sxh;\r
1701 \r
1702 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);\r
1703 \r
1704 for(row=j;row<=g_x2;row++)\r
1705 {\r
1706 *ta++=(*cSRCPtr & 0xF); row++;\r
1707 if(row<=g_x2) *ta++=((*cSRCPtr >> 4) & 0xF); \r
1708 cSRCPtr++;\r
1709 }\r
1710 }\r
1711\r
1712 DefinePalTextureWnd();\r
1713 break;\r
1714 //--------------------------------------------------// \r
1715 // 8bit texture load ..\r
1716 case 1:\r
1717 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1718\r
1719 // not using a lookup table here... speeds up smaller texture areas\r
1720 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1721 LineOffset = 2048 - (g_x2-g_x1+1); \r
1722\r
1723 for(column=g_y1;column<=g_y2;column++)\r
1724 {\r
1725 for(row=g_x1;row<=g_x2;row++)\r
1726 *ta++=*cSRCPtr++;\r
1727 cSRCPtr+=LineOffset;\r
1728 }\r
1729\r
1730 DefinePalTextureWnd();\r
1731 break;\r
1732 }\r
1733 UploadTexWndPal(mode,cx,cy);\r
1734}\r
1735\r
1736////////////////////////////////////////////////////////////////////////\r
1737\r
1738void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)\r
1739{\r
1740 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;\r
677ea103 1741 unsigned char *ta,s;\r
1742 unsigned char *cSRCPtr,*cOSRCPtr;\r
ce879073 1743 unsigned long LineOffset;\r
1744 int pmult=pageid/16;\r
1745\r
1746 ldxo=TWin.Position.x1-TWin.OPosition.x1;\r
1747 ldy =TWin.Position.y1-TWin.OPosition.y1;\r
1748\r
677ea103 1749 ta=(unsigned char *)texturepart;\r
ce879073 1750\r
1751 switch(mode)\r
1752 {\r
1753 //--------------------------------------------------// \r
1754 // 4bit texture load ..\r
1755 case 0:\r
1756 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1757\r
1758 sxm=g_x1&1;sxh=g_x1>>1;\r
1759 if(sxm) j=g_x1+1; else j=g_x1;\r
1760 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1761 for(column=g_y1;column<=g_y2;column++)\r
1762 {\r
1763 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1764 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);\r
1765 \r
1766 for(row=j;row<=g_x2-ldxo;row++)\r
1767 {\r
1768 s=(*cSRCPtr & 0xF);\r
1769 *ta++=s;\r
1770 if(ldx) {*ta++=s;ldx--;}\r
1771 row++;\r
1772 if(row<=g_x2-ldxo) \r
1773 {\r
1774 s=((*cSRCPtr >> 4) & 0xF);\r
1775 *ta++=s; \r
1776 if(ldx) {*ta++=s;ldx--;}\r
1777 }\r
1778 cSRCPtr++;\r
1779 }\r
1780 if(ldy && column&1) \r
1781 {ldy--;cSRCPtr = cOSRCPtr;}\r
1782 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;\r
1783 }\r
1784\r
1785 DefinePalTextureWnd();\r
1786 break;\r
1787 //--------------------------------------------------// \r
1788 // 8bit texture load ..\r
1789 case 1:\r
1790 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1791\r
1792 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1793 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo; \r
1794\r
1795 for(column=g_y1;column<=g_y2;column++)\r
1796 {\r
1797 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1798 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1799 {\r
1800 s=*cSRCPtr++;\r
1801 *ta++=s;\r
1802 if(ldx) {*ta++=s;ldx--;}\r
1803 }\r
1804 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}\r
1805 else cSRCPtr+=LineOffset;\r
1806 }\r
1807\r
1808 DefinePalTextureWnd();\r
1809 break;\r
1810 }\r
1811 UploadTexWndPal(mode,cx,cy);\r
1812}\r
1813\r
1814////////////////////////////////////////////////////////////////////////\r
1815// tex window: main selecting, cache handler included\r
1816////////////////////////////////////////////////////////////////////////\r
1817\r
1818GLuint LoadTextureWnd(long pageid,long TextureMode,unsigned long GivenClutId)\r
1819{\r
1820 textureWndCacheEntry * ts, * tsx=NULL;\r
1821 int i;short cx,cy;\r
1822 EXLong npos;\r
1823\r
1824 npos.c[3]=TWin.Position.x0;\r
1825 npos.c[2]=TWin.OPosition.x1;\r
1826 npos.c[1]=TWin.Position.y0;\r
1827 npos.c[0]=TWin.OPosition.y1;\r
1828\r
1829 g_x1=TWin.Position.x0;g_x2=g_x1+TWin.Position.x1-1;\r
1830 g_y1=TWin.Position.y0;g_y2=g_y1+TWin.Position.y1-1;\r
1831\r
1832 if(TextureMode==2) {GivenClutId=0;cx=cy=0;}\r
1833 else \r
1834 {\r
1835 cx=((GivenClutId << 4) & 0x3F0);cy=((GivenClutId >> 6) & CLUTYMASK);\r
1836 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30);\r
1837\r
1838 // palette check sum\r
1839 {\r
1840 unsigned long l=0,row;\r
1841 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));\r
1842 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;\r
1843 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;\r
1844 l=(l+HIWORD(l))&0x3fffL;\r
1845 GivenClutId|=(l<<16);\r
1846 }\r
1847\r
1848 }\r
1849\r
1850 ts=wcWndtexStore;\r
1851\r
1852 for(i=0;i<iMaxTexWnds;i++,ts++)\r
1853 {\r
1854 if(ts->used)\r
1855 {\r
1856 if(ts->pos.l==npos.l &&\r
1857 ts->pageid==pageid &&\r
1858 ts->textureMode==TextureMode)\r
1859 {\r
1860 if(ts->ClutID==GivenClutId)\r
1861 {\r
1862 ubOpaqueDraw=ts->Opaque;\r
1863 return ts->texname;\r
1864 }\r
1865 }\r
1866 }\r
1867 else tsx=ts;\r
1868 }\r
1869\r
1870 if(!tsx) \r
1871 {\r
1872 if(iMaxTexWnds==iTexWndLimit)\r
1873 {\r
1874 tsx=wcWndtexStore+iTexWndTurn;\r
1875 iTexWndTurn++; \r
1876 if(iTexWndTurn==iTexWndLimit) iTexWndTurn=0;\r
1877 }\r
1878 else\r
1879 {\r
1880 tsx=wcWndtexStore+iMaxTexWnds;\r
1881 iMaxTexWnds++;\r
1882 }\r
1883 }\r
1884\r
1885 gTexName=tsx->texname;\r
1886\r
1887 if(TWin.OPosition.y1==TWin.Position.y1 &&\r
1888 TWin.OPosition.x1==TWin.Position.x1)\r
1889 {\r
1890 LoadWndTexturePage(pageid,TextureMode,cx,cy);\r
1891 } \r
1892 else\r
1893 {\r
1894 LoadStretchWndTexturePage(pageid,TextureMode,cx,cy);\r
1895 }\r
1896\r
1897 tsx->Opaque=ubOpaqueDraw;\r
1898 tsx->pos.l=npos.l;\r
1899 tsx->ClutID=GivenClutId;\r
1900 tsx->pageid=pageid;\r
1901 tsx->textureMode=TextureMode;\r
1902 tsx->texname=gTexName;\r
1903 tsx->used=1;\r
1904 \r
1905 return gTexName;\r
1906}\r
1907\r
1908/////////////////////////////////////////////////////////////////////////////\r
1909/////////////////////////////////////////////////////////////////////////////\r
1910/////////////////////////////////////////////////////////////////////////////\r
1911\r
1912////////////////////////////////////////////////////////////////////////\r
1913// movie texture: define\r
1914////////////////////////////////////////////////////////////////////////\r
1915\r
1916void DefinePackedTextureMovie(void)\r
1917{\r
1918 if(gTexMovieName==0)\r
1919 {\r
9f58cabb 1920 glEnable(GL_TEXTURE_2D);\r
1921 glGenTextures(1, &gTexMovieName); glError();\r
ce879073 1922 gTexName=gTexMovieName;\r
9f58cabb 1923 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1924\r
9f58cabb 1925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
1926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
ce879073 1927\r
1928 if(!bUseFastMdec) \r
1929 {\r
9f58cabb 1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();\r
1931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();\r
ce879073 1932 }\r
1933 else\r
1934 {\r
9f58cabb 1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
1936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 1937 }\r
1938 \r
1939 glTexImage2D(GL_TEXTURE_2D, 0, //giWantedRGBA, \r
1940 GL_RGBA,\r
9f58cabb 1941 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
ce879073 1942 }\r
1943 else \r
1944 {\r
9f58cabb 1945 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1946 }\r
1947\r
1948 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,\r
1949 (xrMovieArea.x1-xrMovieArea.x0), \r
1950 (xrMovieArea.y1-xrMovieArea.y0), \r
1951 GL_RGBA,\r
1952 GL_UNSIGNED_SHORT,\r
9f58cabb 1953 texturepart); glError();\r
1954 //LOGE("DefinePackedTextureMovie x:%d y:%d",(xrMovieArea.x1-xrMovieArea.x0),(xrMovieArea.y1-xrMovieArea.y0));\r
1955\r
ce879073 1956}\r
1957\r
1958////////////////////////////////////////////////////////////////////////\r
1959\r
1960void DefineTextureMovie(void)\r
1961{\r
1962 if(gTexMovieName==0)\r
1963 {\r
9f58cabb 1964 glGenTextures(1, &gTexMovieName); glError();\r
ce879073 1965 gTexName=gTexMovieName;\r
9f58cabb 1966 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1967\r
9f58cabb 1968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
1969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
ce879073 1970 \r
1971 if(!bUseFastMdec) \r
1972 {\r
9f58cabb 1973 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();\r
1974 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();\r
ce879073 1975 }\r
1976 else\r
1977 {\r
9f58cabb 1978 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
1979 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 1980 }\r
1981\r
9f58cabb 1982 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
ce879073 1983 }\r
1984 else \r
1985 {\r
9f58cabb 1986 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1987 }\r
1988\r
1989 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,\r
1990 (xrMovieArea.x1-xrMovieArea.x0), \r
1991 (xrMovieArea.y1-xrMovieArea.y0), \r
9f58cabb 1992 GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
1993 //LOGE("DefineTextureMovie x:%d y:%d",(xrMovieArea.x1-xrMovieArea.x0),(xrMovieArea.y1-xrMovieArea.y0));\r
ce879073 1994}\r
1995\r
1996////////////////////////////////////////////////////////////////////////\r
1997// movie texture: load\r
1998////////////////////////////////////////////////////////////////////////\r
1999\r
2000#define MRED(x) ((x>>3) & 0x1f)\r
2001#define MGREEN(x) ((x>>6) & 0x3e0)\r
2002#define MBLUE(x) ((x>>9) & 0x7c00)\r
2003\r
2004#define XMGREEN(x) ((x>>5) & 0x07c0)\r
2005#define XMRED(x) ((x<<8) & 0xf800)\r
2006#define XMBLUE(x) ((x>>18) & 0x003e)\r
2007\r
2008////////////////////////////////////////////////////////////////////////\r
2009// movie texture: load\r
2010////////////////////////////////////////////////////////////////////////\r
2011\r
677ea103 2012unsigned char * LoadDirectMovieFast(void)\r
ce879073 2013{\r
2014 long row,column;\r
2015 unsigned int startxy;\r
2016\r
2017 unsigned long * ta=(unsigned long *)texturepart;\r
2018\r
2019 if(PSXDisplay.RGB24)\r
2020 {\r
677ea103 2021 unsigned char * pD;\r
ce879073 2022\r
2023 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;\r
2024\r
2025 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)\r
2026 {\r
677ea103 2027 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2028 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2029 {\r
2030 *ta++=*((unsigned long *)pD)|0xff000000;\r
2031 pD+=3;\r
2032 }\r
2033 }\r
2034 }\r
2035 else\r
2036 {\r
2037 unsigned long (*LTCOL)(unsigned long);\r
2038\r
2039 LTCOL=XP8RGBA_0;//TCF[0];\r
2040\r
2041 ubOpaqueDraw=0;\r
2042\r
2043 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2044 {\r
2045 startxy=((1024)*column)+xrMovieArea.x0;\r
2046 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2047 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2048 }\r
2049 }\r
2050 \r
2051 return texturepart;\r
2052}\r
2053\r
2054////////////////////////////////////////////////////////////////////////\r
2055\r
2056GLuint LoadTextureMovieFast(void)\r
2057{\r
2058 long row,column;\r
2059 unsigned int start,startxy;\r
2060\r
2061{\r
2062 if(PSXDisplay.RGB24)\r
2063 {\r
677ea103 2064 unsigned char * pD;\r
ce879073 2065 unsigned long * ta=(unsigned long *)texturepart;\r
2066\r
2067 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;\r
2068\r
2069 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)\r
2070 {\r
2071 //startxy=((1024)*column)+xrMovieArea.x0;\r
677ea103 2072 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2073 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2074 {\r
2075 *ta++=*((unsigned long *)pD)|0xff000000;\r
2076 pD+=3;\r
2077 }\r
2078 }\r
2079 }\r
2080 else\r
2081 {\r
2082 unsigned long (*LTCOL)(unsigned long);\r
2083 unsigned long *ta;\r
2084\r
2085 LTCOL=XP8RGBA_0;//TCF[0];\r
2086\r
2087 ubOpaqueDraw=0;\r
2088 ta=(unsigned long *)texturepart;\r
2089\r
2090 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2091 {\r
2092 startxy=((1024)*column)+xrMovieArea.x0;\r
2093 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2094 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2095 }\r
2096 }\r
2097 DefineTextureMovie();\r
2098 }\r
2099 return gTexName; \r
2100}\r
2101\r
2102////////////////////////////////////////////////////////////////////////\r
2103\r
2104GLuint LoadTextureMovie(void)\r
2105{\r
2106 short row,column,dx;\r
2107 unsigned int startxy;\r
2108 BOOL b_X,b_Y;\r
2109\r
2110 if(bUseFastMdec) return LoadTextureMovieFast();\r
2111\r
2112 b_X=FALSE;b_Y=FALSE;\r
2113\r
2114 if((xrMovieArea.x1-xrMovieArea.x0)<255) b_X=TRUE;\r
2115 if((xrMovieArea.y1-xrMovieArea.y0)<255) b_Y=TRUE;\r
2116\r
2117{\r
2118 if(PSXDisplay.RGB24)\r
2119 {\r
677ea103 2120 unsigned char * pD;\r
ce879073 2121 unsigned long * ta=(unsigned long *)texturepart;\r
2122\r
2123 if(b_X)\r
2124 {\r
2125 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2126 {\r
2127 startxy=((1024)*column)+xrMovieArea.x0;\r
677ea103 2128 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2129 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2130 {\r
2131 *ta++=*((unsigned long *)pD)|0xff000000;\r
2132 pD+=3;\r
2133 }\r
2134 *ta++=*(ta-1);\r
2135 }\r
2136 if(b_Y)\r
2137 {\r
2138 dx=xrMovieArea.x1-xrMovieArea.x0+1;\r
2139 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2140 *ta++=*(ta-dx);\r
2141 *ta++=*(ta-1);\r
2142 }\r
2143 }\r
2144 else\r
2145 {\r
2146 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2147 {\r
2148 startxy=((1024)*column)+xrMovieArea.x0;\r
677ea103 2149 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2150 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2151 {\r
2152 *ta++=*((unsigned long *)pD)|0xff000000;\r
2153 pD+=3;\r
2154 }\r
2155 }\r
2156 if(b_Y)\r
2157 {\r
2158 dx=xrMovieArea.x1-xrMovieArea.x0;\r
2159 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2160 *ta++=*(ta-dx);\r
2161 }\r
2162 }\r
2163 }\r
2164 else\r
2165 {\r
2166 unsigned long (*LTCOL)(unsigned long);\r
2167 unsigned long *ta;\r
2168\r
2169 LTCOL=XP8RGBA_0;//TCF[0];\r
2170\r
2171 ubOpaqueDraw=0;\r
2172 ta=(unsigned long *)texturepart;\r
2173\r
2174 if(b_X)\r
2175 {\r
2176 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2177 {\r
2178 startxy=((1024)*column)+xrMovieArea.x0;\r
2179 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2180 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2181 *ta++=*(ta-1);\r
2182 }\r
2183\r
2184 if(b_Y)\r
2185 {\r
2186 dx=xrMovieArea.x1-xrMovieArea.x0+1;\r
2187 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2188 *ta++=*(ta-dx);\r
2189 *ta++=*(ta-1);\r
2190 }\r
2191 }\r
2192 else\r
2193 {\r
2194 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2195 {\r
2196 startxy=((1024)*column)+xrMovieArea.x0;\r
2197 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2198 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2199 }\r
2200\r
2201 if(b_Y)\r
2202 {\r
2203 dx=xrMovieArea.x1-xrMovieArea.x0;\r
2204 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2205 *ta++=*(ta-dx);\r
2206 }\r
2207 }\r
2208 }\r
2209\r
2210 xrMovieArea.x1+=b_X;xrMovieArea.y1+=b_Y;\r
2211 DefineTextureMovie();\r
2212 xrMovieArea.x1-=b_X;xrMovieArea.y1-=b_Y;\r
2213 }\r
2214 return gTexName; \r
2215}\r
2216\r
2217/////////////////////////////////////////////////////////////////////////////\r
2218/////////////////////////////////////////////////////////////////////////////\r
2219/////////////////////////////////////////////////////////////////////////////\r
2220\r
2221GLuint BlackFake15BitTexture(void)\r
2222{\r
2223 long pmult;short x1,x2,y1,y2;\r
2224\r
2225 if(PSXDisplay.InterlacedTest) return 0;\r
2226 \r
2227 pmult=GlobalTexturePage/16;\r
2228 x1=gl_ux[7];\r
2229 x2=gl_ux[6]-gl_ux[7];\r
2230 y1=gl_ux[5];\r
2231 y2=gl_ux[4]-gl_ux[5];\r
2232\r
2233 if(iSpriteTex)\r
2234 {\r
2235 if(x2<255) x2++;\r
2236 if(y2<255) y2++;\r
2237 }\r
2238\r
2239 y1+=pmult*256;\r
2240 x1+=((GlobalTexturePage-16*pmult)<<6);\r
2241\r
2242 if( FastCheckAgainstFrontScreen(x1,y1,x2,y2)\r
2243 || FastCheckAgainstScreen(x1,y1,x2,y2))\r
2244 {\r
2245 if(!gTexFrameName)\r
2246 {\r
9f58cabb 2247 glGenTextures(1, &gTexFrameName); glError();\r
ce879073 2248 gTexName=gTexFrameName;\r
9f58cabb 2249 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2250\r
9f58cabb 2251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
2252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
2253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
2254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 2255 \r
2256 {\r
2257 unsigned long * ta=(unsigned long *)texturepart;\r
2258 for(y1=0;y1<=4;y1++)\r
2259 for(x1=0;x1<=4;x1++)\r
2260 *ta++=0xff000000;\r
2261 }\r
9f58cabb 2262 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
2263\r
ce879073 2264 }\r
2265 else\r
2266 {\r
2267 gTexName=gTexFrameName;\r
9f58cabb 2268 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2269 }\r
9f58cabb 2270 //LOGE("BlackFake15BitTexture x:%d y:%d",4,4);\r
ce879073 2271 ubOpaqueDraw=0;\r
2272\r
2273 return (GLuint)gTexName;\r
2274 }\r
2275 return 0;\r
2276}\r
2277\r
2278/////////////////////////////////////////////////////////////////////////////\r
2279\r
2280BOOL bFakeFrontBuffer=FALSE;\r
2281BOOL bIgnoreNextTile =FALSE;\r
2282\r
2283int iFTex=512;\r
2284\r
2285GLuint Fake15BitTexture(void)\r
2286{\r
2287 long pmult;short x1,x2,y1,y2;int iYAdjust;\r
2288 float ScaleX,ScaleY;RECT rSrc;\r
2289\r
2290 if(iFrameTexType==1) return BlackFake15BitTexture();\r
2291 if(PSXDisplay.InterlacedTest) return 0;\r
2292 \r
2293 pmult=GlobalTexturePage/16;\r
2294 x1=gl_ux[7];\r
2295 x2=gl_ux[6]-gl_ux[7];\r
2296 y1=gl_ux[5];\r
2297 y2=gl_ux[4]-gl_ux[5];\r
2298\r
2299 y1+=pmult*256;\r
2300 x1+=((GlobalTexturePage-16*pmult)<<6);\r
2301\r
2302 if(iFrameTexType==3)\r
2303 {\r
2304 if(iFrameReadType==4) return 0;\r
2305\r
2306 if(!FastCheckAgainstFrontScreen(x1,y1,x2,y2) &&\r
2307 !FastCheckAgainstScreen(x1,y1,x2,y2))\r
2308 return 0;\r
2309\r
2310 if(bFakeFrontBuffer) bIgnoreNextTile=TRUE;\r
2311 CheckVRamReadEx(x1,y1,x1+x2,y1+y2);\r
2312 return 0;\r
2313 }\r
2314\r
2315 /////////////////////////\r
2316\r
2317 if(FastCheckAgainstFrontScreen(x1,y1,x2,y2))\r
2318 {\r
2319 x1-=PSXDisplay.DisplayPosition.x;\r
2320 y1-=PSXDisplay.DisplayPosition.y;\r
2321 }\r
2322 else\r
2323 if(FastCheckAgainstScreen(x1,y1,x2,y2))\r
2324 {\r
2325 x1-=PreviousPSXDisplay.DisplayPosition.x;\r
2326 y1-=PreviousPSXDisplay.DisplayPosition.y;\r
2327 }\r
2328 else return 0;\r
2329\r
2330 bDrawMultiPass = FALSE;\r
2331\r
2332 if(!gTexFrameName)\r
2333 {\r
677ea103 2334 char * p;\r
ce879073 2335\r
2336 if(iResX>1280 || iResY>1024) iFTex=2048;\r
2337 else\r
2338 if(iResX>640 || iResY>480) iFTex=1024;\r
2339 else iFTex=512; \r
2340\r
9f58cabb 2341 glGenTextures(1, &gTexFrameName); glError();\r
ce879073 2342 gTexName=gTexFrameName;\r
9f58cabb 2343 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2344\r
9f58cabb 2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
2346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
2347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
2348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 2349\r
677ea103 2350 p=(char *)malloc(iFTex*iFTex*4);\r
ce879073 2351 memset(p,0,iFTex*iFTex*4);\r
9f58cabb 2352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iFTex, iFTex, 0, GL_RGBA, GL_UNSIGNED_BYTE, p); glError();\r
ce879073 2353 free(p);\r
2354\r
2355 glGetError();\r
2356 }\r
2357 else \r
2358 {\r
2359 gTexName=gTexFrameName;\r
9f58cabb 2360 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2361 }\r
9f58cabb 2362 //LOGE("Fake15BitTexture x:%d y:%d",iFTex,iFTex);\r
ce879073 2363 x1+=PreviousPSXDisplay.Range.x0;\r
2364 y1+=PreviousPSXDisplay.Range.y0;\r
2365\r
2366 if(PSXDisplay.DisplayMode.x)\r
2367 ScaleX=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;\r
2368 else ScaleX=1.0f;\r
2369 if(PSXDisplay.DisplayMode.y)\r
2370 ScaleY=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;\r
2371 else ScaleY=1.0f;\r
2372\r
2373 rSrc.left =max(x1*ScaleX,0);\r
2374 rSrc.right =min((x1+x2)*ScaleX+0.99f,iResX-1);\r
2375 rSrc.top =max(y1*ScaleY,0);\r
2376 rSrc.bottom=min((y1+y2)*ScaleY+0.99f,iResY-1);\r
2377\r
2378 iYAdjust=(y1+y2)-PSXDisplay.DisplayMode.y;\r
2379 if(iYAdjust>0)\r
2380 iYAdjust=(int)((float)iYAdjust*ScaleY)+1;\r
2381 else iYAdjust=0;\r
2382 \r
2383 gl_vy[0]=255-gl_vy[0];\r
2384 gl_vy[1]=255-gl_vy[1];\r
2385 gl_vy[2]=255-gl_vy[2];\r
2386 gl_vy[3]=255-gl_vy[3];\r
2387\r
2388 y1=min(gl_vy[0],min(gl_vy[1],min(gl_vy[2],gl_vy[3])));\r
2389\r
2390 gl_vy[0]-=y1;\r
2391 gl_vy[1]-=y1;\r
2392 gl_vy[2]-=y1;\r
2393 gl_vy[3]-=y1;\r
2394 gl_ux[0]-=gl_ux[7];\r
2395 gl_ux[1]-=gl_ux[7];\r
2396 gl_ux[2]-=gl_ux[7];\r
2397 gl_ux[3]-=gl_ux[7];\r
2398\r
2399 ScaleX*=256.0f/((float)(iFTex));\r
2400 ScaleY*=256.0f/((float)(iFTex));\r
2401\r
2402 y1=((float)gl_vy[0]*ScaleY); if(y1>255) y1=255;\r
2403 gl_vy[0]=y1;\r
2404 y1=((float)gl_vy[1]*ScaleY); if(y1>255) y1=255;\r
2405 gl_vy[1]=y1;\r
2406 y1=((float)gl_vy[2]*ScaleY); if(y1>255) y1=255;\r
2407 gl_vy[2]=y1;\r
2408 y1=((float)gl_vy[3]*ScaleY); if(y1>255) y1=255;\r
2409 gl_vy[3]=y1;\r
2410\r
2411 x1=((float)gl_ux[0]*ScaleX); if(x1>255) x1=255;\r
2412 gl_ux[0]=x1;\r
2413 x1=((float)gl_ux[1]*ScaleX); if(x1>255) x1=255;\r
2414 gl_ux[1]=x1;\r
2415 x1=((float)gl_ux[2]*ScaleX); if(x1>255) x1=255;\r
2416 gl_ux[2]=x1;\r
2417 x1=((float)gl_ux[3]*ScaleX); if(x1>255) x1=255;\r
2418 gl_ux[3]=x1;\r
2419\r
2420 x1=rSrc.right-rSrc.left;\r
2421 if(x1<=0) x1=1;\r
2422 if(x1>iFTex) x1=iFTex;\r
2423\r
2424 y1=rSrc.bottom-rSrc.top;\r
2425 if(y1<=0) y1=1;\r
2426 if(y1+iYAdjust>iFTex) y1=iFTex-iYAdjust;\r
2427\r
2428\r
2429 glCopyTexSubImage2D( GL_TEXTURE_2D, 0, \r
2430 0,\r
2431 iYAdjust,\r
2432 rSrc.left+rRatioRect.left,\r
2433 iResY-rSrc.bottom-rRatioRect.top,\r
9f58cabb 2434 x1,y1); glError();\r
ce879073 2435\r
2436 if(glGetError()) \r
2437 {\r
677ea103 2438 char * p=(char *)malloc(iFTex*iFTex*4);\r
ce879073 2439 memset(p,0,iFTex*iFTex*4);\r
2440 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, iFTex, iFTex,\r
9f58cabb 2441 GL_RGBA, GL_UNSIGNED_BYTE, p); glError();\r
ce879073 2442 free(p);\r
2443 }\r
2444\r
2445 \r
2446 ubOpaqueDraw=0;\r
2447\r
2448 if(iSpriteTex)\r
2449 {\r
2450 sprtW=gl_ux[1]-gl_ux[0]; \r
2451 sprtH=-(gl_vy[0]-gl_vy[2]);\r
2452 }\r
2453\r
2454 return (GLuint)gTexName;\r
2455}\r
2456\r
2457/////////////////////////////////////////////////////////////////////////////\r
2458/////////////////////////////////////////////////////////////////////////////\r
2459/////////////////////////////////////////////////////////////////////////////\r
2460//\r
2461// load texture part (unpacked)\r
2462//\r
2463/////////////////////////////////////////////////////////////////////////////\r
2464/////////////////////////////////////////////////////////////////////////////\r
2465/////////////////////////////////////////////////////////////////////////////\r
2466\r
2467void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)\r
2468{\r
2469 unsigned long start,row,column,j,sxh,sxm;\r
2470 unsigned int palstart;\r
2471 unsigned long *px,*pa,*ta;\r
677ea103 2472 unsigned char *cSRCPtr;\r
ce879073 2473 unsigned short *wSRCPtr;\r
2474 unsigned long LineOffset;\r
2475 unsigned long x2a,xalign=0;\r
2476 unsigned long x1=gl_ux[7];\r
2477 unsigned long x2=gl_ux[6];\r
2478 unsigned long y1=gl_ux[5];\r
2479 unsigned long y2=gl_ux[4];\r
2480 unsigned long dx=x2-x1+1;\r
2481 unsigned long dy=y2-y1+1;\r
2482 int pmult=pageid/16;\r
2483 unsigned long (*LTCOL)(unsigned long);\r
2484 unsigned int a,r,g,b,cnt,h;\r
2485 unsigned long scol[8];\r
2486 \r
2487 LTCOL=TCF[DrawSemiTrans];\r
2488\r
2489 pa=px=(unsigned long *)ubPaletteBuffer;\r
2490 ta=(unsigned long *)texturepart;\r
2491 palstart=cx+(cy<<10);\r
2492\r
2493 ubOpaqueDraw=0;\r
2494\r
2495 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}\r
2496 if(XTexS) {ta+=1;xalign=2;}\r
2497\r
2498 switch(mode)\r
2499 {\r
2500 //--------------------------------------------------// \r
2501 // 4bit texture load ..\r
2502 case 0:\r
2503 if(GlobalTextIL)\r
2504 {\r
2505 unsigned int TXV,TXU,n_xi,n_yi;\r
2506\r
2507 wSRCPtr=psxVuw+palstart;\r
2508\r
2509 row=4;do\r
2510 {\r
2511 *px =LTCOL(*wSRCPtr);\r
2512 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2513 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2514 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2515 row--;px+=4;wSRCPtr+=4;\r
2516 }\r
2517 while (row);\r
2518\r
2519 for(TXV=y1;TXV<=y2;TXV++)\r
2520 {\r
2521 for(TXU=x1;TXU<=x2;TXU++)\r
2522 {\r
2523 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
2524 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
2525\r
2526 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
2527 }\r
2528 ta+=xalign;\r
2529 }\r
2530 break;\r
2531 }\r
2532\r
2533 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2534 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
2535\r
2536 wSRCPtr=psxVuw+palstart;\r
2537\r
2538 row=4;do\r
2539 {\r
2540 *px =LTCOL(*wSRCPtr);\r
2541 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2542 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2543 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2544 row--;px+=4;wSRCPtr+=4;\r
2545 }\r
2546 while (row);\r
2547\r
2548 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;\r
2549 sxm=x1&1;sxh=x1>>1;\r
2550 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;\r
2551 for(column=y1;column<=y2;column++)\r
2552 {\r
2553 cSRCPtr = psxVub + start + (column<<11) + sxh;\r
2554 \r
2555 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
2556\r
2557 for(row=j;row<x2a;row+=2)\r
2558 {\r
2559 *ta =*(pa+(*cSRCPtr & 0xF)); \r
2560 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
2561 cSRCPtr++;ta+=2;\r
2562 }\r
2563\r
2564 if(row<=x2) \r
2565 {\r
2566 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;\r
2567 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));\r
2568 }\r
2569\r
2570 ta+=xalign;\r
2571 }\r
2572\r
2573 break;\r
2574 //--------------------------------------------------// \r
2575 // 8bit texture load ..\r
2576 case 1:\r
2577 if(GlobalTextIL)\r
2578 {\r
2579 unsigned int TXV,TXU,n_xi,n_yi;\r
2580\r
2581 wSRCPtr=psxVuw+palstart;\r
2582\r
2583 row=64;do\r
2584 {\r
2585 *px =LTCOL(*wSRCPtr);\r
2586 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2587 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2588 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2589 row--;px+=4;wSRCPtr+=4;\r
2590 }\r
2591 while (row);\r
2592\r
2593 for(TXV=y1;TXV<=y2;TXV++)\r
2594 {\r
2595 for(TXU=x1;TXU<=x2;TXU++)\r
2596 {\r
2597 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
2598 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
2599\r
2600 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
2601 }\r
2602 ta+=xalign;\r
2603 }\r
2604\r
2605 break;\r
2606 }\r
2607\r
2608 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2609\r
2610 cSRCPtr = psxVub + start + (y1<<11) + x1;\r
2611 LineOffset = 2048 - dx; \r
2612\r
2613 if(dy*dx>384)\r
2614 {\r
2615 wSRCPtr=psxVuw+palstart;\r
2616\r
2617 row=64;do\r
2618 {\r
2619 *px =LTCOL(*wSRCPtr);\r
2620 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2621 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2622 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2623 row--;px+=4;wSRCPtr+=4;\r
2624 }\r
2625 while (row);\r
2626\r
2627 column=dy;do \r
2628 {\r
2629 row=dx;\r
2630 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);\r
2631 ta+=xalign;\r
2632 cSRCPtr+=LineOffset;column--;\r
2633 }\r
2634 while(column);\r
2635 }\r
2636 else\r
2637 {\r
2638 wSRCPtr=psxVuw+palstart;\r
2639\r
2640 column=dy;do \r
2641 {\r
2642 row=dx;\r
2643 do {*ta++=LTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);\r
2644 ta+=xalign;\r
2645 cSRCPtr+=LineOffset;column--;\r
2646 }\r
2647 while(column);\r
2648 }\r
2649\r
2650 break;\r
2651 //--------------------------------------------------// \r
2652 // 16bit texture load ..\r
2653 case 2:\r
2654 start=((pageid-16*pmult)<<6)+262144*pmult;\r
2655\r
2656 wSRCPtr = psxVuw + start + (y1<<10) + x1;\r
2657 LineOffset = 1024 - dx; \r
2658\r
2659 column=dy;do \r
2660 {\r
2661 row=dx;\r
2662 do {*ta++=LTCOL(*wSRCPtr++);row--;} while(row);\r
2663 ta+=xalign;\r
2664 wSRCPtr+=LineOffset;column--;\r
2665 }\r
2666 while(column);\r
2667\r
2668 break;\r
2669 //--------------------------------------------------//\r
2670 // others are not possible !\r
2671 }\r
2672\r
2673 x2a=dx+xalign;\r
2674\r
2675 if(YTexS)\r
2676 {\r
2677 ta=(unsigned long *)texturepart;\r
2678 pa=(unsigned long *)texturepart+x2a;\r
2679 row=x2a;do {*ta++=*pa++;row--;} while(row); \r
2680 pa=(unsigned long *)texturepart+dy*x2a;\r
2681 ta=pa+x2a;\r
2682 row=x2a;do {*ta++=*pa++;row--;} while(row);\r
2683 YTexS--;\r
2684 dy+=2;\r
2685 }\r
2686\r
2687 if(XTexS)\r
2688 {\r
2689 ta=(unsigned long *)texturepart;\r
2690 pa=ta+1;\r
2691 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
2692 pa=(unsigned long *)texturepart+dx;\r
2693 ta=pa+1;\r
2694 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
2695 XTexS--;\r
2696 dx+=2;\r
2697 }\r
2698\r
2699 DXTexS=dx;DYTexS=dy;\r
2700\r
2701 if(!iFilterType) {DefineSubTextureSort();return;}\r
2702 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}\r
2703 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)\r
2704 {DefineSubTextureSort();return;}\r
2705\r
2706 ta=(unsigned long *)texturepart;\r
2707 x1=dx-1;\r
2708 y1=dy-1;\r
2709\r
2710 if(bOpaquePass)\r
2711 {\r
2712{\r
2713 for(column=0;column<dy;column++)\r
2714 {\r
2715 for(row=0;row<dx;row++)\r
2716 {\r
2717 if(*ta==0x50000000)\r
2718 {\r
2719 cnt=0;\r
2720\r
2721 if( column && *(ta-dx) !=0x50000000 && *(ta-dx)>>24!=1) scol[cnt++]=*(ta-dx);\r
2722 if(row && *(ta-1) !=0x50000000 && *(ta-1)>>24!=1) scol[cnt++]=*(ta-1);\r
2723 if(row!=x1 && *(ta+1) !=0x50000000 && *(ta+1)>>24!=1) scol[cnt++]=*(ta+1);\r
2724 if( column!=y1 && *(ta+dx) !=0x50000000 && *(ta+dx)>>24!=1) scol[cnt++]=*(ta+dx);\r
2725\r
2726 if(row && column && *(ta-dx-1)!=0x50000000 && *(ta-dx-1)>>24!=1) scol[cnt++]=*(ta-dx-1);\r
2727 if(row!=x1 && column && *(ta-dx+1)!=0x50000000 && *(ta-dx+1)>>24!=1) scol[cnt++]=*(ta-dx+1);\r
2728 if(row && column!=y1 && *(ta+dx-1)!=0x50000000 && *(ta+dx-1)>>24!=1) scol[cnt++]=*(ta+dx-1);\r
2729 if(row!=x1 && column!=y1 && *(ta+dx+1)!=0x50000000 && *(ta+dx+1)>>24!=1) scol[cnt++]=*(ta+dx+1);\r
2730\r
2731 if(cnt)\r
2732 {\r
2733 r=g=b=a=0;\r
2734 for(h=0;h<cnt;h++)\r
2735 {\r
2736 a+=(scol[h]>>24);\r
2737 r+=(scol[h]>>16)&0xff;\r
2738 g+=(scol[h]>>8)&0xff;\r
2739 b+=scol[h]&0xff;\r
2740 }\r
2741 r/=cnt;b/=cnt;g/=cnt;\r
2742\r
2743 *ta=(r<<16)|(g<<8)|b;\r
2744 if(a) *ta|=0x50000000;\r
2745 else *ta|=0x01000000;\r
2746 }\r
2747 }\r
2748 ta++;\r
2749 }\r
2750 }\r
2751 }\r
2752 }\r
2753 else\r
2754 for(column=0;column<dy;column++)\r
2755 {\r
2756 for(row=0;row<dx;row++)\r
2757 {\r
2758 if(*ta==0x00000000)\r
2759 {\r
2760 cnt=0;\r
2761\r
2762 if(row!=x1 && *(ta+1) !=0x00000000) scol[cnt++]=*(ta+1);\r
2763 if( column!=y1 && *(ta+dx) !=0x00000000) scol[cnt++]=*(ta+dx);\r
2764\r
2765 if(cnt)\r
2766 {\r
2767 r=g=b=0;\r
2768 for(h=0;h<cnt;h++)\r
2769 {\r
2770 r+=(scol[h]>>16)&0xff;\r
2771 g+=(scol[h]>>8)&0xff;\r
2772 b+=scol[h]&0xff;\r
2773 }\r
2774 r/=cnt;b/=cnt;g/=cnt;\r
2775 *ta=(r<<16)|(g<<8)|b;\r
2776 }\r
2777 }\r
2778 ta++;\r
2779 }\r
2780 }\r
2781\r
2782 DefineSubTextureSort();\r
2783}\r
2784\r
2785/////////////////////////////////////////////////////////////////////////////\r
2786/////////////////////////////////////////////////////////////////////////////\r
2787/////////////////////////////////////////////////////////////////////////////\r
2788//\r
2789// load texture part (packed)\r
2790//\r
2791/////////////////////////////////////////////////////////////////////////////\r
2792/////////////////////////////////////////////////////////////////////////////\r
2793/////////////////////////////////////////////////////////////////////////////\r
2794\r
2795void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)\r
2796{\r
2797 unsigned long start,row,column,j,sxh,sxm;\r
2798 unsigned int palstart;\r
2799 unsigned short *px,*pa,*ta;\r
677ea103 2800 unsigned char *cSRCPtr;\r
ce879073 2801 unsigned short *wSRCPtr;\r
2802 unsigned long LineOffset;\r
2803 unsigned long x2a,xalign=0;\r
2804 unsigned long x1=gl_ux[7];\r
2805 unsigned long x2=gl_ux[6];\r
2806 unsigned long y1=gl_ux[5];\r
2807 unsigned long y2=gl_ux[4];\r
2808 unsigned long dx=x2-x1+1;\r
2809 unsigned long dy=y2-y1+1;\r
2810 int pmult=pageid/16;\r
2811 unsigned short (*LPTCOL)(unsigned short);\r
2812 unsigned int a,r,g,b,cnt,h;\r
2813 unsigned short scol[8];\r
2814\r
2815 LPTCOL=PTCF[DrawSemiTrans];\r
2816\r
2817 pa=px=(unsigned short *)ubPaletteBuffer;\r
2818 ta=(unsigned short *)texturepart;\r
2819 palstart=cx+(cy<<10);\r
2820\r
2821 ubOpaqueDraw=0;\r
2822\r
2823 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}\r
2824 if(XTexS) {ta+=1;xalign=2;}\r
2825\r
2826 switch(mode)\r
2827 {\r
2828 //--------------------------------------------------// \r
2829 // 4bit texture load ..\r
2830 case 0:\r
2831 if(GlobalTextIL)\r
2832 {\r
2833 unsigned int TXV,TXU,n_xi,n_yi;\r
2834\r
2835 wSRCPtr=psxVuw+palstart;\r
2836 row=4;do\r
2837 {\r
2838 *px =LPTCOL(*wSRCPtr);\r
2839 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2840 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2841 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2842 row--;px+=4;wSRCPtr+=4;\r
2843 }\r
2844 while (row);\r
2845\r
2846 for(TXV=y1;TXV<=y2;TXV++)\r
2847 {\r
2848 for(TXU=x1;TXU<=x2;TXU++)\r
2849 {\r
2850 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
2851 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
2852\r
2853 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
2854 }\r
2855 ta+=xalign;\r
2856 }\r
2857 break;\r
2858 }\r
2859\r
2860 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2861\r
2862 wSRCPtr=psxVuw+palstart;\r
2863 row=4;do\r
2864 {\r
2865 *px =LPTCOL(*wSRCPtr);\r
2866 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2867 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2868 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2869 row--;px+=4;wSRCPtr+=4;\r
2870 }\r
2871 while (row);\r
2872\r
2873 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;\r
2874 sxm=x1&1;sxh=x1>>1;\r
2875 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;\r
2876\r
2877 for(column=y1;column<=y2;column++)\r
2878 {\r
2879 cSRCPtr = psxVub + start + (column<<11) + sxh;\r
2880 \r
2881 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
2882 \r
2883 for(row=j;row<x2a;row+=2)\r
2884 {\r
2885 *ta =*(pa+(*cSRCPtr & 0xF));\r
2886 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
2887 cSRCPtr++;ta+=2;\r
2888 }\r
2889\r
2890 if(row<=x2)\r
2891 {\r
2892 *ta++=*(pa+(*cSRCPtr & 0xF));row++;\r
2893 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));\r
2894 }\r
2895\r
2896 ta+=xalign;\r
2897 }\r
2898 break;\r
2899 //--------------------------------------------------// \r
2900 // 8bit texture load ..\r
2901 case 1:\r
2902 if(GlobalTextIL)\r
2903 {\r
2904 unsigned int TXV,TXU,n_xi,n_yi;\r
2905\r
2906 wSRCPtr=psxVuw+palstart;\r
2907\r
2908 row=64;do\r
2909 {\r
2910 *px =LPTCOL(*wSRCPtr);\r
2911 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2912 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2913 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2914 row--;px+=4;wSRCPtr+=4;\r
2915 }\r
2916 while (row);\r
2917\r
2918 for(TXV=y1;TXV<=y2;TXV++)\r
2919 {\r
2920 for(TXU=x1;TXU<=x2;TXU++)\r
2921 {\r
2922 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
2923 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
2924\r
2925 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
2926 }\r
2927 ta+=xalign;\r
2928 }\r
2929\r
2930 break;\r
2931 }\r
2932\r
2933 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2934\r
2935 cSRCPtr = psxVub + start + (y1<<11) + x1;\r
2936 LineOffset = 2048 - dx;\r
2937\r
2938 if(dy*dx>384) // more pix? use lut\r
2939 {\r
2940 wSRCPtr=psxVuw+palstart;\r
2941\r
2942 row=64;do\r
2943 {\r
2944 *px =LPTCOL(*wSRCPtr);\r
2945 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2946 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2947 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2948 row--;px+=4;wSRCPtr+=4;\r
2949 }\r
2950 while (row);\r
2951\r
2952 column=dy;do \r
2953 {\r
2954 row=dx;\r
2955 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);\r
2956\r
2957 ta+=xalign;\r
2958\r
2959 cSRCPtr+=LineOffset;column--;\r
2960 }\r
2961 while(column);\r
2962 }\r
2963 else // small area? no lut\r
2964 { \r
2965 wSRCPtr=psxVuw+palstart;\r
2966\r
2967 column=dy;do \r
2968 {\r
2969 row=dx;\r
2970 do {*ta++=LPTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);\r
2971\r
2972 ta+=xalign;\r
2973\r
2974 cSRCPtr+=LineOffset;column--;\r
2975 }\r
2976 while(column);\r
2977 }\r
2978 break;\r
2979 //--------------------------------------------------// \r
2980 // 16bit texture load ..\r
2981 case 2:\r
2982 start=((pageid-16*pmult)<<6)+262144*pmult;\r
2983\r
2984 wSRCPtr = psxVuw + start + (y1<<10) + x1;\r
2985 LineOffset = 1024 - dx; \r
2986\r
2987 column=dy;do \r
2988 {\r
2989 row=dx;\r
2990 do {*ta++=LPTCOL(*wSRCPtr++);row--;} while(row);\r
2991\r
2992 ta+=xalign;\r
2993\r
2994 wSRCPtr+=LineOffset;column--;\r
2995 }\r
2996 while(column);\r
2997 break;\r
2998 //--------------------------------------------------// \r
2999 // others are not possible !\r
3000 }\r
3001\r
3002 ////////////////////////////////////////////////////////\r
3003\r
3004 x2a=dx+xalign;\r
3005\r
3006 if(YTexS)\r
3007 {\r
3008 ta=(unsigned short *)texturepart;\r
3009 pa=(unsigned short *)texturepart+x2a;\r
3010 row=x2a;do {*ta++=*pa++;row--;} while(row);\r
3011\r
3012 pa=(unsigned short *)texturepart+dy*x2a;\r
3013 ta=pa+x2a;\r
3014 row=x2a;do {*ta++=*pa++;row--;} while(row);\r
3015\r
3016 YTexS--;\r
3017 dy+=2;\r
3018 }\r
3019\r
3020 if(XTexS)\r
3021 {\r
3022 ta=(unsigned short *)texturepart;\r
3023 pa=ta+1;\r
3024 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
3025\r
3026 pa=(unsigned short *)texturepart+dx;\r
3027 ta=pa+1;\r
3028 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
3029\r
3030 XTexS--;\r
3031 dx+=2;\r
3032 }\r
3033\r
3034 DXTexS=dx;DYTexS=dy;\r
3035\r
3036 if(!iFilterType) {DefineSubTextureSort();return;}\r
3037 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}\r
3038 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)\r
3039 {DefineSubTextureSort();return;}\r
3040\r
3041 ta=(unsigned short *)texturepart;\r
3042 x1=dx-1;\r
3043 y1=dy-1; \r
3044\r
3045{\r
3046 for(column=0;column<dy;column++)\r
3047 {\r
3048 for(row=0;row<dx;row++)\r
3049 {\r
3050 if(*ta==0)\r
3051 {\r
3052 cnt=0;\r
3053\r
3054 if( column && *(ta-dx) &1) scol[cnt++]=*(ta-dx);\r
3055 if(row && *(ta-1) &1) scol[cnt++]=*(ta-1);\r
3056 if(row!=x1 && *(ta+1) &1) scol[cnt++]=*(ta+1);\r
3057 if( column!=y1 && *(ta+dx) &1) scol[cnt++]=*(ta+dx);\r
3058\r
3059 if(row && column && *(ta-dx-1)&1) scol[cnt++]=*(ta-dx-1);\r
3060 if(row!=x1 && column && *(ta-dx+1)&1) scol[cnt++]=*(ta-dx+1);\r
3061 if(row && column!=y1 && *(ta+dx-1)&1) scol[cnt++]=*(ta+dx-1);\r
3062 if(row!=x1 && column!=y1 && *(ta+dx+1)&1) scol[cnt++]=*(ta+dx+1);\r
3063\r
3064 if(cnt)\r
3065 {\r
3066 r=g=b=0;\r
3067 for(h=0;h<cnt;h++)\r
3068 {\r
3069 r+=scol[h]>>11;\r
3070 g+=(scol[h]>>6)&0x1f;\r
3071 b+=(scol[h]>>1)&0x1f;\r
3072 }\r
3073 r/=cnt;b/=cnt;g/=cnt;\r
3074 *ta=(r<<11)|(g<<6)|(b<<1);\r
3075 }\r
3076 }\r
3077 ta++;\r
3078 }\r
3079 }\r
3080 }\r
3081\r
3082 DefineSubTextureSort();\r
3083}\r
3084\r
3085/////////////////////////////////////////////////////////////////////////////\r
3086\r
3087/////////////////////////////////////////////////////////////////////////////\r
3088/////////////////////////////////////////////////////////////////////////////\r
3089/////////////////////////////////////////////////////////////////////////////\r
3090//\r
3091// hires texture funcs\r
3092//\r
3093/////////////////////////////////////////////////////////////////////////////\r
3094/////////////////////////////////////////////////////////////////////////////\r
3095/////////////////////////////////////////////////////////////////////////////\r
3096\r
3097\r
3098#define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))\r
3099\r
3100////////////////////////////////////////////////////////////////////////\r
3101\r
3102#define colorMask8 0x00FEFEFE\r
3103#define lowPixelMask8 0x00010101\r
3104#define qcolorMask8 0x00FCFCFC\r
3105#define qlowpixelMask8 0x00030303\r
3106\r
3107\r
3108#define INTERPOLATE8_02(A, B) (((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8))|((((A&0xFF000000)==0x03000000)?0x03000000:(((B&0xFF000000)==0x03000000)?0x03000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))\r
3109\r
3110#define Q_INTERPOLATE8_02(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x03000000)?0x03000000:(((B&0xFF000000)==0x03000000)?0x03000000:(((C&0xFF000000)==0x03000000)?0x03000000:(((D&0xFF000000)==0x03000000)?0x03000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))\r
3111\r
3112#define INTERPOLATE8(A, B) (((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))\r
3113\r
3114#define Q_INTERPOLATE8(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((C&0xFF000000)==0x50000000)?0x50000000:(((D&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))\r
3115\r
677ea103 3116void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,\r
3117 unsigned char *dstBitmap, int width, int height)\r
ce879073 3118{\r
3119 DWORD dstPitch = srcPitch * 2;\r
3120 DWORD line;\r
3121 DWORD *dP;\r
3122 DWORD *bP;\r
3123 int width2 = width*2;\r
3124 int iXA,iXB,iXC,iYA,iYB,iYC,finish;\r
3125 DWORD color4, color5, color6;\r
3126 DWORD color1, color2, color3;\r
3127 DWORD colorA0, colorA1, colorA2, colorA3,\r
3128 colorB0, colorB1, colorB2, colorB3,\r
3129 colorS1, colorS2;\r
3130 DWORD product1a, product1b,\r
3131 product2a, product2b;\r
3132\r
3133 line = 0;\r
3134\r
3135 {\r
3136 for (; height; height-=1)\r
3137 {\r
3138 bP = (DWORD *)srcPtr;\r
3139 dP = (DWORD *)(dstBitmap + line*dstPitch);\r
3140 for (finish = width; finish; finish -= 1 )\r
3141 {\r
3142//--------------------------------------- B1 B2\r
3143// 4 5 6 S2\r
3144// 1 2 3 S1\r
3145// A1 A2\r
3146 if(finish==width) iXA=0;\r
3147 else iXA=1;\r
3148 if(finish>4) {iXB=1;iXC=2;}\r
3149 else\r
3150 if(finish>3) {iXB=1;iXC=1;}\r
3151 else {iXB=0;iXC=0;}\r
3152 if(line==0) iYA=0;\r
3153 else iYA=width;\r
3154 if(height>4) {iYB=width;iYC=width2;}\r
3155 else\r
3156 if(height>3) {iYB=width;iYC=width;}\r
3157 else {iYB=0;iYC=0;}\r
3158\r
3159\r
3160 colorB0 = *(bP- iYA - iXA);\r
3161 colorB1 = *(bP- iYA);\r
3162 colorB2 = *(bP- iYA + iXB);\r
3163 colorB3 = *(bP- iYA + iXC);\r
3164\r
3165 color4 = *(bP - iXA);\r
3166 color5 = *(bP);\r
3167 color6 = *(bP + iXB);\r
3168 colorS2 = *(bP + iXC);\r
3169\r
3170 color1 = *(bP + iYB - iXA);\r
3171 color2 = *(bP + iYB);\r
3172 color3 = *(bP + iYB + iXB);\r
3173 colorS1= *(bP + iYB + iXC);\r
3174\r
3175 colorA0 = *(bP + iYC - iXA);\r
3176 colorA1 = *(bP + iYC);\r
3177 colorA2 = *(bP + iYC + iXB);\r
3178 colorA3 = *(bP + iYC + iXC);\r
3179\r
3180//--------------------------------------\r
3181 if (color2 == color6 && color5 != color3)\r
3182 {\r
3183 product2b = product1b = color2;\r
3184 }\r
3185 else\r
3186 if (color5 == color3 && color2 != color6)\r
3187 {\r
3188 product2b = product1b = color5;\r
3189 }\r
3190 else\r
3191 if (color5 == color3 && color2 == color6)\r
3192 {\r
3193 register int r = 0;\r
3194\r
3195 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));\r
3196 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));\r
3197 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));\r
3198 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));\r
3199\r
3200 if (r > 0)\r
3201 product2b = product1b = color6;\r
3202 else\r
3203 if (r < 0)\r
3204 product2b = product1b = color5;\r
3205 else\r
3206 {\r
3207 product2b = product1b = INTERPOLATE8_02(color5, color6);\r
3208 }\r
3209 }\r
3210 else\r
3211 {\r
3212 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)\r
3213 product2b = Q_INTERPOLATE8_02 (color3, color3, color3, color2);\r
3214 else\r
3215 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)\r
3216 product2b = Q_INTERPOLATE8_02 (color2, color2, color2, color3);\r
3217 else\r
3218 product2b = INTERPOLATE8_02 (color2, color3);\r
3219\r
3220 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)\r
3221 product1b = Q_INTERPOLATE8_02 (color6, color6, color6, color5);\r
3222 else\r
3223 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)\r
3224 product1b = Q_INTERPOLATE8_02 (color6, color5, color5, color5);\r
3225 else\r
3226 product1b = INTERPOLATE8_02 (color5, color6);\r
3227 }\r
3228\r
3229 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)\r
3230 product2a = INTERPOLATE8_02(color2, color5);\r
3231 else\r
3232 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)\r
3233 product2a = INTERPOLATE8_02(color2, color5);\r
3234 else\r
3235 product2a = color2;\r
3236\r
3237 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)\r
3238 product1a = INTERPOLATE8_02(color2, color5);\r
3239 else\r
3240 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)\r
3241 product1a = INTERPOLATE8_02(color2, color5);\r
3242 else\r
3243 product1a = color5;\r
3244\r
3245 *dP=product1a;\r
3246 *(dP+1)=product1b;\r
3247 *(dP+(width2))=product2a;\r
3248 *(dP+1+(width2))=product2b;\r
3249\r
3250 bP += 1;\r
3251 dP += 2;\r
3252 }//end of for ( finish= width etc..)\r
3253\r
3254 line += 2;\r
3255 srcPtr += srcPitch;\r
3256 }; //endof: for (; height; height--)\r
3257 }\r
3258}\r
3259\r
3260\r
677ea103 3261void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,\r
3262 unsigned char *dstBitmap, int width, int height)\r
ce879073 3263{\r
3264 DWORD dstPitch = srcPitch * 2;\r
3265 DWORD line;\r
3266 DWORD *dP;\r
3267 DWORD *bP;\r
3268 int width2 = width*2;\r
3269 int iXA,iXB,iXC,iYA,iYB,iYC,finish;\r
3270 DWORD color4, color5, color6;\r
3271 DWORD color1, color2, color3;\r
3272 DWORD colorA0, colorA1, colorA2, colorA3,\r
3273 colorB0, colorB1, colorB2, colorB3,\r
3274 colorS1, colorS2;\r
3275 DWORD product1a, product1b,\r
3276 product2a, product2b;\r
3277\r
3278 line = 0;\r
3279\r
3280 {\r
3281 for (; height; height-=1)\r
3282 {\r
3283 bP = (DWORD *)srcPtr;\r
3284 dP = (DWORD *)(dstBitmap + line*dstPitch);\r
3285 for (finish = width; finish; finish -= 1 )\r
3286 {\r
3287//--------------------------------------- B1 B2\r
3288// 4 5 6 S2\r
3289// 1 2 3 S1\r
3290// A1 A2\r
3291 if(finish==width) iXA=0;\r
3292 else iXA=1;\r
3293 if(finish>4) {iXB=1;iXC=2;}\r
3294 else\r
3295 if(finish>3) {iXB=1;iXC=1;}\r
3296 else {iXB=0;iXC=0;}\r
3297 if(line==0) iYA=0;\r
3298 else iYA=width;\r
3299 if(height>4) {iYB=width;iYC=width2;}\r
3300 else\r
3301 if(height>3) {iYB=width;iYC=width;}\r
3302 else {iYB=0;iYC=0;}\r
3303\r
3304\r
3305 colorB0 = *(bP- iYA - iXA);\r
3306 colorB1 = *(bP- iYA);\r
3307 colorB2 = *(bP- iYA + iXB);\r
3308 colorB3 = *(bP- iYA + iXC);\r
3309\r
3310 color4 = *(bP - iXA);\r
3311 color5 = *(bP);\r
3312 color6 = *(bP + iXB);\r
3313 colorS2 = *(bP + iXC);\r
3314\r
3315 color1 = *(bP + iYB - iXA);\r
3316 color2 = *(bP + iYB);\r
3317 color3 = *(bP + iYB + iXB);\r
3318 colorS1= *(bP + iYB + iXC);\r
3319\r
3320 colorA0 = *(bP + iYC - iXA);\r
3321 colorA1 = *(bP + iYC);\r
3322 colorA2 = *(bP + iYC + iXB);\r
3323 colorA3 = *(bP + iYC + iXC);\r
3324\r
3325//--------------------------------------\r
3326 if (color2 == color6 && color5 != color3)\r
3327 {\r
3328 product2b = product1b = color2;\r
3329 }\r
3330 else\r
3331 if (color5 == color3 && color2 != color6)\r
3332 {\r
3333 product2b = product1b = color5;\r
3334 }\r
3335 else\r
3336 if (color5 == color3 && color2 == color6)\r
3337 {\r
3338 register int r = 0;\r
3339\r
3340 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));\r
3341 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));\r
3342 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));\r
3343 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));\r
3344\r
3345 if (r > 0)\r
3346 product2b = product1b = color6;\r
3347 else\r
3348 if (r < 0)\r
3349 product2b = product1b = color5;\r
3350 else\r
3351 {\r
3352 product2b = product1b = INTERPOLATE8(color5, color6);\r
3353 }\r
3354 }\r
3355 else\r
3356 {\r
3357 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)\r
3358 product2b = Q_INTERPOLATE8 (color3, color3, color3, color2);\r
3359 else\r
3360 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)\r
3361 product2b = Q_INTERPOLATE8 (color2, color2, color2, color3);\r
3362 else\r
3363 product2b = INTERPOLATE8 (color2, color3);\r
3364\r
3365 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)\r
3366 product1b = Q_INTERPOLATE8 (color6, color6, color6, color5);\r
3367 else\r
3368 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)\r
3369 product1b = Q_INTERPOLATE8 (color6, color5, color5, color5);\r
3370 else\r
3371 product1b = INTERPOLATE8 (color5, color6);\r
3372 }\r
3373\r
3374 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)\r
3375 product2a = INTERPOLATE8(color2, color5);\r
3376 else\r
3377 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)\r
3378 product2a = INTERPOLATE8(color2, color5);\r
3379 else\r
3380 product2a = color2;\r
3381\r
3382 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)\r
3383 product1a = INTERPOLATE8(color2, color5);\r
3384 else\r
3385 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)\r
3386 product1a = INTERPOLATE8(color2, color5);\r
3387 else\r
3388 product1a = color5;\r
3389\r
3390 *dP=product1a;\r
3391 *(dP+1)=product1b;\r
3392 *(dP+(width2))=product2a;\r
3393 *(dP+1+(width2))=product2b;\r
3394\r
3395 bP += 1;\r
3396 dP += 2;\r
3397 }//end of for ( finish= width etc..)\r
3398\r
3399 line += 2;\r
3400 srcPtr += srcPitch;\r
3401 }; //endof: for (; height; height--)\r
3402 }\r
3403}\r
3404/////////////////////////////////////////////////////////////////////////////\r
3405\r
3406#define colorMask4 0x0000EEE0\r
3407#define lowPixelMask4 0x00001110\r
3408#define qcolorMask4 0x0000CCC0\r
3409#define qlowpixelMask4 0x00003330\r
3410\r
3411#define INTERPOLATE4(A, B) ((((A & colorMask4) >> 1) + ((B & colorMask4) >> 1) + (A & B & lowPixelMask4))|((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))\r
3412\r
3413#define Q_INTERPOLATE4(A, B, C, D) ((((A & qcolorMask4) >> 2) + ((B & qcolorMask4) >> 2) + ((C & qcolorMask4) >> 2) + ((D & qcolorMask4) >> 2) + ((((A & qlowpixelMask4) + (B & qlowpixelMask4) + (C & qlowpixelMask4) + (D & qlowpixelMask4)) >> 2) & qlowpixelMask4))| ((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((C&0x0000000F)==0x00000006)?0x00000006:(((D&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:(((C&0x0000000F)==0x00000000)?0x00000000:(((D&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))))))\r
3414\r
3415\r
3416#define colorMask5 0x0000F7BC\r
3417#define lowPixelMask5 0x00000842\r
3418#define qcolorMask5 0x0000E738\r
3419#define qlowpixelMask5 0x000018C6\r
3420\r
3421#define INTERPOLATE5(A, B) ((((A & colorMask5) >> 1) + ((B & colorMask5) >> 1) + (A & B & lowPixelMask5))|((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:0x00000001))))\r
3422\r
3423#define Q_INTERPOLATE5(A, B, C, D) ((((A & qcolorMask5) >> 2) + ((B & qcolorMask5) >> 2) + ((C & qcolorMask5) >> 2) + ((D & qcolorMask5) >> 2) + ((((A & qlowpixelMask5) + (B & qlowpixelMask5) + (C & qlowpixelMask5) + (D & qlowpixelMask5)) >> 2) & qlowpixelMask5))| ((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:(((C&0x00000001)==0x00000000)?0x00000000:(((D&0x00000001)==0x00000000)?0x00000000:0x00000001))))))\r
3424/////////////////////////////////////////////////////////////////////////////\r
3425/////////////////////////////////////////////////////////////////////////////\r
3426/////////////////////////////////////////////////////////////////////////////\r
3427//\r
3428// ogl texture defines\r
3429//\r
3430/////////////////////////////////////////////////////////////////////////////\r
3431/////////////////////////////////////////////////////////////////////////////\r
3432/////////////////////////////////////////////////////////////////////////////\r
3433\r
3434void DefineSubTextureSortHiRes(void)\r
3435{\r
3436 int x,y,dx2;\r
3437\r
3438 if(!gTexName) \r
3439 {\r
9f58cabb 3440 glGenTextures(1, &gTexName); glError();\r
3441 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 3442\r
9f58cabb 3443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
3444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
ce879073 3445\r
3446 if(iFilterType)\r
3447 {\r
9f58cabb 3448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();\r
3449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();\r
ce879073 3450 }\r
3451 else\r
3452 { \r
9f58cabb 3453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
3454 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 3455 } \r
9f58cabb 3456 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturebuffer); glError();\r
ce879073 3457 }\r
9f58cabb 3458 else glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 3459\r
3460 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS<<1, YTexS<<1,\r
3461 DXTexS<<1, DYTexS<<1,\r
9f58cabb 3462 GL_RGBA, GL_UNSIGNED_BYTE, texturebuffer); glError();\r
3463 //LOGE("DefineSubTextureSortHiRes x:%d y:%d",XTexS<<1,YTexS<<1);\r
ce879073 3464}\r
3465\r
3466/////////////////////////////////////////////////////////////////////////////\r
3467\r
3468void DefineSubTextureSort(void)\r
3469{\r
3470\r
3471 if(!gTexName)\r
3472 {\r
9f58cabb 3473 glGenTextures(1, &gTexName); glError();\r
3474 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 3475\r
9f58cabb 3476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
3477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
ce879073 3478\r
3479 if(iFilterType)\r
3480 {\r
9f58cabb 3481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();\r
3482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();\r
ce879073 3483 }\r
3484 else\r
3485 {\r
9f58cabb 3486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
3487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 3488 }\r
9f58cabb 3489 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
ce879073 3490 }\r
9f58cabb 3491 else glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 3492\r
3493 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS, YTexS,\r
3494 DXTexS, DYTexS,\r
9f58cabb 3495 GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
3496 //LOGE("DefineSubTextureSort x:%d y:%d w:%d h:%d",XTexS,YTexS,DXTexS,DYTexS);\r
ce879073 3497}\r
3498\r
3499/////////////////////////////////////////////////////////////////////////////\r
3500\r
3501/////////////////////////////////////////////////////////////////////////////\r
3502/////////////////////////////////////////////////////////////////////////////\r
3503/////////////////////////////////////////////////////////////////////////////\r
3504//\r
3505// texture cache garbage collection\r
3506//\r
3507/////////////////////////////////////////////////////////////////////////////\r
3508/////////////////////////////////////////////////////////////////////////////\r
3509/////////////////////////////////////////////////////////////////////////////\r
3510\r
3511void DoTexGarbageCollection(void)\r
3512{\r
3513 static unsigned short LRUCleaned=0;\r
3514 unsigned short iC,iC1,iC2;\r
3515 int i,j,iMax;textureSubCacheEntryS * tsb;\r
3516\r
3517 iC=4;//=iSortTexCnt/2,\r
3518 LRUCleaned+=iC; // we clean different textures each time\r
3519 if((LRUCleaned+iC)>=iSortTexCnt) LRUCleaned=0; // wrap? wrap!\r
3520 iC1=LRUCleaned; // range of textures to clean\r
3521 iC2=LRUCleaned+iC;\r
3522\r
3523 for(iC=iC1;iC<iC2;iC++) // make some textures available\r
3524 {\r
3525 pxSsubtexLeft[iC]->l=0;\r
3526 }\r
3527\r
3528 for(i=0;i<3;i++) // remove all references to that textures\r
3529 for(j=0;j<MAXTPAGES;j++)\r
3530 for(iC=0;iC<4;iC++) // loop all texture rect info areas\r
3531 {\r
3532 tsb=pscSubtexStore[i][j]+(iC*SOFFB);\r
3533 iMax=tsb->pos.l;\r
3534 if(iMax)\r
3535 do\r
3536 {\r
3537 tsb++;\r
3538 if(tsb->cTexID>=iC1 && tsb->cTexID<iC2) // info uses the cleaned textures? remove info\r
3539 tsb->ClutID=0;\r
3540 } \r
3541 while(--iMax);\r
3542 }\r
3543\r
3544 usLRUTexPage=LRUCleaned;\r
3545}\r
3546\r
3547/////////////////////////////////////////////////////////////////////////////\r
3548/////////////////////////////////////////////////////////////////////////////\r
3549/////////////////////////////////////////////////////////////////////////////\r
3550//\r
3551// search cache for existing (already used) parts\r
3552//\r
3553/////////////////////////////////////////////////////////////////////////////\r
3554/////////////////////////////////////////////////////////////////////////////\r
3555/////////////////////////////////////////////////////////////////////////////\r
3556\r
677ea103 3557unsigned char * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache)\r
ce879073 3558{\r
3559 textureSubCacheEntryS * tsx, * tsb, *tsg;//, *tse=NULL;\r
3560 int i,iMax;EXLong npos;\r
677ea103 3561 unsigned char cx,cy;\r
ce879073 3562 int iC,j,k;unsigned long rx,ry,mx,my;\r
3563 EXLong * ul=0, * uls;\r
3564 EXLong rfree;\r
677ea103 3565 unsigned char cXAdj,cYAdj;\r
ce879073 3566\r
3567 npos.l=*((unsigned long *)&gl_ux[4]);\r
3568\r
3569 //--------------------------------------------------------------//\r
3570 // find matching texturepart first... speed up...\r
3571 //--------------------------------------------------------------//\r
3572\r
3573 tsg=pscSubtexStore[TextureMode][GlobalTexturePage];\r
3574 tsg+=((GivenClutId&CLUTCHK)>>CLUTSHIFT)*SOFFB;\r
3575\r
3576 iMax=tsg->pos.l;\r
3577 if(iMax)\r
3578 {\r
3579 i=iMax;\r
3580 tsb=tsg+1; \r
3581 do\r
3582 {\r
3583 if(GivenClutId==tsb->ClutID &&\r
3584 (INCHECK(tsb->pos,npos)))\r
3585 {\r
3586 {\r
3587 cx=tsb->pos.c[3]-tsb->posTX;\r
3588 cy=tsb->pos.c[1]-tsb->posTY;\r
3589\r
3590 gl_ux[0]-=cx;\r
3591 gl_ux[1]-=cx;\r
3592 gl_ux[2]-=cx;\r
3593 gl_ux[3]-=cx;\r
3594 gl_vy[0]-=cy;\r
3595 gl_vy[1]-=cy;\r
3596 gl_vy[2]-=cy;\r
3597 gl_vy[3]-=cy;\r
3598\r
3599 ubOpaqueDraw=tsb->Opaque;\r
3600 *pCache=tsb->cTexID;\r
3601 return NULL;\r
3602 }\r
3603 } \r
3604 tsb++;\r
3605 }\r
3606 while(--i);\r
3607 }\r
3608\r
3609 //----------------------------------------------------//\r
3610\r
3611 cXAdj=1;cYAdj=1;\r
3612\r
3613 rx=(int)gl_ux[6]-(int)gl_ux[7];\r
3614 ry=(int)gl_ux[4]-(int)gl_ux[5];\r
3615\r
3616 tsx=NULL;tsb=tsg+1;\r
3617 for(i=0;i<iMax;i++,tsb++)\r
3618 {\r
3619 if(!tsb->ClutID) {tsx=tsb;break;}\r
3620 }\r
3621\r
3622 if(!tsx) \r
3623 {\r
3624 iMax++;\r
3625 if(iMax>=SOFFB-2) \r
3626 {\r
3627 if(iTexGarbageCollection) // gc mode?\r
3628 {\r
3629 if(*pCache==0) \r
3630 {\r
3631 dwTexPageComp|=(1<<GlobalTexturePage);\r
3632 *pCache=0xffff;\r
3633 return 0;\r
3634 }\r
3635\r
3636 iMax--;\r
3637 tsb=tsg+1;\r
3638\r
3639 for(i=0;i<iMax;i++,tsb++) // 1. search other slots with same cluts, and unite the area\r
3640 if(GivenClutId==tsb->ClutID)\r
3641 {\r
3642 if(!tsx) {tsx=tsb;rfree.l=npos.l;} // \r
3643 else tsb->ClutID=0;\r
3644 rfree.c[3]=min(rfree.c[3],tsb->pos.c[3]);\r
3645 rfree.c[2]=max(rfree.c[2],tsb->pos.c[2]);\r
3646 rfree.c[1]=min(rfree.c[1],tsb->pos.c[1]);\r
3647 rfree.c[0]=max(rfree.c[0],tsb->pos.c[0]);\r
3648 MarkFree(tsb);\r
3649 }\r
3650\r
3651 if(tsx) // 3. if one or more found, create a new rect with bigger size\r
3652 {\r
3653 *((unsigned long *)&gl_ux[4])=npos.l=rfree.l;\r
3654 rx=(int)rfree.c[2]-(int)rfree.c[3];\r
3655 ry=(int)rfree.c[0]-(int)rfree.c[1];\r
3656 DoTexGarbageCollection();\r
3657 \r
3658 goto ENDLOOP3;\r
3659 }\r
3660 }\r
3661\r
3662 iMax=1;\r
3663 }\r
3664 tsx=tsg+iMax;\r
3665 tsg->pos.l=iMax;\r
3666 }\r
3667\r
3668 //----------------------------------------------------//\r
3669 // now get a free texture space\r
3670 //----------------------------------------------------//\r
3671\r
3672 if(iTexGarbageCollection) usLRUTexPage=0;\r
3673\r
3674ENDLOOP3:\r
3675\r
3676 rx+=3;if(rx>255) {cXAdj=0;rx=255;}\r
3677 ry+=3;if(ry>255) {cYAdj=0;ry=255;}\r
3678\r
3679 iC=usLRUTexPage;\r
3680\r
3681 for(k=0;k<iSortTexCnt;k++)\r
3682 {\r
3683 uls=pxSsubtexLeft[iC];\r
3684 iMax=uls->l;ul=uls+1;\r
3685\r
3686 //--------------------------------------------------//\r
3687 // first time\r
3688\r
3689 if(!iMax) \r
3690 {\r
3691 rfree.l=0;\r
3692\r
3693 if(rx>252 && ry>252)\r
3694 {uls->l=1;ul->l=0xffffffff;ul=0;goto ENDLOOP;}\r
3695\r
3696 if(rx<253)\r
3697 {\r
3698 uls->l=uls->l+1;\r
3699 ul->c[3]=rx;\r
3700 ul->c[2]=255-rx;\r
3701 ul->c[1]=0;\r
3702 ul->c[0]=ry;\r
3703 ul++;\r
3704 }\r
3705\r
3706 if(ry<253)\r
3707 {\r
3708 uls->l=uls->l+1; \r
3709 ul->c[3]=0;\r
3710 ul->c[2]=255;\r
3711 ul->c[1]=ry;\r
3712 ul->c[0]=255-ry;\r
3713 }\r
3714 ul=0;\r
3715 goto ENDLOOP;\r
3716 }\r
3717 \r
3718 //--------------------------------------------------//\r
3719 for(i=0;i<iMax;i++,ul++)\r
3720 {\r
3721 if(ul->l!=0xffffffff && \r
3722 ry<=ul->c[0] && \r
3723 rx<=ul->c[2])\r
3724 {\r
3725 rfree=*ul;\r
3726 mx=ul->c[2]-2;\r
3727 my=ul->c[0]-2;\r
3728 if(rx<mx && ry<my)\r
3729 {\r
3730 ul->c[3]+=rx;\r
3731 ul->c[2]-=rx;\r
3732 ul->c[0]=ry;\r
3733\r
3734 for(ul=uls+1,j=0;j<iMax;j++,ul++)\r
3735 if(ul->l==0xffffffff) break;\r
3736 \r
3737 if(j<CSUBSIZE-2)\r
3738 {\r
3739 if(j==iMax) uls->l=uls->l+1;\r
3740\r
3741 ul->c[3]=rfree.c[3];\r
3742 ul->c[2]=rfree.c[2];\r
3743 ul->c[1]=rfree.c[1]+ry;\r
3744 ul->c[0]=rfree.c[0]-ry;\r
3745 }\r
3746 }\r
3747 else if(rx<mx)\r
3748 {\r
3749 ul->c[3]+=rx;\r
3750 ul->c[2]-=rx;\r
3751 }\r
3752 else if(ry<my)\r
3753 {\r
3754 ul->c[1]+=ry;\r
3755 ul->c[0]-=ry;\r
3756 }\r
3757 else\r
3758 {\r
3759 ul->l=0xffffffff;\r
3760 }\r
3761 ul=0;\r
3762 goto ENDLOOP;\r
3763 }\r
3764 }\r
3765\r
3766 //--------------------------------------------------//\r
3767\r
3768 iC++; if(iC>=iSortTexCnt) iC=0;\r
3769 }\r
3770\r
3771 //----------------------------------------------------//\r
3772 // check, if free space got\r
3773 //----------------------------------------------------//\r
3774\r
3775ENDLOOP:\r
3776 if(ul)\r
3777 {\r
3778 //////////////////////////////////////////////////////\r
3779\r
3780 {\r
3781 dwTexPageComp=0;\r
3782\r
3783 for(i=0;i<3;i++) // cleaning up\r
3784 for(j=0;j<MAXTPAGES;j++)\r
3785 {\r
3786 tsb=pscSubtexStore[i][j];\r
3787 (tsb+SOFFA)->pos.l=0;\r
3788 (tsb+SOFFB)->pos.l=0;\r
3789 (tsb+SOFFC)->pos.l=0;\r
3790 (tsb+SOFFD)->pos.l=0;\r
3791 }\r
3792 for(i=0;i<iSortTexCnt;i++)\r
3793 {ul=pxSsubtexLeft[i];ul->l=0;}\r
3794 usLRUTexPage=0;\r
3795 }\r
3796\r
3797 //////////////////////////////////////////////////////\r
3798 iC=usLRUTexPage;\r
3799 uls=pxSsubtexLeft[usLRUTexPage];\r
3800 uls->l=0;ul=uls+1;\r
3801 rfree.l=0;\r
3802\r
3803 if(rx>252 && ry>252)\r
3804 {uls->l=1;ul->l=0xffffffff;}\r
3805 else\r
3806 {\r
3807 if(rx<253)\r
3808 {\r
3809 uls->l=uls->l+1;\r
3810 ul->c[3]=rx;\r
3811 ul->c[2]=255-rx;\r
3812 ul->c[1]=0;\r
3813 ul->c[0]=ry;\r
3814 ul++;\r
3815 }\r
3816 if(ry<253)\r
3817 {\r
3818 uls->l=uls->l+1; \r
3819 ul->c[3]=0;\r
3820 ul->c[2]=255;\r
3821 ul->c[1]=ry;\r
3822 ul->c[0]=255-ry;\r
3823 }\r
3824 }\r
3825 tsg->pos.l=1;tsx=tsg+1;\r
3826 }\r
3827\r
3828 rfree.c[3]+=cXAdj;\r
3829 rfree.c[1]+=cYAdj;\r
3830\r
3831 tsx->cTexID =*pCache=iC;\r
3832 tsx->pos = npos;\r
3833 tsx->ClutID = GivenClutId;\r
3834 tsx->posTX = rfree.c[3];\r
3835 tsx->posTY = rfree.c[1];\r
3836\r
3837 cx=gl_ux[7]-rfree.c[3];\r
3838 cy=gl_ux[5]-rfree.c[1];\r
3839\r
3840 gl_ux[0]-=cx;\r
3841 gl_ux[1]-=cx;\r
3842 gl_ux[2]-=cx;\r
3843 gl_ux[3]-=cx;\r
3844 gl_vy[0]-=cy;\r
3845 gl_vy[1]-=cy;\r
3846 gl_vy[2]-=cy;\r
3847 gl_vy[3]-=cy;\r
3848\r
3849 XTexS=rfree.c[3];\r
3850 YTexS=rfree.c[1];\r
3851\r
3852 return &tsx->Opaque;\r
3853}\r
3854 \r
3855/////////////////////////////////////////////////////////////////////////////\r
3856/////////////////////////////////////////////////////////////////////////////\r
3857/////////////////////////////////////////////////////////////////////////////\r
3858//\r
3859// search cache for free place (on compress)\r
3860//\r
3861/////////////////////////////////////////////////////////////////////////////\r
3862/////////////////////////////////////////////////////////////////////////////\r
3863/////////////////////////////////////////////////////////////////////////////\r
3864\r
3865BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)\r
3866{\r
3867 int i,j,k,iMax,iC;unsigned long rx,ry,mx,my;\r
3868 EXLong * ul=0, * uls, rfree;\r
677ea103 3869 unsigned char cXAdj=1,cYAdj=1;\r
ce879073 3870\r
3871 rx=(int)tsx->pos.c[2]-(int)tsx->pos.c[3];\r
3872 ry=(int)tsx->pos.c[0]-(int)tsx->pos.c[1];\r
3873\r
3874 rx+=3;if(rx>255) {cXAdj=0;rx=255;}\r
3875 ry+=3;if(ry>255) {cYAdj=0;ry=255;}\r
3876\r
3877 iC=usLRUTexPage;\r
3878\r
3879 for(k=0;k<iSortTexCnt;k++)\r
3880 {\r
3881 uls=pxSsubtexLeft[iC];\r
3882 iMax=uls->l;ul=uls+1;\r
3883\r
3884 //--------------------------------------------------//\r
3885 // first time\r
3886\r
3887 if(!iMax)\r
3888 {\r
3889 rfree.l=0;\r
3890\r
3891 if(rx>252 && ry>252)\r
3892 {uls->l=1;ul->l=0xffffffff;ul=0;goto TENDLOOP;}\r
3893\r
3894 if(rx<253)\r
3895 {\r
3896 uls->l=uls->l+1;\r
3897 ul->c[3]=rx;\r
3898 ul->c[2]=255-rx;\r
3899 ul->c[1]=0;\r
3900 ul->c[0]=ry;\r
3901 ul++;\r
3902 }\r
3903\r
3904 if(ry<253)\r
3905 {\r
3906 uls->l=uls->l+1;\r
3907 ul->c[3]=0;\r
3908 ul->c[2]=255;\r
3909 ul->c[1]=ry;\r
3910 ul->c[0]=255-ry;\r
3911 }\r
3912 ul=0;\r
3913 goto TENDLOOP;\r
3914 }\r
3915\r
3916 //--------------------------------------------------//\r
3917 for(i=0;i<iMax;i++,ul++)\r
3918 {\r
3919 if(ul->l!=0xffffffff &&\r
3920 ry<=ul->c[0] &&\r
3921 rx<=ul->c[2])\r
3922 {\r
3923 rfree=*ul;\r
3924 mx=ul->c[2]-2;\r
3925 my=ul->c[0]-2;\r
3926\r
3927 if(rx<mx && ry<my)\r
3928 {\r
3929 ul->c[3]+=rx;\r
3930 ul->c[2]-=rx;\r
3931 ul->c[0]=ry;\r
3932\r
3933 for(ul=uls+1,j=0;j<iMax;j++,ul++)\r
3934 if(ul->l==0xffffffff) break;\r
3935\r
3936 if(j<CSUBSIZE-2)\r
3937 {\r
3938 if(j==iMax) uls->l=uls->l+1;\r
3939\r
3940 ul->c[3]=rfree.c[3];\r
3941 ul->c[2]=rfree.c[2];\r
3942 ul->c[1]=rfree.c[1]+ry;\r
3943 ul->c[0]=rfree.c[0]-ry;\r
3944 }\r
3945 }\r
3946 else if(rx<mx)\r
3947 {\r
3948 ul->c[3]+=rx;\r
3949 ul->c[2]-=rx;\r
3950 }\r
3951 else if(ry<my)\r
3952 {\r
3953 ul->c[1]+=ry;\r
3954 ul->c[0]-=ry;\r
3955 }\r
3956 else\r
3957 {\r
3958 ul->l=0xffffffff;\r
3959 }\r
3960 ul=0;\r
3961 goto TENDLOOP;\r
3962 }\r
3963 }\r
3964\r
3965 //--------------------------------------------------//\r
3966\r
3967 iC++; if(iC>=iSortTexCnt) iC=0;\r
3968 }\r
3969\r
3970 //----------------------------------------------------//\r
3971 // check, if free space got\r
3972 //----------------------------------------------------//\r
3973\r
3974TENDLOOP:\r
3975 if(ul) return FALSE;\r
3976\r
3977 rfree.c[3]+=cXAdj;\r
3978 rfree.c[1]+=cYAdj;\r
3979\r
3980 tsx->cTexID = iC;\r
3981 tsx->posTX = rfree.c[3];\r
3982 tsx->posTY = rfree.c[1];\r
3983\r
3984 XTexS=rfree.c[3];\r
3985 YTexS=rfree.c[1];\r
3986\r
3987 return TRUE;\r
3988}\r
3989\r
3990/////////////////////////////////////////////////////////////////////////////\r
3991/////////////////////////////////////////////////////////////////////////////\r
3992/////////////////////////////////////////////////////////////////////////////\r
3993//\r
3994// compress texture cache (to make place for new texture part, if needed)\r
3995//\r
3996/////////////////////////////////////////////////////////////////////////////\r
3997/////////////////////////////////////////////////////////////////////////////\r
3998/////////////////////////////////////////////////////////////////////////////\r
3999\r
4000void CompressTextureSpace(void)\r
4001{\r
4002 textureSubCacheEntryS * tsx, * tsg, * tsb;\r
4003 int i,j,k,m,n,iMax;EXLong * ul, r,opos;\r
4004 short sOldDST=DrawSemiTrans,cx,cy;\r
4005 long lOGTP=GlobalTexturePage;\r
4006 unsigned long l,row;\r
4007 unsigned long * lSRCPtr;\r
4008\r
4009 opos.l=*((unsigned long *)&gl_ux[4]);\r
4010\r
4011 // 1. mark all textures as free\r
4012 for(i=0;i<iSortTexCnt;i++)\r
4013 {ul=pxSsubtexLeft[i];ul->l=0;}\r
4014 usLRUTexPage=0;\r
4015\r
4016 // 2. compress\r
4017 for(j=0;j<3;j++)\r
4018 {\r
4019 for(k=0;k<MAXTPAGES;k++)\r
4020 {\r
4021 tsg=pscSubtexStore[j][k];\r
4022\r
4023 if((!(dwTexPageComp&(1<<k))))\r
4024 {\r
4025 (tsg+SOFFA)->pos.l=0;\r
4026 (tsg+SOFFB)->pos.l=0;\r
4027 (tsg+SOFFC)->pos.l=0;\r
4028 (tsg+SOFFD)->pos.l=0;\r
4029 continue;\r
4030 }\r
4031\r
4032 for(m=0;m<4;m++,tsg+=SOFFB)\r
4033 {\r
4034 iMax=tsg->pos.l;\r
4035\r
4036 tsx=tsg+1;\r
4037 for(i=0;i<iMax;i++,tsx++)\r
4038 {\r
4039 if(tsx->ClutID)\r
4040 {\r
4041 r.l=tsx->pos.l;\r
4042 for(n=i+1,tsb=tsx+1;n<iMax;n++,tsb++)\r
4043 {\r
4044 if(tsx->ClutID==tsb->ClutID)\r
4045 {\r
4046 r.c[3]=min(r.c[3],tsb->pos.c[3]);\r
4047 r.c[2]=max(r.c[2],tsb->pos.c[2]);\r
4048 r.c[1]=min(r.c[1],tsb->pos.c[1]);\r
4049 r.c[0]=max(r.c[0],tsb->pos.c[0]);\r
4050 tsb->ClutID=0;\r
4051 }\r
4052 }\r
4053\r
4054// if(r.l!=tsx->pos.l)\r
4055 {\r
4056 cx=((tsx->ClutID << 4) & 0x3F0); \r
4057 cy=((tsx->ClutID >> 6) & CLUTYMASK);\r
4058\r
4059 if(j!=2)\r
4060 {\r
4061 // palette check sum\r
4062 l=0;lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));\r
4063 if(j==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;\r
4064 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;\r
4065 l=((l+HIWORD(l))&0x3fffL)<<16;\r
4066 if(l!=(tsx->ClutID&(0x00003fff<<16)))\r
4067 {\r
4068 tsx->ClutID=0;continue;\r
4069 }\r
4070 }\r
4071\r
4072 tsx->pos.l=r.l;\r
4073 if(!GetCompressTexturePlace(tsx)) // no place?\r
4074 {\r
4075 for(i=0;i<3;i++) // -> clean up everything\r
4076 for(j=0;j<MAXTPAGES;j++)\r
4077 {\r
4078 tsb=pscSubtexStore[i][j];\r
4079 (tsb+SOFFA)->pos.l=0;\r
4080 (tsb+SOFFB)->pos.l=0;\r
4081 (tsb+SOFFC)->pos.l=0;\r
4082 (tsb+SOFFD)->pos.l=0;\r
4083 }\r
4084 for(i=0;i<iSortTexCnt;i++)\r
4085 {ul=pxSsubtexLeft[i];ul->l=0;}\r
4086 usLRUTexPage=0;\r
4087 DrawSemiTrans=sOldDST;\r
4088 GlobalTexturePage=lOGTP;\r
4089 *((unsigned long *)&gl_ux[4])=opos.l;\r
4090 dwTexPageComp=0;\r
4091\r
4092 return;\r
4093 }\r
4094\r
4095 if(tsx->ClutID&(1<<30)) DrawSemiTrans=1;\r
4096 else DrawSemiTrans=0;\r
4097 *((unsigned long *)&gl_ux[4])=r.l;\r
4098 \r
4099 gTexName=uiStexturePage[tsx->cTexID];\r
4100 LoadSubTexFn(k,j,cx,cy);\r
4101 uiStexturePage[tsx->cTexID]=gTexName;\r
4102 tsx->Opaque=ubOpaqueDraw;\r
4103 }\r
4104 }\r
4105 }\r
4106\r
4107 if(iMax) \r
4108 {\r
4109 tsx=tsg+iMax;\r
4110 while(!tsx->ClutID && iMax) {tsx--;iMax--;}\r
4111 tsg->pos.l=iMax;\r
4112 }\r
4113\r
4114 } \r
4115 }\r
4116 }\r
4117\r
4118 if(dwTexPageComp==0xffffffff) dwTexPageComp=0;\r
4119\r
4120 *((unsigned long *)&gl_ux[4])=opos.l;\r
4121 GlobalTexturePage=lOGTP;\r
4122 DrawSemiTrans=sOldDST;\r
4123}\r
4124\r
4125/////////////////////////////////////////////////////////////////////////////\r
4126/////////////////////////////////////////////////////////////////////////////\r
4127/////////////////////////////////////////////////////////////////////////////\r
4128//\r
4129// main entry for searching/creating textures, called from prim.c\r
4130//\r
4131/////////////////////////////////////////////////////////////////////////////\r
4132/////////////////////////////////////////////////////////////////////////////\r
4133/////////////////////////////////////////////////////////////////////////////\r
4134\r
4135GLuint SelectSubTextureS(long TextureMode, unsigned long GivenClutId) \r
4136{\r
677ea103 4137 unsigned char * OPtr;unsigned short iCache;short cx,cy;\r
ce879073 4138\r
4139 // sort sow/tow infos for fast access\r
4140\r
677ea103 4141 unsigned char ma1,ma2,mi1,mi2;\r
ce879073 4142 if(gl_ux[0]>gl_ux[1]) {mi1=gl_ux[1];ma1=gl_ux[0];}\r
4143 else {mi1=gl_ux[0];ma1=gl_ux[1];}\r
4144 if(gl_ux[2]>gl_ux[3]) {mi2=gl_ux[3];ma2=gl_ux[2];}\r
4145 else {mi2=gl_ux[2];ma2=gl_ux[3];}\r
4146 if(mi1>mi2) gl_ux[7]=mi2; \r
4147 else gl_ux[7]=mi1;\r
4148 if(ma1>ma2) gl_ux[6]=ma1; \r
4149 else gl_ux[6]=ma2;\r
4150\r
4151 if(gl_vy[0]>gl_vy[1]) {mi1=gl_vy[1];ma1=gl_vy[0];}\r
4152 else {mi1=gl_vy[0];ma1=gl_vy[1];}\r
4153 if(gl_vy[2]>gl_vy[3]) {mi2=gl_vy[3];ma2=gl_vy[2];}\r
4154 else {mi2=gl_vy[2];ma2=gl_vy[3];}\r
4155 if(mi1>mi2) gl_ux[5]=mi2; \r
4156 else gl_ux[5]=mi1;\r
4157 if(ma1>ma2) gl_ux[4]=ma1; \r
4158 else gl_ux[4]=ma2;\r
4159\r
4160 // get clut infos in one 32 bit val\r
4161\r
4162 if(TextureMode==2) // no clut here\r
4163 {\r
4164 GivenClutId=CLUTUSED|(DrawSemiTrans<<30);cx=cy=0;\r
4165 \r
4166 if(iFrameTexType && Fake15BitTexture()) \r
4167 return (GLuint)gTexName;\r
4168 } \r
4169 else \r
4170 {\r
4171 cx=((GivenClutId << 4) & 0x3F0); // but here\r
4172 cy=((GivenClutId >> 6) & CLUTYMASK);\r
4173 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30)|CLUTUSED;\r
4174\r
4175 // palette check sum.. removed MMX asm, this easy func works as well\r
4176 {\r
4177 unsigned long l=0,row;\r
4178\r
4179 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));\r
4180 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;\r
4181 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;\r
4182 l=(l+HIWORD(l))&0x3fffL;\r
4183 GivenClutId|=(l<<16);\r
4184 }\r
4185\r
4186 }\r
4187\r
4188 // search cache\r
4189 iCache=0;\r
4190 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);\r
4191\r
4192 // cache full? compress and try again\r
4193 if(iCache==0xffff)\r
4194 {\r
4195 CompressTextureSpace();\r
4196 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);\r
4197 }\r
4198\r
4199 // found? fine\r
4200 usLRUTexPage=iCache;\r
4201 if(!OPtr) return uiStexturePage[iCache];\r
4202\r
4203 // not found? upload texture and store infos in cache\r
4204 gTexName=uiStexturePage[iCache];\r
4205 LoadSubTexFn(GlobalTexturePage,TextureMode,cx,cy);\r
4206 uiStexturePage[iCache]=gTexName;\r
4207 *OPtr=ubOpaqueDraw;\r
4208 return (GLuint) gTexName;\r
4209}\r
4210\r
4211/////////////////////////////////////////////////////////////////////////////\r
4212/////////////////////////////////////////////////////////////////////////////\r
4213/////////////////////////////////////////////////////////////////////////////\r