Commit b8ab7bc8 authored by Janis Born's avatar Janis Born

code cleanups

parent 847e1ab1
......@@ -594,6 +594,32 @@ 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 )
{
......@@ -601,10 +627,7 @@ void TextureCubeMap::texImage2DCube( const SharedTextureData &_data, GLenum _cub
mWidth = _data->getWidth();
mHeight = _data->getHeight();
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexImage2D(
_cubeSide,
_mipmapLevel,
......@@ -614,17 +637,14 @@ void TextureCubeMap::texImage2DCube( const SharedTextureData &_data, GLenum _cub
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
void TextureCubeMap::texSubImage2DCube( const SharedTextureData &_data, GLenum _cubeSide, GLint _mipmapLevel, glm::ivec2 _offset )
{
bind();
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexSubImage2D(
_cubeSide,
_mipmapLevel,
......@@ -633,21 +653,15 @@ void TextureCubeMap::texSubImage2DCube( const SharedTextureData &_data, GLenum _
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
void TextureBase::texImage1D( const SharedTextureData &_data, GLint _mipmapLevel )
{
bind();
mWidth = _data->getWidth();
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexImage1D(
mTarget,
_mipmapLevel,
......@@ -657,8 +671,6 @@ void TextureBase::texImage1D( const SharedTextureData &_data, GLint _mipmapLevel
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
void TextureBase::texSubImage1D( const SharedTextureData &_data, GLint _mipmapLevel, uint32_t _offset )
......@@ -666,10 +678,7 @@ void TextureBase::texSubImage1D( const SharedTextureData &_data, GLint _mipmapLe
bind();
GLsizei w = std::min( mWidth, _data->getWidth() );
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexSubImage1D(
mTarget,
_mipmapLevel,
......@@ -678,8 +687,6 @@ void TextureBase::texSubImage1D( const SharedTextureData &_data, GLint _mipmapLe
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
void TextureBase::texImage2D( const SharedTextureData &_data, GLint _mipmapLevel )
......@@ -688,10 +695,7 @@ void TextureBase::texImage2D( const SharedTextureData &_data, GLint _mipmapLevel
mWidth = _data->getWidth();
mHeight = _data->getHeight();
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexImage2D(
mTarget,
_mipmapLevel,
......@@ -701,8 +705,6 @@ void TextureBase::texImage2D( const SharedTextureData &_data, GLint _mipmapLevel
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
void TextureBase::texSubImage2D( const SharedTextureData &_data, GLint _mipmapLevel, glm::uvec2 _offset )
......@@ -711,10 +713,7 @@ void TextureBase::texSubImage2D( const SharedTextureData &_data, GLint _mipmapLe
GLsizei w = std::min( mWidth, _data->getWidth() );
GLsizei h = std::max( std::min( mHeight, _data->getHeight() ), 1);
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexSubImage2D(
mTarget,
_mipmapLevel,
......@@ -723,8 +722,6 @@ void TextureBase::texSubImage2D( const SharedTextureData &_data, GLint _mipmapLe
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
......@@ -735,10 +732,7 @@ void TextureBase::texImage3D( const SharedTextureData &_data, GLint _mipmapLevel
mHeight = _data->getHeight();
mDepth = _data->getDepth();
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexImage3D(
mTarget,
_mipmapLevel,
......@@ -748,8 +742,6 @@ void TextureBase::texImage3D( const SharedTextureData &_data, GLint _mipmapLevel
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
void TextureBase::texSubImage3D( const SharedTextureData &_data, GLint _mipmapLevel, glm::uvec3 _offset )
......@@ -759,10 +751,7 @@ void TextureBase::texSubImage3D( const SharedTextureData &_data, GLint _mipmapLe
GLsizei h = std::max( std::min( mHeight, _data->getHeight() ), 1);
GLsizei d = std::max( std::min( mDepth, _data->getDepth() ), 1);
GLint previousUnpackAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &previousUnpackAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(_data->getPackAlignment(), 8));
ScopedUnpackAlignment alignment(_data->getPackAlignment());
glTexSubImage3D(
mTarget,
_mipmapLevel,
......@@ -771,7 +760,5 @@ void TextureBase::texSubImage3D( const SharedTextureData &_data, GLint _mipmapLe
_data->getFormat(),
_data->getType(),
_data->getData() );
glPixelStorei(GL_UNPACK_ALIGNMENT, previousUnpackAlignment);
}
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