00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <Windows.h>
00023 #include <stdio.h>
00024
00025 #include "D3DDrv.h"
00026 #include "DCommon.h"
00027
00028 #include "Scene.h"
00029 #include "Render.h"
00030 #include "D3DCache.h"
00031 #include "D3D_Main.h"
00032 #include "PCache.h"
00033 #include "THandle.h"
00034
00035
00036
00037
00038
00039
00040
00041
00042 DRV_Window ClientWindow;
00043 BOOL ExitHandlerActive = FALSE;
00044
00045 int32 LastError;
00046 char LastErrorStr[200];
00047
00048 geBoolean DRIVERCC DrvShutdown(void);
00049 geBoolean DRIVERCC ScreenShot(const char *Name);
00050
00051 BOOL DRIVERCC DrvInit(DRV_DriverHook *Hook)
00052 {
00053 RECT WRect;
00054
00055
00056 if (!D3DMain_InitD3D(Hook->hWnd, Hook->DriverName+5, Hook->Width, Hook->Height))
00057 {
00058
00059 return FALSE;
00060 }
00061
00062
00063 if (Hook->Width ==-1 && Hook->Height == -1)
00064 {
00065 GetClientRect(Hook->hWnd, &WRect);
00066
00067 Hook->Width = (WRect.right - WRect.left);
00068 Hook->Height = (WRect.bottom - WRect.top);
00069 }
00070
00071 ClientWindow.Width = Hook->Width;
00072 ClientWindow.Height = Hook->Height;
00073 ClientWindow.hWnd = Hook->hWnd;
00074
00075 return TRUE;
00076 }
00077
00078
00079
00080 BOOL DRIVERCC DrvShutdown(void)
00081 {
00082 D3DMain_ShutdownD3D();
00083
00084 return TRUE;
00085 }
00086
00087
00088
00089
00090 geBoolean DRIVERCC DrvResetAll(void)
00091 {
00092 return D3DMain_Reset();
00093 }
00094
00095 geRDriver_PixelFormat PixelFormat[10];
00096
00097 #define NUM_PIXEL_FORMATS (sizeof(PixelFormats)/sizeof(geRDriver_PixelFormat))
00098
00099 geBoolean DRIVERCC EnumPixelFormats(DRV_ENUM_PFORMAT_CB *Cb, void *Context)
00100 {
00101 int32 i;
00102 gePixelFormat Format3d, Format2d;
00103 uint32 CurrentBpp;
00104
00105 CurrentBpp = AppInfo.ddsd.ddpfPixelFormat.dwRGBBitCount;
00106
00107
00108 if (CurrentBpp == 32 && AppInfo.ddSurfFormat.ddpfPixelFormat.dwRGBAlphaBitMask == 0xff000000)
00109 Format2d = GE_PIXELFORMAT_32BIT_ARGB;
00110 else if (CurrentBpp == 32 && AppInfo.ddSurfFormat.ddpfPixelFormat.dwBBitMask == 0xff)
00111 Format2d = GE_PIXELFORMAT_32BIT_XRGB;
00112 else if (CurrentBpp == 24 && AppInfo.ddSurfFormat.ddpfPixelFormat.dwBBitMask == 0xff)
00113 Format2d = GE_PIXELFORMAT_24BIT_RGB;
00114 else if (AppInfo.ddSurfFormat.ddpfPixelFormat.dwGBitMask == (31<<5))
00115 Format2d = GE_PIXELFORMAT_16BIT_555_RGB;
00116 else
00117 Format2d = GE_PIXELFORMAT_16BIT_565_RGB;
00118
00119
00120 if (AppInfo.ddTexFormat.ddpfPixelFormat.dwGBitMask == (31<<5))
00121 Format3d = GE_PIXELFORMAT_16BIT_555_RGB;
00122 else
00123 Format3d = GE_PIXELFORMAT_16BIT_565_RGB;
00124
00125
00126
00127 PixelFormat[0].PixelFormat = Format3d;
00128 PixelFormat[0].Flags = RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP;
00129
00130 PixelFormat[1].PixelFormat = GE_PIXELFORMAT_16BIT_4444_ARGB;
00131 PixelFormat[1].Flags = RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP;
00132
00133 PixelFormat[2].PixelFormat = Format2d;
00134 PixelFormat[2].Flags = RDRIVER_PF_2D | RDRIVER_PF_CAN_DO_COLORKEY;
00135
00136 PixelFormat[3].PixelFormat = Format3d;
00137 PixelFormat[3].Flags = RDRIVER_PF_LIGHTMAP;
00138
00139 PixelFormat[4].PixelFormat = GE_PIXELFORMAT_16BIT_1555_ARGB;
00140 PixelFormat[4].Flags = RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP;
00141
00142
00143 for (i=0; i<5; i++)
00144 {
00145 if (!Cb(&PixelFormat[i], Context))
00146 return GE_TRUE;
00147 }
00148
00149 return TRUE;
00150 }
00151
00152 geBoolean DRIVERCC SetGamma(float Gamma)
00153 {
00154 return GE_TRUE;
00155 }
00156
00157 geBoolean DRIVERCC GetGamma(float *Gamma)
00158 {
00159 *Gamma = 1.0f;
00160
00161 return GE_TRUE;
00162 }
00163
00164 BOOL DRIVERCC EnumSubDrivers2(DRV_ENUM_DRV_CB *Cb, void *Context);
00165 BOOL DRIVERCC EnumModes2(int32 Driver, char *DriverName, DRV_ENUM_MODES_CB *Cb, void *Context);
00166
00167 DRV_Driver D3DDRV =
00168 {
00169 "D3D driver. v"DRV_VMAJS"."DRV_VMINS". Copyright 1999, WildTangent Inc.; All Rights Reserved.",
00170 DRV_VERSION_MAJOR,
00171 DRV_VERSION_MINOR,
00172
00173 DRV_ERROR_NONE,
00174 NULL,
00175
00176 EnumSubDrivers2,
00177 EnumModes2,
00178
00179 EnumPixelFormats,
00180
00181 DrvInit,
00182 DrvShutdown,
00183 DrvResetAll,
00184 D3DMain_UpdateWindow,
00185 D3DMain_SetActive,
00186
00187 THandle_Create,
00188 THandle_Destroy,
00189
00190 THandle_Lock,
00191 THandle_UnLock,
00192
00193 NULL,
00194 NULL,
00195
00196 NULL,
00197 NULL,
00198
00199 THandle_GetInfo,
00200
00201 BeginScene,
00202 EndScene,
00203 BeginWorld,
00204 EndWorld,
00205 BeginMeshes,
00206 EndMeshes,
00207 BeginModels,
00208 EndModels,
00209
00210 RenderGouraudPoly,
00211 RenderWorldPoly,
00212 RenderMiscTexturePoly,
00213
00214 DrawDecal,
00215
00216 0,0,0,
00217
00218 &CacheInfo,
00219
00220 ScreenShot,
00221
00222 SetGamma,
00223 GetGamma,
00224
00225 D3DMain_SetFogEnable,
00226
00227 NULL,
00228 NULL,
00229 NULL
00230 };
00231
00232 DRV_EngineSettings EngineSettings;
00233
00234 DllExport BOOL DriverHook(DRV_Driver **Driver)
00235 {
00236
00237 EngineSettings.CanSupportFlags = (DRV_SUPPORT_ALPHA | DRV_SUPPORT_COLORKEY);
00238 EngineSettings.PreferenceFlags = 0;
00239
00240 D3DDRV.EngineSettings = &EngineSettings;
00241
00242 *Driver = &D3DDRV;
00243
00244
00245 D3DDRV.LastErrorStr = LastErrorStr;
00246
00247 SetLastDrvError(DRV_ERROR_NONE, "D3DDrv: No error.");
00248
00249 return TRUE;
00250 }
00251
00252 void SetLastDrvError(int32 Error, char *ErrorStr)
00253 {
00254 LastError = Error;
00255
00256 if (ErrorStr)
00257 {
00258 strcpy(LastErrorStr, ErrorStr);
00259 }
00260 else
00261 LastErrorStr[0] = NULL;
00262
00263 D3DDRV.LastErrorStr = LastErrorStr;
00264 D3DDRV.LastError = LastError;
00265 }
00266
00267
00268
00269
00270
00271
00272 BOOL GENESISCC ScreenShot(const char *Name)
00273 {
00274 DDSURFACEDESC2 ddsd;
00275 BITMAPFILEHEADER bfh;
00276 BITMAPINFOHEADER bih;
00277 HRESULT result;
00278 HDC surfDC = NULL;
00279 HDC memDC = NULL;
00280 HBITMAP bitmap = NULL;
00281 HGDIOBJ oldbit = NULL;
00282 FILE *file = NULL;
00283 void *data= NULL;
00284 int width, height, bpp;
00285 int datasize;
00286 BOOL success = FALSE;
00287
00288 memset(&ddsd,0,sizeof(ddsd));
00289 ddsd.dwSize = sizeof(ddsd);
00290 result = AppInfo.lpBackBuffer->GetSurfaceDesc(&ddsd);
00291
00292 if (FAILED(result))
00293 goto cleanup;
00294
00295 width = ddsd.dwWidth;
00296 height= ddsd.dwHeight;
00297 bpp = ddsd.ddpfPixelFormat.dwRGBBitCount / 8;
00298
00299 if (bpp < 2)
00300 bpp = 2;
00301
00302 if (bpp > 3)
00303 bpp = 3;
00304
00305 datasize = width * bpp * height;
00306
00307 if (width * bpp % 4)
00308 datasize += height * (4 - width * bpp % 4);
00309
00310 memset((void*)&bfh, 0, sizeof(bfh));
00311
00312 bfh.bfType = 'B'+('M'<<8);
00313 bfh.bfSize = sizeof(bfh) + sizeof(bih) + datasize;
00314 bfh.bfOffBits = sizeof(bfh) + sizeof(bih);
00315
00316 memset((void*)&bih, 0, sizeof(bih));
00317
00318 bih.biSize = sizeof(bih);
00319 bih.biWidth = ddsd.dwWidth;
00320 bih.biHeight = ddsd.dwHeight;
00321 bih.biPlanes = 1;
00322 bih.biBitCount = (unsigned short)(bpp * 8);
00323 bih.biCompression = BI_RGB;
00324
00325 result = AppInfo.lpBackBuffer->GetDC(&surfDC);
00326
00327 if (FAILED(result))
00328 goto cleanup;
00329
00330 bitmap = CreateDIBSection(NULL, (BITMAPINFO *)&bih, DIB_RGB_COLORS, &data, NULL, 0);
00331
00332 if (!bitmap)
00333 goto cleanup;
00334
00335 if (!data)
00336 goto cleanup;
00337
00338 memDC = CreateCompatibleDC(surfDC);
00339
00340 if (!memDC)
00341 goto cleanup;
00342
00343 oldbit = SelectObject(memDC, bitmap);
00344
00345 if (!oldbit || FAILED(oldbit))
00346 goto cleanup;
00347
00348 result = BitBlt(memDC, 0, 0, width, height, surfDC, 0, 0, SRCCOPY);
00349
00350 if (!result)
00351 goto cleanup;
00352
00353 AppInfo.lpBackBuffer->ReleaseDC(surfDC);
00354 surfDC = NULL;
00355 file = fopen(Name, "wb");
00356
00357 if (!file)
00358 goto cleanup;
00359
00360 fwrite((void*)&bfh, sizeof(bfh), 1, file);
00361 fwrite((void*)&bih, sizeof(bih), 1, file);
00362 fwrite((void*)data, 1, datasize, file);
00363
00364 success = TRUE;
00365
00366 cleanup:
00367
00368 if (oldbit && !FAILED(oldbit))
00369 SelectObject(memDC, oldbit);
00370
00371 if (memDC)
00372 DeleteDC(memDC);
00373
00374 if (surfDC)
00375 AppInfo.lpBackBuffer->ReleaseDC(surfDC);
00376
00377 if (bitmap)
00378 DeleteObject(bitmap);
00379
00380 if (file)
00381 fclose(file);
00382
00383 return success;
00384 }
00385
00386