Commit b4071b0b authored by Frédéric Larue's avatar Frédéric Larue

Functions added to the GPU module for best computation of GL pack/unpack alignment

parent 9241ccac
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#ifndef __GPU__ALIGNMENT_H__
#define __GPU__ALIGNMENT_H__
#include "GPUdefs.h"
#include <assert.h>
namespace GPU
{
inline unsigned int ChannelCount( GLenum format )
{
switch( format )
{
case GL_LUMINANCE: return 1;
case GL_RGB : return 3;
case GL_RGBA : return 4;
default : assert(false);
}
return 0;
}
inline unsigned int TypeSize( GLenum type )
{
switch( type )
{
case GL_UNSIGNED_BYTE : return sizeof(GLubyte );
case GL_BYTE : return sizeof(GLbyte );
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_SHORT : return sizeof(GLshort );
case GL_UNSIGNED_INT : return sizeof(GLuint );
case GL_INT : return sizeof(GLint );
case GL_FLOAT : return sizeof(GLfloat );
case GL_DOUBLE : return sizeof(GLdouble);
default : assert(false);
}
return 0;
}
inline unsigned int PixelSize( GLenum format, GLenum type )
{
return ChannelCount(format) * TypeSize(type);
}
inline void SetAlignment( GLenum alignParam, unsigned int stride )
{
static const int alignment[8] = { 8, 1, 2, 1, 4, 1, 2, 1 };
glPixelStorei( alignParam, alignment[stride & 7] );
}
inline void SetPackAlignment( unsigned int stride )
{
SetAlignment( GL_PACK_ALIGNMENT, stride );
}
inline void SetPackAlignment( unsigned int width,
GLenum format,
GLenum type )
{
SetPackAlignment( width * PixelSize(format, type) );
}
inline void SetUnpackAlignment( unsigned int stride )
{
SetAlignment( GL_UNPACK_ALIGNMENT, stride );
}
inline void SetUnpackAlignment( unsigned int width,
GLenum format,
GLenum type )
{
SetUnpackAlignment( width * PixelSize(format, type) );
}
}
#endif //__GPU__ALIGNMENT_H__
......@@ -12,6 +12,7 @@
#include "Alignment.h"
#include "Shader.h"
#include "VBO.h"
#include "FrameBuffer.h"
......
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