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
70 #include "gpuStdafx.h"
\r
72 #include "gpuDraw.h"
\r
73 //#include "plugins.h"
\r
74 #include "gpuExternals.h"
\r
75 #include "gpuTexture.h"
\r
76 #include "gpuPlugin.h"
\r
77 #include "gpuPrim.h"
\r
79 #define CLUTCHK 0x00060000
\r
80 #define CLUTSHIFT 17
\r
82 ////////////////////////////////////////////////////////////////////////
\r
83 // texture conversion buffer ..
\r
84 ////////////////////////////////////////////////////////////////////////
\r
86 GLubyte ubPaletteBuffer[256][4];
\r
87 GLuint gTexMovieName=0;
\r
88 GLuint gTexBlurName=0;
\r
89 GLuint gTexFrameName=0;
\r
90 int iTexGarbageCollection=1;
\r
91 unsigned long dwTexPageComp=0;
\r
93 int iClampType=GL_CLAMP_TO_EDGE;
\r
94 int iFilter = GL_LINEAR;
\r
95 void (*LoadSubTexFn) (int,int,short,short);
\r
96 unsigned long (*PalTexturedColourFn) (unsigned long);
\r
98 ////////////////////////////////////////////////////////////////////////
\r
100 ////////////////////////////////////////////////////////////////////////
\r
102 #define PALCOL(x) PalTexturedColourFn (x)
\r
104 #define CSUBSIZE 2048
\r
105 #define CSUBSIZEA 8192
\r
106 #define CSUBSIZES 4096
\r
123 #define MAXWNDTEXCACHE 128
\r
125 #define XCHECK(pos1,pos2) ((pos1.c[0]>=pos2.c[1])&&(pos1.c[1]<=pos2.c[0])&&(pos1.c[2]>=pos2.c[3])&&(pos1.c[3]<=pos2.c[2]))
\r
126 #define INCHECK(pos2,pos1) ((pos1.c[0]<=pos2.c[0]) && (pos1.c[1]>=pos2.c[1]) && (pos1.c[2]<=pos2.c[2]) && (pos1.c[3]>=pos2.c[3]))
\r
128 ////////////////////////////////////////////////////////////////////////
\r
130 unsigned char * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache);
\r
131 void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);
\r
132 void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);
\r
133 void DefineSubTextureSort(void);
\r
135 ////////////////////////////////////////////////////////////////////////
\r
137 ////////////////////////////////////////////////////////////////////////
\r
139 long GlobalTexturePage;
\r
144 int iSortTexCnt=32;
\r
145 BOOL bUseFastMdec=FALSE;
\r
146 BOOL bUse15bitMdec=FALSE;
\r
147 int iFrameTexType=0;
\r
148 int iFrameReadType=0;
\r
150 unsigned long (*TCF[2]) (unsigned long);
\r
151 unsigned short (*PTCF[2]) (unsigned short);
\r
153 ////////////////////////////////////////////////////////////////////////
\r
154 // texture cache implementation
\r
155 ////////////////////////////////////////////////////////////////////////
\r
157 // "texture window" cache entry
\r
159 typedef struct textureWndCacheEntryTag
\r
161 unsigned long ClutID;
\r
168 } textureWndCacheEntry;
\r
170 // "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)
\r
172 typedef struct textureSubCacheEntryTagS
\r
174 unsigned long ClutID;
\r
176 unsigned char posTX;
\r
177 unsigned char posTY;
\r
178 unsigned char cTexID;
\r
179 unsigned char Opaque;
\r
180 } textureSubCacheEntryS;
\r
183 //---------------------------------------------
\r
185 #define MAXTPAGES_MAX 64
\r
186 #define MAXSORTTEX_MAX 196
\r
188 //---------------------------------------------
\r
190 textureWndCacheEntry wcWndtexStore[MAXWNDTEXCACHE];
\r
191 textureSubCacheEntryS * pscSubtexStore[3][MAXTPAGES_MAX];
\r
192 EXLong * pxSsubtexLeft [MAXSORTTEX_MAX];
\r
193 GLuint uiStexturePage[MAXSORTTEX_MAX];
\r
195 unsigned short usLRUTexPage=0;
\r
199 int iTexWndLimit=MAXWNDTEXCACHE/2;
\r
201 GLubyte * texturepart=NULL;
\r
202 GLubyte * texturebuffer=NULL;
\r
203 unsigned long g_x1,g_y1,g_x2,g_y2;
\r
204 unsigned char ubOpaqueDraw=0;
\r
206 unsigned short MAXTPAGES = 32;
\r
207 unsigned short CLUTMASK = 0x7fff;
\r
208 unsigned short CLUTYMASK = 0x1ff;
\r
209 unsigned short MAXSORTTEX = 196;
\r
211 ////////////////////////////////////////////////////////////////////////
\r
212 // Texture color conversions... all my ASM funcs are removed for easier
\r
213 // porting... and honestly: nowadays the speed gain would be pointless
\r
214 ////////////////////////////////////////////////////////////////////////
\r
216 unsigned long XP8RGBA(unsigned long BGR)
\r
218 if(!(BGR&0xffff)) return 0x50000000;
\r
219 if(DrawSemiTrans && !(BGR&0x8000))
\r
220 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
221 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
224 unsigned long XP8RGBAEx(unsigned long BGR)
\r
226 if(!(BGR&0xffff)) return 0x03000000;
\r
227 if(DrawSemiTrans && !(BGR&0x8000))
\r
228 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
229 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
232 unsigned long CP8RGBA(unsigned long BGR)
\r
235 if(!(BGR&0xffff)) return 0x50000000;
\r
236 if(DrawSemiTrans && !(BGR&0x8000))
\r
237 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
238 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
239 if(l==0xffffff00) l=0xff000000;
\r
243 unsigned long CP8RGBAEx(unsigned long BGR)
\r
246 if(!(BGR&0xffff)) return 0x03000000;
\r
247 if(DrawSemiTrans && !(BGR&0x8000))
\r
248 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
249 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
250 if(l==0xffffff00) l=0xff000000;
\r
254 unsigned long XP8RGBA_0(unsigned long BGR)
\r
256 if(!(BGR&0xffff)) return 0x50000000;
\r
257 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
260 unsigned long XP8RGBAEx_0(unsigned long BGR)
\r
262 if(!(BGR&0xffff)) return 0x03000000;
\r
263 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
266 unsigned long XP8BGRA_0(unsigned long BGR)
\r
268 if(!(BGR&0xffff)) return 0x50000000;
\r
269 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
272 unsigned long XP8BGRAEx_0(unsigned long BGR)
\r
274 if(!(BGR&0xffff)) return 0x03000000;
\r
275 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
278 unsigned long CP8RGBA_0(unsigned long BGR)
\r
282 if(!(BGR&0xffff)) return 0x50000000;
\r
283 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
284 if(l==0xfff8f800) l=0xff000000;
\r
288 unsigned long CP8RGBAEx_0(unsigned long BGR)
\r
292 if(!(BGR&0xffff)) return 0x03000000;
\r
293 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
294 if(l==0xfff8f800) l=0xff000000;
\r
298 unsigned long CP8BGRA_0(unsigned long BGR)
\r
302 if(!(BGR&0xffff)) return 0x50000000;
\r
303 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
304 if(l==0xff00f8f8) l=0xff000000;
\r
308 unsigned long CP8BGRAEx_0(unsigned long BGR)
\r
312 if(!(BGR&0xffff)) return 0x03000000;
\r
313 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
314 if(l==0xff00f8f8) l=0xff000000;
\r
318 unsigned long XP8RGBA_1(unsigned long BGR)
\r
320 if(!(BGR&0xffff)) return 0x50000000;
\r
321 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
322 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
325 unsigned long XP8RGBAEx_1(unsigned long BGR)
\r
327 if(!(BGR&0xffff)) return 0x03000000;
\r
328 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}
\r
329 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
332 unsigned long XP8BGRA_1(unsigned long BGR)
\r
334 if(!(BGR&0xffff)) return 0x50000000;
\r
335 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}
\r
336 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
339 unsigned long XP8BGRAEx_1(unsigned long BGR)
\r
341 if(!(BGR&0xffff)) return 0x03000000;
\r
342 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}
\r
343 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
346 unsigned long P8RGBA(unsigned long BGR)
\r
348 if(!(BGR&0xffff)) return 0;
\r
349 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;
\r
352 unsigned long P8BGRA(unsigned long BGR)
\r
354 if(!(BGR&0xffff)) return 0;
\r
355 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;
\r
358 unsigned short XP5RGBA(unsigned short BGR)
\r
361 if(DrawSemiTrans && !(BGR&0x8000))
\r
362 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
363 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
366 unsigned short XP5RGBA_0 (unsigned short BGR)
\r
370 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
373 unsigned short CP5RGBA_0 (unsigned short BGR)
\r
379 s=((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
384 unsigned short XP5RGBA_1(unsigned short BGR)
\r
388 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
389 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
392 unsigned short P5RGBA(unsigned short BGR)
\r
395 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;
\r
398 unsigned short XP4RGBA(unsigned short BGR)
\r
401 if(DrawSemiTrans && !(BGR&0x8000))
\r
402 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
403 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
406 unsigned short XP4RGBA_0 (unsigned short BGR)
\r
409 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
412 unsigned short CP4RGBA_0 (unsigned short BGR)
\r
416 s=(((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
417 if(s==0x0fff) s=0x000f;
\r
421 unsigned short XP4RGBA_1(unsigned short BGR)
\r
425 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}
\r
426 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
429 unsigned short P4RGBA(unsigned short BGR)
\r
432 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;
\r
435 ////////////////////////////////////////////////////////////////////////
\r
436 // CHECK TEXTURE MEM (on plugin startup)
\r
437 ////////////////////////////////////////////////////////////////////////
\r
442 void CheckTextureMemory(void)
\r
444 GLboolean b;GLboolean * bDetail;
\r
445 int i,iCnt,iRam=iVRamSize*1024*1024;
\r
446 int iTSize;char * p;
\r
453 iRam-=(iResX*iResY*8);
\r
454 iRam-=(iResX*iResY*(iZBufferDepth/8));
\r
457 iSortTexCnt=iRam/(256*256*ts);
\r
459 if(iSortTexCnt>MAXSORTTEX)
\r
461 iSortTexCnt=MAXSORTTEX-min(1,0);
\r
465 iSortTexCnt-=3+min(1,0);
\r
466 if(iSortTexCnt<8) iSortTexCnt=8;
\r
469 for(i=0;i<MAXSORTTEX;i++)
\r
470 uiStexturePage[i]=0;
\r
476 iSortTexCnt=MAXSORTTEX;
\r
477 #else // below vram detector supposedly crashes some drivers
\r
480 p=(char *)malloc(iTSize*iTSize*4);
\r
483 glGenTextures(MAXSORTTEX,uiStexturePage);
\r
484 for(i=0;i<MAXSORTTEX;i++)
\r
486 glBindTexture(GL_TEXTURE_2D,uiStexturePage[i]);
\r
487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);
\r
488 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);
\r
489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
491 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTSize, iTSize, 0,GL_RGBA, GL_UNSIGNED_BYTE, p);
\r
493 glBindTexture(GL_TEXTURE_2D,0);
\r
497 bDetail=(GLboolean*)malloc(MAXSORTTEX*sizeof(GLboolean));
\r
498 memset(bDetail,0,MAXSORTTEX*sizeof(GLboolean));
\r
500 glDeleteTextures(MAXSORTTEX,uiStexturePage);
\r
502 for(i=0;i<MAXSORTTEX;i++)
\r
504 if(bDetail[i]) iCnt++;
\r
505 uiStexturePage[i]=0;
\r
510 if(b) iSortTexCnt=MAXSORTTEX-min(1,0);
\r
511 else iSortTexCnt=iCnt-3+min(1,0); // place for menu&texwnd
\r
513 if(iSortTexCnt<8) iSortTexCnt=8;
\r
517 ////////////////////////////////////////////////////////////////////////
\r
518 // Main init of textures
\r
519 ////////////////////////////////////////////////////////////////////////
\r
521 void InitializeTextureStore()
\r
525 if(iGPUHeight==1024)
\r
531 iTexGarbageCollection=0;
\r
541 memset(vertex,0,4*sizeof(OGLVertex)); // init vertices
\r
543 gTexName=0; // init main tex name
\r
545 iTexWndLimit=MAXWNDTEXCACHE;
\r
546 /* if(!iUsePalTextures) */iTexWndLimit/=2;
\r
548 memset(wcWndtexStore,0,sizeof(textureWndCacheEntry)*
\r
550 texturepart=(GLubyte *)malloc(256*256*4);
\r
551 memset(texturepart,0,256*256*4);
\r
552 texturebuffer=NULL;
\r
554 for(i=0;i<3;i++) // -> info for 32*3
\r
555 for(j=0;j<MAXTPAGES;j++)
\r
557 pscSubtexStore[i][j]=(textureSubCacheEntryS *)malloc(CSUBSIZES*sizeof(textureSubCacheEntryS));
\r
558 memset(pscSubtexStore[i][j],0,CSUBSIZES*sizeof(textureSubCacheEntryS));
\r
560 for(i=0;i<MAXSORTTEX;i++) // -> info 0..511
\r
562 pxSsubtexLeft[i]=(EXLong *)malloc(CSUBSIZE*sizeof(EXLong));
\r
563 memset(pxSsubtexLeft[i],0,CSUBSIZE*sizeof(EXLong));
\r
564 uiStexturePage[i]=0;
\r
568 ////////////////////////////////////////////////////////////////////////
\r
569 // Clean up on exit
\r
570 ////////////////////////////////////////////////////////////////////////
\r
572 void CleanupTextureStore()
\r
574 int i,j;textureWndCacheEntry * tsx;
\r
575 //----------------------------------------------------//
\r
576 glBindTexture(GL_TEXTURE_2D,0);
\r
578 //----------------------------------------------------//
\r
579 free(texturepart); // free tex part
\r
583 free(texturebuffer);
\r
586 //----------------------------------------------------//
\r
587 tsx=wcWndtexStore; // loop tex window cache
\r
588 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)
\r
590 if(tsx->texname) // -> some tex?
\r
591 glDeleteTextures(1,&tsx->texname); // --> delete it
\r
594 iMaxTexWnds=0; // no more tex wnds
\r
595 //----------------------------------------------------//
\r
596 if(gTexMovieName!=0) // some movie tex?
\r
597 glDeleteTextures(1, &gTexMovieName); // -> delete it
\r
599 gTexMovieName=0; // no more movie tex
\r
600 //----------------------------------------------------//
\r
601 if(gTexFrameName!=0) // some 15bit framebuffer tex?
\r
602 glDeleteTextures(1, &gTexFrameName); // -> delete it
\r
604 gTexFrameName=0; // no more movie tex
\r
605 //----------------------------------------------------//
\r
606 if(gTexBlurName!=0) // some 15bit framebuffer tex?
\r
607 glDeleteTextures(1, &gTexBlurName); // -> delete it
\r
609 gTexBlurName=0; // no more movie tex
\r
610 //----------------------------------------------------//
\r
611 for(i=0;i<3;i++) // -> loop
\r
612 for(j=0;j<MAXTPAGES;j++) // loop tex pages
\r
614 free(pscSubtexStore[i][j]); // -> clean mem
\r
615 pscSubtexStore[i][j]=0;
\r
617 for(i=0;i<MAXSORTTEX;i++)
\r
619 if(uiStexturePage[i]) // --> tex used ?
\r
621 glDeleteTextures(1,&uiStexturePage[i]);
\r
623 uiStexturePage[i]=0; // --> delete it
\r
625 free(pxSsubtexLeft[i]); // -> clean mem
\r
626 pxSsubtexLeft[i]=0;
\r
628 //----------------------------------------------------//
\r
631 ////////////////////////////////////////////////////////////////////////
\r
632 // Reset textures in game...
\r
633 ////////////////////////////////////////////////////////////////////////
\r
635 void ResetTextureArea(BOOL bDelTex)
\r
637 int i,j;textureSubCacheEntryS * tss;EXLong * lu;
\r
638 textureWndCacheEntry * tsx;
\r
639 //----------------------------------------------------//
\r
643 //----------------------------------------------------//
\r
644 if(bDelTex) {glBindTexture(GL_TEXTURE_2D,0); glError();gTexName=0;}
\r
645 //----------------------------------------------------//
\r
647 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)
\r
650 if(bDelTex && tsx->texname)
\r
652 glDeleteTextures(1,&tsx->texname); glError();
\r
657 //----------------------------------------------------//
\r
660 for(j=0;j<MAXTPAGES;j++)
\r
662 tss=pscSubtexStore[i][j];
\r
663 (tss+SOFFA)->pos.l=0;
\r
664 (tss+SOFFB)->pos.l=0;
\r
665 (tss+SOFFC)->pos.l=0;
\r
666 (tss+SOFFD)->pos.l=0;
\r
669 for(i=0;i<iSortTexCnt;i++)
\r
671 lu=pxSsubtexLeft[i];
\r
673 if(bDelTex && uiStexturePage[i])
\r
674 {glDeleteTextures(1,&uiStexturePage[i]); glError();uiStexturePage[i]=0;}
\r
679 ////////////////////////////////////////////////////////////////////////
\r
680 // Invalidate tex windows
\r
681 ////////////////////////////////////////////////////////////////////////
\r
683 void InvalidateWndTextureArea(long X,long Y,long W, long H)
\r
685 int i,px1,px2,py1,py2,iYM=1;
\r
686 textureWndCacheEntry * tsw=wcWndtexStore;
\r
690 if(X<0) X=0;if(X>1023) X=1023;
\r
691 if(W<0) W=0;if(W>1023) W=1023;
\r
692 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
\r
693 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
\r
696 if(iGPUHeight==1024) iYM=3;
\r
699 py2=min(iYM,H>>8); // y: 0 or 1
\r
702 px2=min(15,(W>>6));
\r
706 py1=py1<<4;px1+=py1;px2+=py1; // change to 0-31
\r
707 for(i=0;i<iMaxTexWnds;i++,tsw++)
\r
711 if(tsw->pageid>=px1 && tsw->pageid<=px2)
\r
720 py1=px1+16;py2=px2+16;
\r
721 for(i=0;i<iMaxTexWnds;i++,tsw++)
\r
725 if((tsw->pageid>=px1 && tsw->pageid<=px2) ||
\r
726 (tsw->pageid>=py1 && tsw->pageid<=py2))
\r
734 // adjust tex window count
\r
735 tsw=wcWndtexStore+iMaxTexWnds-1;
\r
736 while(iMaxTexWnds && !tsw->used) {iMaxTexWnds--;tsw--;}
\r
741 ////////////////////////////////////////////////////////////////////////
\r
742 // same for sort textures
\r
743 ////////////////////////////////////////////////////////////////////////
\r
745 void MarkFree(textureSubCacheEntryS * tsx)
\r
747 EXLong * ul, * uls;
\r
748 int j,iMax;unsigned char x1,y1,dx,dy;
\r
750 uls=pxSsubtexLeft[tsx->cTexID];
\r
751 iMax=uls->l;ul=uls+1;
\r
755 for(j=0;j<iMax;j++,ul++)
\r
756 if(ul->l==0xffffffff) break;
\r
760 if(j==iMax) uls->l=uls->l+1;
\r
762 x1=tsx->posTX;dx=tsx->pos.c[2]-tsx->pos.c[3];
\r
763 if(tsx->posTX) {x1--;dx+=3;}
\r
764 y1=tsx->posTY;dy=tsx->pos.c[0]-tsx->pos.c[1];
\r
765 if(tsx->posTY) {y1--;dy+=3;}
\r
774 void InvalidateSubSTextureArea(long X,long Y,long W, long H)
\r
776 int i,j,k,iMax,px,py,px1,px2,py1,py2,iYM=1;
\r
777 EXLong npos;textureSubCacheEntryS * tsb;
\r
778 long x1,x2,y1,y2,xa,sw;
\r
782 if(X<0) X=0;if(X>1023) X=1023;
\r
783 if(W<0) W=0;if(W>1023) W=1023;
\r
784 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
\r
785 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
\r
788 if(iGPUHeight==1024) iYM=3;
\r
791 py2=min(iYM,H>>8); // y: 0 or 1
\r
792 px1=max(0,(X>>6)-3);
\r
793 px2=min(15,(W>>6)+3); // x: 0-15
\r
795 for(py=py1;py<=py2;py++)
\r
797 j=(py<<4)+px1; // get page
\r
799 y1=py*256;y2=y1+255;
\r
806 if(y2<y1) {sw=y1;y1=y2;y2=sw;}
\r
810 for(px=px1;px<=px2;px++,j++)
\r
821 if(x2<x1) {sw=x1;x1=x2;x2=sw;}
\r
823 if (dwGPUVersion == 2)
\r
826 npos.l=((x1-xa)<<(26-k))|((x2-xa)<<(18-k))|y1|y2;
\r
829 tsb=pscSubtexStore[k][j]+SOFFA;iMax=tsb->pos.l;tsb++;
\r
830 for(i=0;i<iMax;i++,tsb++)
\r
831 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
833 // if(npos.l & 0x00800000)
\r
835 tsb=pscSubtexStore[k][j]+SOFFB;iMax=tsb->pos.l;tsb++;
\r
836 for(i=0;i<iMax;i++,tsb++)
\r
837 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
840 // if(npos.l & 0x00000080)
\r
842 tsb=pscSubtexStore[k][j]+SOFFC;iMax=tsb->pos.l;tsb++;
\r
843 for(i=0;i<iMax;i++,tsb++)
\r
844 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
847 // if(npos.l & 0x00800080)
\r
849 tsb=pscSubtexStore[k][j]+SOFFD;iMax=tsb->pos.l;tsb++;
\r
850 for(i=0;i<iMax;i++,tsb++)
\r
851 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}
\r
859 ////////////////////////////////////////////////////////////////////////
\r
860 // Invalidate some parts of cache: main routine
\r
861 ////////////////////////////////////////////////////////////////////////
\r
863 void InvalidateTextureAreaEx(void)
\r
865 short W=sxmax-sxmin;
\r
866 short H=symax-symin;
\r
868 if(W==0 && H==0) return;
\r
871 InvalidateWndTextureArea(sxmin,symin,W,H);
\r
873 InvalidateSubSTextureArea(sxmin,symin,W,H);
\r
876 ////////////////////////////////////////////////////////////////////////
\r
878 void InvalidateTextureArea(long X,long Y,long W, long H)
\r
880 if(W==0 && H==0) return;
\r
882 if(iMaxTexWnds) InvalidateWndTextureArea(X,Y,W,H);
\r
884 InvalidateSubSTextureArea(X,Y,W,H);
\r
888 ////////////////////////////////////////////////////////////////////////
\r
889 // tex window: define
\r
890 ////////////////////////////////////////////////////////////////////////
\r
892 void DefineTextureWnd(void)
\r
895 glGenTextures(1, &gTexName);
\r
897 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
899 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
\r
900 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
\r
903 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
904 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
908 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,
\r
911 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);
\r
913 //LOGE("DefineTextureWnd x:%d y:%d",TWin.Position.x1,TWin.Position.y1);
\r
917 ////////////////////////////////////////////////////////////////////////
\r
918 // tex window: load packed stretch
\r
919 ////////////////////////////////////////////////////////////////////////
\r
921 void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
\r
923 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;
\r
924 unsigned int palstart;
\r
925 unsigned short *px,*pa,*ta;
\r
926 unsigned char *cSRCPtr,*cOSRCPtr;
\r
927 unsigned short *wSRCPtr,*wOSRCPtr;
\r
928 unsigned long LineOffset;unsigned short s;
\r
929 int pmult=pageid/16;
\r
930 unsigned short (*LPTCOL)(unsigned short);
\r
932 LPTCOL=PTCF[DrawSemiTrans];
\r
934 ldxo=TWin.Position.x1-TWin.OPosition.x1;
\r
935 ldy =TWin.Position.y1-TWin.OPosition.y1;
\r
937 pa=px=(unsigned short *)ubPaletteBuffer;
\r
938 ta=(unsigned short *)texturepart;
\r
939 palstart=cx+(cy*1024);
\r
945 //--------------------------------------------------//
\r
946 // 4bit texture load ..
\r
950 unsigned int TXV,TXU,n_xi,n_yi;
\r
952 wSRCPtr=psxVuw+palstart;
\r
953 for(row=0;row<16;row++)
\r
954 *px++=LPTCOL(*wSRCPtr++);
\r
957 for(TXV=g_y1;TXV<=column;TXV++)
\r
960 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
962 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
963 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
965 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
968 if(ldx) {*ta++=s;ldx--;}
\r
973 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
974 *ta++=*(ta-(g_x2-g_x1));
\r
978 DefineTextureWnd();
\r
984 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
986 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
988 wSRCPtr=psxVuw+palstart;
\r
989 for(row=0;row<16;row++)
\r
990 *px++=LPTCOL(*wSRCPtr++);
\r
992 sxm=g_x1&1;sxh=g_x1>>1;
\r
993 if(sxm) j=g_x1+1; else j=g_x1;
\r
994 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
995 for(column=g_y1;column<=g_y2;column++)
\r
997 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
998 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1000 for(row=j;row<=g_x2-ldxo;row++)
\r
1002 s=*(pa+(*cSRCPtr & 0xF));
\r
1004 if(ldx) {*ta++=s;ldx--;}
\r
1006 if(row<=g_x2-ldxo)
\r
1008 s=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1010 if(ldx) {*ta++=s;ldx--;}
\r
1015 if(ldy && column&1)
\r
1016 {ldy--;cSRCPtr = cOSRCPtr;}
\r
1017 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
\r
1020 DefineTextureWnd();
\r
1022 //--------------------------------------------------//
\r
1023 // 8bit texture load ..
\r
1027 unsigned int TXV,TXU,n_xi,n_yi;
\r
1029 wSRCPtr=psxVuw+palstart;
\r
1030 for(row=0;row<256;row++)
\r
1031 *px++=LPTCOL(*wSRCPtr++);
\r
1034 for(TXV=g_y1;TXV<=column;TXV++)
\r
1037 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1039 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1040 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1042 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1045 if(ldx) {*ta++=s;ldx--;}
\r
1050 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1051 *ta++=*(ta-(g_x2-g_x1));
\r
1056 DefineTextureWnd();
\r
1061 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1063 // not using a lookup table here... speeds up smaller texture areas
\r
1064 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1065 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
\r
1067 for(column=g_y1;column<=g_y2;column++)
\r
1069 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1070 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1072 s=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1074 if(ldx) {*ta++=s;ldx--;}
\r
1076 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
\r
1077 else cSRCPtr+=LineOffset;
\r
1080 DefineTextureWnd();
\r
1082 //--------------------------------------------------//
\r
1083 // 16bit texture load ..
\r
1085 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1086 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1087 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo;
\r
1089 for(column=g_y1;column<=g_y2;column++)
\r
1091 wOSRCPtr=wSRCPtr;ldx=ldxo;
\r
1092 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1094 s=LPTCOL(*wSRCPtr++);
\r
1096 if(ldx) {*ta++=s;ldx--;}
\r
1098 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}
\r
1099 else wSRCPtr+=LineOffset;
\r
1102 DefineTextureWnd();
\r
1104 //--------------------------------------------------//
\r
1105 // others are not possible !
\r
1109 ////////////////////////////////////////////////////////////////////////
\r
1110 // tex window: load stretched
\r
1111 ////////////////////////////////////////////////////////////////////////
\r
1113 void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1115 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo,s;
\r
1116 unsigned int palstart;
\r
1117 unsigned long *px,*pa,*ta;
\r
1118 unsigned char *cSRCPtr,*cOSRCPtr;
\r
1119 unsigned short *wSRCPtr,*wOSRCPtr;
\r
1120 unsigned long LineOffset;
\r
1121 int pmult=pageid/16;
\r
1122 unsigned long (*LTCOL)(unsigned long);
\r
1124 LTCOL=TCF[DrawSemiTrans];
\r
1126 ldxo=TWin.Position.x1-TWin.OPosition.x1;
\r
1127 ldy =TWin.Position.y1-TWin.OPosition.y1;
\r
1129 pa=px=(unsigned long *)ubPaletteBuffer;
\r
1130 ta=(unsigned long *)texturepart;
\r
1131 palstart=cx+(cy*1024);
\r
1137 //--------------------------------------------------//
\r
1138 // 4bit texture load ..
\r
1140 //------------------- ZN STUFF
\r
1144 unsigned int TXV,TXU,n_xi,n_yi;
\r
1146 wSRCPtr=psxVuw+palstart;
\r
1150 *px =LTCOL(*wSRCPtr);
\r
1151 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1152 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1153 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1154 row--;px+=4;wSRCPtr+=4;
\r
1159 for(TXV=g_y1;TXV<=column;TXV++)
\r
1162 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1164 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1165 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1167 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1170 if(ldx) {*ta++=s;ldx--;}
\r
1175 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1176 *ta++=*(ta-(g_x2-g_x1));
\r
1180 DefineTextureWnd();
\r
1185 //-------------------
\r
1187 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1188 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
1190 wSRCPtr=psxVuw+palstart;
\r
1191 for(row=0;row<16;row++)
\r
1192 *px++=LTCOL(*wSRCPtr++);
\r
1194 sxm=g_x1&1;sxh=g_x1>>1;
\r
1195 if(sxm) j=g_x1+1; else j=g_x1;
\r
1196 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1197 for(column=g_y1;column<=g_y2;column++)
\r
1199 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1200 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1202 for(row=j;row<=g_x2-ldxo;row++)
\r
1204 s=*(pa+(*cSRCPtr & 0xF));
\r
1206 if(ldx) {*ta++=s;ldx--;}
\r
1208 if(row<=g_x2-ldxo)
\r
1210 s=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1212 if(ldx) {*ta++=s;ldx--;}
\r
1216 if(ldy && column&1)
\r
1217 {ldy--;cSRCPtr = cOSRCPtr;}
\r
1218 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
\r
1221 DefineTextureWnd();
\r
1223 //--------------------------------------------------//
\r
1224 // 8bit texture load ..
\r
1226 //------------ ZN STUFF
\r
1229 unsigned int TXV,TXU,n_xi,n_yi;
\r
1231 wSRCPtr=psxVuw+palstart;
\r
1235 *px =LTCOL(*wSRCPtr);
\r
1236 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1237 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1238 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1239 row--;px+=4;wSRCPtr+=4;
\r
1244 for(TXV=g_y1;TXV<=column;TXV++)
\r
1247 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
\r
1249 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1250 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1252 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1254 if(ldx) {*ta++=s;ldx--;}
\r
1259 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1260 *ta++=*(ta-(g_x2-g_x1));
\r
1265 DefineTextureWnd();
\r
1271 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1273 // not using a lookup table here... speeds up smaller texture areas
\r
1274 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1275 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
\r
1277 for(column=g_y1;column<=g_y2;column++)
\r
1279 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1280 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1282 s=LTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1284 if(ldx) {*ta++=s;ldx--;}
\r
1286 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
\r
1287 else cSRCPtr+=LineOffset;
\r
1290 DefineTextureWnd();
\r
1292 //--------------------------------------------------//
\r
1293 // 16bit texture load ..
\r
1295 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1297 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1298 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo;
\r
1300 for(column=g_y1;column<=g_y2;column++)
\r
1302 wOSRCPtr=wSRCPtr;ldx=ldxo;
\r
1303 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1305 s=LTCOL(*wSRCPtr++);
\r
1307 if(ldx) {*ta++=s;ldx--;}
\r
1309 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}
\r
1310 else wSRCPtr+=LineOffset;
\r
1313 DefineTextureWnd();
\r
1315 //--------------------------------------------------//
\r
1316 // others are not possible !
\r
1320 ////////////////////////////////////////////////////////////////////////
\r
1321 // tex window: load packed simple
\r
1322 ////////////////////////////////////////////////////////////////////////
\r
1324 void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1326 unsigned long start,row,column,j,sxh,sxm;
\r
1327 unsigned int palstart;
\r
1328 unsigned short *px,*pa,*ta;
\r
1329 unsigned char *cSRCPtr;
\r
1330 unsigned short *wSRCPtr;
\r
1331 unsigned long LineOffset;
\r
1332 int pmult=pageid/16;
\r
1333 unsigned short (*LPTCOL)(unsigned short);
\r
1335 LPTCOL=PTCF[DrawSemiTrans];
\r
1337 pa=px=(unsigned short *)ubPaletteBuffer;
\r
1338 ta=(unsigned short *)texturepart;
\r
1339 palstart=cx+(cy*1024);
\r
1345 //--------------------------------------------------//
\r
1346 // 4bit texture load ..
\r
1350 unsigned int TXV,TXU,n_xi,n_yi;
\r
1352 wSRCPtr=psxVuw+palstart;
\r
1353 for(row=0;row<16;row++)
\r
1354 *px++=LPTCOL(*wSRCPtr++);
\r
1356 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1358 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1360 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1361 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1363 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1367 DefineTextureWnd();
\r
1372 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1374 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
1376 wSRCPtr=psxVuw+palstart;
\r
1377 for(row=0;row<16;row++)
\r
1378 *px++=LPTCOL(*wSRCPtr++);
\r
1380 sxm=g_x1&1;sxh=g_x1>>1;
\r
1381 if(sxm) j=g_x1+1; else j=g_x1;
\r
1382 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1383 for(column=g_y1;column<=g_y2;column++)
\r
1385 cSRCPtr = psxVub + start + (2048*column) + sxh;
\r
1387 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1389 for(row=j;row<=g_x2;row++)
\r
1391 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
\r
1392 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1397 DefineTextureWnd();
\r
1399 //--------------------------------------------------//
\r
1400 // 8bit texture load ..
\r
1404 unsigned int TXV,TXU,n_xi,n_yi;
\r
1406 wSRCPtr=psxVuw+palstart;
\r
1407 for(row=0;row<256;row++)
\r
1408 *px++=LPTCOL(*wSRCPtr++);
\r
1410 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1412 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1414 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1415 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1417 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1421 DefineTextureWnd();
\r
1426 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1428 // not using a lookup table here... speeds up smaller texture areas
\r
1429 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1430 LineOffset = 2048 - (g_x2-g_x1+1);
\r
1432 for(column=g_y1;column<=g_y2;column++)
\r
1434 for(row=g_x1;row<=g_x2;row++)
\r
1435 *ta++=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1436 cSRCPtr+=LineOffset;
\r
1439 DefineTextureWnd();
\r
1441 //--------------------------------------------------//
\r
1442 // 16bit texture load ..
\r
1444 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1445 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1446 LineOffset = 1024 - (g_x2-g_x1+1);
\r
1448 for(column=g_y1;column<=g_y2;column++)
\r
1450 for(row=g_x1;row<=g_x2;row++)
\r
1451 *ta++=LPTCOL(*wSRCPtr++);
\r
1452 wSRCPtr+=LineOffset;
\r
1455 DefineTextureWnd();
\r
1457 //--------------------------------------------------//
\r
1458 // others are not possible !
\r
1462 ////////////////////////////////////////////////////////////////////////
\r
1463 // tex window: load simple
\r
1464 ////////////////////////////////////////////////////////////////////////
\r
1466 void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1468 unsigned long start,row,column,j,sxh,sxm;
\r
1469 unsigned int palstart;
\r
1470 unsigned long *px,*pa,*ta;
\r
1471 unsigned char *cSRCPtr;
\r
1472 unsigned short *wSRCPtr;
\r
1473 unsigned long LineOffset;
\r
1474 int pmult=pageid/16;
\r
1475 unsigned long (*LTCOL)(unsigned long);
\r
1477 LTCOL=TCF[DrawSemiTrans];
\r
1479 pa=px=(unsigned long *)ubPaletteBuffer;
\r
1480 ta=(unsigned long *)texturepart;
\r
1481 palstart=cx+(cy*1024);
\r
1487 //--------------------------------------------------//
\r
1488 // 4bit texture load ..
\r
1492 unsigned int TXV,TXU,n_xi,n_yi;
\r
1494 wSRCPtr=psxVuw+palstart;
\r
1498 *px =LTCOL(*wSRCPtr);
\r
1499 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1500 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1501 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1502 row--;px+=4;wSRCPtr+=4;
\r
1506 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1508 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1510 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
1511 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
1513 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
1517 DefineTextureWnd();
\r
1522 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1524 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
1526 wSRCPtr=psxVuw+palstart;
\r
1527 for(row=0;row<16;row++)
\r
1528 *px++=LTCOL(*wSRCPtr++);
\r
1530 sxm=g_x1&1;sxh=g_x1>>1;
\r
1531 if(sxm) j=g_x1+1; else j=g_x1;
\r
1532 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1533 for(column=g_y1;column<=g_y2;column++)
\r
1535 cSRCPtr = psxVub + start + (2048*column) + sxh;
\r
1537 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
1539 for(row=j;row<=g_x2;row++)
\r
1541 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
\r
1542 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
1547 DefineTextureWnd();
\r
1549 //--------------------------------------------------//
\r
1550 // 8bit texture load ..
\r
1554 unsigned int TXV,TXU,n_xi,n_yi;
\r
1556 wSRCPtr=psxVuw+palstart;
\r
1560 *px =LTCOL(*wSRCPtr);
\r
1561 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
1562 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
1563 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
1564 row--;px+=4;wSRCPtr+=4;
\r
1568 for(TXV=g_y1;TXV<=g_y2;TXV++)
\r
1570 for(TXU=g_x1;TXU<=g_x2;TXU++)
\r
1572 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
1573 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
1575 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
1579 DefineTextureWnd();
\r
1584 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1586 // not using a lookup table here... speeds up smaller texture areas
\r
1587 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1588 LineOffset = 2048 - (g_x2-g_x1+1);
\r
1590 for(column=g_y1;column<=g_y2;column++)
\r
1592 for(row=g_x1;row<=g_x2;row++)
\r
1593 *ta++=LTCOL(psxVuw[palstart+ *cSRCPtr++]);
\r
1594 cSRCPtr+=LineOffset;
\r
1597 DefineTextureWnd();
\r
1599 //--------------------------------------------------//
\r
1600 // 16bit texture load ..
\r
1602 start=((pageid-16*pmult)*64)+256*1024*pmult;
\r
1604 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;
\r
1605 LineOffset = 1024 - (g_x2-g_x1+1);
\r
1607 for(column=g_y1;column<=g_y2;column++)
\r
1609 for(row=g_x1;row<=g_x2;row++)
\r
1610 *ta++=LTCOL(*wSRCPtr++);
\r
1611 wSRCPtr+=LineOffset;
\r
1614 DefineTextureWnd();
\r
1616 //--------------------------------------------------//
\r
1617 // others are not possible !
\r
1621 ////////////////////////////////////////////////////////////////////////
\r
1622 ////////////////////////////////////////////////////////////////////////
\r
1623 ////////////////////////////////////////////////////////////////////////
\r
1624 ////////////////////////////////////////////////////////////////////////
\r
1626 void UploadTexWndPal(int mode,short cx,short cy)
\r
1628 unsigned int i,iSize;
\r
1629 unsigned short * wSrcPtr;
\r
1630 unsigned long * ta=(unsigned long *)texturepart;
\r
1632 wSrcPtr=psxVuw+cx+(cy*1024);
\r
1633 if(mode==0) i=4; else i=64;
\r
1639 *ta =PALCOL(*wSrcPtr);
\r
1640 *(ta+1)=PALCOL(*(wSrcPtr+1));
\r
1641 *(ta+2)=PALCOL(*(wSrcPtr+2));
\r
1642 *(ta+3)=PALCOL(*(wSrcPtr+3));
\r
1643 ta+=4;wSrcPtr+=4;i--;
\r
1647 /* (*glColorTableEXTEx)(GL_TEXTURE_2D,GL_RGBA8,iSize,
\r
1648 GL_RGBA,GL_UNSIGNED_BYTE,texturepart);
\r
1651 ////////////////////////////////////////////////////////////////////////
\r
1653 void DefinePalTextureWnd(void)
\r
1656 glGenTextures(1, &gTexName);
\r
1658 glBindTexture(GL_TEXTURE_2D, gTexName);
\r
1660 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
\r
1661 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
\r
1664 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);
\r
1665 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);
\r
1668 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA,
\r
1669 TWin.Position.x1,
\r
1670 TWin.Position.y1,
\r
1671 0, GL_RGBA, GL_UNSIGNED_BYTE,texturepart);
\r
1673 //LOGE("DefinePalTextureWnd x:%d y:%d",TWin.Position.x1,TWin.Position.y1);
\r
1676 ///////////////////////////////////////////////////////
\r
1678 void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1680 unsigned long start,row,column,j,sxh,sxm;
\r
1681 unsigned char *ta;
\r
1682 unsigned char *cSRCPtr;
\r
1683 unsigned long LineOffset;
\r
1684 int pmult=pageid/16;
\r
1686 ta=(unsigned char *)texturepart;
\r
1690 //--------------------------------------------------//
\r
1691 // 4bit texture load ..
\r
1693 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1695 sxm=g_x1&1;sxh=g_x1>>1;
\r
1696 if(sxm) j=g_x1+1; else j=g_x1;
\r
1697 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1698 for(column=g_y1;column<=g_y2;column++)
\r
1700 cSRCPtr = psxVub + start + (2048*column) + sxh;
\r
1702 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);
\r
1704 for(row=j;row<=g_x2;row++)
\r
1706 *ta++=(*cSRCPtr & 0xF); row++;
\r
1707 if(row<=g_x2) *ta++=((*cSRCPtr >> 4) & 0xF);
\r
1712 DefinePalTextureWnd();
\r
1714 //--------------------------------------------------//
\r
1715 // 8bit texture load ..
\r
1717 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1719 // not using a lookup table here... speeds up smaller texture areas
\r
1720 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1721 LineOffset = 2048 - (g_x2-g_x1+1);
\r
1723 for(column=g_y1;column<=g_y2;column++)
\r
1725 for(row=g_x1;row<=g_x2;row++)
\r
1727 cSRCPtr+=LineOffset;
\r
1730 DefinePalTextureWnd();
\r
1733 UploadTexWndPal(mode,cx,cy);
\r
1736 ////////////////////////////////////////////////////////////////////////
\r
1738 void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
\r
1740 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;
\r
1741 unsigned char *ta,s;
\r
1742 unsigned char *cSRCPtr,*cOSRCPtr;
\r
1743 unsigned long LineOffset;
\r
1744 int pmult=pageid/16;
\r
1746 ldxo=TWin.Position.x1-TWin.OPosition.x1;
\r
1747 ldy =TWin.Position.y1-TWin.OPosition.y1;
\r
1749 ta=(unsigned char *)texturepart;
\r
1753 //--------------------------------------------------//
\r
1754 // 4bit texture load ..
\r
1756 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1758 sxm=g_x1&1;sxh=g_x1>>1;
\r
1759 if(sxm) j=g_x1+1; else j=g_x1;
\r
1760 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;
\r
1761 for(column=g_y1;column<=g_y2;column++)
\r
1763 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1764 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);
\r
1766 for(row=j;row<=g_x2-ldxo;row++)
\r
1768 s=(*cSRCPtr & 0xF);
\r
1770 if(ldx) {*ta++=s;ldx--;}
\r
1772 if(row<=g_x2-ldxo)
\r
1774 s=((*cSRCPtr >> 4) & 0xF);
\r
1776 if(ldx) {*ta++=s;ldx--;}
\r
1780 if(ldy && column&1)
\r
1781 {ldy--;cSRCPtr = cOSRCPtr;}
\r
1782 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;
\r
1785 DefinePalTextureWnd();
\r
1787 //--------------------------------------------------//
\r
1788 // 8bit texture load ..
\r
1790 start=((pageid-16*pmult)*128)+256*2048*pmult;
\r
1792 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
\r
1793 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
\r
1795 for(column=g_y1;column<=g_y2;column++)
\r
1797 cOSRCPtr=cSRCPtr;ldx=ldxo;
\r
1798 for(row=g_x1;row<=g_x2-ldxo;row++)
\r
1802 if(ldx) {*ta++=s;ldx--;}
\r
1804 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}
\r
1805 else cSRCPtr+=LineOffset;
\r
1808 DefinePalTextureWnd();
\r
1811 UploadTexWndPal(mode,cx,cy);
\r
1814 ////////////////////////////////////////////////////////////////////////
\r
1815 // tex window: main selecting, cache handler included
\r
1816 ////////////////////////////////////////////////////////////////////////
\r
1818 GLuint LoadTextureWnd(long pageid,long TextureMode,unsigned long GivenClutId)
\r
1820 textureWndCacheEntry * ts, * tsx=NULL;
\r
1821 int i;short cx,cy;
\r
1824 npos.c[3]=TWin.Position.x0;
\r
1825 npos.c[2]=TWin.OPosition.x1;
\r
1826 npos.c[1]=TWin.Position.y0;
\r
1827 npos.c[0]=TWin.OPosition.y1;
\r
1829 g_x1=TWin.Position.x0;g_x2=g_x1+TWin.Position.x1-1;
\r
1830 g_y1=TWin.Position.y0;g_y2=g_y1+TWin.Position.y1-1;
\r
1832 if(TextureMode==2) {GivenClutId=0;cx=cy=0;}
\r
1835 cx=((GivenClutId << 4) & 0x3F0);cy=((GivenClutId >> 6) & CLUTYMASK);
\r
1836 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30);
\r
1838 // palette check sum
\r
1840 unsigned long l=0,row;
\r
1841 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));
\r
1842 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
\r
1843 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
\r
1844 l=(l+HIWORD(l))&0x3fffL;
\r
1845 GivenClutId|=(l<<16);
\r
1852 for(i=0;i<iMaxTexWnds;i++,ts++)
\r
1856 if(ts->pos.l==npos.l &&
\r
1857 ts->pageid==pageid &&
\r
1858 ts->textureMode==TextureMode)
\r
1860 if(ts->ClutID==GivenClutId)
\r
1862 ubOpaqueDraw=ts->Opaque;
\r
1863 return ts->texname;
\r
1872 if(iMaxTexWnds==iTexWndLimit)
\r
1874 tsx=wcWndtexStore+iTexWndTurn;
\r
1876 if(iTexWndTurn==iTexWndLimit) iTexWndTurn=0;
\r
1880 tsx=wcWndtexStore+iMaxTexWnds;
\r
1885 gTexName=tsx->texname;
\r
1887 if(TWin.OPosition.y1==TWin.Position.y1 &&
\r
1888 TWin.OPosition.x1==TWin.Position.x1)
\r
1890 LoadWndTexturePage(pageid,TextureMode,cx,cy);
\r
1894 LoadStretchWndTexturePage(pageid,TextureMode,cx,cy);
\r
1897 tsx->Opaque=ubOpaqueDraw;
\r
1898 tsx->pos.l=npos.l;
\r
1899 tsx->ClutID=GivenClutId;
\r
1900 tsx->pageid=pageid;
\r
1901 tsx->textureMode=TextureMode;
\r
1902 tsx->texname=gTexName;
\r
1908 /////////////////////////////////////////////////////////////////////////////
\r
1909 /////////////////////////////////////////////////////////////////////////////
\r
1910 /////////////////////////////////////////////////////////////////////////////
\r
1912 ////////////////////////////////////////////////////////////////////////
\r
1913 // movie texture: define
\r
1914 ////////////////////////////////////////////////////////////////////////
\r
1916 void DefinePackedTextureMovie(void)
\r
1918 if(gTexMovieName==0)
\r
1920 glEnable(GL_TEXTURE_2D);
\r
1921 glGenTextures(1, &gTexMovieName); glError();
\r
1922 gTexName=gTexMovieName;
\r
1923 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
1925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();
\r
1926 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();
\r
1928 if(!bUseFastMdec)
\r
1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();
\r
1931 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();
\r
1935 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();
\r
1936 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();
\r
1939 glTexImage2D(GL_TEXTURE_2D, 0, //giWantedRGBA,
\r
1941 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();
\r
1945 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\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
1953 texturepart); glError();
\r
1954 //LOGE("DefinePackedTextureMovie x:%d y:%d",(xrMovieArea.x1-xrMovieArea.x0),(xrMovieArea.y1-xrMovieArea.y0));
\r
1958 ////////////////////////////////////////////////////////////////////////
\r
1960 void DefineTextureMovie(void)
\r
1962 if(gTexMovieName==0)
\r
1964 glGenTextures(1, &gTexMovieName); glError();
\r
1965 gTexName=gTexMovieName;
\r
1966 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
1968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();
\r
1969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();
\r
1971 if(!bUseFastMdec)
\r
1973 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();
\r
1974 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();
\r
1978 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();
\r
1979 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();
\r
1982 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();
\r
1986 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
1989 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
\r
1990 (xrMovieArea.x1-xrMovieArea.x0),
\r
1991 (xrMovieArea.y1-xrMovieArea.y0),
\r
1992 GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();
\r
1993 //LOGE("DefineTextureMovie x:%d y:%d",(xrMovieArea.x1-xrMovieArea.x0),(xrMovieArea.y1-xrMovieArea.y0));
\r
1996 ////////////////////////////////////////////////////////////////////////
\r
1997 // movie texture: load
\r
1998 ////////////////////////////////////////////////////////////////////////
\r
2000 #define MRED(x) ((x>>3) & 0x1f)
\r
2001 #define MGREEN(x) ((x>>6) & 0x3e0)
\r
2002 #define MBLUE(x) ((x>>9) & 0x7c00)
\r
2004 #define XMGREEN(x) ((x>>5) & 0x07c0)
\r
2005 #define XMRED(x) ((x<<8) & 0xf800)
\r
2006 #define XMBLUE(x) ((x>>18) & 0x003e)
\r
2008 ////////////////////////////////////////////////////////////////////////
\r
2009 // movie texture: load
\r
2010 ////////////////////////////////////////////////////////////////////////
\r
2012 unsigned char * LoadDirectMovieFast(void)
\r
2015 unsigned int startxy;
\r
2017 unsigned long * ta=(unsigned long *)texturepart;
\r
2019 if(PSXDisplay.RGB24)
\r
2021 unsigned char * pD;
\r
2023 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
\r
2025 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)
\r
2027 pD=(unsigned char *)&psxVuw[startxy];
\r
2028 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2030 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2037 unsigned long (*LTCOL)(unsigned long);
\r
2039 LTCOL=XP8RGBA_0;//TCF[0];
\r
2043 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2045 startxy=((1024)*column)+xrMovieArea.x0;
\r
2046 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2047 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2051 return texturepart;
\r
2054 ////////////////////////////////////////////////////////////////////////
\r
2056 GLuint LoadTextureMovieFast(void)
\r
2059 unsigned int start,startxy;
\r
2062 if(PSXDisplay.RGB24)
\r
2064 unsigned char * pD;
\r
2065 unsigned long * ta=(unsigned long *)texturepart;
\r
2067 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;
\r
2069 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)
\r
2071 //startxy=((1024)*column)+xrMovieArea.x0;
\r
2072 pD=(unsigned char *)&psxVuw[startxy];
\r
2073 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2075 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2082 unsigned long (*LTCOL)(unsigned long);
\r
2083 unsigned long *ta;
\r
2085 LTCOL=XP8RGBA_0;//TCF[0];
\r
2088 ta=(unsigned long *)texturepart;
\r
2090 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2092 startxy=((1024)*column)+xrMovieArea.x0;
\r
2093 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2094 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2097 DefineTextureMovie();
\r
2102 ////////////////////////////////////////////////////////////////////////
\r
2104 GLuint LoadTextureMovie(void)
\r
2106 short row,column,dx;
\r
2107 unsigned int startxy;
\r
2110 if(bUseFastMdec) return LoadTextureMovieFast();
\r
2112 b_X=FALSE;b_Y=FALSE;
\r
2114 if((xrMovieArea.x1-xrMovieArea.x0)<255) b_X=TRUE;
\r
2115 if((xrMovieArea.y1-xrMovieArea.y0)<255) b_Y=TRUE;
\r
2118 if(PSXDisplay.RGB24)
\r
2120 unsigned char * pD;
\r
2121 unsigned long * ta=(unsigned long *)texturepart;
\r
2125 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2127 startxy=((1024)*column)+xrMovieArea.x0;
\r
2128 pD=(unsigned char *)&psxVuw[startxy];
\r
2129 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2131 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2138 dx=xrMovieArea.x1-xrMovieArea.x0+1;
\r
2139 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2146 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2148 startxy=((1024)*column)+xrMovieArea.x0;
\r
2149 pD=(unsigned char *)&psxVuw[startxy];
\r
2150 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2152 *ta++=*((unsigned long *)pD)|0xff000000;
\r
2158 dx=xrMovieArea.x1-xrMovieArea.x0;
\r
2159 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2166 unsigned long (*LTCOL)(unsigned long);
\r
2167 unsigned long *ta;
\r
2169 LTCOL=XP8RGBA_0;//TCF[0];
\r
2172 ta=(unsigned long *)texturepart;
\r
2176 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2178 startxy=((1024)*column)+xrMovieArea.x0;
\r
2179 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2180 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2186 dx=xrMovieArea.x1-xrMovieArea.x0+1;
\r
2187 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2194 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
\r
2196 startxy=((1024)*column)+xrMovieArea.x0;
\r
2197 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2198 *ta++=LTCOL(psxVuw[startxy++]|0x8000);
\r
2203 dx=xrMovieArea.x1-xrMovieArea.x0;
\r
2204 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
\r
2210 xrMovieArea.x1+=b_X;xrMovieArea.y1+=b_Y;
\r
2211 DefineTextureMovie();
\r
2212 xrMovieArea.x1-=b_X;xrMovieArea.y1-=b_Y;
\r
2217 /////////////////////////////////////////////////////////////////////////////
\r
2218 /////////////////////////////////////////////////////////////////////////////
\r
2219 /////////////////////////////////////////////////////////////////////////////
\r
2221 GLuint BlackFake15BitTexture(void)
\r
2223 long pmult;short x1,x2,y1,y2;
\r
2225 if(PSXDisplay.InterlacedTest) return 0;
\r
2227 pmult=GlobalTexturePage/16;
\r
2229 x2=gl_ux[6]-gl_ux[7];
\r
2231 y2=gl_ux[4]-gl_ux[5];
\r
2240 x1+=((GlobalTexturePage-16*pmult)<<6);
\r
2242 if( FastCheckAgainstFrontScreen(x1,y1,x2,y2)
\r
2243 || FastCheckAgainstScreen(x1,y1,x2,y2))
\r
2245 if(!gTexFrameName)
\r
2247 glGenTextures(1, &gTexFrameName); glError();
\r
2248 gTexName=gTexFrameName;
\r
2249 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
2251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();
\r
2252 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();
\r
2253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();
\r
2254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();
\r
2257 unsigned long * ta=(unsigned long *)texturepart;
\r
2258 for(y1=0;y1<=4;y1++)
\r
2259 for(x1=0;x1<=4;x1++)
\r
2262 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();
\r
2267 gTexName=gTexFrameName;
\r
2268 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
2270 //LOGE("BlackFake15BitTexture x:%d y:%d",4,4);
\r
2273 return (GLuint)gTexName;
\r
2278 /////////////////////////////////////////////////////////////////////////////
\r
2280 BOOL bFakeFrontBuffer=FALSE;
\r
2281 BOOL bIgnoreNextTile =FALSE;
\r
2285 GLuint Fake15BitTexture(void)
\r
2287 long pmult;short x1,x2,y1,y2;int iYAdjust;
\r
2288 float ScaleX,ScaleY;RECT rSrc;
\r
2290 if(iFrameTexType==1) return BlackFake15BitTexture();
\r
2291 if(PSXDisplay.InterlacedTest) return 0;
\r
2293 pmult=GlobalTexturePage/16;
\r
2295 x2=gl_ux[6]-gl_ux[7];
\r
2297 y2=gl_ux[4]-gl_ux[5];
\r
2300 x1+=((GlobalTexturePage-16*pmult)<<6);
\r
2302 if(iFrameTexType==3)
\r
2304 if(iFrameReadType==4) return 0;
\r
2306 if(!FastCheckAgainstFrontScreen(x1,y1,x2,y2) &&
\r
2307 !FastCheckAgainstScreen(x1,y1,x2,y2))
\r
2310 if(bFakeFrontBuffer) bIgnoreNextTile=TRUE;
\r
2311 CheckVRamReadEx(x1,y1,x1+x2,y1+y2);
\r
2315 /////////////////////////
\r
2317 if(FastCheckAgainstFrontScreen(x1,y1,x2,y2))
\r
2319 x1-=PSXDisplay.DisplayPosition.x;
\r
2320 y1-=PSXDisplay.DisplayPosition.y;
\r
2323 if(FastCheckAgainstScreen(x1,y1,x2,y2))
\r
2325 x1-=PreviousPSXDisplay.DisplayPosition.x;
\r
2326 y1-=PreviousPSXDisplay.DisplayPosition.y;
\r
2330 bDrawMultiPass = FALSE;
\r
2332 if(!gTexFrameName)
\r
2336 if(iResX>1280 || iResY>1024) iFTex=2048;
\r
2338 if(iResX>640 || iResY>480) iFTex=1024;
\r
2341 glGenTextures(1, &gTexFrameName); glError();
\r
2342 gTexName=gTexFrameName;
\r
2343 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
2345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();
\r
2346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();
\r
2347 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();
\r
2348 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();
\r
2350 p=(char *)malloc(iFTex*iFTex*4);
\r
2351 memset(p,0,iFTex*iFTex*4);
\r
2352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iFTex, iFTex, 0, GL_RGBA, GL_UNSIGNED_BYTE, p); glError();
\r
2359 gTexName=gTexFrameName;
\r
2360 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
2362 //LOGE("Fake15BitTexture x:%d y:%d",iFTex,iFTex);
\r
2363 x1+=PreviousPSXDisplay.Range.x0;
\r
2364 y1+=PreviousPSXDisplay.Range.y0;
\r
2366 if(PSXDisplay.DisplayMode.x)
\r
2367 ScaleX=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;
\r
2369 if(PSXDisplay.DisplayMode.y)
\r
2370 ScaleY=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;
\r
2373 rSrc.left =max(x1*ScaleX,0);
\r
2374 rSrc.right =min((x1+x2)*ScaleX+0.99f,iResX-1);
\r
2375 rSrc.top =max(y1*ScaleY,0);
\r
2376 rSrc.bottom=min((y1+y2)*ScaleY+0.99f,iResY-1);
\r
2378 iYAdjust=(y1+y2)-PSXDisplay.DisplayMode.y;
\r
2380 iYAdjust=(int)((float)iYAdjust*ScaleY)+1;
\r
2383 gl_vy[0]=255-gl_vy[0];
\r
2384 gl_vy[1]=255-gl_vy[1];
\r
2385 gl_vy[2]=255-gl_vy[2];
\r
2386 gl_vy[3]=255-gl_vy[3];
\r
2388 y1=min(gl_vy[0],min(gl_vy[1],min(gl_vy[2],gl_vy[3])));
\r
2394 gl_ux[0]-=gl_ux[7];
\r
2395 gl_ux[1]-=gl_ux[7];
\r
2396 gl_ux[2]-=gl_ux[7];
\r
2397 gl_ux[3]-=gl_ux[7];
\r
2399 ScaleX*=256.0f/((float)(iFTex));
\r
2400 ScaleY*=256.0f/((float)(iFTex));
\r
2402 y1=((float)gl_vy[0]*ScaleY); if(y1>255) y1=255;
\r
2404 y1=((float)gl_vy[1]*ScaleY); if(y1>255) y1=255;
\r
2406 y1=((float)gl_vy[2]*ScaleY); if(y1>255) y1=255;
\r
2408 y1=((float)gl_vy[3]*ScaleY); if(y1>255) y1=255;
\r
2411 x1=((float)gl_ux[0]*ScaleX); if(x1>255) x1=255;
\r
2413 x1=((float)gl_ux[1]*ScaleX); if(x1>255) x1=255;
\r
2415 x1=((float)gl_ux[2]*ScaleX); if(x1>255) x1=255;
\r
2417 x1=((float)gl_ux[3]*ScaleX); if(x1>255) x1=255;
\r
2420 x1=rSrc.right-rSrc.left;
\r
2422 if(x1>iFTex) x1=iFTex;
\r
2424 y1=rSrc.bottom-rSrc.top;
\r
2426 if(y1+iYAdjust>iFTex) y1=iFTex-iYAdjust;
\r
2429 glCopyTexSubImage2D( GL_TEXTURE_2D, 0,
\r
2432 rSrc.left+rRatioRect.left,
\r
2433 iResY-rSrc.bottom-rRatioRect.top,
\r
2434 x1,y1); glError();
\r
2438 char * p=(char *)malloc(iFTex*iFTex*4);
\r
2439 memset(p,0,iFTex*iFTex*4);
\r
2440 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, iFTex, iFTex,
\r
2441 GL_RGBA, GL_UNSIGNED_BYTE, p); glError();
\r
2450 sprtW=gl_ux[1]-gl_ux[0];
\r
2451 sprtH=-(gl_vy[0]-gl_vy[2]);
\r
2454 return (GLuint)gTexName;
\r
2457 /////////////////////////////////////////////////////////////////////////////
\r
2458 /////////////////////////////////////////////////////////////////////////////
\r
2459 /////////////////////////////////////////////////////////////////////////////
\r
2461 // load texture part (unpacked)
\r
2463 /////////////////////////////////////////////////////////////////////////////
\r
2464 /////////////////////////////////////////////////////////////////////////////
\r
2465 /////////////////////////////////////////////////////////////////////////////
\r
2467 void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)
\r
2469 unsigned long start,row,column,j,sxh,sxm;
\r
2470 unsigned int palstart;
\r
2471 unsigned long *px,*pa,*ta;
\r
2472 unsigned char *cSRCPtr;
\r
2473 unsigned short *wSRCPtr;
\r
2474 unsigned long LineOffset;
\r
2475 unsigned long x2a,xalign=0;
\r
2476 unsigned long x1=gl_ux[7];
\r
2477 unsigned long x2=gl_ux[6];
\r
2478 unsigned long y1=gl_ux[5];
\r
2479 unsigned long y2=gl_ux[4];
\r
2480 unsigned long dx=x2-x1+1;
\r
2481 unsigned long dy=y2-y1+1;
\r
2482 int pmult=pageid/16;
\r
2483 unsigned long (*LTCOL)(unsigned long);
\r
2484 unsigned int a,r,g,b,cnt,h;
\r
2485 unsigned long scol[8];
\r
2487 LTCOL=TCF[DrawSemiTrans];
\r
2489 pa=px=(unsigned long *)ubPaletteBuffer;
\r
2490 ta=(unsigned long *)texturepart;
\r
2491 palstart=cx+(cy<<10);
\r
2495 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}
\r
2496 if(XTexS) {ta+=1;xalign=2;}
\r
2500 //--------------------------------------------------//
\r
2501 // 4bit texture load ..
\r
2505 unsigned int TXV,TXU,n_xi,n_yi;
\r
2507 wSRCPtr=psxVuw+palstart;
\r
2511 *px =LTCOL(*wSRCPtr);
\r
2512 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2513 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2514 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2515 row--;px+=4;wSRCPtr+=4;
\r
2519 for(TXV=y1;TXV<=y2;TXV++)
\r
2521 for(TXU=x1;TXU<=x2;TXU++)
\r
2523 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
2524 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
2526 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
2533 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2534 // convert CLUT to 32bits .. and then use THAT as a lookup table
\r
2536 wSRCPtr=psxVuw+palstart;
\r
2540 *px =LTCOL(*wSRCPtr);
\r
2541 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2542 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2543 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2544 row--;px+=4;wSRCPtr+=4;
\r
2548 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;
\r
2549 sxm=x1&1;sxh=x1>>1;
\r
2550 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;
\r
2551 for(column=y1;column<=y2;column++)
\r
2553 cSRCPtr = psxVub + start + (column<<11) + sxh;
\r
2555 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
2557 for(row=j;row<x2a;row+=2)
\r
2559 *ta =*(pa+(*cSRCPtr & 0xF));
\r
2560 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2566 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;
\r
2567 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2574 //--------------------------------------------------//
\r
2575 // 8bit texture load ..
\r
2579 unsigned int TXV,TXU,n_xi,n_yi;
\r
2581 wSRCPtr=psxVuw+palstart;
\r
2585 *px =LTCOL(*wSRCPtr);
\r
2586 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2587 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2588 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2589 row--;px+=4;wSRCPtr+=4;
\r
2593 for(TXV=y1;TXV<=y2;TXV++)
\r
2595 for(TXU=x1;TXU<=x2;TXU++)
\r
2597 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
2598 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
2600 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
2608 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2610 cSRCPtr = psxVub + start + (y1<<11) + x1;
\r
2611 LineOffset = 2048 - dx;
\r
2615 wSRCPtr=psxVuw+palstart;
\r
2619 *px =LTCOL(*wSRCPtr);
\r
2620 *(px+1)=LTCOL(*(wSRCPtr+1));
\r
2621 *(px+2)=LTCOL(*(wSRCPtr+2));
\r
2622 *(px+3)=LTCOL(*(wSRCPtr+3));
\r
2623 row--;px+=4;wSRCPtr+=4;
\r
2630 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);
\r
2632 cSRCPtr+=LineOffset;column--;
\r
2638 wSRCPtr=psxVuw+palstart;
\r
2643 do {*ta++=LTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);
\r
2645 cSRCPtr+=LineOffset;column--;
\r
2651 //--------------------------------------------------//
\r
2652 // 16bit texture load ..
\r
2654 start=((pageid-16*pmult)<<6)+262144*pmult;
\r
2656 wSRCPtr = psxVuw + start + (y1<<10) + x1;
\r
2657 LineOffset = 1024 - dx;
\r
2662 do {*ta++=LTCOL(*wSRCPtr++);row--;} while(row);
\r
2664 wSRCPtr+=LineOffset;column--;
\r
2669 //--------------------------------------------------//
\r
2670 // others are not possible !
\r
2677 ta=(unsigned long *)texturepart;
\r
2678 pa=(unsigned long *)texturepart+x2a;
\r
2679 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
2680 pa=(unsigned long *)texturepart+dy*x2a;
\r
2682 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
2689 ta=(unsigned long *)texturepart;
\r
2691 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
2692 pa=(unsigned long *)texturepart+dx;
\r
2694 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
2699 DXTexS=dx;DYTexS=dy;
\r
2701 if(!iFilterType) {DefineSubTextureSort();return;}
\r
2702 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}
\r
2703 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)
\r
2704 {DefineSubTextureSort();return;}
\r
2706 ta=(unsigned long *)texturepart;
\r
2713 for(column=0;column<dy;column++)
\r
2715 for(row=0;row<dx;row++)
\r
2717 if(*ta==0x50000000)
\r
2721 if( column && *(ta-dx) !=0x50000000 && *(ta-dx)>>24!=1) scol[cnt++]=*(ta-dx);
\r
2722 if(row && *(ta-1) !=0x50000000 && *(ta-1)>>24!=1) scol[cnt++]=*(ta-1);
\r
2723 if(row!=x1 && *(ta+1) !=0x50000000 && *(ta+1)>>24!=1) scol[cnt++]=*(ta+1);
\r
2724 if( column!=y1 && *(ta+dx) !=0x50000000 && *(ta+dx)>>24!=1) scol[cnt++]=*(ta+dx);
\r
2726 if(row && column && *(ta-dx-1)!=0x50000000 && *(ta-dx-1)>>24!=1) scol[cnt++]=*(ta-dx-1);
\r
2727 if(row!=x1 && column && *(ta-dx+1)!=0x50000000 && *(ta-dx+1)>>24!=1) scol[cnt++]=*(ta-dx+1);
\r
2728 if(row && column!=y1 && *(ta+dx-1)!=0x50000000 && *(ta+dx-1)>>24!=1) scol[cnt++]=*(ta+dx-1);
\r
2729 if(row!=x1 && column!=y1 && *(ta+dx+1)!=0x50000000 && *(ta+dx+1)>>24!=1) scol[cnt++]=*(ta+dx+1);
\r
2734 for(h=0;h<cnt;h++)
\r
2737 r+=(scol[h]>>16)&0xff;
\r
2738 g+=(scol[h]>>8)&0xff;
\r
2741 r/=cnt;b/=cnt;g/=cnt;
\r
2743 *ta=(r<<16)|(g<<8)|b;
\r
2744 if(a) *ta|=0x50000000;
\r
2745 else *ta|=0x01000000;
\r
2754 for(column=0;column<dy;column++)
\r
2756 for(row=0;row<dx;row++)
\r
2758 if(*ta==0x00000000)
\r
2762 if(row!=x1 && *(ta+1) !=0x00000000) scol[cnt++]=*(ta+1);
\r
2763 if( column!=y1 && *(ta+dx) !=0x00000000) scol[cnt++]=*(ta+dx);
\r
2768 for(h=0;h<cnt;h++)
\r
2770 r+=(scol[h]>>16)&0xff;
\r
2771 g+=(scol[h]>>8)&0xff;
\r
2774 r/=cnt;b/=cnt;g/=cnt;
\r
2775 *ta=(r<<16)|(g<<8)|b;
\r
2782 DefineSubTextureSort();
\r
2785 /////////////////////////////////////////////////////////////////////////////
\r
2786 /////////////////////////////////////////////////////////////////////////////
\r
2787 /////////////////////////////////////////////////////////////////////////////
\r
2789 // load texture part (packed)
\r
2791 /////////////////////////////////////////////////////////////////////////////
\r
2792 /////////////////////////////////////////////////////////////////////////////
\r
2793 /////////////////////////////////////////////////////////////////////////////
\r
2795 void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
\r
2797 unsigned long start,row,column,j,sxh,sxm;
\r
2798 unsigned int palstart;
\r
2799 unsigned short *px,*pa,*ta;
\r
2800 unsigned char *cSRCPtr;
\r
2801 unsigned short *wSRCPtr;
\r
2802 unsigned long LineOffset;
\r
2803 unsigned long x2a,xalign=0;
\r
2804 unsigned long x1=gl_ux[7];
\r
2805 unsigned long x2=gl_ux[6];
\r
2806 unsigned long y1=gl_ux[5];
\r
2807 unsigned long y2=gl_ux[4];
\r
2808 unsigned long dx=x2-x1+1;
\r
2809 unsigned long dy=y2-y1+1;
\r
2810 int pmult=pageid/16;
\r
2811 unsigned short (*LPTCOL)(unsigned short);
\r
2812 unsigned int a,r,g,b,cnt,h;
\r
2813 unsigned short scol[8];
\r
2815 LPTCOL=PTCF[DrawSemiTrans];
\r
2817 pa=px=(unsigned short *)ubPaletteBuffer;
\r
2818 ta=(unsigned short *)texturepart;
\r
2819 palstart=cx+(cy<<10);
\r
2823 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}
\r
2824 if(XTexS) {ta+=1;xalign=2;}
\r
2828 //--------------------------------------------------//
\r
2829 // 4bit texture load ..
\r
2833 unsigned int TXV,TXU,n_xi,n_yi;
\r
2835 wSRCPtr=psxVuw+palstart;
\r
2838 *px =LPTCOL(*wSRCPtr);
\r
2839 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2840 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2841 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2842 row--;px+=4;wSRCPtr+=4;
\r
2846 for(TXV=y1;TXV<=y2;TXV++)
\r
2848 for(TXU=x1;TXU<=x2;TXU++)
\r
2850 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
\r
2851 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
\r
2853 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
\r
2860 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2862 wSRCPtr=psxVuw+palstart;
\r
2865 *px =LPTCOL(*wSRCPtr);
\r
2866 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2867 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2868 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2869 row--;px+=4;wSRCPtr+=4;
\r
2873 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;
\r
2874 sxm=x1&1;sxh=x1>>1;
\r
2875 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;
\r
2877 for(column=y1;column<=y2;column++)
\r
2879 cSRCPtr = psxVub + start + (column<<11) + sxh;
\r
2881 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));
\r
2883 for(row=j;row<x2a;row+=2)
\r
2885 *ta =*(pa+(*cSRCPtr & 0xF));
\r
2886 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2892 *ta++=*(pa+(*cSRCPtr & 0xF));row++;
\r
2893 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));
\r
2899 //--------------------------------------------------//
\r
2900 // 8bit texture load ..
\r
2904 unsigned int TXV,TXU,n_xi,n_yi;
\r
2906 wSRCPtr=psxVuw+palstart;
\r
2910 *px =LPTCOL(*wSRCPtr);
\r
2911 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2912 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2913 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2914 row--;px+=4;wSRCPtr+=4;
\r
2918 for(TXV=y1;TXV<=y2;TXV++)
\r
2920 for(TXU=x1;TXU<=x2;TXU++)
\r
2922 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
\r
2923 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
\r
2925 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
\r
2933 start=((pageid-16*pmult)<<7)+524288*pmult;
\r
2935 cSRCPtr = psxVub + start + (y1<<11) + x1;
\r
2936 LineOffset = 2048 - dx;
\r
2938 if(dy*dx>384) // more pix? use lut
\r
2940 wSRCPtr=psxVuw+palstart;
\r
2944 *px =LPTCOL(*wSRCPtr);
\r
2945 *(px+1)=LPTCOL(*(wSRCPtr+1));
\r
2946 *(px+2)=LPTCOL(*(wSRCPtr+2));
\r
2947 *(px+3)=LPTCOL(*(wSRCPtr+3));
\r
2948 row--;px+=4;wSRCPtr+=4;
\r
2955 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);
\r
2959 cSRCPtr+=LineOffset;column--;
\r
2963 else // small area? no lut
\r
2965 wSRCPtr=psxVuw+palstart;
\r
2970 do {*ta++=LPTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);
\r
2974 cSRCPtr+=LineOffset;column--;
\r
2979 //--------------------------------------------------//
\r
2980 // 16bit texture load ..
\r
2982 start=((pageid-16*pmult)<<6)+262144*pmult;
\r
2984 wSRCPtr = psxVuw + start + (y1<<10) + x1;
\r
2985 LineOffset = 1024 - dx;
\r
2990 do {*ta++=LPTCOL(*wSRCPtr++);row--;} while(row);
\r
2994 wSRCPtr+=LineOffset;column--;
\r
2998 //--------------------------------------------------//
\r
2999 // others are not possible !
\r
3002 ////////////////////////////////////////////////////////
\r
3008 ta=(unsigned short *)texturepart;
\r
3009 pa=(unsigned short *)texturepart+x2a;
\r
3010 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
3012 pa=(unsigned short *)texturepart+dy*x2a;
\r
3014 row=x2a;do {*ta++=*pa++;row--;} while(row);
\r
3022 ta=(unsigned short *)texturepart;
\r
3024 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
3026 pa=(unsigned short *)texturepart+dx;
\r
3028 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);
\r
3034 DXTexS=dx;DYTexS=dy;
\r
3036 if(!iFilterType) {DefineSubTextureSort();return;}
\r
3037 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}
\r
3038 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)
\r
3039 {DefineSubTextureSort();return;}
\r
3041 ta=(unsigned short *)texturepart;
\r
3046 for(column=0;column<dy;column++)
\r
3048 for(row=0;row<dx;row++)
\r
3054 if( column && *(ta-dx) &1) scol[cnt++]=*(ta-dx);
\r
3055 if(row && *(ta-1) &1) scol[cnt++]=*(ta-1);
\r
3056 if(row!=x1 && *(ta+1) &1) scol[cnt++]=*(ta+1);
\r
3057 if( column!=y1 && *(ta+dx) &1) scol[cnt++]=*(ta+dx);
\r
3059 if(row && column && *(ta-dx-1)&1) scol[cnt++]=*(ta-dx-1);
\r
3060 if(row!=x1 && column && *(ta-dx+1)&1) scol[cnt++]=*(ta-dx+1);
\r
3061 if(row && column!=y1 && *(ta+dx-1)&1) scol[cnt++]=*(ta+dx-1);
\r
3062 if(row!=x1 && column!=y1 && *(ta+dx+1)&1) scol[cnt++]=*(ta+dx+1);
\r
3067 for(h=0;h<cnt;h++)
\r
3070 g+=(scol[h]>>6)&0x1f;
\r
3071 b+=(scol[h]>>1)&0x1f;
\r
3073 r/=cnt;b/=cnt;g/=cnt;
\r
3074 *ta=(r<<11)|(g<<6)|(b<<1);
\r
3082 DefineSubTextureSort();
\r
3085 /////////////////////////////////////////////////////////////////////////////
\r
3087 /////////////////////////////////////////////////////////////////////////////
\r
3088 /////////////////////////////////////////////////////////////////////////////
\r
3089 /////////////////////////////////////////////////////////////////////////////
\r
3091 // hires texture funcs
\r
3093 /////////////////////////////////////////////////////////////////////////////
\r
3094 /////////////////////////////////////////////////////////////////////////////
\r
3095 /////////////////////////////////////////////////////////////////////////////
\r
3098 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
\r
3100 ////////////////////////////////////////////////////////////////////////
\r
3102 #define colorMask8 0x00FEFEFE
\r
3103 #define lowPixelMask8 0x00010101
\r
3104 #define qcolorMask8 0x00FCFCFC
\r
3105 #define qlowpixelMask8 0x00030303
\r
3108 #define INTERPOLATE8_02(A, B) (((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8))|((((A&0xFF000000)==0x03000000)?0x03000000:(((B&0xFF000000)==0x03000000)?0x03000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))
\r
3110 #define Q_INTERPOLATE8_02(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x03000000)?0x03000000:(((B&0xFF000000)==0x03000000)?0x03000000:(((C&0xFF000000)==0x03000000)?0x03000000:(((D&0xFF000000)==0x03000000)?0x03000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))
\r
3112 #define INTERPOLATE8(A, B) (((((A & colorMask8) >> 1) + ((B & colorMask8) >> 1) + (A & B & lowPixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))
\r
3114 #define Q_INTERPOLATE8(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((C&0xFF000000)==0x50000000)?0x50000000:(((D&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))
\r
3116 void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,
\r
3117 unsigned char *dstBitmap, int width, int height)
\r
3119 DWORD dstPitch = srcPitch * 2;
\r
3123 int width2 = width*2;
\r
3124 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
\r
3125 DWORD color4, color5, color6;
\r
3126 DWORD color1, color2, color3;
\r
3127 DWORD colorA0, colorA1, colorA2, colorA3,
\r
3128 colorB0, colorB1, colorB2, colorB3,
\r
3130 DWORD product1a, product1b,
\r
3131 product2a, product2b;
\r
3136 for (; height; height-=1)
\r
3138 bP = (DWORD *)srcPtr;
\r
3139 dP = (DWORD *)(dstBitmap + line*dstPitch);
\r
3140 for (finish = width; finish; finish -= 1 )
\r
3142 //--------------------------------------- B1 B2
\r
3146 if(finish==width) iXA=0;
\r
3148 if(finish>4) {iXB=1;iXC=2;}
\r
3150 if(finish>3) {iXB=1;iXC=1;}
\r
3151 else {iXB=0;iXC=0;}
\r
3152 if(line==0) iYA=0;
\r
3154 if(height>4) {iYB=width;iYC=width2;}
\r
3156 if(height>3) {iYB=width;iYC=width;}
\r
3157 else {iYB=0;iYC=0;}
\r
3160 colorB0 = *(bP- iYA - iXA);
\r
3161 colorB1 = *(bP- iYA);
\r
3162 colorB2 = *(bP- iYA + iXB);
\r
3163 colorB3 = *(bP- iYA + iXC);
\r
3165 color4 = *(bP - iXA);
\r
3167 color6 = *(bP + iXB);
\r
3168 colorS2 = *(bP + iXC);
\r
3170 color1 = *(bP + iYB - iXA);
\r
3171 color2 = *(bP + iYB);
\r
3172 color3 = *(bP + iYB + iXB);
\r
3173 colorS1= *(bP + iYB + iXC);
\r
3175 colorA0 = *(bP + iYC - iXA);
\r
3176 colorA1 = *(bP + iYC);
\r
3177 colorA2 = *(bP + iYC + iXB);
\r
3178 colorA3 = *(bP + iYC + iXC);
\r
3180 //--------------------------------------
\r
3181 if (color2 == color6 && color5 != color3)
\r
3183 product2b = product1b = color2;
\r
3186 if (color5 == color3 && color2 != color6)
\r
3188 product2b = product1b = color5;
\r
3191 if (color5 == color3 && color2 == color6)
\r
3193 register int r = 0;
\r
3195 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
\r
3196 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
\r
3197 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
\r
3198 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
\r
3201 product2b = product1b = color6;
\r
3204 product2b = product1b = color5;
\r
3207 product2b = product1b = INTERPOLATE8_02(color5, color6);
\r
3212 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
\r
3213 product2b = Q_INTERPOLATE8_02 (color3, color3, color3, color2);
\r
3215 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
\r
3216 product2b = Q_INTERPOLATE8_02 (color2, color2, color2, color3);
\r
3218 product2b = INTERPOLATE8_02 (color2, color3);
\r
3220 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
\r
3221 product1b = Q_INTERPOLATE8_02 (color6, color6, color6, color5);
\r
3223 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
\r
3224 product1b = Q_INTERPOLATE8_02 (color6, color5, color5, color5);
\r
3226 product1b = INTERPOLATE8_02 (color5, color6);
\r
3229 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
\r
3230 product2a = INTERPOLATE8_02(color2, color5);
\r
3232 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
\r
3233 product2a = INTERPOLATE8_02(color2, color5);
\r
3235 product2a = color2;
\r
3237 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
\r
3238 product1a = INTERPOLATE8_02(color2, color5);
\r
3240 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
\r
3241 product1a = INTERPOLATE8_02(color2, color5);
\r
3243 product1a = color5;
\r
3246 *(dP+1)=product1b;
\r
3247 *(dP+(width2))=product2a;
\r
3248 *(dP+1+(width2))=product2b;
\r
3252 }//end of for ( finish= width etc..)
\r
3255 srcPtr += srcPitch;
\r
3256 }; //endof: for (; height; height--)
\r
3261 void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
\r
3262 unsigned char *dstBitmap, int width, int height)
\r
3264 DWORD dstPitch = srcPitch * 2;
\r
3268 int width2 = width*2;
\r
3269 int iXA,iXB,iXC,iYA,iYB,iYC,finish;
\r
3270 DWORD color4, color5, color6;
\r
3271 DWORD color1, color2, color3;
\r
3272 DWORD colorA0, colorA1, colorA2, colorA3,
\r
3273 colorB0, colorB1, colorB2, colorB3,
\r
3275 DWORD product1a, product1b,
\r
3276 product2a, product2b;
\r
3281 for (; height; height-=1)
\r
3283 bP = (DWORD *)srcPtr;
\r
3284 dP = (DWORD *)(dstBitmap + line*dstPitch);
\r
3285 for (finish = width; finish; finish -= 1 )
\r
3287 //--------------------------------------- B1 B2
\r
3291 if(finish==width) iXA=0;
\r
3293 if(finish>4) {iXB=1;iXC=2;}
\r
3295 if(finish>3) {iXB=1;iXC=1;}
\r
3296 else {iXB=0;iXC=0;}
\r
3297 if(line==0) iYA=0;
\r
3299 if(height>4) {iYB=width;iYC=width2;}
\r
3301 if(height>3) {iYB=width;iYC=width;}
\r
3302 else {iYB=0;iYC=0;}
\r
3305 colorB0 = *(bP- iYA - iXA);
\r
3306 colorB1 = *(bP- iYA);
\r
3307 colorB2 = *(bP- iYA + iXB);
\r
3308 colorB3 = *(bP- iYA + iXC);
\r
3310 color4 = *(bP - iXA);
\r
3312 color6 = *(bP + iXB);
\r
3313 colorS2 = *(bP + iXC);
\r
3315 color1 = *(bP + iYB - iXA);
\r
3316 color2 = *(bP + iYB);
\r
3317 color3 = *(bP + iYB + iXB);
\r
3318 colorS1= *(bP + iYB + iXC);
\r
3320 colorA0 = *(bP + iYC - iXA);
\r
3321 colorA1 = *(bP + iYC);
\r
3322 colorA2 = *(bP + iYC + iXB);
\r
3323 colorA3 = *(bP + iYC + iXC);
\r
3325 //--------------------------------------
\r
3326 if (color2 == color6 && color5 != color3)
\r
3328 product2b = product1b = color2;
\r
3331 if (color5 == color3 && color2 != color6)
\r
3333 product2b = product1b = color5;
\r
3336 if (color5 == color3 && color2 == color6)
\r
3338 register int r = 0;
\r
3340 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));
\r
3341 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));
\r
3342 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));
\r
3343 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));
\r
3346 product2b = product1b = color6;
\r
3349 product2b = product1b = color5;
\r
3352 product2b = product1b = INTERPOLATE8(color5, color6);
\r
3357 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
\r
3358 product2b = Q_INTERPOLATE8 (color3, color3, color3, color2);
\r
3360 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
\r
3361 product2b = Q_INTERPOLATE8 (color2, color2, color2, color3);
\r
3363 product2b = INTERPOLATE8 (color2, color3);
\r
3365 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
\r
3366 product1b = Q_INTERPOLATE8 (color6, color6, color6, color5);
\r
3368 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
\r
3369 product1b = Q_INTERPOLATE8 (color6, color5, color5, color5);
\r
3371 product1b = INTERPOLATE8 (color5, color6);
\r
3374 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
\r
3375 product2a = INTERPOLATE8(color2, color5);
\r
3377 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
\r
3378 product2a = INTERPOLATE8(color2, color5);
\r
3380 product2a = color2;
\r
3382 if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
\r
3383 product1a = INTERPOLATE8(color2, color5);
\r
3385 if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
\r
3386 product1a = INTERPOLATE8(color2, color5);
\r
3388 product1a = color5;
\r
3391 *(dP+1)=product1b;
\r
3392 *(dP+(width2))=product2a;
\r
3393 *(dP+1+(width2))=product2b;
\r
3397 }//end of for ( finish= width etc..)
\r
3400 srcPtr += srcPitch;
\r
3401 }; //endof: for (; height; height--)
\r
3404 /////////////////////////////////////////////////////////////////////////////
\r
3406 #define colorMask4 0x0000EEE0
\r
3407 #define lowPixelMask4 0x00001110
\r
3408 #define qcolorMask4 0x0000CCC0
\r
3409 #define qlowpixelMask4 0x00003330
\r
3411 #define INTERPOLATE4(A, B) ((((A & colorMask4) >> 1) + ((B & colorMask4) >> 1) + (A & B & lowPixelMask4))|((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))
\r
3413 #define Q_INTERPOLATE4(A, B, C, D) ((((A & qcolorMask4) >> 2) + ((B & qcolorMask4) >> 2) + ((C & qcolorMask4) >> 2) + ((D & qcolorMask4) >> 2) + ((((A & qlowpixelMask4) + (B & qlowpixelMask4) + (C & qlowpixelMask4) + (D & qlowpixelMask4)) >> 2) & qlowpixelMask4))| ((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((C&0x0000000F)==0x00000006)?0x00000006:(((D&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:(((C&0x0000000F)==0x00000000)?0x00000000:(((D&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))))))
\r
3416 #define colorMask5 0x0000F7BC
\r
3417 #define lowPixelMask5 0x00000842
\r
3418 #define qcolorMask5 0x0000E738
\r
3419 #define qlowpixelMask5 0x000018C6
\r
3421 #define INTERPOLATE5(A, B) ((((A & colorMask5) >> 1) + ((B & colorMask5) >> 1) + (A & B & lowPixelMask5))|((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:0x00000001))))
\r
3423 #define Q_INTERPOLATE5(A, B, C, D) ((((A & qcolorMask5) >> 2) + ((B & qcolorMask5) >> 2) + ((C & qcolorMask5) >> 2) + ((D & qcolorMask5) >> 2) + ((((A & qlowpixelMask5) + (B & qlowpixelMask5) + (C & qlowpixelMask5) + (D & qlowpixelMask5)) >> 2) & qlowpixelMask5))| ((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:(((C&0x00000001)==0x00000000)?0x00000000:(((D&0x00000001)==0x00000000)?0x00000000:0x00000001))))))
\r
3424 /////////////////////////////////////////////////////////////////////////////
\r
3425 /////////////////////////////////////////////////////////////////////////////
\r
3426 /////////////////////////////////////////////////////////////////////////////
\r
3428 // ogl texture defines
\r
3430 /////////////////////////////////////////////////////////////////////////////
\r
3431 /////////////////////////////////////////////////////////////////////////////
\r
3432 /////////////////////////////////////////////////////////////////////////////
\r
3434 void DefineSubTextureSortHiRes(void)
\r
3440 glGenTextures(1, &gTexName); glError();
\r
3441 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
3443 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();
\r
3444 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();
\r
3448 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();
\r
3449 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();
\r
3453 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();
\r
3454 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();
\r
3456 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturebuffer); glError();
\r
3458 else glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
3460 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS<<1, YTexS<<1,
\r
3461 DXTexS<<1, DYTexS<<1,
\r
3462 GL_RGBA, GL_UNSIGNED_BYTE, texturebuffer); glError();
\r
3463 //LOGE("DefineSubTextureSortHiRes x:%d y:%d",XTexS<<1,YTexS<<1);
\r
3466 /////////////////////////////////////////////////////////////////////////////
\r
3468 void DefineSubTextureSort(void)
\r
3473 glGenTextures(1, &gTexName); glError();
\r
3474 glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
3476 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();
\r
3477 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();
\r
3481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();
\r
3482 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();
\r
3486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();
\r
3487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();
\r
3489 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();
\r
3491 else glBindTexture(GL_TEXTURE_2D, gTexName); glError();
\r
3493 glTexSubImage2D(GL_TEXTURE_2D, 0, XTexS, YTexS,
\r
3495 GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();
\r
3496 //LOGE("DefineSubTextureSort x:%d y:%d w:%d h:%d",XTexS,YTexS,DXTexS,DYTexS);
\r
3499 /////////////////////////////////////////////////////////////////////////////
\r
3501 /////////////////////////////////////////////////////////////////////////////
\r
3502 /////////////////////////////////////////////////////////////////////////////
\r
3503 /////////////////////////////////////////////////////////////////////////////
\r
3505 // texture cache garbage collection
\r
3507 /////////////////////////////////////////////////////////////////////////////
\r
3508 /////////////////////////////////////////////////////////////////////////////
\r
3509 /////////////////////////////////////////////////////////////////////////////
\r
3511 void DoTexGarbageCollection(void)
\r
3513 static unsigned short LRUCleaned=0;
\r
3514 unsigned short iC,iC1,iC2;
\r
3515 int i,j,iMax;textureSubCacheEntryS * tsb;
\r
3517 iC=4;//=iSortTexCnt/2,
\r
3518 LRUCleaned+=iC; // we clean different textures each time
\r
3519 if((LRUCleaned+iC)>=iSortTexCnt) LRUCleaned=0; // wrap? wrap!
\r
3520 iC1=LRUCleaned; // range of textures to clean
\r
3521 iC2=LRUCleaned+iC;
\r
3523 for(iC=iC1;iC<iC2;iC++) // make some textures available
\r
3525 pxSsubtexLeft[iC]->l=0;
\r
3528 for(i=0;i<3;i++) // remove all references to that textures
\r
3529 for(j=0;j<MAXTPAGES;j++)
\r
3530 for(iC=0;iC<4;iC++) // loop all texture rect info areas
\r
3532 tsb=pscSubtexStore[i][j]+(iC*SOFFB);
\r
3538 if(tsb->cTexID>=iC1 && tsb->cTexID<iC2) // info uses the cleaned textures? remove info
\r
3544 usLRUTexPage=LRUCleaned;
\r
3547 /////////////////////////////////////////////////////////////////////////////
\r
3548 /////////////////////////////////////////////////////////////////////////////
\r
3549 /////////////////////////////////////////////////////////////////////////////
\r
3551 // search cache for existing (already used) parts
\r
3553 /////////////////////////////////////////////////////////////////////////////
\r
3554 /////////////////////////////////////////////////////////////////////////////
\r
3555 /////////////////////////////////////////////////////////////////////////////
\r
3557 unsigned char * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache)
\r
3559 textureSubCacheEntryS * tsx, * tsb, *tsg;//, *tse=NULL;
\r
3560 int i,iMax;EXLong npos;
\r
3561 unsigned char cx,cy;
\r
3562 int iC,j,k;unsigned long rx,ry,mx,my;
\r
3563 EXLong * ul=0, * uls;
\r
3565 unsigned char cXAdj,cYAdj;
\r
3567 npos.l=*((unsigned long *)&gl_ux[4]);
\r
3569 //--------------------------------------------------------------//
\r
3570 // find matching texturepart first... speed up...
\r
3571 //--------------------------------------------------------------//
\r
3573 tsg=pscSubtexStore[TextureMode][GlobalTexturePage];
\r
3574 tsg+=((GivenClutId&CLUTCHK)>>CLUTSHIFT)*SOFFB;
\r
3583 if(GivenClutId==tsb->ClutID &&
\r
3584 (INCHECK(tsb->pos,npos)))
\r
3587 cx=tsb->pos.c[3]-tsb->posTX;
\r
3588 cy=tsb->pos.c[1]-tsb->posTY;
\r
3599 ubOpaqueDraw=tsb->Opaque;
\r
3600 *pCache=tsb->cTexID;
\r
3609 //----------------------------------------------------//
\r
3613 rx=(int)gl_ux[6]-(int)gl_ux[7];
\r
3614 ry=(int)gl_ux[4]-(int)gl_ux[5];
\r
3616 tsx=NULL;tsb=tsg+1;
\r
3617 for(i=0;i<iMax;i++,tsb++)
\r
3619 if(!tsb->ClutID) {tsx=tsb;break;}
\r
3625 if(iMax>=SOFFB-2)
\r
3627 if(iTexGarbageCollection) // gc mode?
\r
3631 dwTexPageComp|=(1<<GlobalTexturePage);
\r
3639 for(i=0;i<iMax;i++,tsb++) // 1. search other slots with same cluts, and unite the area
\r
3640 if(GivenClutId==tsb->ClutID)
\r
3642 if(!tsx) {tsx=tsb;rfree.l=npos.l;} //
\r
3643 else tsb->ClutID=0;
\r
3644 rfree.c[3]=min(rfree.c[3],tsb->pos.c[3]);
\r
3645 rfree.c[2]=max(rfree.c[2],tsb->pos.c[2]);
\r
3646 rfree.c[1]=min(rfree.c[1],tsb->pos.c[1]);
\r
3647 rfree.c[0]=max(rfree.c[0],tsb->pos.c[0]);
\r
3651 if(tsx) // 3. if one or more found, create a new rect with bigger size
\r
3653 *((unsigned long *)&gl_ux[4])=npos.l=rfree.l;
\r
3654 rx=(int)rfree.c[2]-(int)rfree.c[3];
\r
3655 ry=(int)rfree.c[0]-(int)rfree.c[1];
\r
3656 DoTexGarbageCollection();
\r
3668 //----------------------------------------------------//
\r
3669 // now get a free texture space
\r
3670 //----------------------------------------------------//
\r
3672 if(iTexGarbageCollection) usLRUTexPage=0;
\r
3676 rx+=3;if(rx>255) {cXAdj=0;rx=255;}
\r
3677 ry+=3;if(ry>255) {cYAdj=0;ry=255;}
\r
3681 for(k=0;k<iSortTexCnt;k++)
\r
3683 uls=pxSsubtexLeft[iC];
\r
3684 iMax=uls->l;ul=uls+1;
\r
3686 //--------------------------------------------------//
\r
3693 if(rx>252 && ry>252)
\r
3694 {uls->l=1;ul->l=0xffffffff;ul=0;goto ENDLOOP;}
\r
3718 //--------------------------------------------------//
\r
3719 for(i=0;i<iMax;i++,ul++)
\r
3721 if(ul->l!=0xffffffff &&
\r
3728 if(rx<mx && ry<my)
\r
3734 for(ul=uls+1,j=0;j<iMax;j++,ul++)
\r
3735 if(ul->l==0xffffffff) break;
\r
3739 if(j==iMax) uls->l=uls->l+1;
\r
3741 ul->c[3]=rfree.c[3];
\r
3742 ul->c[2]=rfree.c[2];
\r
3743 ul->c[1]=rfree.c[1]+ry;
\r
3744 ul->c[0]=rfree.c[0]-ry;
\r
3766 //--------------------------------------------------//
\r
3768 iC++; if(iC>=iSortTexCnt) iC=0;
\r
3771 //----------------------------------------------------//
\r
3772 // check, if free space got
\r
3773 //----------------------------------------------------//
\r
3778 //////////////////////////////////////////////////////
\r
3783 for(i=0;i<3;i++) // cleaning up
\r
3784 for(j=0;j<MAXTPAGES;j++)
\r
3786 tsb=pscSubtexStore[i][j];
\r
3787 (tsb+SOFFA)->pos.l=0;
\r
3788 (tsb+SOFFB)->pos.l=0;
\r
3789 (tsb+SOFFC)->pos.l=0;
\r
3790 (tsb+SOFFD)->pos.l=0;
\r
3792 for(i=0;i<iSortTexCnt;i++)
\r
3793 {ul=pxSsubtexLeft[i];ul->l=0;}
\r
3797 //////////////////////////////////////////////////////
\r
3799 uls=pxSsubtexLeft[usLRUTexPage];
\r
3800 uls->l=0;ul=uls+1;
\r
3803 if(rx>252 && ry>252)
\r
3804 {uls->l=1;ul->l=0xffffffff;}
\r
3825 tsg->pos.l=1;tsx=tsg+1;
\r
3828 rfree.c[3]+=cXAdj;
\r
3829 rfree.c[1]+=cYAdj;
\r
3831 tsx->cTexID =*pCache=iC;
\r
3833 tsx->ClutID = GivenClutId;
\r
3834 tsx->posTX = rfree.c[3];
\r
3835 tsx->posTY = rfree.c[1];
\r
3837 cx=gl_ux[7]-rfree.c[3];
\r
3838 cy=gl_ux[5]-rfree.c[1];
\r
3852 return &tsx->Opaque;
\r
3855 /////////////////////////////////////////////////////////////////////////////
\r
3856 /////////////////////////////////////////////////////////////////////////////
\r
3857 /////////////////////////////////////////////////////////////////////////////
\r
3859 // search cache for free place (on compress)
\r
3861 /////////////////////////////////////////////////////////////////////////////
\r
3862 /////////////////////////////////////////////////////////////////////////////
\r
3863 /////////////////////////////////////////////////////////////////////////////
\r
3865 BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)
\r
3867 int i,j,k,iMax,iC;unsigned long rx,ry,mx,my;
\r
3868 EXLong * ul=0, * uls, rfree;
\r
3869 unsigned char cXAdj=1,cYAdj=1;
\r
3871 rx=(int)tsx->pos.c[2]-(int)tsx->pos.c[3];
\r
3872 ry=(int)tsx->pos.c[0]-(int)tsx->pos.c[1];
\r
3874 rx+=3;if(rx>255) {cXAdj=0;rx=255;}
\r
3875 ry+=3;if(ry>255) {cYAdj=0;ry=255;}
\r
3879 for(k=0;k<iSortTexCnt;k++)
\r
3881 uls=pxSsubtexLeft[iC];
\r
3882 iMax=uls->l;ul=uls+1;
\r
3884 //--------------------------------------------------//
\r
3891 if(rx>252 && ry>252)
\r
3892 {uls->l=1;ul->l=0xffffffff;ul=0;goto TENDLOOP;}
\r
3916 //--------------------------------------------------//
\r
3917 for(i=0;i<iMax;i++,ul++)
\r
3919 if(ul->l!=0xffffffff &&
\r
3927 if(rx<mx && ry<my)
\r
3933 for(ul=uls+1,j=0;j<iMax;j++,ul++)
\r
3934 if(ul->l==0xffffffff) break;
\r
3938 if(j==iMax) uls->l=uls->l+1;
\r
3940 ul->c[3]=rfree.c[3];
\r
3941 ul->c[2]=rfree.c[2];
\r
3942 ul->c[1]=rfree.c[1]+ry;
\r
3943 ul->c[0]=rfree.c[0]-ry;
\r
3965 //--------------------------------------------------//
\r
3967 iC++; if(iC>=iSortTexCnt) iC=0;
\r
3970 //----------------------------------------------------//
\r
3971 // check, if free space got
\r
3972 //----------------------------------------------------//
\r
3975 if(ul) return FALSE;
\r
3977 rfree.c[3]+=cXAdj;
\r
3978 rfree.c[1]+=cYAdj;
\r
3981 tsx->posTX = rfree.c[3];
\r
3982 tsx->posTY = rfree.c[1];
\r
3990 /////////////////////////////////////////////////////////////////////////////
\r
3991 /////////////////////////////////////////////////////////////////////////////
\r
3992 /////////////////////////////////////////////////////////////////////////////
\r
3994 // compress texture cache (to make place for new texture part, if needed)
\r
3996 /////////////////////////////////////////////////////////////////////////////
\r
3997 /////////////////////////////////////////////////////////////////////////////
\r
3998 /////////////////////////////////////////////////////////////////////////////
\r
4000 void CompressTextureSpace(void)
\r
4002 textureSubCacheEntryS * tsx, * tsg, * tsb;
\r
4003 int i,j,k,m,n,iMax;EXLong * ul, r,opos;
\r
4004 short sOldDST=DrawSemiTrans,cx,cy;
\r
4005 long lOGTP=GlobalTexturePage;
\r
4006 unsigned long l,row;
\r
4007 unsigned long * lSRCPtr;
\r
4009 opos.l=*((unsigned long *)&gl_ux[4]);
\r
4011 // 1. mark all textures as free
\r
4012 for(i=0;i<iSortTexCnt;i++)
\r
4013 {ul=pxSsubtexLeft[i];ul->l=0;}
\r
4019 for(k=0;k<MAXTPAGES;k++)
\r
4021 tsg=pscSubtexStore[j][k];
\r
4023 if((!(dwTexPageComp&(1<<k))))
\r
4025 (tsg+SOFFA)->pos.l=0;
\r
4026 (tsg+SOFFB)->pos.l=0;
\r
4027 (tsg+SOFFC)->pos.l=0;
\r
4028 (tsg+SOFFD)->pos.l=0;
\r
4032 for(m=0;m<4;m++,tsg+=SOFFB)
\r
4037 for(i=0;i<iMax;i++,tsx++)
\r
4042 for(n=i+1,tsb=tsx+1;n<iMax;n++,tsb++)
\r
4044 if(tsx->ClutID==tsb->ClutID)
\r
4046 r.c[3]=min(r.c[3],tsb->pos.c[3]);
\r
4047 r.c[2]=max(r.c[2],tsb->pos.c[2]);
\r
4048 r.c[1]=min(r.c[1],tsb->pos.c[1]);
\r
4049 r.c[0]=max(r.c[0],tsb->pos.c[0]);
\r
4054 // if(r.l!=tsx->pos.l)
\r
4056 cx=((tsx->ClutID << 4) & 0x3F0);
\r
4057 cy=((tsx->ClutID >> 6) & CLUTYMASK);
\r
4061 // palette check sum
\r
4062 l=0;lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));
\r
4063 if(j==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
\r
4064 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
\r
4065 l=((l+HIWORD(l))&0x3fffL)<<16;
\r
4066 if(l!=(tsx->ClutID&(0x00003fff<<16)))
\r
4068 tsx->ClutID=0;continue;
\r
4073 if(!GetCompressTexturePlace(tsx)) // no place?
\r
4075 for(i=0;i<3;i++) // -> clean up everything
\r
4076 for(j=0;j<MAXTPAGES;j++)
\r
4078 tsb=pscSubtexStore[i][j];
\r
4079 (tsb+SOFFA)->pos.l=0;
\r
4080 (tsb+SOFFB)->pos.l=0;
\r
4081 (tsb+SOFFC)->pos.l=0;
\r
4082 (tsb+SOFFD)->pos.l=0;
\r
4084 for(i=0;i<iSortTexCnt;i++)
\r
4085 {ul=pxSsubtexLeft[i];ul->l=0;}
\r
4087 DrawSemiTrans=sOldDST;
\r
4088 GlobalTexturePage=lOGTP;
\r
4089 *((unsigned long *)&gl_ux[4])=opos.l;
\r
4095 if(tsx->ClutID&(1<<30)) DrawSemiTrans=1;
\r
4096 else DrawSemiTrans=0;
\r
4097 *((unsigned long *)&gl_ux[4])=r.l;
\r
4099 gTexName=uiStexturePage[tsx->cTexID];
\r
4100 LoadSubTexFn(k,j,cx,cy);
\r
4101 uiStexturePage[tsx->cTexID]=gTexName;
\r
4102 tsx->Opaque=ubOpaqueDraw;
\r
4110 while(!tsx->ClutID && iMax) {tsx--;iMax--;}
\r
4118 if(dwTexPageComp==0xffffffff) dwTexPageComp=0;
\r
4120 *((unsigned long *)&gl_ux[4])=opos.l;
\r
4121 GlobalTexturePage=lOGTP;
\r
4122 DrawSemiTrans=sOldDST;
\r
4125 /////////////////////////////////////////////////////////////////////////////
\r
4126 /////////////////////////////////////////////////////////////////////////////
\r
4127 /////////////////////////////////////////////////////////////////////////////
\r
4129 // main entry for searching/creating textures, called from prim.c
\r
4131 /////////////////////////////////////////////////////////////////////////////
\r
4132 /////////////////////////////////////////////////////////////////////////////
\r
4133 /////////////////////////////////////////////////////////////////////////////
\r
4135 GLuint SelectSubTextureS(long TextureMode, unsigned long GivenClutId)
\r
4137 unsigned char * OPtr;unsigned short iCache;short cx,cy;
\r
4139 // sort sow/tow infos for fast access
\r
4141 unsigned char ma1,ma2,mi1,mi2;
\r
4142 if(gl_ux[0]>gl_ux[1]) {mi1=gl_ux[1];ma1=gl_ux[0];}
\r
4143 else {mi1=gl_ux[0];ma1=gl_ux[1];}
\r
4144 if(gl_ux[2]>gl_ux[3]) {mi2=gl_ux[3];ma2=gl_ux[2];}
\r
4145 else {mi2=gl_ux[2];ma2=gl_ux[3];}
\r
4146 if(mi1>mi2) gl_ux[7]=mi2;
\r
4147 else gl_ux[7]=mi1;
\r
4148 if(ma1>ma2) gl_ux[6]=ma1;
\r
4149 else gl_ux[6]=ma2;
\r
4151 if(gl_vy[0]>gl_vy[1]) {mi1=gl_vy[1];ma1=gl_vy[0];}
\r
4152 else {mi1=gl_vy[0];ma1=gl_vy[1];}
\r
4153 if(gl_vy[2]>gl_vy[3]) {mi2=gl_vy[3];ma2=gl_vy[2];}
\r
4154 else {mi2=gl_vy[2];ma2=gl_vy[3];}
\r
4155 if(mi1>mi2) gl_ux[5]=mi2;
\r
4156 else gl_ux[5]=mi1;
\r
4157 if(ma1>ma2) gl_ux[4]=ma1;
\r
4158 else gl_ux[4]=ma2;
\r
4160 // get clut infos in one 32 bit val
\r
4162 if(TextureMode==2) // no clut here
\r
4164 GivenClutId=CLUTUSED|(DrawSemiTrans<<30);cx=cy=0;
\r
4166 if(iFrameTexType && Fake15BitTexture())
\r
4167 return (GLuint)gTexName;
\r
4171 cx=((GivenClutId << 4) & 0x3F0); // but here
\r
4172 cy=((GivenClutId >> 6) & CLUTYMASK);
\r
4173 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30)|CLUTUSED;
\r
4175 // palette check sum.. removed MMX asm, this easy func works as well
\r
4177 unsigned long l=0,row;
\r
4179 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));
\r
4180 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
\r
4181 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;
\r
4182 l=(l+HIWORD(l))&0x3fffL;
\r
4183 GivenClutId|=(l<<16);
\r
4190 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
\r
4192 // cache full? compress and try again
\r
4193 if(iCache==0xffff)
\r
4195 CompressTextureSpace();
\r
4196 OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
\r
4200 usLRUTexPage=iCache;
\r
4201 if(!OPtr) return uiStexturePage[iCache];
\r
4203 // not found? upload texture and store infos in cache
\r
4204 gTexName=uiStexturePage[iCache];
\r
4205 LoadSubTexFn(GlobalTexturePage,TextureMode,cx,cy);
\r
4206 uiStexturePage[iCache]=gTexName;
\r
4207 *OPtr=ubOpaqueDraw;
\r
4208 return (GLuint) gTexName;
\r
4211 /////////////////////////////////////////////////////////////////////////////
\r
4212 /////////////////////////////////////////////////////////////////////////////
\r
4213 /////////////////////////////////////////////////////////////////////////////
\r