1 /***************************************************************************
\r
2 texture.c - description
\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
9 /***************************************************************************
\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
17 ***************************************************************************/
\r
21 ////////////////////////////////////////////////////////////////////////////////////
22 // Texture related functions are here !
24 // The texture handling is heart and soul of this gpu. The plugin was developed
\r
25 // 1999, by this time no shaders were available. Since the psx gpu is making
\r
26 // heavy use of CLUT (="color lookup tables", aka palettized textures), it was
\r
27 // an interesting task to get those emulated at good speed on NV TNT cards
\r
28 // (which was my major goal when I created the first "gpuPeteTNT"). Later cards
\r
29 // (Geforce256) supported texture palettes by an OGL extension, but at some point
\r
30 // this support was dropped again by gfx card vendors.
\r
31 // Well, at least there is a certain advatage, if no texture palettes extension can
\r
32 // be used: it is possible to modify the textures in any way, allowing "hi-res"
\r
33 // textures and other tweaks.
\r
35 // My main texture caching is kinda complex: the plugin is allocating "n" 256x256 textures,
\r
36 // and it places small psx texture parts inside them. The plugin keeps track what
\r
37 // part (with what palette) it had placed in which texture, so it can re-use this
\r
38 // part again. The more ogl textures it can use, the better (of course the managing/
\r
39 // searching will be slower, but everything is faster than uploading textures again
\r
40 // and again to a gfx card). My first card (TNT1) had 16 MB Vram, and it worked
\r
41 // well with many games, but I recommend nowadays 64 MB Vram to get a good speed.
\r
43 // Sadly, there is also a second kind of texture cache needed, for "psx texture windows".
\r
44 // Those are "repeated" textures, so a psx "texture window" needs to be put in
\r
45 // a whole texture to use the GL_TEXTURE_WRAP_ features. This cache can get full very
\r
46 // fast in games which are having an heavy "texture window" usage, like RRT4. As an
\r
47 // alternative, this plugin can use the OGL "palette" extension on texture windows,
\r
48 // if available. Nowadays also a fragment shader can easily be used to emulate
\r
49 // texture wrapping in a texture atlas, so the main cache could hold the texture
\r
50 // windows as well (that's what I am doing in the OGL2 plugin). But currently the
\r
51 // OGL1 plugin is a "shader-free" zone, so heavy "texture window" games will cause
\r
52 // much texture uploads.
\r
54 // Some final advice: take care if you change things in here. I've removed my ASM
\r
55 // handlers (they didn't cause much speed gain anyway) for readability/portability,
\r
56 // but still the functions/data structures used here are easy to mess up. I guess it
\r
57 // can be a pain in the ass to port the plugin to another byte order :)
\r
59 ////////////////////////////////////////////////////////////////////////////////////
\r
63 #include "externals.h"
68 #define CLUTCHK 0x00060000
71 ////////////////////////////////////////////////////////////////////////
72 // texture conversion buffer ..
73 ////////////////////////////////////////////////////////////////////////
76 GLubyte ubPaletteBuffer[256][4];
77 GLuint gTexMovieName=0;
78 GLuint gTexBlurName=0;
79 GLuint gTexFrameName=0;
80 int iTexGarbageCollection=1;
81 uint32_t dwTexPageComp=0;
83 int iClampType=GL_CLAMP;
\r
85 void (*LoadSubTexFn) (int,int,short,short);
\r
86 uint32_t (*PalTexturedColourFn) (uint32_t);
88 ////////////////////////////////////////////////////////////////////////
90 ////////////////////////////////////////////////////////////////////////
92 #define PALCOL(x) PalTexturedColourFn (x)
95 #define CSUBSIZEA 8192
96 #define CSUBSIZES 4096
113 #define MAXWNDTEXCACHE 128
115 #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]))
116 #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]))
118 ////////////////////////////////////////////////////////////////////////
120 unsigned char * CheckTextureInSubSCache(int TextureMode, uint32_t GivenClutId, unsigned short *pCache);
121 void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);
122 void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);
123 void DefineSubTextureSort(void);
125 ////////////////////////////////////////////////////////////////////////
127 ////////////////////////////////////////////////////////////////////////
129 GLint giWantedRGBA=4;
130 GLint giWantedFMT=GL_RGBA;
131 GLint giWantedTYPE=GL_UNSIGNED_BYTE;
132 int GlobalTexturePage;
138 BOOL bUseFastMdec=FALSE;
139 BOOL bUse15bitMdec=FALSE;
141 int iFrameReadType=0;
143 uint32_t (*TCF[2]) (uint32_t);
144 unsigned short (*PTCF[2]) (unsigned short);
146 ////////////////////////////////////////////////////////////////////////
147 // texture cache implementation
148 ////////////////////////////////////////////////////////////////////////
150 // "texture window" cache entry
\r
152 typedef struct textureWndCacheEntryTag
161 } textureWndCacheEntry;
163 // "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)
\r
165 typedef struct textureSubCacheEntryTagS
171 unsigned char cTexID;
172 unsigned char Opaque;
173 } textureSubCacheEntryS;
175 //---------------------------------------------
\r
177 #define MAXTPAGES_MAX 64
\r
178 #define MAXSORTTEX_MAX 196
\r
180 //---------------------------------------------
\r
182 textureWndCacheEntry wcWndtexStore[MAXWNDTEXCACHE];
183 textureSubCacheEntryS * pscSubtexStore[3][MAXTPAGES_MAX];
184 EXLong * pxSsubtexLeft [MAXSORTTEX_MAX];
185 GLuint uiStexturePage[MAXSORTTEX_MAX];
187 unsigned short usLRUTexPage = 0;
191 int iTexWndLimit = MAXWNDTEXCACHE/2;
193 GLubyte * texturepart = NULL;
194 GLubyte * texturebuffer = NULL;
195 uint32_t g_x1,g_y1,g_x2,g_y2;
196 unsigned char ubOpaqueDraw = 0;
198 unsigned short MAXTPAGES = 32;
\r
199 unsigned short CLUTMASK = 0x7fff;
\r
200 unsigned short CLUTYMASK = 0x1ff;
\r
201 unsigned short MAXSORTTEX = 196;
\r
203 ////////////////////////////////////////////////////////////////////////
204 // Texture color conversions... all my ASM funcs are removed for easier
\r
205 // porting... and honestly: nowadays the speed gain would be pointless
206 ////////////////////////////////////////////////////////////////////////
208 uint32_t XP8RGBA(uint32_t BGR)
210 if(!(BGR&0xffff)) return 0x50000000;
211 if(DrawSemiTrans && !(BGR&0x8000))
212 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
213 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
216 uint32_t XP8RGBAEx(uint32_t BGR)
218 if(!(BGR&0xffff)) return 0x03000000;
219 if(DrawSemiTrans && !(BGR&0x8000))
220 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
221 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
224 uint32_t CP8RGBA(uint32_t BGR)
227 if(!(BGR&0xffff)) return 0x50000000;
228 if(DrawSemiTrans && !(BGR&0x8000))
229 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
230 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
231 if(l==0xffffff00) l=0xff000000;
235 uint32_t CP8RGBAEx(uint32_t BGR)
238 if(!(BGR&0xffff)) return 0x03000000;
239 if(DrawSemiTrans && !(BGR&0x8000))
240 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
241 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
242 if(l==0xffffff00) l=0xff000000;
246 uint32_t XP8RGBA_0(uint32_t BGR)
248 if(!(BGR&0xffff)) return 0x50000000;
249 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
252 uint32_t XP8RGBAEx_0(uint32_t BGR)
254 if(!(BGR&0xffff)) return 0x03000000;
255 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
258 uint32_t XP8BGRA_0(uint32_t BGR)
260 if(!(BGR&0xffff)) return 0x50000000;
261 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
264 uint32_t XP8BGRAEx_0(uint32_t BGR)
266 if(!(BGR&0xffff)) return 0x03000000;
267 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
270 uint32_t CP8RGBA_0(uint32_t BGR)
274 if(!(BGR&0xffff)) return 0x50000000;
275 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
276 if(l==0xfff8f800) l=0xff000000;
280 uint32_t CP8RGBAEx_0(uint32_t BGR)
284 if(!(BGR&0xffff)) return 0x03000000;
285 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
286 if(l==0xfff8f800) l=0xff000000;
290 uint32_t CP8BGRA_0(uint32_t BGR)
294 if(!(BGR&0xffff)) return 0x50000000;
295 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
296 if(l==0xff00f8f8) l=0xff000000;
300 uint32_t CP8BGRAEx_0(uint32_t BGR)
304 if(!(BGR&0xffff)) return 0x03000000;
305 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
306 if(l==0xff00f8f8) l=0xff000000;
310 uint32_t XP8RGBA_1(uint32_t BGR)
312 if(!(BGR&0xffff)) return 0x50000000;
313 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
314 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
317 uint32_t XP8RGBAEx_1(uint32_t BGR)
319 if(!(BGR&0xffff)) return 0x03000000;
320 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
321 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
324 uint32_t XP8BGRA_1(uint32_t BGR)
326 if(!(BGR&0xffff)) return 0x50000000;
327 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}
328 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
331 uint32_t XP8BGRAEx_1(uint32_t BGR)
333 if(!(BGR&0xffff)) return 0x03000000;
334 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}
335 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
338 uint32_t P8RGBA(uint32_t BGR)
340 if(!(BGR&0xffff)) return 0;
341 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
344 uint32_t P8BGRA(uint32_t BGR)
346 if(!(BGR&0xffff)) return 0;
347 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
350 unsigned short XP5RGBA(unsigned short BGR)
353 if(DrawSemiTrans && !(BGR&0x8000))
354 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
355 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
358 unsigned short XP5RGBA_0 (unsigned short BGR)
362 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
365 unsigned short CP5RGBA_0 (unsigned short BGR)
371 s=((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
376 unsigned short XP5RGBA_1(unsigned short BGR)
380 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
381 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
384 unsigned short P5RGBA(unsigned short BGR)
387 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
390 unsigned short XP4RGBA(unsigned short BGR)
393 if(DrawSemiTrans && !(BGR&0x8000))
394 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
395 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
398 unsigned short XP4RGBA_0 (unsigned short BGR)
401 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
404 unsigned short CP4RGBA_0 (unsigned short BGR)
408 s=(((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
409 if(s==0x0fff) s=0x000f;
413 unsigned short XP4RGBA_1(unsigned short BGR)
417 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
418 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
421 unsigned short P4RGBA(unsigned short BGR)
424 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
427 ////////////////////////////////////////////////////////////////////////
428 // CHECK TEXTURE MEM (on plugin startup)
429 ////////////////////////////////////////////////////////////////////////
434 void CheckTextureMemory(void)
436 GLboolean b;GLboolean * bDetail;
437 int i,iCnt,iRam=iVRamSize*1024*1024;
444 if(iResX>1024) iFTexA=2048;
446 if(iResX>512) iFTexA=1024;
448 if(iResY>1024) iFTexB=2048;
450 if(iResY>512) iFTexB=1024;
453 glGenTextures(1, &gTexBlurName);
454 gTexName=gTexBlurName;
455 glBindTexture(GL_TEXTURE_2D, gTexName);
457 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
458 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
462 p=(char *)malloc(iFTexA*iFTexB*4);
463 memset(p,0,iFTexA*iFTexB*4);
464 glTexImage2D(GL_TEXTURE_2D, 0, 3, iFTexA, iFTexB, 0, GL_RGB, GL_UNSIGNED_BYTE, p);
467 iRam-=iFTexA*iFTexB*3;
468 iFTexA=(iResX*256)/iFTexA;
469 iFTexB=(iResY*256)/iFTexB;
476 iRam-=(iResX*iResY*8);
477 iRam-=(iResX*iResY*(iZBufferDepth/8));
479 if(iTexQuality==0 || iTexQuality==3) ts=4;
483 iSortTexCnt=iRam/(512*512*ts);
484 else iSortTexCnt=iRam/(256*256*ts);
486 if(iSortTexCnt>MAXSORTTEX)
488 iSortTexCnt=MAXSORTTEX-min(1,iHiResTextures);
492 iSortTexCnt-=3+min(1,iHiResTextures);
493 if(iSortTexCnt<8) iSortTexCnt=8;
496 for(i=0;i<MAXSORTTEX;i++)
503 if(iHiResTextures) iTSize=512;
505 p=(char *)malloc(iTSize*iTSize*4);
508 glGenTextures(MAXSORTTEX,uiStexturePage);
509 for(i=0;i<MAXSORTTEX;i++)
511 glBindTexture(GL_TEXTURE_2D,uiStexturePage[i]);
512 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
516 glTexImage2D(GL_TEXTURE_2D, 0, giWantedRGBA, iTSize, iTSize, 0,GL_RGBA, giWantedTYPE, p);
518 glBindTexture(GL_TEXTURE_2D,0);
522 bDetail=malloc(MAXSORTTEX*sizeof(GLboolean));
523 memset(bDetail,0,MAXSORTTEX*sizeof(GLboolean));
524 b=glAreTexturesResident(MAXSORTTEX,uiStexturePage,bDetail);
526 glDeleteTextures(MAXSORTTEX,uiStexturePage);
528 for(i=0;i<MAXSORTTEX;i++)
530 if(bDetail[i]) iCnt++;
536 if(b) iSortTexCnt=MAXSORTTEX-min(1,iHiResTextures);
537 else iSortTexCnt=iCnt-3+min(1,iHiResTextures); // place for menu&texwnd
539 if(iSortTexCnt<8) iSortTexCnt=8;
542 ////////////////////////////////////////////////////////////////////////
543 // Main init of textures
544 ////////////////////////////////////////////////////////////////////////
546 void InitializeTextureStore()
550 if(iGPUHeight==1024)
\r
556 iTexGarbageCollection=0;
\r
566 memset(vertex,0,4*sizeof(OGLVertex)); // init vertices
568 gTexName=0; // init main tex name
570 iTexWndLimit=MAXWNDTEXCACHE;
571 if(!iUsePalTextures) iTexWndLimit/=2;
573 memset(wcWndtexStore,0,sizeof(textureWndCacheEntry)*
575 texturepart=(GLubyte *)malloc(256*256*4);
576 memset(texturepart,0,256*256*4);
578 texturebuffer=(GLubyte *)malloc(512*512*4);
579 else texturebuffer=NULL;
581 for(i=0;i<3;i++) // -> info for 32*3
582 for(j=0;j<MAXTPAGES;j++)
584 pscSubtexStore[i][j]=(textureSubCacheEntryS *)malloc(CSUBSIZES*sizeof(textureSubCacheEntryS));
585 memset(pscSubtexStore[i][j],0,CSUBSIZES*sizeof(textureSubCacheEntryS));
587 for(i=0;i<MAXSORTTEX;i++) // -> info 0..511
589 pxSsubtexLeft[i]=(EXLong *)malloc(CSUBSIZE*sizeof(EXLong));
590 memset(pxSsubtexLeft[i],0,CSUBSIZE*sizeof(EXLong));
595 ////////////////////////////////////////////////////////////////////////
597 ////////////////////////////////////////////////////////////////////////
599 void CleanupTextureStore()
601 int i,j;textureWndCacheEntry * tsx;
602 //----------------------------------------------------//
603 glBindTexture(GL_TEXTURE_2D,0);
604 //----------------------------------------------------//
605 free(texturepart); // free tex part
612 //----------------------------------------------------//
613 tsx=wcWndtexStore; // loop tex window cache
614 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)
616 if(tsx->texname) // -> some tex?
617 glDeleteTextures(1,&tsx->texname); // --> delete it
619 iMaxTexWnds=0; // no more tex wnds
620 //----------------------------------------------------//
621 if(gTexMovieName!=0) // some movie tex?
622 glDeleteTextures(1, &gTexMovieName); // -> delete it
623 gTexMovieName=0; // no more movie tex
624 //----------------------------------------------------//
625 if(gTexFrameName!=0) // some 15bit framebuffer tex?
626 glDeleteTextures(1, &gTexFrameName); // -> delete it
627 gTexFrameName=0; // no more movie tex
628 //----------------------------------------------------//
629 if(gTexBlurName!=0) // some 15bit framebuffer tex?
630 glDeleteTextures(1, &gTexBlurName); // -> delete it
631 gTexBlurName=0; // no more movie tex
632 //----------------------------------------------------//
633 for(i=0;i<3;i++) // -> loop
634 for(j=0;j<MAXTPAGES;j++) // loop tex pages
636 free(pscSubtexStore[i][j]); // -> clean mem
638 for(i=0;i<MAXSORTTEX;i++)
640 if(uiStexturePage[i]) // --> tex used ?
642 glDeleteTextures(1,&uiStexturePage[i]);
643 uiStexturePage[i]=0; // --> delete it
645 free(pxSsubtexLeft[i]); // -> clean mem
647 //----------------------------------------------------//
650 ////////////////////////////////////////////////////////////////////////
651 // Reset textures in game...
652 ////////////////////////////////////////////////////////////////////////
654 void ResetTextureArea(BOOL bDelTex)
656 int i,j;textureSubCacheEntryS * tss;EXLong * lu;
657 textureWndCacheEntry * tsx;
658 //----------------------------------------------------//
662 //----------------------------------------------------//
663 if(bDelTex) {glBindTexture(GL_TEXTURE_2D,0);gTexName=0;}
664 //----------------------------------------------------//
666 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)
669 if(bDelTex && tsx->texname)
671 glDeleteTextures(1,&tsx->texname);
676 //----------------------------------------------------//
679 for(j=0;j<MAXTPAGES;j++)
681 tss=pscSubtexStore[i][j];
682 (tss+SOFFA)->pos.l=0;
683 (tss+SOFFB)->pos.l=0;
684 (tss+SOFFC)->pos.l=0;
685 (tss+SOFFD)->pos.l=0;
688 for(i=0;i<iSortTexCnt;i++)
692 if(bDelTex && uiStexturePage[i])
693 {glDeleteTextures(1,&uiStexturePage[i]);uiStexturePage[i]=0;}
698 ////////////////////////////////////////////////////////////////////////
699 // Invalidate tex windows
700 ////////////////////////////////////////////////////////////////////////
702 void InvalidateWndTextureArea(int X, int Y, int W, int H)
704 int i,px1,px2,py1,py2,iYM=1;
705 textureWndCacheEntry * tsw=wcWndtexStore;
709 if(X<0) X=0;if(X>1023) X=1023;
710 if(W<0) W=0;if(W>1023) W=1023;
\r
711 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
\r
712 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
\r
715 if(iGPUHeight==1024) iYM=3;
\r
718 py2=min(iYM,H>>8); // y: 0 or 1
\r
725 py1=py1<<4;px1+=py1;px2+=py1; // change to 0-31
726 for(i=0;i<iMaxTexWnds;i++,tsw++)
730 if(tsw->pageid>=px1 && tsw->pageid<=px2)
739 py1=px1+16;py2=px2+16;
740 for(i=0;i<iMaxTexWnds;i++,tsw++)
744 if((tsw->pageid>=px1 && tsw->pageid<=px2) ||
745 (tsw->pageid>=py1 && tsw->pageid<=py2))
753 // adjust tex window count
754 tsw=wcWndtexStore+iMaxTexWnds-1;
755 while(iMaxTexWnds && !tsw->used) {iMaxTexWnds--;tsw--;}
760 ////////////////////////////////////////////////////////////////////////
761 // same for sort textures
762 ////////////////////////////////////////////////////////////////////////
764 void MarkFree(textureSubCacheEntryS * tsx)
767 int j,iMax;unsigned char x1,y1,dx,dy;
769 uls=pxSsubtexLeft[tsx->cTexID];
770 iMax=uls->l;ul=uls+1;
774 for(j=0;j<iMax;j++,ul++)
775 if(ul->l==0xffffffff) break;
779 if(j==iMax) uls->l=uls->l+1;
781 x1=tsx->posTX;dx=tsx->pos.c[2]-tsx->pos.c[3];
782 if(tsx->posTX) {x1--;dx+=3;}
783 y1=tsx->posTY;dy=tsx->pos.c[0]-tsx->pos.c[1];
784 if(tsx->posTY) {y1--;dy+=3;}
793 void InvalidateSubSTextureArea(int X, int Y, int W, int H)
795 int i,j,k,iMax,px,py,px1,px2,py1,py2,iYM = 1;
797 textureSubCacheEntryS *tsb;
798 int x1,x2,y1,y2,xa,sw;
802 if(X<0) X=0;if(X>1023) X=1023;
803 if(W<0) W=0;if(W>1023) W=1023;
\r
804 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
\r
805 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
\r
808 if(iGPUHeight==1024) iYM=3;
\r
811 py2=min(iYM,H>>8); // y: 0 or 1
\r
812 px1=max(0,(X>>6)-3);
\r
813 px2=min(15,(W>>6)+3); // x: 0-15
815 for(py=py1;py<=py2;py++)
817 j=(py<<4)+px1; // get page
826 if(y2<y1) {sw=y1;y1=y2;y2=sw;}
830 for(px=px1;px<=px2;px++,j++)
841 if(x2<x1) {sw=x1;x1=x2;x2=sw;}
843 if (dwGPUVersion == 2)
\r
846 npos.l=((x1-xa)<<(26-k))|((x2-xa)<<(18-k))|y1|y2;
849 tsb=pscSubtexStore[k][j]+SOFFA;iMax=tsb->pos.l;tsb++;
850 for(i=0;i<iMax;i++,tsb++)
851 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
853 // if(npos.l & 0x00800000)
855 tsb=pscSubtexStore[k][j]+SOFFB;iMax=tsb->pos.l;tsb++;
856 for(i=0;i<iMax;i++,tsb++)
857 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
860 // if(npos.l & 0x00000080)
862 tsb=pscSubtexStore[k][j]+SOFFC;iMax=tsb->pos.l;tsb++;
863 for(i=0;i<iMax;i++,tsb++)
864 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
867 // if(npos.l & 0x00800080)
869 tsb=pscSubtexStore[k][j]+SOFFD;iMax=tsb->pos.l;tsb++;
870 for(i=0;i<iMax;i++,tsb++)
871 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
879 ////////////////////////////////////////////////////////////////////////
880 // Invalidate some parts of cache: main routine
881 ////////////////////////////////////////////////////////////////////////
883 void InvalidateTextureAreaEx(void)
888 if (W == 0 && H == 0) return;
891 InvalidateWndTextureArea(sxmin,symin,W,H);
893 InvalidateSubSTextureArea(sxmin,symin,W,H);
896 ////////////////////////////////////////////////////////////////////////
898 void InvalidateTextureArea(int X, int Y, int W, int H)
900 if (W == 0 && H == 0) return;
902 if (iMaxTexWnds) InvalidateWndTextureArea(X, Y, W, H);
904 InvalidateSubSTextureArea(X, Y, W, H);
908 ////////////////////////////////////////////////////////////////////////
909 // tex window: define
910 ////////////////////////////////////////////////////////////////////////
912 void DefineTextureWnd(void)
915 glGenTextures(1, &gTexName);
917 glBindTexture(GL_TEXTURE_2D, gTexName);
919 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
920 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
922 if(iFilterType && iFilterType<3 && iHiResTextures!=2)
924 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
933 glTexImage2D(GL_TEXTURE_2D, 0,giWantedRGBA,
936 0, giWantedFMT, giWantedTYPE, texturepart);
939 ////////////////////////////////////////////////////////////////////////
940 // tex window: load packed stretch
941 ////////////////////////////////////////////////////////////////////////
943 void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
945 uint32_t start, row, column, j, sxh, sxm, ldx, ldy, ldxo;
946 unsigned int palstart;
947 unsigned short *px, *pa, *ta;
948 unsigned char *cSRCPtr,*cOSRCPtr;
949 unsigned short *wSRCPtr,*wOSRCPtr;
952 int pmult = pageid / 16;
953 unsigned short (*LPTCOL)(unsigned short);
955 LPTCOL = PTCF[DrawSemiTrans];
957 ldxo = TWin.Position.x1-TWin.OPosition.x1;
958 ldy = TWin.Position.y1-TWin.OPosition.y1;
960 pa = px = (unsigned short *)ubPaletteBuffer;
961 ta = (unsigned short *)texturepart;
962 palstart = cx + (cy * 1024);
968 //--------------------------------------------------//
969 // 4bit texture load ..
973 unsigned int TXV,TXU,n_xi,n_yi;
\r
975 wSRCPtr=psxVuw+palstart;
\r
976 for(row=0;row<16;row++)
\r
977 *px++=LPTCOL(*wSRCPtr++);
\r
980 for(TXV=g_y1;TXV<=column;TXV++)
\r
983 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
985 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
986 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
988 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
991 if(ldx) {*ta++=s;ldx--;}
\r
996 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
997 *ta++=*(ta-(g_x2-g_x1));
\r
1001 DefineTextureWnd();
\r
1007 start=((pageid-16*pmult)*128)+256*2048*pmult;
1009 // convert CLUT to 32bits .. and then use THAT as a lookup table
1011 wSRCPtr=psxVuw+palstart;
1012 for(row=0;row<16;row++)
1013 *px++=LPTCOL(*wSRCPtr++);
1015 sxm=g_x1&1;sxh=g_x1>>1;
1016 if(sxm) j=g_x1+1; else j=g_x1;
1017 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
1018 for(column=g_y1;column<=g_y2;column++)
1020 cOSRCPtr=cSRCPtr;ldx=ldxo;
1021 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
1023 for(row=j;row<=g_x2-ldxo;row++)
1025 s=*(pa+(*cSRCPtr & 0xF));
1027 if(ldx) {*ta++=s;ldx--;}
1031 s=*(pa+((*cSRCPtr >> 4) & 0xF));
1033 if(ldx) {*ta++=s;ldx--;}
1039 {ldy--;cSRCPtr = cOSRCPtr;}
1040 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
1045 //--------------------------------------------------//
1046 // 8bit texture load ..
1050 unsigned int TXV,TXU,n_xi,n_yi;
\r
1052 wSRCPtr=psxVuw+palstart;
\r
1053 for(row=0;row<256;row++)
\r
1054 *px++=LPTCOL(*wSRCPtr++);
\r
1057 for(TXV=g_y1;TXV<=column;TXV++)
\r
1060 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1062 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1063 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1065 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1068 if(ldx) {*ta++=s;ldx--;}
\r
1073 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1074 *ta++=*(ta-(g_x2-g_x1));
\r
1079 DefineTextureWnd();
\r
1084 start=((pageid-16*pmult)*128)+256*2048*pmult;
1086 // not using a lookup table here... speeds up smaller texture areas
1087 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
1088 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
1090 for(column=g_y1;column<=g_y2;column++)
1092 cOSRCPtr=cSRCPtr;ldx=ldxo;
1093 for(row=g_x1;row<=g_x2-ldxo;row++)
1095 s=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);
1097 if(ldx) {*ta++=s;ldx--;}
1099 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
1100 else cSRCPtr+=LineOffset;
1105 //--------------------------------------------------//
1106 // 16bit texture load ..
1108 start=((pageid-16*pmult)*64)+256*1024*pmult;
1109 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
1110 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo;
1112 for(column=g_y1;column<=g_y2;column++)
1114 wOSRCPtr=wSRCPtr;ldx=ldxo;
1115 for(row=g_x1;row<=g_x2-ldxo;row++)
1117 s=LPTCOL(*wSRCPtr++);
1119 if(ldx) {*ta++=s;ldx--;}
1121 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}
1122 else wSRCPtr+=LineOffset;
1127 //--------------------------------------------------//
1128 // others are not possible !
1132 ////////////////////////////////////////////////////////////////////////
1133 // tex window: load stretched
1134 ////////////////////////////////////////////////////////////////////////
1136 void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
1138 uint32_t start,row,column,j,sxh,sxm,ldx,ldy,ldxo,s;
1139 unsigned int palstart;
1140 uint32_t *px,*pa,*ta;
1141 unsigned char *cSRCPtr,*cOSRCPtr;
1142 unsigned short *wSRCPtr,*wOSRCPtr;
1143 uint32_t LineOffset;
1144 int pmult = pageid / 16;
1145 uint32_t (*LTCOL)(uint32_t);
1147 LTCOL = TCF[DrawSemiTrans];
1149 ldxo=TWin.Position.x1-TWin.OPosition.x1;
1150 ldy =TWin.Position.y1-TWin.OPosition.y1;
1152 pa = px = (uint32_t *)ubPaletteBuffer;
1153 ta = (uint32_t *)texturepart;
1154 palstart = cx + (cy * 1024);
1160 //--------------------------------------------------//
1161 // 4bit texture load ..
1163 //------------------- ZN STUFF
\r
1167 unsigned int TXV,TXU,n_xi,n_yi;
\r
1169 wSRCPtr=psxVuw+palstart;
\r
1173 *px =LTCOL(*wSRCPtr);
\r
1174 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1175 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1176 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1177 row--;px+=4;wSRCPtr+=4;
\r
1182 for(TXV=g_y1;TXV<=column;TXV++)
\r
1185 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1187 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1188 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1190 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1193 if(ldx) {*ta++=s;ldx--;}
\r
1198 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1199 *ta++=*(ta-(g_x2-g_x1));
\r
1203 DefineTextureWnd();
\r
1208 //-------------------
\r
1210 start=((pageid-16*pmult)*128)+256*2048*pmult;
1211 // convert CLUT to 32bits .. and then use THAT as a lookup table
1213 wSRCPtr=psxVuw+palstart;
1214 for(row=0;row<16;row++)
1215 *px++=LTCOL(*wSRCPtr++);
1217 sxm=g_x1&1;sxh=g_x1>>1;
1218 if(sxm) j=g_x1+1; else j=g_x1;
1219 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
1220 for(column=g_y1;column<=g_y2;column++)
1222 cOSRCPtr=cSRCPtr;ldx=ldxo;
1223 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
1225 for(row=j;row<=g_x2-ldxo;row++)
1227 s=*(pa+(*cSRCPtr & 0xF));
1229 if(ldx) {*ta++=s;ldx--;}
1233 s=*(pa+((*cSRCPtr >> 4) & 0xF));
1235 if(ldx) {*ta++=s;ldx--;}
1240 {ldy--;cSRCPtr = cOSRCPtr;}
1241 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
1246 //--------------------------------------------------//
1247 // 8bit texture load ..
1249 //------------ ZN STUFF
\r
1252 unsigned int TXV,TXU,n_xi,n_yi;
\r
1254 wSRCPtr=psxVuw+palstart;
\r
1258 *px =LTCOL(*wSRCPtr);
\r
1259 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1260 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1261 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1262 row--;px+=4;wSRCPtr+=4;
\r
1267 for(TXV=g_y1;TXV<=column;TXV++)
\r
1270 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1272 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1273 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1275 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1277 if(ldx) {*ta++=s;ldx--;}
\r
1282 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1283 *ta++=*(ta-(g_x2-g_x1));
\r
1288 DefineTextureWnd();
\r
1294 start=((pageid-16*pmult)*128)+256*2048*pmult;
1296 // not using a lookup table here... speeds up smaller texture areas
1297 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
1298 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
1300 for(column=g_y1;column<=g_y2;column++)
1302 cOSRCPtr=cSRCPtr;ldx=ldxo;
1303 for(row=g_x1;row<=g_x2-ldxo;row++)
1305 s=LTCOL(psxVuw[palstart+ *cSRCPtr++]);
1307 if(ldx) {*ta++=s;ldx--;}
1309 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
1310 else cSRCPtr+=LineOffset;
1315 //--------------------------------------------------//
1316 // 16bit texture load ..
1318 start=((pageid-16*pmult)*64)+256*1024*pmult;
1320 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
1321 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo;
1323 for(column=g_y1;column<=g_y2;column++)
1325 wOSRCPtr=wSRCPtr;ldx=ldxo;
1326 for(row=g_x1;row<=g_x2-ldxo;row++)
1328 s=LTCOL(*wSRCPtr++);
1330 if(ldx) {*ta++=s;ldx--;}
1332 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}
1333 else wSRCPtr+=LineOffset;
1338 //--------------------------------------------------//
1339 // others are not possible !
1343 ////////////////////////////////////////////////////////////////////////
1344 // tex window: load packed simple
1345 ////////////////////////////////////////////////////////////////////////
1347 void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
1349 uint32_t start,row,column,j,sxh,sxm;
1350 unsigned int palstart;
1351 unsigned short *px,*pa,*ta;
1352 unsigned char *cSRCPtr;
1353 unsigned short *wSRCPtr;
1354 uint32_t LineOffset;
1355 int pmult=pageid/16;
1356 unsigned short (*LPTCOL)(unsigned short);
1358 LPTCOL=PTCF[DrawSemiTrans];
1360 pa=px=(unsigned short *)ubPaletteBuffer;
1361 ta=(unsigned short *)texturepart;
1362 palstart=cx+(cy*1024);
1368 //--------------------------------------------------//
1369 // 4bit texture load ..
1373 unsigned int TXV,TXU,n_xi,n_yi;
\r
1375 wSRCPtr=psxVuw+palstart;
\r
1376 for(row=0;row<16;row++)
\r
1377 *px++=LPTCOL(*wSRCPtr++);
\r
1379 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1381 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1383 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1384 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1386 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1390 DefineTextureWnd();
\r
1395 start=((pageid-16*pmult)*128)+256*2048*pmult;
1397 // convert CLUT to 32bits .. and then use THAT as a lookup table
1399 wSRCPtr=psxVuw+palstart;
1400 for(row=0;row<16;row++)
1401 *px++=LPTCOL(*wSRCPtr++);
1403 sxm=g_x1&1;sxh=g_x1>>1;
1404 if(sxm) j=g_x1+1; else j=g_x1;
1405 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
1406 for(column=g_y1;column<=g_y2;column++)
1408 cSRCPtr = psxVub + start + (2048*column) + sxh;
1410 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
1412 for(row=j;row<=g_x2;row++)
1414 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
1415 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
1422 //--------------------------------------------------//
1423 // 8bit texture load ..
1427 unsigned int TXV,TXU,n_xi,n_yi;
\r
1429 wSRCPtr=psxVuw+palstart;
\r
1430 for(row=0;row<256;row++)
\r
1431 *px++=LPTCOL(*wSRCPtr++);
\r
1433 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1435 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1437 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1438 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1440 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1444 DefineTextureWnd();
\r
1449 start=((pageid-16*pmult)*128)+256*2048*pmult;
1451 // not using a lookup table here... speeds up smaller texture areas
1452 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
1453 LineOffset = 2048 - (g_x2-g_x1+1);
1455 for(column=g_y1;column<=g_y2;column++)
1457 for(row=g_x1;row<=g_x2;row++)
1458 *ta++=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);
1459 cSRCPtr+=LineOffset;
1464 //--------------------------------------------------//
1465 // 16bit texture load ..
1467 start=((pageid-16*pmult)*64)+256*1024*pmult;
1468 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
1469 LineOffset = 1024 - (g_x2-g_x1+1);
1471 for(column=g_y1;column<=g_y2;column++)
1473 for(row=g_x1;row<=g_x2;row++)
1474 *ta++=LPTCOL(*wSRCPtr++);
1475 wSRCPtr+=LineOffset;
1480 //--------------------------------------------------//
1481 // others are not possible !
1485 ////////////////////////////////////////////////////////////////////////
1486 // tex window: load simple
1487 ////////////////////////////////////////////////////////////////////////
1489 void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
1491 uint32_t start,row,column,j,sxh,sxm;
1492 unsigned int palstart;
1493 uint32_t *px,*pa,*ta;
1494 unsigned char *cSRCPtr;
1495 unsigned short *wSRCPtr;
1496 uint32_t LineOffset;
1497 int pmult = pageid / 16;
1498 uint32_t (*LTCOL)(uint32_t);
1500 LTCOL=TCF[DrawSemiTrans];
1502 pa = px = (uint32_t *)ubPaletteBuffer;
1503 ta = (uint32_t *)texturepart;
1504 palstart = cx + (cy * 1024);
1510 //--------------------------------------------------//
1511 // 4bit texture load ..
1515 unsigned int TXV,TXU,n_xi,n_yi;
\r
1517 wSRCPtr=psxVuw+palstart;
\r
1521 *px =LTCOL(*wSRCPtr);
\r
1522 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1523 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1524 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1525 row--;px+=4;wSRCPtr+=4;
\r
1529 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1531 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1533 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1534 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1536 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1540 DefineTextureWnd();
\r
1545 start=((pageid-16*pmult)*128)+256*2048*pmult;
1547 // convert CLUT to 32bits .. and then use THAT as a lookup table
1549 wSRCPtr=psxVuw+palstart;
1550 for(row=0;row<16;row++)
1551 *px++=LTCOL(*wSRCPtr++);
1553 sxm=g_x1&1;sxh=g_x1>>1;
1554 if(sxm) j=g_x1+1; else j=g_x1;
1555 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
1556 for(column=g_y1;column<=g_y2;column++)
1558 cSRCPtr = psxVub + start + (2048*column) + sxh;
1560 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
1562 for(row=j;row<=g_x2;row++)
1564 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
1565 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
1572 //--------------------------------------------------//
1573 // 8bit texture load ..
1577 unsigned int TXV,TXU,n_xi,n_yi;
\r
1579 wSRCPtr=psxVuw+palstart;
\r
1583 *px =LTCOL(*wSRCPtr);
\r
1584 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1585 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1586 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1587 row--;px+=4;wSRCPtr+=4;
\r
1591 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1593 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1595 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1596 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1598 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1602 DefineTextureWnd();
\r
1607 start=((pageid-16*pmult)*128)+256*2048*pmult;
1609 // not using a lookup table here... speeds up smaller texture areas
1610 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
1611 LineOffset = 2048 - (g_x2-g_x1+1);
1613 for(column=g_y1;column<=g_y2;column++)
1615 for(row=g_x1;row<=g_x2;row++)
1616 *ta++=LTCOL(psxVuw[palstart+ *cSRCPtr++]);
1617 cSRCPtr+=LineOffset;
1622 //--------------------------------------------------//
1623 // 16bit texture load ..
1625 start=((pageid-16*pmult)*64)+256*1024*pmult;
1627 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
1628 LineOffset = 1024 - (g_x2-g_x1+1);
1630 for(column=g_y1;column<=g_y2;column++)
1632 for(row=g_x1;row<=g_x2;row++)
1633 *ta++=LTCOL(*wSRCPtr++);
1634 wSRCPtr+=LineOffset;
1639 //--------------------------------------------------//
1640 // others are not possible !
1644 ////////////////////////////////////////////////////////////////////////
1645 ////////////////////////////////////////////////////////////////////////
1646 ////////////////////////////////////////////////////////////////////////
1647 ////////////////////////////////////////////////////////////////////////
1649 void UploadTexWndPal(int mode,short cx,short cy)
1651 unsigned int i,iSize;
1652 unsigned short *wSrcPtr;
1653 uint32_t *ta = (uint32_t *)texturepart;
1655 wSrcPtr = psxVuw + cx + (cy * 1024);
1656 if (mode == 0) i = 4; else i = 64;
1662 *ta =PALCOL(*wSrcPtr);
1663 *(ta+1)=PALCOL(*(wSrcPtr+1));
1664 *(ta+2)=PALCOL(*(wSrcPtr+2));
1665 *(ta+3)=PALCOL(*(wSrcPtr+3));
1666 ta+=4;wSrcPtr+=4;i--;
1670 (*glColorTableEXTEx)(GL_TEXTURE_2D,GL_RGBA8,iSize,
1671 GL_RGBA,GL_UNSIGNED_BYTE,texturepart);
1674 ////////////////////////////////////////////////////////////////////////
1676 void DefinePalTextureWnd(void)
1679 glGenTextures(1, &gTexName);
1681 glBindTexture(GL_TEXTURE_2D, gTexName);
1683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1686 if(iFilterType && iFilterType<3 && iHiResTextures!=2)
1688 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1689 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1693 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1694 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1697 glTexImage2D(GL_TEXTURE_2D, 0,GL_COLOR_INDEX8_EXT,
1700 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE,texturepart);
1703 ///////////////////////////////////////////////////////
1705 void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
1707 uint32_t start,row,column,j,sxh,sxm;
1709 unsigned char *cSRCPtr;
1710 uint32_t LineOffset;
\r
1711 int pmult = pageid / 16;
1713 ta = (unsigned char *)texturepart;
1717 //--------------------------------------------------//
1718 // 4bit texture load ..
1720 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1722 sxm=g_x1&1;sxh=g_x1>>1;
1723 if(sxm) j=g_x1+1; else j=g_x1;
1724 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
1725 for(column=g_y1;column<=g_y2;column++)
1727 cSRCPtr = psxVub + start + (2048*column) + sxh;
1729 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);
1731 for(row=j;row<=g_x2;row++)
1733 *ta++=(*cSRCPtr & 0xF); row++;
1734 if(row<=g_x2) *ta++=((*cSRCPtr >> 4) & 0xF);
1739 DefinePalTextureWnd();
1741 //--------------------------------------------------//
1742 // 8bit texture load ..
1744 start=((pageid-16*pmult)*128)+256*2048*pmult;
1746 // not using a lookup table here... speeds up smaller texture areas
1747 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
1748 LineOffset = 2048 - (g_x2-g_x1+1);
1750 for(column=g_y1;column<=g_y2;column++)
1752 for(row=g_x1;row<=g_x2;row++)
1754 cSRCPtr+=LineOffset;
1757 DefinePalTextureWnd();
1760 UploadTexWndPal(mode,cx,cy);
1763 ////////////////////////////////////////////////////////////////////////
1765 void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
1767 uint32_t start,row,column,j,sxh,sxm,ldx,ldy,ldxo;
1768 unsigned char *ta,s;
1769 unsigned char *cSRCPtr,*cOSRCPtr;
1770 uint32_t LineOffset;
1771 int pmult = pageid / 16;
\r
1773 ldxo = TWin.Position.x1-TWin.OPosition.x1;
1774 ldy = TWin.Position.y1-TWin.OPosition.y1;
1776 ta = (unsigned char *)texturepart;
1780 //--------------------------------------------------//
1781 // 4bit texture load ..
1783 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1785 sxm=g_x1&1;sxh=g_x1>>1;
1786 if(sxm) j=g_x1+1; else j=g_x1;
1787 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
1788 for(column=g_y1;column<=g_y2;column++)
1790 cOSRCPtr=cSRCPtr;ldx=ldxo;
1791 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);
1793 for(row=j;row<=g_x2-ldxo;row++)
1797 if(ldx) {*ta++=s;ldx--;}
1801 s=((*cSRCPtr >> 4) & 0xF);
1803 if(ldx) {*ta++=s;ldx--;}
1808 {ldy--;cSRCPtr = cOSRCPtr;}
1809 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
1812 DefinePalTextureWnd();
1814 //--------------------------------------------------//
1815 // 8bit texture load ..
1817 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1819 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
1820 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
1822 for(column=g_y1;column<=g_y2;column++)
1824 cOSRCPtr=cSRCPtr;ldx=ldxo;
1825 for(row=g_x1;row<=g_x2-ldxo;row++)
1829 if(ldx) {*ta++=s;ldx--;}
1831 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
1832 else cSRCPtr+=LineOffset;
1835 DefinePalTextureWnd();
1838 UploadTexWndPal(mode,cx,cy);
1841 ////////////////////////////////////////////////////////////////////////
1842 // tex window: main selecting, cache handler included
1843 ////////////////////////////////////////////////////////////////////////
1845 GLuint LoadTextureWnd(int pageid, int TextureMode, uint32_t GivenClutId)
1847 textureWndCacheEntry *ts, *tsx = NULL;
1852 npos.c[3] = TWin.Position.x0;
1853 npos.c[2] = TWin.OPosition.x1;
1854 npos.c[1] = TWin.Position.y0;
1855 npos.c[0] = TWin.OPosition.y1;
1857 g_x1 = TWin.Position.x0; g_x2 = g_x1 + TWin.Position.x1 - 1;
1858 g_y1 = TWin.Position.y0; g_y2 = g_y1 + TWin.Position.y1 - 1;
1860 if (TextureMode == 2) { GivenClutId = 0; cx = cy = 0; }
1863 cx = ((GivenClutId << 4) & 0x3F0);
1864 cy = ((GivenClutId >> 6) & CLUTYMASK);
1865 GivenClutId = (GivenClutId & CLUTMASK) | (DrawSemiTrans << 30);
1867 // palette check sum
1870 uint32_t *lSRCPtr = (uint32_t *)(psxVuw + cx + (cy * 1024));
1871 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
1872 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
1873 l=(l+HIWORD(l))&0x3fffL;
1874 GivenClutId|=(l<<16);
1881 for(i=0;i<iMaxTexWnds;i++,ts++)
1885 if(ts->pos.l==npos.l &&
1886 ts->pageid==pageid &&
1887 ts->textureMode==TextureMode)
1889 if(ts->ClutID==GivenClutId)
1891 ubOpaqueDraw=ts->Opaque;
1894 else if(glColorTableEXTEx && TextureMode!=2)
1896 ts->ClutID=GivenClutId;
1897 if(ts->texname!=gTexName)
1899 gTexName=ts->texname;
1900 glBindTexture(GL_TEXTURE_2D, gTexName);
1902 UploadTexWndPal(TextureMode,cx,cy);
1903 ts->Opaque=ubOpaqueDraw;
1913 if(iMaxTexWnds==iTexWndLimit)
1915 tsx=wcWndtexStore+iTexWndTurn;
1917 if(iTexWndTurn==iTexWndLimit) iTexWndTurn=0;
1921 tsx=wcWndtexStore+iMaxTexWnds;
1926 gTexName=tsx->texname;
1928 if(TWin.OPosition.y1==TWin.Position.y1 &&
1929 TWin.OPosition.x1==TWin.Position.x1)
1931 if(glColorTableEXTEx && TextureMode!=2)
1932 LoadPalWndTexturePage(pageid,TextureMode,cx,cy);
1935 LoadPackedWndTexturePage(pageid,TextureMode,cx,cy);
1937 LoadWndTexturePage(pageid,TextureMode,cx,cy);
1941 if(glColorTableEXTEx && TextureMode!=2)
1942 LoadStretchPalWndTexturePage(pageid,TextureMode,cx,cy);
1945 LoadStretchPackedWndTexturePage(pageid,TextureMode,cx,cy);
1947 LoadStretchWndTexturePage(pageid,TextureMode,cx,cy);
1950 tsx->Opaque=ubOpaqueDraw;
1952 tsx->ClutID=GivenClutId;
1954 tsx->textureMode=TextureMode;
1955 tsx->texname=gTexName;
1961 /////////////////////////////////////////////////////////////////////////////
1962 /////////////////////////////////////////////////////////////////////////////
1963 /////////////////////////////////////////////////////////////////////////////
1965 ////////////////////////////////////////////////////////////////////////
1966 // movie texture: define
1967 ////////////////////////////////////////////////////////////////////////
1969 void DefinePackedTextureMovie(void)
1971 if(gTexMovieName==0)
1973 glGenTextures(1, &gTexMovieName);
1974 gTexName=gTexMovieName;
1975 glBindTexture(GL_TEXTURE_2D, gTexName);
1977 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
1978 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
1982 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1983 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1987 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1988 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1991 glTexImage2D(GL_TEXTURE_2D, 0, //giWantedRGBA,
1993 256, 256, 0, GL_RGBA, giWantedTYPE, texturepart);
1997 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName);
2000 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
2001 (xrMovieArea.x1-xrMovieArea.x0),
2002 (xrMovieArea.y1-xrMovieArea.y0),
2004 GL_UNSIGNED_SHORT_5_5_5_1_EXT,
2008 ////////////////////////////////////////////////////////////////////////
2010 void DefineTextureMovie(void)
2012 if(gTexMovieName==0)
2014 glGenTextures(1, &gTexMovieName);
2015 gTexName=gTexMovieName;
2016 glBindTexture(GL_TEXTURE_2D, gTexName);
2018 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
2019 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
2023 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2024 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2028 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2029 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2032 glTexImage2D(GL_TEXTURE_2D, 0, giWantedRGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
2036 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName);
2039 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
2040 (xrMovieArea.x1-xrMovieArea.x0),
2041 (xrMovieArea.y1-xrMovieArea.y0),
2042 GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
2045 ////////////////////////////////////////////////////////////////////////
2046 // movie texture: load
2047 ////////////////////////////////////////////////////////////////////////
2049 #define MRED(x) ((x>>3) & 0x1f)
2050 #define MGREEN(x) ((x>>6) & 0x3e0)
2051 #define MBLUE(x) ((x>>9) & 0x7c00)
2053 #define XMGREEN(x) ((x>>5) & 0x07c0)
2054 #define XMRED(x) ((x<<8) & 0xf800)
2055 #define XMBLUE(x) ((x>>18) & 0x003e)
2057 ////////////////////////////////////////////////////////////////////////
2058 // movie texture: load
2059 ////////////////////////////////////////////////////////////////////////
2061 unsigned char * LoadDirectMovieFast(void)
2064 unsigned int startxy;
2066 uint32_t *ta=(uint32_t *)texturepart;
2068 if(PSXDisplay.RGB24)
2072 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
2074 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)
2076 pD=(unsigned char *)&psxVuw[startxy];
2077 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2079 *ta++=*((uint32_t *)pD)|0xff000000;
2086 uint32_t (*LTCOL)(uint32_t);
2088 LTCOL=XP8RGBA_0;//TCF[0];
2092 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2094 startxy=((1024)*column)+xrMovieArea.x0;
2095 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2096 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
2103 ////////////////////////////////////////////////////////////////////////
2105 GLuint LoadTextureMovieFast(void)
2108 unsigned int start,startxy;
2112 if(PSXDisplay.RGB24)
2114 unsigned char * pD; uint32_t lu1,lu2;
2115 unsigned short * ta=(unsigned short *)texturepart;
2116 short sx0=xrMovieArea.x1-1;
2120 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
2121 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2123 pD=(unsigned char *)&psxVuw[startxy];
2126 for(row=xrMovieArea.x0;row<sx0;row+=2)
2128 lu1=*((uint32_t *)pD);pD+=3;
2129 lu2=*((uint32_t *)pD);pD+=3;
2132 (XMBLUE(lu1)|XMGREEN(lu1)|XMRED(lu1)|1)|
2133 ((XMBLUE(lu2)|XMGREEN(lu2)|XMRED(lu2)|1)<<16);
2138 lu1=*((uint32_t *)pD);
2139 *ta++=XMBLUE(lu1)|XMGREEN(lu1)|XMRED(lu1)|1;
2145 unsigned short *ta=(unsigned short *)texturepart;
2147 short sx0=xrMovieArea.x1-1;
2149 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2151 startxy=((1024)*column)+xrMovieArea.x0;
2152 for(row=xrMovieArea.x0;row<sx0;row+=2)
2154 lc=*((uint32_t *)&psxVuw[startxy]);
2156 ((lc&0x001f001f)<<11)|((lc&0x03e003e0)<<1)|((lc&0x7c007c00)>>9)|0x00010001;
2159 if(row==sx0) *ta++=(psxVuw[startxy]<<1)|1;
2162 DefinePackedTextureMovie();
2166 if(PSXDisplay.RGB24)
2169 uint32_t *ta = (uint32_t *)texturepart;
2171 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
2173 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)
2175 //startxy=((1024)*column)+xrMovieArea.x0;
2176 pD = (unsigned char *)&psxVuw[startxy];
2177 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2179 *ta++=*((uint32_t *)pD)|0xff000000;
2186 uint32_t (*LTCOL)(uint32_t);
2189 LTCOL = XP8RGBA_0;//TCF[0];
2192 ta = (uint32_t *)texturepart;
2194 for (column = xrMovieArea.y0; column < xrMovieArea.y1; column++)
2196 startxy = (1024 * column) + xrMovieArea.x0;
2197 for (row = xrMovieArea.x0; row < xrMovieArea.x1; row++)
2198 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
2201 DefineTextureMovie();
2206 ////////////////////////////////////////////////////////////////////////
2208 GLuint LoadTextureMovie(void)
2210 short row,column,dx;
2211 unsigned int startxy;
2214 if(bUseFastMdec) return LoadTextureMovieFast();
2216 b_X=FALSE;b_Y=FALSE;
2218 if((xrMovieArea.x1-xrMovieArea.x0)<255) b_X=TRUE;
2219 if((xrMovieArea.y1-xrMovieArea.y0)<255) b_Y=TRUE;
2225 if(PSXDisplay.RGB24)
2229 unsigned short * ta=(unsigned short *)texturepart;
2233 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2235 startxy=((1024)*column)+xrMovieArea.x0;
2236 pD=(unsigned char *)&psxVuw[startxy];
2237 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2239 lu=*((uint32_t *)pD);pD+=3;
2240 *ta++=XMBLUE(lu)|XMGREEN(lu)|XMRED(lu)|1;
2246 dx=xrMovieArea.x1-xrMovieArea.x0+1;
2247 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2254 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2256 startxy=((1024)*column)+xrMovieArea.x0;
2257 pD=(unsigned char *)&psxVuw[startxy];
2258 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2260 lu=*((uint32_t *)pD);pD+=3;
2261 *ta++=XMBLUE(lu)|XMGREEN(lu)|XMRED(lu)|1;
2266 dx=xrMovieArea.x1-xrMovieArea.x0;
2267 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2278 ta=(unsigned short *)texturepart;
2282 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2284 startxy=((1024)*column)+xrMovieArea.x0;
2285 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2287 c=psxVuw[startxy++];
2288 *ta++=((c&0x1f)<<11)|((c&0x3e0)<<1)|((c&0x7c00)>>9)|1;
2295 dx=xrMovieArea.x1-xrMovieArea.x0+1;
2296 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2303 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2305 startxy=((1024)*column)+xrMovieArea.x0;
2306 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2308 c=psxVuw[startxy++];
2309 *ta++=((c&0x1f)<<11)|((c&0x3e0)<<1)|((c&0x7c00)>>9)|1;
2314 dx=xrMovieArea.x1-xrMovieArea.x0;
2315 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2320 xrMovieArea.x1+=b_X;xrMovieArea.y1+=b_Y;
2321 DefinePackedTextureMovie();
2322 xrMovieArea.x1-=b_X;xrMovieArea.y1-=b_Y;
2326 if(PSXDisplay.RGB24)
2329 uint32_t * ta=(uint32_t *)texturepart;
2333 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2335 startxy=((1024)*column)+xrMovieArea.x0;
2336 pD=(unsigned char *)&psxVuw[startxy];
2337 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2339 *ta++=*((uint32_t *)pD)|0xff000000;
2346 dx=xrMovieArea.x1-xrMovieArea.x0+1;
2347 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2354 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2356 startxy=((1024)*column)+xrMovieArea.x0;
2357 pD=(unsigned char *)&psxVuw[startxy];
2358 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2360 *ta++=*((uint32_t *)pD)|0xff000000;
2366 dx=xrMovieArea.x1-xrMovieArea.x0;
2367 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2374 uint32_t (*LTCOL)(uint32_t);
2377 LTCOL=XP8RGBA_0;//TCF[0];
2380 ta=(uint32_t *)texturepart;
2384 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2386 startxy=((1024)*column)+xrMovieArea.x0;
2387 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2388 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
2394 dx=xrMovieArea.x1-xrMovieArea.x0+1;
2395 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2402 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
2404 startxy=((1024)*column)+xrMovieArea.x0;
2405 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2406 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
2411 dx=xrMovieArea.x1-xrMovieArea.x0;
2412 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
2418 xrMovieArea.x1+=b_X;xrMovieArea.y1+=b_Y;
2419 DefineTextureMovie();
2420 xrMovieArea.x1-=b_X;xrMovieArea.y1-=b_Y;
2425 /////////////////////////////////////////////////////////////////////////////
2426 /////////////////////////////////////////////////////////////////////////////
2427 /////////////////////////////////////////////////////////////////////////////
2429 GLuint BlackFake15BitTexture(void)
2431 int pmult;short x1,x2,y1,y2;
2433 if(PSXDisplay.InterlacedTest) return 0;
2435 pmult=GlobalTexturePage/16;
2437 x2=gl_ux[6]-gl_ux[7];
2439 y2=gl_ux[4]-gl_ux[5];
2448 x1+=((GlobalTexturePage-16*pmult)<<6);
2450 if( FastCheckAgainstFrontScreen(x1,y1,x2,y2)
2451 || FastCheckAgainstScreen(x1,y1,x2,y2))
2455 glGenTextures(1, &gTexFrameName);
2456 gTexName=gTexFrameName;
2457 glBindTexture(GL_TEXTURE_2D, gTexName);
2459 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
2460 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
2461 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2462 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2466 unsigned short s;unsigned short * ta;
2468 if(giWantedTYPE==GL_UNSIGNED_SHORT_4_4_4_4_EXT)
2472 ta=(unsigned short *)texturepart;
2473 for(y1=0;y1<=4;y1++)
2474 for(x1=0;x1<=4;x1++)
2479 uint32_t *ta=(uint32_t *)texturepart;
2480 for(y1=0;y1<=4;y1++)
2481 for(x1=0;x1<=4;x1++)
2484 glTexImage2D(GL_TEXTURE_2D, 0, giWantedRGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
2488 gTexName=gTexFrameName;
2489 glBindTexture(GL_TEXTURE_2D, gTexName);
2494 return (GLuint)gTexName;
2499 /////////////////////////////////////////////////////////////////////////////
2501 BOOL bFakeFrontBuffer=FALSE;
2502 BOOL bIgnoreNextTile =FALSE;
2506 GLuint Fake15BitTexture(void)
2508 int pmult;short x1,x2,y1,y2;int iYAdjust;
2509 float ScaleX,ScaleY;RECT rSrc;
2511 if(iFrameTexType==1) return BlackFake15BitTexture();
2512 if(PSXDisplay.InterlacedTest) return 0;
2514 pmult=GlobalTexturePage/16;
2516 x2=gl_ux[6]-gl_ux[7];
2518 y2=gl_ux[4]-gl_ux[5];
2521 x1+=((GlobalTexturePage-16*pmult)<<6);
2523 if(iFrameTexType==3)
2525 if(iFrameReadType==4) return 0;
2527 if(!FastCheckAgainstFrontScreen(x1,y1,x2,y2) &&
2528 !FastCheckAgainstScreen(x1,y1,x2,y2))
2531 if(bFakeFrontBuffer) bIgnoreNextTile=TRUE;
2532 CheckVRamReadEx(x1,y1,x1+x2,y1+y2);
2536 /////////////////////////
2538 if(FastCheckAgainstFrontScreen(x1,y1,x2,y2))
2540 x1-=PSXDisplay.DisplayPosition.x;
2541 y1-=PSXDisplay.DisplayPosition.y;
2544 if(FastCheckAgainstScreen(x1,y1,x2,y2))
2546 x1-=PreviousPSXDisplay.DisplayPosition.x;
2547 y1-=PreviousPSXDisplay.DisplayPosition.y;
2551 bDrawMultiPass = FALSE;
2557 if(iResX>1280 || iResY>1024) iFTex=2048;
2559 if(iResX>640 || iResY>480) iFTex=1024;
2562 glGenTextures(1, &gTexFrameName);
2563 gTexName=gTexFrameName;
2564 glBindTexture(GL_TEXTURE_2D, gTexName);
2566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
2567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
2568 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2569 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2571 p=(char *)malloc(iFTex*iFTex*4);
2572 memset(p,0,iFTex*iFTex*4);
2573 glTexImage2D(GL_TEXTURE_2D, 0, 3, iFTex, iFTex, 0, GL_RGB, GL_UNSIGNED_BYTE, p);
2580 gTexName=gTexFrameName;
2581 glBindTexture(GL_TEXTURE_2D, gTexName);
2584 x1+=PreviousPSXDisplay.Range.x0;
2585 y1+=PreviousPSXDisplay.Range.y0;
2587 if(PSXDisplay.DisplayMode.x)
2588 ScaleX=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;
2590 if(PSXDisplay.DisplayMode.y)
2591 ScaleY=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;
2594 rSrc.left =max(x1*ScaleX,0);
2595 rSrc.right =min((x1+x2)*ScaleX+0.99f,iResX-1);
2596 rSrc.top =max(y1*ScaleY,0);
2597 rSrc.bottom=min((y1+y2)*ScaleY+0.99f,iResY-1);
2599 iYAdjust=(y1+y2)-PSXDisplay.DisplayMode.y;
2601 iYAdjust=(int)((float)iYAdjust*ScaleY)+1;
2604 gl_vy[0]=255-gl_vy[0];
2605 gl_vy[1]=255-gl_vy[1];
2606 gl_vy[2]=255-gl_vy[2];
2607 gl_vy[3]=255-gl_vy[3];
2609 y1=min(gl_vy[0],min(gl_vy[1],min(gl_vy[2],gl_vy[3])));
2620 ScaleX*=256.0f/((float)(iFTex));
2621 ScaleY*=256.0f/((float)(iFTex));
2623 y1=((float)gl_vy[0]*ScaleY); if(y1>255) y1=255;
2625 y1=((float)gl_vy[1]*ScaleY); if(y1>255) y1=255;
2627 y1=((float)gl_vy[2]*ScaleY); if(y1>255) y1=255;
2629 y1=((float)gl_vy[3]*ScaleY); if(y1>255) y1=255;
2632 x1=((float)gl_ux[0]*ScaleX); if(x1>255) x1=255;
2634 x1=((float)gl_ux[1]*ScaleX); if(x1>255) x1=255;
2636 x1=((float)gl_ux[2]*ScaleX); if(x1>255) x1=255;
2638 x1=((float)gl_ux[3]*ScaleX); if(x1>255) x1=255;
2641 x1=rSrc.right-rSrc.left;
2643 if(x1>iFTex) x1=iFTex;
2645 y1=rSrc.bottom-rSrc.top;
2647 if(y1+iYAdjust>iFTex) y1=iFTex-iYAdjust;
2649 if(bFakeFrontBuffer) glReadBuffer(GL_FRONT);
2651 glCopyTexSubImage2D( GL_TEXTURE_2D, 0,
2654 rSrc.left+rRatioRect.left,
2655 iResY-rSrc.bottom-rRatioRect.top,
2660 char * p=(char *)malloc(iFTex*iFTex*4);
2661 memset(p,0,iFTex*iFTex*4);
2662 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, iFTex, iFTex,
2663 GL_RGB, GL_UNSIGNED_BYTE, p);
2667 if(bFakeFrontBuffer)
2668 {glReadBuffer(GL_BACK);bIgnoreNextTile=TRUE;}
2674 sprtW=gl_ux[1]-gl_ux[0];
2675 sprtH=-(gl_vy[0]-gl_vy[2]);
2678 return (GLuint)gTexName;
2681 /////////////////////////////////////////////////////////////////////////////
2682 /////////////////////////////////////////////////////////////////////////////
2683 /////////////////////////////////////////////////////////////////////////////
2685 // load texture part (unpacked)
2687 /////////////////////////////////////////////////////////////////////////////
2688 /////////////////////////////////////////////////////////////////////////////
2689 /////////////////////////////////////////////////////////////////////////////
2691 void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)
2693 uint32_t start,row,column,j,sxh,sxm;
2694 unsigned int palstart;
2695 uint32_t *px,*pa,*ta;
2696 unsigned char *cSRCPtr;
2697 unsigned short *wSRCPtr;
2698 uint32_t LineOffset;
2699 uint32_t x2a,xalign=0;
2700 uint32_t x1=gl_ux[7];
2701 uint32_t x2=gl_ux[6];
2702 uint32_t y1=gl_ux[5];
2703 uint32_t y2=gl_ux[4];
2704 uint32_t dx=x2-x1+1;
2705 uint32_t dy=y2-y1+1;
2706 int pmult=pageid/16;
2707 uint32_t (*LTCOL)(uint32_t);
2708 unsigned int a,r,g,b,cnt,h;
2711 LTCOL=TCF[DrawSemiTrans];
2713 pa=px=(uint32_t *)ubPaletteBuffer;
2714 ta=(uint32_t *)texturepart;
2715 palstart=cx+(cy<<10);
2719 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}
2720 if(XTexS) {ta+=1;xalign=2;}
2724 //--------------------------------------------------//
2725 // 4bit texture load ..
2729 unsigned int TXV,TXU,n_xi,n_yi;
\r
2731 wSRCPtr=psxVuw+palstart;
\r
2735 *px =LTCOL(*wSRCPtr);
\r
2736 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2737 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2738 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2739 row--;px+=4;wSRCPtr+=4;
\r
2743 for(TXV=y1;TXV<=y2;TXV++)
\r
2745 for(TXU=x1;TXU<=x2;TXU++)
\r
2747 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
2748 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
2750 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
2757 start=((pageid-16*pmult)<<7)+524288*pmult;
2758 // convert CLUT to 32bits .. and then use THAT as a lookup table
2760 wSRCPtr=psxVuw+palstart;
2764 *px =LTCOL(*wSRCPtr);
2765 *(px+1)=LTCOL(*(wSRCPtr+1));
2766 *(px+2)=LTCOL(*(wSRCPtr+2));
2767 *(px+3)=LTCOL(*(wSRCPtr+3));
2768 row--;px+=4;wSRCPtr+=4;
2772 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;
2774 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;
2775 for(column=y1;column<=y2;column++)
2777 cSRCPtr = psxVub + start + (column<<11) + sxh;
2779 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
2781 for(row=j;row<x2a;row+=2)
2783 *ta =*(pa+(*cSRCPtr & 0xF));
2784 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF));
2790 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
2791 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
2798 //--------------------------------------------------//
2799 // 8bit texture load ..
2803 unsigned int TXV,TXU,n_xi,n_yi;
\r
2805 wSRCPtr=psxVuw+palstart;
\r
2809 *px =LTCOL(*wSRCPtr);
\r
2810 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2811 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2812 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2813 row--;px+=4;wSRCPtr+=4;
\r
2817 for(TXV=y1;TXV<=y2;TXV++)
\r
2819 for(TXU=x1;TXU<=x2;TXU++)
\r
2821 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
2822 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
2824 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
2832 start=((pageid-16*pmult)<<7)+524288*pmult;
2834 cSRCPtr = psxVub + start + (y1<<11) + x1;
2835 LineOffset = 2048 - dx;
2839 wSRCPtr=psxVuw+palstart;
2843 *px =LTCOL(*wSRCPtr);
2844 *(px+1)=LTCOL(*(wSRCPtr+1));
2845 *(px+2)=LTCOL(*(wSRCPtr+2));
2846 *(px+3)=LTCOL(*(wSRCPtr+3));
2847 row--;px+=4;wSRCPtr+=4;
2854 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);
2856 cSRCPtr+=LineOffset;column--;
2862 wSRCPtr=psxVuw+palstart;
2867 do {*ta++=LTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);
2869 cSRCPtr+=LineOffset;column--;
2875 //--------------------------------------------------//
2876 // 16bit texture load ..
2878 start=((pageid-16*pmult)<<6)+262144*pmult;
2880 wSRCPtr = psxVuw + start + (y1<<10) + x1;
2881 LineOffset = 1024 - dx;
2886 do {*ta++=LTCOL(*wSRCPtr++);row--;} while(row);
2888 wSRCPtr+=LineOffset;column--;
2893 //--------------------------------------------------//
2894 // others are not possible !
2901 ta=(uint32_t *)texturepart;
2902 pa=(uint32_t *)texturepart+x2a;
2903 row=x2a;do {*ta++=*pa++;row--;} while(row);
2904 pa=(uint32_t *)texturepart+dy*x2a;
2906 row=x2a;do {*ta++=*pa++;row--;} while(row);
2913 ta=(uint32_t *)texturepart;
2915 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
2916 pa=(uint32_t *)texturepart+dx;
2918 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
2923 DXTexS=dx;DYTexS=dy;
2925 if(!iFilterType) {DefineSubTextureSort();return;}
2926 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}
2927 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)
2928 {DefineSubTextureSort();return;}
2930 ta=(uint32_t *)texturepart;
2938 for(column=0;column<dy;column++)
2940 for(row=0;row<dx;row++)
2946 if( column && *(ta-dx) >>24 !=0x03) scol[cnt++]=*(ta-dx);
2947 if(row && *(ta-1) >>24 !=0x03) scol[cnt++]=*(ta-1);
2948 if(row!=x1 && *(ta+1) >>24 !=0x03) scol[cnt++]=*(ta+1);
2949 if( column!=y1 && *(ta+dx) >>24 !=0x03) scol[cnt++]=*(ta+dx);
2951 if(row && column && *(ta-dx-1)>>24 !=0x03) scol[cnt++]=*(ta-dx-1);
2952 if(row!=x1 && column && *(ta-dx+1)>>24 !=0x03) scol[cnt++]=*(ta-dx+1);
2953 if(row && column!=y1 && *(ta+dx-1)>>24 !=0x03) scol[cnt++]=*(ta+dx-1);
2954 if(row!=x1 && column!=y1 && *(ta+dx+1)>>24 !=0x03) scol[cnt++]=*(ta+dx+1);
2961 r+=(scol[h]>>16)&0xff;
2962 g+=(scol[h]>>8)&0xff;
2965 r/=cnt;b/=cnt;g/=cnt;
2967 *ta=(r<<16)|(g<<8)|b;
2977 for(column=0;column<dy;column++)
2979 for(row=0;row<dx;row++)
2985 if( column && *(ta-dx) !=0x50000000 && *(ta-dx)>>24!=1) scol[cnt++]=*(ta-dx);
2986 if(row && *(ta-1) !=0x50000000 && *(ta-1)>>24!=1) scol[cnt++]=*(ta-1);
2987 if(row!=x1 && *(ta+1) !=0x50000000 && *(ta+1)>>24!=1) scol[cnt++]=*(ta+1);
2988 if( column!=y1 && *(ta+dx) !=0x50000000 && *(ta+dx)>>24!=1) scol[cnt++]=*(ta+dx);
2990 if(row && column && *(ta-dx-1)!=0x50000000 && *(ta-dx-1)>>24!=1) scol[cnt++]=*(ta-dx-1);
2991 if(row!=x1 && column && *(ta-dx+1)!=0x50000000 && *(ta-dx+1)>>24!=1) scol[cnt++]=*(ta-dx+1);
2992 if(row && column!=y1 && *(ta+dx-1)!=0x50000000 && *(ta+dx-1)>>24!=1) scol[cnt++]=*(ta+dx-1);
2993 if(row!=x1 && column!=y1 && *(ta+dx+1)!=0x50000000 && *(ta+dx+1)>>24!=1) scol[cnt++]=*(ta+dx+1);
3001 r+=(scol[h]>>16)&0xff;
3002 g+=(scol[h]>>8)&0xff;
3005 r/=cnt;b/=cnt;g/=cnt;
3007 *ta=(r<<16)|(g<<8)|b;
3008 if(a) *ta|=0x50000000;
3009 else *ta|=0x01000000;
3018 for(column=0;column<dy;column++)
3020 for(row=0;row<dx;row++)
3026 if(row!=x1 && *(ta+1) !=0x00000000) scol[cnt++]=*(ta+1);
3027 if( column!=y1 && *(ta+dx) !=0x00000000) scol[cnt++]=*(ta+dx);
3034 r+=(scol[h]>>16)&0xff;
3035 g+=(scol[h]>>8)&0xff;
3038 r/=cnt;b/=cnt;g/=cnt;
3039 *ta=(r<<16)|(g<<8)|b;
3046 DefineSubTextureSort();
3049 /////////////////////////////////////////////////////////////////////////////
3050 /////////////////////////////////////////////////////////////////////////////
3051 /////////////////////////////////////////////////////////////////////////////
3053 // load texture part (packed)
\r
3055 /////////////////////////////////////////////////////////////////////////////
3056 /////////////////////////////////////////////////////////////////////////////
3057 /////////////////////////////////////////////////////////////////////////////
3059 void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
3061 uint32_t start,row,column,j,sxh,sxm;
3062 unsigned int palstart;
3063 unsigned short *px,*pa,*ta;
3064 unsigned char *cSRCPtr;
3065 unsigned short *wSRCPtr;
3066 uint32_t LineOffset;
3067 uint32_t x2a,xalign=0;
3068 uint32_t x1=gl_ux[7];
3069 uint32_t x2=gl_ux[6];
3070 uint32_t y1=gl_ux[5];
3071 uint32_t y2=gl_ux[4];
3072 uint32_t dx=x2-x1+1;
3073 uint32_t dy=y2-y1+1;
3074 int pmult=pageid/16;
3075 unsigned short (*LPTCOL)(unsigned short);
3076 unsigned int a,r,g,b,cnt,h;
3077 unsigned short scol[8];
3079 LPTCOL=PTCF[DrawSemiTrans];
3081 pa=px=(unsigned short *)ubPaletteBuffer;
3082 ta=(unsigned short *)texturepart;
3083 palstart=cx+(cy<<10);
3087 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}
3088 if(XTexS) {ta+=1;xalign=2;}
3092 //--------------------------------------------------//
3093 // 4bit texture load ..
3097 unsigned int TXV,TXU,n_xi,n_yi;
\r
3099 wSRCPtr=psxVuw+palstart;
\r
3102 *px =LPTCOL(*wSRCPtr);
\r
3103 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
3104 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
3105 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
3106 row--;px+=4;wSRCPtr+=4;
\r
3110 for(TXV=y1;TXV<=y2;TXV++)
\r
3112 for(TXU=x1;TXU<=x2;TXU++)
\r
3114 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
3115 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
3117 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
3124 start=((pageid-16*pmult)<<7)+524288*pmult;
3126 wSRCPtr=psxVuw+palstart;
3129 *px =LPTCOL(*wSRCPtr);
3130 *(px+1)=LPTCOL(*(wSRCPtr+1));
3131 *(px+2)=LPTCOL(*(wSRCPtr+2));
3132 *(px+3)=LPTCOL(*(wSRCPtr+3));
3133 row--;px+=4;wSRCPtr+=4;
3137 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;
3139 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;
3141 for(column=y1;column<=y2;column++)
3143 cSRCPtr = psxVub + start + (column<<11) + sxh;
3145 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
3147 for(row=j;row<x2a;row+=2)
3149 *ta =*(pa+(*cSRCPtr & 0xF));
3150 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF));
3156 *ta++=*(pa+(*cSRCPtr & 0xF));row++;
3157 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
3163 //--------------------------------------------------//
3164 // 8bit texture load ..
3168 unsigned int TXV,TXU,n_xi,n_yi;
\r
3170 wSRCPtr=psxVuw+palstart;
\r
3174 *px =LPTCOL(*wSRCPtr);
\r
3175 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
3176 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
3177 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
3178 row--;px+=4;wSRCPtr+=4;
\r
3182 for(TXV=y1;TXV<=y2;TXV++)
\r
3184 for(TXU=x1;TXU<=x2;TXU++)
\r
3186 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
3187 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
3189 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
3197 start=((pageid-16*pmult)<<7)+524288*pmult;
3199 cSRCPtr = psxVub + start + (y1<<11) + x1;
3200 LineOffset = 2048 - dx;
3202 if(dy*dx>384) // more pix? use lut
3204 wSRCPtr=psxVuw+palstart;
3208 *px =LPTCOL(*wSRCPtr);
3209 *(px+1)=LPTCOL(*(wSRCPtr+1));
3210 *(px+2)=LPTCOL(*(wSRCPtr+2));
3211 *(px+3)=LPTCOL(*(wSRCPtr+3));
3212 row--;px+=4;wSRCPtr+=4;
3219 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);
3223 cSRCPtr+=LineOffset;column--;
3227 else // small area? no lut
3229 wSRCPtr=psxVuw+palstart;
3234 do {*ta++=LPTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);
3238 cSRCPtr+=LineOffset;column--;
3243 //--------------------------------------------------//
3244 // 16bit texture load ..
3246 start=((pageid-16*pmult)<<6)+262144*pmult;
3248 wSRCPtr = psxVuw + start + (y1<<10) + x1;
3249 LineOffset = 1024 - dx;
3254 do {*ta++=LPTCOL(*wSRCPtr++);row--;} while(row);
3258 wSRCPtr+=LineOffset;column--;
3262 //--------------------------------------------------//
3263 // others are not possible !
3266 ////////////////////////////////////////////////////////
3272 ta=(unsigned short *)texturepart;
3273 pa=(unsigned short *)texturepart+x2a;
3274 row=x2a;do {*ta++=*pa++;row--;} while(row);
3276 pa=(unsigned short *)texturepart+dy*x2a;
3278 row=x2a;do {*ta++=*pa++;row--;} while(row);
3286 ta=(unsigned short *)texturepart;
3288 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
3290 pa=(unsigned short *)texturepart+dx;
3292 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
3298 DXTexS=dx;DYTexS=dy;
3300 if(!iFilterType) {DefineSubTextureSort();return;}
3301 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}
3302 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)
3303 {DefineSubTextureSort();return;}
3305 ta=(unsigned short *)texturepart;
3313 for(column=0;column<dy;column++)
3315 for(row=0;row<dx;row++)
3321 if( column && *(ta-dx) != 0x0006 && *(ta-dx)!=0) scol[cnt++]=*(ta-dx);
3322 if(row && *(ta-1) != 0x0006 && *(ta-1) !=0) scol[cnt++]=*(ta-1);
3323 if(row!=x1 && *(ta+1) != 0x0006 && *(ta+1) !=0) scol[cnt++]=*(ta+1);
3324 if( column!=y1 && *(ta+dx) != 0x0006 && *(ta+dx)!=0) scol[cnt++]=*(ta+dx);
3326 if(row && column && *(ta-dx-1)!= 0x0006 && *(ta-dx-1)!=0) scol[cnt++]=*(ta-dx-1);
3327 if(row!=x1 && column && *(ta-dx+1)!= 0x0006 && *(ta-dx+1)!=0) scol[cnt++]=*(ta-dx+1);
3328 if(row && column!=y1 && *(ta+dx-1)!= 0x0006 && *(ta+dx-1)!=0) scol[cnt++]=*(ta+dx-1);
3329 if(row!=x1 && column!=y1 && *(ta+dx+1)!= 0x0006 && *(ta+dx+1)!=0) scol[cnt++]=*(ta+dx+1);
3338 g+=(scol[h]>>8)&0xf;
3339 b+=(scol[h]>>4)&0xf;
3341 r/=cnt;b/=cnt;g/=cnt;
3342 *ta=(r<<12)|(g<<8)|(b<<4);
3351 for(column=0;column<dy;column++)
3353 for(row=0;row<dx;row++)
3359 if( column && *(ta-dx) != 0x0000) scol[cnt++]=*(ta-dx);
3360 if(row && *(ta-1) != 0x0000) scol[cnt++]=*(ta-1);
3361 if(row!=x1 && *(ta+1) != 0x0000) scol[cnt++]=*(ta+1);
3362 if( column!=y1 && *(ta+dx) != 0x0000) scol[cnt++]=*(ta+dx);
3364 if(row && column && *(ta-dx-1)!= 0x0000) scol[cnt++]=*(ta-dx-1);
3365 if(row!=x1 && column && *(ta-dx+1)!= 0x0000) scol[cnt++]=*(ta-dx+1);
3366 if(row && column!=y1 && *(ta+dx-1)!= 0x0000) scol[cnt++]=*(ta+dx-1);
3367 if(row!=x1 && column!=y1 && *(ta+dx+1)!= 0x0000) scol[cnt++]=*(ta+dx+1);
3375 g+=(scol[h]>>8)&0xf;
3376 b+=(scol[h]>>4)&0xf;
3378 r/=cnt;b/=cnt;g/=cnt;
3379 *ta=(r<<12)|(g<<8)|(b<<4);
3388 for(column=0;column<dy;column++)
3390 for(row=0;row<dx;row++)
3396 if( column && *(ta-dx) &1) scol[cnt++]=*(ta-dx);
3397 if(row && *(ta-1) &1) scol[cnt++]=*(ta-1);
3398 if(row!=x1 && *(ta+1) &1) scol[cnt++]=*(ta+1);
3399 if( column!=y1 && *(ta+dx) &1) scol[cnt++]=*(ta+dx);
3401 if(row && column && *(ta-dx-1)&1) scol[cnt++]=*(ta-dx-1);
3402 if(row!=x1 && column && *(ta-dx+1)&1) scol[cnt++]=*(ta-dx+1);
3403 if(row && column!=y1 && *(ta+dx-1)&1) scol[cnt++]=*(ta+dx-1);
3404 if(row!=x1 && column!=y1 && *(ta+dx+1)&1) scol[cnt++]=*(ta+dx+1);
3412 g+=(scol[h]>>6)&0x1f;
3413 b+=(scol[h]>>1)&0x1f;
3415 r/=cnt;b/=cnt;g/=cnt;
3416 *ta=(r<<11)|(g<<6)|(b<<1);
3424 DefineSubTextureSort();
3427 /////////////////////////////////////////////////////////////////////////////
3429 /////////////////////////////////////////////////////////////////////////////
\r
3430 /////////////////////////////////////////////////////////////////////////////
\r
3431 /////////////////////////////////////////////////////////////////////////////
\r
3433 // hires texture funcs
\r
3435 /////////////////////////////////////////////////////////////////////////////
\r
3436 /////////////////////////////////////////////////////////////////////////////
\r
3437 /////////////////////////////////////////////////////////////////////////////
\r
3440 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
3442 ////////////////////////////////////////////////////////////////////////
3444 #define colorMask8 0x00FEFEFE
3445 #define lowPixelMask8 0x00010101
3446 #define qcolorMask8 0x00FCFCFC
3447 #define qlowpixelMask8 0x00030303
3450 #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)))))))
3452 #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)))))))))))
3454 #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)))))))
3456 #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)))))))))))
3458 void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,
3459 unsigned char *dstBitmap, int width, int height)
3461 DWORD dstPitch = srcPitch * 2;
3465 int width2 = width*2;
3466 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
3467 DWORD color4, color5, color6;
3468 DWORD color1, color2, color3;
3469 DWORD colorA0, colorA1, colorA2, colorA3,
3470 colorB0, colorB1, colorB2, colorB3,
3472 DWORD product1a, product1b,
3473 product2a, product2b;
3478 for (; height; height-=1)
3480 bP = (DWORD *)srcPtr;
3481 dP = (DWORD *)(dstBitmap + line*dstPitch);
3482 for (finish = width; finish; finish -= 1 )
3484 //--------------------------------------- B1 B2
3488 if(finish==width) iXA=0;
3490 if(finish>4) {iXB=1;iXC=2;}
3492 if(finish>3) {iXB=1;iXC=1;}
3496 if(height>4) {iYB=width;iYC=width2;}
3498 if(height>3) {iYB=width;iYC=width;}
3502 colorB0 = *(bP- iYA - iXA);
3503 colorB1 = *(bP- iYA);
3504 colorB2 = *(bP- iYA + iXB);
3505 colorB3 = *(bP- iYA + iXC);
3507 color4 = *(bP - iXA);
3509 color6 = *(bP + iXB);
3510 colorS2 = *(bP + iXC);
3512 color1 = *(bP + iYB - iXA);
3513 color2 = *(bP + iYB);
3514 color3 = *(bP + iYB + iXB);
3515 colorS1= *(bP + iYB + iXC);
3517 colorA0 = *(bP + iYC - iXA);
3518 colorA1 = *(bP + iYC);
3519 colorA2 = *(bP + iYC + iXB);
3520 colorA3 = *(bP + iYC + iXC);
3522 //--------------------------------------
3523 if (color2 == color6 && color5 != color3)
3525 product2b = product1b = color2;
3528 if (color5 == color3 && color2 != color6)
3530 product2b = product1b = color5;
3533 if (color5 == color3 && color2 == color6)
3537 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
3538 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
3539 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
3540 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
3543 product2b = product1b = color6;
3546 product2b = product1b = color5;
3549 product2b = product1b = INTERPOLATE8_02(color5, color6);
3554 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
3555 product2b = Q_INTERPOLATE8_02 (color3, color3, color3, color2);
3557 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
3558 product2b = Q_INTERPOLATE8_02 (color2, color2, color2, color3);
3560 product2b = INTERPOLATE8_02 (color2, color3);
3562 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
3563 product1b = Q_INTERPOLATE8_02 (color6, color6, color6, color5);
3565 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
3566 product1b = Q_INTERPOLATE8_02 (color6, color5, color5, color5);
3568 product1b = INTERPOLATE8_02 (color5, color6);
3571 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
3572 product2a = INTERPOLATE8_02(color2, color5);
3574 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
3575 product2a = INTERPOLATE8_02(color2, color5);
3579 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
3580 product1a = INTERPOLATE8_02(color2, color5);
3582 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
3583 product1a = INTERPOLATE8_02(color2, color5);
3589 *(dP+(width2))=product2a;
3590 *(dP+1+(width2))=product2b;
3594 }//end of for ( finish= width etc..)
3598 }; //endof: for (; height; height--)
3603 void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
3604 unsigned char *dstBitmap, int width, int height)
3606 DWORD dstPitch = srcPitch * 2;
3610 int width2 = width*2;
3611 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
3612 DWORD color4, color5, color6;
3613 DWORD color1, color2, color3;
3614 DWORD colorA0, colorA1, colorA2, colorA3,
3615 colorB0, colorB1, colorB2, colorB3,
3617 DWORD product1a, product1b,
3618 product2a, product2b;
3623 for (; height; height-=1)
3625 bP = (DWORD *)srcPtr;
3626 dP = (DWORD *)(dstBitmap + line*dstPitch);
3627 for (finish = width; finish; finish -= 1 )
3629 //--------------------------------------- B1 B2
3633 if(finish==width) iXA=0;
3635 if(finish>4) {iXB=1;iXC=2;}
3637 if(finish>3) {iXB=1;iXC=1;}
3641 if(height>4) {iYB=width;iYC=width2;}
3643 if(height>3) {iYB=width;iYC=width;}
3647 colorB0 = *(bP- iYA - iXA);
3648 colorB1 = *(bP- iYA);
3649 colorB2 = *(bP- iYA + iXB);
3650 colorB3 = *(bP- iYA + iXC);
3652 color4 = *(bP - iXA);
3654 color6 = *(bP + iXB);
3655 colorS2 = *(bP + iXC);
3657 color1 = *(bP + iYB - iXA);
3658 color2 = *(bP + iYB);
3659 color3 = *(bP + iYB + iXB);
3660 colorS1= *(bP + iYB + iXC);
3662 colorA0 = *(bP + iYC - iXA);
3663 colorA1 = *(bP + iYC);
3664 colorA2 = *(bP + iYC + iXB);
3665 colorA3 = *(bP + iYC + iXC);
3667 //--------------------------------------
3668 if (color2 == color6 && color5 != color3)
3670 product2b = product1b = color2;
3673 if (color5 == color3 && color2 != color6)
3675 product2b = product1b = color5;
3678 if (color5 == color3 && color2 == color6)
3682 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
3683 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
3684 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
3685 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
3688 product2b = product1b = color6;
3691 product2b = product1b = color5;
3694 product2b = product1b = INTERPOLATE8(color5, color6);
3699 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
3700 product2b = Q_INTERPOLATE8 (color3, color3, color3, color2);
3702 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
3703 product2b = Q_INTERPOLATE8 (color2, color2, color2, color3);
3705 product2b = INTERPOLATE8 (color2, color3);
3707 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
3708 product1b = Q_INTERPOLATE8 (color6, color6, color6, color5);
3710 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
3711 product1b = Q_INTERPOLATE8 (color6, color5, color5, color5);
3713 product1b = INTERPOLATE8 (color5, color6);
3716 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
3717 product2a = INTERPOLATE8(color2, color5);
3719 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
3720 product2a = INTERPOLATE8(color2, color5);
3724 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
3725 product1a = INTERPOLATE8(color2, color5);
3727 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
3728 product1a = INTERPOLATE8(color2, color5);
3734 *(dP+(width2))=product2a;
3735 *(dP+1+(width2))=product2b;
3739 }//end of for ( finish= width etc..)
3743 }; //endof: for (; height; height--)
3746 /////////////////////////////////////////////////////////////////////////////
3748 #define colorMask4 0x0000EEE0
3749 #define lowPixelMask4 0x00001110
3750 #define qcolorMask4 0x0000CCC0
3751 #define qlowpixelMask4 0x00003330
3753 #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))))))
3755 #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))))))))))
3757 void Super2xSaI_ex4(unsigned char *srcPtr, DWORD srcPitch,
3758 unsigned char *dstBitmap, int width, int height)
3760 DWORD dstPitch = srcPitch * 2;
3764 int width2 = width*2;
3765 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
3766 DWORD color4, color5, color6;
3767 DWORD color1, color2, color3;
3768 DWORD colorA0, colorA1, colorA2, colorA3,
3769 colorB0, colorB1, colorB2, colorB3,
3771 DWORD product1a, product1b,
3772 product2a, product2b;
3777 for (; height; height-=1)
3779 bP = (unsigned short *)srcPtr;
3780 dP = (unsigned short *)(dstBitmap + line*dstPitch);
3781 for (finish = width; finish; finish -= 1 )
3783 //--------------------------------------- B1 B2
3787 if(finish==width) iXA=0;
3789 if(finish>4) {iXB=1;iXC=2;}
3791 if(finish>3) {iXB=1;iXC=1;}
3795 if(height>4) {iYB=width;iYC=width2;}
3797 if(height>3) {iYB=width;iYC=width;}
3801 colorB0 = *(bP- iYA - iXA);
3802 colorB1 = *(bP- iYA);
3803 colorB2 = *(bP- iYA + iXB);
3804 colorB3 = *(bP- iYA + iXC);
3806 color4 = *(bP - iXA);
3808 color6 = *(bP + iXB);
3809 colorS2 = *(bP + iXC);
3811 color1 = *(bP + iYB - iXA);
3812 color2 = *(bP + iYB);
3813 color3 = *(bP + iYB + iXB);
3814 colorS1= *(bP + iYB + iXC);
3816 colorA0 = *(bP + iYC - iXA);
3817 colorA1 = *(bP + iYC);
3818 colorA2 = *(bP + iYC + iXB);
3819 colorA3 = *(bP + iYC + iXC);
3821 //--------------------------------------
3822 if (color2 == color6 && color5 != color3)
3824 product2b = product1b = color2;
3827 if (color5 == color3 && color2 != color6)
3829 product2b = product1b = color5;
3832 if (color5 == color3 && color2 == color6)
3836 r += GET_RESULT ((color6&0xfffffff0), (color5&0xfffffff0), (color1&0xfffffff0), (colorA1&0xfffffff0));
3837 r += GET_RESULT ((color6&0xfffffff0), (color5&0xfffffff0), (color4&0xfffffff0), (colorB1&0xfffffff0));
3838 r += GET_RESULT ((color6&0xfffffff0), (color5&0xfffffff0), (colorA2&0xfffffff0), (colorS1&0xfffffff0));
3839 r += GET_RESULT ((color6&0xfffffff0), (color5&0xfffffff0), (colorB2&0xfffffff0), (colorS2&0xfffffff0));
3842 product2b = product1b = color6;
3845 product2b = product1b = color5;
3848 product2b = product1b = INTERPOLATE4 (color5, color6);
3853 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
3854 product2b = Q_INTERPOLATE4 (color3, color3, color3, color2);
3856 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
3857 product2b = Q_INTERPOLATE4 (color2, color2, color2, color3);
3859 product2b = INTERPOLATE4 (color2, color3);
3861 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
3862 product1b = Q_INTERPOLATE4 (color6, color6, color6, color5);
3864 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
3865 product1b = Q_INTERPOLATE4 (color6, color5, color5, color5);
3867 product1b = INTERPOLATE4 (color5, color6);
3870 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
3871 product2a = INTERPOLATE4 (color2, color5);
3873 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
3874 product2a = INTERPOLATE4(color2, color5);
3878 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
3879 product1a = INTERPOLATE4 (color2, color5);
3881 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
3882 product1a = INTERPOLATE4(color2, color5);
3888 *(dP+(width2))=product2a;
3889 *(dP+1+(width2))=product2b;
3893 }//end of for ( finish= width etc..)
3897 }; //endof: for (; height; height--)
3901 /////////////////////////////////////////////////////////////////////////////
3903 #define colorMask5 0x0000F7BC
3904 #define lowPixelMask5 0x00000842
3905 #define qcolorMask5 0x0000E738
3906 #define qlowpixelMask5 0x000018C6
3908 #define INTERPOLATE5(A, B) ((((A & colorMask5) >> 1) + ((B & colorMask5) >> 1) + (A & B & lowPixelMask5))|((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:0x00000001))))
3910 #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))))))
3912 void Super2xSaI_ex5(unsigned char *srcPtr, DWORD srcPitch,
3913 unsigned char *dstBitmap, int width, int height)
3915 DWORD dstPitch = srcPitch * 2;
3919 int width2 = width*2;
3920 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
3921 DWORD color4, color5, color6;
3922 DWORD color1, color2, color3;
3923 DWORD colorA0, colorA1, colorA2, colorA3,
3924 colorB0, colorB1, colorB2, colorB3,
3926 DWORD product1a, product1b,
3927 product2a, product2b;
3932 for (; height; height-=1)
3934 bP = (unsigned short *)srcPtr;
3935 dP = (unsigned short *)(dstBitmap + line*dstPitch);
3936 for (finish = width; finish; finish -= 1 )
3938 //--------------------------------------- B1 B2
3942 if(finish==width) iXA=0;
3944 if(finish>4) {iXB=1;iXC=2;}
3946 if(finish>3) {iXB=1;iXC=1;}
3950 if(height>4) {iYB=width;iYC=width2;}
3952 if(height>3) {iYB=width;iYC=width;}
3956 colorB0 = *(bP- iYA - iXA);
3957 colorB1 = *(bP- iYA);
3958 colorB2 = *(bP- iYA + iXB);
3959 colorB3 = *(bP- iYA + iXC);
3961 color4 = *(bP - iXA);
3963 color6 = *(bP + iXB);
3964 colorS2 = *(bP + iXC);
3966 color1 = *(bP + iYB - iXA);
3967 color2 = *(bP + iYB);
3968 color3 = *(bP + iYB + iXB);
3969 colorS1= *(bP + iYB + iXC);
3971 colorA0 = *(bP + iYC - iXA);
3972 colorA1 = *(bP + iYC);
3973 colorA2 = *(bP + iYC + iXB);
3974 colorA3 = *(bP + iYC + iXC);
3976 //--------------------------------------
3977 if (color2 == color6 && color5 != color3)
3979 product2b = product1b = color2;
3982 if (color5 == color3 && color2 != color6)
3984 product2b = product1b = color5;
3987 if (color5 == color3 && color2 == color6)
3991 r += GET_RESULT ((color6&0xfffffffe), (color5&0xfffffffe), (color1&0xfffffffe), (colorA1&0xfffffffe));
3992 r += GET_RESULT ((color6&0xfffffffe), (color5&0xfffffffe), (color4&0xfffffffe), (colorB1&0xfffffffe));
3993 r += GET_RESULT ((color6&0xfffffffe), (color5&0xfffffffe), (colorA2&0xfffffffe), (colorS1&0xfffffffe));
3994 r += GET_RESULT ((color6&0xfffffffe), (color5&0xfffffffe), (colorB2&0xfffffffe), (colorS2&0xfffffffe));
3997 product2b = product1b = color6;
4000 product2b = product1b = color5;
4003 product2b = product1b = INTERPOLATE5 (color5, color6);
4008 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
4009 product2b = Q_INTERPOLATE5 (color3, color3, color3, color2);
4011 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
4012 product2b = Q_INTERPOLATE5 (color2, color2, color2, color3);
4014 product2b = INTERPOLATE5 (color2, color3);
4016 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
4017 product1b = Q_INTERPOLATE5 (color6, color6, color6, color5);
4019 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
4020 product1b = Q_INTERPOLATE5 (color6, color5, color5, color5);
4022 product1b = INTERPOLATE5 (color5, color6);
4025 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
4026 product2a = INTERPOLATE5 (color2, color5);
4028 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
4029 product2a = INTERPOLATE5(color2, color5);
4033 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
4034 product1a = INTERPOLATE5(color2, color5);
4036 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
4037 product1a = INTERPOLATE5(color2, color5);
4043 *(dP+(width2))=product2a;
4044 *(dP+1+(width2))=product2b;
4048 }//end of for ( finish= width etc..)
4052 }; //endof: for (; height; height--)
4056 /////////////////////////////////////////////////////////////////////////////
4057 /////////////////////////////////////////////////////////////////////////////
4058 /////////////////////////////////////////////////////////////////////////////
4060 // ogl texture defines
\r
4062 /////////////////////////////////////////////////////////////////////////////
\r
4063 /////////////////////////////////////////////////////////////////////////////
\r
4064 /////////////////////////////////////////////////////////////////////////////
\r
4066 void DefineSubTextureSortHiRes(void)
4072 glGenTextures(1, &gTexName);
4073 glBindTexture(GL_TEXTURE_2D, gTexName);
4075 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
4076 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
4080 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4081 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4085 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4086 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4088 glTexImage2D(GL_TEXTURE_2D, 0, giWantedRGBA, 512, 512, 0, giWantedFMT, giWantedTYPE, texturebuffer);
4090 else glBindTexture(GL_TEXTURE_2D, gTexName);
4092 if(bGLExt && (iTexQuality==1 || iTexQuality==2))
4094 if(DXTexS < 4 || DYTexS < 4 || iHiResTextures==2)
4096 unsigned short * pS,*pD1,*pD2;
4098 pS=(unsigned short *)texturepart;
4099 pD1=(unsigned short *)texturebuffer;
4100 pD2=(unsigned short *)texturebuffer;
4102 for(y=0;y<DYTexS;y++)
4104 for(x=0;x<DXTexS;x++)
4106 *(pD2+1)=*pD2=*(pD1+1)=*pD1=*pS;
4118 Super2xSaI_ex4(texturepart, DXTexS<<1, texturebuffer, DXTexS, DYTexS);
4120 Super2xSaI_ex5(texturepart, DXTexS<<1, texturebuffer, DXTexS, DYTexS);
4125 if(DXTexS < 4 || DYTexS < 4 || iHiResTextures==2)
4127 uint32_t * pS,*pD1,*pD2;
4129 pS=(uint32_t *)texturepart;
4130 pD1=(uint32_t *)texturebuffer;
4131 pD2=(uint32_t *)texturebuffer;
4133 for(y=0;y<DYTexS;y++)
4135 for(x=0;x<DXTexS;x++)
4137 *(pD2+1)=*pD2=*(pD1+1)=*pD1=*pS;
4148 Super2xSaI_ex8_Ex(texturepart, DXTexS*4, texturebuffer, DXTexS, DYTexS);
4150 Super2xSaI_ex8(texturepart, DXTexS*4, texturebuffer, DXTexS, DYTexS);
4153 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS<<1, YTexS<<1,
4154 DXTexS<<1, DYTexS<<1,
4155 giWantedFMT, giWantedTYPE, texturebuffer);
4158 /////////////////////////////////////////////////////////////////////////////
4160 void DefineSubTextureSort(void)
4164 DefineSubTextureSortHiRes();
4170 glGenTextures(1, &gTexName);
4171 glBindTexture(GL_TEXTURE_2D, gTexName);
4173 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
4174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
4178 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4183 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
4184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
4186 glTexImage2D(GL_TEXTURE_2D, 0, giWantedRGBA, 256, 256, 0,giWantedFMT, giWantedTYPE, texturepart);
4188 else glBindTexture(GL_TEXTURE_2D, gTexName);
4190 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS, YTexS,
4192 giWantedFMT, giWantedTYPE, texturepart);
4195 /////////////////////////////////////////////////////////////////////////////
4197 /////////////////////////////////////////////////////////////////////////////
\r
4198 /////////////////////////////////////////////////////////////////////////////
\r
4199 /////////////////////////////////////////////////////////////////////////////
\r
4201 // texture cache garbage collection
\r
4203 /////////////////////////////////////////////////////////////////////////////
\r
4204 /////////////////////////////////////////////////////////////////////////////
\r
4205 /////////////////////////////////////////////////////////////////////////////
\r
4207 void DoTexGarbageCollection(void)
4209 static unsigned short LRUCleaned=0;
4210 unsigned short iC,iC1,iC2;
4211 int i,j,iMax;textureSubCacheEntryS * tsb;
4213 iC=4;//=iSortTexCnt/2,
4214 LRUCleaned+=iC; // we clean different textures each time
4215 if((LRUCleaned+iC)>=iSortTexCnt) LRUCleaned=0; // wrap? wrap!
4216 iC1=LRUCleaned; // range of textures to clean
4219 for(iC=iC1;iC<iC2;iC++) // make some textures available
4221 pxSsubtexLeft[iC]->l=0;
4224 for(i=0;i<3;i++) // remove all references to that textures
4225 for(j=0;j<MAXTPAGES;j++)
4226 for(iC=0;iC<4;iC++) // loop all texture rect info areas
4228 tsb=pscSubtexStore[i][j]+(iC*SOFFB);
4234 if(tsb->cTexID>=iC1 && tsb->cTexID<iC2) // info uses the cleaned textures? remove info
4240 usLRUTexPage=LRUCleaned;
4243 /////////////////////////////////////////////////////////////////////////////
\r
4244 /////////////////////////////////////////////////////////////////////////////
\r
4245 /////////////////////////////////////////////////////////////////////////////
\r
4247 // search cache for existing (already used) parts
\r
4249 /////////////////////////////////////////////////////////////////////////////
\r
4250 /////////////////////////////////////////////////////////////////////////////
\r
4251 /////////////////////////////////////////////////////////////////////////////
\r
4253 unsigned char * CheckTextureInSubSCache(int TextureMode, uint32_t GivenClutId, unsigned short * pCache)
4255 textureSubCacheEntryS * tsx, * tsb, *tsg;//, *tse=NULL;
4256 int i,iMax;EXLong npos;
4257 unsigned char cx,cy;
4258 int iC,j,k;uint32_t rx,ry,mx,my;
4259 EXLong * ul=0, * uls;
4261 unsigned char cXAdj,cYAdj;
4263 npos.l=*((uint32_t *)&gl_ux[4]);
4265 //--------------------------------------------------------------//
4266 // find matching texturepart first... speed up...
4267 //--------------------------------------------------------------//
4269 tsg=pscSubtexStore[TextureMode][GlobalTexturePage];
4270 tsg+=((GivenClutId&CLUTCHK)>>CLUTSHIFT)*SOFFB;
4279 if(GivenClutId==tsb->ClutID &&
4280 (INCHECK(tsb->pos,npos)))
4283 cx=tsb->pos.c[3]-tsb->posTX;
4284 cy=tsb->pos.c[1]-tsb->posTY;
4295 ubOpaqueDraw=tsb->Opaque;
4296 *pCache=tsb->cTexID;
4305 //----------------------------------------------------//
4309 rx=(int)gl_ux[6]-(int)gl_ux[7];
4310 ry=(int)gl_ux[4]-(int)gl_ux[5];
4313 for(i=0;i<iMax;i++,tsb++)
4315 if(!tsb->ClutID) {tsx=tsb;break;}
4323 if(iTexGarbageCollection) // gc mode?
4327 dwTexPageComp|=(1<<GlobalTexturePage);
4335 for(i=0;i<iMax;i++,tsb++) // 1. search other slots with same cluts, and unite the area
4336 if(GivenClutId==tsb->ClutID)
4338 if(!tsx) {tsx=tsb;rfree.l=npos.l;} //
4340 rfree.c[3]=min(rfree.c[3],tsb->pos.c[3]);
4341 rfree.c[2]=max(rfree.c[2],tsb->pos.c[2]);
4342 rfree.c[1]=min(rfree.c[1],tsb->pos.c[1]);
4343 rfree.c[0]=max(rfree.c[0],tsb->pos.c[0]);
4347 if(tsx) // 3. if one or more found, create a new rect with bigger size
4349 *((uint32_t *)&gl_ux[4])=npos.l=rfree.l;
4350 rx=(int)rfree.c[2]-(int)rfree.c[3];
4351 ry=(int)rfree.c[0]-(int)rfree.c[1];
4352 DoTexGarbageCollection();
4364 //----------------------------------------------------//
4365 // now get a free texture space
4366 //----------------------------------------------------//
4368 if(iTexGarbageCollection) usLRUTexPage=0;
4372 rx+=3;if(rx>255) {cXAdj=0;rx=255;}
4373 ry+=3;if(ry>255) {cYAdj=0;ry=255;}
4377 for(k=0;k<iSortTexCnt;k++)
4379 uls=pxSsubtexLeft[iC];
4380 iMax=uls->l;ul=uls+1;
4382 //--------------------------------------------------//
4389 if(rx>252 && ry>252)
4390 {uls->l=1;ul->l=0xffffffff;ul=0;goto ENDLOOP;}
4414 //--------------------------------------------------//
4415 for(i=0;i<iMax;i++,ul++)
4417 if(ul->l!=0xffffffff &&
4430 for(ul=uls+1,j=0;j<iMax;j++,ul++)
4431 if(ul->l==0xffffffff) break;
4435 if(j==iMax) uls->l=uls->l+1;
4437 ul->c[3]=rfree.c[3];
4438 ul->c[2]=rfree.c[2];
4439 ul->c[1]=rfree.c[1]+ry;
4440 ul->c[0]=rfree.c[0]-ry;
4462 //--------------------------------------------------//
4464 iC++; if(iC>=iSortTexCnt) iC=0;
4467 //----------------------------------------------------//
4468 // check, if free space got
4469 //----------------------------------------------------//
4474 //////////////////////////////////////////////////////
4479 for(i=0;i<3;i++) // cleaning up
4480 for(j=0;j<MAXTPAGES;j++)
4482 tsb=pscSubtexStore[i][j];
4483 (tsb+SOFFA)->pos.l=0;
4484 (tsb+SOFFB)->pos.l=0;
4485 (tsb+SOFFC)->pos.l=0;
4486 (tsb+SOFFD)->pos.l=0;
4488 for(i=0;i<iSortTexCnt;i++)
4489 {ul=pxSsubtexLeft[i];ul->l=0;}
4493 //////////////////////////////////////////////////////
4495 uls=pxSsubtexLeft[usLRUTexPage];
4499 if(rx>252 && ry>252)
4500 {uls->l=1;ul->l=0xffffffff;}
4521 tsg->pos.l=1;tsx=tsg+1;
4527 tsx->cTexID =*pCache=iC;
4529 tsx->ClutID = GivenClutId;
4530 tsx->posTX = rfree.c[3];
4531 tsx->posTY = rfree.c[1];
4533 cx=gl_ux[7]-rfree.c[3];
4534 cy=gl_ux[5]-rfree.c[1];
4548 return &tsx->Opaque;
4551 /////////////////////////////////////////////////////////////////////////////
\r
4552 /////////////////////////////////////////////////////////////////////////////
\r
4553 /////////////////////////////////////////////////////////////////////////////
\r
4555 // search cache for free place (on compress)
\r
4557 /////////////////////////////////////////////////////////////////////////////
\r
4558 /////////////////////////////////////////////////////////////////////////////
\r
4559 /////////////////////////////////////////////////////////////////////////////
\r
4561 BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)
4563 int i,j,k,iMax,iC;uint32_t rx,ry,mx,my;
4564 EXLong * ul=0, * uls, rfree;
4565 unsigned char cXAdj=1,cYAdj=1;
4567 rx=(int)tsx->pos.c[2]-(int)tsx->pos.c[3];
4568 ry=(int)tsx->pos.c[0]-(int)tsx->pos.c[1];
4570 rx+=3;if(rx>255) {cXAdj=0;rx=255;}
4571 ry+=3;if(ry>255) {cYAdj=0;ry=255;}
4575 for(k=0;k<iSortTexCnt;k++)
4577 uls=pxSsubtexLeft[iC];
4578 iMax=uls->l;ul=uls+1;
4580 //--------------------------------------------------//
4587 if(rx>252 && ry>252)
4588 {uls->l=1;ul->l=0xffffffff;ul=0;goto TENDLOOP;}
4612 //--------------------------------------------------//
4613 for(i=0;i<iMax;i++,ul++)
4615 if(ul->l!=0xffffffff &&
4629 for(ul=uls+1,j=0;j<iMax;j++,ul++)
4630 if(ul->l==0xffffffff) break;
4634 if(j==iMax) uls->l=uls->l+1;
4636 ul->c[3]=rfree.c[3];
4637 ul->c[2]=rfree.c[2];
4638 ul->c[1]=rfree.c[1]+ry;
4639 ul->c[0]=rfree.c[0]-ry;
4661 //--------------------------------------------------//
4663 iC++; if(iC>=iSortTexCnt) iC=0;
4666 //----------------------------------------------------//
4667 // check, if free space got
4668 //----------------------------------------------------//
4671 if(ul) return FALSE;
4677 tsx->posTX = rfree.c[3];
4678 tsx->posTY = rfree.c[1];
4686 /////////////////////////////////////////////////////////////////////////////
\r
4687 /////////////////////////////////////////////////////////////////////////////
\r
4688 /////////////////////////////////////////////////////////////////////////////
\r
4690 // compress texture cache (to make place for new texture part, if needed)
\r
4692 /////////////////////////////////////////////////////////////////////////////
\r
4693 /////////////////////////////////////////////////////////////////////////////
\r
4694 /////////////////////////////////////////////////////////////////////////////
\r
4696 void CompressTextureSpace(void)
4698 textureSubCacheEntryS * tsx, * tsg, * tsb;
4699 int i,j,k,m,n,iMax;EXLong * ul, r,opos;
4700 short sOldDST=DrawSemiTrans,cx,cy;
4701 int lOGTP=GlobalTexturePage;
4705 opos.l=*((uint32_t *)&gl_ux[4]);
4707 // 1. mark all textures as free
4708 for(i=0;i<iSortTexCnt;i++)
4709 {ul=pxSsubtexLeft[i];ul->l=0;}
4715 for(k=0;k<MAXTPAGES;k++)
4717 tsg=pscSubtexStore[j][k];
4719 if((!(dwTexPageComp&(1<<k))))
4721 (tsg+SOFFA)->pos.l=0;
4722 (tsg+SOFFB)->pos.l=0;
4723 (tsg+SOFFC)->pos.l=0;
4724 (tsg+SOFFD)->pos.l=0;
4728 for(m=0;m<4;m++,tsg+=SOFFB)
4733 for(i=0;i<iMax;i++,tsx++)
4738 for(n=i+1,tsb=tsx+1;n<iMax;n++,tsb++)
4740 if(tsx->ClutID==tsb->ClutID)
4742 r.c[3]=min(r.c[3],tsb->pos.c[3]);
4743 r.c[2]=max(r.c[2],tsb->pos.c[2]);
4744 r.c[1]=min(r.c[1],tsb->pos.c[1]);
4745 r.c[0]=max(r.c[0],tsb->pos.c[0]);
4750 // if(r.l!=tsx->pos.l)
4752 cx=((tsx->ClutID << 4) & 0x3F0);
4753 cy=((tsx->ClutID >> 6) & CLUTYMASK);
4757 // palette check sum
4758 l=0;lSRCPtr=(uint32_t *)(psxVuw+cx+(cy*1024));
4759 if(j==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
4760 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
4761 l=((l+HIWORD(l))&0x3fffL)<<16;
4762 if(l!=(tsx->ClutID&(0x00003fff<<16)))
4764 tsx->ClutID=0;continue;
4769 if(!GetCompressTexturePlace(tsx)) // no place?
\r
4771 for(i=0;i<3;i++) // -> clean up everything
\r
4772 for(j=0;j<MAXTPAGES;j++)
4774 tsb=pscSubtexStore[i][j];
4775 (tsb+SOFFA)->pos.l=0;
4776 (tsb+SOFFB)->pos.l=0;
4777 (tsb+SOFFC)->pos.l=0;
4778 (tsb+SOFFD)->pos.l=0;
4780 for(i=0;i<iSortTexCnt;i++)
4781 {ul=pxSsubtexLeft[i];ul->l=0;}
4783 DrawSemiTrans=sOldDST;
4784 GlobalTexturePage=lOGTP;
4785 *((uint32_t *)&gl_ux[4])=opos.l;
4791 if(tsx->ClutID&(1<<30)) DrawSemiTrans=1;
4792 else DrawSemiTrans=0;
4793 *((uint32_t *)&gl_ux[4])=r.l;
4795 gTexName=uiStexturePage[tsx->cTexID];
4796 LoadSubTexFn(k,j,cx,cy);
4797 uiStexturePage[tsx->cTexID]=gTexName;
4798 tsx->Opaque=ubOpaqueDraw;
4806 while(!tsx->ClutID && iMax) {tsx--;iMax--;}
4814 if(dwTexPageComp==0xffffffff) dwTexPageComp=0;
4816 *((uint32_t *)&gl_ux[4])=opos.l;
4817 GlobalTexturePage=lOGTP;
4818 DrawSemiTrans=sOldDST;
4821 /////////////////////////////////////////////////////////////////////////////
\r
4822 /////////////////////////////////////////////////////////////////////////////
\r
4823 /////////////////////////////////////////////////////////////////////////////
\r
4825 // main entry for searching/creating textures, called from prim.c
\r
4827 /////////////////////////////////////////////////////////////////////////////
\r
4828 /////////////////////////////////////////////////////////////////////////////
\r
4829 /////////////////////////////////////////////////////////////////////////////
\r
4831 GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId)
4833 unsigned char * OPtr;unsigned short iCache;short cx,cy;
4835 // sort sow/tow infos for fast access
\r
4837 unsigned char ma1,ma2,mi1,mi2;
4838 if(gl_ux[0]>gl_ux[1]) {mi1=gl_ux[1];ma1=gl_ux[0];}
4839 else {mi1=gl_ux[0];ma1=gl_ux[1];}
4840 if(gl_ux[2]>gl_ux[3]) {mi2=gl_ux[3];ma2=gl_ux[2];}
4841 else {mi2=gl_ux[2];ma2=gl_ux[3];}
4842 if(mi1>mi2) gl_ux[7]=mi2;
4844 if(ma1>ma2) gl_ux[6]=ma1;
4847 if(gl_vy[0]>gl_vy[1]) {mi1=gl_vy[1];ma1=gl_vy[0];}
4848 else {mi1=gl_vy[0];ma1=gl_vy[1];}
4849 if(gl_vy[2]>gl_vy[3]) {mi2=gl_vy[3];ma2=gl_vy[2];}
4850 else {mi2=gl_vy[2];ma2=gl_vy[3];}
4851 if(mi1>mi2) gl_ux[5]=mi2;
4853 if(ma1>ma2) gl_ux[4]=ma1;
4856 // get clut infos in one 32 bit val
\r
4858 if(TextureMode==2) // no clut here
\r
4860 GivenClutId=CLUTUSED|(DrawSemiTrans<<30);cx=cy=0;
4862 if(iFrameTexType && Fake15BitTexture())
4863 return (GLuint)gTexName;
4867 cx=((GivenClutId << 4) & 0x3F0); // but here
4868 cy=((GivenClutId >> 6) & CLUTYMASK);
4869 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30)|CLUTUSED;
4871 // palette check sum.. removed MMX asm, this easy func works as well
4875 uint32_t *lSRCPtr = (uint32_t *)(psxVuw+cx+(cy*1024));
4876 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
4877 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
4878 l=(l+HIWORD(l))&0x3fffL;
4879 GivenClutId|=(l<<16);
4886 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
\r
4888 // cache full? compress and try again
4891 CompressTextureSpace();
4892 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
4896 usLRUTexPage=iCache;
4897 if(!OPtr) return uiStexturePage[iCache];
\r
4899 // not found? upload texture and store infos in cache
4900 gTexName=uiStexturePage[iCache];
4901 LoadSubTexFn(GlobalTexturePage,TextureMode,cx,cy);
4902 uiStexturePage[iCache]=gTexName;
4904 return (GLuint) gTexName;
4907 /////////////////////////////////////////////////////////////////////////////
4908 /////////////////////////////////////////////////////////////////////////////
4909 /////////////////////////////////////////////////////////////////////////////