[make] don't install addon data of disabled addons
[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()  { return m_width; }
54   UINT GetHeight() { return m_height; }
55
56   virtual void OnDestroyDevice();
57   virtual void OnCreateDevice();
58   virtual void OnLostDevice();
59   virtual void OnResetDevice();
60
61
62 private:
63   unsigned int GetMemoryUsage(unsigned int pitch) const;
64
65   void SaveTexture();
66   void RestoreTexture();
67
68   // creation parameters
69   UINT      m_width;
70   UINT      m_height;
71   UINT      m_mipLevels;
72   DWORD     m_usage;
73   D3DFORMAT m_format;
74   D3DPOOL   m_pool;
75   UINT      m_pitch;
76
77   // created texture
78   LPDIRECT3DTEXTURE9 m_texture;
79
80   // saved data
81   BYTE*     m_data;
82 };
83
84 typedef std::map<CStdString, CStdString> DefinesMap;
85
86 class CD3DEffect : public ID3DResource
87 {
88 public:
89   CD3DEffect();
90   virtual ~CD3DEffect();
91   bool Create(const CStdString &effectString, DefinesMap* defines);
92   void Release();
93   bool SetFloatArray(D3DXHANDLE handle, const float* val, unsigned int count);
94   bool SetMatrix(D3DXHANDLE handle, const D3DXMATRIX* mat);
95   bool SetTechnique(D3DXHANDLE handle);
96   bool SetTexture(D3DXHANDLE handle, CD3DTexture &texture);
97   bool Begin(UINT *passes, DWORD flags);
98   bool BeginPass(UINT pass);
99   bool EndPass();
100   bool End();
101
102   ID3DXEffect *Get() const { return m_effect; };
103
104   virtual void OnDestroyDevice();
105   virtual void OnCreateDevice();
106   virtual void OnLostDevice();
107   virtual void OnResetDevice();
108 private:
109   bool         CreateEffect();
110   CStdString   m_effectString;
111   ID3DXEffect  *m_effect;
112   DefinesMap   m_defines;
113 };
114
115 class CD3DVertexBuffer : public ID3DResource
116 {
117 public:
118   CD3DVertexBuffer();
119   virtual ~CD3DVertexBuffer();
120   bool Create(UINT length, DWORD usage, DWORD fvf, D3DPOOL pool);
121   void Release();
122   bool Lock(UINT offset, UINT size, void **data, DWORD flags);
123   bool Unlock();
124
125   LPDIRECT3DVERTEXBUFFER9 Get() const { return m_vertex; };
126
127   virtual void OnDestroyDevice();
128   virtual void OnCreateDevice();
129 private:
130   bool CreateVertexBuffer();
131   UINT    m_length;
132   DWORD   m_usage;
133   DWORD   m_fvf;
134   D3DPOOL m_pool;
135   LPDIRECT3DVERTEXBUFFER9 m_vertex;
136
137   // saved data
138   BYTE*   m_data;
139 };
140
141 #endif