HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>


d3dutil.h

00001 /*
00002  * Copyright (c) 1998-2001 by Tech Soft 3D, LLC.
00003  * The information contained herein is confidential and proprietary to
00004  * Tech Soft 3D, LLC., and considered a trade secret as defined under
00005  * civil and criminal statutes.  Tech Soft 3D shall pursue its civil
00006  * and criminal remedies in the event of unauthorized use or misappropriation
00007  * of its trade secrets.  Use of this information by anyone other than
00008  * authorized employees of Tech Soft 3D, LLC. is granted only under a
00009  * written non-disclosure agreement, expressly prescribing the scope and
00010  * manner of such use.
00011  *
00012  * $Id: d3dutil_8h-source.html,v 1.29 2008-03-10 07:09:28 stage Exp $
00013  */
00014 
00015 //-----------------------------------------------------------------------------
00016 // File: D3DUtil.h
00017 //
00018 // Desc: Helper functions and typing shortcuts for Direct3D programming.
00019 //-----------------------------------------------------------------------------
00020 #ifndef HD3DUTIL_H
00021 #define HD3DUTIL_H
00022 #ifdef _DEBUG
00023 #ifndef D3D_DEBUG_INFO
00024 #define D3D_DEBUG_INFO
00025 #endif
00026 #endif 
00027 #include <D3D9.h>
00028 #include <D3DX9Math.h>
00029 
00030 typedef struct d3d_system_data 
00031 {
00032     int                     ref_count;              // reference count
00033     LPDIRECT3D9             pD3D;                   // the main D3D object
00034 } D3D_System_Data;
00035 
00036 
00037 //-----------------------------------------------------------------------------
00038 // Name: D3DUtil_InitMaterial()
00039 // Desc: Initializes a D3DMATERIAL9 structure, setting the diffuse and ambient
00040 //               colors. It does not set emissive or specular colors.
00041 //-----------------------------------------------------------------------------
00042 VOID D3DUtil_InitMaterial(
00043     D3DMATERIAL9& mtrl, 
00044     FLOAT r=0.0f, 
00045     FLOAT g=0.0f,
00046     FLOAT b=0.0f, 
00047     FLOAT a=1.0f);
00048 
00049 
00050 //-----------------------------------------------------------------------------
00051 // File: DXUtil.h
00052 //
00053 // Desc: Helper functions and typing shortcuts for DirectX programming.
00054 //-----------------------------------------------------------------------------
00055 
00056 
00057 //-----------------------------------------------------------------------------
00058 // Miscellaneous helper functions
00059 //-----------------------------------------------------------------------------
00060 #define H_SAFE_DELETE(p)             { if (p) { delete (p);    (p)=NULL; } }
00061 #define H_SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p);   (p)=NULL; } }
00062 #define H_SAFE_RELEASE(p)            { if (p) { (p)->Release(); (p)=NULL; } }
00063 
00064 
00065 
00066 
00067 //-----------------------------------------------------------------------------
00068 // Name: ArrayListType
00069 // Desc: Indicates how data should be stored in a CArrayList
00070 //-----------------------------------------------------------------------------
00071 enum ArrayListType
00072 {
00073         AL_VALUE,               // entry data is copied into the list
00074         AL_REFERENCE,   // entry pointers are copied into the list
00075 };
00076 
00077 
00078 //-----------------------------------------------------------------------------
00079 // Name: CArrayList
00080 // Desc: A growable array
00081 //-----------------------------------------------------------------------------
00082 class CArrayList
00083 {
00084 protected:
00085         ArrayListType m_ArrayListType;
00086         void* m_pData;
00087         UINT m_BytesPerEntry;
00088         UINT m_NumEntries;
00089         UINT m_NumEntriesAllocated;
00090 
00091 public:
00092         CArrayList(ArrayListType Type, UINT BytesPerEntry = 0);
00093         ~CArrayList(void);
00094         HRESULT Add(void* pEntry);
00095         void Remove(UINT Entry);
00096         void* GetPtr(UINT Entry);
00097         UINT Count(void) { return m_NumEntries; }
00098         bool Contains(void* pEntryData);
00099         void Clear(void) { m_NumEntries = 0; }
00100 };
00101 
00102 
00103 //-----------------------------------------------------------------------------
00104 // File: D3DEnumeration.h
00105 //
00106 // Desc: Enumerates D3D adapters, devices, modes, etc.
00107 //-----------------------------------------------------------------------------
00108 
00109 extern UINT ColorChannelBits(D3DFORMAT fmt);
00110 extern UINT AlphaChannelBits(D3DFORMAT fmt);
00111 extern UINT DepthBits(D3DFORMAT fmt);
00112 extern UINT StencilBits(D3DFORMAT fmt);
00113 
00114 //-----------------------------------------------------------------------------
00115 // Name: enum VertexProcessingType
00116 // Desc: Enumeration of all possible D3D vertex processing types.
00117 //-----------------------------------------------------------------------------
00118 enum VertexProcessingType
00119 {
00120         SOFTWARE_VP,
00121         MIXED_VP,
00122         HARDWARE_VP,
00123         PURE_HARDWARE_VP
00124 };
00125 
00126 
00127 //-----------------------------------------------------------------------------
00128 // Name: struct D3DAdapterInfo
00129 // Desc: Info about a display adapter.
00130 //-----------------------------------------------------------------------------
00131 struct D3DAdapterInfo
00132 {
00133         int AdapterOrdinal;
00134         D3DADAPTER_IDENTIFIER9 AdapterIdentifier;
00135         CArrayList* pDisplayModeList; // List of D3DDISPLAYMODEs
00136         CArrayList* pDeviceInfoList; // List of D3DDeviceInfo pointers
00137         ~D3DAdapterInfo(void);
00138 };
00139 
00140 
00141 //-----------------------------------------------------------------------------
00142 // Name: struct D3DDeviceInfo
00143 // Desc: Info about a D3D device, including a list of D3DDeviceCombos (see below) 
00144 //               that work with the device.
00145 //-----------------------------------------------------------------------------
00146 struct D3DDeviceInfo
00147 {
00148         int AdapterOrdinal;
00149         D3DDEVTYPE DevType;
00150         D3DCAPS9 Caps;
00151         CArrayList* pDeviceComboList; // List of D3DDeviceCombo pointers
00152         ~D3DDeviceInfo(void);
00153 };
00154 
00155 
00156 //-----------------------------------------------------------------------------
00157 // Name: struct D3DDSMSConflict
00158 // Desc: A depth/stencil buffer format that is incompatible with a
00159 //               multisample type.
00160 //-----------------------------------------------------------------------------
00161 struct D3DDSMSConflict
00162 {
00163         D3DFORMAT DSFormat;
00164         D3DMULTISAMPLE_TYPE MSType;
00165 };
00166 
00167 
00168 //-----------------------------------------------------------------------------
00169 // Name: struct D3DDeviceCombo
00170 // Desc: A combination of adapter format, back buffer format, and windowed/fullscreen 
00171 //               that is compatible with a particular D3D device (and the app).
00172 //-----------------------------------------------------------------------------
00173 struct D3DDeviceCombo
00174 {
00175         int AdapterOrdinal;
00176         D3DDEVTYPE DevType;
00177         D3DFORMAT AdapterFormat;
00178         D3DFORMAT BackBufferFormat;
00179         bool IsWindowed;
00180         CArrayList* pDepthStencilFormatList; // List of D3DFORMATs
00181         CArrayList* pMultiSampleTypeList; // List of D3DMULTISAMPLE_TYPEs
00182         CArrayList* pMultiSampleQualityList; // List of DWORDs (number of quality 
00183                                                                                  // levels for each multisample type)
00184         CArrayList* pDSMSConflictList; // List of D3DDSMSConflicts
00185         CArrayList* pVertexProcessingTypeList; // List of VertexProcessingTypes
00186         CArrayList* pPresentIntervalList; // List of D3DPRESENT_INTERVALs
00187 
00188         ~D3DDeviceCombo(void);
00189 };
00190 
00191 
00192 typedef bool(* CONFIRMDEVICECALLBACK)(D3DCAPS9* pCaps, VertexProcessingType vertexProcessingType, 
00193                                                                                    D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat);
00194 
00195 
00196 
00197 //-----------------------------------------------------------------------------
00198 // Name: class HD3DEnumeration
00199 // Desc: Enumerates available D3D adapters, devices, modes, etc.
00200 //-----------------------------------------------------------------------------
00201 class HD3DEnumeration
00202 {
00203 private:
00204         IDirect3D9* m_pD3D;
00205 
00206 private:
00207         HRESULT EnumerateDevices(D3DAdapterInfo* pAdapterInfo, CArrayList* pAdapterFormatList);
00208         HRESULT EnumerateDeviceCombos(D3DDeviceInfo* pDeviceInfo, CArrayList* pAdapterFormatList);
00209         void BuildDepthStencilFormatList(D3DDeviceCombo* pDeviceCombo);
00210         void BuildMultiSampleTypeList(D3DDeviceCombo* pDeviceCombo);
00211         void BuildDSMSConflictList(D3DDeviceCombo* pDeviceCombo);
00212         void BuildVertexProcessingTypeList(D3DDeviceInfo* pDeviceInfo, D3DDeviceCombo* pDeviceCombo);
00213         void BuildPresentIntervalList(D3DDeviceInfo* pDeviceInfo, D3DDeviceCombo* pDeviceCombo);
00214 
00215 public:
00216         CArrayList* m_pAdapterInfoList;
00217         // The following variables can be used to limit what modes, formats, 
00218         // etc. are enumerated.  Set them to the values you want before calling
00219         // Enumerate().
00220         CONFIRMDEVICECALLBACK ConfirmDeviceCallback;
00221         UINT AppMinFullscreenWidth;
00222         UINT AppMinFullscreenHeight;
00223         UINT AppMinColorChannelBits; // min color bits per channel in adapter format
00224         UINT AppMinAlphaChannelBits; // min alpha bits per pixel in back buffer format
00225         UINT AppMinDepthBits;
00226         UINT AppMinStencilBits;
00227         bool AppUsesDepthBuffer;
00228         bool AppUsesMixedVP; // whether app can take advantage of mixed vp mode
00229         bool AppRequiresWindowed;
00230         bool AppRequiresFullscreen;
00231         CArrayList* m_pAllowedAdapterFormatList; // list of D3DFORMATs
00232 
00233         HD3DEnumeration();
00234         ~HD3DEnumeration();
00235         void SetD3D(IDirect3D9* pD3D) { m_pD3D = pD3D; }
00236         HRESULT Enumerate();
00237 };
00238 
00239 extern bool confirm_device_helper(
00240     D3DCAPS9* pCaps, 
00241     VertexProcessingType vertexProcessingType,
00242     D3DFORMAT adapterFormat, 
00243     D3DFORMAT backBufferFormat);
00244 
00245 //-----------------------------------------------------------------------------
00246 // File: D3DSettings.h
00247 //
00248 // Desc: Settings class and change-settings dialog class for the Direct3D 
00249 //               samples framework library.
00250 //-----------------------------------------------------------------------------
00251 
00252 
00253 //-----------------------------------------------------------------------------
00254 // Name: class HD3DSettings
00255 // Desc: Current D3D settings: adapter, device, mode, formats, etc.
00256 //-----------------------------------------------------------------------------
00257 class HD3DSettings 
00258 {
00259 public:
00260         bool IsWindowed;
00261 
00262         D3DAdapterInfo* pWindowed_AdapterInfo;
00263         D3DDeviceInfo* pWindowed_DeviceInfo;
00264         D3DDeviceCombo* pWindowed_DeviceCombo;
00265 
00266         D3DDISPLAYMODE Windowed_DisplayMode; // not changable by the user
00267         D3DFORMAT Windowed_DepthStencilBufferFormat;
00268         D3DMULTISAMPLE_TYPE Windowed_MultisampleType;
00269         DWORD Windowed_MultisampleQuality;
00270         VertexProcessingType Windowed_VertexProcessingType;
00271         UINT Windowed_PresentInterval;
00272         int Windowed_Width;
00273         int Windowed_Height;
00274 
00275         D3DAdapterInfo* pFullscreen_AdapterInfo;
00276         D3DDeviceInfo* pFullscreen_DeviceInfo;
00277         D3DDeviceCombo* pFullscreen_DeviceCombo;
00278 
00279         D3DDISPLAYMODE Fullscreen_DisplayMode; // changable by the user
00280         D3DFORMAT Fullscreen_DepthStencilBufferFormat;
00281         D3DMULTISAMPLE_TYPE Fullscreen_MultisampleType;
00282         DWORD Fullscreen_MultisampleQuality;
00283         VertexProcessingType Fullscreen_VertexProcessingType;
00284         UINT Fullscreen_PresentInterval;
00285 
00286         D3DAdapterInfo* PAdapterInfo() { return IsWindowed ? pWindowed_AdapterInfo : pFullscreen_AdapterInfo; }
00287         D3DDeviceInfo* PDeviceInfo() { return IsWindowed ? pWindowed_DeviceInfo : pFullscreen_DeviceInfo; }
00288         D3DDeviceCombo* PDeviceCombo() { return IsWindowed ? pWindowed_DeviceCombo : pFullscreen_DeviceCombo; }
00289 
00290         int AdapterOrdinal() { return PDeviceCombo()->AdapterOrdinal; }
00291         D3DDEVTYPE DevType() { return PDeviceCombo()->DevType; }
00292         D3DFORMAT BackBufferFormat() { return PDeviceCombo()->BackBufferFormat; }
00293 
00294         D3DDISPLAYMODE DisplayMode() { return IsWindowed ? Windowed_DisplayMode : Fullscreen_DisplayMode; }
00295         void SetDisplayMode(D3DDISPLAYMODE value) { if (IsWindowed) Windowed_DisplayMode = value; else Fullscreen_DisplayMode = value; }
00296 
00297         D3DFORMAT DepthStencilBufferFormat() { return IsWindowed ? Windowed_DepthStencilBufferFormat : Fullscreen_DepthStencilBufferFormat; }
00298         void SetDepthStencilBufferFormat(D3DFORMAT value) { if (IsWindowed) Windowed_DepthStencilBufferFormat = value; else Fullscreen_DepthStencilBufferFormat = value; }
00299 
00300         D3DMULTISAMPLE_TYPE MultisampleType() { return IsWindowed ? Windowed_MultisampleType : Fullscreen_MultisampleType; }
00301         void SetMultisampleType(D3DMULTISAMPLE_TYPE value) { if (IsWindowed) Windowed_MultisampleType = value; else Fullscreen_MultisampleType = value; }
00302 
00303         DWORD MultisampleQuality() { return IsWindowed ? Windowed_MultisampleQuality : Fullscreen_MultisampleQuality; }
00304         void SetMultisampleQuality(DWORD value) { if (IsWindowed) Windowed_MultisampleQuality = value; else Fullscreen_MultisampleQuality = value; }
00305 
00306         VertexProcessingType GetVertexProcessingType() { return IsWindowed ? Windowed_VertexProcessingType : Fullscreen_VertexProcessingType; }
00307         void SetVertexProcessingType(VertexProcessingType value) { if (IsWindowed) Windowed_VertexProcessingType = value; else Fullscreen_VertexProcessingType = value; }
00308 
00309         UINT PresentInterval() { return IsWindowed ? Windowed_PresentInterval : Fullscreen_PresentInterval; }
00310         void SetPresentInterval(UINT value) { if (IsWindowed) Windowed_PresentInterval = value; else Fullscreen_PresentInterval = value; }
00311 };
00312 
00313 
00314 
00315 #endif // HD3DUTIL_H
Main Index
HOOPS/3dGS I.M. Interface

     << Back      Full Index      Forward >>