|
From: Tapio V. <aa...@us...> - 2009-12-08 22:46:45
|
Module: performous
Branch: dance
Commit: 212bc0f93468058a21c0533e18ab833f664eb70e
Author: Tapio Vierros <tap...@gm...>
Date: Tue Dec 8 23:52:54 2009 +0200
Avoid unnecessary rescaling in texture loading.
(Occured when non-pow2 tex extension is unavailable resulting in lowered quality in some cases.)
---
game/surface.cc | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/game/surface.cc b/game/surface.cc
index 19cd95d..b98eab7 100644
--- a/game/surface.cc
+++ b/game/surface.cc
@@ -25,9 +25,9 @@ float Dimensions::screenY() const {
namespace {
bool isPow2(unsigned int val) {
- unsigned int count = 0;
- do { if (val & 1) ++count; } while (val >>= 1);
- return val == 1;
+ if (val == 0) return false;
+ if ((val & (val-1)) == 0) return true; // From Wikipedia: Power_of_two
+ return false;
}
unsigned int nextPow2(unsigned int val) {
@@ -161,7 +161,8 @@ void Texture::load(unsigned int width, unsigned int height, pix::Format format,
PixFmt const& f = getPixFmt(format);
glPixelStorei(GL_UNPACK_SWAP_BYTES, f.swap);
// Load the data into texture
- if (checkExtension("GL_ARB_texture_non_power_of_two")) { // Use OpenGL 2.0 functionality
+ if ((isPow2(width) && isPow2(height)) ||
+ checkExtension("GL_ARB_texture_non_power_of_two")) { // Use OpenGL 2.0 functionality
glTexImage2D(type(), 0, GL_RGBA, width, height, 0, f.format, f.type, buffer);
} else {
// TODO: Test for OpenGL extension GL_ARB_texture_non_power_of_two and if not found,
|