]> icculus.org git repositories - btb/d2x.git/blob - arch/win32/include/texture.h
Allow use of 22K sound samples
[btb/d2x.git] / arch / win32 / include / texture.h
1 #ifndef __TEXTURE_H__
2 #define __TEXTURE_H__
3
4 struct CPaletteInfo
5 {
6         HRESULT Initialize ();
7         HRESULT Uninitialize ();
8
9         LONG GetShift (DWORD dwMask)
10         {
11                 ULONG cshft = 0;
12                 while (dwMask)
13                 {
14                         cshft += 1;
15                         dwMask >>= 1;
16                 }
17                 return cshft;
18         }
19
20         DWORD ShiftLeft (DWORD dwVal, LONG lShift)
21         {
22                 if (lShift > 0)
23                         return dwVal << lShift;
24                 else
25                         return dwVal >> (-lShift);
26         }
27
28         WORD Read16 (BYTE b)
29         {
30                 DWORD dwPal = *(DWORD*) &m_rgpe [b];
31                 WORD w;
32                 
33                 w  = ShiftLeft (dwPal, m_cshftR -  8) & m_mskR;
34                 w |= ShiftLeft (dwPal, m_cshftG - 16) & m_mskG;
35                 w |= ShiftLeft (dwPal, m_cshftB - 24) & m_mskB;
36
37                 return w;
38         }
39
40         BOOL IsPow2 () const { return m_bPow2; }
41         BOOL IsSquare () const { return m_bSquare; }
42
43         void GetPixelFormat (DDPIXELFORMAT *pddpf) { *pddpf = m_ddpfPixelFormat; }
44         BOOL IsIndexed () const { return m_ddpfPixelFormat.dwRGBBitCount == 8; }
45         void SetPaletteEntries (PALETTEENTRY rgpe [256]);
46         void GetPaletteEntries (PALETTEENTRY rgpe [256]);
47
48         LPDIRECTDRAWPALETTE GetPalette () { return m_spddpPalette; }
49         PALETTEENTRY ReadPalette (BYTE b) const { return m_rgpe [b]; }
50
51         DWORD m_mskR, m_mskG, m_mskB;
52         ULONG m_cshftR, m_cshftG, m_cshftB;
53         DDPIXELFORMAT m_ddpfPixelFormat;
54         BOOL m_bPow2, m_bSquare;
55         PALETTEENTRY m_rgpe [256];
56         CComPtr <IDirectDrawPalette> m_spddpPalette;
57 };
58
59 struct CTexture
60 {
61         HRESULT Initialize (BYTE *rgbSource, ULONG ulWidth, ULONG ulHeight, ULONG ulPitch);
62
63         HRESULT Allocate (CPaletteInfo *ppi);
64         HRESULT Free (void);
65
66         HRESULT Lock (void);
67         HRESULT Unlock (void);
68         void PlotPixel (ULONG ulX, ULONG ulY, BYTE b);
69         void SetBitmapData (BYTE *rgb, BOOL bRle);
70         void CopyFromSource (void);
71
72         void DirtyMemory (void) { m_bDirtyMemory = TRUE; }
73         BOOL isDirtyMemory (void) const { return m_bDirtyMemory; }
74         HRESULT CleanMemory (void);
75
76         void SetTransparent (BOOL bTransparent) { m_bTransparent = bTransparent; }
77         BOOL IsTransparent (void) const { return m_bTransparent; }
78
79         ULONG GetPixelCount () const { return m_ulHeight * m_ulWidth; }
80         void GetBitmapAdj (D3DVALUE *pflAdjX, D3DVALUE *pflAdjY)
81         {
82                 *pflAdjX = m_flAdjX;
83                 *pflAdjY = m_flAdjY;
84         }
85
86         IDirectDrawSurface4 *GetSurface () { return m_spddsMemory; }
87         IDirect3DTexture2 *GetTexture ();
88
89         ULONG m_ulWidth;
90         ULONG m_ulHeight;
91         ULONG m_ulWidthSource;
92         ULONG m_ulHeightSource;
93
94 protected:
95         CComPtr <IDirectDrawSurface4> m_spddsMemory;
96         CComQIPtr <IDirect3DTexture2, &IID_IDirect3DTexture2> m_spddtMemory;
97         ULONG m_ulPitchSource;
98         ULONG m_ulAge;
99         BYTE *m_rgbSource;
100
101         BOOL m_bDirtyMemory;
102         BOOL m_bTransparent;
103         BOOL m_bRle;
104         D3DVALUE m_flAdjX, m_flAdjY;
105
106 public:
107         static CPaletteInfo *m_ppi;
108         static DDSURFACEDESC2 s_ddsd;
109         static BOOL s_bLocked;
110 };
111
112 struct CTextureSet
113 {
114         HRESULT Initialize ();
115         HRESULT Uninitialize ();
116
117         CTexture *CreateTexture (BYTE *rgbSource, ULONG dx, ULONG dy, ULONG ulPitch);
118         void FreeTexture (CTexture *pTexture);
119         void SetPaletteEntries (PALETTEENTRY rgpe [256]);
120         void GetPaletteEntries (PALETTEENTRY rgpe [256]);
121         void DirtyTextures (void);
122
123         PALETTEENTRY ReadPalette (BYTE b) { return m_pi.ReadPalette (b); }
124         BOOL HasPalette () { return m_pi.IsIndexed (); }
125
126 protected:
127         typedef std::set <CTexture *> TEXTURE_SET;
128         TEXTURE_SET m_setTextures;
129         CPaletteInfo m_pi;
130 };
131
132
133
134 #endif  // __TEXTURE_H__