ScummVM API documentation
Texture.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_TEXTURE_H
29 #define HPL_TEXTURE_H
30 
31 #include "common/array.h"
32 #include "graphics/pixelformat.h"
33 #include "hpl1/engine/graphics/GraphicsTypes.h"
34 #include "hpl1/engine/graphics/LowLevelPicture.h"
35 #include "hpl1/engine/graphics/bitmap2D.h"
36 #include "hpl1/engine/resources/ResourceBase.h"
37 
38 namespace hpl {
39 
40 enum eTextureType {
41  eTextureType_Normal,
42  eTextureType_RenderTarget,
43  eTextureType_LastEnum
44 };
45 
46 //-----------------------------------------
47 
48 enum eTextureTarget {
49  eTextureTarget_1D,
50  eTextureTarget_2D,
51  eTextureTarget_Rect,
52  eTextureTarget_CubeMap,
53  eTextureTarget_3D,
54  eTextureTarget_LastEnum
55 };
56 
57 //-----------------------------------------
58 
59 enum eTextureWrap {
60  eTextureWrap_Repeat,
61  eTextureWrap_Clamp,
62  eTextureWrap_ClampToEdge,
63  eTextureWrap_ClampToBorder,
64  eTextureWrap_LastEnum
65 };
66 
67 //-----------------------------------------
68 
69 enum eTextureFilter {
70  eTextureFilter_Bilinear,
71  eTextureFilter_Trilinear,
72  eTextureFilter_LastEnum
73 };
74 
75 //-----------------------------------------
76 
77 enum eTextureAnimMode {
78  eTextureAnimMode_None,
79  eTextureAnimMode_Loop,
80  eTextureAnimMode_Oscillate,
81  eTextureAnimMode_LastEnum
82 };
83 
84 //-----------------------------------------
85 
86 class iLowLevelGraphics;
87 
88 class iTexture : public LowLevelPicture, public iResourceBase {
89 public:
90  iTexture(tString asName, tString asType, Graphics::PixelFormat *apPxlFmt, iLowLevelGraphics *apLowLevelGraphics,
91  eTextureType aType, bool abUseMipMaps, eTextureTarget aTarget,
92  bool abCompress = false)
93  : LowLevelPicture(asType), iResourceBase(asName, 0),
94  mType(aType), mbUseMipMaps(abUseMipMaps),
95  mpLowLevelGraphics(apLowLevelGraphics), mbCompress(abCompress),
96  mTarget(aTarget),
97  mWrapS(eTextureWrap_Repeat), mWrapT(eTextureWrap_Repeat), mWrapR(eTextureWrap_Repeat),
98  mfFrameTime(1), mAnimMode(eTextureAnimMode_Loop), mlSizeLevel(0), mvMinLevelSize(16, 16),
99  mfAnisotropyDegree(1.0f), mFilter(eTextureFilter_Bilinear), _bpp(apPxlFmt->bpp()) {}
100 
101  virtual ~iTexture() {}
102 
103  void SetSizeLevel(unsigned int alLevel) { mlSizeLevel = alLevel; }
104  void SetMinLevelSize(const cVector2l &avSize) { mvMinLevelSize = avSize; }
105 
106  bool reload() override { return false; }
107  void unload() override {}
108  void destroy() override {}
109 
115  virtual bool CreateFromBitmap(Bitmap2D *pBmp) = 0;
122  virtual bool CreateCubeFromBitmapVec(tBitmap2DVec *avBitmaps) = 0;
130  virtual bool Create(unsigned int alWidth, unsigned int alHeight, cColor aCol) = 0;
131 
132  virtual bool CreateAnimFromBitmapVec(tBitmap2DVec *avBitmaps) = 0;
133 
134  virtual bool CreateFromArray(unsigned char *apPixelData, int alChannels, const cVector3l &avSize) = 0;
135 
136  virtual void Update(float afTimeStep) = 0;
137 
138  virtual void SetPixels2D(int alLevel, const cVector2l &avOffset, const cVector2l &avSize,
139  eColorDataFormat aDataFormat, void *apPixelData) = 0;
140 
141  virtual void SetFilter(eTextureFilter aFilter) = 0;
142  virtual void SetAnisotropyDegree(float afX) = 0;
143  eTextureFilter GetFilter() { return mFilter; }
144  float GetAnisotropyDegree(float afX) { return mfAnisotropyDegree; }
145 
146  virtual float GetGamma() = 0;
147  virtual void SetGamma(float afGamma) = 0;
148  virtual int GetHandle() = 0;
149 
150  virtual bool hasAlpha() override { return false; }
151  uint32 getBpp() const override { return _bpp; }
152 
153  virtual void SetWrapS(eTextureWrap aMode) = 0;
154  virtual void SetWrapT(eTextureWrap aMode) = 0;
155  virtual void SetWrapR(eTextureWrap aMode) = 0;
156 
157  eTextureWrap GetWrapS() { return mWrapS; }
158  eTextureWrap GetWrapT() { return mWrapT; }
159  eTextureWrap GetWrapR() { return mWrapR; }
160 
161  void SetFrameTime(float afX) { mfFrameTime = afX; }
162  float GetFrameTime() { return mfFrameTime; }
163 
164  eTextureAnimMode GetAnimMode() { return mAnimMode; }
165  void SetAnimMode(eTextureAnimMode aMode) { mAnimMode = aMode; };
166 
167  eTextureType GetTextureType() { return mType; }
168  bool UsesMipMaps() { return mbUseMipMaps; }
169  void SetMipMapUse(bool abX) { mbUseMipMaps = abX; }
170  eTextureTarget GetTarget() { return mTarget; }
171 
172  virtual bool HasAnimation() = 0;
173  virtual void NextFrame() = 0;
174  virtual void PrevFrame() = 0;
175  virtual float GetT() = 0;
176  virtual float GetTimeCount() = 0;
177  virtual void SetTimeCount(float afX) = 0;
178  virtual int GetCurrentLowlevelHandle() = 0;
179 
180 protected:
181  eTextureType mType;
182  eTextureTarget mTarget;
183  eTextureWrap mWrapS;
184  eTextureWrap mWrapT;
185  eTextureWrap mWrapR;
186  eTextureFilter mFilter;
187  float mfAnisotropyDegree;
188 
189  bool mbUseMipMaps;
190  bool mbCompress;
191  iLowLevelGraphics *mpLowLevelGraphics;
192  float mfFrameTime;
193  eTextureAnimMode mAnimMode;
194  unsigned int mlSizeLevel;
195  uint32 _bpp;
196  cVector2l mvMinLevelSize;
197 };
198 
200 typedef tTextureVec::iterator tTextureVecIt;
201 
202 } // namespace hpl
203 
204 #endif // HPL_TEXTURE_H
Definition: AI.h:36
Definition: str.h:59
virtual bool Create(unsigned int alWidth, unsigned int alHeight, cColor aCol)=0
Definition: ResourceBase.h:36
Definition: array.h:52
Definition: pixelformat.h:138
Definition: LowLevelPicture.h:37
Definition: bitmap2D.h:42
Definition: Texture.h:88
iTexture * * iterator
Definition: array.h:54
bool reload() override
Definition: Texture.h:106
Definition: Vector3.h:38
void destroy() override
Definition: Texture.h:108
void unload() override
Definition: Texture.h:107
virtual bool CreateFromBitmap(Bitmap2D *pBmp)=0
Definition: Color.h:37
byte bpp() const
Definition: pixelformat.h:306
virtual bool CreateCubeFromBitmapVec(tBitmap2DVec *avBitmaps)=0
Definition: LowLevelGraphics.h:200