summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--o3d/core/cross/image_utils.cc4
-rw-r--r--o3d/core/cross/image_utils.h3
-rw-r--r--o3d/core/cross/image_utils_test.cc11
-rw-r--r--o3d/core/cross/pack.cc2
4 files changed, 19 insertions, 1 deletions
diff --git a/o3d/core/cross/image_utils.cc b/o3d/core/cross/image_utils.cc
index 5570d2b..8c1eecb 100644
--- a/o3d/core/cross/image_utils.cc
+++ b/o3d/core/cross/image_utils.cc
@@ -141,6 +141,10 @@ unsigned int GetNumComponentsForFormat(o3d::Texture::Format format) {
return 0;
}
+bool CanMakeMips(o3d::Texture::Format format) {
+ return GetNumComponentsForFormat(format) != 0;
+}
+
namespace {
static const float kEpsilon = 0.0001f;
diff --git a/o3d/core/cross/image_utils.h b/o3d/core/cross/image_utils.h
index e37d8eb..cb2f761 100644
--- a/o3d/core/cross/image_utils.h
+++ b/o3d/core/cross/image_utils.h
@@ -66,6 +66,9 @@ inline bool CheckImageDimensions(unsigned int width, unsigned int height) {
return width <= kMaxImageDimension && height <= kMaxImageDimension;
}
+// Returns whether or not we can make mips.
+bool CanMakeMips(Texture::Format format);
+
// Gets the number of mip-maps required for a full chain starting at
// width x height.
inline unsigned int ComputeMipMapCount(
diff --git a/o3d/core/cross/image_utils_test.cc b/o3d/core/cross/image_utils_test.cc
index b7ca6f6..58cebdf 100644
--- a/o3d/core/cross/image_utils_test.cc
+++ b/o3d/core/cross/image_utils_test.cc
@@ -72,6 +72,17 @@ TEST_F(ImageTest, ComputePOTSize) {
EXPECT_EQ(image::ComputePOTSize(4096), 4096u);
}
+TEST_F(ImageTest, CanMakeMips) {
+ EXPECT_TRUE(image::CanMakeMips(Texture::Format::XRGB8));
+ EXPECT_TRUE(image::CanMakeMips(Texture::Format::ARGB8));
+ EXPECT_TRUE(image::CanMakeMips(Texture::Format::ABGR16F));
+ EXPECT_TRUE(image::CanMakeMips(Texture::Format::R32F));
+ EXPECT_TRUE(image::CanMakeMips(Texture::Format::ABGR32F));
+ EXPECT_FALSE(image::CanMakeMips(Texture::Format::DXT1));
+ EXPECT_FALSE(image::CanMakeMips(Texture::Format::DXT3));
+ EXPECT_FALSE(image::CanMakeMips(Texture::Format::DXT5));
+};
+
static const uint8 kScaleUPDataNPOT[] = {
// This is a 3x3 image.
0x75, 0x58, 0x7b, 0x76,
diff --git a/o3d/core/cross/pack.cc b/o3d/core/cross/pack.cc
index a874c02..168d700 100644
--- a/o3d/core/cross/pack.cc
+++ b/o3d/core/cross/pack.cc
@@ -181,7 +181,7 @@ Texture* Pack::CreateTextureFromBitmaps(
O3D_ERROR(service_locator()) << "Bitmaps are not all the same dimensions";
return NULL;
}
- if (generate_mipmaps) {
+ if (generate_mipmaps && image::CanMakeMips(bitmap->format())) {
unsigned total_mips = image::ComputeMipMapCount(
bitmap->width(), bitmap->height());
// If we don't already have mips and we could use them then make them.