00001
00013
00014 #ifndef ___SimpleDX10_SimpleDX10_SimpleDX10_H___
00015 #define ___SimpleDX10_SimpleDX10_SimpleDX10_H___
00016
00017
00018
00019
00020
00021 #include "Common.h"
00022
00023 namespace Simplestar
00024 {
00025
00033 class SimpleDX10
00034 {
00035
00036
00037
00038 private:
00039
00040 typedef std::vector<D3D10_INPUT_ELEMENT_DESC> InputElementDescVector;
00041
00042 typedef std::map<std::string, unsigned int> PathToIndexMap;
00043
00044 typedef std::vector<ID3D10Effect*> EffectVector;
00045
00046 typedef std::vector<ID3D10ShaderResourceView*> ResourceVector;
00047
00048 typedef std::vector<std::vector<ID3D10InputLayout*> > InputLayout2Vector;
00049
00050
00051
00052
00053 private:
00054 HINSTANCE m_hInst;
00055 HWND m_hWnd;
00056 RESOLUTION_TYPE m_resolution;
00057 D3D10_DRIVER_TYPE m_driverType;
00058 ID3D10Device* m_pd3dDevice;
00059 IDXGISwapChain* m_pSwapChain;
00060 ID3D10RenderTargetView* m_pRenderTargetView;
00061 ID3D10Texture2D* m_pDepthStencil;
00062 ID3D10DepthStencilView* m_pDepthStencilView;
00063 EffectVector m_effectVector;
00064 ResourceVector m_resourceVector;
00065 ID3D10Buffer* m_pVertexBuffer;
00066 ID3D10Buffer* m_pIndexBuffer;
00067 InputLayout2Vector m_vertexLayout2Vector;
00068 D3DXMATRIX m_matView;
00069 D3DXMATRIX m_matProjection;
00070 bool m_bInitialized;
00071
00072 PathToIndexMap m_effectPathToIndexMap;
00073 PathToIndexMap m_resourcePathToIndexMap;
00074
00075
00076
00077
00078 public:
00080 typedef enum ErrorCode_SetRenderTarget
00081 {
00082 ERROR_SETRNDTGT_NONE = 0,
00083 ERROR_SETRNDTGT_REGISTER_CLASS,
00084 ERROR_SETRNDTGT_CREATE_WINDOW,
00085 ERROR_SETRNDTGT_RESIZE_WND,
00086 ERROR_SETRNDTGT_CREATE_DEVICE,
00087 ERROR_SETRNDTGT_CREATE_RNDTGT,
00088 ERROR_SETRNDTGT_CREATE_DEPTH_TEX,
00089 ERROR_SETRNDTGT_CREATE_DEPTH_VIEW,
00090 ERROR_SETRNDTGT_RESIZE_RNDTGT,
00091 };
00092
00093
00094
00095
00096 private:
00097 SimpleDX10(void);
00098 SimpleDX10(const SimpleDX10& copySrc);
00099 SimpleDX10& operator=(const SimpleDX10& copySrc);
00100 virtual ~SimpleDX10(void);
00101
00102
00103 void _CleanupDevice(void);
00104
00105
00106 bool _GetInputElementDescArray(SMPLDX10_VERTEX_FORMAT format, InputElementDescVector& outInputElementDescArray) const;
00107
00108
00109
00110
00111 public:
00112
00113 static SimpleDX10& Instance(void);
00114
00115 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
00116
00117
00118 ErrorCode_SetRenderTarget SetRenderTarget( RESOLUTION_TYPE& resolution, bool bFllScreen = false,
00119 HINSTANCE hInstance = NULL, int nCmdShow = SW_SHOWNORMAL);
00120
00121
00122 bool AppendEffect(const char* pFilePath, unsigned int& outIndex);
00123
00124 void EraseEffectByIndex(unsigned int index);
00125
00126 void EraseEffectByFilePath(const char* pFilePath);
00127
00128 void ReleaseEffects(void);
00129
00130 ID3D10Effect* GetEffect(unsigned int index, ID3D10Effect*& pOutEffect) const;
00131
00132
00133 bool AppendResource(const char* pFilePath, unsigned int& outIndex);
00134
00135 void EraseResourceByIndex(unsigned int index);
00136
00137 void EraseResourceByFilePath(const char* pFilePath);
00138
00139 void ReleaseResources(void);
00140
00141 ID3D10ShaderResourceView* GetResource(unsigned int index, ID3D10ShaderResourceView*& pOutResource) const;
00142
00143
00144 bool CreateVertexBuffer(unsigned int bufferSize, const void* pBuffer);
00145
00146 void ReleaseVertexBuffer(void);
00147
00148 bool CreateIndexBuffer(unsigned int bufferSize, const void* pBuffer);
00149
00150 void ReleaseIndexBuffer(void);
00151
00152 bool CreateVertexLayout(SMPLDX10_VERTEX_FORMAT format, unsigned int effectIndex, unsigned int techniqueIndex);
00153
00154 void ReleaseVertexLayout(void);
00155
00156
00157 void SetCamera(D3DXMATRIX& matWorld, D3DXVECTOR3& vecAt);
00158
00159 void SetProjection(float angle);
00160
00161 void ClearTargetView(void);
00162
00163 bool DrawMesh(MESH_INFO_TYPE& meshInfo, unsigned int effectIndex, unsigned int techIndex = 0) const;
00164
00165 void Present(void);
00166 };
00167 }
00168
00169
00170 #include "SimpleDX10.inl"
00171
00172 #endif // ___SimpleDX10_SimpleDX10_SimpleDX10_H___
00173
00174
00175
00176