Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

Render.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  Render.c                                                                            */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description: Code to render polys in glide                                          */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00018 /*Genesis3D Version 1.1 released November 15, 1999                            */
00019 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00020 /*                                                                                      */
00021 /****************************************************************************************/
00022 #include <assert.h>
00023 #include <Math.h>
00024 
00025 #include "Render.h"
00026 #include "GMain.h"
00027 #include "GlideDrv.h"
00028 #include "GSpan.h"
00029 #include "GTHandle.h"
00030 
00031 #define ENABLE_WIREFRAME        
00032 
00033 #ifdef ENABLE_WIREFRAME
00034 static int DoWireFrame = 0;
00035 #endif
00036 
00037 #define MAX_LMAP_SIZE           32
00038 
00039 #define SNAP_VERT(v)  ( ( geFloat )( ( long )( ( v ) * 16 ) ) * 0.0625f /* 1/16 */ )
00040 
00041 #define RENDER_MAX_PNTS (64)
00042 
00043 typedef enum
00044 {
00045         ColorCombine_Undefined,
00046         ColorCombine_Gouraud,
00047         ColorCombine_Texture,
00048         ColorCombine_TextureGouraud,
00049         ColorCombine_TextureGouraudWithFog,
00050 } Render_ColorCombine;
00051 
00052 typedef enum
00053 {
00054         TexCombine_Undefined,
00055         TexCombine_SinglePassGouraud,
00056         TexCombine_SinglePassTexture,
00057         TexCombine_SimultaneousPass,
00058         TexCombine_PassThrough
00059 } Render_TexCombine;
00060 
00061 DRV_RENDER_MODE         RenderMode = RENDER_NONE;
00062 Render_ColorCombine     Render_OldColorCombine = ColorCombine_Undefined;
00063 Render_TexCombine       Render_OldTexCombine = TexCombine_Undefined;
00064 int32                           Render_HardwareMode = RENDER_UNKNOWN_MODE;
00065 uint32                          Render_HardwareFlags = 0;
00066 
00067 uint32                          PolyMode = DRV_POLYMODE_NORMAL;
00068 
00069 DRV_CacheInfo           CacheInfo;
00070 
00071 uint32                          CurrentLRU;
00072 
00073 extern                          g_FogEnable;
00074 
00075 static FxU32 LastTextureAddr[2] = {(FxU32)-1, (FxU32)-1};
00076 
00077 //==========================================================================================
00078 //      TextureSource
00079 //==========================================================================================
00080 void TextureSource(GrChipID_t Tmu, FxU32 startAddress, FxU32 evenOdd, GrTexInfo  *info )
00081 {
00082         if (LastTextureAddr[Tmu] == startAddress)
00083                 return;
00084 
00085         grTexSource(Tmu, startAddress, evenOdd, info);
00086 
00087         LastTextureAddr[Tmu] = startAddress;
00088 }
00089 
00090 //==========================================================================================
00091 //      Render_SetColorCombine
00092 //==========================================================================================
00093 void Render_SetColorCombine(Render_ColorCombine ColorCombine)
00094 {
00095         if (Render_OldColorCombine == ColorCombine)
00096                 return;         // Nothing to change
00097         
00098         switch(ColorCombine)
00099         {
00100                 case ColorCombine_Gouraud:
00101                 {
00102                         guColorCombineFunction( GR_COLORCOMBINE_ITRGB);
00103                         break;
00104                 }
00105                 case ColorCombine_Texture:
00106                 {
00107                         guColorCombineFunction( GR_COLORCOMBINE_DECAL_TEXTURE);
00108                         break;
00109                 }
00110                 case ColorCombine_TextureGouraud:
00111                 {
00112                         guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB);
00113                         break;
00114                 }
00115                 case ColorCombine_TextureGouraudWithFog:
00116                 {
00117                         guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB_ADD_ALPHA);
00118                         break;
00119                 }
00120 
00121                 default:
00122                         assert(0);
00123         }
00124         
00125         Render_OldColorCombine = ColorCombine;
00126 }
00127 
00128 //==========================================================================================
00129 //      Render_SetTexCombine
00130 //==========================================================================================
00131 void Render_SetTexCombine(Render_TexCombine TexCombine)
00132 {
00133         if (Render_OldTexCombine == TexCombine)
00134                 return;         // Nothing to change
00135         
00136         switch(TexCombine)
00137         {
00138                 case TexCombine_SinglePassGouraud:
00139                 {
00140                         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_ONE);
00141                         
00142                         if (g_BoardInfo.NumTMU >= 2)
00143                                 guTexCombineFunction( TMU[1], GR_TEXTURECOMBINE_ZERO);
00144                         break;
00145                 }
00146 
00147                 case TexCombine_SinglePassTexture:
00148                 {
00149                         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_DECAL);
00150                         
00151                         if (g_BoardInfo.NumTMU >= 2)
00152                                 guTexCombineFunction( TMU[1], GR_TEXTURECOMBINE_ZERO);
00153                         break;
00154                 }
00155 
00156                 case TexCombine_SimultaneousPass:
00157                 {
00158                         assert(g_BoardInfo.NumTMU >= 2);
00159 
00160                         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_MULTIPLY);
00161                         guTexCombineFunction( TMU[1], GR_TEXTURECOMBINE_DECAL);
00162                 
00163                         break;
00164                 }
00165         
00166                 case TexCombine_PassThrough:
00167                 {
00168                         assert(g_BoardInfo.NumTMU >= 2);
00169         
00170                         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_OTHER);
00171                         guTexCombineFunction( TMU[1], GR_TEXTURECOMBINE_DECAL);
00172                 
00173                         break;
00174                 }
00175 
00176                 default:
00177                         assert(0);
00178         }
00179 
00180         Render_OldTexCombine = TexCombine;
00181 }
00182 
00183 #if 1
00184 //==========================================================================================
00185 //      Render_SetHardwareMode
00186 //==========================================================================================
00187 void Render_SetHardwareMode(int32 NewMode, uint32 NewFlags)
00188 {
00189         if (NewFlags != Render_HardwareFlags)           // See if the flags gave changed,,,
00190         {
00191                 if (NewFlags & DRV_RENDER_NO_ZMASK)
00192                         grDepthBufferFunction(GR_CMP_ALWAYS);
00193                 else if (Render_HardwareFlags & DRV_RENDER_NO_ZMASK)
00194                         grDepthBufferFunction( GR_CMP_GEQUAL ); 
00195 
00196                 if (NewFlags & DRV_RENDER_NO_ZWRITE)
00197                         grDepthMask(FXFALSE);
00198                 else if (Render_HardwareFlags & DRV_RENDER_NO_ZWRITE)
00199                         grDepthMask(FXTRUE);
00200                 
00201                 if (NewFlags & DRV_RENDER_CLAMP_UV)
00202                         grTexClampMode(TMU[0], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);
00203                 else if (Render_HardwareFlags & DRV_RENDER_CLAMP_UV)
00204                         grTexClampMode(TMU[0], GR_TEXTURECLAMP_WRAP,GR_TEXTURECLAMP_WRAP);
00205         }
00206 
00207         // Make these flags recent
00208         Render_HardwareFlags = NewFlags;
00209 
00210         if (NewMode == Render_HardwareMode)// && NewFlags == Render_HardwareFlags) 
00211                 return;         // Nothing to change
00212 
00213         if (Render_HardwareMode == RENDER_DECAL_MODE)
00214                 grChromakeyMode(GR_CHROMAKEY_DISABLE);          // Restore chroma key mode
00215 
00216         // sets up hardware mode 
00217         switch (NewMode)
00218         {
00219                 case (RENDER_MISC_TEX_POLY_MODE):
00220                 {
00221                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);           // Bug fix thanks to Bobtree
00222 
00223                         Render_SetColorCombine(ColorCombine_TextureGouraud);
00224                         Render_SetTexCombine(TexCombine_SinglePassTexture);
00225 
00226                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA,  GR_BLEND_ONE_MINUS_SRC_ALPHA,
00227                                                                  GR_BLEND_SRC_ALPHA,  GR_BLEND_ONE_MINUS_SRC_ALPHA);
00228 
00229                         if (g_FogEnable)
00230                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA); 
00231                                 grFogMode(GR_FOG_WITH_TABLE); 
00232 
00233                         break;
00234                 }
00235 
00236                 case (RENDER_MISC_GOURAD_POLY_MODE):
00237                 {
00238                         Render_SetColorCombine(ColorCombine_Gouraud);
00239                         Render_SetTexCombine(TexCombine_SinglePassGouraud);
00240 
00241                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00242                                                                  GR_BLEND_ONE, GR_BLEND_ONE);
00243 
00244                         if (g_FogEnable)
00245                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA); 
00246                                 grFogMode(GR_FOG_WITH_TABLE); 
00247 
00248                         break;
00249                 }
00250 
00251                 case (RENDER_LINES_POLY_MODE):
00252                 {       
00253                         Render_SetColorCombine(ColorCombine_Gouraud);
00254                         Render_SetTexCombine(TexCombine_SinglePassGouraud);
00255                         
00256                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00257                                                                  GR_BLEND_ONE, GR_BLEND_ONE);
00258 
00259                         if (g_FogEnable)
00260                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA); 
00261                                 grFogMode(GR_FOG_WITH_TABLE); 
00262 
00263                         break;
00264                 }
00265 
00266                 case (RENDER_WORLD_POLY_MODE_NO_LIGHTMAP):
00267                 {
00268                         Render_SetColorCombine(ColorCombine_TextureGouraud);
00269                         Render_SetTexCombine(TexCombine_SinglePassTexture);
00270                         
00271                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00272 
00273                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO,
00274                                                                  GR_BLEND_ONE, GR_BLEND_ZERO);
00275 
00276                         if (g_FogEnable)
00277                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA); 
00278                                 grFogMode(GR_FOG_WITH_TABLE); 
00279 
00280                         break;
00281                 }
00282 
00283                 case (RENDER_WORLD_POLY_MODE):
00284                 {
00285                         Render_SetColorCombine(ColorCombine_TextureGouraud);
00286                         Render_SetTexCombine(TexCombine_SinglePassTexture);
00287                         
00288                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00289 
00290                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO,
00291                                                                  GR_BLEND_ONE, GR_BLEND_ZERO);
00292 
00293                         if (g_FogEnable)
00294                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA | GR_FOG_ADD2); 
00295                                 grFogMode(GR_FOG_WITH_TABLE | GR_FOG_ADD2); 
00296 
00297                         break;
00298                 }
00299 
00300                 case (RENDER_WORLD_TRANSPARENT_POLY_MODE):
00301                 {
00302                         Render_SetColorCombine(ColorCombine_TextureGouraud);
00303                         Render_SetTexCombine(TexCombine_SinglePassTexture);
00304 
00305                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);           // Bug fix thanks to Bobtree
00306 
00307                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00308                                                                  GR_BLEND_SRC_COLOR, GR_BLEND_DST_COLOR);
00309 
00310                         if (g_FogEnable)
00311                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA);
00312                                 grFogMode(GR_FOG_WITH_TABLE); 
00313 
00314                         break;
00315                 }
00316 
00317                 // NOTE - IF this card has 2 TMU's, world polys AND lightmap polys will be piped through here
00318                 //      Notice how Simultaneous mode is turned on when 2 TMU's are detected... -JP
00319                 case(RENDER_LIGHTMAP_POLY_MODE):
00320                 {
00321                         grTexMipMapMode( TMU[1], GR_MIPMAP_DISABLE, FXFALSE );
00322 
00323                 
00324                         if (g_BoardInfo.NumTMU >= 2)
00325                         {
00326                                 Render_SetColorCombine(ColorCombine_TextureGouraud);
00327 
00328                                 grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00329                                                                          GR_BLEND_SRC_COLOR, GR_BLEND_DST_COLOR);
00330 
00331                                 if (g_FogEnable)
00332                                         //grFogMode(GR_FOG_WITH_ITERATED_ALPHA);
00333                                         grFogMode(GR_FOG_WITH_TABLE); 
00334 
00335                                 Render_SetTexCombine(TexCombine_SimultaneousPass);
00336                         
00337                                 grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00338                         }
00339                         else
00340                         {
00341                                 Render_SetColorCombine(ColorCombine_TextureGouraud);
00342 
00343                                 // Singlepass mode if there is onle 1 TMU
00344                                 Render_SetTexCombine(TexCombine_SinglePassTexture);
00345                         
00346                                 // Modulate the texture with the framebuffer
00347                                 if (g_FogEnable)
00348                                 {
00349                                         //grFogMode(GR_FOG_WITH_ITERATED_ALPHA | GR_FOG_MULT2);
00350                                         grFogMode(GR_FOG_WITH_TABLE | GR_FOG_MULT2); 
00351 
00352                                         grAlphaBlendFunction(   GR_BLEND_ONE, GR_BLEND_PREFOG_COLOR,
00353                                                                                         GR_BLEND_ONE, GR_BLEND_ZERO);
00354                                 }
00355                                 else
00356                                 {
00357                                         grAlphaBlendFunction(   GR_BLEND_DST_COLOR, GR_BLEND_ZERO,
00358                                                                                         GR_BLEND_ONE, GR_BLEND_ZERO);
00359                                 }
00360 
00361                                 // Force clamping to be on if this card only has one TMU
00362                                 grTexClampMode(TMU[0], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);
00363                                 Render_HardwareFlags |= DRV_RENDER_CLAMP_UV;
00364                         }
00365 
00366                         break;
00367                 }
00368 
00369                 case(RENDER_LIGHTMAP_FOG_POLY_MODE):
00370                 {
00371                         grTexMipMapMode( TMU[1], GR_MIPMAP_DISABLE, FXFALSE );
00372 
00373                         Render_SetColorCombine(ColorCombine_TextureGouraud);
00374 
00375                         if (g_BoardInfo.NumTMU >= 2)
00376                         {
00377                                 Render_SetTexCombine(TexCombine_PassThrough);
00378                                 grTexMipMapMode(TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00379                         }
00380                         else
00381                         {
00382                                 Render_SetTexCombine(TexCombine_SinglePassTexture);
00383                         }
00384 
00385                         if (g_FogEnable)
00386                                 //grFogMode(GR_FOG_WITH_ITERATED_ALPHA); 
00387                                 grFogMode(GR_FOG_DISABLE); 
00388 
00389                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ONE,
00390                                                                  GR_BLEND_ONE, GR_BLEND_ONE);
00391 
00392                         break;
00393                 }
00394 
00395                 case (RENDER_DECAL_MODE):
00396                 {
00397                         grLfbConstantDepth(0xffff);
00398                         grLfbConstantAlpha(0xff);
00399                         grChromakeyMode(GR_CHROMAKEY_ENABLE);
00400                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO,
00401                                                                  GR_BLEND_ONE, GR_BLEND_ZERO);
00402 
00403                         break;
00404                 }
00405 
00406                 default:
00407                 {
00408                         assert(0);
00409                 }
00410         }
00411 
00412         Render_HardwareMode = NewMode;
00413 }
00414 #else
00415 //==========================================================================================
00416 //      Render_SetHardwareMode
00417 //==========================================================================================
00418 void Render_SetHardwareMode(int32 NewMode, uint32 NewFlags)
00419 {
00420         if (NewFlags != Render_HardwareFlags)           // See if the flags gave changed,,,
00421         {
00422                 if (NewFlags & DRV_RENDER_NO_ZMASK)
00423                         grDepthBufferFunction(GR_CMP_ALWAYS);
00424                 else if (Render_HardwareFlags & DRV_RENDER_NO_ZMASK)
00425                         grDepthBufferFunction( GR_CMP_GEQUAL ); 
00426 
00427                 if (NewFlags & DRV_RENDER_NO_ZWRITE)
00428                         grDepthMask(FXFALSE);
00429                 else if (Render_HardwareFlags & DRV_RENDER_NO_ZWRITE)
00430                         grDepthMask(FXTRUE);
00431                 
00432                 if (NewFlags & DRV_RENDER_CLAMP_UV)
00433                         grTexClampMode(TMU[0], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);
00434                 else if (Render_HardwareFlags & DRV_RENDER_CLAMP_UV)
00435                         grTexClampMode(TMU[0], GR_TEXTURECLAMP_WRAP,GR_TEXTURECLAMP_WRAP);
00436         }
00437 
00438         // Make these flags recent
00439         Render_HardwareFlags = NewFlags;
00440 
00441         if (NewMode == Render_HardwareMode)// && NewFlags == Render_HardwareFlags) 
00442                 return;         // Nothing to change
00443 
00444         if (Render_HardwareMode == RENDER_DECAL_MODE)
00445                 grChromakeyMode(GR_CHROMAKEY_DISABLE);          // Restore chroma key mode
00446 
00447         // sets up all hardware mode 
00448         switch (NewMode)
00449         {
00450                 case (RENDER_MISC_TEX_POLY_MODE):
00451                 {
00452                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);           //Bug fix thanks to Bobtree
00453 
00454                         guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB);
00455 
00456                         if (g_BoardInfo.NumTMU >= 2)
00457                         {
00458                                 grTexCombine( TMU[0],
00459                                                           GR_COMBINE_FUNCTION_LOCAL,
00460                                                           GR_COMBINE_FACTOR_NONE,
00461                                                           GR_COMBINE_FUNCTION_LOCAL,
00462                                                           GR_COMBINE_FACTOR_NONE,
00463                                                           FXFALSE, FXFALSE );
00464                                 grTexCombine(   TMU[1], 
00465                                                                 GR_COMBINE_FUNCTION_NONE, 
00466                                                                 GR_COMBINE_FACTOR_NONE,
00467                                                                 GR_COMBINE_FUNCTION_NONE, 
00468                                                                 GR_COMBINE_FACTOR_NONE,
00469                                                                 FXFALSE, FXFALSE );
00470                         }
00471                         else
00472                         {
00473                                 grTexCombine( TMU[0],
00474                                                           GR_COMBINE_FUNCTION_LOCAL,
00475                                                           GR_COMBINE_FACTOR_NONE,
00476                                                           GR_COMBINE_FUNCTION_LOCAL,
00477                                                           GR_COMBINE_FACTOR_NONE,
00478                                                           FXFALSE, FXFALSE );
00479                         }
00480 
00481                         //grChromakeyMode(GR_CHROMAKEY_ENABLE);                 
00482 
00483                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA,  GR_BLEND_ONE_MINUS_SRC_ALPHA,
00484                                                                  GR_BLEND_SRC_ALPHA,  GR_BLEND_ONE_MINUS_SRC_ALPHA);
00485 
00486                         if (Render_HardwareMode == RENDER_MISC_GOURAD_POLY_MODE)
00487                         {
00488                                 grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
00489                                         GR_COMBINE_FACTOR_LOCAL,
00490                                         GR_COMBINE_LOCAL_ITERATED,
00491                                         GR_COMBINE_OTHER_TEXTURE,
00492                                         FXFALSE );
00493                         }
00494                         
00495                         break;
00496                 }
00497                 case (RENDER_MISC_GOURAD_POLY_MODE):
00498                 {
00499                         guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB);
00500                         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_ONE );
00501                         
00502                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00503                                                                  GR_BLEND_ONE, GR_BLEND_ONE);
00504 
00505                         //grChromakeyMode(GR_CHROMAKEY_DISABLE);
00506 
00507                         break;
00508                 }
00509 
00510                 case (RENDER_LINES_POLY_MODE):
00511                 {       
00512                         guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB);
00513                         guTexCombineFunction( TMU[0], GR_TEXTURECOMBINE_ONE );
00514                         
00515                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00516                                                                  GR_BLEND_ONE, GR_BLEND_ONE);
00517 
00518                         //grChromakeyMode(GR_CHROMAKEY_DISABLE);
00519                         break;
00520                 }
00521 
00522                 case (RENDER_WORLD_POLY_MODE_NO_LIGHTMAP):
00523                 case (RENDER_WORLD_POLY_MODE):
00524                 {
00525                         grTexCombine( TMU[0],
00526                                                   GR_COMBINE_FUNCTION_LOCAL,
00527                                                   GR_COMBINE_FACTOR_NONE,
00528                                                   GR_COMBINE_FUNCTION_LOCAL,
00529                                                   GR_COMBINE_FACTOR_NONE,
00530                                                   FXFALSE, FXFALSE );
00531 
00532                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00533 
00534                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO,
00535                                                                  GR_BLEND_ONE, GR_BLEND_ZERO);
00536 
00537                         if (Render_HardwareMode == RENDER_MISC_GOURAD_POLY_MODE)
00538                         {
00539                                 grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
00540                                         GR_COMBINE_FACTOR_LOCAL,
00541                                         GR_COMBINE_LOCAL_ITERATED,
00542                                         GR_COMBINE_OTHER_TEXTURE,
00543                                         FXFALSE );
00544                         }
00545                 
00546                         break;
00547                 }
00548 
00549                 case (RENDER_WORLD_TRANSPARENT_POLY_MODE):
00550                 {
00551                         //grChromakeyMode(GR_CHROMAKEY_ENABLE);                 
00552 
00553                         if (g_BoardInfo.NumTMU >= 2)
00554                         {
00555                                 grTexCombine( TMU[0],
00556                                                           GR_COMBINE_FUNCTION_LOCAL,
00557                                                           GR_COMBINE_FACTOR_NONE,
00558                                                           GR_COMBINE_FUNCTION_LOCAL,
00559                                                           GR_COMBINE_FACTOR_NONE,
00560                                                           FXFALSE, FXFALSE );
00561 
00562                                 grTexCombine(   TMU[1], 
00563                                                                 GR_COMBINE_FUNCTION_NONE, 
00564                                                                 GR_COMBINE_FACTOR_NONE,
00565                                                                 GR_COMBINE_FUNCTION_NONE, 
00566                                                                 GR_COMBINE_FACTOR_NONE,
00567                                                                 FXFALSE, FXFALSE ); 
00568                         }
00569                         else
00570                         {
00571                                 grTexCombine( TMU[0],
00572                                                           GR_COMBINE_FUNCTION_LOCAL,
00573                                                           GR_COMBINE_FACTOR_NONE,
00574                                                           GR_COMBINE_FUNCTION_LOCAL,
00575                                                           GR_COMBINE_FACTOR_NONE,
00576                                                           FXFALSE, FXFALSE );
00577                                 
00578                         }
00579 
00580                         grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);           //Bug fix thanks to Bobtree
00581 
00582                         grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00583                                                                  GR_BLEND_SRC_COLOR, GR_BLEND_DST_COLOR);
00584 
00585                         if (Render_HardwareMode == RENDER_MISC_GOURAD_POLY_MODE)
00586                         {
00587                                 grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
00588                                         GR_COMBINE_FACTOR_LOCAL,
00589                                         GR_COMBINE_LOCAL_ITERATED,
00590                                         GR_COMBINE_OTHER_TEXTURE,
00591                                         FXFALSE );
00592                         }
00593                 
00594                         break;
00595                 }
00596 
00597                 case(RENDER_LIGHTMAP_POLY_MODE):
00598                 {
00599                         grTexMipMapMode( TMU[1], GR_MIPMAP_DISABLE, FXFALSE );
00600 
00601                         //grChromakeyMode(GR_CHROMAKEY_DISABLE);
00602 
00603                         if (g_BoardInfo.NumTMU >= 2)
00604                         {
00605                                 grTexCombine(TMU[0], 
00606                                                          GR_COMBINE_FUNCTION_SCALE_OTHER, 
00607                                                          GR_COMBINE_FACTOR_LOCAL,
00608                                                          GR_COMBINE_FUNCTION_SCALE_OTHER, 
00609                                                          GR_COMBINE_FACTOR_LOCAL,
00610                                                          FXFALSE, FXFALSE ); 
00611                         
00612                                 // The lightmap textures (TMU[1]) will be blended locally
00613                                 grTexCombine( TMU[1],
00614                                                           GR_COMBINE_FUNCTION_LOCAL,
00615                                                           GR_COMBINE_FACTOR_NONE,
00616                                                           GR_COMBINE_FUNCTION_LOCAL,
00617                                                           GR_COMBINE_FACTOR_NONE,
00618                                                           FXFALSE, FXFALSE );
00619                         
00620                                 grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA,
00621                                                                          GR_BLEND_SRC_COLOR, GR_BLEND_DST_COLOR);
00622                         
00623                                 grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00624                         }
00625                         else
00626                         {
00627                                 grAlphaBlendFunction(GR_BLEND_SRC_COLOR, GR_BLEND_DST_COLOR,
00628                                                                          GR_BLEND_SRC_COLOR, GR_BLEND_DST_COLOR);
00629                                 
00630                                 // Force clamping to be on TMU0 if this is a 1 TMU board
00631                                 grTexClampMode(TMU[0], GR_TEXTURECLAMP_CLAMP,GR_TEXTURECLAMP_CLAMP);
00632                                 Render_HardwareFlags |= DRV_RENDER_CLAMP_UV;
00633                         }
00634 
00635                         if (Render_HardwareMode == RENDER_MISC_GOURAD_POLY_MODE)
00636                         {
00637                                 grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
00638                                         GR_COMBINE_FACTOR_LOCAL,
00639                                         GR_COMBINE_LOCAL_ITERATED,
00640                                         GR_COMBINE_OTHER_TEXTURE,
00641                                         FXFALSE );
00642                         }
00643                         
00644                         break;
00645                 }
00646 
00647                 case(RENDER_LIGHTMAP_FOG_POLY_MODE):
00648                 {
00649                         grTexMipMapMode( TMU[1], GR_MIPMAP_DISABLE, FXFALSE );
00650 
00651                         //grChromakeyMode(GR_CHROMAKEY_DISABLE);
00652 
00653                         if (g_BoardInfo.NumTMU >= 2)
00654                         {
00655                         
00656                                 grTexCombine(TMU[0], 
00657                                                          GR_COMBINE_FUNCTION_SCALE_OTHER, 
00658                                                          GR_COMBINE_FACTOR_ONE,
00659                                                          GR_COMBINE_FUNCTION_SCALE_OTHER, 
00660                                                          GR_COMBINE_FACTOR_ONE,
00661                                                          FXFALSE, FXFALSE ); 
00662                         
00663                                 // The lightmap textures (TMU[1]) will be blended locally
00664                                 grTexCombine( TMU[1],
00665                                                           GR_COMBINE_FUNCTION_LOCAL,
00666                                                           GR_COMBINE_FACTOR_ONE,
00667                                                           GR_COMBINE_FUNCTION_LOCAL,
00668                                                           GR_COMBINE_FACTOR_ONE,
00669                                                           FXFALSE, FXFALSE );
00670 
00671                                 grTexMipMapMode( TMU[0], GR_MIPMAP_NEAREST, FXFALSE);
00672                         }
00673 
00674                         if (Render_HardwareMode == RENDER_MISC_GOURAD_POLY_MODE)
00675                         {
00676                                 grColorCombine( GR_COMBINE_FUNCTION_SCALE_OTHER,
00677                                         GR_COMBINE_FACTOR_LOCAL,
00678                                         GR_COMBINE_LOCAL_ITERATED,
00679                                         GR_COMBINE_OTHER_TEXTURE,
00680                                         FXFALSE );
00681                         }
00682 
00683                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ONE,
00684                                                                  GR_BLEND_ONE, GR_BLEND_ONE);
00685 
00686                         break;
00687                 }
00688 
00689                 case (RENDER_DECAL_MODE):
00690                 {
00691                         grLfbConstantDepth(0xffff);
00692                         grLfbConstantAlpha(0xff);
00693                         grChromakeyMode(GR_CHROMAKEY_ENABLE);
00694                         grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO,
00695                                                                  GR_BLEND_ONE, GR_BLEND_ZERO);
00696 
00697                         break;
00698                 }
00699 
00700                 default:
00701                 {
00702                         assert(0);
00703                 }
00704         }
00705 
00706         Render_HardwareMode = NewMode;
00707 }
00708 #endif
00709 
00710 //****************************************************************************
00711 //      Render a regualar gouraud shaded poly
00712 //****************************************************************************
00713 geBoolean DRIVERCC Render_GouraudPoly(DRV_TLVertex *Pnts, int32 NumPoints, uint32 Flags)
00714 {
00715         int32 i;
00716         GrVertex        vrtx[RENDER_MAX_PNTS];
00717         geFloat         Alpha = Pnts->a;
00718 
00719         for (i = 0; i< NumPoints; i++)
00720         {
00721                 geFloat ZRecip;
00722 
00723                 vrtx[i].r = Pnts->r;
00724                 vrtx[i].g = Pnts->g;
00725                 vrtx[i].b = Pnts->b;
00726                 vrtx[i].a = Alpha;
00727                 
00728                 // set the SOW, TOW, and OOW values for a 1 TMU configuration TMU0 
00729                 ZRecip = (1.0f/(Pnts->z));
00730                 vrtx[i].ooz = (65535.0f) * ZRecip;
00731                 vrtx[i].oow = ZRecip;
00732                 vrtx[i].tmuvtx[0].oow = ZRecip;
00733 
00734                 vrtx[i].x = SNAP_VERT(Pnts->x);
00735                 vrtx[i].y = SNAP_VERT(Pnts->y);
00736 
00737                 Pnts++;
00738         }
00739 
00740         Render_SetHardwareMode(RENDER_MISC_GOURAD_POLY_MODE, Flags);
00741 
00742         grDrawPolygonVertexList( NumPoints, vrtx); 
00743 
00744         GLIDEDRV.NumRenderedPolys++;
00745 
00746         return TRUE;
00747 }
00748 
00749 //==========================================================================================
00750 //      Render_LinesPoly
00751 //==========================================================================================
00752 geBoolean DRIVERCC Render_LinesPoly(DRV_TLVertex *Pnts, int32 NumPoints)
00753 {
00754         int32 i;
00755         GrVertex        vrtx[RENDER_MAX_PNTS];
00756 
00757         for (i = 0; i< NumPoints; i++)
00758         {
00759                 geFloat ZRecip;
00760 
00761                 vrtx[i].r = 255.0f;//Pnts->r;
00762                 vrtx[i].g = 255.0f;//Pnts->g;
00763                 vrtx[i].b = 255.0f;//Pnts->b;
00764                 vrtx[i].a = 255.0f;
00765                 
00766                 // set the SOW, TOW, and OOW values for a 1 TMU configuration TMU0 
00767                 ZRecip = (1/(Pnts->z));
00768                 vrtx[i].ooz = (65535.0f) / Pnts->z;
00769                 vrtx[i].oow = ZRecip;
00770                 vrtx[i].tmuvtx[0].oow = ZRecip;
00771 
00772                 vrtx[i].x = SNAP_VERT(Pnts->x);
00773                 vrtx[i].y = SNAP_VERT(Pnts->y);
00774 
00775                 Pnts++;
00776         }
00777 
00778         Render_SetHardwareMode(RENDER_LINES_POLY_MODE, 0);
00779 
00780         for (i=0; i< NumPoints; i++)
00781         {
00782                 int32 i2 = ((i+1) < NumPoints) ? (i+1) : 0;
00783 
00784                 grDrawLine(&vrtx[i], &vrtx[i2]);
00785         }
00786 
00787         GLIDEDRV.NumRenderedPolys++;
00788 
00789         return TRUE;
00790 }
00791 
00792 //****************************************************************************
00793 //      Render a world texture / lightmap 
00794 //****************************************************************************
00795 geBoolean DRIVERCC Render_WorldPoly(DRV_TLVertex *Pnts, int32 NumPoints, geRDriver_THandle *THandle, DRV_TexInfo *TexInfo, DRV_LInfo *LInfo, uint32 Flags)
00796 {
00797         GrVertex                Vrtx[RENDER_MAX_PNTS], *pVrtx;
00798         geFloat                 OneOverSize_255;
00799         geFloat                 ShiftU, ShiftV, ScaleU, ScaleV;
00800         DRV_TLVertex    *pPnts;
00801         int32                   i;
00802         geFloat                 Alpha;
00803 
00804         assert(Pnts);
00805         assert(TexInfo);
00806 
00807 #ifdef ENABLE_WIREFRAME 
00808         if ( DoWireFrame )
00809                 return (Render_LinesPoly(Pnts, NumPoints));
00810 #endif
00811 
00812 #if 0
00813         switch (PolyMode)
00814         {
00815                 case DRV_POLYMODE_NORMAL:
00816                         break;                                                  // Use this function
00817                 case DRV_POLYMODE_GOURAUD:
00818                         return (Render_GouraudPoly(Pnts, NumPoints, 0));
00819                 case DRV_POLYMODE_LINES:
00820                         return (Render_LinesPoly(Pnts, NumPoints));
00821         }
00822 #endif
00823         
00824         GLIDEDRV.NumRenderedPolys++;
00825 
00826         OneOverSize_255 = THandle->OneOverLogSize_255;
00827 
00828         // Get how much to shift U, and V for the Texture
00829         ShiftU = TexInfo->ShiftU;
00830         ShiftV = TexInfo->ShiftV;
00831         ScaleU = 1.0f/TexInfo->DrawScaleU;
00832         ScaleV = 1.0f/TexInfo->DrawScaleV;
00833 
00834         pPnts = Pnts;
00835 
00836         pVrtx = Vrtx;
00837 
00838 #if 0
00839         // Fix the uv's to be as close to the origin as possible, without affecting their appearance...
00840         //if (pPnts->u > 1000.0f || pPnts->v > 1000.0f)
00841         {
00842                 geFloat         OneOverLogSize;
00843 
00844                 OneOverLogSize = 1.0f / (geFloat)THandle->LogSize;
00845                 
00846                 ShiftU -= (geFloat)(((int32)(pPnts->u*ScaleU/THandle->Width))*THandle->Width);
00847                 ShiftV -= (geFloat)(((int32)(pPnts->v*ScaleV/THandle->Height))*THandle->Height);
00848         }
00849 #endif
00850 
00851         Alpha = Pnts->a;
00852 
00853         for (i = 0; i< NumPoints; i++)
00854         {
00855                 geFloat ZRecip;
00856                 
00857                 pVrtx->a = Alpha;
00858 
00859                 pVrtx->r = pPnts->r;
00860                 pVrtx->g = pPnts->g;
00861                 pVrtx->b = pPnts->b;
00862                 
00863                 ZRecip = (1.0f/(pPnts->z));
00864                 pVrtx->ooz = 65535.0f * ZRecip;
00865                 pVrtx->oow = ZRecip;
00866 
00867                 pVrtx->tmuvtx[0].oow = ZRecip;
00868                 pVrtx->tmuvtx[1].oow = ZRecip;
00869         
00870                 ZRecip *= OneOverSize_255;
00871 
00872                 pVrtx->tmuvtx[TMU[0]].sow = (pPnts->u*ScaleU + ShiftU) * ZRecip;
00873                 pVrtx->tmuvtx[TMU[0]].tow = (pPnts->v*ScaleV + ShiftV) * ZRecip;
00874 
00875                 pVrtx->x = SNAP_VERT(pPnts->x);
00876                 pVrtx->y = SNAP_VERT(pPnts->y);
00877 
00878                 pPnts++;
00879                 pVrtx++;
00880         }
00881         
00882 
00883         // Set the source texture for TMU 0
00884         SetupTexture(THandle);
00885         
00886         // If only 1 TMU (or no lightmap), then draw first pass poly now. 
00887         if (g_BoardInfo.NumTMU == 1 || !LInfo)          
00888         {                                                               // The lightmap will blend over it
00889                 if (Flags & DRV_RENDER_ALPHA)
00890                         Render_SetHardwareMode(RENDER_WORLD_TRANSPARENT_POLY_MODE, Flags);
00891                 else
00892                 {
00893                         if (LInfo)
00894                                 Render_SetHardwareMode(RENDER_WORLD_POLY_MODE, Flags);
00895                         else
00896                                 Render_SetHardwareMode(RENDER_WORLD_POLY_MODE_NO_LIGHTMAP, Flags);
00897                 }
00898 
00899                 grDrawPolygonVertexList( NumPoints, Vrtx); 
00900         }
00901 
00902         if (LInfo)                                      // If there is a lightmap, render it now, on top of the first pass poly
00903         {
00904                 geBoolean  Dynamic;
00905 
00906                 // How much to shift u'vs back into lightmap space
00907                 ShiftU = (geFloat)LInfo->MinU-8.0f;
00908                 ShiftV = (geFloat)LInfo->MinV-8.0f;
00909                 
00910                 pPnts = Pnts;
00911 
00912                 // Call the engine to set this sucker up, because it's visible...
00913                 GLIDEDRV.SetupLightmap(LInfo, &Dynamic);
00914                 
00915                 OneOverSize_255 = LInfo->THandle->OneOverLogSize_255;
00916 
00917                 pVrtx = Vrtx;
00918 
00919                 for (i = 0; i< NumPoints; i++)
00920                 {
00921                         geFloat u = pPnts->u-ShiftU;
00922                         geFloat v = pPnts->v-ShiftV;
00923                         geFloat ZRecip = pVrtx->oow * OneOverSize_255;
00924 
00925                         pVrtx->tmuvtx[TMU[1]].sow = u*ZRecip;
00926                         pVrtx->tmuvtx[TMU[1]].tow = v*ZRecip;
00927                         pPnts++;
00928                         pVrtx++;
00929                 }
00930                 
00931                 RenderLightmapPoly(Vrtx, NumPoints, LInfo, (geBoolean)Dynamic, Flags);
00932         }
00933 
00934         return TRUE;
00935 }
00936 
00937 void RenderLightmapPoly(GrVertex *vrtx, int32 NumPoints, DRV_LInfo *LInfo, geBoolean Dynamic, uint32 Flags)
00938 {
00939         geRDriver_THandle       *THandle;
00940         int32                           l;
00941         GCache_Slot                     *Slot;
00942 
00943         THandle = LInfo->THandle;
00944 
00945         Slot = SetupLMapTexture(THandle, LInfo, Dynamic, 0);
00946         
00947         GCache_SlotSetLRU(Slot, CurrentLRU);
00948         TextureSource(TMU[1], GCache_SlotGetMemAddress(Slot), GR_MIPMAPLEVELMASK_BOTH, GCache_SlotGetInfo(Slot));
00949 
00950         Render_SetHardwareMode(RENDER_LIGHTMAP_POLY_MODE, Flags);
00951 
00952         grDrawPolygonVertexList( NumPoints, vrtx); 
00953 
00954         // Render special maps
00955         for (l=1; l< 2; l++)
00956         {
00957                 if (!LInfo->RGBLight[l])
00958                         continue;
00959                 
00960                 switch(l)
00961                 {
00962                         case LMAP_TYPE_LIGHT:
00963                                 DownloadLightmap(LInfo, THandle->LogSize, Slot, 0);
00964                                 TextureSource(TMU[1], GCache_SlotGetMemAddress(Slot), GR_MIPMAPLEVELMASK_BOTH, GCache_SlotGetInfo(Slot));
00965                                 Render_SetHardwareMode(RENDER_LIGHTMAP_POLY_MODE, Flags);
00966                                 break;
00967 
00968                         case LMAP_TYPE_FOG:
00969                                 DownloadLightmap(LInfo, THandle->LogSize, Slot, l);
00970                                 TextureSource(TMU[1], GCache_SlotGetMemAddress(Slot), GR_MIPMAPLEVELMASK_BOTH, GCache_SlotGetInfo(Slot));
00971                                 Render_SetHardwareMode(RENDER_LIGHTMAP_FOG_POLY_MODE, Flags);
00972                                 break;
00973                 }
00974                 
00975                 grDrawPolygonVertexList( NumPoints, vrtx); 
00976         }
00977 }
00978 
00979 //**********************************************************************************
00980 //      Downloads a lightmap to the card
00981 //**********************************************************************************
00982 void DownloadLightmap(DRV_LInfo *LInfo, int32 Wh, GCache_Slot *Slot, int32 LMapNum)
00983 {
00984         uint16                  TempL[MAX_LMAP_SIZE*MAX_LMAP_SIZE];                     // Temp to hold converted 565 lightmap
00985         int32                   w,h;
00986         uint16                  *pTempP = TempL;
00987         uint8                   r,g,b;
00988         uint8                   *Bits;
00989         int32                   W = LInfo->Width;
00990         int32                   H = LInfo->Height;
00991         GrTexInfo               *Info;
00992 
00993         //memset(TempL, 0, sizeof(uint6)*32*32);
00994         Bits = (uint8*)LInfo->RGBLight[LMapNum];
00995 
00996         for (h = 0; h< H; h++)
00997         {
00998                 for (w = 0; w< W; w++)
00999                 {
01000                         r = *(Bits++);
01001                         g = *(Bits++);
01002                         b = *(Bits++);
01003 
01004                         r >>= 3;
01005                         g >>= 2;
01006                         b >>= 3;
01007 
01008                         *pTempP++ = (uint16)((r<<(11)) + (g << 5) + b);
01009                 }
01010                 pTempP += (Wh - w);
01011         }
01012         
01013         Info = GCache_SlotGetInfo(Slot);
01014         Info->data = TempL;
01015         
01016         GCache_UpdateSlot(LMapCache, Slot, Info);
01017 }
01018 
01019 
01020 //************************************************************************************
01021 //      Render a misc texture poly....
01022 //************************************************************************************
01023 geBoolean DRIVERCC Render_MiscTexturePoly(DRV_TLVertex *Pnts, int32 NumPoints, geRDriver_THandle *THandle, uint32 Flags)
01024 {
01025         int32                           i;
01026         GrVertex                        vrtx[RENDER_MAX_PNTS];
01027         DRV_TLVertex            *pPnt = Pnts;
01028         geFloat                         Alpha, Width_255, Height_255;
01029         
01030 #ifdef ENABLE_WIREFRAME
01031         if ( DoWireFrame )
01032                 return (Render_LinesPoly(Pnts, NumPoints));
01033 #endif
01034 
01035         assert( Pnts != NULL );
01036         assert( NumPoints < RENDER_MAX_PNTS );
01037         assert( THandle != NULL );
01038 
01039         {
01040                 geFloat OneOverLogSize;
01041                 
01042                 OneOverLogSize = THandle->OneOverLogSize_255;
01043 
01044                 Width_255  = (geFloat)THandle->Width  * OneOverLogSize;
01045                 Height_255 = (geFloat)THandle->Height * OneOverLogSize;
01046         }
01047 
01048         Alpha = Pnts->a;
01049 
01050         for (i = 0; i< NumPoints; i++)
01051         {
01052                 geFloat ZRecip;
01053 
01054                 vrtx[i].a = Alpha;
01055                 vrtx[i].r = pPnt->r;
01056                 vrtx[i].g = pPnt->g;
01057                 vrtx[i].b = pPnt->b;
01058                 // set the SOW, TOW, and OOW values for a 1 TMU configuration TMU0 
01059                 ZRecip = (1.0f/(pPnt->z));              // 1/2 frame in this divide.
01060                 vrtx[i].ooz = (65535.0f) * ZRecip; 
01061                 vrtx[i].oow = ZRecip;
01062                 vrtx[i].tmuvtx[0].oow = ZRecip;
01063 
01064                 vrtx[i].tmuvtx[0].sow = pPnt->u * Width_255 * ZRecip;
01065                 vrtx[i].tmuvtx[0].tow = pPnt->v * Height_255 * ZRecip;
01066 
01067                 vrtx[i].x = SNAP_VERT(pPnt->x);
01068                 vrtx[i].y = SNAP_VERT(pPnt->y);
01069 
01070                 pPnt++;
01071         }
01072 
01073         SetupTexture(THandle);
01074 
01075         Render_SetHardwareMode(RENDER_MISC_TEX_POLY_MODE, Flags);
01076 
01077         grDrawPolygonVertexList( NumPoints, vrtx); 
01078         //grAADrawPolygonVertexList( NumPoints, vrtx); 
01079 
01080         //GLIDEDRV.NumRenderedPolys++;
01081 
01082         return TRUE;
01083 }
01084 
01085 geRDriver_THandle               *OldPalHandle;
01086 
01087 //============================================================================================
01088 //      SetupTexture
01089 //============================================================================================
01090 void SetupTexture(geRDriver_THandle *THandle)
01091 {
01092         GTHandle_CheckTextures();
01093 
01094         // Setup the palette
01095         if (THandle->PixelFormat.PixelFormat == GE_PIXELFORMAT_8BIT)
01096         {
01097                 assert(THandle->PalHandle);
01098                 assert(THandle->PalHandle->Data);
01099 
01100                 // CB <> one shared palette in glide; added _UPDATE check
01101                 if ((OldPalHandle != THandle->PalHandle) || (THandle->PalHandle->Flags & THANDLE_UPDATE))
01102                 {
01103                         grTexDownloadTable(TMU[0], GR_TEXTABLE_PALETTE, THandle->PalHandle->Data);
01104                         OldPalHandle = THandle->PalHandle;
01105                         THandle->PalHandle->Flags &= ~THANDLE_UPDATE;
01106                 }
01107         }
01108 
01109         if (!THandle->Slot || GCache_SlotGetUserData(THandle->Slot) != THandle)
01110         {
01111                 THandle->Slot = GCache_TypeFindSlot(THandle->CacheType);
01112                 assert(THandle->Slot);
01113 
01114                 GCache_SlotSetUserData(THandle->Slot, THandle);
01115                 THandle->Flags |= THANDLE_UPDATE;
01116                 
01117                 CacheInfo.TexMisses++;
01118         }
01119         
01120         if (THandle->Flags & THANDLE_UPDATE)
01121         {
01122                 GrTexInfo               *Info;
01123 
01124                 Info = GCache_SlotGetInfo(THandle->Slot);
01125         
01126                 // Set the data to the correct bits
01127                 Info->data = THandle->Data;
01128         
01129                 // We must make sure the textures formats and the caches format match (formats can change on the fly)
01130                 GlideFormatFromGenesisFormat(THandle->PixelFormat.PixelFormat, &Info->format);
01131 
01132                 GCache_UpdateSlot(TextureCache, THandle->Slot, Info);
01133 
01134                 THandle->Flags &= ~THANDLE_UPDATE;
01135         }
01136 
01137         GCache_SlotSetLRU(THandle->Slot, CurrentLRU);
01138         TextureSource(TMU[0], GCache_SlotGetMemAddress(THandle->Slot), GR_MIPMAPLEVELMASK_BOTH, GCache_SlotGetInfo(THandle->Slot));
01139 }
01140 
01141 //============================================================================================
01142 //      SetupLMapTexture
01143 //============================================================================================
01144 GCache_Slot *SetupLMapTexture(geRDriver_THandle *THandle, DRV_LInfo *LInfo, geBoolean Dynamic, int32 LMapNum)
01145 {
01146         GTHandle_CheckTextures();
01147 
01148         if (Dynamic)
01149                 THandle->Flags |= THANDLE_UPDATE;
01150 
01151         if (!THandle->Slot || GCache_SlotGetUserData(THandle->Slot) != THandle)
01152         {
01153                 THandle->Slot = GCache_TypeFindSlot(THandle->CacheType);
01154                 assert(THandle->Slot);
01155 
01156                 GCache_SlotSetUserData(THandle->Slot, THandle);
01157                 THandle->Flags |= THANDLE_UPDATE;
01158 
01159                 CacheInfo.LMapMisses++;
01160         }
01161 
01162         if (THandle->Flags & THANDLE_UPDATE)
01163         {
01164                 DownloadLightmap(LInfo, THandle->LogSize, THandle->Slot, LMapNum);
01165         }
01166         
01167         if (Dynamic)
01168                 THandle->Flags |= THANDLE_UPDATE;
01169         else
01170                 THandle->Flags &= ~THANDLE_UPDATE;
01171 
01172         GCache_SlotSetLRU(THandle->Slot, CurrentLRU);
01173 
01174         return THandle->Slot;
01175 }
01176 
01177 //==================================================================================
01178 //      Render_DrawDecal
01179 //==================================================================================
01180 geBoolean DRIVERCC Render_DrawDecal(geRDriver_THandle *THandle, RECT *SRect, int32 x, int32 y)
01181 {
01182         int32           Width, Height, Stride, OriginalWidth, w, h, Add1, Add2;
01183         uint16          *Data;
01184         GrLfbInfo_t     Info;
01185         uint16          *BackBuffer;
01186         
01187         if (x >= ClientWindow.Width)
01188                 return TRUE;
01189         if (y >= ClientWindow.Height)
01190                 return TRUE;
01191 
01192         Width = THandle->Width;
01193         OriginalWidth = Width;
01194         Height = THandle->Height;
01195         Stride = Width<<1;
01196         Data = (uint16*)THandle->Data;
01197 
01198         if (SRect)
01199         {
01200                 Data += SRect->top*Width + SRect->left;
01201                 Height = SRect->bottom - SRect->top;
01202                 Width = SRect->right - SRect->left;
01203         }
01204 
01205         if (x < 0)
01206         {
01207                 if (x+Width <= 0)
01208                         return TRUE;
01209                 Data += -x;
01210                 Width -= -x;
01211                 x=0;
01212         }
01213 
01214         if (y < 0)
01215         {
01216                 if (y+Height <= 0)
01217                         return TRUE;
01218                 Data += (-y)*OriginalWidth;
01219                 Height -= -y;
01220                 y=0;
01221         }
01222         
01223         if (x + Width >= ClientWindow.Width)
01224                 Width -= (x+Width) - ClientWindow.Width;
01225 
01226         if (y + Height >= ClientWindow.Height)
01227                 Height -=  (y+Height)- ClientWindow.Height;
01228 
01229         /*
01230         if (!grLfbWriteRegion(GR_BUFFER_BACKBUFFER , 
01231                                                 x, y, 
01232                                                 GR_LFB_SRC_FMT_1555, 
01233                                                 Width, Height, Stride, 
01234                                                 (void*)Data))
01235         {
01236                 SetLastDrvError(DRV_ERROR_GENERIC, "GLIDE_BlitDecal:  The GLIDE decal blit operation could not be performed.");
01237                 return FALSE;
01238         }
01239         */
01240 
01241         Info.size = sizeof(Info);
01242 
01243         Render_SetHardwareMode(RENDER_DECAL_MODE, 0);
01244         
01245         if (!grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_565, 0, FXFALSE, &Info))
01246         //if (!grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER, GR_LFBWRITEMODE_1555, 0, FXTRUE, &Info))
01247         {
01248                 SetLastDrvError(DRV_ERROR_GENERIC, "GLIDE_BlitDecal:  Could not lock the back buffer.");
01249                 return FALSE;
01250         }
01251 
01252         BackBuffer = (uint16*)Info.lfbPtr;
01253 
01254         BackBuffer += (y * (Info.strideInBytes>>1)) + x;
01255 
01256         Add1 = OriginalWidth - Width;
01257         Add2 = (Info.strideInBytes>>1) - Width;
01258 
01259         for (h=0; h<Height; h++)
01260         {
01261                 for (w=0; w<Width; w++)
01262                 {
01263                         if (*Data != 1)
01264                                 *BackBuffer = *Data;
01265 
01266                         Data++;
01267                         BackBuffer++;
01268                 }
01269                 Data += Add1;
01270                 BackBuffer += Add2;
01271         }
01272 
01273         if (!grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER))
01274         {
01275                 SetLastDrvError(DRV_ERROR_GENERIC, "GLIDE_BlitDecal:  Could not unlock the back buffer.");
01276                 return GE_FALSE;
01277         }
01278 
01279         return GE_TRUE;
01280 }
01281 
01282 //=====================================================================================
01283 //      Scene managment functions
01284 //=====================================================================================
01285 geBoolean DRIVERCC BeginScene(geBoolean Clear, geBoolean ClearZ, RECT *WorldRect)
01286 {
01287         memset(&CacheInfo, 0, sizeof(DRV_CacheInfo));
01288 
01289 #ifdef ENABLE_WIREFRAME 
01290         {
01291                 uint32 KeyState1, KeyState2;
01292                 
01293                 #pragma message("Glide : WireFrame enabled!")
01294                 KeyState1 = GetAsyncKeyState(VK_CONTROL) & 0x8001;
01295                 KeyState2 = GetAsyncKeyState(VK_F8) & 0x8001;
01296                 if (KeyState1 && KeyState2)
01297                 {
01298                         DoWireFrame ^= 1;
01299                 }
01300         }
01301 
01302         if (DoWireFrame)
01303         {
01304                 Clear = GE_TRUE;
01305                 ClearZ = GE_TRUE;
01306         }
01307 #endif
01308         
01309         if (!GTHandle_CheckTextures())
01310                 return GE_FALSE;
01311 
01312         // FIXME:       Make clear zbuffer and frame buffer seperate
01313         if (Clear)
01314                 grColorMask(FXTRUE, FXFALSE);
01315         else
01316                 grColorMask(FXFALSE, FXFALSE);
01317 
01318         
01319         if (g_FogEnable)
01320                 grBufferClear(((uint32)g_FogB<<16)|((uint32)g_FogG<<8)|(uint32)g_FogR, 0, GR_ZDEPTHVALUE_FARTHEST);
01321         else
01322                 grBufferClear(0, 0, GR_ZDEPTHVALUE_FARTHEST);
01323 
01324         grColorMask(FXTRUE, FXTRUE);
01325 
01326         GLIDEDRV.NumRenderedPolys = 0;
01327         
01328         CurrentLRU++;
01329 
01330         return TRUE;
01331 }
01332 
01333 geBoolean DRIVERCC EndScene(void)
01334 {
01335 
01336 // Mike: force z buffer on
01337         grDepthMask(FXTRUE);
01338         Render_HardwareFlags &= ~DRV_RENDER_NO_ZWRITE;
01339 
01340         grDepthBufferFunction( GR_CMP_GEQUAL ); 
01341         Render_HardwareFlags &= ~DRV_RENDER_NO_ZMASK;
01342 
01343         // swapping the front and back buffer on the next vertical retrace
01344 #if 1
01345         grBufferSwap( 1 );
01346 #else
01347         grBufferSwap( 0 );
01348 #endif
01349 
01350         return TRUE;
01351 }
01352 
01353 geBoolean DRIVERCC BeginWorld(void)
01354 {
01355 
01356         ResetSpans(ClientWindow.Height);
01357         NumWorldPixels = 0;
01358 
01359         GLIDEDRV.NumWorldPixels = 0;
01360         GLIDEDRV.NumWorldSpans = 0;
01361 
01362         RenderMode = RENDER_WORLD;
01363 
01364         return TRUE;
01365 }
01366 
01367 geBoolean DRIVERCC EndWorld(void)
01368 {
01369         
01370         GLIDEDRV.NumWorldPixels = NumWorldPixels;
01371         GLIDEDRV.NumWorldSpans = NumSpans;
01372 
01373         RenderMode = RENDER_NONE;
01374 
01375         return TRUE;
01376 }
01377 
01378 geBoolean DRIVERCC BeginMeshes(void)
01379 {
01380         
01381         RenderMode = RENDER_MESHES;
01382 
01383         return TRUE;
01384 }
01385 
01386 geBoolean DRIVERCC EndMeshes(void)
01387 {
01388         RenderMode = RENDER_NONE;
01389 
01390         return TRUE;
01391 }
01392 
01393 geBoolean DRIVERCC BeginModels(void)
01394 {
01395 
01396         RenderMode = RENDER_MODELS;
01397 
01398         return TRUE;
01399 }
01400 
01401 geBoolean DRIVERCC EndModels(void)
01402 {
01403 
01404         RenderMode = RENDER_NONE;
01405 
01406         return TRUE;
01407 }

Generated on Tue Sep 30 12:36:17 2003 for GTestAndEngine by doxygen 1.3.2