Commit 9e90c81e authored by Robert Menzel's avatar Robert Menzel

Merge branch 'master' of...

Merge branch 'master' of ssh://beatrix.informatik.rwth-aachen.de/data/git-repository/acgl/libraries/acgl
parents 8fd50ec7 a579773f
cmake @ 801556b2
Subproject commit 2ab8ddba5b6c77730193e734bfb63cc45ac93e77
Subproject commit 801556b2e0dee07c9661b35d9187cfe5dc3f7267
......@@ -18,6 +18,7 @@
#include <cmath>
#include <limits>
#include <algorithm>
namespace ACGL{
namespace Math{
......
......@@ -20,8 +20,8 @@ enum ColorSpace
COLOR_SPACE_SRGB
};
/// Converts an OpenGL color format to an equivalent format of the given color space. If there is no matching format, the format is returned unchanged.
GLenum formatToColorSpace(GLenum _inputFormat, ColorSpace _colorSpace);
//! Recommends an OpenGL internal format for a given pair of format and color spaces
GLenum recommendedInternalFormat(GLenum _format, ColorSpace _colorSpace);
} // OpenGL
} // ACGL
......
......@@ -16,6 +16,7 @@
#include <ACGL/OpenGL/Data/GeometryData.hh>
#include <string>
#include <algorithm>
namespace ACGL{
namespace OpenGL{
......
......@@ -16,6 +16,7 @@
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Data/ColorSpace.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Math/Math.hh>
......@@ -29,51 +30,59 @@ class TextureData
// ========================================================================================================= \/
public:
TextureData(void)
: pData(NULL),
width(0),
height(0),
depth(0),
format(GL_RGBA),
: mData(NULL),
mWidth(0),
mHeight(0),
mDepth(0),
mFormat(GL_RGBA),
mType(GL_UNSIGNED_BYTE),
paddingBytesPerRow(0)
mPaddingBytesPerRow(0),
mColorSpace(COLOR_SPACE_AUTO_DETECT)
{}
virtual ~TextureData(void)
{
delete[] pData;
delete[] mData;
}
// ========================================================================================================= \/
// ================================================================================================= GETTERS \/
// ========================================================================================================= \/
public:
GLubyte* getData (void) const { return pData; }
//! pointer to the raw pixel data
GLubyte* getData() const { return mData; }
//! width in pixel
GLsizei getWidth (void) const { return width; }
//! width in pixels
GLsizei getWidth() const { return mWidth; }
//! height in pixel
GLsizei getHeight (void) const { return height; }
//! height in pixels
GLsizei getHeight() const { return mHeight; }
//! depth in pixel
GLsizei getDepth (void) const { return depth; }
//! depth in pixels
GLsizei getDepth() const { return mDepth; }
//! channels etc. e.g. GL_RGB
GLenum getFormat (void) const { return format; }
//! channels etc. (e.g. GL_RGB)
GLenum getFormat() const { return mFormat; }
//! data type (e.g. GL_BYTE)
GLenum getType (void) const { return mType; }
GLenum getType() const { return mType; }
//! each line can have a few bytes of padding, number of bytes is returned
GLsizei getPadding (void) const { return paddingBytesPerRow; }
GLsizei getPadding() const { return mPaddingBytesPerRow; }
//! the color space in which the data is represented
ColorSpace getColorSpace() const { return mColorSpace; }
//! in bytes
glm::uvec3 getSize (void) const { return glm::uvec3( width, height, depth ); }
glm::uvec3 getSize() const { return glm::uvec3( mWidth, mHeight, mDepth ); }
//! the byte alignment of each pixel row, e.g. 1,2,4,8 (bytes)
//! the byte alignment of each pixel row, (e.g. 1, 2, 4, 8 bytes)
GLsizei getPackAlignment()const;
//! 1,2,3 or 4 based on format
GLsizei getNumberOfChannels() const;
//! 1, 2, 3 or 4 based on format
GLsizei getNumberOfChannels() const;
//! A recommended value for the internalFormat enum of a Texture object. Based on the format, type and color space
GLenum getRecommendedInternalFormat() const;
//! flips the image vertically as some image formats have a different coordinate system as OpenGL has. (flip it upside down)
void flipVertically();
......@@ -91,32 +100,35 @@ public:
// ================================================================================================= SETTERS \/
// ========================================================================================================= \/
public:
//! _pData has to be created by new GLubyte[...] and will get deleted by this TextureData object!
void setData (GLubyte* _pData) { pData = _pData; }
void setWidth (GLsizei _width) { width = _width; }
void setHeight(GLsizei _height) { height = _height; }
void setDepth (GLsizei _depth) { depth = _depth; }
void setFormat(GLenum _format) { format = _format; }
void setType (GLenum _type) { mType = _type; }
void setPadding(GLsizei _padding){ paddingBytesPerRow = _padding; }
void setSize (const glm::uvec3 &_size) { width = _size.x; height = _size.y; depth = _size.z; }
//! mData has to be created by new GLubyte[...] and will get deleted by this TextureData object!
void setData (GLubyte* _data) { mData = _data; }
void setWidth (GLsizei _width) { mWidth = _width; }
void setHeight (GLsizei _height) { mHeight = _height; }
void setDepth (GLsizei _depth) { mDepth = _depth; }
void setFormat (GLenum _format) { mFormat = _format; }
void setType (GLenum _type) { mType = _type; }
void setPadding (GLsizei _padding) { mPaddingBytesPerRow = _padding; }
void setColorSpace(ColorSpace _colorSpace) { mColorSpace = _colorSpace; }
void setSize (const glm::uvec3& _size) { mWidth = _size.x; mHeight = _size.y; mDepth = _size.z; }
//! deletes the data attached to this object
void deleteData() { delete[] pData; pData = NULL; }
void deleteData() { delete[] mData; mData = NULL; }
private:
size_t getBytesPerScanline() const;
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
private:
size_t getBytesPerScanline() const;
GLubyte* pData;
GLsizei width;
GLsizei height;
GLsizei depth;
GLenum format; // channel types and count
GLenum mType; // data type
GLsizei paddingBytesPerRow; // number of padding bytes added per row: glReadPixel can read with padding and
// some image writers support/need this as well (e.g. QT)
GLubyte* mData;
GLsizei mWidth;
GLsizei mHeight;
GLsizei mDepth;
GLenum mFormat; // channel types and count
GLenum mType; // data type
GLsizei mPaddingBytesPerRow; // number of padding bytes added per row: glReadPixel can read with padding and
// some image writers support/need this as well (e.g. QT)
ColorSpace mColorSpace;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureData)
......
......@@ -29,7 +29,7 @@ namespace OpenGL{
///////////////////////////////////////////////////////////////////////////////////////////////////
//! functionpointer which can be used for generic Texture loading
typedef SharedTextureData (*TextureLoadFuncPtr)(const std::string&);
typedef SharedTextureData (*TextureLoadFuncPtr)(const std::string&, ColorSpace);
//! registers a functionpointer to be used for loading specified file types (E.G. provide a load function which loads compressed)
void registerTextureLoadFunction(std::vector<std::string> _endings, TextureLoadFuncPtr _function);
......@@ -38,7 +38,7 @@ void registerTextureLoadFunction(std::vector<std::string> _endings, TextureLoadF
void unregisterTextureLoadFunction(TextureLoadFuncPtr _function);
//! generic load function that will use one of the loading functions below based on the file ending
SharedTextureData loadTextureData(const std::string &_filename);
SharedTextureData loadTextureData(const std::string &_filename, ColorSpace _colorSpace = COLOR_SPACE_AUTO_DETECT);
//! generic save function that will use one of the saving functions below based on the file ending
bool saveTextureData(const SharedTextureData &_textureData, const std::string &_filename);
......@@ -59,21 +59,21 @@ inline bool saveScreenshotWithDate( const std::string& _fileEnding = "png" ) {
///////////////////////////////////////////////////////////////////////////////////////////////////
//! loads from a PNG using the simple lodepng library
SharedTextureData loadTextureDataFromLodepng(const std::string &_filename);
SharedTextureData loadTextureDataFromLodepng(const std::string& _filename, ColorSpace _colorSpace = COLOR_SPACE_AUTO_DETECT);
#ifdef ACGL_COMPILE_WITH_QT
//! loads various formats from the QT library
SharedTextureData loadTextureDataFromQT(const std::string &_filename);
SharedTextureData loadTextureDataFromQT(const std::string& _filename, ColorSpace _colorSpace = COLOR_SPACE_AUTO_DETECT);
#endif
//! loads RGBE aka Radiance files
SharedTextureData loadTextureDataFromRGBE(const std::string &_filename);
SharedTextureData loadTextureDataFromRGBE(const std::string& _filename, ColorSpace _colorSpace = COLOR_SPACE_AUTO_DETECT);
//! loads EXR / OpenEXR files iff the library is present AT RUNTIME (linux only)
SharedTextureData loadTextureDataFromEXR(const std::string &_filename);
SharedTextureData loadTextureDataFromEXR(const std::string& _filename, ColorSpace _colorSpace = COLOR_SPACE_AUTO_DETECT);
//! loads PNM / PPM files:
SharedTextureData loadTextureDataFromPNM(const std::string &_filename);
SharedTextureData loadTextureDataFromPNM(const std::string& _filename, ColorSpace _colorSpace = COLOR_SPACE_AUTO_DETECT);
///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save
......
......@@ -26,7 +26,7 @@ const char *debugSeverityName( GLenum _type );
void ACGLRegisterDefaultDebugCallback();
//! default debug callback
void ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLuint _id, GLenum _severity, GLsizei _length, const GLchar *_message, const void *_userParam);
void APIENTRY ACGL_KHR_default_debug_callback( GLenum _source, GLenum _type, GLuint _id, GLenum _severity, GLsizei _length, const GLchar *_message, const void *_userParam);
} // OpenGL
} // ACGL
......
......@@ -57,6 +57,7 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <algorithm>
#include <string>
#include <vector>
......
......@@ -312,6 +312,12 @@ public:
glMultiDrawElements( mMode, count, type, indices, primcount );
}
inline void drawRangeElements( GLuint start,
GLsizei count )
{
glDrawRangeElements( mMode, start, getIndexCount(), count, getIndexType(), nullptr);
}
#if (ACGL_OPENGL_VERSION >= 32)
inline void multiDrawElements( GLsizei *count, GLenum type, GLvoid **indices, GLsizei primcount, GLint *basevertex ) const
{
......
......@@ -48,6 +48,9 @@ namespace StringHelpers
//! strips a string of all leading and trailing characters out of a given list (but leaves the ones in between)
std::string stripOfCharacters( const std::string &_string, const std::string &_charsToStrip );
//! converts an int to a string but adds leading zeros (e.g. _maxPadding = 2, 1 -> 01)
std::string intToString( const int _number, const int _maxPadding = 0 );
//! Convert a primitive type to a string (e.g. string s = toString(1.5f)), also supports some GLM types (but not complete)
template<class T>
std::string toString(const T& _t);
......
The MIT License
Copyright (c) 2005 - 2012 G-Truc Creation
Copyright (c) 2005 - 2013 G-Truc Creation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
......@@ -445,7 +445,14 @@ namespace detail
# define GLM_RESTRICT __declspec(restrict)
# define GLM_RESTRICT_VAR __restrict
# define GLM_CONSTEXPR
#elif((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31))
#elif(GLM_COMPILER & GLM_COMPILER_INTEL)
# define GLM_DEPRECATED
# define GLM_ALIGN(x) __declspec(align(x))
# define GLM_ALIGNED_STRUCT(x) __declspec(align(x)) struct
# define GLM_RESTRICT
# define GLM_RESTRICT_VAR __restrict
# define GLM_CONSTEXPR
#elif(((GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_LLVM_GCC)) && (GLM_COMPILER >= GLM_COMPILER_GCC31)) || (GLM_COMPILER & GLM_COMPILER_CLANG))
# define GLM_DEPRECATED __attribute__((__deprecated__))
# define GLM_ALIGN(x) __attribute__((aligned(x)))
# define GLM_ALIGNED_STRUCT(x) struct __attribute__((aligned(x)))
......
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
......
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
......@@ -60,8 +60,8 @@ namespace detail
typedef T value_type;
protected:
value_type& elem (size_t i) { return (reinterpret_cast<value_type*>(_buffer))[i]; }
const value_type& elem (size_t i) const { return (reinterpret_cast<const value_type*>(_buffer))[i]; }
GLM_FUNC_QUALIFIER value_type& elem (size_t i) { return (reinterpret_cast<value_type*>(_buffer))[i]; }
GLM_FUNC_QUALIFIER const value_type& elem (size_t i) const { return (reinterpret_cast<const value_type*>(_buffer))[i]; }
// Use an opaque buffer to *ensure* the compiler doesn't call a constructor.
// The size 1 buffer is assumed to aligned to the actual members so that the
......@@ -77,19 +77,19 @@ namespace detail
template <typename T, typename V, int E0, int E1>
struct _swizzle_base1<T,V,E0,E1,-1,-2,2> : public _swizzle_base0<T,2>
{
V operator ()() const { return V(this->elem(E0), this->elem(E1)); }
GLM_FUNC_QUALIFIER V operator ()() const { return V(this->elem(E0), this->elem(E1)); }
};
template <typename T, typename V, int E0, int E1, int E2>
struct _swizzle_base1<T,V,E0,E1,E2,-1,3> : public _swizzle_base0<T,3>
{
V operator ()() const { return V(this->elem(E0), this->elem(E1), this->elem(E2)); }
GLM_FUNC_QUALIFIER V operator ()() const { return V(this->elem(E0), this->elem(E1), this->elem(E2)); }
};
template <typename T, typename V, int E0, int E1, int E2, int E3>
struct _swizzle_base1<T,V,E0,E1,E2,E3,4> : public _swizzle_base0<T,4>
{
V operator ()() const { return V(this->elem(E0), this->elem(E1), this->elem(E2), this->elem(E3)); }
GLM_FUNC_QUALIFIER V operator ()() const { return V(this->elem(E0), this->elem(E1), this->elem(E2), this->elem(E3)); }
};
// Internal class for implementing swizzle operators
......@@ -110,67 +110,73 @@ namespace detail
typedef VecType vec_type;
typedef ValueType value_type;
_swizzle_base2& operator= (const ValueType& t)
GLM_FUNC_QUALIFIER _swizzle_base2& operator= (const ValueType& t)
{
for (int i = 0; i < N; ++i)
(*this)[i] = t;
return *this;
}
_swizzle_base2& operator= (const VecType& that)
GLM_FUNC_QUALIFIER _swizzle_base2& operator= (const VecType& that)
{
struct op {
void operator() (value_type& e, value_type& t) { e = t; }
GLM_FUNC_QUALIFIER void operator() (value_type& e, value_type& t) { e = t; }
};
_apply_op(that, op());
return *this;
}
void operator -= (const VecType& that)
GLM_FUNC_QUALIFIER void operator -= (const VecType& that)
{
struct op {
void operator() (value_type& e, value_type& t) { e -= t; }
GLM_FUNC_QUALIFIER void operator() (value_type& e, value_type& t) { e -= t; }
};
_apply_op(that, op());
}
void operator += (const VecType& that)
GLM_FUNC_QUALIFIER void operator += (const VecType& that)
{
struct op {
void operator() (value_type& e, value_type& t) { e += t; }
GLM_FUNC_QUALIFIER void operator() (value_type& e, value_type& t) { e += t; }
};
_apply_op(that, op());
}
void operator *= (const VecType& that)
GLM_FUNC_QUALIFIER void operator *= (const VecType& that)
{
struct op {
void operator() (value_type& e, value_type& t) { e *= t; }
GLM_FUNC_QUALIFIER void operator() (value_type& e, value_type& t) { e *= t; }
};
_apply_op(that, op());
}
void operator /= (const VecType& that)
GLM_FUNC_QUALIFIER void operator /= (const VecType& that)
{
struct op {
void operator() (value_type& e, value_type& t) { e /= t; }
GLM_FUNC_QUALIFIER void operator() (value_type& e, value_type& t) { e /= t; }
};
_apply_op(that, op());
}
value_type& operator[] (size_t i)
GLM_FUNC_QUALIFIER value_type& operator[] (size_t i)
{
static const int offset_dst[4] = { E0, E1, E2, E3 };
#ifndef __CUDA_ARCH__
static
#endif
const int offset_dst[4] = { E0, E1, E2, E3 };
return this->elem(offset_dst[i]);
}
value_type operator[] (size_t i) const
GLM_FUNC_QUALIFIER value_type operator[] (size_t i) const
{
static const int offset_dst[4] = { E0, E1, E2, E3 };
#ifndef __CUDA_ARCH__
static
#endif
const int offset_dst[4] = { E0, E1, E2, E3 };
return this->elem(offset_dst[i]);
}
protected:
template <typename T>
void _apply_op(const VecType& that, T op)
GLM_FUNC_QUALIFIER void _apply_op(const VecType& that, T op)
{
// Make a copy of the data in this == &that.
// The copier should optimize out the copy in cases where the function is
......@@ -191,11 +197,14 @@ namespace detail
typedef ValueType value_type;
struct Stub {};
_swizzle_base2& operator= (Stub const &) {}
GLM_FUNC_QUALIFIER _swizzle_base2& operator= (Stub const &) { return *this; }
value_type operator[] (size_t i) const
GLM_FUNC_QUALIFIER value_type operator[] (size_t i) const
{
static const int offset_dst[4] = { E0, E1, E2, E3 };
#ifndef __CUDA_ARCH__
static
#endif
const int offset_dst[4] = { E0, E1, E2, E3 };
return this->elem(offset_dst[i]);
}
};
......@@ -207,7 +216,7 @@ namespace detail
using base_type::operator=;
operator VecType () const { return (*this)(); }
GLM_FUNC_QUALIFIER operator VecType () const { return (*this)(); }
};
//
......@@ -223,17 +232,17 @@ namespace detail
//
#define _GLM_SWIZZLE_VECTOR_BINARY_OPERATOR_IMPLEMENTATION(OPERAND) \
_GLM_SWIZZLE_TEMPLATE2 \
V operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const _GLM_SWIZZLE_TYPE2& b) \
GLM_FUNC_QUALIFIER V operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const _GLM_SWIZZLE_TYPE2& b) \
{ \
return a() OPERAND b(); \
} \
_GLM_SWIZZLE_TEMPLATE1 \
V operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const V& b) \
GLM_FUNC_QUALIFIER V operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const V& b) \
{ \
return a() OPERAND b; \
} \
_GLM_SWIZZLE_TEMPLATE1 \
V operator OPERAND ( const V& a, const _GLM_SWIZZLE_TYPE1& b) \
GLM_FUNC_QUALIFIER V operator OPERAND ( const V& a, const _GLM_SWIZZLE_TYPE1& b) \
{ \
return a OPERAND b(); \
}
......@@ -243,12 +252,12 @@ namespace detail
//
#define _GLM_SWIZZLE_SCALAR_BINARY_OPERATOR_IMPLEMENTATION(OPERAND) \
_GLM_SWIZZLE_TEMPLATE1 \
V operator OPERAND ( const _GLM_SWIZZLE_TYPE1& a, const T& b) \