Commit e5d3acc4 authored by Kersten Schuster's avatar Kersten Schuster
Browse files

Fix mipmapping.

parent 7e4edb5f
...@@ -320,13 +320,16 @@ Texture2D::Texture2D(GLenum unit) ...@@ -320,13 +320,16 @@ Texture2D::Texture2D(GLenum unit)
bool Texture2D::autogenerateMipMaps() 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 #ifdef GL_SGIS_generate_mipmap
if (supportsGenerateMipmap()) 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); parameter(GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
return true; return true;
} }
...@@ -349,13 +352,14 @@ void Texture2D::disableAutogenerateMipMaps() ...@@ -349,13 +352,14 @@ void Texture2D::disableAutogenerateMipMaps()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Texture2D::setData(GLint _level, void Texture2D::setData(GLint _level,
GLint _internalFormat, GLint _internalFormat,
GLsizei _width, GLsizei _width,
GLsizei _height, GLsizei _height,
GLenum _format, GLenum _format,
GLenum _type, GLenum _type,
const GLvoid* _data) { const GLvoid* _data,
bool _mipmaps) {
if (getUnit() == GL_NONE) if (getUnit() == GL_NONE)
setUnit(GL_TEXTURE0); setUnit(GL_TEXTURE0);
...@@ -367,6 +371,10 @@ void Texture2D::setData(GLint _level, ...@@ -367,6 +371,10 @@ void Texture2D::setData(GLint _level,
else else
glTexImage2D(GL_TEXTURE_2D, _level, _internalFormat, _width, _height, 0, _format, _type, _data); 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; width_ = _width;
height_ = _height; height_ = _height;
internalFormat_ = _internalFormat; internalFormat_ = _internalFormat;
...@@ -642,7 +650,7 @@ bool Texture2D::loadFromFile( const std::string& _filename, GLenum _minFilter, G ...@@ -642,7 +650,7 @@ bool Texture2D::loadFromFile( const std::string& _filename, GLenum _minFilter, G
QImage gltex = ACG::Util::convertToGLFormat(qtex); 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: ...@@ -412,7 +412,7 @@ public:
void disableAutogenerateMipMaps(); void disableAutogenerateMipMaps();
// initialize and set texture data via glTexImage2D // 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) // specify storage of texture (OpenGL 4.2)
// use setData with a nullptr instead if 4.2 is not available // use setData with a nullptr instead if 4.2 is not available
......
...@@ -224,8 +224,9 @@ void TextureNode::setTextureDataGL ( GLuint _textureId, ...@@ -224,8 +224,9 @@ void TextureNode::setTextureDataGL ( GLuint _textureId,
applyTextureParameters(_textureId); applyTextureParameters(_textureId);
bool mipmaps = mipmapping_globally_active_ && mipmapping_;
// Load the image // Load the image
if ( mipmapping_globally_active_ && mipmapping_ ) if ( mipmaps )
tex->autogenerateMipMaps(); tex->autogenerateMipMaps();
tex->setData( 0, // level tex->setData( 0, // level
...@@ -234,7 +235,8 @@ void TextureNode::setTextureDataGL ( GLuint _textureId, ...@@ -234,7 +235,8 @@ void TextureNode::setTextureDataGL ( GLuint _textureId,
_height, // height (2^m) _height, // height (2^m)
_format, // format _format, // format
_type, // type _type, // type
_data ); // pointer to pixels _data, // pointer to pixels
mipmaps); // mipmaps or not
// Unbind until we use it // Unbind until we use it
ACG::GLState::bindTexture(GL_TEXTURE_2D,0); 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