00001 #ifndef __GXDEVICECONTAINER
00002 #define __GXDEVICECONTAINER
00003
00004
00005 #include "GXStandardDefines.h"
00006
00007 #define TEXTURE_CACHE_SIZE 2
00008
00009
00010 struct SGXDeviceOptions
00011 {
00012 HWND hWnd;
00013 UINT uWidth;
00014 UINT uHeight;
00015 bool bFullScreen;
00016
00017 };
00018
00019
00020 struct SGXCaps
00021 {
00022 bool bDP3;
00023 UINT nPixelMajor;
00024 UINT nPixelMinor;
00025 UINT nVertexMajor;
00026 UINT nVertexMinor;
00027 UINT nTextureCount;
00028 };
00029
00030
00031 class CGXDeviceContainer
00032 {
00033 public:
00034 CGXDeviceContainer();
00035 virtual ~CGXDeviceContainer();
00036
00037 virtual bool Init(SGXDeviceOptions* pOptions,
00038 void (*pErrorCallback)(char*));
00039
00040 virtual void Cleanup();
00041
00042 virtual bool GetCaps(SGXCaps* pOut);
00043
00044
00045
00046 virtual bool ToggleWindowSize(bool bFullScreen, UINT uWidth, UINT uHeight);
00047
00048 virtual bool GXDrawText(char* szText, D3DXVECTOR2* pStartPos, D3DCOLOR Color);
00049
00050
00051 virtual bool BeginDrawSprites();
00052 virtual bool EndDrawSprites();
00053 virtual bool DrawSprite(IDirect3DTexture8* pTexture, D3DXVECTOR2* pUpperLeft,
00054 D3DXVECTOR2* pSize, D3DXVECTOR2* pRotationCenter,
00055 float fRotation, DWORD dwColor);
00056
00057 virtual bool InitCache();
00058
00059 virtual bool Reset();
00060
00061 HRESULT TestCooperativeLevel();
00062
00063
00064 HRESULT D3DXCreateTextureFromFileEx(LPCTSTR pSrcFile,
00065 UINT Width,
00066 UINT Height,
00067 UINT MipLevels,
00068 DWORD Usage,
00069 D3DFORMAT Format,
00070 D3DPOOL Pool,
00071 DWORD Filter,
00072 DWORD MipFilter,
00073 D3DCOLOR ColorKey,
00074 D3DXIMAGE_INFO* pSrcInfo,
00075 PALETTEENTRY* pPalette,
00076 LPDIRECT3DTEXTURE8* ppTexture);
00077
00078
00079 HRESULT SetStreamSource(UINT StreamNumber,
00080 IDirect3DVertexBuffer8* pStreamData,
00081 UINT Stride);
00082
00083 HRESULT SetIndices(IDirect3DIndexBuffer8* pIndexData,
00084 UINT BaseVertexIndex);
00085
00086 HRESULT DrawIndexedPrimitive(D3DPRIMITIVETYPE Type,
00087 UINT MinIndex,
00088 UINT NumVertices,
00089 UINT StartIndex,
00090 UINT PrimitiveCount);
00091
00092
00093 HRESULT CreateVertexBuffer(UINT Length,
00094 DWORD Usage,
00095 DWORD FVF,
00096 D3DPOOL Pool,
00097 IDirect3DVertexBuffer8** ppVertexBuffer);
00098
00099
00100 HRESULT CreateIndexBuffer(UINT Length,
00101 DWORD Usage,
00102 D3DFORMAT Format,
00103 D3DPOOL Pool,
00104 IDirect3DIndexBuffer8** ppIndexBuffer);
00105
00106
00107 HRESULT CreateVertexShader(CONST DWORD* pDeclaration,
00108 CONST DWORD* pFunction,
00109 DWORD* pHandle,
00110 DWORD Usage);
00111
00112 HRESULT SetVertexShader(DWORD Handle);
00113
00114 HRESULT DeleteVertexShader(DWORD Handle);
00115
00116
00117
00118
00119
00120 HRESULT D3DXCreateTexture(UINT Width,
00121 UINT Height,
00122 UINT MipLevels,
00123 DWORD Usage,
00124 D3DFORMAT Format,
00125 D3DPOOL Pool,
00126 LPDIRECT3DTEXTURE8* ppTexture);
00127
00128
00129 HRESULT SetVertexShaderConstant(DWORD Register,
00130 CONST void* pConstantData,
00131 DWORD ConstantCount);
00132
00133
00134 HRESULT SetTexture(DWORD Stage,
00135 IDirect3DBaseTexture8* pTexture);
00136
00137 HRESULT GetCreationParameters(D3DDEVICE_CREATION_PARAMETERS* pParameters);
00138
00139
00140
00141 HRESULT SetTextureStageState(DWORD Stage,
00142 D3DTEXTURESTAGESTATETYPE Type,
00143 DWORD Value);
00144
00145
00146
00147 HRESULT CloneMeshFVF(DWORD Options,
00148 DWORD FVF,
00149 ID3DXBaseMesh* pMesh,
00150 LPD3DXMESH* ppCloneMesh);
00151
00152
00153 HRESULT D3DXCreateMeshFVF(DWORD NumFaces,
00154 DWORD NumVertices,
00155 DWORD Options,
00156 DWORD FVF,
00157 LPD3DXMESH* ppMesh);
00158
00159
00160 HRESULT D3DXCreatePMeshFromStream(IStream* pStream,
00161 DWORD Options,
00162 LPD3DXBUFFER* ppMaterials,
00163 DWORD* pNumMaterials,
00164 LPD3DXPMESH* ppPMesh);
00165
00166
00167 ULONG Release(void);
00168 ULONG AddRef(void);
00169
00170
00171 HRESULT D3DXCreateSphere(FLOAT Radius,
00172 UINT Slices,
00173 UINT Stacks,
00174 LPD3DXMESH* ppMesh,
00175 LPD3DXBUFFER* ppAdjacency);
00176
00177
00178 HRESULT SetClipPlane(DWORD Index,
00179 CONST float* pPlane);
00180
00181
00182 HRESULT Present(CONST RECT* pSourceRect,
00183 CONST RECT* pDestRect,
00184 HWND hDestWindowOverride,
00185 CONST RGNDATA* pDirtyRegion);
00186
00187
00188 HRESULT BeginScene();
00189 HRESULT EndScene();
00190
00191 HRESULT Clear(DWORD Count,
00192 CONST D3DRECT* pRects,
00193 DWORD Flags,
00194 D3DCOLOR Color,
00195 float Z,
00196 DWORD Stencil);
00197
00198
00199
00200 HRESULT GetBackBuffer(UINT BackBuffer,
00201 D3DBACKBUFFER_TYPE Type,
00202 IDirect3DSurface8** ppBackBuffer);
00203
00204 HRESULT GetDepthStencilSurface(IDirect3DSurface8** ppZStencilSurface);
00205
00206 HRESULT SetRenderTarget(IDirect3DSurface8* pRenderTarget,
00207 IDirect3DSurface8* pNewZStencil);
00208
00209
00210 HRESULT GetRenderState(
00211 D3DRENDERSTATETYPE State,
00212 DWORD* pValue
00213 );
00214
00215
00216 HRESULT SetRenderState(
00217 D3DRENDERSTATETYPE State,
00218 DWORD Value
00219 );
00220
00221
00222
00223 HRESULT SetTransform(
00224 D3DTRANSFORMSTATETYPE State,
00225 CONST D3DMATRIX* pMatrix
00226 );
00227
00228
00229
00230 inline void DisplayStats(bool bDisplay)
00231 {
00232 m_bDisplayStats=bDisplay;
00233 }
00234
00235
00236
00237
00238 public:
00239
00240
00241
00242
00243
00244
00245
00246 protected:
00247
00248 IDirect3D8* m_pD3D;
00249 IDirect3DDevice8* m_pDevice;
00250 ID3DXFont* m_pFont;
00251 ID3DXSprite* m_pSprite;
00252
00253 IDirect3DBaseTexture8* m_rgpTextureCache[TEXTURE_CACHE_SIZE];
00254 IDirect3DVertexBuffer8* m_pVBCache;
00255 IDirect3DIndexBuffer8* m_pIBCache;
00256
00257 D3DPRESENT_PARAMETERS m_PresentParams;
00258
00259 bool m_bDisplayStats;
00260 UINT m_uTrianglesDrawn;
00261 UINT m_uFrame;
00262 UINT m_uLastTickCount;
00263 UINT m_uFPS;
00264
00265
00266 protected:
00267 virtual bool DrawStats();
00268 virtual bool GXCreateFontAndSprite();
00269
00270 virtual bool CreateDevice(D3DFORMAT BBFormat,
00271 D3DFORMAT DepthFormat,
00272 SGXDeviceOptions* pOptions);
00273
00274
00275
00276 virtual bool ShouldGoSWVP();
00277
00278 virtual bool IsDepthBBCombinationSupported(D3DFORMAT BBFormat,
00279 D3DFORMAT DepthFormat,
00280 bool bFullScreen);
00281
00282 };
00283
00284
00285 #endif