xoreos  0.0.5
cubemapcombiner.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include <boost/scope_exit.hpp>
26 
27 #include "src/common/util.h"
28 #include "src/common/error.h"
29 
31 
32 namespace Graphics {
33 
35  BOOST_SCOPE_EXIT( (&sides) ) {
36  for (size_t i = 0; i < ARRAYSIZE(sides); i++)
37  delete sides[i];
38  } BOOST_SCOPE_EXIT_END
39 
40  _layerCount = ARRAYSIZE(sides);
41  _isCubeMap = true;
42 
43  const size_t mipMapCount = sides[0] ? sides[0]->getMipMapCount() : 0;
44  if (mipMapCount < 1)
45  throw Common::Exception("CubeMapCombiner: No mip maps");
46 
47  _compressed = sides[0]->isCompressed();
48  _hasAlpha = sides[0]->hasAlpha();
49 
50  _format = sides[0]->getFormat();
51  _formatRaw = sides[0]->getFormatRaw();
52  _dataType = sides[0]->getDataType();
53 
54  const int32 width = sides[0]->getMipMap(0).width;
55  const int32 height = sides[0]->getMipMap(0).height;
56 
57  for (size_t i = 0; i < ARRAYSIZE(sides); i++) {
58  if (!sides[i])
59  throw Common::Exception("CubeMapCombiner: Side %u is empty", (uint) i);
60 
61  if (sides[i]->getLayerCount() != 1)
62  throw Common::Exception("CubeMapCombiner: Side %u is has multiple layers", (uint) i);
63 
64  if (sides[i]->getMipMapCount() != mipMapCount)
65  throw Common::Exception("CubeMapCombiner: Mip map count mismatch (%u != %u)",
66  (uint) sides[i]->getMipMapCount(), (uint) mipMapCount);
67 
68  if ((width != sides[i]->getMipMap(0).width) || (height != sides[i]->getMipMap(0).height))
69  throw Common::Exception("CubeMapCombiner: Dimensions mismatch (%ux%u != %ux%u)",
70  width, height, sides[i]->getMipMap(0).width, sides[i]->getMipMap(0).height);
71 
72  if ((_compressed != sides[i]->isCompressed()) ||
73  (_hasAlpha != sides[i]->hasAlpha ()) ||
74  (_format != sides[i]->getFormat ()) ||
75  (_formatRaw != sides[i]->getFormatRaw()) ||
76  (_dataType != sides[i]->getDataType ()))
77  throw Common::Exception("CubeMapCombiner: Format mismatch (%u, %u, %u, %u, %u != %u, %u, %u, %u, %u)",
80  (uint) sides[i]->isCompressed(), (uint) sides[i]->hasAlpha(),
81  (uint) sides[i]->getFormat(), (uint) sides[i]->getFormatRaw(),
82  (uint) sides[i]->getDataType());
83  }
84 
85  _txi = sides[0]->getTXI();
86 
87  _mipMaps.resize(_layerCount * mipMapCount);
88 
89  for (size_t layer = 0; layer < _layerCount; layer++) {
90  for (size_t mipMap = 0; mipMap < mipMapCount; mipMap++) {
91  const size_t index = layer * mipMapCount + mipMap;
92 
93  _mipMaps[index] = new MipMap(sides[layer]->getMipMap(mipMap), this);
94  }
95  }
96 }
97 
99 }
100 
101 } // End of namespace Graphics
PixelFormat getFormat() const
Return the image data&#39;s general format.
Definition: decoder.cpp:176
bool _isCubeMap
Is this image a cube map? A cube map always needs to have 6 layers!
Definition: decoder.h:129
void resize(typename std::vector< T *>::size_type n, typename std::vector< T *>::value_type val=typename std::vector< T *>::value_type())
Definition: ptrvector.h:76
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
PixelDataType _dataType
Definition: decoder.h:124
size_t getLayerCount() const
Return the number of layers contained in the image.
Definition: decoder.cpp:194
Basic exceptions to throw.
PixelFormat _format
Definition: decoder.h:122
Utility templates and functions.
size_t _layerCount
Number of layers in this image.
Definition: decoder.h:127
A class creating a cube map by combining six images.
PixelFormatRaw getFormatRaw() const
Return the image data&#39;s raw format.
Definition: decoder.cpp:180
PixelFormatRaw _formatRaw
Definition: decoder.h:123
const MipMap & getMipMap(size_t mipMap, size_t layer=0) const
Return a mip map.
Definition: decoder.cpp:204
StackException Exception
Definition: error.h:59
CubeMapCombiner(ImageDecoder *(&sides)[6])
Take over this six images and combine them into a single cube map.
PixelDataType getDataType() const
Return the image data pixel&#39;s type.
Definition: decoder.cpp:184
A generic interface for image decoders.
Definition: decoder.h:48
size_t getMipMapCount() const
Return the number of mip maps contained in the image.
Definition: decoder.cpp:188
bool hasAlpha() const
Does the image data have alpha? .
Definition: decoder.cpp:172
bool isCompressed() const
Is the image data compressed?
Definition: decoder.cpp:168
unsigned int uint
Definition: types.h:211
int32_t int32
Definition: types.h:203