summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics/opengl/gldevice.cpp6
-rw-r--r--src/math/func.h6
2 files changed, 11 insertions, 1 deletions
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index df64e34..86f92b2 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -417,12 +417,16 @@ bool CGLDevice::GetLightEnabled(int index)
Texture CGLDevice::CreateTexture(CImage *image, const TextureCreateParams &params)
{
ImageData *data = image->GetData();
- if (data == NULL)
+ if (data == nullptr)
{
GetLogger()->Error("Invalid texture data\n");
return Texture(); // invalid texture
}
+ Math::IntPoint size = image->GetSize();
+ if (!Math::IsPowerOfTwo(size.x) || !Math::IsPowerOfTwo(size.y))
+ GetLogger()->Warn("Creating non-power-of-2 texture (%dx%d)!\n", size.x, size.y);
+
return CreateTexture(data, params);
}
diff --git a/src/math/func.h b/src/math/func.h
index 413b5d9..83e8ca4 100644
--- a/src/math/func.h
+++ b/src/math/func.h
@@ -128,6 +128,12 @@ inline float Rand()
return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
}
+//! Returns whether \a x is an even power of 2
+inline bool IsPowerOfTwo(unsigned int x)
+{
+ return x && !(x & (x - 1));
+}
+
//! Returns the next nearest power of two to \a x
inline int NextPowerOfTwo(int x)
{