Commit c3d36361 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

npot texture support in TextureNode refs #2218

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18845 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 83fefc7a
...@@ -481,6 +481,26 @@ TextureNode::add_texture(const QImage& _image) ...@@ -481,6 +481,26 @@ TextureNode::add_texture(const QImage& _image)
if (5 * tex_h > 7 *h) // tex_h longer than sqrt(2)*h means too much waste of storage space (7/5 = sqrt(2)-1%) if (5 * tex_h > 7 *h) // tex_h longer than sqrt(2)*h means too much waste of storage space (7/5 = sqrt(2)-1%)
tex_h >>= 1; tex_h >>= 1;
// is size of input image a power of 2?
bool isNPOT = ( tex_w != _image.width() ) || ( tex_h != _image.height() );
// image has to be converted to gl format to avoid crash
QImage textureGL;
// eventually scale to pot image if no hw support / core in GL 2.0
if (!openGLVersion(2,0) && isNPOT)
{
// because texture will only be accessed proportionally by texture coordinates, aspect ratio is of no concern
textureGL = QGLWidget::convertToGLFormat ( _image.scaled( tex_w, tex_h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
}
else
{
// use npot texture
tex_w = _image.width();
tex_h = _image.height();
textureGL = QGLWidget::convertToGLFormat ( _image );
}
// enough texture mem? // enough texture mem?
glTexImage2D( GL_PROXY_TEXTURE_2D, 0, GL_RGBA, tex_w, tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 ); glTexImage2D( GL_PROXY_TEXTURE_2D, 0, GL_RGBA, tex_w, tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );
GLint testWidth; GLint testWidth;
...@@ -490,9 +510,6 @@ TextureNode::add_texture(const QImage& _image) ...@@ -490,9 +510,6 @@ TextureNode::add_texture(const QImage& _image)
return 0; // does not really help return 0; // does not really help
} }
// because texture will only be accessed proportionally by texture coordinates, aspect ratio is of no concern
QImage texture( QGLWidget::convertToGLFormat ( _image.scaled( tex_w, tex_h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ) );
textures_.resize(textures_.size()+1); // can't push_back, because glGenTextures needs a pointer textures_.resize(textures_.size()+1); // can't push_back, because glGenTextures needs a pointer
// Generate new texture // Generate new texture
...@@ -501,7 +518,7 @@ TextureNode::add_texture(const QImage& _image) ...@@ -501,7 +518,7 @@ TextureNode::add_texture(const QImage& _image)
activeTexture_ = int(textures_.size() - 1); activeTexture_ = int(textures_.size() - 1);
// Set the image // Set the image
setTextureDataGL(activeTexture_ ,GL_TEXTURE_2D,tex_w,tex_h,GL_RGBA,GL_UNSIGNED_BYTE,texture.bits()); setTextureDataGL(activeTexture_ ,GL_TEXTURE_2D,tex_w,tex_h,GL_RGBA,GL_UNSIGNED_BYTE,textureGL.bits());
// return the id of the new texture // return the id of the new texture
return textures_.back().id; return textures_.back().id;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment