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

display.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  Display.C                                                                           */
00003 /*                                                                                      */
00004 /*  Author:  Mike Sandige                                                               */
00005 /*  Description:  Abstracts all low-level display surfaces into a single API            */
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 #pragma warning(disable : 4201 4214 4115)
00023 #include <windows.h>
00024 #pragma warning(default : 4201 4214 4115; disable : 4514)
00025 #include <assert.h>
00026 #include "basetype.h"
00027 #include "display.h"
00028 #include "DIBDisplay.h"
00029 #include "DDRAWDisplay.h"
00030 
00031 #ifdef GENESIS_VERSION_2
00032 #include "errorlog.h"
00033 #else
00034 #define geErrorLog_AddString(Error,xx,yy) 
00035 #endif
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040 
00041 typedef struct Display 
00042 {
00043         Display_Type DisplayType;
00044         DIBDisplay       *pDIBDisplay;
00045         DDRAWDisplay *pDDRAWDisplay;
00046 }Display;
00047 
00048 #pragma message ("BitsPerPixel should be a Bitmap Format")
00049 
00050 void Display_GetDisplayFormat(          const Display *D,
00051                                                                         Display_Type *DisplayType,
00052                                                                         int32   *Width, 
00053                                                                         int32   *Height,
00054                                                                         int32   *BitsPerPixel,
00055                                                                         uint32  *Flags)
00056 {
00057         assert( D            != NULL );
00058         assert( DisplayType  != NULL );
00059         assert( Width        != NULL );
00060         assert( Height       != NULL );
00061         assert( BitsPerPixel != NULL );
00062         assert( Flags        != NULL );
00063 
00064         *DisplayType = D->DisplayType;
00065         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00066                 {
00067                         DIBDisplay_GetDisplayFormat(    D->pDIBDisplay,
00068                                                                                         Width, 
00069                                                                                         Height,
00070                                                                                         BitsPerPixel,
00071                                                                                         Flags);
00072                 }
00073         else
00074                 {
00075                         DDRAWDisplay_GetDisplayFormat(  D->pDDRAWDisplay,
00076                                                                                         Width, 
00077                                                                                         Height,
00078                                                                                         BitsPerPixel,
00079                                                                                         Flags);
00080                 }
00081 }       
00082 
00083 
00084 
00085 geBoolean Display_GetPixelFormat        (       const Display *D,
00086                                                                                 //int32       *pixel_pitch,
00087                                                                                 int32       *bytes_per_pixel,
00088                                                                                 int32       *R_shift,
00089                                                                                 uint32      *R_mask,
00090                                                                                 int32       *R_width,
00091                                                                                 int32       *G_shift,
00092                                                                                 uint32      *G_mask,
00093                                                                                 int32       *G_width,
00094                                                                                 int32       *B_shift,
00095                                                                                 uint32      *B_mask,
00096                                                                                 int32       *B_width)
00097 {
00098         assert( D != NULL);
00099         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00100                 {
00101                         return DIBDisplay_GetPixelFormat(       D->pDIBDisplay,
00102                                                                                                 //pixel_pitch,
00103                                                                                                 bytes_per_pixel,
00104                                                                                                 R_shift, R_mask, R_width,
00105                                                                                                 G_shift, G_mask, G_width,
00106                                                                                                 B_shift, B_mask, B_width);
00107                 }
00108         else
00109                 {
00110                         return DDRAWDisplay_GetPixelFormat( D->pDDRAWDisplay,
00111                                                                                                 //pixel_pitch,
00112                                                                                                 bytes_per_pixel,
00113                                                                                                 R_shift, R_mask, R_width,
00114                                                                                                 G_shift, G_mask, G_width,
00115                                                                                                 B_shift, B_mask, B_width);
00116                 }
00117 }
00118 
00119 
00120 
00121 geBoolean Display_Blit          (       Display *D )
00122 {
00123         assert( D != NULL);
00124         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00125                 {
00126                         return DIBDisplay_Blit( D->pDIBDisplay );
00127                 }
00128         else
00129                 {
00130                         return DDRAWDisplay_Blit( D->pDDRAWDisplay );
00131                 }
00132 }
00133 
00134 geBoolean Display_Wipe          (       Display *D,     
00135                                                                 uint32        color)
00136 {
00137         assert( D != NULL);
00138         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00139                 {
00140                         return DIBDisplay_Wipe( D->pDIBDisplay, color );
00141                 }
00142         else
00143                 {
00144                         return DDRAWDisplay_Wipe(       D->pDDRAWDisplay, color );
00145                 }
00146 }
00147 
00148 #pragma message ("should the ptr argument to Display_Lock be a uint8?")
00149 
00150 geBoolean Display_Lock          (       Display *D,
00151                                                                 uint8       **ptr,
00152                                                                 int32       *pitch)
00153 {
00154         assert( D != NULL);
00155         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00156                 {
00157                         return DIBDisplay_Lock( D->pDIBDisplay, ptr, pitch );
00158                 }
00159         else
00160                 {
00161                         return DDRAWDisplay_Lock(D->pDDRAWDisplay,ptr,pitch);
00162                 }
00163 }
00164 
00165 geBoolean Display_Unlock        (       Display *D  )
00166 {
00167         assert( D != NULL);
00168         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00169                 {
00170                         return DIBDisplay_Unlock(       D->pDIBDisplay );
00171                 }
00172         else
00173                 {
00174                         return DDRAWDisplay_Unlock( D->pDDRAWDisplay);
00175                 }
00176 }
00177 
00178 geBoolean Display_SetActive     (       Display *D, geBoolean Active )
00179 {
00180         assert( D != NULL);
00181         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00182                 {
00183                         return GE_TRUE;
00184                 }
00185         else
00186                 {
00187                         return DDRAWDisplay_SetActive(D->pDDRAWDisplay,Active);
00188                 }
00189 }
00190 
00191 void Display_Destroy            (       Display **pDisplay )
00192 {
00193         Display *D;
00194         assert( pDisplay != NULL );
00195         D = *pDisplay;
00196         assert( D != NULL);
00197         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00198                 {
00199                         DIBDisplay_Destroy(     &(D->pDIBDisplay) );
00200                         D->pDIBDisplay = NULL;
00201                 }
00202         else
00203                 {
00204                         DDRAWDisplay_Destroy(   &(D->pDDRAWDisplay) );
00205                         D->pDDRAWDisplay = NULL;
00206                 }
00207         free( D );
00208         *pDisplay = NULL;
00209 }
00210 
00211 
00212 Display *Display_Create (       HWND hWindow,
00213                                                         Display_Type DisplayType,
00214                                                         int32   RenderSizeAcross, 
00215                                                         int32   RenderSizeDown,
00216                                                         int32   Display_BitsPerPixel,
00217                                                         uint32   Flags)
00218 {
00219         Display *D;
00220         D = malloc( sizeof( Display ) );
00221         assert( (DisplayType == DISPLAY_DIB_WINDOW) || (DisplayType == DISPLAY_DDRAW_FULLSCREEN));
00222         
00223         if (D == NULL)
00224                 {
00225                         geErrorLog_AddString(GE_ERR_MEMORY_RESOURCE,"unable to create Display object",NULL);
00226                         return NULL;
00227                 }
00228 
00229         D->DisplayType   = DisplayType;
00230         D->pDIBDisplay   = NULL;
00231         D->pDDRAWDisplay = NULL;
00232                 
00233         if (D->DisplayType == DISPLAY_DIB_WINDOW)
00234                 {
00235                         D->pDIBDisplay =  DIBDisplay_Create( hWindow,RenderSizeAcross,RenderSizeDown,Display_BitsPerPixel,Flags );
00236                         if (D->pDIBDisplay == NULL)
00237                                 {
00238                                         geErrorLog_AddString(GE_ERR_SUBSYSTEM_FAILURE,"Unable to create DIBDisplay object",NULL);
00239                                         free(D);
00240                                         return NULL;
00241                                 }
00242                 }
00243         else
00244                 {
00245                         D->pDDRAWDisplay = DDRAWDisplay_Create( hWindow,RenderSizeAcross,RenderSizeDown,Display_BitsPerPixel,Flags );
00246                         if (D->pDDRAWDisplay == NULL)
00247                                 {
00248                                         geErrorLog_AddString(GE_ERR_SUBSYSTEM_FAILURE,"Unable to create DDRAWDisplay object",NULL);
00249                                         free(D);
00250                                         return NULL;
00251                                 }
00252                 }
00253         return D;
00254 }
00255 
00256 
00257 geBoolean Display_GetDisplayInfo(       Display_Type     DisplayType,
00258                                                                         char                    *DescriptionString, 
00259                                                                         unsigned int     DescriptionStringMaxLength,
00260                                                                         DisplayModeInfo *Info)
00261 {
00262         assert( (DisplayType == DISPLAY_DIB_WINDOW) || (DisplayType == DISPLAY_DDRAW_FULLSCREEN));
00263         if (DisplayType == DISPLAY_DDRAW_FULLSCREEN)
00264                 {
00265                         return DDRAWDisplay_GetDisplayInfo(     DescriptionString,  DescriptionStringMaxLength, Info);
00266                 }
00267         else
00268                 {
00269                         return DIBDisplay_GetDisplayInfo(       DescriptionString,  DescriptionStringMaxLength, Info);
00270                 }
00271 }

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