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