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

Dcommon.h

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  DCommon.h                                                                           */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description: Header file for all driver modules.                                    */
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 #ifndef DCOMMON_H
00023 #define DCOMMON_H
00024 
00025 //#include <Windows.h>  // {} CB commented out windows
00026 // If you include Windows it MUST be before dcommon!
00027 
00028 // FIXME:  What should we do with these?
00029 #include "XForm3d.h"
00030 #include "Vec3d.h"
00031 #include "PixelFormat.h"
00032 #include "geTypes.h"            // This is a no no
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00038 #pragma pack(push)
00039 #pragma pack(8)
00040 
00041 #ifndef WINVER
00042 #ifdef STRICT
00043 typedef struct HWND__ * HWND;
00044 typedef struct HBITMAP__ * HBITMAP;
00045 #else // STRICT
00046 typedef void * HWND;
00047 typedef void * HBITMAP;
00048 #endif // STRICT
00049 
00050 #ifndef VOID
00051 #define VOID void
00052 typedef char CHAR;
00053 typedef short SHORT;
00054 typedef long LONG;
00055 #endif
00056 
00057 #ifndef BASETYPES
00058 #define BASETYPES
00059 typedef unsigned long ULONG;
00060 typedef ULONG *PULONG;
00061 typedef unsigned short USHORT;
00062 typedef USHORT *PUSHORT;
00063 typedef unsigned char UCHAR;
00064 typedef UCHAR *PUCHAR;
00065 typedef char *PSZ;
00066 #endif  /* !BASETYPES */
00067 
00068 typedef unsigned long       DWORD;
00069 typedef int                 geBoolean;
00070 typedef unsigned char       BYTE;
00071 typedef unsigned short      WORD;
00072 typedef geFloat               FLOAT;
00073 
00074 typedef struct tagRECT
00075 {
00076     LONG    left;
00077     LONG    top;
00078     LONG    right;
00079     LONG    bottom;
00080 } RECT;
00081 
00082 #endif // WINVER
00083 
00084 #define DRIVERCC _fastcall
00085 
00086 #ifndef __cplusplus
00087         #define DllImport       __declspec( dllimport )
00088         #define DllExport       __declspec( dllexport )
00089 #else
00090         #define DllImport       extern "C" __declspec( dllimport )
00091         #define DllExport       extern "C" __declspec( dllexport )
00092 #endif
00093 
00094 #define DRV_VERSION_MAJOR               100                     // Genesis 1.0
00095 #define DRV_VERSION_MINOR               3                       // >= 3.0 added fog
00096 #define DRV_VMAJS                               "100"
00097 #define DRV_VMINS                               "3"
00098 
00099 #ifndef US_TYPEDEFS
00100 #define US_TYPEDEFS
00101 
00102         typedef uint8   U8;
00103         typedef uint16  U16;
00104         typedef uint32  U32;
00105         typedef char    C8;
00106         typedef int8    S8;
00107         typedef int16   S16;
00108         typedef int32   S32;
00109 #endif
00110 
00111 //===
00112 typedef struct geRDriver_THandle        geRDriver_THandle;
00113 
00114 // DriverFormat flags
00115 #define RDRIVER_PF_2D_SHIFT                                     (0)                     // Supports being used as a 2d decal surface
00116 #define RDRIVER_PF_3D_SHIFT                                     (1)                     // Supports being used as a 3d poly surface
00117 #define RDRIVER_PF_LIGHTMAP_SHIFT                       (2)                     // Surface is a lightmap surface
00118 #define RDRIVER_PF_PALETTE_SHIFT                        (3)                     // Surface is a palette
00119 #define RDRIVER_PF_ALPHA_SHIFT                          (4)                     // Surface is an alpha map
00120 #define RDRIVER_PF_OPTIONAL_SHIFT                       (16)
00121 #define RDRIVER_PF_HAS_ALPHA_SHIFT                      (RDRIVER_PF_OPTIONAL_SHIFT + 0)         // Surface can take an alpha map
00122 #define RDRIVER_PF_CAN_DO_COLORKEY_SHIFT        (RDRIVER_PF_OPTIONAL_SHIFT + 1)         // Surface supports colorkeying
00123 #define RDRIVER_PF_COMBINE_LIGHTMAP_SHIFT       (RDRIVER_PF_OPTIONAL_SHIFT + 2)                 // Supports being rendered with a lightmap (3d will be set as well)
00124 
00125 #define RDRIVER_PF_2D                                   (1<<RDRIVER_PF_2D_SHIFT)                                
00126 #define RDRIVER_PF_3D                                   (1<<RDRIVER_PF_3D_SHIFT)                                
00127 #define RDRIVER_PF_LIGHTMAP                             (1<<RDRIVER_PF_LIGHTMAP_SHIFT)                  
00128 #define RDRIVER_PF_COMBINE_LIGHTMAP             (1<<RDRIVER_PF_COMBINE_LIGHTMAP_SHIFT)  
00129 #define RDRIVER_PF_PALETTE                              (1<<RDRIVER_PF_PALETTE_SHIFT)                   
00130 #define RDRIVER_PF_ALPHA                                (1<<RDRIVER_PF_ALPHA_SHIFT)                     
00131 #define RDRIVER_PF_CAN_DO_COLORKEY              (1<<RDRIVER_PF_CAN_DO_COLORKEY_SHIFT)
00132 #define RDRIVER_PF_HAS_ALPHA                    (1<<RDRIVER_PF_HAS_ALPHA_SHIFT)         
00133 #define RDRIVER_PF_MAJOR_MASK                   ((1<<RDRIVER_PF_OPTIONAL_SHIFT)-1)
00134 
00135 typedef struct
00136 {
00137         gePixelFormat   PixelFormat;
00138         uint32                  Flags;                          
00139 } geRDriver_PixelFormat;
00140 
00141 #define RDRIVER_THANDLE_HAS_COLORKEY    (1<<0)          // The thandle is using color keying
00142 
00143 typedef struct
00144 {
00145         int32                                   Width;
00146         int32                                   Height;
00147         int32                                   Stride;
00148         uint32                                  ColorKey;
00149         uint32                                  Flags;
00150         geRDriver_PixelFormat   PixelFormat;
00151 
00152 } geRDriver_THandleInfo;
00153 
00154 //===
00155 
00156 typedef struct
00157 {
00158         S32     LMapCount[16][4];                               // LMap size / MipLevel
00159 } DRV_Debug;
00160 
00161 typedef struct
00162 {
00163         int32           CacheFull;
00164         int32           CacheRemoved;
00165         int32           CacheFlushes;
00166         int32           TexMisses;
00167         int32           LMapMisses;
00168 } DRV_CacheInfo;
00169 
00170 typedef struct
00171 {
00172         HWND            hWnd;
00173         
00174         U8                      *Buffer;
00175 
00176         S32                     Width;
00177         S32                     Height;
00178 
00179         S32                     PixelPitch;
00180         S32                     BytesPerPixel;
00181 
00182         S32                     R_shift;
00183         S32                     G_shift;
00184         S32                     B_shift;
00185 
00186         U32                     R_mask;
00187         U32                     G_mask;
00188         U32                     B_mask;
00189 
00190         S32                     R_width;
00191         S32                     G_width;
00192         S32                     B_width;
00193 } DRV_Window;
00194 
00195 typedef struct 
00196 {
00197     U8 r, g, b;                                                         // RGB components for RGB lightmaps
00198 } DRV_RGB;
00199 
00200 //===========================================================================================
00201 // FIXME:  Get palette stuff, and bitmap out of dcommon
00202 #define DRV_PALETTE_ENTRIES     256
00203 typedef DRV_RGB DRV_Palette[DRV_PALETTE_ENTRIES];
00204 
00205 // Bitmap hook into the drivers (engine uses these explicitly as is)
00206 typedef struct
00207 {
00208         char    Name[32];                                               // Duh, name of bitmap...
00209         U32             Flags;                                                  // Flags
00210         S32             Width;                                                  // Width of bitmap
00211         S32             Height;                                                 // Height of bitmap
00212         U8              MipLevels;
00213         U8              *BitPtr[4];                                             // Pointer to location of bits (up to 4 miplevels)
00214         DRV_RGB *Palette;
00215 
00216         // Driver sets these in register functions
00217         //S32           Id;                                                             // Bitmap handle for hardware...
00218         geRDriver_THandle       *THandle;
00219 } DRV_Bitmap;
00220 //===========================================================================================
00221 
00222 #define LMAP_TYPE_LIGHT                 0
00223 #define LMAP_TYPE_FOG                   1
00224 
00225 // Lightmap hook into the drivers (Engine uses these exlicitly as is...)
00226 // Lightmap info
00227 typedef struct
00228 {
00229         S16                                     Width, Height;                          // lightmap width/height / 16 +1
00230     S32                                 MinU, MinV;                                     // Min U,V values
00231     DRV_RGB                             *RGBLight[2];                           // Pointer to RGB light map data
00232 
00233         S32                                     Face;                                           // Face that this map belongs too
00234         geRDriver_THandle       *THandle;
00235 } DRV_LInfo;
00236 
00237 typedef struct
00238 {
00239         geFloat         ShiftU;                                         // How much to shift right before draw
00240         geFloat         ShiftV;
00241 
00242         geFloat         DrawScaleU;                                             // How much to scale right before draw
00243         geFloat         DrawScaleV;
00244 } DRV_TexInfo;
00245     
00246 // Render Flags for ALL render functions
00247 #define DRV_RENDER_ALPHA                (1<<0)  // Render function should expect alpha set in vertices
00248 #define DRV_RENDER_FLUSH                (1<<1)  // Render function should gaurentee that this render happens NOW
00249 #define DRV_RENDER_NO_ZMASK             (1<<2)  // No zbuffering should be performed
00250 #define DRV_RENDER_NO_ZWRITE    (1<<3)  // No z writing will be performed
00251 #define DRV_RENDER_CLAMP_UV             (1<<4)  // Clamp UV in both directions
00252 #define DRV_RENDER_POLY_NO_FOG  (1<<5)  // Don't render this poly with fog 
00253 
00254 //
00255 //  PolyMode flags      (A method to override how polys are drawn for debugging purposes...)
00256 //
00257 // Put these in the poly flags!!!  They are currently not used right now...
00258 #define DRV_POLYMODE_NORMAL             1                       // Draw as is
00259 #define DRV_POLYMODE_GOURAUD    2                       // Gouraud only
00260 #define DRV_POLYMODE_LINES              3                       // Outlines only
00261 
00262 
00263 typedef struct
00264 {
00265         geFloat x,y,z;                                          // geFloat 3d z value
00266         geFloat u,v;                                            // geFloat texture coords
00267         geFloat r,g,b,a;                                        // Color of point, and Alpha
00268 } DRV_TLVertex;
00269 
00270 typedef struct
00271 {
00272         char                            AppName[512];
00273         S32                                     Driver;
00274         char                            DriverName[512];
00275         S32                                     Mode;
00276         char                            ModeName[512];
00277         S32                                     Width;
00278         S32                                     Height;
00279         HWND                            hWnd;
00280 } DRV_DriverHook;
00281 
00282 typedef struct
00283 {
00284         // Texture info
00285         geVec3d         VecU;
00286         geVec3d         VecV;
00287         int32           TexMinsX;
00288         int32           TexMinsY;
00289         int32           TexWidth;
00290         int32           TexHeight;
00291         geFloat         TexShiftX;
00292         geFloat         TexShiftY;
00293 
00294         // Camera info
00295         geXForm3d       CXForm;
00296         geVec3d         CPov;
00297 
00298         geFloat         XCenter;
00299         geFloat         YCenter;
00300 
00301         geFloat         XScale;
00302         geFloat         YScale;
00303         geFloat         XScaleInv;                      // 1 / XScale
00304         geFloat         YScaleInv;                      // 1 / YScale;
00305         geFloat         ZScale;                         // camera z scale
00306 
00307 
00308         geVec3d         PlaneNormal;            // Face normal
00309         geFloat         PlaneDist;
00310         geVec3d         RPlaneNormal;           // Rotated Face normal
00311         geVec3d         Pov;
00312 } GInfo;
00313 
00314 // What the driver can support as far as texture mapping is concerned
00315 #define DRV_SUPPORT_ALPHA                                       (1<<0)          // Driver can do alpha blending
00316 #define DRV_SUPPORT_COLORKEY                            (1<<1)          // Driver can do pixel masking
00317 #define DRV_SUPPORT_GAMMA                                       (1<<2)          // Gamma function works with the driver
00318 
00319 // A hint to the engine as far as what to turn on and off...
00320 #define DRV_PREFERENCE_NO_MIRRORS                       (1<<0)          // Engine should NOT render mirrors
00321 #define DRV_PREFERENCE_SORT_WORLD_FB            (1<<1)          // Sort world Front to Back
00322 #define DRV_PREFERENCE_SORT_WORLD_BF            (1<<2)          // Sort world Back to Front
00323 #define DRV_PREFERENCE_DRAW_WALPHA_IN_BSP       (1<<3)          // Draw world alphas in BSP sort
00324 
00325 typedef struct
00326 {
00327         U32                     CanSupportFlags;
00328         U32                     PreferenceFlags;
00329         U32                     Reserved1;
00330         U32                     Reserved2;
00331 } DRV_EngineSettings;
00332 
00333 // Enumeration defines
00334 typedef geBoolean DRV_ENUM_MODES_CB( S32 Mode, char *ModeName, S32 Width, S32 Height, void *Context);
00335 typedef geBoolean DRV_ENUM_DRV_CB( S32 Driver, char *DriverName, void *Context);
00336 
00337 typedef geBoolean DRIVERCC DRV_ENUM_DRIVER(DRV_ENUM_DRV_CB *Cb, void *Context); 
00338 typedef geBoolean DRIVERCC DRV_ENUM_MODES(S32 Driver, char *DriverName, DRV_ENUM_MODES_CB *Cb, void *Context); 
00339 
00340 typedef geBoolean DRV_ENUM_PFORMAT_CB(geRDriver_PixelFormat *Format, void *Context);
00341 typedef geBoolean DRIVERCC DRV_ENUM_PFORMAT(DRV_ENUM_PFORMAT_CB *Cb, void *Context); 
00342 
00343 // Create/Destroy/Etc Driver functions
00344 typedef geBoolean DRIVERCC DRV_INIT(DRV_DriverHook *Hook);
00345 typedef geBoolean DRIVERCC DRV_SHUTDOWN(void);
00346 typedef geBoolean DRIVERCC DRV_RESET(void);
00347 typedef geBoolean DRIVERCC DRV_UPDATE_WINDOW(void);
00348 typedef geBoolean DRIVERCC DRV_SET_ACTIVE(geBoolean active);
00349 
00350 // Texture surface functions
00351 typedef geRDriver_THandle *DRIVERCC CREATE_TEXTURE(int32 Width, int32 Height, int32 NumMipLevels, const geRDriver_PixelFormat *PixelFormat);
00352 typedef geBoolean DRIVERCC DESTROY_TEXTURE(geRDriver_THandle *THandle);
00353 
00354 typedef geBoolean DRIVERCC LOCK_THANDLE(geRDriver_THandle *THandle, int32 MipLevel, void **Data);
00355 typedef geBoolean DRIVERCC UNLOCK_THANDLE(geRDriver_THandle *THandle, int32 MipLevel);
00356 
00357 typedef geBoolean DRIVERCC SET_PALETTE(geRDriver_THandle *THandle, geRDriver_THandle *PalHandle);
00358 typedef geRDriver_THandle *DRIVERCC GET_PALETTE(geRDriver_THandle *THandle);
00359 
00360 typedef geBoolean DRIVERCC SET_ALPHA(geRDriver_THandle *THandle, geRDriver_THandle *PalHandle);
00361 typedef geRDriver_THandle *DRIVERCC GET_ALPHA(geRDriver_THandle *THandle);
00362 
00363 typedef geBoolean DRIVERCC THANDLE_GET_INFO(geRDriver_THandle *THandle, int32 MipLevel, geRDriver_THandleInfo *Info);
00364 
00365 // Scene management functions
00366 typedef geBoolean DRIVERCC BEGIN_SCENE(geBoolean Clear, geBoolean ClearZ, RECT *WorldRect);
00367 typedef geBoolean DRIVERCC END_SCENE(void);
00368 typedef geBoolean DRIVERCC BEGIN_WORLD(void);
00369 typedef geBoolean DRIVERCC END_WORLD(void);
00370 typedef geBoolean DRIVERCC BEGIN_MESHES(void);
00371 typedef geBoolean DRIVERCC END_MESHES(void);
00372 typedef geBoolean DRIVERCC BEGIN_MODELS(void);
00373 typedef geBoolean DRIVERCC END_MODELS(void);
00374 
00375 // Render functions
00376 typedef geBoolean DRIVERCC RENDER_G_POLY(DRV_TLVertex *Pnts, S32 NumPoints, U32 Flags);
00377 typedef geBoolean DRIVERCC RENDER_W_POLY(DRV_TLVertex *Pnts, S32 NumPoints, geRDriver_THandle *THandle, DRV_TexInfo *TexInfo, DRV_LInfo *LInfo, U32 Flags);
00378 typedef geBoolean DRIVERCC RENDER_MT_POLY(DRV_TLVertex *Pnts, S32 NumPoints, geRDriver_THandle *THandle, U32 Flags);
00379 
00380 typedef geBoolean DRIVERCC DRAW_DECAL(geRDriver_THandle *THandle, RECT *SRect, int32 x, int32 y);
00381 
00382 typedef geBoolean DRIVERCC SCREEN_SHOT(const char *Name);
00383 
00384 typedef geBoolean DRIVERCC SET_GAMMA(geFloat Gamma);
00385 typedef geBoolean DRIVERCC GET_GAMMA(geFloat *Gamma);
00386 typedef geBoolean DRIVERCC DRV_SET_FOG_ENABLE(geBoolean Enable, geFloat r, geFloat g, geFloat b, geFloat Start, geFloat End);
00387 
00388 typedef void SETUP_LIGHTMAP_CB(DRV_LInfo *LInfo, geBoolean *Dynamic);
00389 
00390 typedef struct
00391 {
00392         char                            *Name;
00393         S32                                     VersionMajor;
00394         S32                                     VersionMinor;
00395 
00396         // Error handling hooks set by driver
00397         S32                                     LastError;                                                      // Last error driver made
00398         char                            *LastErrorStr;                                          // NULL terminated error string
00399         
00400         // Enum Modes/Drivers
00401         DRV_ENUM_DRIVER         *EnumSubDrivers;
00402         DRV_ENUM_MODES          *EnumModes;
00403         
00404         DRV_ENUM_PFORMAT        *EnumPixelFormats;
00405 
00406         // Init/DeInit functions
00407         DRV_INIT                                        *Init;
00408         DRV_SHUTDOWN                            *Shutdown;
00409         DRV_RESET                                       *Reset;
00410         DRV_UPDATE_WINDOW                       *UpdateWindow;
00411         DRV_SET_ACTIVE                          *SetActive;
00412         
00413         // Create/Destroy texture functions
00414         CREATE_TEXTURE          *THandle_Create;
00415         DESTROY_TEXTURE         *THandle_Destroy;
00416 
00417         // Texture manipulation functions
00418         LOCK_THANDLE            *THandle_Lock;
00419         UNLOCK_THANDLE          *THandle_UnLock;
00420 
00421         // Palette access functions
00422         SET_PALETTE                     *THandle_SetPalette;
00423         GET_PALETTE                     *THandle_GetPalette;
00424 
00425         // Palette access functions
00426         SET_ALPHA                       *THandle_SetAlpha;
00427         GET_ALPHA                       *THandle_GetAlpha;
00428 
00429         THANDLE_GET_INFO        *THandle_GetInfo;
00430 
00431         // Scene management functions
00432         BEGIN_SCENE                     *BeginScene;
00433         END_SCENE                       *EndScene;
00434         BEGIN_WORLD                     *BeginWorld;
00435         END_WORLD                       *EndWorld;
00436         BEGIN_MESHES            *BeginMeshes;
00437         END_MESHES                      *EndMeshes;
00438         BEGIN_MODELS            *BeginModels;
00439         END_MODELS                      *EndModels;
00440         
00441         // Render functions
00442         RENDER_G_POLY           *RenderGouraudPoly;
00443         RENDER_W_POLY           *RenderWorldPoly;
00444         RENDER_MT_POLY          *RenderMiscTexturePoly;
00445 
00446         //Decal functions
00447         DRAW_DECAL                      *DrawDecal;
00448 
00449         S32                                     NumWorldPixels;
00450         S32                                     NumWorldSpans;
00451         S32                                     NumRenderedPolys;
00452         DRV_CacheInfo           *CacheInfo;
00453 
00454         SCREEN_SHOT                     *ScreenShot;
00455 
00456         SET_GAMMA                       *SetGamma;
00457         GET_GAMMA                       *GetGamma;
00458 
00459         DRV_SET_FOG_ENABLE      *SetFogEnable;
00460         
00461         // Driver preferences
00462         DRV_EngineSettings      *EngineSettings;
00463 
00464         // The engine supplies these for the drivers misc use
00465         SETUP_LIGHTMAP_CB       *SetupLightmap;
00466 
00467         // Temp hack global
00468         GInfo                           *GlobalInfo;
00469 } DRV_Driver;
00470 
00471 typedef geBoolean DRV_Hook(DRV_Driver **Hook);
00472 
00473 //
00474 //      Error defines set by the driver.  These will be in the LastError member of DRV_Driver
00475 //      structure.  LastErrorStr will contain a NULL terminated detail error string set by the driver
00476 //
00477 #define DRV_ERROR_NONE                                  0       // No error has occured
00478 #define DRV_ERROR_INVALID_PARMS                 1       // invalid parameters passed
00479 #define DRV_ERROR_NULL_WINDOW                   2       // Null window supplied
00480 #define DRV_ERROR_INIT_ERROR                    3       // Error intitializing
00481 #define DRV_ERROR_INVALID_REGISTER_MODE 4       // Invalid register mode
00482 #define DRV_ERROR_NO_MEMORY                             5       // Not enough ram
00483 #define DRV_ERROR_MAX_TEXTURES                  6       // Max texture capacity has been exceeded...
00484 #define DRV_ERROR_GENERIC                               7       // Generic error         
00485 #define DRV_ERROR_UNDEFINED                             8       // An undefined error has occured
00486 #define DRV_ERROR_INVALID_WINDOW_MODE   9       // Requested window/full not supported
00487 
00488 typedef enum
00489 {
00490         RENDER_NONE,
00491         RENDER_WORLD,
00492         RENDER_MESHES,
00493         RENDER_MODELS
00494 } DRV_RENDER_MODE;
00495 
00496 #ifdef __cplusplus
00497 }
00498 #endif
00499 
00500 #pragma pack(pop)
00501 
00502 #endif

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