gpu-gles: schtruck/fpse merge: gl error checks
[pcsx_rearmed.git] / plugins / gpu-gles / gpuTexture.c
CommitLineData
ce879073 1/***************************************************************************\r
2 texture.c - description\r
3 -------------------\r
4 begin : Sun Mar 08 2009\r
5 copyright : (C) 1999-2009 by Pete Bernert\r
6 web : www.pbernert.com \r
7 ***************************************************************************/\r
8\r
9/***************************************************************************\r
10 * *\r
11 * This program is free software; you can redistribute it and/or modify *\r
12 * it under the terms of the GNU General Public License as published by *\r
13 * the Free Software Foundation; either version 2 of the License, or *\r
14 * (at your option) any later version. See also the license.txt file for *\r
15 * additional informations. *\r
16 * *\r
17 ***************************************************************************/\r
18\r
19//*************************************************************************// \r
20// History of changes:\r
21//\r
22// 2009/03/08 - Pete \r
23// - generic cleanup for the Peops release\r
24//\r
25//*************************************************************************// \r
26\r
27\r
28////////////////////////////////////////////////////////////////////////////////////\r
29// Texture related functions are here !\r
30//\r
31// The texture handling is heart and soul of this gpu. The plugin was developed\r
32// 1999, by this time no shaders were available. Since the psx gpu is making\r
33// heavy use of CLUT (="color lookup tables", aka palettized textures), it was \r
34// an interesting task to get those emulated at good speed on NV TNT cards \r
35// (which was my major goal when I created the first "gpuPeteTNT"). Later cards \r
36// (Geforce256) supported texture palettes by an OGL extension, but at some point\r
37// this support was dropped again by gfx card vendors.\r
38// Well, at least there is a certain advatage, if no texture palettes extension can\r
39// be used: it is possible to modify the textures in any way, allowing "hi-res" \r
40// textures and other tweaks.\r
41//\r
42// My main texture caching is kinda complex: the plugin is allocating "n" 256x256 textures,\r
43// and it places small psx texture parts inside them. The plugin keeps track what \r
44// part (with what palette) it had placed in which texture, so it can re-use this \r
45// part again. The more ogl textures it can use, the better (of course the managing/\r
46// searching will be slower, but everything is faster than uploading textures again\r
47// and again to a gfx card). My first card (TNT1) had 16 MB Vram, and it worked\r
48// well with many games, but I recommend nowadays 64 MB Vram to get a good speed.\r
49//\r
50// Sadly, there is also a second kind of texture cache needed, for "psx texture windows".\r
51// Those are "repeated" textures, so a psx "texture window" needs to be put in \r
52// a whole texture to use the GL_TEXTURE_WRAP_ features. This cache can get full very\r
53// fast in games which are having an heavy "texture window" usage, like RRT4. As an \r
54// alternative, this plugin can use the OGL "palette" extension on texture windows, \r
55// if available. Nowadays also a fragment shader can easily be used to emulate\r
56// texture wrapping in a texture atlas, so the main cache could hold the texture\r
57// windows as well (that's what I am doing in the OGL2 plugin). But currently the\r
58// OGL1 plugin is a "shader-free" zone, so heavy "texture window" games will cause\r
59// much texture uploads.\r
60//\r
61// Some final advice: take care if you change things in here. I've removed my ASM\r
62// handlers (they didn't cause much speed gain anyway) for readability/portability,\r
63// but still the functions/data structures used here are easy to mess up. I guess it\r
64// can be a pain in the ass to port the plugin to another byte order :)\r
65//\r
66////////////////////////////////////////////////////////////////////////////////////\r
67 \r
68#define _IN_TEXTURE\r
69\r
ce879073 70#include "gpuStdafx.h"\r
7eadbf88 71\r
ce879073 72#include "gpuDraw.h"\r
73//#include "plugins.h"\r
74#include "gpuExternals.h"\r
75#include "gpuTexture.h"\r
76#include "gpuPlugin.h"\r
77#include "gpuPrim.h"\r
13326d3e 78\r
ce879073 79#define CLUTCHK 0x00060000\r
80#define CLUTSHIFT 17\r
81\r
82////////////////////////////////////////////////////////////////////////\r
83// texture conversion buffer .. \r
84////////////////////////////////////////////////////////////////////////\r
85\r
86GLubyte ubPaletteBuffer[256][4];\r
87GLuint gTexMovieName=0;\r
88GLuint gTexBlurName=0;\r
89GLuint gTexFrameName=0;\r
90int iTexGarbageCollection=1;\r
91unsigned long dwTexPageComp=0;\r
92int iVRamSize=0;\r
ce879073 93int iClampType=GL_CLAMP_TO_EDGE;\r
ce879073 94int iFilter = GL_LINEAR;\r
95void (*LoadSubTexFn) (int,int,short,short);\r
96unsigned long (*PalTexturedColourFn) (unsigned long);\r
97\r
98////////////////////////////////////////////////////////////////////////\r
99// defines\r
100////////////////////////////////////////////////////////////////////////\r
101\r
102#define PALCOL(x) PalTexturedColourFn (x)\r
103\r
104#define CSUBSIZE 2048\r
105#define CSUBSIZEA 8192\r
106#define CSUBSIZES 4096\r
107\r
108#define OFFA 0\r
109#define OFFB 2048\r
110#define OFFC 4096\r
111#define OFFD 6144\r
112\r
113#define XOFFA 0\r
114#define XOFFB 512\r
115#define XOFFC 1024\r
116#define XOFFD 1536\r
117\r
118#define SOFFA 0\r
119#define SOFFB 1024\r
120#define SOFFC 2048\r
121#define SOFFD 3072\r
122\r
123#define MAXWNDTEXCACHE 128\r
124\r
125#define XCHECK(pos1,pos2) ((pos1.c[0]>=pos2.c[1])&&(pos1.c[1]<=pos2.c[0])&&(pos1.c[2]>=pos2.c[3])&&(pos1.c[3]<=pos2.c[2]))\r
126#define INCHECK(pos2,pos1) ((pos1.c[0]<=pos2.c[0]) && (pos1.c[1]>=pos2.c[1]) && (pos1.c[2]<=pos2.c[2]) && (pos1.c[3]>=pos2.c[3]))\r
127\r
128////////////////////////////////////////////////////////////////////////\r
129\r
677ea103 130unsigned char * CheckTextureInSubSCache(long TextureMode,unsigned long GivenClutId,unsigned short * pCache);\r
ce879073 131void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);\r
132void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);\r
133void DefineSubTextureSort(void);\r
134\r
135////////////////////////////////////////////////////////////////////////\r
136// some globals\r
137////////////////////////////////////////////////////////////////////////\r
138\r
139long GlobalTexturePage;\r
140GLint XTexS;\r
141GLint YTexS;\r
142GLint DXTexS;\r
143GLint DYTexS;\r
144int iSortTexCnt=32;\r
145BOOL bUseFastMdec=FALSE;\r
146BOOL bUse15bitMdec=FALSE;\r
147int iFrameTexType=0;\r
148int iFrameReadType=0;\r
149\r
150unsigned long (*TCF[2]) (unsigned long);\r
151unsigned short (*PTCF[2]) (unsigned short);\r
152\r
153////////////////////////////////////////////////////////////////////////\r
154// texture cache implementation\r
155////////////////////////////////////////////////////////////////////////\r
156\r
ce879073 157// "texture window" cache entry\r
158\r
159typedef struct textureWndCacheEntryTag\r
160{\r
161 unsigned long ClutID;\r
162 short pageid;\r
163 short textureMode;\r
164 short Opaque;\r
165 short used;\r
166 EXLong pos;\r
167 GLuint texname;\r
168} textureWndCacheEntry;\r
169\r
170// "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)\r
171\r
172typedef struct textureSubCacheEntryTagS \r
173{\r
174 unsigned long ClutID;\r
175 EXLong pos;\r
677ea103 176 unsigned char posTX;\r
177 unsigned char posTY;\r
178 unsigned char cTexID;\r
179 unsigned char Opaque;\r
ce879073 180} textureSubCacheEntryS;\r
181\r
ce879073 182\r
183//---------------------------------------------\r
184\r
185#define MAXTPAGES_MAX 64\r
186#define MAXSORTTEX_MAX 196\r
187\r
188//---------------------------------------------\r
189\r
190textureWndCacheEntry wcWndtexStore[MAXWNDTEXCACHE];\r
191textureSubCacheEntryS * pscSubtexStore[3][MAXTPAGES_MAX];\r
192EXLong * pxSsubtexLeft [MAXSORTTEX_MAX];\r
193GLuint uiStexturePage[MAXSORTTEX_MAX];\r
194\r
195unsigned short usLRUTexPage=0;\r
196\r
197int iMaxTexWnds=0;\r
198int iTexWndTurn=0;\r
199int iTexWndLimit=MAXWNDTEXCACHE/2;\r
200\r
201GLubyte * texturepart=NULL;\r
202GLubyte * texturebuffer=NULL;\r
203unsigned long g_x1,g_y1,g_x2,g_y2;\r
677ea103 204unsigned char ubOpaqueDraw=0;\r
ce879073 205\r
206unsigned short MAXTPAGES = 32;\r
207unsigned short CLUTMASK = 0x7fff;\r
208unsigned short CLUTYMASK = 0x1ff;\r
209unsigned short MAXSORTTEX = 196;\r
210\r
211////////////////////////////////////////////////////////////////////////\r
212// Texture color conversions... all my ASM funcs are removed for easier\r
213// porting... and honestly: nowadays the speed gain would be pointless \r
214////////////////////////////////////////////////////////////////////////\r
215\r
216unsigned long XP8RGBA(unsigned long BGR)\r
217{\r
218 if(!(BGR&0xffff)) return 0x50000000;\r
219 if(DrawSemiTrans && !(BGR&0x8000)) \r
220 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
221 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
222}\r
223\r
224unsigned long XP8RGBAEx(unsigned long BGR)\r
225{\r
226 if(!(BGR&0xffff)) return 0x03000000;\r
227 if(DrawSemiTrans && !(BGR&0x8000)) \r
228 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
229 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
230}\r
231\r
232unsigned long CP8RGBA(unsigned long BGR)\r
233{\r
234 unsigned long l;\r
235 if(!(BGR&0xffff)) return 0x50000000;\r
236 if(DrawSemiTrans && !(BGR&0x8000)) \r
237 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
238 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
239 if(l==0xffffff00) l=0xff000000;\r
240 return l;\r
241}\r
242\r
243unsigned long CP8RGBAEx(unsigned long BGR)\r
244{\r
245 unsigned long l;\r
246 if(!(BGR&0xffff)) return 0x03000000;\r
247 if(DrawSemiTrans && !(BGR&0x8000)) \r
248 {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
249 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
250 if(l==0xffffff00) l=0xff000000;\r
251 return l;\r
252}\r
253\r
254unsigned long XP8RGBA_0(unsigned long BGR)\r
255{\r
256 if(!(BGR&0xffff)) return 0x50000000;\r
257 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
258}\r
259\r
260unsigned long XP8RGBAEx_0(unsigned long BGR)\r
261{\r
262 if(!(BGR&0xffff)) return 0x03000000;\r
263 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
264}\r
265\r
266unsigned long XP8BGRA_0(unsigned long BGR)\r
267{\r
268 if(!(BGR&0xffff)) return 0x50000000;\r
269 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
270}\r
271\r
272unsigned long XP8BGRAEx_0(unsigned long BGR)\r
273{\r
274 if(!(BGR&0xffff)) return 0x03000000;\r
275 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
276}\r
277\r
278unsigned long CP8RGBA_0(unsigned long BGR)\r
279{\r
280 unsigned long l;\r
281\r
282 if(!(BGR&0xffff)) return 0x50000000;\r
283 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
284 if(l==0xfff8f800) l=0xff000000;\r
285 return l;\r
286}\r
287\r
288unsigned long CP8RGBAEx_0(unsigned long BGR)\r
289{\r
290 unsigned long l;\r
291\r
292 if(!(BGR&0xffff)) return 0x03000000;\r
293 l=((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
294 if(l==0xfff8f800) l=0xff000000;\r
295 return l;\r
296}\r
297\r
298unsigned long CP8BGRA_0(unsigned long BGR)\r
299{\r
300 unsigned long l;\r
301\r
302 if(!(BGR&0xffff)) return 0x50000000;\r
303 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
304 if(l==0xff00f8f8) l=0xff000000;\r
305 return l;\r
306}\r
307\r
308unsigned long CP8BGRAEx_0(unsigned long BGR)\r
309{\r
310 unsigned long l;\r
311\r
312 if(!(BGR&0xffff)) return 0x03000000;\r
313 l=((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
314 if(l==0xff00f8f8) l=0xff000000;\r
315 return l;\r
316}\r
317\r
318unsigned long XP8RGBA_1(unsigned long BGR)\r
319{\r
320 if(!(BGR&0xffff)) return 0x50000000;\r
321 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
322 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
323}\r
324\r
325unsigned long XP8RGBAEx_1(unsigned long BGR)\r
326{\r
327 if(!(BGR&0xffff)) return 0x03000000;\r
328 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff);}\r
329 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
330}\r
331\r
332unsigned long XP8BGRA_1(unsigned long BGR)\r
333{\r
334 if(!(BGR&0xffff)) return 0x50000000;\r
335 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}\r
336 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
337}\r
338\r
339unsigned long XP8BGRAEx_1(unsigned long BGR)\r
340{\r
341 if(!(BGR&0xffff)) return 0x03000000;\r
342 if(!(BGR&0x8000)) {ubOpaqueDraw=1;return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff);}\r
343 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
344}\r
345\r
346unsigned long P8RGBA(unsigned long BGR)\r
347{\r
348 if(!(BGR&0xffff)) return 0;\r
349 return ((((BGR<<3)&0xf8)|((BGR<<6)&0xf800)|((BGR<<9)&0xf80000))&0xffffff)|0xff000000;\r
350}\r
351\r
352unsigned long P8BGRA(unsigned long BGR)\r
353{\r
354 if(!(BGR&0xffff)) return 0;\r
355 return ((((BGR>>7)&0xf8)|((BGR<<6)&0xf800)|((BGR<<19)&0xf80000))&0xffffff)|0xff000000;\r
356}\r
357\r
358unsigned short XP5RGBA(unsigned short BGR)\r
359{\r
360 if(!BGR) return 0;\r
361 if(DrawSemiTrans && !(BGR&0x8000)) \r
362 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
363 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
364}\r
365\r
366unsigned short XP5RGBA_0 (unsigned short BGR)\r
367{\r
368 if(!BGR) return 0;\r
369\r
370 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
371}\r
372\r
373unsigned short CP5RGBA_0 (unsigned short BGR)\r
374{\r
375 unsigned short s;\r
376\r
377 if(!BGR) return 0;\r
378\r
379 s=((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
380 if(s==0x07ff) s=1;\r
381 return s;\r
382}\r
383\r
384unsigned short XP5RGBA_1(unsigned short BGR)\r
385{\r
386 if(!BGR) return 0;\r
387 if(!(BGR&0x8000)) \r
388 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
389 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
390}\r
391\r
392unsigned short P5RGBA(unsigned short BGR)\r
393{\r
394 if(!BGR) return 0;\r
395 return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)))|1;\r
396}\r
397\r
398unsigned short XP4RGBA(unsigned short BGR)\r
399{\r
400 if(!BGR) return 6;\r
401 if(DrawSemiTrans && !(BGR&0x8000)) \r
402 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
403 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
404}\r
405\r
406unsigned short XP4RGBA_0 (unsigned short BGR)\r
407{\r
408 if(!BGR) return 6;\r
409 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
410}\r
411\r
412unsigned short CP4RGBA_0 (unsigned short BGR)\r
413{\r
414 unsigned short s;\r
415 if(!BGR) return 6;\r
416 s=(((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
417 if(s==0x0fff) s=0x000f;\r
418 return s;\r
419}\r
420\r
421unsigned short XP4RGBA_1(unsigned short BGR)\r
422{\r
423 if(!BGR) return 6;\r
424 if(!(BGR&0x8000)) \r
425 {ubOpaqueDraw=1;return ((((BGR<<11))|((BGR>>9)&0x3e)|((BGR<<1)&0x7c0)));}\r
426 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
427}\r
428\r
429unsigned short P4RGBA(unsigned short BGR)\r
430{\r
431 if(!BGR) return 0;\r
432 return (((((BGR&0x1e)<<11))|((BGR&0x7800)>>7)|((BGR&0x3c0)<<2)))|0xf;\r
433}\r
434\r
435////////////////////////////////////////////////////////////////////////\r
436// CHECK TEXTURE MEM (on plugin startup)\r
437////////////////////////////////////////////////////////////////////////\r
438\r
439int iFTexA=512;\r
440int iFTexB=512;\r
441\r
442void CheckTextureMemory(void)\r
443{\r
444 GLboolean b;GLboolean * bDetail;\r
445 int i,iCnt,iRam=iVRamSize*1024*1024;\r
677ea103 446 int iTSize;char * p;\r
ce879073 447\r
448\r
449 if(iVRamSize)\r
450 {\r
451 int ts;\r
452\r
453 iRam-=(iResX*iResY*8);\r
454 iRam-=(iResX*iResY*(iZBufferDepth/8));\r
455\r
456 ts=4;\r
457 iSortTexCnt=iRam/(256*256*ts);\r
458\r
459 if(iSortTexCnt>MAXSORTTEX) \r
460 {\r
461 iSortTexCnt=MAXSORTTEX-min(1,0);\r
462 }\r
463 else\r
464 {\r
465 iSortTexCnt-=3+min(1,0);\r
466 if(iSortTexCnt<8) iSortTexCnt=8;\r
467 }\r
468\r
469 for(i=0;i<MAXSORTTEX;i++)\r
470 uiStexturePage[i]=0;\r
471 \r
472 return;\r
473 }\r
474\r
475\r
476 iTSize=256;\r
677ea103 477 p=(char *)malloc(iTSize*iTSize*4);\r
ce879073 478\r
479 iCnt=0;\r
480 glGenTextures(MAXSORTTEX,uiStexturePage);\r
481 for(i=0;i<MAXSORTTEX;i++)\r
482 {\r
483 glBindTexture(GL_TEXTURE_2D,uiStexturePage[i]);\r
484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType);\r
485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType);\r
486 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);\r
487 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);\r
488 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iTSize, iTSize, 0,GL_RGBA, GL_UNSIGNED_BYTE, p);\r
489 }\r
490 glBindTexture(GL_TEXTURE_2D,0);\r
491\r
492 free(p);\r
493\r
494 bDetail=(GLboolean*)malloc(MAXSORTTEX*sizeof(GLboolean));\r
495 memset(bDetail,0,MAXSORTTEX*sizeof(GLboolean));\r
496\r
497 glDeleteTextures(MAXSORTTEX,uiStexturePage);\r
498\r
499 for(i=0;i<MAXSORTTEX;i++)\r
500 {\r
501 if(bDetail[i]) iCnt++;\r
502 uiStexturePage[i]=0;\r
503 }\r
504\r
505 free(bDetail);\r
506\r
507 if(b) iSortTexCnt=MAXSORTTEX-min(1,0);\r
508 else iSortTexCnt=iCnt-3+min(1,0); // place for menu&texwnd\r
509\r
510 if(iSortTexCnt<8) iSortTexCnt=8;\r
511} \r
512\r
513////////////////////////////////////////////////////////////////////////\r
514// Main init of textures\r
515////////////////////////////////////////////////////////////////////////\r
516\r
517void InitializeTextureStore() \r
518{\r
519 int i,j;\r
520\r
521 if(iGPUHeight==1024)\r
522 {\r
523 MAXTPAGES = 64;\r
524 CLUTMASK = 0xffff;\r
525 CLUTYMASK = 0x3ff;\r
526 MAXSORTTEX = 128;\r
527 iTexGarbageCollection=0;\r
528 }\r
529 else\r
530 {\r
531 MAXTPAGES = 32;\r
532 CLUTMASK = 0x7fff;\r
533 CLUTYMASK = 0x1ff;\r
534 MAXSORTTEX = 196;\r
535 }\r
536\r
537 memset(vertex,0,4*sizeof(OGLVertex)); // init vertices\r
538\r
539 gTexName=0; // init main tex name\r
540\r
541 iTexWndLimit=MAXWNDTEXCACHE;\r
542/* if(!iUsePalTextures) */iTexWndLimit/=2;\r
543\r
544 memset(wcWndtexStore,0,sizeof(textureWndCacheEntry)*\r
545 MAXWNDTEXCACHE);\r
546 texturepart=(GLubyte *)malloc(256*256*4);\r
547 memset(texturepart,0,256*256*4);\r
548 texturebuffer=NULL;\r
549\r
550 for(i=0;i<3;i++) // -> info for 32*3\r
551 for(j=0;j<MAXTPAGES;j++)\r
552 { \r
553 pscSubtexStore[i][j]=(textureSubCacheEntryS *)malloc(CSUBSIZES*sizeof(textureSubCacheEntryS));\r
554 memset(pscSubtexStore[i][j],0,CSUBSIZES*sizeof(textureSubCacheEntryS));\r
555 }\r
556 for(i=0;i<MAXSORTTEX;i++) // -> info 0..511\r
557 {\r
558 pxSsubtexLeft[i]=(EXLong *)malloc(CSUBSIZE*sizeof(EXLong));\r
559 memset(pxSsubtexLeft[i],0,CSUBSIZE*sizeof(EXLong));\r
560 uiStexturePage[i]=0;\r
561 }\r
562}\r
563\r
564////////////////////////////////////////////////////////////////////////\r
565// Clean up on exit\r
566////////////////////////////////////////////////////////////////////////\r
567\r
568void CleanupTextureStore() \r
569{\r
570 int i,j;textureWndCacheEntry * tsx;\r
571 //----------------------------------------------------//\r
572 glBindTexture(GL_TEXTURE_2D,0);\r
9f58cabb 573 glError();\r
ce879073 574 //----------------------------------------------------//\r
575 free(texturepart); // free tex part\r
576 texturepart=0;\r
577 if(texturebuffer)\r
578 {\r
579 free(texturebuffer);\r
580 texturebuffer=0;\r
581 }\r
582 //----------------------------------------------------//\r
583 tsx=wcWndtexStore; // loop tex window cache\r
584 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)\r
585 {\r
586 if(tsx->texname) // -> some tex?\r
587 glDeleteTextures(1,&tsx->texname); // --> delete it\r
9f58cabb 588 glError();\r
ce879073 589 }\r
590 iMaxTexWnds=0; // no more tex wnds\r
591 //----------------------------------------------------//\r
592 if(gTexMovieName!=0) // some movie tex?\r
593 glDeleteTextures(1, &gTexMovieName); // -> delete it\r
9f58cabb 594 glError();\r
ce879073 595 gTexMovieName=0; // no more movie tex\r
596 //----------------------------------------------------//\r
597 if(gTexFrameName!=0) // some 15bit framebuffer tex?\r
598 glDeleteTextures(1, &gTexFrameName); // -> delete it\r
9f58cabb 599 glError();\r
ce879073 600 gTexFrameName=0; // no more movie tex\r
601 //----------------------------------------------------//\r
602 if(gTexBlurName!=0) // some 15bit framebuffer tex?\r
603 glDeleteTextures(1, &gTexBlurName); // -> delete it\r
9f58cabb 604 glError();\r
ce879073 605 gTexBlurName=0; // no more movie tex\r
606 //----------------------------------------------------//\r
607 for(i=0;i<3;i++) // -> loop\r
608 for(j=0;j<MAXTPAGES;j++) // loop tex pages\r
609 {\r
610 free(pscSubtexStore[i][j]); // -> clean mem\r
611 }\r
612 for(i=0;i<MAXSORTTEX;i++)\r
613 {\r
614 if(uiStexturePage[i]) // --> tex used ?\r
615 {\r
616 glDeleteTextures(1,&uiStexturePage[i]);\r
9f58cabb 617 glError();\r
ce879073 618 uiStexturePage[i]=0; // --> delete it\r
619 }\r
620 free(pxSsubtexLeft[i]); // -> clean mem\r
621 }\r
622 //----------------------------------------------------//\r
623}\r
624\r
625////////////////////////////////////////////////////////////////////////\r
626// Reset textures in game...\r
627////////////////////////////////////////////////////////////////////////\r
628\r
629void ResetTextureArea(BOOL bDelTex)\r
630{\r
631 int i,j;textureSubCacheEntryS * tss;EXLong * lu;\r
632 textureWndCacheEntry * tsx;\r
633 //----------------------------------------------------//\r
634\r
635 dwTexPageComp=0;\r
636\r
637 //----------------------------------------------------//\r
9f58cabb 638 if(bDelTex) {glBindTexture(GL_TEXTURE_2D,0); glError();gTexName=0;}\r
ce879073 639 //----------------------------------------------------//\r
640 tsx=wcWndtexStore;\r
641 for(i=0;i<MAXWNDTEXCACHE;i++,tsx++)\r
642 {\r
643 tsx->used=0;\r
644 if(bDelTex && tsx->texname)\r
645 {\r
9f58cabb 646 glDeleteTextures(1,&tsx->texname); glError();\r
ce879073 647 tsx->texname=0;\r
648 }\r
649 }\r
650 iMaxTexWnds=0;\r
651 //----------------------------------------------------//\r
652\r
653 for(i=0;i<3;i++)\r
654 for(j=0;j<MAXTPAGES;j++)\r
655 {\r
656 tss=pscSubtexStore[i][j];\r
657 (tss+SOFFA)->pos.l=0;\r
658 (tss+SOFFB)->pos.l=0;\r
659 (tss+SOFFC)->pos.l=0;\r
660 (tss+SOFFD)->pos.l=0;\r
661 }\r
662\r
663 for(i=0;i<iSortTexCnt;i++)\r
664 {\r
665 lu=pxSsubtexLeft[i];\r
666 lu->l=0;\r
667 if(bDelTex && uiStexturePage[i])\r
9f58cabb 668 {glDeleteTextures(1,&uiStexturePage[i]); glError();uiStexturePage[i]=0;}\r
ce879073 669 }\r
670}\r
671\r
672\r
673////////////////////////////////////////////////////////////////////////\r
674// Invalidate tex windows\r
675////////////////////////////////////////////////////////////////////////\r
676\r
677void InvalidateWndTextureArea(long X,long Y,long W, long H)\r
678{\r
679 int i,px1,px2,py1,py2,iYM=1;\r
680 textureWndCacheEntry * tsw=wcWndtexStore;\r
681\r
682 W+=X-1; \r
683 H+=Y-1;\r
684 if(X<0) X=0;if(X>1023) X=1023;\r
685 if(W<0) W=0;if(W>1023) W=1023;\r
686 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;\r
687 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;\r
688 W++;H++;\r
689\r
690 if(iGPUHeight==1024) iYM=3;\r
691\r
692 py1=min(iYM,Y>>8);\r
693 py2=min(iYM,H>>8); // y: 0 or 1\r
694\r
695 px1=max(0,(X>>6));\r
696 px2=min(15,(W>>6));\r
697\r
698 if(py1==py2)\r
699 {\r
700 py1=py1<<4;px1+=py1;px2+=py1; // change to 0-31\r
701 for(i=0;i<iMaxTexWnds;i++,tsw++)\r
702 {\r
703 if(tsw->used)\r
704 {\r
705 if(tsw->pageid>=px1 && tsw->pageid<=px2)\r
706 {\r
707 tsw->used=0;\r
708 }\r
709 }\r
710 }\r
711 }\r
712 else\r
713 {\r
714 py1=px1+16;py2=px2+16;\r
715 for(i=0;i<iMaxTexWnds;i++,tsw++)\r
716 {\r
717 if(tsw->used)\r
718 {\r
719 if((tsw->pageid>=px1 && tsw->pageid<=px2) ||\r
720 (tsw->pageid>=py1 && tsw->pageid<=py2))\r
721 {\r
722 tsw->used=0;\r
723 }\r
724 }\r
725 }\r
726 }\r
727\r
728 // adjust tex window count\r
729 tsw=wcWndtexStore+iMaxTexWnds-1;\r
730 while(iMaxTexWnds && !tsw->used) {iMaxTexWnds--;tsw--;}\r
731}\r
732\r
733\r
734\r
735////////////////////////////////////////////////////////////////////////\r
736// same for sort textures\r
737////////////////////////////////////////////////////////////////////////\r
738\r
739void MarkFree(textureSubCacheEntryS * tsx)\r
740{\r
741 EXLong * ul, * uls;\r
677ea103 742 int j,iMax;unsigned char x1,y1,dx,dy;\r
ce879073 743\r
744 uls=pxSsubtexLeft[tsx->cTexID];\r
745 iMax=uls->l;ul=uls+1;\r
746\r
747 if(!iMax) return;\r
748\r
749 for(j=0;j<iMax;j++,ul++)\r
750 if(ul->l==0xffffffff) break;\r
751\r
752 if(j<CSUBSIZE-2)\r
753 {\r
754 if(j==iMax) uls->l=uls->l+1;\r
755\r
756 x1=tsx->posTX;dx=tsx->pos.c[2]-tsx->pos.c[3];\r
757 if(tsx->posTX) {x1--;dx+=3;}\r
758 y1=tsx->posTY;dy=tsx->pos.c[0]-tsx->pos.c[1];\r
759 if(tsx->posTY) {y1--;dy+=3;}\r
760\r
761 ul->c[3]=x1;\r
762 ul->c[2]=dx;\r
763 ul->c[1]=y1;\r
764 ul->c[0]=dy;\r
765 }\r
766}\r
767\r
768void InvalidateSubSTextureArea(long X,long Y,long W, long H)\r
769{\r
770 int i,j,k,iMax,px,py,px1,px2,py1,py2,iYM=1;\r
771 EXLong npos;textureSubCacheEntryS * tsb;\r
772 long x1,x2,y1,y2,xa,sw;\r
773\r
774 W+=X-1; \r
775 H+=Y-1;\r
776 if(X<0) X=0;if(X>1023) X=1023;\r
777 if(W<0) W=0;if(W>1023) W=1023;\r
778 if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;\r
779 if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;\r
780 W++;H++;\r
781\r
782 if(iGPUHeight==1024) iYM=3;\r
783\r
784 py1=min(iYM,Y>>8);\r
785 py2=min(iYM,H>>8); // y: 0 or 1\r
786 px1=max(0,(X>>6)-3); \r
787 px2=min(15,(W>>6)+3); // x: 0-15\r
788\r
789 for(py=py1;py<=py2;py++)\r
790 {\r
791 j=(py<<4)+px1; // get page\r
792\r
793 y1=py*256;y2=y1+255;\r
794\r
795 if(H<y1) continue;\r
796 if(Y>y2) continue;\r
797\r
798 if(Y>y1) y1=Y;\r
799 if(H<y2) y2=H;\r
800 if(y2<y1) {sw=y1;y1=y2;y2=sw;}\r
801 y1=((y1%256)<<8);\r
802 y2=(y2%256);\r
803\r
804 for(px=px1;px<=px2;px++,j++)\r
805 {\r
806 for(k=0;k<3;k++)\r
807 {\r
808 xa=x1=px<<6;\r
809 if(W<x1) continue;\r
810 x2=x1+(64<<k)-1;\r
811 if(X>x2) continue;\r
812\r
813 if(X>x1) x1=X;\r
814 if(W<x2) x2=W;\r
815 if(x2<x1) {sw=x1;x1=x2;x2=sw;}\r
816\r
817 if (dwGPUVersion == 2)\r
818 npos.l=0x00ff00ff;\r
819 else\r
820 npos.l=((x1-xa)<<(26-k))|((x2-xa)<<(18-k))|y1|y2;\r
821\r
822 {\r
823 tsb=pscSubtexStore[k][j]+SOFFA;iMax=tsb->pos.l;tsb++;\r
824 for(i=0;i<iMax;i++,tsb++)\r
825 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
826\r
827// if(npos.l & 0x00800000)\r
828 {\r
829 tsb=pscSubtexStore[k][j]+SOFFB;iMax=tsb->pos.l;tsb++;\r
830 for(i=0;i<iMax;i++,tsb++)\r
831 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
832 }\r
833\r
834// if(npos.l & 0x00000080)\r
835 {\r
836 tsb=pscSubtexStore[k][j]+SOFFC;iMax=tsb->pos.l;tsb++;\r
837 for(i=0;i<iMax;i++,tsb++)\r
838 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
839 }\r
840\r
841// if(npos.l & 0x00800080)\r
842 {\r
843 tsb=pscSubtexStore[k][j]+SOFFD;iMax=tsb->pos.l;tsb++;\r
844 for(i=0;i<iMax;i++,tsb++)\r
845 if(tsb->ClutID && XCHECK(tsb->pos,npos)) {tsb->ClutID=0;MarkFree(tsb);}\r
846 }\r
847 }\r
848 }\r
849 }\r
850 }\r
851}\r
852\r
853////////////////////////////////////////////////////////////////////////\r
854// Invalidate some parts of cache: main routine\r
855////////////////////////////////////////////////////////////////////////\r
856\r
857void InvalidateTextureAreaEx(void)\r
858{\r
859 short W=sxmax-sxmin;\r
860 short H=symax-symin;\r
861\r
862 if(W==0 && H==0) return;\r
863\r
864 if(iMaxTexWnds) \r
865 InvalidateWndTextureArea(sxmin,symin,W,H);\r
866\r
867 InvalidateSubSTextureArea(sxmin,symin,W,H);\r
868}\r
869\r
870////////////////////////////////////////////////////////////////////////\r
871\r
872void InvalidateTextureArea(long X,long Y,long W, long H)\r
873{\r
874 if(W==0 && H==0) return;\r
875\r
876 if(iMaxTexWnds) InvalidateWndTextureArea(X,Y,W,H); \r
877\r
878 InvalidateSubSTextureArea(X,Y,W,H);\r
879}\r
880\r
881\r
882////////////////////////////////////////////////////////////////////////\r
883// tex window: define\r
884////////////////////////////////////////////////////////////////////////\r
885\r
886void DefineTextureWnd(void)\r
887{\r
888 if(gTexName==0)\r
889 glGenTextures(1, &gTexName);\r
9f58cabb 890 glError();\r
ce879073 891 glBindTexture(GL_TEXTURE_2D, gTexName);\r
9f58cabb 892 glError();\r
ce879073 893 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\r
894 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\r
9f58cabb 895 glError(); \r
ce879073 896{\r
897 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);\r
898 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);\r
9f58cabb 899 glError();\r
ce879073 900 }\r
901\r
902 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, \r
903 TWin.Position.x1, \r
904 TWin.Position.y1, \r
905 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart);\r
9f58cabb 906 glError();\r
907 //LOGE("DefineTextureWnd x:%d y:%d",TWin.Position.x1,TWin.Position.y1);\r
908\r
ce879073 909}\r
910\r
911////////////////////////////////////////////////////////////////////////\r
912// tex window: load packed stretch\r
913////////////////////////////////////////////////////////////////////////\r
914\r
915void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)\r
916{\r
917 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;\r
918 unsigned int palstart;\r
919 unsigned short *px,*pa,*ta;\r
677ea103 920 unsigned char *cSRCPtr,*cOSRCPtr;\r
ce879073 921 unsigned short *wSRCPtr,*wOSRCPtr;\r
922 unsigned long LineOffset;unsigned short s;\r
923 int pmult=pageid/16;\r
924 unsigned short (*LPTCOL)(unsigned short);\r
925\r
926 LPTCOL=PTCF[DrawSemiTrans];\r
927\r
928 ldxo=TWin.Position.x1-TWin.OPosition.x1;\r
929 ldy =TWin.Position.y1-TWin.OPosition.y1;\r
930\r
931 pa=px=(unsigned short *)ubPaletteBuffer;\r
932 ta=(unsigned short *)texturepart;\r
933 palstart=cx+(cy*1024);\r
934\r
935 ubOpaqueDraw=0;\r
936\r
937 switch(mode)\r
938 {\r
939 //--------------------------------------------------// \r
940 // 4bit texture load ..\r
941 case 0:\r
942 if(GlobalTextIL)\r
943 {\r
944 unsigned int TXV,TXU,n_xi,n_yi;\r
945\r
946 wSRCPtr=psxVuw+palstart;\r
947 for(row=0;row<16;row++)\r
948 *px++=LPTCOL(*wSRCPtr++);\r
949\r
950 column=g_y2-ldy;\r
951 for(TXV=g_y1;TXV<=column;TXV++)\r
952 {\r
953 ldx=ldxo;\r
954 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
955 {\r
956 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
957 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
958\r
959 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
960 *ta++=s;\r
961\r
962 if(ldx) {*ta++=s;ldx--;}\r
963 }\r
964\r
965 if(ldy) \r
966 {ldy--;\r
967 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
968 *ta++=*(ta-(g_x2-g_x1));\r
969 }\r
970 }\r
971\r
972 DefineTextureWnd();\r
973\r
974 break;\r
975 }\r
976\r
977\r
978 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
979\r
980 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
981\r
982 wSRCPtr=psxVuw+palstart;\r
983 for(row=0;row<16;row++)\r
984 *px++=LPTCOL(*wSRCPtr++);\r
985\r
986 sxm=g_x1&1;sxh=g_x1>>1;\r
987 if(sxm) j=g_x1+1; else j=g_x1;\r
988 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
989 for(column=g_y1;column<=g_y2;column++)\r
990 {\r
991 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
992 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
993 \r
994 for(row=j;row<=g_x2-ldxo;row++)\r
995 {\r
996 s=*(pa+(*cSRCPtr & 0xF));\r
997 *ta++=s;\r
998 if(ldx) {*ta++=s;ldx--;}\r
999 row++;\r
1000 if(row<=g_x2-ldxo) \r
1001 {\r
1002 s=*(pa+((*cSRCPtr >> 4) & 0xF));\r
1003 *ta++=s; \r
1004 if(ldx) {*ta++=s;ldx--;}\r
1005 }\r
1006 cSRCPtr++;\r
1007 }\r
1008\r
1009 if(ldy && column&1) \r
1010 {ldy--;cSRCPtr = cOSRCPtr;}\r
1011 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;\r
1012 }\r
1013\r
1014 DefineTextureWnd();\r
1015 break;\r
1016 //--------------------------------------------------// \r
1017 // 8bit texture load ..\r
1018 case 1:\r
1019 if(GlobalTextIL)\r
1020 {\r
1021 unsigned int TXV,TXU,n_xi,n_yi;\r
1022\r
1023 wSRCPtr=psxVuw+palstart;\r
1024 for(row=0;row<256;row++)\r
1025 *px++=LPTCOL(*wSRCPtr++);\r
1026\r
1027 column=g_y2-ldy;\r
1028 for(TXV=g_y1;TXV<=column;TXV++)\r
1029 {\r
1030 ldx=ldxo;\r
1031 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
1032 {\r
1033 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1034 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1035\r
1036 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1037\r
1038 *ta++=s;\r
1039 if(ldx) {*ta++=s;ldx--;}\r
1040 }\r
1041\r
1042 if(ldy) \r
1043 {ldy--;\r
1044 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1045 *ta++=*(ta-(g_x2-g_x1));\r
1046 }\r
1047\r
1048 }\r
1049\r
1050 DefineTextureWnd();\r
1051\r
1052 break;\r
1053 }\r
1054\r
1055 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1056\r
1057 // not using a lookup table here... speeds up smaller texture areas\r
1058 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1059 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo; \r
1060\r
1061 for(column=g_y1;column<=g_y2;column++)\r
1062 {\r
1063 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1064 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1065 {\r
1066 s=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1067 *ta++=s;\r
1068 if(ldx) {*ta++=s;ldx--;}\r
1069 }\r
1070 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}\r
1071 else cSRCPtr+=LineOffset;\r
1072 }\r
1073\r
1074 DefineTextureWnd();\r
1075 break;\r
1076 //--------------------------------------------------// \r
1077 // 16bit texture load ..\r
1078 case 2:\r
1079 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1080 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1081 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo; \r
1082 \r
1083 for(column=g_y1;column<=g_y2;column++)\r
1084 {\r
1085 wOSRCPtr=wSRCPtr;ldx=ldxo;\r
1086 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1087 {\r
1088 s=LPTCOL(*wSRCPtr++);\r
1089 *ta++=s;\r
1090 if(ldx) {*ta++=s;ldx--;}\r
1091 }\r
1092 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}\r
1093 else wSRCPtr+=LineOffset;\r
1094 }\r
1095\r
1096 DefineTextureWnd();\r
1097 break;\r
1098 //--------------------------------------------------// \r
1099 // others are not possible !\r
1100 }\r
1101}\r
1102\r
1103////////////////////////////////////////////////////////////////////////\r
1104// tex window: load stretched\r
1105////////////////////////////////////////////////////////////////////////\r
1106\r
1107void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)\r
1108{\r
1109 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo,s;\r
1110 unsigned int palstart;\r
1111 unsigned long *px,*pa,*ta;\r
677ea103 1112 unsigned char *cSRCPtr,*cOSRCPtr;\r
ce879073 1113 unsigned short *wSRCPtr,*wOSRCPtr;\r
1114 unsigned long LineOffset;\r
1115 int pmult=pageid/16;\r
1116 unsigned long (*LTCOL)(unsigned long);\r
1117 \r
1118 LTCOL=TCF[DrawSemiTrans];\r
1119\r
1120 ldxo=TWin.Position.x1-TWin.OPosition.x1;\r
1121 ldy =TWin.Position.y1-TWin.OPosition.y1;\r
1122\r
1123 pa=px=(unsigned long *)ubPaletteBuffer;\r
1124 ta=(unsigned long *)texturepart;\r
1125 palstart=cx+(cy*1024);\r
1126\r
1127 ubOpaqueDraw=0;\r
1128\r
1129 switch(mode)\r
1130 {\r
1131 //--------------------------------------------------// \r
1132 // 4bit texture load ..\r
1133 case 0:\r
1134 //------------------- ZN STUFF\r
1135\r
1136 if(GlobalTextIL)\r
1137 {\r
1138 unsigned int TXV,TXU,n_xi,n_yi;\r
1139\r
1140 wSRCPtr=psxVuw+palstart;\r
1141\r
1142 row=4;do\r
1143 {\r
1144 *px =LTCOL(*wSRCPtr);\r
1145 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1146 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1147 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1148 row--;px+=4;wSRCPtr+=4;\r
1149 }\r
1150 while (row);\r
1151\r
1152 column=g_y2-ldy;\r
1153 for(TXV=g_y1;TXV<=column;TXV++)\r
1154 {\r
1155 ldx=ldxo;\r
1156 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
1157 {\r
1158 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
1159 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
1160\r
1161 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
1162 *ta++=s;\r
1163\r
1164 if(ldx) {*ta++=s;ldx--;}\r
1165 }\r
1166\r
1167 if(ldy) \r
1168 {ldy--;\r
1169 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1170 *ta++=*(ta-(g_x2-g_x1));\r
1171 }\r
1172 }\r
1173\r
1174 DefineTextureWnd();\r
1175\r
1176 break;\r
1177 }\r
1178\r
1179 //-------------------\r
1180\r
1181 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1182 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
1183\r
1184 wSRCPtr=psxVuw+palstart;\r
1185 for(row=0;row<16;row++)\r
1186 *px++=LTCOL(*wSRCPtr++);\r
1187\r
1188 sxm=g_x1&1;sxh=g_x1>>1;\r
1189 if(sxm) j=g_x1+1; else j=g_x1;\r
1190 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1191 for(column=g_y1;column<=g_y2;column++)\r
1192 {\r
1193 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1194 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
1195 \r
1196 for(row=j;row<=g_x2-ldxo;row++)\r
1197 {\r
1198 s=*(pa+(*cSRCPtr & 0xF));\r
1199 *ta++=s;\r
1200 if(ldx) {*ta++=s;ldx--;}\r
1201 row++;\r
1202 if(row<=g_x2-ldxo) \r
1203 {\r
1204 s=*(pa+((*cSRCPtr >> 4) & 0xF));\r
1205 *ta++=s; \r
1206 if(ldx) {*ta++=s;ldx--;}\r
1207 }\r
1208 cSRCPtr++;\r
1209 }\r
1210 if(ldy && column&1) \r
1211 {ldy--;cSRCPtr = cOSRCPtr;}\r
1212 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;\r
1213 }\r
1214\r
1215 DefineTextureWnd();\r
1216 break;\r
1217 //--------------------------------------------------//\r
1218 // 8bit texture load ..\r
1219 case 1:\r
1220 //------------ ZN STUFF\r
1221 if(GlobalTextIL)\r
1222 {\r
1223 unsigned int TXV,TXU,n_xi,n_yi;\r
1224\r
1225 wSRCPtr=psxVuw+palstart;\r
1226\r
1227 row=64;do\r
1228 {\r
1229 *px =LTCOL(*wSRCPtr);\r
1230 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1231 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1232 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1233 row--;px+=4;wSRCPtr+=4;\r
1234 }\r
1235 while (row);\r
1236\r
1237 column=g_y2-ldy;\r
1238 for(TXV=g_y1;TXV<=column;TXV++)\r
1239 {\r
1240 ldx=ldxo;\r
1241 for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)\r
1242 {\r
1243 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1244 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1245\r
1246 s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1247 *ta++=s;\r
1248 if(ldx) {*ta++=s;ldx--;}\r
1249 }\r
1250\r
1251 if(ldy) \r
1252 {ldy--;\r
1253 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1254 *ta++=*(ta-(g_x2-g_x1));\r
1255 }\r
1256\r
1257 }\r
1258\r
1259 DefineTextureWnd();\r
1260\r
1261 break;\r
1262 }\r
1263 //------------\r
1264\r
1265 start=((pageid-16*pmult)*128)+256*2048*pmult; \r
1266\r
1267 // not using a lookup table here... speeds up smaller texture areas\r
1268 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1269 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo; \r
1270\r
1271 for(column=g_y1;column<=g_y2;column++)\r
1272 {\r
1273 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1274 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1275 {\r
1276 s=LTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1277 *ta++=s;\r
1278 if(ldx) {*ta++=s;ldx--;}\r
1279 }\r
1280 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}\r
1281 else cSRCPtr+=LineOffset;\r
1282 }\r
1283\r
1284 DefineTextureWnd();\r
1285 break;\r
1286 //--------------------------------------------------// \r
1287 // 16bit texture load ..\r
1288 case 2:\r
1289 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1290\r
1291 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1292 LineOffset = 1024 - (g_x2-g_x1+1) +ldxo; \r
1293\r
1294 for(column=g_y1;column<=g_y2;column++)\r
1295 {\r
1296 wOSRCPtr=wSRCPtr;ldx=ldxo;\r
1297 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1298 {\r
1299 s=LTCOL(*wSRCPtr++);\r
1300 *ta++=s;\r
1301 if(ldx) {*ta++=s;ldx--;}\r
1302 }\r
1303 if(ldy && column&1) {ldy--;wSRCPtr=wOSRCPtr;}\r
1304 else wSRCPtr+=LineOffset;\r
1305 }\r
1306\r
1307 DefineTextureWnd();\r
1308 break;\r
1309 //--------------------------------------------------// \r
1310 // others are not possible !\r
1311 }\r
1312}\r
1313\r
1314////////////////////////////////////////////////////////////////////////\r
1315// tex window: load packed simple\r
1316////////////////////////////////////////////////////////////////////////\r
1317\r
1318void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)\r
1319{\r
1320 unsigned long start,row,column,j,sxh,sxm;\r
1321 unsigned int palstart;\r
1322 unsigned short *px,*pa,*ta;\r
677ea103 1323 unsigned char *cSRCPtr;\r
ce879073 1324 unsigned short *wSRCPtr;\r
1325 unsigned long LineOffset;\r
1326 int pmult=pageid/16;\r
1327 unsigned short (*LPTCOL)(unsigned short);\r
1328\r
1329 LPTCOL=PTCF[DrawSemiTrans];\r
1330\r
1331 pa=px=(unsigned short *)ubPaletteBuffer;\r
1332 ta=(unsigned short *)texturepart;\r
1333 palstart=cx+(cy*1024);\r
1334\r
1335 ubOpaqueDraw=0;\r
1336\r
1337 switch(mode)\r
1338 {\r
1339 //--------------------------------------------------// \r
1340 // 4bit texture load ..\r
1341 case 0:\r
1342 if(GlobalTextIL)\r
1343 {\r
1344 unsigned int TXV,TXU,n_xi,n_yi;\r
1345\r
1346 wSRCPtr=psxVuw+palstart;\r
1347 for(row=0;row<16;row++)\r
1348 *px++=LPTCOL(*wSRCPtr++);\r
1349\r
1350 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1351 {\r
1352 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1353 {\r
1354 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
1355 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
1356\r
1357 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
1358 }\r
1359 }\r
1360\r
1361 DefineTextureWnd();\r
1362\r
1363 break;\r
1364 }\r
1365\r
1366 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1367\r
1368 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
1369\r
1370 wSRCPtr=psxVuw+palstart;\r
1371 for(row=0;row<16;row++)\r
1372 *px++=LPTCOL(*wSRCPtr++);\r
1373\r
1374 sxm=g_x1&1;sxh=g_x1>>1;\r
1375 if(sxm) j=g_x1+1; else j=g_x1;\r
1376 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1377 for(column=g_y1;column<=g_y2;column++)\r
1378 {\r
1379 cSRCPtr = psxVub + start + (2048*column) + sxh;\r
1380 \r
1381 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
1382 \r
1383 for(row=j;row<=g_x2;row++)\r
1384 {\r
1385 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;\r
1386 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
1387 cSRCPtr++;\r
1388 }\r
1389 }\r
1390\r
1391 DefineTextureWnd();\r
1392 break;\r
1393 //--------------------------------------------------// \r
1394 // 8bit texture load ..\r
1395 case 1:\r
1396 if(GlobalTextIL)\r
1397 {\r
1398 unsigned int TXV,TXU,n_xi,n_yi;\r
1399\r
1400 wSRCPtr=psxVuw+palstart;\r
1401 for(row=0;row<256;row++)\r
1402 *px++=LPTCOL(*wSRCPtr++);\r
1403\r
1404 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1405 {\r
1406 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1407 {\r
1408 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1409 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1410\r
1411 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1412 }\r
1413 }\r
1414\r
1415 DefineTextureWnd();\r
1416\r
1417 break;\r
1418 }\r
1419\r
1420 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1421\r
1422 // not using a lookup table here... speeds up smaller texture areas\r
1423 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1424 LineOffset = 2048 - (g_x2-g_x1+1); \r
1425\r
1426 for(column=g_y1;column<=g_y2;column++)\r
1427 {\r
1428 for(row=g_x1;row<=g_x2;row++)\r
1429 *ta++=LPTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1430 cSRCPtr+=LineOffset;\r
1431 }\r
1432\r
1433 DefineTextureWnd();\r
1434 break;\r
1435 //--------------------------------------------------// \r
1436 // 16bit texture load ..\r
1437 case 2:\r
1438 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1439 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1440 LineOffset = 1024 - (g_x2-g_x1+1); \r
1441\r
1442 for(column=g_y1;column<=g_y2;column++)\r
1443 {\r
1444 for(row=g_x1;row<=g_x2;row++)\r
1445 *ta++=LPTCOL(*wSRCPtr++);\r
1446 wSRCPtr+=LineOffset;\r
1447 }\r
1448\r
1449 DefineTextureWnd();\r
1450 break;\r
1451 //--------------------------------------------------// \r
1452 // others are not possible !\r
1453 }\r
1454}\r
1455\r
1456////////////////////////////////////////////////////////////////////////\r
1457// tex window: load simple\r
1458////////////////////////////////////////////////////////////////////////\r
1459\r
1460void LoadWndTexturePage(int pageid, int mode, short cx, short cy)\r
1461{\r
1462 unsigned long start,row,column,j,sxh,sxm;\r
1463 unsigned int palstart;\r
1464 unsigned long *px,*pa,*ta;\r
677ea103 1465 unsigned char *cSRCPtr;\r
ce879073 1466 unsigned short *wSRCPtr;\r
1467 unsigned long LineOffset;\r
1468 int pmult=pageid/16;\r
1469 unsigned long (*LTCOL)(unsigned long);\r
1470 \r
1471 LTCOL=TCF[DrawSemiTrans];\r
1472\r
1473 pa=px=(unsigned long *)ubPaletteBuffer;\r
1474 ta=(unsigned long *)texturepart;\r
1475 palstart=cx+(cy*1024);\r
1476\r
1477 ubOpaqueDraw=0;\r
1478\r
1479 switch(mode)\r
1480 {\r
1481 //--------------------------------------------------// \r
1482 // 4bit texture load ..\r
1483 case 0:\r
1484 if(GlobalTextIL)\r
1485 {\r
1486 unsigned int TXV,TXU,n_xi,n_yi;\r
1487\r
1488 wSRCPtr=psxVuw+palstart;\r
1489\r
1490 row=4;do\r
1491 {\r
1492 *px =LTCOL(*wSRCPtr);\r
1493 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1494 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1495 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1496 row--;px+=4;wSRCPtr+=4;\r
1497 }\r
1498 while (row);\r
1499\r
1500 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1501 {\r
1502 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1503 {\r
1504 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
1505 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
1506\r
1507 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
1508 }\r
1509 }\r
1510\r
1511 DefineTextureWnd();\r
1512\r
1513 break;\r
1514 }\r
1515\r
1516 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1517\r
1518 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
1519\r
1520 wSRCPtr=psxVuw+palstart;\r
1521 for(row=0;row<16;row++)\r
1522 *px++=LTCOL(*wSRCPtr++);\r
1523\r
1524 sxm=g_x1&1;sxh=g_x1>>1;\r
1525 if(sxm) j=g_x1+1; else j=g_x1;\r
1526 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1527 for(column=g_y1;column<=g_y2;column++)\r
1528 {\r
1529 cSRCPtr = psxVub + start + (2048*column) + sxh;\r
1530 \r
1531 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
1532 \r
1533 for(row=j;row<=g_x2;row++)\r
1534 {\r
1535 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;\r
1536 if(row<=g_x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
1537 cSRCPtr++;\r
1538 }\r
1539 }\r
1540\r
1541 DefineTextureWnd();\r
1542 break;\r
1543 //--------------------------------------------------//\r
1544 // 8bit texture load ..\r
1545 case 1:\r
1546 if(GlobalTextIL)\r
1547 {\r
1548 unsigned int TXV,TXU,n_xi,n_yi;\r
1549\r
1550 wSRCPtr=psxVuw+palstart;\r
1551\r
1552 row=64;do\r
1553 {\r
1554 *px =LTCOL(*wSRCPtr);\r
1555 *(px+1)=LTCOL(*(wSRCPtr+1));\r
1556 *(px+2)=LTCOL(*(wSRCPtr+2));\r
1557 *(px+3)=LTCOL(*(wSRCPtr+3));\r
1558 row--;px+=4;wSRCPtr+=4;\r
1559 }\r
1560 while (row);\r
1561\r
1562 for(TXV=g_y1;TXV<=g_y2;TXV++)\r
1563 {\r
1564 for(TXU=g_x1;TXU<=g_x2;TXU++)\r
1565 {\r
1566 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
1567 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
1568\r
1569 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
1570 }\r
1571 }\r
1572\r
1573 DefineTextureWnd();\r
1574\r
1575 break;\r
1576 }\r
1577\r
1578 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1579\r
1580 // not using a lookup table here... speeds up smaller texture areas\r
1581 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1582 LineOffset = 2048 - (g_x2-g_x1+1); \r
1583\r
1584 for(column=g_y1;column<=g_y2;column++)\r
1585 {\r
1586 for(row=g_x1;row<=g_x2;row++)\r
1587 *ta++=LTCOL(psxVuw[palstart+ *cSRCPtr++]);\r
1588 cSRCPtr+=LineOffset;\r
1589 }\r
1590\r
1591 DefineTextureWnd();\r
1592 break;\r
1593 //--------------------------------------------------// \r
1594 // 16bit texture load ..\r
1595 case 2:\r
1596 start=((pageid-16*pmult)*64)+256*1024*pmult;\r
1597\r
1598 wSRCPtr = psxVuw + start + (1024*g_y1) + g_x1;\r
1599 LineOffset = 1024 - (g_x2-g_x1+1); \r
1600\r
1601 for(column=g_y1;column<=g_y2;column++)\r
1602 {\r
1603 for(row=g_x1;row<=g_x2;row++)\r
1604 *ta++=LTCOL(*wSRCPtr++);\r
1605 wSRCPtr+=LineOffset;\r
1606 }\r
1607\r
1608 DefineTextureWnd();\r
1609 break;\r
1610 //--------------------------------------------------// \r
1611 // others are not possible !\r
1612 }\r
1613}\r
1614\r
1615////////////////////////////////////////////////////////////////////////\r
1616////////////////////////////////////////////////////////////////////////\r
1617////////////////////////////////////////////////////////////////////////\r
1618////////////////////////////////////////////////////////////////////////\r
1619\r
1620void UploadTexWndPal(int mode,short cx,short cy)\r
1621{\r
1622 unsigned int i,iSize;\r
1623 unsigned short * wSrcPtr;\r
1624 unsigned long * ta=(unsigned long *)texturepart;\r
1625\r
1626 wSrcPtr=psxVuw+cx+(cy*1024);\r
1627 if(mode==0) i=4; else i=64;\r
1628 iSize=i<<2;\r
1629 ubOpaqueDraw=0;\r
1630\r
1631 do\r
1632 {\r
1633 *ta =PALCOL(*wSrcPtr);\r
1634 *(ta+1)=PALCOL(*(wSrcPtr+1));\r
1635 *(ta+2)=PALCOL(*(wSrcPtr+2));\r
1636 *(ta+3)=PALCOL(*(wSrcPtr+3));\r
1637 ta+=4;wSrcPtr+=4;i--;\r
1638 }\r
1639 while(i);\r
1640\r
1641/* (*glColorTableEXTEx)(GL_TEXTURE_2D,GL_RGBA8,iSize,\r
1642 GL_RGBA,GL_UNSIGNED_BYTE,texturepart);\r
1643*/}\r
1644\r
1645////////////////////////////////////////////////////////////////////////\r
1646\r
1647void DefinePalTextureWnd(void)\r
1648{\r
1649 if(gTexName==0)\r
1650 glGenTextures(1, &gTexName);\r
9f58cabb 1651 glError();\r
ce879073 1652 glBindTexture(GL_TEXTURE_2D, gTexName);\r
9f58cabb 1653 glError();\r
ce879073 1654 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\r
1655 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\r
9f58cabb 1656 glError();\r
ce879073 1657{\r
1658 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter);\r
1659 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter);\r
1660 }\r
9f58cabb 1661 glError();\r
ce879073 1662 glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, \r
1663 TWin.Position.x1, \r
1664 TWin.Position.y1, \r
1665 0, GL_RGBA, GL_UNSIGNED_BYTE,texturepart);\r
9f58cabb 1666 glError();\r
1667 //LOGE("DefinePalTextureWnd x:%d y:%d",TWin.Position.x1,TWin.Position.y1);\r
ce879073 1668}\r
1669\r
1670///////////////////////////////////////////////////////\r
1671\r
1672void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)\r
1673{\r
1674 unsigned long start,row,column,j,sxh,sxm;\r
677ea103 1675 unsigned char *ta;\r
1676 unsigned char *cSRCPtr;\r
ce879073 1677 unsigned long LineOffset;\r
1678 int pmult=pageid/16;\r
1679\r
677ea103 1680 ta=(unsigned char *)texturepart;\r
ce879073 1681\r
1682 switch(mode)\r
1683 {\r
1684 //--------------------------------------------------// \r
1685 // 4bit texture load ..\r
1686 case 0:\r
1687 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1688\r
1689 sxm=g_x1&1;sxh=g_x1>>1;\r
1690 if(sxm) j=g_x1+1; else j=g_x1;\r
1691 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1692 for(column=g_y1;column<=g_y2;column++)\r
1693 {\r
1694 cSRCPtr = psxVub + start + (2048*column) + sxh;\r
1695 \r
1696 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);\r
1697 \r
1698 for(row=j;row<=g_x2;row++)\r
1699 {\r
1700 *ta++=(*cSRCPtr & 0xF); row++;\r
1701 if(row<=g_x2) *ta++=((*cSRCPtr >> 4) & 0xF); \r
1702 cSRCPtr++;\r
1703 }\r
1704 }\r
1705\r
1706 DefinePalTextureWnd();\r
1707 break;\r
1708 //--------------------------------------------------// \r
1709 // 8bit texture load ..\r
1710 case 1:\r
1711 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1712\r
1713 // not using a lookup table here... speeds up smaller texture areas\r
1714 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1715 LineOffset = 2048 - (g_x2-g_x1+1); \r
1716\r
1717 for(column=g_y1;column<=g_y2;column++)\r
1718 {\r
1719 for(row=g_x1;row<=g_x2;row++)\r
1720 *ta++=*cSRCPtr++;\r
1721 cSRCPtr+=LineOffset;\r
1722 }\r
1723\r
1724 DefinePalTextureWnd();\r
1725 break;\r
1726 }\r
1727 UploadTexWndPal(mode,cx,cy);\r
1728}\r
1729\r
1730////////////////////////////////////////////////////////////////////////\r
1731\r
1732void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)\r
1733{\r
1734 unsigned long start,row,column,j,sxh,sxm,ldx,ldy,ldxo;\r
677ea103 1735 unsigned char *ta,s;\r
1736 unsigned char *cSRCPtr,*cOSRCPtr;\r
ce879073 1737 unsigned long LineOffset;\r
1738 int pmult=pageid/16;\r
1739\r
1740 ldxo=TWin.Position.x1-TWin.OPosition.x1;\r
1741 ldy =TWin.Position.y1-TWin.OPosition.y1;\r
1742\r
677ea103 1743 ta=(unsigned char *)texturepart;\r
ce879073 1744\r
1745 switch(mode)\r
1746 {\r
1747 //--------------------------------------------------// \r
1748 // 4bit texture load ..\r
1749 case 0:\r
1750 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1751\r
1752 sxm=g_x1&1;sxh=g_x1>>1;\r
1753 if(sxm) j=g_x1+1; else j=g_x1;\r
1754 cSRCPtr = psxVub + start + (2048*g_y1) + sxh;\r
1755 for(column=g_y1;column<=g_y2;column++)\r
1756 {\r
1757 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1758 if(sxm) *ta++=((*cSRCPtr++ >> 4) & 0xF);\r
1759 \r
1760 for(row=j;row<=g_x2-ldxo;row++)\r
1761 {\r
1762 s=(*cSRCPtr & 0xF);\r
1763 *ta++=s;\r
1764 if(ldx) {*ta++=s;ldx--;}\r
1765 row++;\r
1766 if(row<=g_x2-ldxo) \r
1767 {\r
1768 s=((*cSRCPtr >> 4) & 0xF);\r
1769 *ta++=s; \r
1770 if(ldx) {*ta++=s;ldx--;}\r
1771 }\r
1772 cSRCPtr++;\r
1773 }\r
1774 if(ldy && column&1) \r
1775 {ldy--;cSRCPtr = cOSRCPtr;}\r
1776 else cSRCPtr = psxVub + start + (2048*(column+1)) + sxh;\r
1777 }\r
1778\r
1779 DefinePalTextureWnd();\r
1780 break;\r
1781 //--------------------------------------------------// \r
1782 // 8bit texture load ..\r
1783 case 1:\r
1784 start=((pageid-16*pmult)*128)+256*2048*pmult;\r
1785\r
1786 cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;\r
1787 LineOffset = 2048 - (g_x2-g_x1+1) +ldxo; \r
1788\r
1789 for(column=g_y1;column<=g_y2;column++)\r
1790 {\r
1791 cOSRCPtr=cSRCPtr;ldx=ldxo;\r
1792 for(row=g_x1;row<=g_x2-ldxo;row++)\r
1793 {\r
1794 s=*cSRCPtr++;\r
1795 *ta++=s;\r
1796 if(ldx) {*ta++=s;ldx--;}\r
1797 }\r
1798 if(ldy && column&1) {ldy--;cSRCPtr=cOSRCPtr;}\r
1799 else cSRCPtr+=LineOffset;\r
1800 }\r
1801\r
1802 DefinePalTextureWnd();\r
1803 break;\r
1804 }\r
1805 UploadTexWndPal(mode,cx,cy);\r
1806}\r
1807\r
1808////////////////////////////////////////////////////////////////////////\r
1809// tex window: main selecting, cache handler included\r
1810////////////////////////////////////////////////////////////////////////\r
1811\r
1812GLuint LoadTextureWnd(long pageid,long TextureMode,unsigned long GivenClutId)\r
1813{\r
1814 textureWndCacheEntry * ts, * tsx=NULL;\r
1815 int i;short cx,cy;\r
1816 EXLong npos;\r
1817\r
1818 npos.c[3]=TWin.Position.x0;\r
1819 npos.c[2]=TWin.OPosition.x1;\r
1820 npos.c[1]=TWin.Position.y0;\r
1821 npos.c[0]=TWin.OPosition.y1;\r
1822\r
1823 g_x1=TWin.Position.x0;g_x2=g_x1+TWin.Position.x1-1;\r
1824 g_y1=TWin.Position.y0;g_y2=g_y1+TWin.Position.y1-1;\r
1825\r
1826 if(TextureMode==2) {GivenClutId=0;cx=cy=0;}\r
1827 else \r
1828 {\r
1829 cx=((GivenClutId << 4) & 0x3F0);cy=((GivenClutId >> 6) & CLUTYMASK);\r
1830 GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30);\r
1831\r
1832 // palette check sum\r
1833 {\r
1834 unsigned long l=0,row;\r
1835 unsigned long * lSRCPtr=(unsigned long *)(psxVuw+cx+(cy*1024));\r
1836 if(TextureMode==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;\r
1837 else for(row=1;row<9;row++) l+=((*lSRCPtr++)-1)<<row;\r
1838 l=(l+HIWORD(l))&0x3fffL;\r
1839 GivenClutId|=(l<<16);\r
1840 }\r
1841\r
1842 }\r
1843\r
1844 ts=wcWndtexStore;\r
1845\r
1846 for(i=0;i<iMaxTexWnds;i++,ts++)\r
1847 {\r
1848 if(ts->used)\r
1849 {\r
1850 if(ts->pos.l==npos.l &&\r
1851 ts->pageid==pageid &&\r
1852 ts->textureMode==TextureMode)\r
1853 {\r
1854 if(ts->ClutID==GivenClutId)\r
1855 {\r
1856 ubOpaqueDraw=ts->Opaque;\r
1857 return ts->texname;\r
1858 }\r
1859 }\r
1860 }\r
1861 else tsx=ts;\r
1862 }\r
1863\r
1864 if(!tsx) \r
1865 {\r
1866 if(iMaxTexWnds==iTexWndLimit)\r
1867 {\r
1868 tsx=wcWndtexStore+iTexWndTurn;\r
1869 iTexWndTurn++; \r
1870 if(iTexWndTurn==iTexWndLimit) iTexWndTurn=0;\r
1871 }\r
1872 else\r
1873 {\r
1874 tsx=wcWndtexStore+iMaxTexWnds;\r
1875 iMaxTexWnds++;\r
1876 }\r
1877 }\r
1878\r
1879 gTexName=tsx->texname;\r
1880\r
1881 if(TWin.OPosition.y1==TWin.Position.y1 &&\r
1882 TWin.OPosition.x1==TWin.Position.x1)\r
1883 {\r
1884 LoadWndTexturePage(pageid,TextureMode,cx,cy);\r
1885 } \r
1886 else\r
1887 {\r
1888 LoadStretchWndTexturePage(pageid,TextureMode,cx,cy);\r
1889 }\r
1890\r
1891 tsx->Opaque=ubOpaqueDraw;\r
1892 tsx->pos.l=npos.l;\r
1893 tsx->ClutID=GivenClutId;\r
1894 tsx->pageid=pageid;\r
1895 tsx->textureMode=TextureMode;\r
1896 tsx->texname=gTexName;\r
1897 tsx->used=1;\r
1898 \r
1899 return gTexName;\r
1900}\r
1901\r
1902/////////////////////////////////////////////////////////////////////////////\r
1903/////////////////////////////////////////////////////////////////////////////\r
1904/////////////////////////////////////////////////////////////////////////////\r
1905\r
1906////////////////////////////////////////////////////////////////////////\r
1907// movie texture: define\r
1908////////////////////////////////////////////////////////////////////////\r
1909\r
1910void DefinePackedTextureMovie(void)\r
1911{\r
1912 if(gTexMovieName==0)\r
1913 {\r
9f58cabb 1914 glEnable(GL_TEXTURE_2D);\r
1915 glGenTextures(1, &gTexMovieName); glError();\r
ce879073 1916 gTexName=gTexMovieName;\r
9f58cabb 1917 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1918\r
9f58cabb 1919 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
1920 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
ce879073 1921\r
1922 if(!bUseFastMdec) \r
1923 {\r
9f58cabb 1924 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();\r
1925 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();\r
ce879073 1926 }\r
1927 else\r
1928 {\r
9f58cabb 1929 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
1930 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 1931 }\r
1932 \r
1933 glTexImage2D(GL_TEXTURE_2D, 0, //giWantedRGBA, \r
1934 GL_RGBA,\r
9f58cabb 1935 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
ce879073 1936 }\r
1937 else \r
1938 {\r
9f58cabb 1939 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1940 }\r
1941\r
1942 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,\r
1943 (xrMovieArea.x1-xrMovieArea.x0), \r
1944 (xrMovieArea.y1-xrMovieArea.y0), \r
1945 GL_RGBA,\r
1946 GL_UNSIGNED_SHORT,\r
9f58cabb 1947 texturepart); glError();\r
1948 //LOGE("DefinePackedTextureMovie x:%d y:%d",(xrMovieArea.x1-xrMovieArea.x0),(xrMovieArea.y1-xrMovieArea.y0));\r
1949\r
ce879073 1950}\r
1951\r
1952////////////////////////////////////////////////////////////////////////\r
1953\r
1954void DefineTextureMovie(void)\r
1955{\r
1956 if(gTexMovieName==0)\r
1957 {\r
9f58cabb 1958 glGenTextures(1, &gTexMovieName); glError();\r
ce879073 1959 gTexName=gTexMovieName;\r
9f58cabb 1960 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1961\r
9f58cabb 1962 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
1963 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
ce879073 1964 \r
1965 if(!bUseFastMdec) \r
1966 {\r
9f58cabb 1967 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glError();\r
1968 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glError();\r
ce879073 1969 }\r
1970 else\r
1971 {\r
9f58cabb 1972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
1973 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 1974 }\r
1975\r
9f58cabb 1976 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
ce879073 1977 }\r
1978 else \r
1979 {\r
9f58cabb 1980 gTexName=gTexMovieName;glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 1981 }\r
1982\r
1983 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,\r
1984 (xrMovieArea.x1-xrMovieArea.x0), \r
1985 (xrMovieArea.y1-xrMovieArea.y0), \r
9f58cabb 1986 GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
1987 //LOGE("DefineTextureMovie x:%d y:%d",(xrMovieArea.x1-xrMovieArea.x0),(xrMovieArea.y1-xrMovieArea.y0));\r
ce879073 1988}\r
1989\r
1990////////////////////////////////////////////////////////////////////////\r
1991// movie texture: load\r
1992////////////////////////////////////////////////////////////////////////\r
1993\r
1994#define MRED(x) ((x>>3) & 0x1f)\r
1995#define MGREEN(x) ((x>>6) & 0x3e0)\r
1996#define MBLUE(x) ((x>>9) & 0x7c00)\r
1997\r
1998#define XMGREEN(x) ((x>>5) & 0x07c0)\r
1999#define XMRED(x) ((x<<8) & 0xf800)\r
2000#define XMBLUE(x) ((x>>18) & 0x003e)\r
2001\r
2002////////////////////////////////////////////////////////////////////////\r
2003// movie texture: load\r
2004////////////////////////////////////////////////////////////////////////\r
2005\r
677ea103 2006unsigned char * LoadDirectMovieFast(void)\r
ce879073 2007{\r
2008 long row,column;\r
2009 unsigned int startxy;\r
2010\r
2011 unsigned long * ta=(unsigned long *)texturepart;\r
2012\r
2013 if(PSXDisplay.RGB24)\r
2014 {\r
677ea103 2015 unsigned char * pD;\r
ce879073 2016\r
2017 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;\r
2018\r
2019 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)\r
2020 {\r
677ea103 2021 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2022 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2023 {\r
2024 *ta++=*((unsigned long *)pD)|0xff000000;\r
2025 pD+=3;\r
2026 }\r
2027 }\r
2028 }\r
2029 else\r
2030 {\r
2031 unsigned long (*LTCOL)(unsigned long);\r
2032\r
2033 LTCOL=XP8RGBA_0;//TCF[0];\r
2034\r
2035 ubOpaqueDraw=0;\r
2036\r
2037 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2038 {\r
2039 startxy=((1024)*column)+xrMovieArea.x0;\r
2040 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2041 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2042 }\r
2043 }\r
2044 \r
2045 return texturepart;\r
2046}\r
2047\r
2048////////////////////////////////////////////////////////////////////////\r
2049\r
2050GLuint LoadTextureMovieFast(void)\r
2051{\r
2052 long row,column;\r
2053 unsigned int start,startxy;\r
2054\r
2055{\r
2056 if(PSXDisplay.RGB24)\r
2057 {\r
677ea103 2058 unsigned char * pD;\r
ce879073 2059 unsigned long * ta=(unsigned long *)texturepart;\r
2060\r
2061 startxy=((1024)*xrMovieArea.y0)+xrMovieArea.x0;\r
2062\r
2063 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++,startxy+=1024)\r
2064 {\r
2065 //startxy=((1024)*column)+xrMovieArea.x0;\r
677ea103 2066 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2067 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2068 {\r
2069 *ta++=*((unsigned long *)pD)|0xff000000;\r
2070 pD+=3;\r
2071 }\r
2072 }\r
2073 }\r
2074 else\r
2075 {\r
2076 unsigned long (*LTCOL)(unsigned long);\r
2077 unsigned long *ta;\r
2078\r
2079 LTCOL=XP8RGBA_0;//TCF[0];\r
2080\r
2081 ubOpaqueDraw=0;\r
2082 ta=(unsigned long *)texturepart;\r
2083\r
2084 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2085 {\r
2086 startxy=((1024)*column)+xrMovieArea.x0;\r
2087 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2088 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2089 }\r
2090 }\r
2091 DefineTextureMovie();\r
2092 }\r
2093 return gTexName; \r
2094}\r
2095\r
2096////////////////////////////////////////////////////////////////////////\r
2097\r
2098GLuint LoadTextureMovie(void)\r
2099{\r
2100 short row,column,dx;\r
2101 unsigned int startxy;\r
2102 BOOL b_X,b_Y;\r
2103\r
2104 if(bUseFastMdec) return LoadTextureMovieFast();\r
2105\r
2106 b_X=FALSE;b_Y=FALSE;\r
2107\r
2108 if((xrMovieArea.x1-xrMovieArea.x0)<255) b_X=TRUE;\r
2109 if((xrMovieArea.y1-xrMovieArea.y0)<255) b_Y=TRUE;\r
2110\r
2111{\r
2112 if(PSXDisplay.RGB24)\r
2113 {\r
677ea103 2114 unsigned char * pD;\r
ce879073 2115 unsigned long * ta=(unsigned long *)texturepart;\r
2116\r
2117 if(b_X)\r
2118 {\r
2119 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2120 {\r
2121 startxy=((1024)*column)+xrMovieArea.x0;\r
677ea103 2122 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2123 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2124 {\r
2125 *ta++=*((unsigned long *)pD)|0xff000000;\r
2126 pD+=3;\r
2127 }\r
2128 *ta++=*(ta-1);\r
2129 }\r
2130 if(b_Y)\r
2131 {\r
2132 dx=xrMovieArea.x1-xrMovieArea.x0+1;\r
2133 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2134 *ta++=*(ta-dx);\r
2135 *ta++=*(ta-1);\r
2136 }\r
2137 }\r
2138 else\r
2139 {\r
2140 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2141 {\r
2142 startxy=((1024)*column)+xrMovieArea.x0;\r
677ea103 2143 pD=(unsigned char *)&psxVuw[startxy];\r
ce879073 2144 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2145 {\r
2146 *ta++=*((unsigned long *)pD)|0xff000000;\r
2147 pD+=3;\r
2148 }\r
2149 }\r
2150 if(b_Y)\r
2151 {\r
2152 dx=xrMovieArea.x1-xrMovieArea.x0;\r
2153 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2154 *ta++=*(ta-dx);\r
2155 }\r
2156 }\r
2157 }\r
2158 else\r
2159 {\r
2160 unsigned long (*LTCOL)(unsigned long);\r
2161 unsigned long *ta;\r
2162\r
2163 LTCOL=XP8RGBA_0;//TCF[0];\r
2164\r
2165 ubOpaqueDraw=0;\r
2166 ta=(unsigned long *)texturepart;\r
2167\r
2168 if(b_X)\r
2169 {\r
2170 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2171 {\r
2172 startxy=((1024)*column)+xrMovieArea.x0;\r
2173 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2174 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2175 *ta++=*(ta-1);\r
2176 }\r
2177\r
2178 if(b_Y)\r
2179 {\r
2180 dx=xrMovieArea.x1-xrMovieArea.x0+1;\r
2181 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2182 *ta++=*(ta-dx);\r
2183 *ta++=*(ta-1);\r
2184 }\r
2185 }\r
2186 else\r
2187 {\r
2188 for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)\r
2189 {\r
2190 startxy=((1024)*column)+xrMovieArea.x0;\r
2191 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2192 *ta++=LTCOL(psxVuw[startxy++]|0x8000);\r
2193 }\r
2194\r
2195 if(b_Y)\r
2196 {\r
2197 dx=xrMovieArea.x1-xrMovieArea.x0;\r
2198 for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)\r
2199 *ta++=*(ta-dx);\r
2200 }\r
2201 }\r
2202 }\r
2203\r
2204 xrMovieArea.x1+=b_X;xrMovieArea.y1+=b_Y;\r
2205 DefineTextureMovie();\r
2206 xrMovieArea.x1-=b_X;xrMovieArea.y1-=b_Y;\r
2207 }\r
2208 return gTexName; \r
2209}\r
2210\r
2211/////////////////////////////////////////////////////////////////////////////\r
2212/////////////////////////////////////////////////////////////////////////////\r
2213/////////////////////////////////////////////////////////////////////////////\r
2214\r
2215GLuint BlackFake15BitTexture(void)\r
2216{\r
2217 long pmult;short x1,x2,y1,y2;\r
2218\r
2219 if(PSXDisplay.InterlacedTest) return 0;\r
2220 \r
2221 pmult=GlobalTexturePage/16;\r
2222 x1=gl_ux[7];\r
2223 x2=gl_ux[6]-gl_ux[7];\r
2224 y1=gl_ux[5];\r
2225 y2=gl_ux[4]-gl_ux[5];\r
2226\r
2227 if(iSpriteTex)\r
2228 {\r
2229 if(x2<255) x2++;\r
2230 if(y2<255) y2++;\r
2231 }\r
2232\r
2233 y1+=pmult*256;\r
2234 x1+=((GlobalTexturePage-16*pmult)<<6);\r
2235\r
2236 if( FastCheckAgainstFrontScreen(x1,y1,x2,y2)\r
2237 || FastCheckAgainstScreen(x1,y1,x2,y2))\r
2238 {\r
2239 if(!gTexFrameName)\r
2240 {\r
9f58cabb 2241 glGenTextures(1, &gTexFrameName); glError();\r
ce879073 2242 gTexName=gTexFrameName;\r
9f58cabb 2243 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2244\r
9f58cabb 2245 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
2246 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
2247 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
2248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 2249 \r
2250 {\r
2251 unsigned long * ta=(unsigned long *)texturepart;\r
2252 for(y1=0;y1<=4;y1++)\r
2253 for(x1=0;x1<=4;x1++)\r
2254 *ta++=0xff000000;\r
2255 }\r
9f58cabb 2256 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, texturepart); glError();\r
2257\r
ce879073 2258 }\r
2259 else\r
2260 {\r
2261 gTexName=gTexFrameName;\r
9f58cabb 2262 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2263 }\r
9f58cabb 2264 //LOGE("BlackFake15BitTexture x:%d y:%d",4,4);\r
ce879073 2265 ubOpaqueDraw=0;\r
2266\r
2267 return (GLuint)gTexName;\r
2268 }\r
2269 return 0;\r
2270}\r
2271\r
2272/////////////////////////////////////////////////////////////////////////////\r
2273\r
2274BOOL bFakeFrontBuffer=FALSE;\r
2275BOOL bIgnoreNextTile =FALSE;\r
2276\r
2277int iFTex=512;\r
2278\r
2279GLuint Fake15BitTexture(void)\r
2280{\r
2281 long pmult;short x1,x2,y1,y2;int iYAdjust;\r
2282 float ScaleX,ScaleY;RECT rSrc;\r
2283\r
2284 if(iFrameTexType==1) return BlackFake15BitTexture();\r
2285 if(PSXDisplay.InterlacedTest) return 0;\r
2286 \r
2287 pmult=GlobalTexturePage/16;\r
2288 x1=gl_ux[7];\r
2289 x2=gl_ux[6]-gl_ux[7];\r
2290 y1=gl_ux[5];\r
2291 y2=gl_ux[4]-gl_ux[5];\r
2292\r
2293 y1+=pmult*256;\r
2294 x1+=((GlobalTexturePage-16*pmult)<<6);\r
2295\r
2296 if(iFrameTexType==3)\r
2297 {\r
2298 if(iFrameReadType==4) return 0;\r
2299\r
2300 if(!FastCheckAgainstFrontScreen(x1,y1,x2,y2) &&\r
2301 !FastCheckAgainstScreen(x1,y1,x2,y2))\r
2302 return 0;\r
2303\r
2304 if(bFakeFrontBuffer) bIgnoreNextTile=TRUE;\r
2305 CheckVRamReadEx(x1,y1,x1+x2,y1+y2);\r
2306 return 0;\r
2307 }\r
2308\r
2309 /////////////////////////\r
2310\r
2311 if(FastCheckAgainstFrontScreen(x1,y1,x2,y2))\r
2312 {\r
2313 x1-=PSXDisplay.DisplayPosition.x;\r
2314 y1-=PSXDisplay.DisplayPosition.y;\r
2315 }\r
2316 else\r
2317 if(FastCheckAgainstScreen(x1,y1,x2,y2))\r
2318 {\r
2319 x1-=PreviousPSXDisplay.DisplayPosition.x;\r
2320 y1-=PreviousPSXDisplay.DisplayPosition.y;\r
2321 }\r
2322 else return 0;\r
2323\r
2324 bDrawMultiPass = FALSE;\r
2325\r
2326 if(!gTexFrameName)\r
2327 {\r
677ea103 2328 char * p;\r
ce879073 2329\r
2330 if(iResX>1280 || iResY>1024) iFTex=2048;\r
2331 else\r
2332 if(iResX>640 || iResY>480) iFTex=1024;\r
2333 else iFTex=512; \r
2334\r
9f58cabb 2335 glGenTextures(1, &gTexFrameName); glError();\r
ce879073 2336 gTexName=gTexFrameName;\r
9f58cabb 2337 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2338\r
9f58cabb 2339 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, iClampType); glError();\r
2340 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, iClampType); glError();\r
2341 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, iFilter); glError();\r
2342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, iFilter); glError();\r
ce879073 2343\r
677ea103 2344 p=(char *)malloc(iFTex*iFTex*4);\r
ce879073 2345 memset(p,0,iFTex*iFTex*4);\r
9f58cabb 2346 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, iFTex, iFTex, 0, GL_RGBA, GL_UNSIGNED_BYTE, p); glError();\r
ce879073 2347 free(p);\r
2348\r
2349 glGetError();\r
2350 }\r
2351 else \r
2352 {\r
2353 gTexName=gTexFrameName;\r
9f58cabb 2354 glBindTexture(GL_TEXTURE_2D, gTexName); glError();\r
ce879073 2355 }\r
9f58cabb 2356 //LOGE("Fake15BitTexture x:%d y:%d",iFTex,iFTex);\r
ce879073 2357 x1+=PreviousPSXDisplay.Range.x0;\r
2358 y1+=PreviousPSXDisplay.Range.y0;\r
2359\r
2360 if(PSXDisplay.DisplayMode.x)\r
2361 ScaleX=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;\r
2362 else ScaleX=1.0f;\r
2363 if(PSXDisplay.DisplayMode.y)\r
2364 ScaleY=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;\r
2365 else ScaleY=1.0f;\r
2366\r
2367 rSrc.left =max(x1*ScaleX,0);\r
2368 rSrc.right =min((x1+x2)*ScaleX+0.99f,iResX-1);\r
2369 rSrc.top =max(y1*ScaleY,0);\r
2370 rSrc.bottom=min((y1+y2)*ScaleY+0.99f,iResY-1);\r
2371\r
2372 iYAdjust=(y1+y2)-PSXDisplay.DisplayMode.y;\r
2373 if(iYAdjust>0)\r
2374 iYAdjust=(int)((float)iYAdjust*ScaleY)+1;\r
2375 else iYAdjust=0;\r
2376 \r
2377 gl_vy[0]=255-gl_vy[0];\r
2378 gl_vy[1]=255-gl_vy[1];\r
2379 gl_vy[2]=255-gl_vy[2];\r
2380 gl_vy[3]=255-gl_vy[3];\r
2381\r
2382 y1=min(gl_vy[0],min(gl_vy[1],min(gl_vy[2],gl_vy[3])));\r
2383\r
2384 gl_vy[0]-=y1;\r
2385 gl_vy[1]-=y1;\r
2386 gl_vy[2]-=y1;\r
2387 gl_vy[3]-=y1;\r
2388 gl_ux[0]-=gl_ux[7];\r
2389 gl_ux[1]-=gl_ux[7];\r
2390 gl_ux[2]-=gl_ux[7];\r
2391 gl_ux[3]-=gl_ux[7];\r
2392\r
2393 ScaleX*=256.0f/((float)(iFTex));\r
2394 ScaleY*=256.0f/((float)(iFTex));\r
2395\r
2396 y1=((float)gl_vy[0]*ScaleY); if(y1>255) y1=255;\r
2397 gl_vy[0]=y1;\r
2398 y1=((float)gl_vy[1]*ScaleY); if(y1>255) y1=255;\r
2399 gl_vy[1]=y1;\r
2400 y1=((float)gl_vy[2]*ScaleY); if(y1>255) y1=255;\r
2401 gl_vy[2]=y1;\r
2402 y1=((float)gl_vy[3]*ScaleY); if(y1>255) y1=255;\r
2403 gl_vy[3]=y1;\r
2404\r
2405 x1=((float)gl_ux[0]*ScaleX); if(x1>255) x1=255;\r
2406 gl_ux[0]=x1;\r
2407 x1=((float)gl_ux[1]*ScaleX); if(x1>255) x1=255;\r
2408 gl_ux[1]=x1;\r
2409 x1=((float)gl_ux[2]*ScaleX); if(x1>255) x1=255;\r
2410 gl_ux[2]=x1;\r
2411 x1=((float)gl_ux[3]*ScaleX); if(x1>255) x1=255;\r
2412 gl_ux[3]=x1;\r
2413\r
2414 x1=rSrc.right-rSrc.left;\r
2415 if(x1<=0) x1=1;\r
2416 if(x1>iFTex) x1=iFTex;\r
2417\r
2418 y1=rSrc.bottom-rSrc.top;\r
2419 if(y1<=0) y1=1;\r
2420 if(y1+iYAdjust>iFTex) y1=iFTex-iYAdjust;\r
2421\r
2422\r
2423 glCopyTexSubImage2D( GL_TEXTURE_2D, 0, \r
2424 0,\r
2425 iYAdjust,\r
2426 rSrc.left+rRatioRect.left,\r
2427 iResY-rSrc.bottom-rRatioRect.top,\r
9f58cabb 2428 x1,y1); glError();\r
ce879073 2429\r
2430 if(glGetError()) \r
2431 {\r
677ea103 2432 char * p=(char *)malloc(iFTex*iFTex*4);\r
ce879073 2433 memset(p,0,iFTex*iFTex*4);\r
2434 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, iFTex, iFTex,\r
9f58cabb 2435 GL_RGBA, GL_UNSIGNED_BYTE, p); glError();\r
ce879073 2436 free(p);\r
2437 }\r
2438\r
2439 \r
2440 ubOpaqueDraw=0;\r
2441\r
2442 if(iSpriteTex)\r
2443 {\r
2444 sprtW=gl_ux[1]-gl_ux[0]; \r
2445 sprtH=-(gl_vy[0]-gl_vy[2]);\r
2446 }\r
2447\r
2448 return (GLuint)gTexName;\r
2449}\r
2450\r
2451/////////////////////////////////////////////////////////////////////////////\r
2452/////////////////////////////////////////////////////////////////////////////\r
2453/////////////////////////////////////////////////////////////////////////////\r
2454//\r
2455// load texture part (unpacked)\r
2456//\r
2457/////////////////////////////////////////////////////////////////////////////\r
2458/////////////////////////////////////////////////////////////////////////////\r
2459/////////////////////////////////////////////////////////////////////////////\r
2460\r
2461void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)\r
2462{\r
2463 unsigned long start,row,column,j,sxh,sxm;\r
2464 unsigned int palstart;\r
2465 unsigned long *px,*pa,*ta;\r
677ea103 2466 unsigned char *cSRCPtr;\r
ce879073 2467 unsigned short *wSRCPtr;\r
2468 unsigned long LineOffset;\r
2469 unsigned long x2a,xalign=0;\r
2470 unsigned long x1=gl_ux[7];\r
2471 unsigned long x2=gl_ux[6];\r
2472 unsigned long y1=gl_ux[5];\r
2473 unsigned long y2=gl_ux[4];\r
2474 unsigned long dx=x2-x1+1;\r
2475 unsigned long dy=y2-y1+1;\r
2476 int pmult=pageid/16;\r
2477 unsigned long (*LTCOL)(unsigned long);\r
2478 unsigned int a,r,g,b,cnt,h;\r
2479 unsigned long scol[8];\r
2480 \r
2481 LTCOL=TCF[DrawSemiTrans];\r
2482\r
2483 pa=px=(unsigned long *)ubPaletteBuffer;\r
2484 ta=(unsigned long *)texturepart;\r
2485 palstart=cx+(cy<<10);\r
2486\r
2487 ubOpaqueDraw=0;\r
2488\r
2489 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}\r
2490 if(XTexS) {ta+=1;xalign=2;}\r
2491\r
2492 switch(mode)\r
2493 {\r
2494 //--------------------------------------------------// \r
2495 // 4bit texture load ..\r
2496 case 0:\r
2497 if(GlobalTextIL)\r
2498 {\r
2499 unsigned int TXV,TXU,n_xi,n_yi;\r
2500\r
2501 wSRCPtr=psxVuw+palstart;\r
2502\r
2503 row=4;do\r
2504 {\r
2505 *px =LTCOL(*wSRCPtr);\r
2506 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2507 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2508 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2509 row--;px+=4;wSRCPtr+=4;\r
2510 }\r
2511 while (row);\r
2512\r
2513 for(TXV=y1;TXV<=y2;TXV++)\r
2514 {\r
2515 for(TXU=x1;TXU<=x2;TXU++)\r
2516 {\r
2517 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
2518 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
2519\r
2520 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
2521 }\r
2522 ta+=xalign;\r
2523 }\r
2524 break;\r
2525 }\r
2526\r
2527 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2528 // convert CLUT to 32bits .. and then use THAT as a lookup table\r
2529\r
2530 wSRCPtr=psxVuw+palstart;\r
2531\r
2532 row=4;do\r
2533 {\r
2534 *px =LTCOL(*wSRCPtr);\r
2535 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2536 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2537 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2538 row--;px+=4;wSRCPtr+=4;\r
2539 }\r
2540 while (row);\r
2541\r
2542 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;\r
2543 sxm=x1&1;sxh=x1>>1;\r
2544 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;\r
2545 for(column=y1;column<=y2;column++)\r
2546 {\r
2547 cSRCPtr = psxVub + start + (column<<11) + sxh;\r
2548 \r
2549 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
2550\r
2551 for(row=j;row<x2a;row+=2)\r
2552 {\r
2553 *ta =*(pa+(*cSRCPtr & 0xF)); \r
2554 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
2555 cSRCPtr++;ta+=2;\r
2556 }\r
2557\r
2558 if(row<=x2) \r
2559 {\r
2560 *ta++=*(pa+(*cSRCPtr & 0xF)); row++;\r
2561 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));\r
2562 }\r
2563\r
2564 ta+=xalign;\r
2565 }\r
2566\r
2567 break;\r
2568 //--------------------------------------------------// \r
2569 // 8bit texture load ..\r
2570 case 1:\r
2571 if(GlobalTextIL)\r
2572 {\r
2573 unsigned int TXV,TXU,n_xi,n_yi;\r
2574\r
2575 wSRCPtr=psxVuw+palstart;\r
2576\r
2577 row=64;do\r
2578 {\r
2579 *px =LTCOL(*wSRCPtr);\r
2580 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2581 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2582 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2583 row--;px+=4;wSRCPtr+=4;\r
2584 }\r
2585 while (row);\r
2586\r
2587 for(TXV=y1;TXV<=y2;TXV++)\r
2588 {\r
2589 for(TXU=x1;TXU<=x2;TXU++)\r
2590 {\r
2591 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
2592 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
2593\r
2594 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
2595 }\r
2596 ta+=xalign;\r
2597 }\r
2598\r
2599 break;\r
2600 }\r
2601\r
2602 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2603\r
2604 cSRCPtr = psxVub + start + (y1<<11) + x1;\r
2605 LineOffset = 2048 - dx; \r
2606\r
2607 if(dy*dx>384)\r
2608 {\r
2609 wSRCPtr=psxVuw+palstart;\r
2610\r
2611 row=64;do\r
2612 {\r
2613 *px =LTCOL(*wSRCPtr);\r
2614 *(px+1)=LTCOL(*(wSRCPtr+1));\r
2615 *(px+2)=LTCOL(*(wSRCPtr+2));\r
2616 *(px+3)=LTCOL(*(wSRCPtr+3));\r
2617 row--;px+=4;wSRCPtr+=4;\r
2618 }\r
2619 while (row);\r
2620\r
2621 column=dy;do \r
2622 {\r
2623 row=dx;\r
2624 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);\r
2625 ta+=xalign;\r
2626 cSRCPtr+=LineOffset;column--;\r
2627 }\r
2628 while(column);\r
2629 }\r
2630 else\r
2631 {\r
2632 wSRCPtr=psxVuw+palstart;\r
2633\r
2634 column=dy;do \r
2635 {\r
2636 row=dx;\r
2637 do {*ta++=LTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);\r
2638 ta+=xalign;\r
2639 cSRCPtr+=LineOffset;column--;\r
2640 }\r
2641 while(column);\r
2642 }\r
2643\r
2644 break;\r
2645 //--------------------------------------------------// \r
2646 // 16bit texture load ..\r
2647 case 2:\r
2648 start=((pageid-16*pmult)<<6)+262144*pmult;\r
2649\r
2650 wSRCPtr = psxVuw + start + (y1<<10) + x1;\r
2651 LineOffset = 1024 - dx; \r
2652\r
2653 column=dy;do \r
2654 {\r
2655 row=dx;\r
2656 do {*ta++=LTCOL(*wSRCPtr++);row--;} while(row);\r
2657 ta+=xalign;\r
2658 wSRCPtr+=LineOffset;column--;\r
2659 }\r
2660 while(column);\r
2661\r
2662 break;\r
2663 //--------------------------------------------------//\r
2664 // others are not possible !\r
2665 }\r
2666\r
2667 x2a=dx+xalign;\r
2668\r
2669 if(YTexS)\r
2670 {\r
2671 ta=(unsigned long *)texturepart;\r
2672 pa=(unsigned long *)texturepart+x2a;\r
2673 row=x2a;do {*ta++=*pa++;row--;} while(row); \r
2674 pa=(unsigned long *)texturepart+dy*x2a;\r
2675 ta=pa+x2a;\r
2676 row=x2a;do {*ta++=*pa++;row--;} while(row);\r
2677 YTexS--;\r
2678 dy+=2;\r
2679 }\r
2680\r
2681 if(XTexS)\r
2682 {\r
2683 ta=(unsigned long *)texturepart;\r
2684 pa=ta+1;\r
2685 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
2686 pa=(unsigned long *)texturepart+dx;\r
2687 ta=pa+1;\r
2688 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
2689 XTexS--;\r
2690 dx+=2;\r
2691 }\r
2692\r
2693 DXTexS=dx;DYTexS=dy;\r
2694\r
2695 if(!iFilterType) {DefineSubTextureSort();return;}\r
2696 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}\r
2697 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)\r
2698 {DefineSubTextureSort();return;}\r
2699\r
2700 ta=(unsigned long *)texturepart;\r
2701 x1=dx-1;\r
2702 y1=dy-1;\r
2703\r
2704 if(bOpaquePass)\r
2705 {\r
2706{\r
2707 for(column=0;column<dy;column++)\r
2708 {\r
2709 for(row=0;row<dx;row++)\r
2710 {\r
2711 if(*ta==0x50000000)\r
2712 {\r
2713 cnt=0;\r
2714\r
2715 if( column && *(ta-dx) !=0x50000000 && *(ta-dx)>>24!=1) scol[cnt++]=*(ta-dx);\r
2716 if(row && *(ta-1) !=0x50000000 && *(ta-1)>>24!=1) scol[cnt++]=*(ta-1);\r
2717 if(row!=x1 && *(ta+1) !=0x50000000 && *(ta+1)>>24!=1) scol[cnt++]=*(ta+1);\r
2718 if( column!=y1 && *(ta+dx) !=0x50000000 && *(ta+dx)>>24!=1) scol[cnt++]=*(ta+dx);\r
2719\r
2720 if(row && column && *(ta-dx-1)!=0x50000000 && *(ta-dx-1)>>24!=1) scol[cnt++]=*(ta-dx-1);\r
2721 if(row!=x1 && column && *(ta-dx+1)!=0x50000000 && *(ta-dx+1)>>24!=1) scol[cnt++]=*(ta-dx+1);\r
2722 if(row && column!=y1 && *(ta+dx-1)!=0x50000000 && *(ta+dx-1)>>24!=1) scol[cnt++]=*(ta+dx-1);\r
2723 if(row!=x1 && column!=y1 && *(ta+dx+1)!=0x50000000 && *(ta+dx+1)>>24!=1) scol[cnt++]=*(ta+dx+1);\r
2724\r
2725 if(cnt)\r
2726 {\r
2727 r=g=b=a=0;\r
2728 for(h=0;h<cnt;h++)\r
2729 {\r
2730 a+=(scol[h]>>24);\r
2731 r+=(scol[h]>>16)&0xff;\r
2732 g+=(scol[h]>>8)&0xff;\r
2733 b+=scol[h]&0xff;\r
2734 }\r
2735 r/=cnt;b/=cnt;g/=cnt;\r
2736\r
2737 *ta=(r<<16)|(g<<8)|b;\r
2738 if(a) *ta|=0x50000000;\r
2739 else *ta|=0x01000000;\r
2740 }\r
2741 }\r
2742 ta++;\r
2743 }\r
2744 }\r
2745 }\r
2746 }\r
2747 else\r
2748 for(column=0;column<dy;column++)\r
2749 {\r
2750 for(row=0;row<dx;row++)\r
2751 {\r
2752 if(*ta==0x00000000)\r
2753 {\r
2754 cnt=0;\r
2755\r
2756 if(row!=x1 && *(ta+1) !=0x00000000) scol[cnt++]=*(ta+1);\r
2757 if( column!=y1 && *(ta+dx) !=0x00000000) scol[cnt++]=*(ta+dx);\r
2758\r
2759 if(cnt)\r
2760 {\r
2761 r=g=b=0;\r
2762 for(h=0;h<cnt;h++)\r
2763 {\r
2764 r+=(scol[h]>>16)&0xff;\r
2765 g+=(scol[h]>>8)&0xff;\r
2766 b+=scol[h]&0xff;\r
2767 }\r
2768 r/=cnt;b/=cnt;g/=cnt;\r
2769 *ta=(r<<16)|(g<<8)|b;\r
2770 }\r
2771 }\r
2772 ta++;\r
2773 }\r
2774 }\r
2775\r
2776 DefineSubTextureSort();\r
2777}\r
2778\r
2779/////////////////////////////////////////////////////////////////////////////\r
2780/////////////////////////////////////////////////////////////////////////////\r
2781/////////////////////////////////////////////////////////////////////////////\r
2782//\r
2783// load texture part (packed)\r
2784//\r
2785/////////////////////////////////////////////////////////////////////////////\r
2786/////////////////////////////////////////////////////////////////////////////\r
2787/////////////////////////////////////////////////////////////////////////////\r
2788\r
2789void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)\r
2790{\r
2791 unsigned long start,row,column,j,sxh,sxm;\r
2792 unsigned int palstart;\r
2793 unsigned short *px,*pa,*ta;\r
677ea103 2794 unsigned char *cSRCPtr;\r
ce879073 2795 unsigned short *wSRCPtr;\r
2796 unsigned long LineOffset;\r
2797 unsigned long x2a,xalign=0;\r
2798 unsigned long x1=gl_ux[7];\r
2799 unsigned long x2=gl_ux[6];\r
2800 unsigned long y1=gl_ux[5];\r
2801 unsigned long y2=gl_ux[4];\r
2802 unsigned long dx=x2-x1+1;\r
2803 unsigned long dy=y2-y1+1;\r
2804 int pmult=pageid/16;\r
2805 unsigned short (*LPTCOL)(unsigned short);\r
2806 unsigned int a,r,g,b,cnt,h;\r
2807 unsigned short scol[8];\r
2808\r
2809 LPTCOL=PTCF[DrawSemiTrans];\r
2810\r
2811 pa=px=(unsigned short *)ubPaletteBuffer;\r
2812 ta=(unsigned short *)texturepart;\r
2813 palstart=cx+(cy<<10);\r
2814\r
2815 ubOpaqueDraw=0;\r
2816\r
2817 if(YTexS) {ta+=dx;if(XTexS) ta+=2;}\r
2818 if(XTexS) {ta+=1;xalign=2;}\r
2819\r
2820 switch(mode)\r
2821 {\r
2822 //--------------------------------------------------// \r
2823 // 4bit texture load ..\r
2824 case 0:\r
2825 if(GlobalTextIL)\r
2826 {\r
2827 unsigned int TXV,TXU,n_xi,n_yi;\r
2828\r
2829 wSRCPtr=psxVuw+palstart;\r
2830 row=4;do\r
2831 {\r
2832 *px =LPTCOL(*wSRCPtr);\r
2833 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2834 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2835 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2836 row--;px+=4;wSRCPtr+=4;\r
2837 }\r
2838 while (row);\r
2839\r
2840 for(TXV=y1;TXV<=y2;TXV++)\r
2841 {\r
2842 for(TXU=x1;TXU<=x2;TXU++)\r
2843 {\r
2844 n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );\r
2845 n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );\r
2846\r
2847 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));\r
2848 }\r
2849 ta+=xalign;\r
2850 }\r
2851 break;\r
2852 }\r
2853\r
2854 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2855\r
2856 wSRCPtr=psxVuw+palstart;\r
2857 row=4;do\r
2858 {\r
2859 *px =LPTCOL(*wSRCPtr);\r
2860 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2861 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2862 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2863 row--;px+=4;wSRCPtr+=4;\r
2864 }\r
2865 while (row);\r
2866\r
2867 x2a=x2?(x2-1):0;//if(x2) x2a=x2-1; else x2a=0;\r
2868 sxm=x1&1;sxh=x1>>1;\r
2869 j=sxm?(x1+1):x1;//if(sxm) j=x1+1; else j=x1;\r
2870\r
2871 for(column=y1;column<=y2;column++)\r
2872 {\r
2873 cSRCPtr = psxVub + start + (column<<11) + sxh;\r
2874 \r
2875 if(sxm) *ta++=*(pa+((*cSRCPtr++ >> 4) & 0xF));\r
2876 \r
2877 for(row=j;row<x2a;row+=2)\r
2878 {\r
2879 *ta =*(pa+(*cSRCPtr & 0xF));\r
2880 *(ta+1)=*(pa+((*cSRCPtr >> 4) & 0xF)); \r
2881 cSRCPtr++;ta+=2;\r
2882 }\r
2883\r
2884 if(row<=x2)\r
2885 {\r
2886 *ta++=*(pa+(*cSRCPtr & 0xF));row++;\r
2887 if(row<=x2) *ta++=*(pa+((*cSRCPtr >> 4) & 0xF));\r
2888 }\r
2889\r
2890 ta+=xalign;\r
2891 }\r
2892 break;\r
2893 //--------------------------------------------------// \r
2894 // 8bit texture load ..\r
2895 case 1:\r
2896 if(GlobalTextIL)\r
2897 {\r
2898 unsigned int TXV,TXU,n_xi,n_yi;\r
2899\r
2900 wSRCPtr=psxVuw+palstart;\r
2901\r
2902 row=64;do\r
2903 {\r
2904 *px =LPTCOL(*wSRCPtr);\r
2905 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2906 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2907 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2908 row--;px+=4;wSRCPtr+=4;\r
2909 }\r
2910 while (row);\r
2911\r
2912 for(TXV=y1;TXV<=y2;TXV++)\r
2913 {\r
2914 for(TXU=x1;TXU<=x2;TXU++)\r
2915 {\r
2916 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );\r
2917 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );\r
2918\r
2919 *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));\r
2920 }\r
2921 ta+=xalign;\r
2922 }\r
2923\r
2924 break;\r
2925 }\r
2926\r
2927 start=((pageid-16*pmult)<<7)+524288*pmult;\r
2928\r
2929 cSRCPtr = psxVub + start + (y1<<11) + x1;\r
2930 LineOffset = 2048 - dx;\r
2931\r
2932 if(dy*dx>384) // more pix? use lut\r
2933 {\r
2934 wSRCPtr=psxVuw+palstart;\r
2935\r
2936 row=64;do\r
2937 {\r
2938 *px =LPTCOL(*wSRCPtr);\r
2939 *(px+1)=LPTCOL(*(wSRCPtr+1));\r
2940 *(px+2)=LPTCOL(*(wSRCPtr+2));\r
2941 *(px+3)=LPTCOL(*(wSRCPtr+3));\r
2942 row--;px+=4;wSRCPtr+=4;\r
2943 }\r
2944 while (row);\r
2945\r
2946 column=dy;do \r
2947 {\r
2948 row=dx;\r
2949 do {*ta++=*(pa+(*cSRCPtr++));row--;} while(row);\r
2950\r
2951 ta+=xalign;\r
2952\r
2953 cSRCPtr+=LineOffset;column--;\r
2954 }\r
2955 while(column);\r
2956 }\r
2957 else // small area? no lut\r
2958 { \r
2959 wSRCPtr=psxVuw+palstart;\r
2960\r
2961 column=dy;do \r
2962 {\r
2963 row=dx;\r
2964 do {*ta++=LPTCOL(*(wSRCPtr+*cSRCPtr++));row--;} while(row);\r
2965\r
2966 ta+=xalign;\r
2967\r
2968 cSRCPtr+=LineOffset;column--;\r
2969 }\r
2970 while(column);\r
2971 }\r
2972 break;\r
2973 //--------------------------------------------------// \r
2974 // 16bit texture load ..\r
2975 case 2:\r
2976 start=((pageid-16*pmult)<<6)+262144*pmult;\r
2977\r
2978 wSRCPtr = psxVuw + start + (y1<<10) + x1;\r
2979 LineOffset = 1024 - dx; \r
2980\r
2981 column=dy;do \r
2982 {\r
2983 row=dx;\r
2984 do {*ta++=LPTCOL(*wSRCPtr++);row--;} while(row);\r
2985\r
2986 ta+=xalign;\r
2987\r
2988 wSRCPtr+=LineOffset;column--;\r
2989 }\r
2990 while(column);\r
2991 break;\r
2992 //--------------------------------------------------// \r
2993 // others are not possible !\r
2994 }\r
2995\r
2996 ////////////////////////////////////////////////////////\r
2997\r
2998 x2a=dx+xalign;\r
2999\r
3000 if(YTexS)\r
3001 {\r
3002 ta=(unsigned short *)texturepart;\r
3003 pa=(unsigned short *)texturepart+x2a;\r
3004 row=x2a;do {*ta++=*pa++;row--;} while(row);\r
3005\r
3006 pa=(unsigned short *)texturepart+dy*x2a;\r
3007 ta=pa+x2a;\r
3008 row=x2a;do {*ta++=*pa++;row--;} while(row);\r
3009\r
3010 YTexS--;\r
3011 dy+=2;\r
3012 }\r
3013\r
3014 if(XTexS)\r
3015 {\r
3016 ta=(unsigned short *)texturepart;\r
3017 pa=ta+1;\r
3018 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
3019\r
3020 pa=(unsigned short *)texturepart+dx;\r
3021 ta=pa+1;\r
3022 row=dy;do {*ta=*pa;ta+=x2a;pa+=x2a;row--;} while(row);\r
3023\r
3024 XTexS--;\r
3025 dx+=2;\r
3026 }\r
3027\r
3028 DXTexS=dx;DYTexS=dy;\r
3029\r
3030 if(!iFilterType) {DefineSubTextureSort();return;}\r
3031 if(iFilterType!=2 && iFilterType!=4 && iFilterType!=6) {DefineSubTextureSort();return;}\r
3032 if((iFilterType==4 || iFilterType==6) && ly0==ly1 && ly2==ly3 && lx0==lx3 && lx1==lx2)\r
3033 {DefineSubTextureSort();return;}\r
3034\r
3035 ta=(unsigned short *)texturepart;\r
3036 x1=dx-1;\r
3037 y1=dy-1; \r
3038\r
3039{\r
3040 for(column=0;column<dy;column++)\r
3041 {\r
3042 for(row=0;row<dx;row++)\r
3043 {\r
3044 if(*ta==0)\r
3045 {\r
3046 cnt=0;\r
3047\r
3048 if( column && *(ta-dx) &1) scol[cnt++]=*(ta-dx);\r
3049 if(row && *(ta-1) &1) scol[cnt++]=*(ta-1);\r
3050 if(row!=x1 && *(ta+1) &1) scol[cnt++]=*(ta+1);\r
3051 if( column!=y1 && *(ta+dx) &1) scol[cnt++]=*(ta+dx);\r
3052\r
3053 if(row && column && *(ta-dx-1)&1) scol[cnt++]=*(ta-dx-1);\r
3054 if(row!=x1 && column && *(ta-dx+1)&1) scol[cnt++]=*(ta-dx+1);\r
3055 if(row && column!=y1 && *(ta+dx-1)&1) scol[cnt++]=*(ta+dx-1);\r
3056 if(row!=x1 && column!=y1 && *(ta+dx+1)&1) scol[cnt++]=*(ta+dx+1);\r
3057\r
3058 if(cnt)\r
3059 {\r
3060 r=g=b=0;\r
3061 for(h=0;h<cnt;h++)\r
3062 {\r
3063 r+=scol[h]>>11;\r
3064 g+=(scol[h]>>6)&0x1f;\r
3065 b+=(scol[h]>>1)&0x1f;\r
3066 }\r
3067 r/=cnt;b/=cnt;g/=cnt;\r
3068 *ta=(r<<11)|(g<<6)|(b<<1);\r
3069 }\r
3070 }\r
3071 ta++;\r
3072 }\r
3073 }\r
3074 }\r
3075\r
3076 DefineSubTextureSort();\r
3077}\r
3078\r
3079/////////////////////////////////////////////////////////////////////////////\r
3080\r
3081/////////////////////////////////////////////////////////////////////////////\r
3082/////////////////////////////////////////////////////////////////////////////\r
3083/////////////////////////////////////////////////////////////////////////////\r
3084//\r
3085// hires texture funcs\r
3086//\r
3087/////////////////////////////////////////////////////////////////////////////\r
3088/////////////////////////////////////////////////////////////////////////////\r
3089/////////////////////////////////////////////////////////////////////////////\r
3090\r
3091\r
3092#define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))\r
3093\r
3094////////////////////////////////////////////////////////////////////////\r
3095\r
3096#define colorMask8 0x00FEFEFE\r
3097#define lowPixelMask8 0x00010101\r
3098#define qcolorMask8 0x00FCFCFC\r
3099#define qlowpixelMask8 0x00030303\r
3100\r
3101\r
3102#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
3103\r
3104#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
3105\r
3106#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
3107\r
3108#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
3109\r
677ea103 3110void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,\r
3111 unsigned char *dstBitmap, int width, int height)\r
ce879073 3112{\r
3113 DWORD dstPitch = srcPitch * 2;\r
3114 DWORD line;\r
3115 DWORD *dP;\r
3116 DWORD *bP;\r
3117 int width2 = width*2;\r
3118 int iXA,iXB,iXC,iYA,iYB,iYC,finish;\r
3119 DWORD color4, color5, color6;\r
3120 DWORD color1, color2, color3;\r
3121 DWORD colorA0, colorA1, colorA2, colorA3,\r
3122 colorB0, colorB1, colorB2, colorB3,\r
3123 colorS1, colorS2;\r
3124 DWORD product1a, product1b,\r
3125 product2a, product2b;\r
3126\r
3127 line = 0;\r
3128\r
3129 {\r
3130 for (; height; height-=1)\r
3131 {\r
3132 bP = (DWORD *)srcPtr;\r
3133 dP = (DWORD *)(dstBitmap + line*dstPitch);\r
3134 for (finish = width; finish; finish -= 1 )\r
3135 {\r
3136//--------------------------------------- B1 B2\r
3137// 4 5 6 S2\r
3138// 1 2 3 S1\r
3139// A1 A2\r
3140 if(finish==width) iXA=0;\r
3141 else iXA=1;\r
3142 if(finish>4) {iXB=1;iXC=2;}\r
3143 else\r
3144 if(finish>3) {iXB=1;iXC=1;}\r
3145 else {iXB=0;iXC=0;}\r
3146 if(line==0) iYA=0;\r
3147 else iYA=width;\r
3148 if(height>4) {iYB=width;iYC=width2;}\r
3149 else\r
3150 if(height>3) {iYB=width;iYC=width;}\r
3151 else {iYB=0;iYC=0;}\r
3152\r
3153\r
3154 colorB0 = *(bP- iYA - iXA);\r
3155 colorB1 = *(bP- iYA);\r
3156 colorB2 = *(bP- iYA + iXB);\r
3157 colorB3 = *(bP- iYA + iXC);\r
3158\r
3159 color4 = *(bP - iXA);\r
3160 color5 = *(bP);\r
3161 color6 = *(bP + iXB);\r
3162 colorS2 = *(bP + iXC);\r
3163\r
3164 color1 = *(bP + iYB - iXA);\r
3165 color2 = *(bP + iYB);\r
3166 color3 = *(bP + iYB + iXB);\r
3167 colorS1= *(bP + iYB + iXC);\r
3168\r
3169 colorA0 = *(bP + iYC - iXA);\r
3170 colorA1 = *(bP + iYC);\r
3171 colorA2 = *(bP + iYC + iXB);\r
3172 colorA3 = *(bP + iYC + iXC);\r
3173\r
3174//--------------------------------------\r
3175 if (color2 == color6 && color5 != color3)\r
3176 {\r
3177 product2b = product1b = color2;\r
3178 }\r
3179 else\r
3180 if (color5 == color3 && color2 != color6)\r
3181 {\r
3182 product2b = product1b = color5;\r
3183 }\r
3184 else\r
3185 if (color5 == color3 && color2 == color6)\r
3186 {\r
3187 register int r = 0;\r
3188\r
3189 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color1&0x00ffffff), (colorA1&0x00ffffff));\r
3190 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (color4&0x00ffffff), (colorB1&0x00ffffff));\r
3191 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorA2&0x00ffffff), (colorS1&0x00ffffff));\r
3192 r += GET_RESULT ((color6&0x00ffffff), (color5&0x00ffffff), (colorB2&0x00ffffff), (colorS2&0x00ffffff));\r
3193\r
3194 if (r > 0)\r
3195 product2b = product1b = color6;\r
3196 else\r
3197 if (r < 0)\r
3198 product2b = product1b = color5;\r
3199 else\r
3200 {\r
3201 product2b = product1b = INTERPOLATE8_02(color5, color6);\r
3202 }\r
3203 }\r
3204 else\r
3205 {\r
3206 if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)\r
3207 product2b = Q_INTERPOLATE8_02 (color3, color3, color3, color2);\r
3208 else\r
3209 if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)\r
3210 product2b = Q_INTERPOLATE8_02 (color2, color2, color2, color3);\r
3211 else\r
3212 product2b = INTERPOLATE8_02 (color2, color3);\r
3213\r
3214 if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)\r
3215 product1b = Q_INTERPOLATE8_02 (color6, color6, color6, color5);\r
3216 else\r
3217 if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)\r
3218 product1b = Q_INTERPOLATE8_02 (color6, color5, color5, color5);\r
3219 else\r
3220 product1b = INTERPOLATE8_02 (color5, color6);\r
3221 }\r
3222\r
3223 if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)\r
3224 product2a = INTERPOLATE8_02(color2, color5);\r
3225 else\r
3226 if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)\r
3227 product2a = INTERPOLATE8_02(color2, color5);\r
3228 else\r
3229 product2a = color2;\r
3230\r
3231 if (color2 == color6 && color5 != color3 && color1 == color2 &am