Fix keymap.
[vuplus_xbmc] / xbmc / guilib / D3DResource.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #pragma once
22
23 #ifdef HAS_DX
24 #include "utils/StdString.h"
25 #include <map>
26
27 class ID3DResource
28 {
29 public:
30   virtual ~ID3DResource() {};
31
32   virtual void OnDestroyDevice()=0;
33   virtual void OnCreateDevice()=0;
34   virtual void OnLostDevice() {};
35   virtual void OnResetDevice() {};
36 };
37
38 class CD3DTexture : public ID3DResource
39 {
40 public:
41   CD3DTexture();
42   ~CD3DTexture();
43
44   bool Create(UINT width, UINT height, UINT mipLevels, DWORD usage, D3DFORMAT format, D3DPOOL pool);
45   void Release();
46   bool LockRect(UINT level, D3DLOCKED_RECT *lr, const RECT *rect, DWORD flags);
47   bool UnlockRect(UINT level);
48   bool GetLevelDesc(UINT level, D3DSURFACE_DESC *desc);
49   bool GetSurfaceLevel(UINT level, LPDIRECT3DSURFACE9 *surface);
50
51   // Accessors
52   LPDIRECT3DTEXTURE9 Get() const { return m_texture; };
53   UINT GetWidth()  const { return m_width; }
54   UINT GetHeight() const { return m_height; }
55   D3DFORMAT GetFormat() const { return m_format; }
56
57   virtual void OnDestroyDevice();
58   virtual void OnCreateDevice();
59   virtual void OnLostDevice();
60   virtual void OnResetDevice();
61
62
63 private:
64   unsigned int GetMemoryUsage(unsigned int pitch) const;
65
66   void SaveTexture();
67   void RestoreTexture();
68
69   // creation parameters
70   UINT      m_width;
71   UINT      m_height;
72   UINT      m_mipLevels;
73   DWORD     m_usage;
74   D3DFORMAT m_format;
75   D3DPOOL   m_pool;
76   UINT      m_pitch;
77
78   // created texture
79   LPDIRECT3DTEXTURE9 m_texture;
80
81   // saved data
82   BYTE*     m_data;
83 };
84
85 typedef std::map<CStdString, CStdString> DefinesMap;
86
87 class CD3DEffect : public ID3DResource
88 {
89 public:
90   CD3DEffect();
91   virtual ~CD3DEffect();
92   bool Create(const CStdString &effectString, DefinesMap* defines);
93   void Release();
94   bool SetFloatArray(D3DXHANDLE handle, const float* val, unsigned int count);
95   bool SetMatrix(D3DXHANDLE handle, const D3DXMATRIX* mat);
96   bool SetTechnique(D3DXHANDLE handle);
97   bool SetTexture(D3DXHANDLE handle, CD3DTexture &texture);
98   bool Begin(UINT *passes, DWORD flags);
99   bool BeginPass(UINT pass);
100   bool EndPass();
101   bool End();
102
103   ID3DXEffect *Get() const { return m_effect; };
104
105   virtual void OnDestroyDevice();
106   virtual void OnCreateDevice();
107   virtual void OnLostDevice();
108   virtual void OnResetDevice();
109 private:
110   bool         CreateEffect();
111   CStdString   m_effectString;
112   ID3DXEffect  *m_effect;
113   DefinesMap   m_defines;
114 };
115
116 class CD3DVertexBuffer : public ID3DResource
117 {
118 public:
119   CD3DVertexBuffer();
120   virtual ~CD3DVertexBuffer();
121   bool Create(UINT length, DWORD usage, DWORD fvf, D3DPOOL pool);
122   void Release();
123   bool Lock(UINT offset, UINT size, void **data, DWORD flags);
124   bool Unlock();
125
126   LPDIRECT3DVERTEXBUFFER9 Get() const { return m_vertex; };
127
128   virtual void OnDestroyDevice();
129   virtual void OnCreateDevice();
130 private:
131   bool CreateVertexBuffer();
132   UINT    m_length;
133   DWORD   m_usage;
134   DWORD   m_fvf;
135   D3DPOOL m_pool;
136   LPDIRECT3DVERTEXBUFFER9 m_vertex;
137
138   // saved data
139   BYTE*   m_data;
140 };
141
142 #endif