diff options
author | Alejandro Marzini | 2010-07-15 04:20:21 +0000 |
---|---|---|
committer | Alejandro Marzini | 2010-07-15 04:20:21 +0000 |
commit | 25f1980dad9348f8c0d81b3ead787c4e06af3ac1 (patch) | |
tree | a03d90e1b92101b76f9b436da5a4f746db771542 | |
parent | 36583ff888c745b2b39e8fcd51e9a4b74da33c49 (diff) | |
download | scummvm-rg350-25f1980dad9348f8c0d81b3ead787c4e06af3ac1.tar.gz scummvm-rg350-25f1980dad9348f8c0d81b3ead787c4e06af3ac1.tar.bz2 scummvm-rg350-25f1980dad9348f8c0d81b3ead787c4e06af3ac1.zip |
Optimized nextHigher2.
svn-id: r50907
-rw-r--r-- | backends/graphics/opengl/gltexture.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/backends/graphics/opengl/gltexture.cpp b/backends/graphics/opengl/gltexture.cpp index 2d6927543f..d609dd612f 100644 --- a/backends/graphics/opengl/gltexture.cpp +++ b/backends/graphics/opengl/gltexture.cpp @@ -41,17 +41,24 @@ static inline GLint xdiv(int numerator, int denominator) { return (numerator << 16) / denominator; } -static GLuint nextHigher2(GLuint k) { - if (k == 0) +static GLuint nextHigher2(GLuint v) { + if (v == 0) return 1; - GLuint nextPow = 1; - while (nextPow <= k) { - nextPow <<= 1; - } - return nextPow; + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + return v++; } void GLTexture::initGLExtensions() { + static bool inited = false; + + if (inited) + return; + const char* ext_string = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); Common::StringTokenizer tokenizer(ext_string, " "); @@ -60,6 +67,7 @@ void GLTexture::initGLExtensions() { if (token == "GL_ARB_texture_non_power_of_two") npot_supported = true; } + inited = true; } GLTexture::GLTexture(byte bpp, GLenum format, GLenum type) @@ -100,6 +108,12 @@ void GLTexture::allocBuffer(GLuint w, GLuint h) { // Already allocated a sufficiently large buffer return; + nextHigher2(0); + nextHigher2(100); + nextHigher2(1025); + nextHigher2(9999); + + if (npot_supported) { _textureWidth = w; _textureHeight = h; |