Commit c27d804a authored by Janis Born's avatar Janis Born

set GL_PACK_ALIGNMENT to 1 when downloading textures via getTextureImageRAW

parent 18ceab66
......@@ -10,6 +10,53 @@
using namespace ACGL::OpenGL;
namespace
{
// Helper class to set the unpack alignment and reset it to the previous value
// at the end of the scope.
class ScopedUnpackAlignment
{
public:
ScopedUnpackAlignment(size_t _unpackAlignment)
{
// Save previous, set new
glGetIntegerv(GL_UNPACK_ALIGNMENT, &mPreviousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min<GLuint>(_unpackAlignment, 8));
}
~ScopedUnpackAlignment()
{
// Restore previous
glPixelStorei(GL_UNPACK_ALIGNMENT, mPreviousUnpackAlignment);
}
private:
GLint mPreviousUnpackAlignment;
};
class ScopedPackAlignment
{
public:
ScopedPackAlignment(size_t _packAlignment)
{
// Save previous, set new
glGetIntegerv(GL_PACK_ALIGNMENT, &mPreviousUnpackAlignment);
glPixelStorei(GL_PACK_ALIGNMENT, std::min<GLuint>(_packAlignment, 1));
}
~ScopedPackAlignment()
{
// Restore previous
glPixelStorei(GL_PACK_ALIGNMENT, mPreviousUnpackAlignment);
}
private:
GLint mPreviousUnpackAlignment;
};
}
void TextureBase::setMinFilter(GLint _value)
{
GLuint prevTexture = bindAndGetOldTexture();
......@@ -301,6 +348,8 @@ GLenum TextureBase::getCompatibleType( GLenum _internalFormat )
#ifndef ACGL_OPENGLES_VERSION_20
TextureData *TextureBase::getTextureImageRAW( const Image &_image, GLenum _format, GLenum _type ) const
{
ScopedPackAlignment alignment(1);
GLenum target = mTarget;
if (target == GL_TEXTURE_CUBE_MAP || target == GL_TEXTURE_CUBE_MAP_ARRAY) {
target = _image.cubeMapFace;
......@@ -595,33 +644,6 @@ bool TextureCubeMap::cubeSideIsValid( const GLenum _cubeSide ) const
return false;
}
namespace
{
// Helper class to set the unpack alignment and reset it to the previous value
// at the end of the scope.
class ScopedUnpackAlignment
{
public:
ScopedUnpackAlignment(size_t _unpackAlignment)
{
// Save previous, set new
glGetIntegerv(GL_UNPACK_ALIGNMENT, &mPreviousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min<GLuint>(_unpackAlignment, 8));
}
~ScopedUnpackAlignment()
{
// Restore previous
glPixelStorei(GL_UNPACK_ALIGNMENT, mPreviousUnpackAlignment);
}
private:
GLint mPreviousUnpackAlignment;
};
}
void TextureCubeMap::texImage2DCube( const SharedTextureData &_data, GLenum _cubeSide, GLint _mipmapLevel )
{
bind();
......
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