Commit 96dd053a authored by Janis Born's avatar Janis Born

add Texture::getImageData

parent 1139bbd0
......@@ -16,6 +16,7 @@
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Data/TextureData.hh>
#include <ACGL/Math/Math.hh>
#include <vector>
......@@ -349,6 +350,9 @@ public:
mType,
_pData);
}
//! Returns a TextureData objects holding the contents of the texture
SharedTextureData getImageData(GLint _lod = 0, GLint _type = 0) const;
//! Generate mipmaps from the current base texture (i.e. the texture from level 0)
//! Note: The function is not const, because it changes the corresponding GPU data
......
......@@ -74,3 +74,30 @@ void Texture::setAnisotropicFilter( GLfloat _sampleCount )
}
}
}
SharedTextureData Texture::getImageData(GLint _lod, GLint _type) const
{
if(_type == 0) _type = mType;
// determine the required buffer size to hold the requested LOD level
bind();
GLint width, height, depth;
glGetTexLevelParameteriv(mTarget, _lod, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(mTarget, _lod, GL_TEXTURE_HEIGHT, &height);
glGetTexLevelParameteriv(mTarget, _lod, GL_TEXTURE_DEPTH, &depth);
// fetch the image data
GLubyte* imageData = new GLubyte[width * height * getGLTypeSize(_type) * 4];
glGetTexImage(mTarget, _lod, GL_RGBA, _type, (GLvoid*)imageData);
// store the image data and meta information in a TextureData object
SharedTextureData dataObject = SharedTextureData(new TextureData());
dataObject->setWidth(width);
dataObject->setHeight(height);
dataObject->setDepth(depth);
dataObject->setType(_type);
dataObject->setFormat(GL_RGBA);
dataObject->setData(imageData); // dataObject will take care of freeing imageData
return dataObject;
}
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