Skip to content

Commit 8ea66e5

Browse files
committed
Added virtual functions IsMipmapped, IsCubemap, GetLayers, and GetCubemapLayers to tBaseImage. This will allow simplification of client code that can now be unaware of the exact tImage type.
1 parent 72f23e8 commit 8ea66e5

File tree

7 files changed

+60
-67
lines changed

7 files changed

+60
-67
lines changed

Modules/Image/Inc/Image/tBaseImage.h

+31-37
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@
2020
namespace tImage
2121
{
2222
class tPicture;
23+
class tLayer;
24+
25+
26+
// These are hany for all image types that may contain cubemaps.
27+
enum tFaceIndex : uint32
28+
{
29+
tFaceIndex_Default,
30+
tFaceIndex_PosX = tFaceIndex_Default,
31+
tFaceIndex_NegX,
32+
tFaceIndex_PosY,
33+
tFaceIndex_NegY,
34+
tFaceIndex_PosZ,
35+
tFaceIndex_NegZ,
36+
tFaceIndex_NumFaces
37+
};
38+
39+
// Faces are always specified using a left-handed coord system even when using the OpenGL functions.
40+
enum tFaceFlag : uint32
41+
{
42+
tFaceFlag_PosX = 1 << tFaceIndex_PosX,
43+
tFaceFlag_NegX = 1 << tFaceIndex_NegX,
44+
tFaceFlag_PosY = 1 << tFaceIndex_PosY,
45+
tFaceFlag_NegY = 1 << tFaceIndex_NegY,
46+
tFaceFlag_PosZ = 1 << tFaceIndex_PosZ,
47+
tFaceFlag_NegZ = 1 << tFaceIndex_NegZ,
48+
tFaceFlag_All = 0xFFFFFFFF
49+
};
2350

2451

2552
// Abstract base class for all tImage types. At a minumum all tImageEXTs need to be able to be set from a single tFrame
@@ -83,23 +110,16 @@ class tBaseImage
83110
virtual tAlphaMode GetAlphaMode() const { return tAlphaMode::Unspecified; }
84111
virtual tChannelType GetChannelType() const { return tChannelType::Unspecified; }
85112

86-
// @wip
87-
#if 0
88113
// Not all derived classes need to support these next four functions.
89-
virtual bool IsMipmapped() const;
90-
virtual bool IsCubemap() const;
91-
92-
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
93-
// delete them when it's destructed. Returns the number of items appended to the list.
94-
virtual int GetLayers(tList<tLayer>&) const;
114+
virtual bool IsMipmapped() const { return false; }
115+
virtual bool IsCubemap() const { return false; }
95116

96117
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
97118
// delete them when it's destructed. Returns the number of items appended to the list.
98-
virtual int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const;
99-
#endif
119+
virtual int GetLayers(tList<tLayer>&) const { return 0; }
120+
virtual int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const { return 0; }
100121

101122
protected:
102-
103123
// Pretty sure all tImageXXX classes will find these useful.
104124
tPixelFormat PixelFormatSrc = tPixelFormat::Unspecified;
105125
tPixelFormat PixelFormat = tPixelFormat::Unspecified;
@@ -108,30 +128,4 @@ class tBaseImage
108128
};
109129

110130

111-
// These are hany for all image types that may contain cubemaps.
112-
enum tFaceIndex : uint32
113-
{
114-
tFaceIndex_Default,
115-
tFaceIndex_PosX = tFaceIndex_Default,
116-
tFaceIndex_NegX,
117-
tFaceIndex_PosY,
118-
tFaceIndex_NegY,
119-
tFaceIndex_PosZ,
120-
tFaceIndex_NegZ,
121-
tFaceIndex_NumFaces
122-
};
123-
124-
// Faces are always specified using a left-handed coord system even when using the OpenGL functions.
125-
enum tFaceFlag : uint32
126-
{
127-
tFaceFlag_PosX = 1 << tFaceIndex_PosX,
128-
tFaceFlag_NegX = 1 << tFaceIndex_NegX,
129-
tFaceFlag_PosY = 1 << tFaceIndex_PosY,
130-
tFaceFlag_NegY = 1 << tFaceIndex_NegY,
131-
tFaceFlag_PosZ = 1 << tFaceIndex_PosZ,
132-
tFaceFlag_NegZ = 1 << tFaceIndex_NegZ,
133-
tFaceFlag_All = 0xFFFFFFFF
134-
};
135-
136-
137131
}

Modules/Image/Inc/Image/tImageDDS.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ class tImageDDS : public tBaseImage
170170
bool IsStateSet(StateBit state) const { return (States & (1<<int(state))); }
171171
static const char* GetStateDesc(StateBit);
172172

173-
bool IsMipmapped() const { return (NumMipmapLayers > 1) ? true : false; }
174-
bool IsCubemap() const { return IsCubeMap; }
173+
bool IsMipmapped() const override { return (NumMipmapLayers > 1) ? true : false; }
174+
bool IsCubemap() const override { return IsCubeMap; }
175175

176176
// Returns true if the loaded dds was a 'modern' dds file and contained the DX10 FourCC in the header. Essentially
177177
// modern means the newer DXGI pixel formats were specified in the dds, Returns false for legacy dds files.
@@ -199,10 +199,9 @@ class tImageDDS : public tBaseImage
199199
bool StealLayers(tList<tLayer>&);
200200
tFrame* GetFrame(bool steal = true) override;
201201

202-
// @wip
203202
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
204203
// delete them when it's destructed. Returns the number of items appended to the list.
205-
bool GetLayers(tList<tLayer>&) const;
204+
int GetLayers(tList<tLayer>&) const override;
206205

207206
// Similar to StealLayers except it steals up to 6 layer-lists if the object is a cubemap. If the tImageDDS
208207
// is not a cubemap this function returns 0 and leaves the object (and list) unmodified. If you only steal a single
@@ -213,7 +212,7 @@ class tImageDDS : public tBaseImage
213212

214213
// Alternative to StealCubemapLayers. Gets the layers but you're not allowed to delete them, they're not yours. Make
215214
// sure the list you supply doesn't delete them when it's destructed.
216-
int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const;
215+
int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const override;
217216

218217
// You do not own the returned pointer.
219218
tLayer* GetLayer(int layerNum, int imageNum) const { return Layers[layerNum][imageNum]; }

Modules/Image/Inc/Image/tImageKTX.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class tImageKTX : public tBaseImage
167167
bool IsStateSet(StateBit state) const { return (States & (1<<int(state))); }
168168
static const char* GetStateDesc(StateBit);
169169

170-
bool IsMipmapped() const { return (NumMipmapLayers > 1) ? true : false; }
171-
bool IsCubemap() const { return IsCubeMap; }
170+
bool IsMipmapped() const override { return (NumMipmapLayers > 1) ? true : false; }
171+
bool IsCubemap() const override { return IsCubeMap; }
172172
bool RowsReversed() const { return RowReversalOperationPerformed; }
173173

174174
// The number of mipmap levels per image is always the same if there is more than one image in the direct texture
@@ -192,9 +192,9 @@ class tImageKTX : public tBaseImage
192192
bool StealLayers(tList<tLayer>&);
193193
tFrame* GetFrame(bool steal = true) override;
194194

195-
// Alternative to StealLayers. Gets the layers but you're not allowed to delete them, they're not yours. Make
196-
// sure the list you supply doesn't delete them when it's destructed.
197-
bool GetLayers(tList<tLayer>&) const;
195+
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
196+
// delete them when it's destructed. Returns the number of items appended to the list.
197+
int GetLayers(tList<tLayer>&) const override;
198198

199199
// Similar to StealLayers except it steals up to 6 layer-lists if the object is a cubemap. If the tImageKTX
200200
// is not a cubemap this function returns 0 and leaves the object (and list) unmodified. If you only steal a single
@@ -203,9 +203,9 @@ class tImageKTX : public tBaseImage
203203
// were populated.
204204
int StealCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All);
205205

206-
// Alternative to StealCubemapLayers. Gets the layers but you're not allowed to delete them, they're not yours. Make
207-
// sure the list you supply doesn't delete them when it's destructed.
208-
int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const;
206+
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
207+
// delete them when it's destructed. Returns the number of items appended to the list.
208+
int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const override;
209209

210210
// You do not own the returned pointer.
211211
tLayer* GetLayer(int layerNum, int imageNum) const { return Layers[layerNum][imageNum]; }

Modules/Image/Inc/Image/tImagePVR.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ class tImagePVR : public tBaseImage
172172
bool IsStateSet(StateBit state) const { return (States & (1<<int(state))); }
173173
static const char* GetStateDesc(StateBit);
174174

175-
bool IsMipmapped() const { return (NumMipmaps > 1) ? true : false; }
176-
bool IsCubemap() const { return (NumFaces == 6); }
175+
bool IsMipmapped() const override { return (NumMipmaps > 1) ? true : false; }
176+
bool IsCubemap() const override { return (NumFaces == 6); }
177177

178178
// Returns the pvr container format version. If the tImagePVR is not valid -1 is returned. If the tImagePVR is valid
179179
// but was not loaded from a .pvr file, 0 is returned. Otherwise 1 is returned for V1, 2 is returned for V2, and 3
@@ -203,9 +203,9 @@ class tImagePVR : public tBaseImage
203203
bool StealLayers(tList<tLayer>&);
204204
tFrame* GetFrame(bool steal = true) override;
205205

206-
// Alternative to StealLayers. Gets the layers but you're not allowed to delete them, they're not yours. Make
207-
// sure the list you supply doesn't delete them when it's destructed. Same rules regarding cubemaps.
208-
bool GetLayers(tList<tLayer>&) const;
206+
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
207+
// delete them when it's destructed. Returns the number of items appended to the list.
208+
int GetLayers(tList<tLayer>&) const override;
209209

210210
// Similar to StealLayers except it steals up to 6 layer-lists if the object is a cubemap. If the tImagePVR
211211
// is not a cubemap this function returns 0 and leaves the object (and list) unmodified. If you only steal a single
@@ -214,9 +214,9 @@ class tImagePVR : public tBaseImage
214214
// were populated.
215215
int StealCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All);
216216

217-
// Alternative to StealCubemapLayers. Gets the layers but you're not allowed to delete them, they're not yours. Make
218-
// sure the list you supply doesn't delete them when it's destructed.
219-
int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const;
217+
// Gets the layers but you're not allowed to delete them, they're not yours. Make sure the list you supply doesn't
218+
// delete them when it's destructed. Returns the number of items appended to the list.
219+
int GetCubemapLayers(tList<tLayer> layers[tFaceIndex_NumFaces], uint32 faceFlags = tFaceFlag_All) const override;
220220

221221
// You do not own the returned pointer.
222222
tLayer* GetLayer(int layerNum, int imageNum) const;

Modules/Image/Src/tImageDDS.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1017,15 +1017,15 @@ bool tImageDDS::StealLayers(tList<tLayer>& layers)
10171017
}
10181018

10191019

1020-
bool tImageDDS::GetLayers(tList<tLayer>& layers) const
1020+
int tImageDDS::GetLayers(tList<tLayer>& layers) const
10211021
{
10221022
if (!IsValid() || IsCubemap() || (NumImages <= 0))
1023-
return false;
1023+
return 0;
10241024

10251025
for (int mip = 0; mip < NumMipmapLayers; mip++)
10261026
layers.Append(Layers[mip][0]);
10271027

1028-
return true;
1028+
return NumMipmapLayers;
10291029
}
10301030

10311031

Modules/Image/Src/tImageKTX.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,15 @@ bool tImageKTX::StealLayers(tList<tLayer>& layers)
676676
}
677677

678678

679-
bool tImageKTX::GetLayers(tList<tLayer>& layers) const
679+
int tImageKTX::GetLayers(tList<tLayer>& layers) const
680680
{
681681
if (!IsValid() || IsCubemap() || (NumImages <= 0))
682-
return false;
682+
return 0;
683683

684684
for (int mip = 0; mip < NumMipmapLayers; mip++)
685685
layers.Append(Layers[mip][0]);
686686

687-
return true;
687+
return NumMipmapLayers;
688688
}
689689

690690

Modules/Image/Src/tImagePVR.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1325,15 +1325,15 @@ bool tImagePVR::StealLayers(tList<tLayer>& layers)
13251325
}
13261326

13271327

1328-
bool tImagePVR::GetLayers(tList<tLayer>& layers) const
1328+
int tImagePVR::GetLayers(tList<tLayer>& layers) const
13291329
{
13301330
if (!IsValid() || IsCubemap())
1331-
return false;
1331+
return 0;
13321332

13331333
for (int layer = 0; layer < NumLayers; layer++)
13341334
layers.Append(Layers[layer]);
13351335

1336-
return true;
1336+
return NumLayers;
13371337
}
13381338

13391339

0 commit comments

Comments
 (0)