d07c171f |
1 | /* |
2 | Copyright (C) 2003 Rice1964 |
3 | |
4 | This program is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU General Public License |
6 | as published by the Free Software Foundation; either version 2 |
7 | of the License, or (at your option) any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | |
18 | */ |
19 | |
20 | |
21 | #ifndef __SURFACEHANDLER_H__ |
22 | #define __SURFACEHANDLER_H__ |
23 | |
24 | #include "typedefs.h" |
25 | |
26 | /////////////// Define a struct to use as |
27 | /////////////// storage for all the surfaces |
28 | /////////////// created so far. |
29 | class CTexture; |
30 | |
31 | typedef struct { |
32 | unsigned short int dwWidth; // Describes the width of the real texture area. Use lPitch to move between successive lines |
33 | unsigned short int dwHeight; // Describes the height of the real texture area |
34 | unsigned short int dwCreatedWidth; // Describes the width of the created texture area. Use lPitch to move between successive lines |
35 | unsigned short int dwCreatedHeight; // Describes the height of the created texture area |
36 | int lPitch; // Specifies the number of bytes on each row (not necessarily bitdepth*width/8) |
37 | void *lpSurface; // Pointer to the top left pixel of the image |
38 | } DrawInfo; |
39 | |
40 | |
41 | enum TextureFmt { |
42 | TEXTURE_FMT_A8R8G8B8, |
43 | TEXTURE_FMT_A4R4G4B4, |
44 | TEXTURE_FMT_UNKNOWN, |
45 | }; |
46 | |
47 | enum TextureUsage { |
48 | AS_NORMAL, |
49 | AS_RENDER_TARGET, |
50 | AS_BACK_BUFFER_SAVE, |
51 | }; |
52 | |
53 | class CTexture |
54 | { |
55 | public: |
56 | virtual ~CTexture(); |
57 | |
58 | uint32 m_dwWidth; // The requested Texture w/h |
59 | uint32 m_dwHeight; |
60 | |
61 | unsigned int m_dwCreatedTextureWidth; // What was actually created |
62 | unsigned int m_dwCreatedTextureHeight; |
63 | |
64 | float m_fXScale; // = m_dwCorrectedWidth/m_dwWidth |
65 | float m_fYScale; // = m_dwCorrectedHeight/m_dwWidth |
66 | |
67 | bool m_bScaledS; |
68 | bool m_bScaledT; |
69 | |
70 | bool m_bClampedS; |
71 | bool m_bClampedT; |
72 | |
73 | bool m_bIsEnhancedTexture; |
74 | |
75 | TextureUsage m_Usage; |
76 | |
77 | virtual void ScaleImageToSurface(bool scaleS=true, bool scaleT=true); |
78 | virtual void ClampImageToSurfaceS(); |
79 | virtual void ClampImageToSurfaceT(); |
80 | |
81 | virtual LPRICETEXTURE GetTexture() { return m_pTexture; } |
82 | |
83 | uint32 GetPixelSize(); |
84 | TextureFmt GetSurfaceFormat(void); // Surface pixel format... |
85 | inline void SetOthersVariables(void) |
86 | { |
87 | m_bClampedS = m_bScaledS = (m_dwWidth == m_dwCreatedTextureWidth); |
88 | m_bClampedT = m_bScaledT = (m_dwHeight == m_dwCreatedTextureHeight); |
89 | } |
90 | |
91 | // Provides access to "surface" |
92 | virtual bool StartUpdate(DrawInfo *di)=0; |
93 | virtual void EndUpdate(DrawInfo *di)=0; |
94 | |
95 | virtual void RestoreAlphaChannel(void); // Restore Alpha channel from RGB channel |
96 | |
97 | protected: |
98 | CTexture(uint32 dwWidth, uint32 dwHeight, TextureUsage usage = AS_NORMAL); |
99 | LPRICETEXTURE m_pTexture; |
100 | TextureFmt m_dwTextureFmt; |
101 | }; |
102 | |
103 | #endif |
104 | |