00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _D3DRENDERER_
00019 #define _D3DRENDERER_
00020
00021 #include <d3d9.h>
00022 #include <d3dx9.h>
00023 #include <hash_map>
00024 #include <string>
00025
00026 #include "renderer/AbstractRenderer.h"
00027 #include "util/StringHasher.h"
00028
00029 #define SAFE_RELEASE(p) if(p) p->Release()
00030 #define MAX_VERTICES 1024
00031
00032 class D3DRenderer : public AbstractRenderer
00033 {
00034 friend class TextureResourceListener;
00035 private:
00036 typedef stdext::hash_map<std::string, LPD3DXFONT, StringHasher> FontMap;
00037
00038 LPDIRECT3DDEVICE9 m_pDevice;
00039 LPD3DXSPRITE m_pSpriteInterface;
00040
00041 LPDIRECT3DVERTEXDECLARATION9 m_pVertexDeclaration;
00042 LPDIRECT3DVERTEXDECLARATION9 m_pLineDeclaration;
00043
00044 Colour m_clearColour;
00045
00046 D3DPRESENT_PARAMETERS m_presentParams;
00047
00048 FontMap m_fontCache;
00049
00050 bool m_bDeviceLost;
00051
00052 LPD3DXFONT CacheFont(const std::string fontName, const int nSize, bool bBold, bool bItalic);
00053 std::string GetFontIdentifier(const std::string& fontName, const int nSize, bool bBold, bool bItalic);
00054 public:
00055 D3DRenderer();
00056 virtual ~D3DRenderer();
00057
00058 virtual void BeginRendering();
00059 virtual void EndRendering();
00060 virtual void SetClearColour(const Colour& c) { m_clearColour = c; }
00061
00062 virtual void DrawLines(const LineVertex* pVertices, const int nNumPoints, const int nWidth, const float fTranslateX, const float fTranslateY, const float fRotation);
00063 virtual void DrawSprite(const Sprite* pSprite, ResourceCache * const pResourceCache, const Vector2& position, const Vector2& center, const float fRotation, const float fScaleX, const float fScaleY);
00064 virtual void DrawString(const std::wstring& text, const std::string& font, const int nSize, const Vector2& position, const int nAlignment, const Colour& c, bool bBold, bool bItalic);
00065 virtual void DrawText(const std::wstring& text, const std::string& font, const int nSize, const Rect& rect, const int nAlignment, Colour& c, bool bBold, bool bItalic);
00066 virtual void DrawModel(const PTModel& model, const Vector2& translation, const float fRotation, const float fScale);
00067
00068 virtual bool CanRender();
00069 virtual std::pair<int, int> GetResolution();
00070 virtual void ClearArea(const Rect& rect, const Colour& c);
00071 virtual int GetStringWidth(const std::wstring& textString, const std::string& font, const int nFontHeight, bool bBold, bool bItalic);
00072
00073 void Reset();
00074 HRESULT InitializeD3D(HWND hWnd, INT nWidth, INT nHeight, D3DFORMAT backBufferFmt, D3DMULTISAMPLE_TYPE multisampling, BOOL bWindowed);
00075 };
00076
00077
00078 #endif