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
19 //*************************************************************************//
\r
20 // History of changes:
\r
22 // 2009/03/08 - Pete
\r
23 // - generic cleanup for the Peops release
\r
25 //*************************************************************************//
\r
28 ////////////////////////////////////////////////////////////////////////////////////
\r
29 // Texture related functions are here !
\r
31 // The texture handling is heart and soul of this gpu. The plugin was developed
\r
32 // 1999, by this time no shaders were available. Since the psx gpu is making
\r
33 // heavy use of CLUT (="color lookup tables", aka palettized textures), it was
\r
34 // an interesting task to get those emulated at good speed on NV TNT cards
\r
35 // (which was my major goal when I created the first "gpuPeteTNT"). Later cards
\r
36 // (Geforce256) supported texture palettes by an OGL extension, but at some point
\r
37 // this support was dropped again by gfx card vendors.
\r
38 // Well, at least there is a certain advatage, if no texture palettes extension can
\r
39 // be used: it is possible to modify the textures in any way, allowing "hi-res"
\r
40 // textures and other tweaks.
\r
42 // My main texture caching is kinda complex: the plugin is allocating "n" 256x256 textures,
\r
43 // and it places small psx texture parts inside them. The plugin keeps track what
\r
44 // part (with what palette) it had placed in which texture, so it can re-use this
\r
45 // part again. The more ogl textures it can use, the better (of course the managing/
\r
46 // searching will be slower, but everything is faster than uploading textures again
\r
47 // and again to a gfx card). My first card (TNT1) had 16 MB Vram, and it worked
\r
48 // well with many games, but I recommend nowadays 64 MB Vram to get a good speed.
\r
50 // Sadly, there is also a second kind of texture cache needed, for "psx texture windows".
\r
51 // Those are "repeated" textures, so a psx "texture window" needs to be put in
\r
52 // a whole texture to use the GL_TEXTURE_WRAP_ features. This cache can get full very
\r
53 // fast in games which are having an heavy "texture window" usage, like RRT4. As an
\r
54 // alternative, this plugin can use the OGL "palette" extension on texture windows,
\r
55 // if available. Nowadays also a fragment shader can easily be used to emulate
\r
56 // texture wrapping in a texture atlas, so the main cache could hold the texture
\r
57 // windows as well (that's what I am doing in the OGL2 plugin). But currently the
\r
58 // OGL1 plugin is a "shader-free" zone, so heavy "texture window" games will cause
\r
59 // much texture uploads.
\r
61 // Some final advice: take care if you change things in here. I've removed my ASM
\r
62 // handlers (they didn't cause much speed gain anyway) for readability/portability,
\r
63 // but still the functions/data structures used here are easy to mess up. I guess it
\r
64 // can be a pain in the ass to port the plugin to another byte order :)
\r
66 ////////////////////////////////////////////////////////////////////////////////////
\r
73 #include "externals.h"
\r
74 #include "texture.h"
\r
78 #include "gpuStdafx.h"
\r
80 #include "gpuDraw.h"
\r
81 //#include "plugins.h"
\r
82 #include "gpuExternals.h"
\r
83 #include "gpuTexture.h"
\r
84 #include "gpuPlugin.h"
\r
85 #include "gpuPrim.h"
\r
87 #define CLUTCHK 0x00060000
\r
88 #define CLUTSHIFT 17
\r
90 ////////////////////////////////////////////////////////////////////////
\r
91 // texture conversion buffer ..
\r
92 ////////////////////////////////////////////////////////////////////////
\r
94 GLubyte ubPaletteBuffer[256][4];
\r
95 GLuint gTexMovieName=0;
\r
96 GLuint gTexBlurName=0;
\r
97 GLuint gTexFrameName=0;
\r
98 int iTexGarbageCollection=1;
\r
99 unsigned long dwTexPageComp=0;
\r
102 int iClampType=GL_CLAMP;
\r
104 int iClampType=GL_CLAMP_TO_EDGE;
\r
106 int iFilter = GL_LINEAR;
\r
107 void (*LoadSubTexFn) (int,int,short,short);
\r
108 unsigned long (*PalTexturedColourFn) (unsigned long);
\r
110 ////////////////////////////////////////////////////////////////////////
\r
112 ////////////////////////////////////////////////////////////////////////
\r
114 #define PALCOL(x) PalTexturedColourFn (x)
\r
116 #define CSUBSIZE 2048
\r
117 #define CSUBSIZEA 8192
\r
118 #define CSUBSIZES 4096
\r
135 #define MAXWNDTEXCACHE 128
\r
137 #define XCHECK(pos1,pos2) ((pos1.c[0]>=pos2.c[1])&&(pos1.c[1]<=pos2.c[0])&&(pos1.c[2]>=pos2.c[3])&&(pos1.c[3]<=pos2.c[2]))
\r
138 #define INCHECK(pos2,pos1) ((pos1.c[0]<=pos2.c[0]) && (pos1.c[1]>=pos2.c[1]) && (pos1.c[2]<=pos2.c[2]) && (pos1.c[3]>=pos2.c[3]))
\r
140 ////////////////////////////////////////////////////////////////////////
\r
142 u8 * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache);
\r
143 void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);
\r
144 void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);
\r
145 void DefineSubTextureSort(void);
\r
147 ////////////////////////////////////////////////////////////////////////
\r
149 ////////////////////////////////////////////////////////////////////////
\r
151 long GlobalTexturePage;
\r
156 int iSortTexCnt=32;
\r
157 BOOL bUseFastMdec=FALSE;
\r
158 BOOL bUse15bitMdec=FALSE;
\r
159 int iFrameTexType=0;
\r
160 int iFrameReadType=0;
\r
162 unsigned long (*TCF[2]) (unsigned long);
\r
163 unsigned short (*PTCF[2]) (unsigned short);
\r
165 ////////////////////////////////////////////////////////////////////////
\r
166 // texture cache implementation
\r
167 ////////////////////////////////////////////////////////////////////////
\r
173 // "texture window" cache entry
\r
175 typedef struct textureWndCacheEntryTag
\r
177 unsigned long ClutID;
\r
184 } textureWndCacheEntry;
\r
186 // "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)
\r
188 typedef struct textureSubCacheEntryTagS
\r
190 unsigned long ClutID;
\r
196 } textureSubCacheEntryS;
\r
202 //---------------------------------------------
\r
204 #define MAXTPAGES_MAX 64
\r
205 #define MAXSORTTEX_MAX 196
\r
207 //---------------------------------------------
\r
209 textureWndCacheEntry wcWndtexStore[MAXWNDTEXCACHE];
\r
210 textureSubCacheEntryS * pscSubtexStore[3][MAXTPAGES_MAX];
\r
211 EXLong * pxSsubtexLeft [MAXSORTTEX_MAX];
\r
212 GLuint uiStexturePage[MAXSORTTEX_MAX];
\r
214 unsigned short usLRUTexPage=0;
\r
218 int iTexWndLimit=MAXWNDTEXCACHE/2;
\r
220 GLubyte * texturepart=NULL;
\r
221 GLubyte * texturebuffer=NULL;
\r
222 unsigned long g_x1,g_y1,g_x2,g_y2;
\r
225 unsigned short MAXTPAGES = 32;
\r
226 unsigned short CLUTMASK = 0x7fff;
\r
227 unsigned short CLUTYMASK = 0x1ff;
\r
228 unsigned short MAXSORTTEX = 196;
\r
230 ////////////////////////////////////////////////////////////////////////
\r
231 // Texture color conversions... all my ASM funcs are removed for easier
\r
232 // porting... and honestly: nowadays the speed gain would be pointless
\r
233 ////////////////////////////////////////////////////////////////////////
\r
235 unsigned long XP8RGBA(unsigned long BGR)
\r
237 if(!(BGR&0xffff)) return 0x50000000;
\r
238 if(DrawSemiTrans && !(BGR&0x8000))
\r
239 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
240 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
243 unsigned long XP8RGBAEx(unsigned long BGR)
\r
245 if(!(BGR&0xffff)) return 0x03000000;
\r
246 if(DrawSemiTrans && !(BGR&0x8000))
\r
247 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
248 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
251 unsigned long CP8RGBA(unsigned long BGR)
\r
254 if(!(BGR&0xffff)) return 0x50000000;
\r
255 if(DrawSemiTrans && !(BGR&0x8000))
\r
256 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
257 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
258 if(l==0xffffff00) l=0xff000000;
\r
262 unsigned long CP8RGBAEx(unsigned long BGR)
\r
265 if(!(BGR&0xffff)) return 0x03000000;
\r
266 if(DrawSemiTrans && !(BGR&0x8000))
\r
267 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
268 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
269 if(l==0xffffff00) l=0xff000000;
\r
273 unsigned long XP8RGBA_0(unsigned long BGR)
\r
275 if(!(BGR&0xffff)) return 0x50000000;
\r
276 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
279 unsigned long XP8RGBAEx_0(unsigned long BGR)
\r
281 if(!(BGR&0xffff)) return 0x03000000;
\r
282 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
285 unsigned long XP8BGRA_0(unsigned long BGR)
\r
287 if(!(BGR&0xffff)) return 0x50000000;
\r
288 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
291 unsigned long XP8BGRAEx_0(unsigned long BGR)
\r
293 if(!(BGR&0xffff)) return 0x03000000;
\r
294 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
297 unsigned long CP8RGBA_0(unsigned long BGR)
\r
301 if(!(BGR&0xffff)) return 0x50000000;
\r
302 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
303 if(l==0xfff8f800) l=0xff000000;
\r
307 unsigned long CP8RGBAEx_0(unsigned long BGR)
\r
311 if(!(BGR&0xffff)) return 0x03000000;
\r
312 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
313 if(l==0xfff8f800) l=0xff000000;
\r
317 unsigned long CP8BGRA_0(unsigned long BGR)
\r
321 if(!(BGR&0xffff)) return 0x50000000;
\r
322 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
323 if(l==0xff00f8f8) l=0xff000000;
\r
327 unsigned long CP8BGRAEx_0(unsigned long BGR)
\r
331 if(!(BGR&0xffff)) return 0x03000000;
\r
332 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
333 if(l==0xff00f8f8) l=0xff000000;
\r
337 unsigned long XP8RGBA_1(unsigned long BGR)
\r
339 if(!(BGR&0xffff)) return 0x50000000;
\r
340 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
341 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
344 unsigned long XP8RGBAEx_1(unsigned long BGR)
\r
346 if(!(BGR&0xffff)) return 0x03000000;
\r
347 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
348 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
351 unsigned long XP8BGRA_1(unsigned long BGR)
\r
353 if(!(BGR&0xffff)) return 0x50000000;
\r
354 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}
\r
355 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
358 unsigned long XP8BGRAEx_1(unsigned long BGR)
\r
360 if(!(BGR&0xffff)) return 0x03000000;
\r
361 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}
\r
362 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
365 unsigned long P8RGBA(unsigned long BGR)
\r
367 if(!(BGR&0xffff)) return 0;
\r
368 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
371 unsigned long P8BGRA(unsigned long BGR)
\r
373 if(!(BGR&0xffff)) return 0;
\r
374 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
377 unsigned short XP5RGBA(unsigned short BGR)
\r
380 if(DrawSemiTrans && !(BGR&0x8000))
\r
381 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
382 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
385 unsigned short XP5RGBA_0 (unsigned short BGR)
\r
389 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
392 unsigned short CP5RGBA_0 (unsigned short BGR)
\r
398 s=((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
403 unsigned short XP5RGBA_1(unsigned short BGR)
\r
407 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
408 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
411 unsigned short P5RGBA(unsigned short BGR)
\r
414 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
417 unsigned short XP4RGBA(unsigned short BGR)
\r
420 if(DrawSemiTrans && !(BGR&0x8000))
\r
421 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
422 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
425 unsigned short XP4RGBA_0 (unsigned short BGR)
\r
428 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
431 unsigned short CP4RGBA_0 (unsigned short BGR)
\r
435 s=(((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
436 if(s==0x0fff) s=0x000f;
\r
440 unsigned short XP4RGBA_1(unsigned short BGR)
\r
444 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
445 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
448 unsigned short P4RGBA(unsigned short BGR)
\r
451 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
454 ////////////////////////////////////////////////////////////////////////
\r
455 // CHECK TEXTURE MEM (on plugin startup)
\r
456 ////////////////////////////////////////////////////////////////////////
\r
461 void CheckTextureMemory(void)
\r
463 GLboolean b;GLboolean * bDetail;
\r
464 int i,iCnt,iRam=iVRamSize*1024*1024;
\r
472 iRam-=(iResX*iResY*8);
\r
473 iRam-=(iResX*iResY*(iZBufferDepth/8));
\r
476 iSortTexCnt=iRam/(256*256*ts);
\r
478 if(iSortTexCnt>MAXSORTTEX)
\r
480 iSortTexCnt=MAXSORTTEX-min(1,0);
\r
484 iSortTexCnt-=3+min(1,0);
\r
485 if(iSortTexCnt<8) iSortTexCnt=8;
\r
488 for(i=0;i<MAXSORTTEX;i++)
\r
489 uiStexturePage[i]=0;
\r
496 p=(s8 *)malloc(iTSize*iTSize*4);
\r
499 glGenTextures(MAXSORTTEX,uiStexturePage);
\r
500 for(i=0;i<MAXSORTTEX;i++)
\r
502 glBindTexture(GL_TEXTURE_2D,uiStexturePage[i]);
\r
503 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
504 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
505 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
506 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
507 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTSize, iTSize, 0,GL_RGBA, GL_UNSIGNED_BYTE, p);
\r
509 glBindTexture(GL_TEXTURE_2D,0);
\r
513 bDetail=(GLboolean*)malloc(MAXSORTTEX*sizeof(GLboolean));
\r
514 memset(bDetail,0,MAXSORTTEX*sizeof(GLboolean));
\r
516 glDeleteTextures(MAXSORTTEX,uiStexturePage);
\r
518 for(i=0;i<MAXSORTTEX;i++)
\r
520 if(bDetail[i]) iCnt++;
\r
521 uiStexturePage[i]=0;
\r
526 if(b) iSortTexCnt=MAXSORTTEX-min(1,0);
\r
527 else iSortTexCnt=iCnt-3+min(1,0); // place for menu&texwnd
\r
529 if(iSortTexCnt<8) iSortTexCnt=8;
\r
532 ////////////////////////////////////////////////////////////////////////
\r
533 // Main init of textures
\r
534 ////////////////////////////////////////////////////////////////////////
\r
536 void InitializeTextureStore()
\r
540 if(iGPUHeight==1024)
\r
546 iTexGarbageCollection=0;
\r
556 memset(vertex,0,4*sizeof(OGLVertex)); // init vertices
\r
558 gTexName=0; // init main tex name
\r
560 iTexWndLimit=MAXWNDTEXCACHE;
\r
561 /* if(!iUsePalTextures) */iTexWndLimit/=2;
\r
563 memset(wcWndtexStore,0,sizeof(textureWndCacheEntry)*
\r
565 texturepart=(GLubyte *)malloc(256*256*4);
\r
566 memset(texturepart,0,256*256*4);
\r
567 texturebuffer=NULL;
\r
569 for(i=0;i<3;i++) // -> info for 32*3
\r
570 for(j=0;j<MAXTPAGES;j++)
\r
572 pscSubtexStore[i][j]=(textureSubCacheEntryS *)malloc(CSUBSIZES*sizeof(textureSubCacheEntryS));
\r
573 memset(pscSubtexStore[i][j],0,CSUBSIZES*sizeof(textureSubCacheEntryS));
\r
575 for(i=0;i<MAXSORTTEX;i++) // -> info 0..511
\r
577 pxSsubtexLeft[i]=(EXLong *)malloc(CSUBSIZE*sizeof(EXLong));
\r
578 memset(pxSsubtexLeft[i],0,CSUBSIZE*sizeof(EXLong));
\r
579 uiStexturePage[i]=0;
\r
583 ////////////////////////////////////////////////////////////////////////
\r
584 // Clean up on exit
\r
585 ////////////////////////////////////////////////////////////////////////
\r
587 void CleanupTextureStore()
\r
589 int i,j;textureWndCacheEntry * tsx;
\r
590 //----------------------------------------------------//
\r
591 glBindTexture(GL_TEXTURE_2D,0);
\r
592 //----------------------------------------------------//
\r
593 free(texturepart); // free tex part
\r
597 free(texturebuffer);
\r
600 //----------------------------------------------------//
\r
601 tsx=wcWndtexStore; // loop tex window cache
\r
602 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)
\r
604 if(tsx->texname) // -> some tex?
\r
605 glDeleteTextures(1,&tsx->texname); // --> delete it
\r
607 iMaxTexWnds=0; // no more tex wnds
\r
608 //----------------------------------------------------//
\r
609 if(gTexMovieName!=0) // some movie tex?
\r
610 glDeleteTextures(1, &gTexMovieName); // -> delete it
\r
611 gTexMovieName=0; // no more movie tex
\r
612 //----------------------------------------------------//
\r
613 if(gTexFrameName!=0) // some 15bit framebuffer tex?
\r
614 glDeleteTextures(1, &gTexFrameName); // -> delete it
\r
615 gTexFrameName=0; // no more movie tex
\r
616 //----------------------------------------------------//
\r
617 if(gTexBlurName!=0) // some 15bit framebuffer tex?
\r
618 glDeleteTextures(1, &gTexBlurName); // -> delete it
\r
619 gTexBlurName=0; // no more movie tex
\r
620 //----------------------------------------------------//
\r
621 for(i=0;i<3;i++) // -> loop
\r
622 for(j=0;j<MAXTPAGES;j++) // loop tex pages
\r
624 free(pscSubtexStore[i][j]); // -> clean mem
\r
626 for(i=0;i<MAXSORTTEX;i++)
\r
628 if(uiStexturePage[i]) // --> tex used ?
\r
630 glDeleteTextures(1,&uiStexturePage[i]);
\r
631 uiStexturePage[i]=0; // --> delete it
\r
633 free(pxSsubtexLeft[i]); // -> clean mem
\r
635 //----------------------------------------------------//
\r
638 ////////////////////////////////////////////////////////////////////////
\r
639 // Reset textures in game...
\r
640 ////////////////////////////////////////////////////////////////////////
\r
642 void ResetTextureArea(BOOL bDelTex)
\r
644 int i,j;textureSubCacheEntryS * tss;EXLong * lu;
\r
645 textureWndCacheEntry * tsx;
\r
646 //----------------------------------------------------//
\r
650 //----------------------------------------------------//
\r
651 if(bDelTex) {glBindTexture(GL_TEXTURE_2D,0);gTexName=0;}
\r
652 //----------------------------------------------------//
\r
654 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)
\r
657 if(bDelTex && tsx->texname)
\r
659 glDeleteTextures(1,&tsx->texname);
\r
664 //----------------------------------------------------//
\r
667 for(j=0;j<MAXTPAGES;j++)
\r
669 tss=pscSubtexStore[i][j];
\r
670 (tss+SOFFA)->pos.l=0;
\r
671 (tss+SOFFB)->pos.l=0;
\r
672 (tss+SOFFC)->pos.l=0;
\r
673 (tss+SOFFD)->pos.l=0;
\r
676 for(i=0;i<iSortTexCnt;i++)
\r
678 lu=pxSsubtexLeft[i];
\r
680 if(bDelTex && uiStexturePage[i])
\r
681 {glDeleteTextures(1,&uiStexturePage[i]);uiStexturePage[i]=0;}
\r
686 ////////////////////////////////////////////////////////////////////////
\r
687 // Invalidate tex windows
\r
688 ////////////////////////////////////////////////////////////////////////
\r
690 void InvalidateWndTextureArea(long X,long Y,long W, long H)
\r
692 int i,px1,px2,py1,py2,iYM=1;
\r
693 textureWndCacheEntry * tsw=wcWndtexStore;
\r
697 if(X<0) X=0;if(X>1023) X=1023;
\r
698 if(W<0) W=0;if(W>1023) W=1023;
\r
699 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
\r
700 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
\r
703 if(iGPUHeight==1024) iYM=3;
\r
706 py2=min(iYM,H>>8); // y: 0 or 1
\r
709 px2=min(15,(W>>6));
\r
713 py1=py1<<4;px1+=py1;px2+=py1; // change to 0-31
\r
714 for(i=0;i<iMaxTexWnds;i++,tsw++)
\r
718 if(tsw->pageid>=px1 && tsw->pageid<=px2)
\r
727 py1=px1+16;py2=px2+16;
\r
728 for(i=0;i<iMaxTexWnds;i++,tsw++)
\r
732 if((tsw->pageid>=px1 && tsw->pageid<=px2) ||
\r
733 (tsw->pageid>=py1 && tsw->pageid<=py2))
\r
741 // adjust tex window count
\r
742 tsw=wcWndtexStore+iMaxTexWnds-1;
\r
743 while(iMaxTexWnds && !tsw->used) {iMaxTexWnds--;tsw--;}
\r
748 ////////////////////////////////////////////////////////////////////////
\r
749 // same for sort textures
\r
750 ////////////////////////////////////////////////////////////////////////
\r
752 void MarkFree(textureSubCacheEntryS * tsx)
\r
754 EXLong * ul, * uls;
\r
755 int j,iMax;u8 x1,y1,dx,dy;
\r
757 uls=pxSsubtexLeft[tsx->cTexID];
\r
758 iMax=uls->l;ul=uls+1;
\r
762 for(j=0;j<iMax;j++,ul++)
\r
763 if(ul->l==0xffffffff) break;
\r
767 if(j==iMax) uls->l=uls->l+1;
\r
769 x1=tsx->posTX;dx=tsx->pos.c[2]-tsx->pos.c[3];
\r
770 if(tsx->posTX) {x1--;dx+=3;}
\r
771 y1=tsx->posTY;dy=tsx->pos.c[0]-tsx->pos.c[1];
\r
772 if(tsx->posTY) {y1--;dy+=3;}
\r
781 void InvalidateSubSTextureArea(long X,long Y,long W, long H)
\r
783 int i,j,k,iMax,px,py,px1,px2,py1,py2,iYM=1;
\r
784 EXLong npos;textureSubCacheEntryS * tsb;
\r
785 long x1,x2,y1,y2,xa,sw;
\r
789 if(X<0) X=0;if(X>1023) X=1023;
\r
790 if(W<0) W=0;if(W>1023) W=1023;
\r
791 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
\r
792 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
\r
795 if(iGPUHeight==1024) iYM=3;
\r
798 py2=min(iYM,H>>8); // y: 0 or 1
\r
799 px1=max(0,(X>>6)-3);
\r
800 px2=min(15,(W>>6)+3); // x: 0-15
\r
802 for(py=py1;py<=py2;py++)
\r
804 j=(py<<4)+px1; // get page
\r
806 y1=py*256;y2=y1+255;
\r
813 if(y2<y1) {sw=y1;y1=y2;y2=sw;}
\r
817 for(px=px1;px<=px2;px++,j++)
\r
828 if(x2<x1) {sw=x1;x1=x2;x2=sw;}
\r
830 if (dwGPUVersion == 2)
\r
833 npos.l=((x1-xa)<<(26-k))|((x2-xa)<<(18-k))|y1|y2;
\r
836 tsb=pscSubtexStore[k][j]+SOFFA;iMax=tsb->pos.l;tsb++;
\r
837 for(i=0;i<iMax;i++,tsb++)
\r
838 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
840 // if(npos.l & 0x00800000)
\r
842 tsb=pscSubtexStore[k][j]+SOFFB;iMax=tsb->pos.l;tsb++;
\r
843 for(i=0;i<iMax;i++,tsb++)
\r
844 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
847 // if(npos.l & 0x00000080)
\r
849 tsb=pscSubtexStore[k][j]+SOFFC;iMax=tsb->pos.l;tsb++;
\r
850 for(i=0;i<iMax;i++,tsb++)
\r
851 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
854 // if(npos.l & 0x00800080)
\r
856 tsb=pscSubtexStore[k][j]+SOFFD;iMax=tsb->pos.l;tsb++;
\r
857 for(i=0;i<iMax;i++,tsb++)
\r
858 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
866 ////////////////////////////////////////////////////////////////////////
\r
867 // Invalidate some parts of cache: main routine
\r
868 ////////////////////////////////////////////////////////////////////////
\r
870 void InvalidateTextureAreaEx(void)
\r
872 short W=sxmax-sxmin;
\r
873 short H=symax-symin;
\r
875 if(W==0 && H==0) return;
\r
878 InvalidateWndTextureArea(sxmin,symin,W,H);
\r
880 InvalidateSubSTextureArea(sxmin,symin,W,H);
\r
883 ////////////////////////////////////////////////////////////////////////
\r
885 void InvalidateTextureArea(long X,long Y,long W, long H)
\r
887 if(W==0 && H==0) return;
\r
889 if(iMaxTexWnds) InvalidateWndTextureArea(X,Y,W,H);
\r
891 InvalidateSubSTextureArea(X,Y,W,H);
\r
895 ////////////////////////////////////////////////////////////////////////
\r
896 // tex window: define
\r
897 ////////////////////////////////////////////////////////////////////////
\r
899 void DefineTextureWnd(void)
\r
902 glGenTextures(1, &gTexName);
\r
904 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
906 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
\r
907 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
\r
910 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
911 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
914 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,
\r
917 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
920 ////////////////////////////////////////////////////////////////////////
\r
921 // tex window: load packed stretch
\r
922 ////////////////////////////////////////////////////////////////////////
\r
924 void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
\r
926 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;
\r
927 unsigned int palstart;
\r
928 unsigned short *px,*pa,*ta;
\r
929 u8 *cSRCPtr,*cOSRCPtr;
\r
930 unsigned short *wSRCPtr,*wOSRCPtr;
\r
931 unsigned long LineOffset;unsigned short s;
\r
932 int pmult=pageid/16;
\r
933 unsigned short (*LPTCOL)(unsigned short);
\r
935 LPTCOL=PTCF[DrawSemiTrans];
\r
937 ldxo=TWin.Position.x1-TWin.OPosition.x1;
\r
938 ldy =TWin.Position.y1-TWin.OPosition.y1;
\r
940 pa=px=(unsigned short *)ubPaletteBuffer;
\r
941 ta=(unsigned short *)texturepart;
\r
942 palstart=cx+(cy*1024);
\r
948 //--------------------------------------------------//
\r
949 // 4bit texture load ..
\r
953 unsigned int TXV,TXU,n_xi,n_yi;
\r
955 wSRCPtr=psxVuw+palstart;
\r
956 for(row=0;row<16;row++)
\r
957 *px++=LPTCOL(*wSRCPtr++);
\r
960 for(TXV=g_y1;TXV<=column;TXV++)
\r
963 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
965 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
966 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
968 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
971 if(ldx) {*ta++=s;ldx--;}
\r
976 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
977 *ta++=*(ta-(g_x2-g_x1));
\r
981 DefineTextureWnd();
\r
987 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
989 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
991 wSRCPtr=psxVuw+palstart;
\r
992 for(row=0;row<16;row++)
\r
993 *px++=LPTCOL(*wSRCPtr++);
\r
995 sxm=g_x1&1;sxh=g_x1>>1;
\r
996 if(sxm) j=g_x1+1; else j=g_x1;
\r
997 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
998 for(column=g_y1;column<=g_y2;column++)
\r
1000 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1001 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1003 for(row=j;row<=g_x2-ldxo;row++)
\r
1005 s=*(pa+(*cSRCPtr & 0xF));
\r
1007 if(ldx) {*ta++=s;ldx--;}
\r
1009 if(row<=g_x2-ldxo)
\r
1011 s=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1013 if(ldx) {*ta++=s;ldx--;}
\r
1018 if(ldy && column&1)
\r
1019 {ldy--;cSRCPtr = cOSRCPtr;}
\r
1020 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
\r
1023 DefineTextureWnd();
\r
1025 //--------------------------------------------------//
\r
1026 // 8bit texture load ..
\r
1030 unsigned int TXV,TXU,n_xi,n_yi;
\r
1032 wSRCPtr=psxVuw+palstart;
\r
1033 for(row=0;row<256;row++)
\r
1034 *px++=LPTCOL(*wSRCPtr++);
\r
1037 for(TXV=g_y1;TXV<=column;TXV++)
\r
1040 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1042 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1043 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1045 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1048 if(ldx) {*ta++=s;ldx--;}
\r
1053 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1054 *ta++=*(ta-(g_x2-g_x1));
\r
1059 DefineTextureWnd();
\r
1064 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1066 // not using a lookup table here... speeds up smaller texture areas
\r
1067 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1068 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
\r
1070 for(column=g_y1;column<=g_y2;column++)
\r
1072 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1073 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1075 s=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1077 if(ldx) {*ta++=s;ldx--;}
\r
1079 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
\r
1080 else cSRCPtr+=LineOffset;
\r
1083 DefineTextureWnd();
\r
1085 //--------------------------------------------------//
\r
1086 // 16bit texture load ..
\r
1088 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1089 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1090 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo;
\r
1092 for(column=g_y1;column<=g_y2;column++)
\r
1094 wOSRCPtr=wSRCPtr;ldx=ldxo;
\r
1095 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1097 s=LPTCOL(*wSRCPtr++);
\r
1099 if(ldx) {*ta++=s;ldx--;}
\r
1101 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}
\r
1102 else wSRCPtr+=LineOffset;
\r
1105 DefineTextureWnd();
\r
1107 //--------------------------------------------------//
\r
1108 // others are not possible !
\r
1112 ////////////////////////////////////////////////////////////////////////
\r
1113 // tex window: load stretched
\r
1114 ////////////////////////////////////////////////////////////////////////
\r
1116 void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1118 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo,s;
\r
1119 unsigned int palstart;
\r
1120 unsigned long *px,*pa,*ta;
\r
1121 u8 *cSRCPtr,*cOSRCPtr;
\r
1122 unsigned short *wSRCPtr,*wOSRCPtr;
\r
1123 unsigned long LineOffset;
\r
1124 int pmult=pageid/16;
\r
1125 unsigned long (*LTCOL)(unsigned long);
\r
1127 LTCOL=TCF[DrawSemiTrans];
\r
1129 ldxo=TWin.Position.x1-TWin.OPosition.x1;
\r
1130 ldy =TWin.Position.y1-TWin.OPosition.y1;
\r
1132 pa=px=(unsigned long *)ubPaletteBuffer;
\r
1133 ta=(unsigned long *)texturepart;
\r
1134 palstart=cx+(cy*1024);
\r
1140 //--------------------------------------------------//
\r
1141 // 4bit texture load ..
\r
1143 //------------------- ZN STUFF
\r
1147 unsigned int TXV,TXU,n_xi,n_yi;
\r
1149 wSRCPtr=psxVuw+palstart;
\r
1153 *px =LTCOL(*wSRCPtr);
\r
1154 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1155 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1156 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1157 row--;px+=4;wSRCPtr+=4;
\r
1162 for(TXV=g_y1;TXV<=column;TXV++)
\r
1165 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1167 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1168 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1170 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1173 if(ldx) {*ta++=s;ldx--;}
\r
1178 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1179 *ta++=*(ta-(g_x2-g_x1));
\r
1183 DefineTextureWnd();
\r
1188 //-------------------
\r
1190 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1191 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
1193 wSRCPtr=psxVuw+palstart;
\r
1194 for(row=0;row<16;row++)
\r
1195 *px++=LTCOL(*wSRCPtr++);
\r
1197 sxm=g_x1&1;sxh=g_x1>>1;
\r
1198 if(sxm) j=g_x1+1; else j=g_x1;
\r
1199 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1200 for(column=g_y1;column<=g_y2;column++)
\r
1202 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1203 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1205 for(row=j;row<=g_x2-ldxo;row++)
\r
1207 s=*(pa+(*cSRCPtr & 0xF));
\r
1209 if(ldx) {*ta++=s;ldx--;}
\r
1211 if(row<=g_x2-ldxo)
\r
1213 s=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1215 if(ldx) {*ta++=s;ldx--;}
\r
1219 if(ldy && column&1)
\r
1220 {ldy--;cSRCPtr = cOSRCPtr;}
\r
1221 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
\r
1224 DefineTextureWnd();
\r
1226 //--------------------------------------------------//
\r
1227 // 8bit texture load ..
\r
1229 //------------ ZN STUFF
\r
1232 unsigned int TXV,TXU,n_xi,n_yi;
\r
1234 wSRCPtr=psxVuw+palstart;
\r
1238 *px =LTCOL(*wSRCPtr);
\r
1239 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1240 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1241 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1242 row--;px+=4;wSRCPtr+=4;
\r
1247 for(TXV=g_y1;TXV<=column;TXV++)
\r
1250 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1252 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1253 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1255 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1257 if(ldx) {*ta++=s;ldx--;}
\r
1262 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1263 *ta++=*(ta-(g_x2-g_x1));
\r
1268 DefineTextureWnd();
\r
1274 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1276 // not using a lookup table here... speeds up smaller texture areas
\r
1277 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1278 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
\r
1280 for(column=g_y1;column<=g_y2;column++)
\r
1282 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1283 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1285 s=LTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1287 if(ldx) {*ta++=s;ldx--;}
\r
1289 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
\r
1290 else cSRCPtr+=LineOffset;
\r
1293 DefineTextureWnd();
\r
1295 //--------------------------------------------------//
\r
1296 // 16bit texture load ..
\r
1298 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1300 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1301 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo;
\r
1303 for(column=g_y1;column<=g_y2;column++)
\r
1305 wOSRCPtr=wSRCPtr;ldx=ldxo;
\r
1306 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1308 s=LTCOL(*wSRCPtr++);
\r
1310 if(ldx) {*ta++=s;ldx--;}
\r
1312 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}
\r
1313 else wSRCPtr+=LineOffset;
\r
1316 DefineTextureWnd();
\r
1318 //--------------------------------------------------//
\r
1319 // others are not possible !
\r
1323 ////////////////////////////////////////////////////////////////////////
\r
1324 // tex window: load packed simple
\r
1325 ////////////////////////////////////////////////////////////////////////
\r
1327 void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1329 unsigned long start,row,column,j,sxh,sxm;
\r
1330 unsigned int palstart;
\r
1331 unsigned short *px,*pa,*ta;
\r
1333 unsigned short *wSRCPtr;
\r
1334 unsigned long LineOffset;
\r
1335 int pmult=pageid/16;
\r
1336 unsigned short (*LPTCOL)(unsigned short);
\r
1338 LPTCOL=PTCF[DrawSemiTrans];
\r
1340 pa=px=(unsigned short *)ubPaletteBuffer;
\r
1341 ta=(unsigned short *)texturepart;
\r
1342 palstart=cx+(cy*1024);
\r
1348 //--------------------------------------------------//
\r
1349 // 4bit texture load ..
\r
1353 unsigned int TXV,TXU,n_xi,n_yi;
\r
1355 wSRCPtr=psxVuw+palstart;
\r
1356 for(row=0;row<16;row++)
\r
1357 *px++=LPTCOL(*wSRCPtr++);
\r
1359 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1361 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1363 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1364 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1366 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1370 DefineTextureWnd();
\r
1375 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1377 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
1379 wSRCPtr=psxVuw+palstart;
\r
1380 for(row=0;row<16;row++)
\r
1381 *px++=LPTCOL(*wSRCPtr++);
\r
1383 sxm=g_x1&1;sxh=g_x1>>1;
\r
1384 if(sxm) j=g_x1+1; else j=g_x1;
\r
1385 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1386 for(column=g_y1;column<=g_y2;column++)
\r
1388 cSRCPtr = psxVub + start + (2048*column) + sxh;
\r
1390 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1392 for(row=j;row<=g_x2;row++)
\r
1394 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
\r
1395 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1400 DefineTextureWnd();
\r
1402 //--------------------------------------------------//
\r
1403 // 8bit texture load ..
\r
1407 unsigned int TXV,TXU,n_xi,n_yi;
\r
1409 wSRCPtr=psxVuw+palstart;
\r
1410 for(row=0;row<256;row++)
\r
1411 *px++=LPTCOL(*wSRCPtr++);
\r
1413 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1415 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1417 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1418 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1420 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1424 DefineTextureWnd();
\r
1429 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1431 // not using a lookup table here... speeds up smaller texture areas
\r
1432 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1433 LineOffset = 2048 - (g_x2-g_x1+1);
\r
1435 for(column=g_y1;column<=g_y2;column++)
\r
1437 for(row=g_x1;row<=g_x2;row++)
\r
1438 *ta++=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1439 cSRCPtr+=LineOffset;
\r
1442 DefineTextureWnd();
\r
1444 //--------------------------------------------------//
\r
1445 // 16bit texture load ..
\r
1447 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1448 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1449 LineOffset = 1024 - (g_x2-g_x1+1);
\r
1451 for(column=g_y1;column<=g_y2;column++)
\r
1453 for(row=g_x1;row<=g_x2;row++)
\r
1454 *ta++=LPTCOL(*wSRCPtr++);
\r
1455 wSRCPtr+=LineOffset;
\r
1458 DefineTextureWnd();
\r
1460 //--------------------------------------------------//
\r
1461 // others are not possible !
\r
1465 ////////////////////////////////////////////////////////////////////////
\r
1466 // tex window: load simple
\r
1467 ////////////////////////////////////////////////////////////////////////
\r
1469 void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1471 unsigned long start,row,column,j,sxh,sxm;
\r
1472 unsigned int palstart;
\r
1473 unsigned long *px,*pa,*ta;
\r
1475 unsigned short *wSRCPtr;
\r
1476 unsigned long LineOffset;
\r
1477 int pmult=pageid/16;
\r
1478 unsigned long (*LTCOL)(unsigned long);
\r
1480 LTCOL=TCF[DrawSemiTrans];
\r
1482 pa=px=(unsigned long *)ubPaletteBuffer;
\r
1483 ta=(unsigned long *)texturepart;
\r
1484 palstart=cx+(cy*1024);
\r
1490 //--------------------------------------------------//
\r
1491 // 4bit texture load ..
\r
1495 unsigned int TXV,TXU,n_xi,n_yi;
\r
1497 wSRCPtr=psxVuw+palstart;
\r
1501 *px =LTCOL(*wSRCPtr);
\r
1502 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1503 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1504 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1505 row--;px+=4;wSRCPtr+=4;
\r
1509 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1511 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1513 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1514 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1516 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1520 DefineTextureWnd();
\r
1525 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1527 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
1529 wSRCPtr=psxVuw+palstart;
\r
1530 for(row=0;row<16;row++)
\r
1531 *px++=LTCOL(*wSRCPtr++);
\r
1533 sxm=g_x1&1;sxh=g_x1>>1;
\r
1534 if(sxm) j=g_x1+1; else j=g_x1;
\r
1535 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1536 for(column=g_y1;column<=g_y2;column++)
\r
1538 cSRCPtr = psxVub + start + (2048*column) + sxh;
\r
1540 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1542 for(row=j;row<=g_x2;row++)
\r
1544 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
\r
1545 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1550 DefineTextureWnd();
\r
1552 //--------------------------------------------------//
\r
1553 // 8bit texture load ..
\r
1557 unsigned int TXV,TXU,n_xi,n_yi;
\r
1559 wSRCPtr=psxVuw+palstart;
\r
1563 *px =LTCOL(*wSRCPtr);
\r
1564 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1565 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1566 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1567 row--;px+=4;wSRCPtr+=4;
\r
1571 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1573 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1575 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1576 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1578 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1582 DefineTextureWnd();
\r
1587 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1589 // not using a lookup table here... speeds up smaller texture areas
\r
1590 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1591 LineOffset = 2048 - (g_x2-g_x1+1);
\r
1593 for(column=g_y1;column<=g_y2;column++)
\r
1595 for(row=g_x1;row<=g_x2;row++)
\r
1596 *ta++=LTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1597 cSRCPtr+=LineOffset;
\r
1600 DefineTextureWnd();
\r
1602 //--------------------------------------------------//
\r
1603 // 16bit texture load ..
\r
1605 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1607 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1608 LineOffset = 1024 - (g_x2-g_x1+1);
\r
1610 for(column=g_y1;column<=g_y2;column++)
\r
1612 for(row=g_x1;row<=g_x2;row++)
\r
1613 *ta++=LTCOL(*wSRCPtr++);
\r
1614 wSRCPtr+=LineOffset;
\r
1617 DefineTextureWnd();
\r
1619 //--------------------------------------------------//
\r
1620 // others are not possible !
\r
1624 ////////////////////////////////////////////////////////////////////////
\r
1625 ////////////////////////////////////////////////////////////////////////
\r
1626 ////////////////////////////////////////////////////////////////////////
\r
1627 ////////////////////////////////////////////////////////////////////////
\r
1629 void UploadTexWndPal(int mode,short cx,short cy)
\r
1631 unsigned int i,iSize;
\r
1632 unsigned short * wSrcPtr;
\r
1633 unsigned long * ta=(unsigned long *)texturepart;
\r
1635 wSrcPtr=psxVuw+cx+(cy*1024);
\r
1636 if(mode==0) i=4; else i=64;
\r
1642 *ta =PALCOL(*wSrcPtr);
\r
1643 *(ta+1)=PALCOL(*(wSrcPtr+1));
\r
1644 *(ta+2)=PALCOL(*(wSrcPtr+2));
\r
1645 *(ta+3)=PALCOL(*(wSrcPtr+3));
\r
1646 ta+=4;wSrcPtr+=4;i--;
\r
1650 /* (*glColorTableEXTEx)(GL_TEXTURE_2D,GL_RGBA8,iSize,
\r
1651 GL_RGBA,GL_UNSIGNED_BYTE,texturepart);
\r
1654 ////////////////////////////////////////////////////////////////////////
\r
1656 void DefinePalTextureWnd(void)
\r
1659 glGenTextures(1, &gTexName);
\r
1661 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
1663 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
\r
1664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
\r
1667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
1668 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
1671 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,
\r
1672 TWin.Position.x1,
\r
1673 TWin.Position.y1,
\r
1674 0, GL_RGBA, GL_UNSIGNED_BYTE,texturepart);
\r
1677 ///////////////////////////////////////////////////////
\r
1679 void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1681 unsigned long start,row,column,j,sxh,sxm;
\r
1684 unsigned long LineOffset;
\r
1685 int pmult=pageid/16;
\r
1687 ta=(u8 *)texturepart;
\r
1691 //--------------------------------------------------//
\r
1692 // 4bit texture load ..
\r
1694 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1696 sxm=g_x1&1;sxh=g_x1>>1;
\r
1697 if(sxm) j=g_x1+1; else j=g_x1;
\r
1698 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1699 for(column=g_y1;column<=g_y2;column++)
\r
1701 cSRCPtr = psxVub + start + (2048*column) + sxh;
\r
1703 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);
\r
1705 for(row=j;row<=g_x2;row++)
\r
1707 *ta++=(*cSRCPtr & 0xF); row++;
\r
1708 if(row<=g_x2) *ta++=((*cSRCPtr >> 4) & 0xF);
\r
1713 DefinePalTextureWnd();
\r
1715 //--------------------------------------------------//
\r
1716 // 8bit texture load ..
\r
1718 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1720 // not using a lookup table here... speeds up smaller texture areas
\r
1721 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1722 LineOffset = 2048 - (g_x2-g_x1+1);
\r
1724 for(column=g_y1;column<=g_y2;column++)
\r
1726 for(row=g_x1;row<=g_x2;row++)
\r
1728 cSRCPtr+=LineOffset;
\r
1731 DefinePalTextureWnd();
\r
1734 UploadTexWndPal(mode,cx,cy);
\r
1737 ////////////////////////////////////////////////////////////////////////
\r
1739 void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1741 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;
\r
1743 u8 *cSRCPtr,*cOSRCPtr;
\r
1744 unsigned long LineOffset;
\r
1745 int pmult=pageid/16;
\r
1747 ldxo=TWin.Position.x1-TWin.OPosition.x1;
\r
1748 ldy =TWin.Position.y1-TWin.OPosition.y1;
\r
1750 ta=(u8 *)texturepart;
\r
1754 //--------------------------------------------------//
\r
1755 // 4bit texture load ..
\r
1757 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1759 sxm=g_x1&1;sxh=g_x1>>1;
\r
1760 if(sxm) j=g_x1+1; else j=g_x1;
\r
1761 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1762 for(column=g_y1;column<=g_y2;column++)
\r
1764 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1765 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);
\r
1767 for(row=j;row<=g_x2-ldxo;row++)
\r
1769 s=(*cSRCPtr & 0xF);
\r
1771 if(ldx) {*ta++=s;ldx--;}
\r
1773 if(row<=g_x2-ldxo)
\r
1775 s=((*cSRCPtr >> 4) & 0xF);
\r
1777 if(ldx) {*ta++=s;ldx--;}
\r
1781 if(ldy && column&1)
\r
1782 {ldy--;cSRCPtr = cOSRCPtr;}
\r
1783 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
\r
1786 DefinePalTextureWnd();
\r
1788 //--------------------------------------------------//
\r
1789 // 8bit texture load ..
\r
1791 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1793 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1794 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
\r
1796 for(column=g_y1;column<=g_y2;column++)
\r
1798 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1799 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1803 if(ldx) {*ta++=s;ldx--;}
\r
1805 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
\r
1806 else cSRCPtr+=LineOffset;
\r
1809 DefinePalTextureWnd();
\r
1812 UploadTexWndPal(mode,cx,cy);
\r
1815 ////////////////////////////////////////////////////////////////////////
\r
1816 // tex window: main selecting, cache handler included
\r
1817 ////////////////////////////////////////////////////////////////////////
\r
1819 GLuint LoadTextureWnd(long pageid,long TextureMode,unsigned long GivenClutId)
\r
1821 textureWndCacheEntry * ts, * tsx=NULL;
\r
1822 int i;short cx,cy;
\r
1825 npos.c[3]=TWin.Position.x0;
\r
1826 npos.c[2]=TWin.OPosition.x1;
\r
1827 npos.c[1]=TWin.Position.y0;
\r
1828 npos.c[0]=TWin.OPosition.y1;
\r
1830 g_x1=TWin.Position.x0;g_x2=g_x1+TWin.Position.x1-1;
\r
1831 g_y1=TWin.Position.y0;g_y2=g_y1+TWin.Position.y1-1;
\r
1833 if(TextureMode==2) {GivenClutId=0;cx=cy=0;}
\r
1836 cx=((GivenClutId << 4) & 0x3F0);cy=((GivenClutId >> 6) & CLUTYMASK);
\r
1837 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30);
\r
1839 // palette check sum
\r
1841 unsigned long l=0,row;
\r
1842 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));
\r
1843 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
\r
1844 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
\r
1845 l=(l+HIWORD(l))&0x3fffL;
\r
1846 GivenClutId|=(l<<16);
\r
1853 for(i=0;i<iMaxTexWnds;i++,ts++)
\r
1857 if(ts->pos.l==npos.l &&
\r
1858 ts->pageid==pageid &&
\r
1859 ts->textureMode==TextureMode)
\r
1861 if(ts->ClutID==GivenClutId)
\r
1863 ubOpaqueDraw=ts->Opaque;
\r
1864 return ts->texname;
\r
1873 if(iMaxTexWnds==iTexWndLimit)
\r
1875 tsx=wcWndtexStore+iTexWndTurn;
\r
1877 if(iTexWndTurn==iTexWndLimit) iTexWndTurn=0;
\r
1881 tsx=wcWndtexStore+iMaxTexWnds;
\r
1886 gTexName=tsx->texname;
\r
1888 if(TWin.OPosition.y1==TWin.Position.y1 &&
\r
1889 TWin.OPosition.x1==TWin.Position.x1)
\r
1891 LoadWndTexturePage(pageid,TextureMode,cx,cy);
\r
1895 LoadStretchWndTexturePage(pageid,TextureMode,cx,cy);
\r
1898 tsx->Opaque=ubOpaqueDraw;
\r
1899 tsx->pos.l=npos.l;
\r
1900 tsx->ClutID=GivenClutId;
\r
1901 tsx->pageid=pageid;
\r
1902 tsx->textureMode=TextureMode;
\r
1903 tsx->texname=gTexName;
\r
1909 /////////////////////////////////////////////////////////////////////////////
\r
1910 /////////////////////////////////////////////////////////////////////////////
\r
1911 /////////////////////////////////////////////////////////////////////////////
\r
1913 ////////////////////////////////////////////////////////////////////////
\r
1914 // movie texture: define
\r
1915 ////////////////////////////////////////////////////////////////////////
\r
1917 void DefinePackedTextureMovie(void)
\r
1919 if(gTexMovieName==0)
\r
1921 glGenTextures(1, &gTexMovieName);
\r
1922 gTexName=gTexMovieName;
\r
1923 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
1925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
1926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
1928 if(!bUseFastMdec)
\r
1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
\r
1931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
\r
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
1936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
1939 glTexImage2D(GL_TEXTURE_2D, 0, //giWantedRGBA,
\r
1941 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
1945 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName);
\r
1948 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
\r
1949 (xrMovieArea.x1-xrMovieArea.x0),
\r
1950 (xrMovieArea.y1-xrMovieArea.y0),
\r
1952 GL_UNSIGNED_SHORT,
\r
1956 ////////////////////////////////////////////////////////////////////////
\r
1958 void DefineTextureMovie(void)
\r
1960 if(gTexMovieName==0)
\r
1962 glGenTextures(1, &gTexMovieName);
\r
1963 gTexName=gTexMovieName;
\r
1964 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
1966 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
1967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
1969 if(!bUseFastMdec)
\r
1971 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
\r
1972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
\r
1976 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
1977 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
1980 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
1984 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName);
\r
1987 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
\r
1988 (xrMovieArea.x1-xrMovieArea.x0),
\r
1989 (xrMovieArea.y1-xrMovieArea.y0),
\r
1990 GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
1993 ////////////////////////////////////////////////////////////////////////
\r
1994 // movie texture: load
\r
1995 ////////////////////////////////////////////////////////////////////////
\r
1997 #define MRED(x) ((x>>3) & 0x1f)
\r
1998 #define MGREEN(x) ((x>>6) & 0x3e0)
\r
1999 #define MBLUE(x) ((x>>9) & 0x7c00)
\r
2001 #define XMGREEN(x) ((x>>5) & 0x07c0)
\r
2002 #define XMRED(x) ((x<<8) & 0xf800)
\r
2003 #define XMBLUE(x) ((x>>18) & 0x003e)
\r
2005 ////////////////////////////////////////////////////////////////////////
\r
2006 // movie texture: load
\r
2007 ////////////////////////////////////////////////////////////////////////
\r
2009 u8 * LoadDirectMovieFast(void)
\r
2012 unsigned int startxy;
\r
2014 unsigned long * ta=(unsigned long *)texturepart;
\r
2016 if(PSXDisplay.RGB24)
\r
2020 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
\r
2022 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)
\r
2024 pD=(u8 *)&psxVuw[startxy];
\r
2025 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2027 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2034 unsigned long (*LTCOL)(unsigned long);
\r
2036 LTCOL=XP8RGBA_0;//TCF[0];
\r
2040 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2042 startxy=((1024)*column)+xrMovieArea.x0;
\r
2043 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2044 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2048 return texturepart;
\r
2051 ////////////////////////////////////////////////////////////////////////
\r
2053 GLuint LoadTextureMovieFast(void)
\r
2056 unsigned int start,startxy;
\r
2059 if(PSXDisplay.RGB24)
\r
2062 unsigned long * ta=(unsigned long *)texturepart;
\r
2064 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
\r
2066 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)
\r
2068 //startxy=((1024)*column)+xrMovieArea.x0;
\r
2069 pD=(u8 *)&psxVuw[startxy];
\r
2070 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2072 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2079 unsigned long (*LTCOL)(unsigned long);
\r
2080 unsigned long *ta;
\r
2082 LTCOL=XP8RGBA_0;//TCF[0];
\r
2085 ta=(unsigned long *)texturepart;
\r
2087 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2089 startxy=((1024)*column)+xrMovieArea.x0;
\r
2090 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2091 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2094 DefineTextureMovie();
\r
2099 ////////////////////////////////////////////////////////////////////////
\r
2101 GLuint LoadTextureMovie(void)
\r
2103 short row,column,dx;
\r
2104 unsigned int startxy;
\r
2107 if(bUseFastMdec) return LoadTextureMovieFast();
\r
2109 b_X=FALSE;b_Y=FALSE;
\r
2111 if((xrMovieArea.x1-xrMovieArea.x0)<255) b_X=TRUE;
\r
2112 if((xrMovieArea.y1-xrMovieArea.y0)<255) b_Y=TRUE;
\r
2115 if(PSXDisplay.RGB24)
\r
2118 unsigned long * ta=(unsigned long *)texturepart;
\r
2122 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2124 startxy=((1024)*column)+xrMovieArea.x0;
\r
2125 pD=(u8 *)&psxVuw[startxy];
\r
2126 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2128 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2135 dx=xrMovieArea.x1-xrMovieArea.x0+1;
\r
2136 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2143 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2145 startxy=((1024)*column)+xrMovieArea.x0;
\r
2146 pD=(u8 *)&psxVuw[startxy];
\r
2147 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2149 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2155 dx=xrMovieArea.x1-xrMovieArea.x0;
\r
2156 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2163 unsigned long (*LTCOL)(unsigned long);
\r
2164 unsigned long *ta;
\r
2166 LTCOL=XP8RGBA_0;//TCF[0];
\r
2169 ta=(unsigned long *)texturepart;
\r
2173 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2175 startxy=((1024)*column)+xrMovieArea.x0;
\r
2176 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2177 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2183 dx=xrMovieArea.x1-xrMovieArea.x0+1;
\r
2184 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2191 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2193 startxy=((1024)*column)+xrMovieArea.x0;
\r
2194 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2195 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2200 dx=xrMovieArea.x1-xrMovieArea.x0;
\r
2201 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2207 xrMovieArea.x1+=b_X;xrMovieArea.y1+=b_Y;
\r
2208 DefineTextureMovie();
\r
2209 xrMovieArea.x1-=b_X;xrMovieArea.y1-=b_Y;
\r
2214 /////////////////////////////////////////////////////////////////////////////
\r
2215 /////////////////////////////////////////////////////////////////////////////
\r
2216 /////////////////////////////////////////////////////////////////////////////
\r
2218 GLuint BlackFake15BitTexture(void)
\r
2220 long pmult;short x1,x2,y1,y2;
\r
2222 if(PSXDisplay.InterlacedTest) return 0;
\r
2224 pmult=GlobalTexturePage/16;
\r
2226 x2=gl_ux[6]-gl_ux[7];
\r
2228 y2=gl_ux[4]-gl_ux[5];
\r
2237 x1+=((GlobalTexturePage-16*pmult)<<6);
\r
2239 if( FastCheckAgainstFrontScreen(x1,y1,x2,y2)
\r
2240 || FastCheckAgainstScreen(x1,y1,x2,y2))
\r
2242 if(!gTexFrameName)
\r
2244 glGenTextures(1, &gTexFrameName);
\r
2245 gTexName=gTexFrameName;
\r
2246 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
2248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
2249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
2250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
2251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
2254 unsigned long * ta=(unsigned long *)texturepart;
\r
2255 for(y1=0;y1<=4;y1++)
\r
2256 for(x1=0;x1<=4;x1++)
\r
2259 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
2263 gTexName=gTexFrameName;
\r
2264 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
2269 return (GLuint)gTexName;
\r
2274 /////////////////////////////////////////////////////////////////////////////
\r
2276 BOOL bFakeFrontBuffer=FALSE;
\r
2277 BOOL bIgnoreNextTile =FALSE;
\r
2281 GLuint Fake15BitTexture(void)
\r
2283 long pmult;short x1,x2,y1,y2;int iYAdjust;
\r
2284 float ScaleX,ScaleY;RECT rSrc;
\r
2286 if(iFrameTexType==1) return BlackFake15BitTexture();
\r
2287 if(PSXDisplay.InterlacedTest) return 0;
\r
2289 pmult=GlobalTexturePage/16;
\r
2291 x2=gl_ux[6]-gl_ux[7];
\r
2293 y2=gl_ux[4]-gl_ux[5];
\r
2296 x1+=((GlobalTexturePage-16*pmult)<<6);
\r
2298 if(iFrameTexType==3)
\r
2300 if(iFrameReadType==4) return 0;
\r
2302 if(!FastCheckAgainstFrontScreen(x1,y1,x2,y2) &&
\r
2303 !FastCheckAgainstScreen(x1,y1,x2,y2))
\r
2306 if(bFakeFrontBuffer) bIgnoreNextTile=TRUE;
\r
2307 CheckVRamReadEx(x1,y1,x1+x2,y1+y2);
\r
2311 /////////////////////////
\r
2313 if(FastCheckAgainstFrontScreen(x1,y1,x2,y2))
\r
2315 x1-=PSXDisplay.DisplayPosition.x;
\r
2316 y1-=PSXDisplay.DisplayPosition.y;
\r
2319 if(FastCheckAgainstScreen(x1,y1,x2,y2))
\r
2321 x1-=PreviousPSXDisplay.DisplayPosition.x;
\r
2322 y1-=PreviousPSXDisplay.DisplayPosition.y;
\r
2326 bDrawMultiPass = FALSE;
\r
2328 if(!gTexFrameName)
\r
2332 if(iResX>1280 || iResY>1024) iFTex=2048;
\r
2334 if(iResX>640 || iResY>480) iFTex=1024;
\r
2337 glGenTextures(1, &gTexFrameName);
\r
2338 gTexName=gTexFrameName;
\r
2339 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
2341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
2342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
2343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
2344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
2346 p=(s8 *)malloc(iFTex*iFTex*4);
\r
2347 memset(p,0,iFTex*iFTex*4);
\r
2348 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iFTex, iFTex, 0, GL_RGBA, GL_UNSIGNED_BYTE, p);
\r
2355 gTexName=gTexFrameName;
\r
2356 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
2359 x1+=PreviousPSXDisplay.Range.x0;
\r
2360 y1+=PreviousPSXDisplay.Range.y0;
\r
2362 if(PSXDisplay.DisplayMode.x)
\r
2363 ScaleX=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;
\r
2365 if(PSXDisplay.DisplayMode.y)
\r
2366 ScaleY=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;
\r
2369 rSrc.left =max(x1*ScaleX,0);
\r
2370 rSrc.right =min((x1+x2)*ScaleX+0.99f,iResX-1);
\r
2371 rSrc.top =max(y1*ScaleY,0);
\r
2372 rSrc.bottom=min((y1+y2)*ScaleY+0.99f,iResY-1);
\r
2374 iYAdjust=(y1+y2)-PSXDisplay.DisplayMode.y;
\r
2376 iYAdjust=(int)((float)iYAdjust*ScaleY)+1;
\r
2379 gl_vy[0]=255-gl_vy[0];
\r
2380 gl_vy[1]=255-gl_vy[1];
\r
2381 gl_vy[2]=255-gl_vy[2];
\r
2382 gl_vy[3]=255-gl_vy[3];
\r
2384 y1=min(gl_vy[0],min(gl_vy[1],min(gl_vy[2],gl_vy[3])));
\r
2390 gl_ux[0]-=gl_ux[7];
\r
2391 gl_ux[1]-=gl_ux[7];
\r
2392 gl_ux[2]-=gl_ux[7];
\r
2393 gl_ux[3]-=gl_ux[7];
\r
2395 ScaleX*=256.0f/((float)(iFTex));
\r
2396 ScaleY*=256.0f/((float)(iFTex));
\r
2398 y1=((float)gl_vy[0]*ScaleY); if(y1>255) y1=255;
\r
2400 y1=((float)gl_vy[1]*ScaleY); if(y1>255) y1=255;
\r
2402 y1=((float)gl_vy[2]*ScaleY); if(y1>255) y1=255;
\r
2404 y1=((float)gl_vy[3]*ScaleY); if(y1>255) y1=255;
\r
2407 x1=((float)gl_ux[0]*ScaleX); if(x1>255) x1=255;
\r
2409 x1=((float)gl_ux[1]*ScaleX); if(x1>255) x1=255;
\r
2411 x1=((float)gl_ux[2]*ScaleX); if(x1>255) x1=255;
\r
2413 x1=((float)gl_ux[3]*ScaleX); if(x1>255) x1=255;
\r
2416 x1=rSrc.right-rSrc.left;
\r
2418 if(x1>iFTex) x1=iFTex;
\r
2420 y1=rSrc.bottom-rSrc.top;
\r
2422 if(y1+iYAdjust>iFTex) y1=iFTex-iYAdjust;
\r
2425 glCopyTexSubImage2D( GL_TEXTURE_2D, 0,
\r
2428 rSrc.left+rRatioRect.left,
\r
2429 iResY-rSrc.bottom-rRatioRect.top,
\r
2434 s8 * p=(s8 *)malloc(iFTex*iFTex*4);
\r
2435 memset(p,0,iFTex*iFTex*4);
\r
2436 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, iFTex, iFTex,
\r
2437 GL_RGBA, GL_UNSIGNED_BYTE, p);
\r
2446 sprtW=gl_ux[1]-gl_ux[0];
\r
2447 sprtH=-(gl_vy[0]-gl_vy[2]);
\r
2450 return (GLuint)gTexName;
\r
2453 /////////////////////////////////////////////////////////////////////////////
\r
2454 /////////////////////////////////////////////////////////////////////////////
\r
2455 /////////////////////////////////////////////////////////////////////////////
\r
2457 // load texture part (unpacked)
\r
2459 /////////////////////////////////////////////////////////////////////////////
\r
2460 /////////////////////////////////////////////////////////////////////////////
\r
2461 /////////////////////////////////////////////////////////////////////////////
\r
2463 void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)
\r
2465 unsigned long start,row,column,j,sxh,sxm;
\r
2466 unsigned int palstart;
\r
2467 unsigned long *px,*pa,*ta;
\r
2469 unsigned short *wSRCPtr;
\r
2470 unsigned long LineOffset;
\r
2471 unsigned long x2a,xalign=0;
\r
2472 unsigned long x1=gl_ux[7];
\r
2473 unsigned long x2=gl_ux[6];
\r
2474 unsigned long y1=gl_ux[5];
\r
2475 unsigned long y2=gl_ux[4];
\r
2476 unsigned long dx=x2-x1+1;
\r
2477 unsigned long dy=y2-y1+1;
\r
2478 int pmult=pageid/16;
\r
2479 unsigned long (*LTCOL)(unsigned long);
\r
2480 unsigned int a,r,g,b,cnt,h;
\r
2481 unsigned long scol[8];
\r
2483 LTCOL=TCF[DrawSemiTrans];
\r
2485 pa=px=(unsigned long *)ubPaletteBuffer;
\r
2486 ta=(unsigned long *)texturepart;
\r
2487 palstart=cx+(cy<<10);
\r
2491 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}
\r
2492 if(XTexS) {ta+=1;xalign=2;}
\r
2496 //--------------------------------------------------//
\r
2497 // 4bit texture load ..
\r
2501 unsigned int TXV,TXU,n_xi,n_yi;
\r
2503 wSRCPtr=psxVuw+palstart;
\r
2507 *px =LTCOL(*wSRCPtr);
\r
2508 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2509 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2510 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2511 row--;px+=4;wSRCPtr+=4;
\r
2515 for(TXV=y1;TXV<=y2;TXV++)
\r
2517 for(TXU=x1;TXU<=x2;TXU++)
\r
2519 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
2520 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
2522 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
2529 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2530 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
2532 wSRCPtr=psxVuw+palstart;
\r
2536 *px =LTCOL(*wSRCPtr);
\r
2537 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2538 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2539 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2540 row--;px+=4;wSRCPtr+=4;
\r
2544 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;
\r
2545 sxm=x1&1;sxh=x1>>1;
\r
2546 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;
\r
2547 for(column=y1;column<=y2;column++)
\r
2549 cSRCPtr = psxVub + start + (column<<11) + sxh;
\r
2551 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
2553 for(row=j;row<x2a;row+=2)
\r
2555 *ta =*(pa+(*cSRCPtr & 0xF));
\r
2556 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2562 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
\r
2563 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2570 //--------------------------------------------------//
\r
2571 // 8bit texture load ..
\r
2575 unsigned int TXV,TXU,n_xi,n_yi;
\r
2577 wSRCPtr=psxVuw+palstart;
\r
2581 *px =LTCOL(*wSRCPtr);
\r
2582 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2583 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2584 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2585 row--;px+=4;wSRCPtr+=4;
\r
2589 for(TXV=y1;TXV<=y2;TXV++)
\r
2591 for(TXU=x1;TXU<=x2;TXU++)
\r
2593 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
2594 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
2596 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
2604 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2606 cSRCPtr = psxVub + start + (y1<<11) + x1;
\r
2607 LineOffset = 2048 - dx;
\r
2611 wSRCPtr=psxVuw+palstart;
\r
2615 *px =LTCOL(*wSRCPtr);
\r
2616 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2617 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2618 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2619 row--;px+=4;wSRCPtr+=4;
\r
2626 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);
\r
2628 cSRCPtr+=LineOffset;column--;
\r
2634 wSRCPtr=psxVuw+palstart;
\r
2639 do {*ta++=LTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);
\r
2641 cSRCPtr+=LineOffset;column--;
\r
2647 //--------------------------------------------------//
\r
2648 // 16bit texture load ..
\r
2650 start=((pageid-16*pmult)<<6)+262144*pmult;
\r
2652 wSRCPtr = psxVuw + start + (y1<<10) + x1;
\r
2653 LineOffset = 1024 - dx;
\r
2658 do {*ta++=LTCOL(*wSRCPtr++);row--;} while(row);
\r
2660 wSRCPtr+=LineOffset;column--;
\r
2665 //--------------------------------------------------//
\r
2666 // others are not possible !
\r
2673 ta=(unsigned long *)texturepart;
\r
2674 pa=(unsigned long *)texturepart+x2a;
\r
2675 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
2676 pa=(unsigned long *)texturepart+dy*x2a;
\r
2678 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
2685 ta=(unsigned long *)texturepart;
\r
2687 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
2688 pa=(unsigned long *)texturepart+dx;
\r
2690 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
2695 DXTexS=dx;DYTexS=dy;
\r
2697 if(!iFilterType) {DefineSubTextureSort();return;}
\r
2698 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}
\r
2699 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)
\r
2700 {DefineSubTextureSort();return;}
\r
2702 ta=(unsigned long *)texturepart;
\r
2709 for(column=0;column<dy;column++)
\r
2711 for(row=0;row<dx;row++)
\r
2713 if(*ta==0x50000000)
\r
2717 if( column && *(ta-dx) !=0x50000000 && *(ta-dx)>>24!=1) scol[cnt++]=*(ta-dx);
\r
2718 if(row && *(ta-1) !=0x50000000 && *(ta-1)>>24!=1) scol[cnt++]=*(ta-1);
\r
2719 if(row!=x1 && *(ta+1) !=0x50000000 && *(ta+1)>>24!=1) scol[cnt++]=*(ta+1);
\r
2720 if( column!=y1 && *(ta+dx) !=0x50000000 && *(ta+dx)>>24!=1) scol[cnt++]=*(ta+dx);
\r
2722 if(row && column && *(ta-dx-1)!=0x50000000 && *(ta-dx-1)>>24!=1) scol[cnt++]=*(ta-dx-1);
\r
2723 if(row!=x1 && column && *(ta-dx+1)!=0x50000000 && *(ta-dx+1)>>24!=1) scol[cnt++]=*(ta-dx+1);
\r
2724 if(row && column!=y1 && *(ta+dx-1)!=0x50000000 && *(ta+dx-1)>>24!=1) scol[cnt++]=*(ta+dx-1);
\r
2725 if(row!=x1 && column!=y1 && *(ta+dx+1)!=0x50000000 && *(ta+dx+1)>>24!=1) scol[cnt++]=*(ta+dx+1);
\r
2730 for(h=0;h<cnt;h++)
\r
2733 r+=(scol[h]>>16)&0xff;
\r
2734 g+=(scol[h]>>8)&0xff;
\r
2737 r/=cnt;b/=cnt;g/=cnt;
\r
2739 *ta=(r<<16)|(g<<8)|b;
\r
2740 if(a) *ta|=0x50000000;
\r
2741 else *ta|=0x01000000;
\r
2750 for(column=0;column<dy;column++)
\r
2752 for(row=0;row<dx;row++)
\r
2754 if(*ta==0x00000000)
\r
2758 if(row!=x1 && *(ta+1) !=0x00000000) scol[cnt++]=*(ta+1);
\r
2759 if( column!=y1 && *(ta+dx) !=0x00000000) scol[cnt++]=*(ta+dx);
\r
2764 for(h=0;h<cnt;h++)
\r
2766 r+=(scol[h]>>16)&0xff;
\r
2767 g+=(scol[h]>>8)&0xff;
\r
2770 r/=cnt;b/=cnt;g/=cnt;
\r
2771 *ta=(r<<16)|(g<<8)|b;
\r
2778 DefineSubTextureSort();
\r
2781 /////////////////////////////////////////////////////////////////////////////
\r
2782 /////////////////////////////////////////////////////////////////////////////
\r
2783 /////////////////////////////////////////////////////////////////////////////
\r
2785 // load texture part (packed)
\r
2787 /////////////////////////////////////////////////////////////////////////////
\r
2788 /////////////////////////////////////////////////////////////////////////////
\r
2789 /////////////////////////////////////////////////////////////////////////////
\r
2791 void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
\r
2793 unsigned long start,row,column,j,sxh,sxm;
\r
2794 unsigned int palstart;
\r
2795 unsigned short *px,*pa,*ta;
\r
2797 unsigned short *wSRCPtr;
\r
2798 unsigned long LineOffset;
\r
2799 unsigned long x2a,xalign=0;
\r
2800 unsigned long x1=gl_ux[7];
\r
2801 unsigned long x2=gl_ux[6];
\r
2802 unsigned long y1=gl_ux[5];
\r
2803 unsigned long y2=gl_ux[4];
\r
2804 unsigned long dx=x2-x1+1;
\r
2805 unsigned long dy=y2-y1+1;
\r
2806 int pmult=pageid/16;
\r
2807 unsigned short (*LPTCOL)(unsigned short);
\r
2808 unsigned int a,r,g,b,cnt,h;
\r
2809 unsigned short scol[8];
\r
2811 LPTCOL=PTCF[DrawSemiTrans];
\r
2813 pa=px=(unsigned short *)ubPaletteBuffer;
\r
2814 ta=(unsigned short *)texturepart;
\r
2815 palstart=cx+(cy<<10);
\r
2819 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}
\r
2820 if(XTexS) {ta+=1;xalign=2;}
\r
2824 //--------------------------------------------------//
\r
2825 // 4bit texture load ..
\r
2829 unsigned int TXV,TXU,n_xi,n_yi;
\r
2831 wSRCPtr=psxVuw+palstart;
\r
2834 *px =LPTCOL(*wSRCPtr);
\r
2835 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2836 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2837 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2838 row--;px+=4;wSRCPtr+=4;
\r
2842 for(TXV=y1;TXV<=y2;TXV++)
\r
2844 for(TXU=x1;TXU<=x2;TXU++)
\r
2846 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
2847 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
2849 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
2856 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2858 wSRCPtr=psxVuw+palstart;
\r
2861 *px =LPTCOL(*wSRCPtr);
\r
2862 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2863 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2864 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2865 row--;px+=4;wSRCPtr+=4;
\r
2869 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;
\r
2870 sxm=x1&1;sxh=x1>>1;
\r
2871 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;
\r
2873 for(column=y1;column<=y2;column++)
\r
2875 cSRCPtr = psxVub + start + (column<<11) + sxh;
\r
2877 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
2879 for(row=j;row<x2a;row+=2)
\r
2881 *ta =*(pa+(*cSRCPtr & 0xF));
\r
2882 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2888 *ta++=*(pa+(*cSRCPtr & 0xF));row++;
\r
2889 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2895 //--------------------------------------------------//
\r
2896 // 8bit texture load ..
\r
2900 unsigned int TXV,TXU,n_xi,n_yi;
\r
2902 wSRCPtr=psxVuw+palstart;
\r
2906 *px =LPTCOL(*wSRCPtr);
\r
2907 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2908 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2909 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2910 row--;px+=4;wSRCPtr+=4;
\r
2914 for(TXV=y1;TXV<=y2;TXV++)
\r
2916 for(TXU=x1;TXU<=x2;TXU++)
\r
2918 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
2919 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
2921 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
2929 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2931 cSRCPtr = psxVub + start + (y1<<11) + x1;
\r
2932 LineOffset = 2048 - dx;
\r
2934 if(dy*dx>384) // more pix? use lut
\r
2936 wSRCPtr=psxVuw+palstart;
\r
2940 *px =LPTCOL(*wSRCPtr);
\r
2941 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2942 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2943 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2944 row--;px+=4;wSRCPtr+=4;
\r
2951 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);
\r
2955 cSRCPtr+=LineOffset;column--;
\r
2959 else // small area? no lut
\r
2961 wSRCPtr=psxVuw+palstart;
\r
2966 do {*ta++=LPTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);
\r
2970 cSRCPtr+=LineOffset;column--;
\r
2975 //--------------------------------------------------//
\r
2976 // 16bit texture load ..
\r
2978 start=((pageid-16*pmult)<<6)+262144*pmult;
\r
2980 wSRCPtr = psxVuw + start + (y1<<10) + x1;
\r
2981 LineOffset = 1024 - dx;
\r
2986 do {*ta++=LPTCOL(*wSRCPtr++);row--;} while(row);
\r
2990 wSRCPtr+=LineOffset;column--;
\r
2994 //--------------------------------------------------//
\r
2995 // others are not possible !
\r
2998 ////////////////////////////////////////////////////////
\r
3004 ta=(unsigned short *)texturepart;
\r
3005 pa=(unsigned short *)texturepart+x2a;
\r
3006 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
3008 pa=(unsigned short *)texturepart+dy*x2a;
\r
3010 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
3018 ta=(unsigned short *)texturepart;
\r
3020 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
3022 pa=(unsigned short *)texturepart+dx;
\r
3024 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
3030 DXTexS=dx;DYTexS=dy;
\r
3032 if(!iFilterType) {DefineSubTextureSort();return;}
\r
3033 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}
\r
3034 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)
\r
3035 {DefineSubTextureSort();return;}
\r
3037 ta=(unsigned short *)texturepart;
\r
3042 for(column=0;column<dy;column++)
\r
3044 for(row=0;row<dx;row++)
\r
3050 if( column && *(ta-dx) &1) scol[cnt++]=*(ta-dx);
\r
3051 if(row && *(ta-1) &1) scol[cnt++]=*(ta-1);
\r
3052 if(row!=x1 && *(ta+1) &1) scol[cnt++]=*(ta+1);
\r
3053 if( column!=y1 && *(ta+dx) &1) scol[cnt++]=*(ta+dx);
\r
3055 if(row && column && *(ta-dx-1)&1) scol[cnt++]=*(ta-dx-1);
\r
3056 if(row!=x1 && column && *(ta-dx+1)&1) scol[cnt++]=*(ta-dx+1);
\r
3057 if(row && column!=y1 && *(ta+dx-1)&1) scol[cnt++]=*(ta+dx-1);
\r
3058 if(row!=x1 && column!=y1 && *(ta+dx+1)&1) scol[cnt++]=*(ta+dx+1);
\r
3063 for(h=0;h<cnt;h++)
\r
3066 g+=(scol[h]>>6)&0x1f;
\r
3067 b+=(scol[h]>>1)&0x1f;
\r
3069 r/=cnt;b/=cnt;g/=cnt;
\r
3070 *ta=(r<<11)|(g<<6)|(b<<1);
\r
3078 DefineSubTextureSort();
\r
3081 /////////////////////////////////////////////////////////////////////////////
\r
3083 /////////////////////////////////////////////////////////////////////////////
\r
3084 /////////////////////////////////////////////////////////////////////////////
\r
3085 /////////////////////////////////////////////////////////////////////////////
\r
3087 // hires texture funcs
\r
3089 /////////////////////////////////////////////////////////////////////////////
\r
3090 /////////////////////////////////////////////////////////////////////////////
\r
3091 /////////////////////////////////////////////////////////////////////////////
\r
3094 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
\r
3096 ////////////////////////////////////////////////////////////////////////
\r
3098 #define colorMask8 0x00FEFEFE
\r
3099 #define lowPixelMask8 0x00010101
\r
3100 #define qcolorMask8 0x00FCFCFC
\r
3101 #define qlowpixelMask8 0x00030303
\r
3104 #define INTERPOLATE8_02(A, B) (((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8))|((((A&0xFF000000)==0x03000000)?0x03000000:(((B&0xFF000000)==0x03000000)?0x03000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))
\r
3106 #define Q_INTERPOLATE8_02(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x03000000)?0x03000000:(((B&0xFF000000)==0x03000000)?0x03000000:(((C&0xFF000000)==0x03000000)?0x03000000:(((D&0xFF000000)==0x03000000)?0x03000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))
\r
3108 #define INTERPOLATE8(A, B) (((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))
\r
3110 #define Q_INTERPOLATE8(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((C&0xFF000000)==0x50000000)?0x50000000:(((D&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))
\r
3112 void Super2xSaI_ex8_Ex(u8 *srcPtr, DWORD srcPitch,
\r
3113 u8 *dstBitmap, int width, int height)
\r
3115 DWORD dstPitch = srcPitch * 2;
\r
3119 int width2 = width*2;
\r
3120 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
\r
3121 DWORD color4, color5, color6;
\r
3122 DWORD color1, color2, color3;
\r
3123 DWORD colorA0, colorA1, colorA2, colorA3,
\r
3124 colorB0, colorB1, colorB2, colorB3,
\r
3126 DWORD product1a, product1b,
\r
3127 product2a, product2b;
\r
3132 for (; height; height-=1)
\r
3134 bP = (DWORD *)srcPtr;
\r
3135 dP = (DWORD *)(dstBitmap + line*dstPitch);
\r
3136 for (finish = width; finish; finish -= 1 )
\r
3138 //--------------------------------------- B1 B2
\r
3142 if(finish==width) iXA=0;
\r
3144 if(finish>4) {iXB=1;iXC=2;}
\r
3146 if(finish>3) {iXB=1;iXC=1;}
\r
3147 else {iXB=0;iXC=0;}
\r
3148 if(line==0) iYA=0;
\r
3150 if(height>4) {iYB=width;iYC=width2;}
\r
3152 if(height>3) {iYB=width;iYC=width;}
\r
3153 else {iYB=0;iYC=0;}
\r
3156 colorB0 = *(bP- iYA - iXA);
\r
3157 colorB1 = *(bP- iYA);
\r
3158 colorB2 = *(bP- iYA + iXB);
\r
3159 colorB3 = *(bP- iYA + iXC);
\r
3161 color4 = *(bP - iXA);
\r
3163 color6 = *(bP + iXB);
\r
3164 colorS2 = *(bP + iXC);
\r
3166 color1 = *(bP + iYB - iXA);
\r
3167 color2 = *(bP + iYB);
\r
3168 color3 = *(bP + iYB + iXB);
\r
3169 colorS1= *(bP + iYB + iXC);
\r
3171 colorA0 = *(bP + iYC - iXA);
\r
3172 colorA1 = *(bP + iYC);
\r
3173 colorA2 = *(bP + iYC + iXB);
\r
3174 colorA3 = *(bP + iYC + iXC);
\r
3176 //--------------------------------------
\r
3177 if (color2 == color6 && color5 != color3)
\r
3179 product2b = product1b = color2;
\r
3182 if (color5 == color3 && color2 != color6)
\r
3184 product2b = product1b = color5;
\r
3187 if (color5 == color3 && color2 == color6)
\r
3189 register int r = 0;
\r
3191 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
\r
3192 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
\r
3193 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
\r
3194 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
\r
3197 product2b = product1b = color6;
\r
3200 product2b = product1b = color5;
\r
3203 product2b = product1b = INTERPOLATE8_02(color5, color6);
\r
3208 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
\r
3209 product2b = Q_INTERPOLATE8_02 (color3, color3, color3, color2);
\r
3211 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
\r
3212 product2b = Q_INTERPOLATE8_02 (color2, color2, color2, color3);
\r
3214 product2b = INTERPOLATE8_02 (color2, color3);
\r
3216 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
\r
3217 product1b = Q_INTERPOLATE8_02 (color6, color6, color6, color5);
\r
3219 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
\r
3220 product1b = Q_INTERPOLATE8_02 (color6, color5, color5, color5);
\r
3222 product1b = INTERPOLATE8_02 (color5, color6);
\r
3225 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
\r
3226 product2a = INTERPOLATE8_02(color2, color5);
\r
3228 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
\r
3229 product2a = INTERPOLATE8_02(color2, color5);
\r
3231 product2a = color2;
\r
3233 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
\r
3234 product1a = INTERPOLATE8_02(color2, color5);
\r
3236 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
\r
3237 product1a = INTERPOLATE8_02(color2, color5);
\r
3239 product1a = color5;
\r
3242 *(dP+1)=product1b;
\r
3243 *(dP+(width2))=product2a;
\r
3244 *(dP+1+(width2))=product2b;
\r
3248 }//end of for ( finish= width etc..)
\r
3251 srcPtr += srcPitch;
\r
3252 }; //endof: for (; height; height--)
\r
3257 void Super2xSaI_ex8(u8 *srcPtr, DWORD srcPitch,
\r
3258 u8 *dstBitmap, int width, int height)
\r
3260 DWORD dstPitch = srcPitch * 2;
\r
3264 int width2 = width*2;
\r
3265 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
\r
3266 DWORD color4, color5, color6;
\r
3267 DWORD color1, color2, color3;
\r
3268 DWORD colorA0, colorA1, colorA2, colorA3,
\r
3269 colorB0, colorB1, colorB2, colorB3,
\r
3271 DWORD product1a, product1b,
\r
3272 product2a, product2b;
\r
3277 for (; height; height-=1)
\r
3279 bP = (DWORD *)srcPtr;
\r
3280 dP = (DWORD *)(dstBitmap + line*dstPitch);
\r
3281 for (finish = width; finish; finish -= 1 )
\r
3283 //--------------------------------------- B1 B2
\r
3287 if(finish==width) iXA=0;
\r
3289 if(finish>4) {iXB=1;iXC=2;}
\r
3291 if(finish>3) {iXB=1;iXC=1;}
\r
3292 else {iXB=0;iXC=0;}
\r
3293 if(line==0) iYA=0;
\r
3295 if(height>4) {iYB=width;iYC=width2;}
\r
3297 if(height>3) {iYB=width;iYC=width;}
\r
3298 else {iYB=0;iYC=0;}
\r
3301 colorB0 = *(bP- iYA - iXA);
\r
3302 colorB1 = *(bP- iYA);
\r
3303 colorB2 = *(bP- iYA + iXB);
\r
3304 colorB3 = *(bP- iYA + iXC);
\r
3306 color4 = *(bP - iXA);
\r
3308 color6 = *(bP + iXB);
\r
3309 colorS2 = *(bP + iXC);
\r
3311 color1 = *(bP + iYB - iXA);
\r
3312 color2 = *(bP + iYB);
\r
3313 color3 = *(bP + iYB + iXB);
\r
3314 colorS1= *(bP + iYB + iXC);
\r
3316 colorA0 = *(bP + iYC - iXA);
\r
3317 colorA1 = *(bP + iYC);
\r
3318 colorA2 = *(bP + iYC + iXB);
\r
3319 colorA3 = *(bP + iYC + iXC);
\r
3321 //--------------------------------------
\r
3322 if (color2 == color6 && color5 != color3)
\r
3324 product2b = product1b = color2;
\r
3327 if (color5 == color3 && color2 != color6)
\r
3329 product2b = product1b = color5;
\r
3332 if (color5 == color3 && color2 == color6)
\r
3334 register int r = 0;
\r
3336 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
\r
3337 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
\r
3338 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
\r
3339 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
\r
3342 product2b = product1b = color6;
\r
3345 product2b = product1b = color5;
\r
3348 product2b = product1b = INTERPOLATE8(color5, color6);
\r
3353 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
\r
3354 product2b = Q_INTERPOLATE8 (color3, color3, color3, color2);
\r
3356 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
\r
3357 product2b = Q_INTERPOLATE8 (color2, color2, color2, color3);
\r
3359 product2b = INTERPOLATE8 (color2, color3);
\r
3361 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
\r
3362 product1b = Q_INTERPOLATE8 (color6, color6, color6, color5);
\r
3364 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
\r
3365 product1b = Q_INTERPOLATE8 (color6, color5, color5, color5);
\r
3367 product1b = INTERPOLATE8 (color5, color6);
\r
3370 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
\r
3371 product2a = INTERPOLATE8(color2, color5);
\r
3373 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
\r
3374 product2a = INTERPOLATE8(color2, color5);
\r
3376 product2a = color2;
\r
3378 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
\r
3379 product1a = INTERPOLATE8(color2, color5);
\r
3381 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
\r
3382 product1a = INTERPOLATE8(color2, color5);
\r
3384 product1a = color5;
\r
3387 *(dP+1)=product1b;
\r
3388 *(dP+(width2))=product2a;
\r
3389 *(dP+1+(width2))=product2b;
\r
3393 }//end of for ( finish= width etc..)
\r
3396 srcPtr += srcPitch;
\r
3397 }; //endof: for (; height; height--)
\r
3400 /////////////////////////////////////////////////////////////////////////////
\r
3402 #define colorMask4 0x0000EEE0
\r
3403 #define lowPixelMask4 0x00001110
\r
3404 #define qcolorMask4 0x0000CCC0
\r
3405 #define qlowpixelMask4 0x00003330
\r
3407 #define INTERPOLATE4(A, B) ((((A & colorMask4) >> 1) + ((B & colorMask4) >> 1) + (A & B & lowPixelMask4))|((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))
\r
3409 #define Q_INTERPOLATE4(A, B, C, D) ((((A & qcolorMask4) >> 2) + ((B & qcolorMask4) >> 2) + ((C & qcolorMask4) >> 2) + ((D & qcolorMask4) >> 2) + ((((A & qlowpixelMask4) + (B & qlowpixelMask4) + (C & qlowpixelMask4) + (D & qlowpixelMask4)) >> 2) & qlowpixelMask4))| ((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((C&0x0000000F)==0x00000006)?0x00000006:(((D&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:(((C&0x0000000F)==0x00000000)?0x00000000:(((D&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))))))
\r
3412 #define colorMask5 0x0000F7BC
\r
3413 #define lowPixelMask5 0x00000842
\r
3414 #define qcolorMask5 0x0000E738
\r
3415 #define qlowpixelMask5 0x000018C6
\r
3417 #define INTERPOLATE5(A, B) ((((A & colorMask5) >> 1) + ((B & colorMask5) >> 1) + (A & B & lowPixelMask5))|((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:0x00000001))))
\r
3419 #define Q_INTERPOLATE5(A, B, C, D) ((((A & qcolorMask5) >> 2) + ((B & qcolorMask5) >> 2) + ((C & qcolorMask5) >> 2) + ((D & qcolorMask5) >> 2) + ((((A & qlowpixelMask5) + (B & qlowpixelMask5) + (C & qlowpixelMask5) + (D & qlowpixelMask5)) >> 2) & qlowpixelMask5))| ((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:(((C&0x00000001)==0x00000000)?0x00000000:(((D&0x00000001)==0x00000000)?0x00000000:0x00000001))))))
\r
3420 /////////////////////////////////////////////////////////////////////////////
\r
3421 /////////////////////////////////////////////////////////////////////////////
\r
3422 /////////////////////////////////////////////////////////////////////////////
\r
3424 // ogl texture defines
\r
3426 /////////////////////////////////////////////////////////////////////////////
\r
3427 /////////////////////////////////////////////////////////////////////////////
\r
3428 /////////////////////////////////////////////////////////////////////////////
\r
3430 void DefineSubTextureSortHiRes(void)
\r
3436 glGenTextures(1, &gTexName);
\r
3437 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
3439 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
3440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
3444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
\r
3445 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
\r
3449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
3450 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
3452 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturebuffer);
\r
3454 else glBindTexture(GL_TEXTURE_2D, gTexName);
\r
3456 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS<<1, YTexS<<1,
\r
3457 DXTexS<<1, DYTexS<<1,
\r
3458 GL_RGBA, GL_UNSIGNED_BYTE, texturebuffer);
\r
3461 /////////////////////////////////////////////////////////////////////////////
\r
3463 void DefineSubTextureSort(void)
\r
3468 glGenTextures(1, &gTexName);
\r
3469 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
3471 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
3472 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
3476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
\r
3477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
\r
3481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
3482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
3484 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
3486 else glBindTexture(GL_TEXTURE_2D, gTexName);
\r
3488 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS, YTexS,
\r
3490 GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
3493 /////////////////////////////////////////////////////////////////////////////
\r
3495 /////////////////////////////////////////////////////////////////////////////
\r
3496 /////////////////////////////////////////////////////////////////////////////
\r
3497 /////////////////////////////////////////////////////////////////////////////
\r
3499 // texture cache garbage collection
\r
3501 /////////////////////////////////////////////////////////////////////////////
\r
3502 /////////////////////////////////////////////////////////////////////////////
\r
3503 /////////////////////////////////////////////////////////////////////////////
\r
3505 void DoTexGarbageCollection(void)
\r
3507 static unsigned short LRUCleaned=0;
\r
3508 unsigned short iC,iC1,iC2;
\r
3509 int i,j,iMax;textureSubCacheEntryS * tsb;
\r
3511 iC=4;//=iSortTexCnt/2,
\r
3512 LRUCleaned+=iC; // we clean different textures each time
\r
3513 if((LRUCleaned+iC)>=iSortTexCnt) LRUCleaned=0; // wrap? wrap!
\r
3514 iC1=LRUCleaned; // range of textures to clean
\r
3515 iC2=LRUCleaned+iC;
\r
3517 for(iC=iC1;iC<iC2;iC++) // make some textures available
\r
3519 pxSsubtexLeft[iC]->l=0;
\r
3522 for(i=0;i<3;i++) // remove all references to that textures
\r
3523 for(j=0;j<MAXTPAGES;j++)
\r
3524 for(iC=0;iC<4;iC++) // loop all texture rect info areas
\r
3526 tsb=pscSubtexStore[i][j]+(iC*SOFFB);
\r
3532 if(tsb->cTexID>=iC1 && tsb->cTexID<iC2) // info uses the cleaned textures? remove info
\r
3538 usLRUTexPage=LRUCleaned;
\r
3541 /////////////////////////////////////////////////////////////////////////////
\r
3542 /////////////////////////////////////////////////////////////////////////////
\r
3543 /////////////////////////////////////////////////////////////////////////////
\r
3545 // search cache for existing (already used) parts
\r
3547 /////////////////////////////////////////////////////////////////////////////
\r
3548 /////////////////////////////////////////////////////////////////////////////
\r
3549 /////////////////////////////////////////////////////////////////////////////
\r
3551 u8 * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache)
\r
3553 textureSubCacheEntryS * tsx, * tsb, *tsg;//, *tse=NULL;
\r
3554 int i,iMax;EXLong npos;
\r
3556 int iC,j,k;unsigned long rx,ry,mx,my;
\r
3557 EXLong * ul=0, * uls;
\r
3561 npos.l=*((unsigned long *)&gl_ux[4]);
\r
3563 //--------------------------------------------------------------//
\r
3564 // find matching texturepart first... speed up...
\r
3565 //--------------------------------------------------------------//
\r
3567 tsg=pscSubtexStore[TextureMode][GlobalTexturePage];
\r
3568 tsg+=((GivenClutId&CLUTCHK)>>CLUTSHIFT)*SOFFB;
\r
3577 if(GivenClutId==tsb->ClutID &&
\r
3578 (INCHECK(tsb->pos,npos)))
\r
3581 cx=tsb->pos.c[3]-tsb->posTX;
\r
3582 cy=tsb->pos.c[1]-tsb->posTY;
\r
3593 ubOpaqueDraw=tsb->Opaque;
\r
3594 *pCache=tsb->cTexID;
\r
3603 //----------------------------------------------------//
\r
3607 rx=(int)gl_ux[6]-(int)gl_ux[7];
\r
3608 ry=(int)gl_ux[4]-(int)gl_ux[5];
\r
3610 tsx=NULL;tsb=tsg+1;
\r
3611 for(i=0;i<iMax;i++,tsb++)
\r
3613 if(!tsb->ClutID) {tsx=tsb;break;}
\r
3619 if(iMax>=SOFFB-2)
\r
3621 if(iTexGarbageCollection) // gc mode?
\r
3625 dwTexPageComp|=(1<<GlobalTexturePage);
\r
3633 for(i=0;i<iMax;i++,tsb++) // 1. search other slots with same cluts, and unite the area
\r
3634 if(GivenClutId==tsb->ClutID)
\r
3636 if(!tsx) {tsx=tsb;rfree.l=npos.l;} //
\r
3637 else tsb->ClutID=0;
\r
3638 rfree.c[3]=min(rfree.c[3],tsb->pos.c[3]);
\r
3639 rfree.c[2]=max(rfree.c[2],tsb->pos.c[2]);
\r
3640 rfree.c[1]=min(rfree.c[1],tsb->pos.c[1]);
\r
3641 rfree.c[0]=max(rfree.c[0],tsb->pos.c[0]);
\r
3645 if(tsx) // 3. if one or more found, create a new rect with bigger size
\r
3647 *((unsigned long *)&gl_ux[4])=npos.l=rfree.l;
\r
3648 rx=(int)rfree.c[2]-(int)rfree.c[3];
\r
3649 ry=(int)rfree.c[0]-(int)rfree.c[1];
\r
3650 DoTexGarbageCollection();
\r
3662 //----------------------------------------------------//
\r
3663 // now get a free texture space
\r
3664 //----------------------------------------------------//
\r
3666 if(iTexGarbageCollection) usLRUTexPage=0;
\r
3670 rx+=3;if(rx>255) {cXAdj=0;rx=255;}
\r
3671 ry+=3;if(ry>255) {cYAdj=0;ry=255;}
\r
3675 for(k=0;k<iSortTexCnt;k++)
\r
3677 uls=pxSsubtexLeft[iC];
\r
3678 iMax=uls->l;ul=uls+1;
\r
3680 //--------------------------------------------------//
\r
3687 if(rx>252 && ry>252)
\r
3688 {uls->l=1;ul->l=0xffffffff;ul=0;goto ENDLOOP;}
\r
3712 //--------------------------------------------------//
\r
3713 for(i=0;i<iMax;i++,ul++)
\r
3715 if(ul->l!=0xffffffff &&
\r
3722 if(rx<mx && ry<my)
\r
3728 for(ul=uls+1,j=0;j<iMax;j++,ul++)
\r
3729 if(ul->l==0xffffffff) break;
\r
3733 if(j==iMax) uls->l=uls->l+1;
\r
3735 ul->c[3]=rfree.c[3];
\r
3736 ul->c[2]=rfree.c[2];
\r
3737 ul->c[1]=rfree.c[1]+ry;
\r
3738 ul->c[0]=rfree.c[0]-ry;
\r
3760 //--------------------------------------------------//
\r
3762 iC++; if(iC>=iSortTexCnt) iC=0;
\r
3765 //----------------------------------------------------//
\r
3766 // check, if free space got
\r
3767 //----------------------------------------------------//
\r
3772 //////////////////////////////////////////////////////
\r
3777 for(i=0;i<3;i++) // cleaning up
\r
3778 for(j=0;j<MAXTPAGES;j++)
\r
3780 tsb=pscSubtexStore[i][j];
\r
3781 (tsb+SOFFA)->pos.l=0;
\r
3782 (tsb+SOFFB)->pos.l=0;
\r
3783 (tsb+SOFFC)->pos.l=0;
\r
3784 (tsb+SOFFD)->pos.l=0;
\r
3786 for(i=0;i<iSortTexCnt;i++)
\r
3787 {ul=pxSsubtexLeft[i];ul->l=0;}
\r
3791 //////////////////////////////////////////////////////
\r
3793 uls=pxSsubtexLeft[usLRUTexPage];
\r
3794 uls->l=0;ul=uls+1;
\r
3797 if(rx>252 && ry>252)
\r
3798 {uls->l=1;ul->l=0xffffffff;}
\r
3819 tsg->pos.l=1;tsx=tsg+1;
\r
3822 rfree.c[3]+=cXAdj;
\r
3823 rfree.c[1]+=cYAdj;
\r
3825 tsx->cTexID =*pCache=iC;
\r
3827 tsx->ClutID = GivenClutId;
\r
3828 tsx->posTX = rfree.c[3];
\r
3829 tsx->posTY = rfree.c[1];
\r
3831 cx=gl_ux[7]-rfree.c[3];
\r
3832 cy=gl_ux[5]-rfree.c[1];
\r
3846 return &tsx->Opaque;
\r
3849 /////////////////////////////////////////////////////////////////////////////
\r
3850 /////////////////////////////////////////////////////////////////////////////
\r
3851 /////////////////////////////////////////////////////////////////////////////
\r
3853 // search cache for free place (on compress)
\r
3855 /////////////////////////////////////////////////////////////////////////////
\r
3856 /////////////////////////////////////////////////////////////////////////////
\r
3857 /////////////////////////////////////////////////////////////////////////////
\r
3859 BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)
\r
3861 int i,j,k,iMax,iC;unsigned long rx,ry,mx,my;
\r
3862 EXLong * ul=0, * uls, rfree;
\r
3863 u8 cXAdj=1,cYAdj=1;
\r
3865 rx=(int)tsx->pos.c[2]-(int)tsx->pos.c[3];
\r
3866 ry=(int)tsx->pos.c[0]-(int)tsx->pos.c[1];
\r
3868 rx+=3;if(rx>255) {cXAdj=0;rx=255;}
\r
3869 ry+=3;if(ry>255) {cYAdj=0;ry=255;}
\r
3873 for(k=0;k<iSortTexCnt;k++)
\r
3875 uls=pxSsubtexLeft[iC];
\r
3876 iMax=uls->l;ul=uls+1;
\r
3878 //--------------------------------------------------//
\r
3885 if(rx>252 && ry>252)
\r
3886 {uls->l=1;ul->l=0xffffffff;ul=0;goto TENDLOOP;}
\r
3910 //--------------------------------------------------//
\r
3911 for(i=0;i<iMax;i++,ul++)
\r
3913 if(ul->l!=0xffffffff &&
\r
3921 if(rx<mx && ry<my)
\r
3927 for(ul=uls+1,j=0;j<iMax;j++,ul++)
\r
3928 if(ul->l==0xffffffff) break;
\r
3932 if(j==iMax) uls->l=uls->l+1;
\r
3934 ul->c[3]=rfree.c[3];
\r
3935 ul->c[2]=rfree.c[2];
\r
3936 ul->c[1]=rfree.c[1]+ry;
\r
3937 ul->c[0]=rfree.c[0]-ry;
\r
3959 //--------------------------------------------------//
\r
3961 iC++; if(iC>=iSortTexCnt) iC=0;
\r
3964 //----------------------------------------------------//
\r
3965 // check, if free space got
\r
3966 //----------------------------------------------------//
\r
3969 if(ul) return FALSE;
\r
3971 rfree.c[3]+=cXAdj;
\r
3972 rfree.c[1]+=cYAdj;
\r
3975 tsx->posTX = rfree.c[3];
\r
3976 tsx->posTY = rfree.c[1];
\r
3984 /////////////////////////////////////////////////////////////////////////////
\r
3985 /////////////////////////////////////////////////////////////////////////////
\r
3986 /////////////////////////////////////////////////////////////////////////////
\r
3988 // compress texture cache (to make place for new texture part, if needed)
\r
3990 /////////////////////////////////////////////////////////////////////////////
\r
3991 /////////////////////////////////////////////////////////////////////////////
\r
3992 /////////////////////////////////////////////////////////////////////////////
\r
3994 void CompressTextureSpace(void)
\r
3996 textureSubCacheEntryS * tsx, * tsg, * tsb;
\r
3997 int i,j,k,m,n,iMax;EXLong * ul, r,opos;
\r
3998 short sOldDST=DrawSemiTrans,cx,cy;
\r
3999 long lOGTP=GlobalTexturePage;
\r
4000 unsigned long l,row;
\r
4001 unsigned long * lSRCPtr;
\r
4003 opos.l=*((unsigned long *)&gl_ux[4]);
\r
4005 // 1. mark all textures as free
\r
4006 for(i=0;i<iSortTexCnt;i++)
\r
4007 {ul=pxSsubtexLeft[i];ul->l=0;}
\r
4013 for(k=0;k<MAXTPAGES;k++)
\r
4015 tsg=pscSubtexStore[j][k];
\r
4017 if((!(dwTexPageComp&(1<<k))))
\r
4019 (tsg+SOFFA)->pos.l=0;
\r
4020 (tsg+SOFFB)->pos.l=0;
\r
4021 (tsg+SOFFC)->pos.l=0;
\r
4022 (tsg+SOFFD)->pos.l=0;
\r
4026 for(m=0;m<4;m++,tsg+=SOFFB)
\r
4031 for(i=0;i<iMax;i++,tsx++)
\r
4036 for(n=i+1,tsb=tsx+1;n<iMax;n++,tsb++)
\r
4038 if(tsx->ClutID==tsb->ClutID)
\r
4040 r.c[3]=min(r.c[3],tsb->pos.c[3]);
\r
4041 r.c[2]=max(r.c[2],tsb->pos.c[2]);
\r
4042 r.c[1]=min(r.c[1],tsb->pos.c[1]);
\r
4043 r.c[0]=max(r.c[0],tsb->pos.c[0]);
\r
4048 // if(r.l!=tsx->pos.l)
\r
4050 cx=((tsx->ClutID << 4) & 0x3F0);
\r
4051 cy=((tsx->ClutID >> 6) & CLUTYMASK);
\r
4055 // palette check sum
\r
4056 l=0;lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));
\r
4057 if(j==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
\r
4058 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
\r
4059 l=((l+HIWORD(l))&0x3fffL)<<16;
\r
4060 if(l!=(tsx->ClutID&(0x00003fff<<16)))
\r
4062 tsx->ClutID=0;continue;
\r
4067 if(!GetCompressTexturePlace(tsx)) // no place?
\r
4069 for(i=0;i<3;i++) // -> clean up everything
\r
4070 for(j=0;j<MAXTPAGES;j++)
\r
4072 tsb=pscSubtexStore[i][j];
\r
4073 (tsb+SOFFA)->pos.l=0;
\r
4074 (tsb+SOFFB)->pos.l=0;
\r
4075 (tsb+SOFFC)->pos.l=0;
\r
4076 (tsb+SOFFD)->pos.l=0;
\r
4078 for(i=0;i<iSortTexCnt;i++)
\r
4079 {ul=pxSsubtexLeft[i];ul->l=0;}
\r
4081 DrawSemiTrans=sOldDST;
\r
4082 GlobalTexturePage=lOGTP;
\r
4083 *((unsigned long *)&gl_ux[4])=opos.l;
\r
4089 if(tsx->ClutID&(1<<30)) DrawSemiTrans=1;
\r
4090 else DrawSemiTrans=0;
\r
4091 *((unsigned long *)&gl_ux[4])=r.l;
\r
4093 gTexName=uiStexturePage[tsx->cTexID];
\r
4094 LoadSubTexFn(k,j,cx,cy);
\r
4095 uiStexturePage[tsx->cTexID]=gTexName;
\r
4096 tsx->Opaque=ubOpaqueDraw;
\r
4104 while(!tsx->ClutID && iMax) {tsx--;iMax--;}
\r
4112 if(dwTexPageComp==0xffffffff) dwTexPageComp=0;
\r
4114 *((unsigned long *)&gl_ux[4])=opos.l;
\r
4115 GlobalTexturePage=lOGTP;
\r
4116 DrawSemiTrans=sOldDST;
\r
4119 /////////////////////////////////////////////////////////////////////////////
\r
4120 /////////////////////////////////////////////////////////////////////////////
\r
4121 /////////////////////////////////////////////////////////////////////////////
\r
4123 // main entry for searching/creating textures, called from prim.c
\r
4125 /////////////////////////////////////////////////////////////////////////////
\r
4126 /////////////////////////////////////////////////////////////////////////////
\r
4127 /////////////////////////////////////////////////////////////////////////////
\r
4129 GLuint SelectSubTextureS(long TextureMode, unsigned long GivenClutId)
\r
4131 u8 * OPtr;unsigned short iCache;short cx,cy;
\r
4133 // sort sow/tow infos for fast access
\r
4135 u8 ma1,ma2,mi1,mi2;
\r
4136 if(gl_ux[0]>gl_ux[1]) {mi1=gl_ux[1];ma1=gl_ux[0];}
\r
4137 else {mi1=gl_ux[0];ma1=gl_ux[1];}
\r
4138 if(gl_ux[2]>gl_ux[3]) {mi2=gl_ux[3];ma2=gl_ux[2];}
\r
4139 else {mi2=gl_ux[2];ma2=gl_ux[3];}
\r
4140 if(mi1>mi2) gl_ux[7]=mi2;
\r
4141 else gl_ux[7]=mi1;
\r
4142 if(ma1>ma2) gl_ux[6]=ma1;
\r
4143 else gl_ux[6]=ma2;
\r
4145 if(gl_vy[0]>gl_vy[1]) {mi1=gl_vy[1];ma1=gl_vy[0];}
\r
4146 else {mi1=gl_vy[0];ma1=gl_vy[1];}
\r
4147 if(gl_vy[2]>gl_vy[3]) {mi2=gl_vy[3];ma2=gl_vy[2];}
\r
4148 else {mi2=gl_vy[2];ma2=gl_vy[3];}
\r
4149 if(mi1>mi2) gl_ux[5]=mi2;
\r
4150 else gl_ux[5]=mi1;
\r
4151 if(ma1>ma2) gl_ux[4]=ma1;
\r
4152 else gl_ux[4]=ma2;
\r
4154 // get clut infos in one 32 bit val
\r
4156 if(TextureMode==2) // no clut here
\r
4158 GivenClutId=CLUTUSED|(DrawSemiTrans<<30);cx=cy=0;
\r
4160 if(iFrameTexType && Fake15BitTexture())
\r
4161 return (GLuint)gTexName;
\r
4165 cx=((GivenClutId << 4) & 0x3F0); // but here
\r
4166 cy=((GivenClutId >> 6) & CLUTYMASK);
\r
4167 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30)|CLUTUSED;
\r
4169 // palette check sum.. removed MMX asm, this easy func works as well
\r
4171 unsigned long l=0,row;
\r
4173 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));
\r
4174 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
\r
4175 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
\r
4176 l=(l+HIWORD(l))&0x3fffL;
\r
4177 GivenClutId|=(l<<16);
\r
4184 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
\r
4186 // cache full? compress and try again
\r
4187 if(iCache==0xffff)
\r
4189 CompressTextureSpace();
\r
4190 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
\r
4194 usLRUTexPage=iCache;
\r
4195 if(!OPtr) return uiStexturePage[iCache];
\r
4197 // not found? upload texture and store infos in cache
\r
4198 gTexName=uiStexturePage[iCache];
\r
4199 LoadSubTexFn(GlobalTexturePage,TextureMode,cx,cy);
\r
4200 uiStexturePage[iCache]=gTexName;
\r
4201 *OPtr=ubOpaqueDraw;
\r
4202 return (GLuint) gTexName;
\r
4205 /////////////////////////////////////////////////////////////////////////////
\r
4206 /////////////////////////////////////////////////////////////////////////////
\r
4207 /////////////////////////////////////////////////////////////////////////////
\r