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 { 33 unsigned short int dwWidth; // Describes the width of the real texture area. Use lPitch to move between successive lines 34 unsigned short int dwHeight; // Describes the height of the real texture area 35 unsigned short int dwCreatedWidth; // Describes the width of the created texture area. Use lPitch to move between successive lines 36 unsigned short int dwCreatedHeight; // Describes the height of the created texture area 37 int lPitch; // Specifies the number of bytes on each row (not necessarily bitdepth*width/8) 38 void *lpSurface; // Pointer to the top left pixel of the image 39 } DrawInfo; 40 41 42 enum TextureFmt 43 { 44 TEXTURE_FMT_A8R8G8B8, 45 TEXTURE_FMT_A4R4G4B4, 46 TEXTURE_FMT_UNKNOWN, 47 }; 48 49 enum TextureUsage 50 { 51 AS_NORMAL, 52 AS_RENDER_TARGET, 53 AS_BACK_BUFFER_SAVE, 54 }; 55 56 class CTexture 57 { 58 public: 59 virtual ~CTexture(); 60 61 uint32_t m_dwWidth; // The requested Texture width. 62 uint32_t m_dwHeight; // The requested Texture height. 63 64 unsigned int m_dwCreatedTextureWidth; // What was actually created 65 unsigned int m_dwCreatedTextureHeight; 66 67 float m_fXScale; // = m_dwCorrectedWidth/m_dwWidth 68 float m_fYScale; // = m_dwCorrectedHeight/m_dwWidth 69 70 bool m_bScaledS; 71 bool m_bScaledT; 72 73 bool m_bClampedS; 74 bool m_bClampedT; 75 76 bool m_bIsEnhancedTexture; 77 78 TextureUsage m_Usage; 79 80 virtual void ScaleImageToSurface(bool scaleS, bool scaleT); 81 virtual void ClampImageToSurfaceS(); 82 virtual void ClampImageToSurfaceT(); 83 GetTexture()84 virtual LPRICETEXTURE GetTexture() { return m_pTexture; } 85 86 uint32_t GetPixelSize(); 87 TextureFmt GetSurfaceFormat(void); // Surface pixel format... SetOthersVariables(void)88 inline void SetOthersVariables(void) 89 { 90 m_bClampedS = m_bScaledS = (m_dwWidth == m_dwCreatedTextureWidth); 91 m_bClampedT = m_bScaledT = (m_dwHeight == m_dwCreatedTextureHeight); 92 } 93 94 // Provides access to "surface" 95 virtual bool StartUpdate(DrawInfo *di)=0; 96 virtual void EndUpdate(DrawInfo *di)=0; 97 98 virtual void RestoreAlphaChannel(void); // Restore Alpha channel from RGB channel 99 100 protected: 101 CTexture(uint32_t dwWidth, uint32_t dwHeight, TextureUsage usage); 102 LPRICETEXTURE m_pTexture; 103 TextureFmt m_dwTextureFmt; 104 }; 105 106 #endif 107 108