Commit e991a6d6 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'fix_mipmapping' into 'master'

Fix mipmapping.

See merge request !81
parents 15ebce8d e5d3acc4
......@@ -320,13 +320,16 @@ Texture2D::Texture2D(GLenum unit)
bool Texture2D::autogenerateMipMaps()
{
if(openGLVersion(3,0))
{
// From OpenGL 3.0, glGenerateMipmap is supported and we should use that
// but glGenerateMipmap must be called AFTER the data was uploaded.
return false;
}
#ifdef GL_SGIS_generate_mipmap
if (supportsGenerateMipmap())
{
//parameter based mipmap generation was removed in 3.1
if( openGLVersion(3,1))
glGenerateMipmap(GL_TEXTURE_2D);
else
parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
return true;
}
......@@ -349,13 +352,14 @@ void Texture2D::disableAutogenerateMipMaps()
//-----------------------------------------------------------------------------
void Texture2D::setData(GLint _level,
GLint _internalFormat,
GLsizei _width,
GLsizei _height,
void Texture2D::setData(GLint _level,
GLint _internalFormat,
GLsizei _width,
GLsizei _height,
GLenum _format,
GLenum _type,
const GLvoid* _data) {
const GLvoid* _data,
bool _mipmaps) {
if (getUnit() == GL_NONE)
setUnit(GL_TEXTURE0);
......@@ -367,6 +371,10 @@ void Texture2D::setData(GLint _level,
else
glTexImage2D(GL_TEXTURE_2D, _level, _internalFormat, _width, _height, 0, _format, _type, _data);
// If mip maps should not be built on cpu and the OpenGL version is high enough, we go the default way
if(_mipmaps && !buildMipsCPU_ && openGLVersion(3,0))
glGenerateMipmap(GL_TEXTURE_2D);
width_ = _width;
height_ = _height;
internalFormat_ = _internalFormat;
......@@ -642,7 +650,7 @@ bool Texture2D::loadFromFile( const std::string& _filename, GLenum _minFilter, G
QImage gltex = ACG::Util::convertToGLFormat(qtex);
setData(0, GL_RGBA, gltex.width(), gltex.height(), GL_RGBA, GL_UNSIGNED_BYTE, gltex.bits());
setData(0, GL_RGBA, gltex.width(), gltex.height(), GL_RGBA, GL_UNSIGNED_BYTE, gltex.bits(), mipmaps);
}
}
......
......@@ -412,7 +412,7 @@ public:
void disableAutogenerateMipMaps();
// initialize and set texture data via glTexImage2D
void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLenum _format, GLenum _type, const GLvoid* _data);
void setData(GLint _level, GLint _internalFormat, GLsizei _width, GLsizei _height, GLenum _format, GLenum _type, const GLvoid* _data, bool _mipmaps = false);
// specify storage of texture (OpenGL 4.2)
// use setData with a nullptr instead if 4.2 is not available
......
......@@ -224,8 +224,9 @@ void TextureNode::setTextureDataGL ( GLuint _textureId,
applyTextureParameters(_textureId);
bool mipmaps = mipmapping_globally_active_ && mipmapping_;
// Load the image
if ( mipmapping_globally_active_ && mipmapping_ )
if ( mipmaps )
tex->autogenerateMipMaps();
tex->setData( 0, // level
......@@ -234,7 +235,8 @@ void TextureNode::setTextureDataGL ( GLuint _textureId,
_height, // height (2^m)
_format, // format
_type, // type
_data ); // pointer to pixels
_data, // pointer to pixels
mipmaps); // mipmaps or not
// Unbind until we use it
ACG::GLState::bindTexture(GL_TEXTURE_2D,0);
......
Markdown is supported
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