Commit ee55a3f9 authored by Philip Trettner's avatar Philip Trettner
Browse files

Merge branch 'experimental' of...

Merge branch 'experimental' of dawes.informatik.rwth-aachen.de:/data/git-repository/acgl/libraries/acgl into experimental
parents f29a25d7 ee341708
...@@ -21,7 +21,13 @@ namespace ACGL{ ...@@ -21,7 +21,13 @@ namespace ACGL{
namespace OpenGL{ namespace OpenGL{
//! loads the texture and creates mip maps //! loads the texture and creates mip maps
SharedTexture2D loadTexture2D( const std::string &_filename ); SharedTexture2D loadTexture2D(const std::string& _filename);
//! loads the texture including mipmaps from a DDS file
//! supports DXT1, DXT3 and DXT5 compression
SharedTexture2D loadTexture2DFromDDS (const std::string& _filename);
SharedTexture3D loadTexture3DFromDDS (const std::string& _filename);
SharedTextureCubeMap loadTextureCubeMapFromDDS(const std::string& _filename);
} }
} }
...@@ -36,7 +36,7 @@ SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool ...@@ -36,7 +36,7 @@ SharedVertexArrayObject loadVertexArrayObject(const std::string& _filename, bool
//! http://www.graphics.rwth-aachen.de/redmine/projects/acgl/wiki/Vao_File_Format //! http://www.graphics.rwth-aachen.de/redmine/projects/acgl/wiki/Vao_File_Format
//! A VAO file can contain several named EABs. Only the EAB whose name matches _eabName will be loaded //! A VAO file can contain several named EABs. Only the EAB whose name matches _eabName will be loaded
//! and attached to the VAO. If _eabName is left blank, the first defined EAB will be used. //! and attached to the VAO. If _eabName is left blank, the first defined EAB will be used.
SharedVertexArrayObject loadVertexArrayObjectVAO(const std::string& _filename, const std::string& _eabName = ""); SharedVertexArrayObject loadVertexArrayObjectFromVAO(const std::string& _filename, const std::string& _eabName = "");
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
// library specific save // library specific save
......
...@@ -159,73 +159,79 @@ ...@@ -159,73 +159,79 @@
#endif #endif
#else // ACGL_OPENGL_ES #else // ACGL_OPENGL_ES
// desktop: // desktop:
#if (defined(__APPLE__) || defined(MACOSX)) && defined(ACGL_OPENGL_PROFILE_FULL) #ifndef __glew_h__
#if ACGL_OPENGL_VERSION > 21 // if glew was already included, don't include anything else
#warning "On MacOS X only core profile is supported for OpenGL >= 3.2" // not the recommended way to do it but possible
#undef ACGL_OPENGL_PROFILE_FULL #if (defined(__APPLE__) || defined(MACOSX)) && defined(ACGL_OPENGL_PROFILE_FULL)
#define ACGL_OPENGL_PROFILE_CORE #if ACGL_OPENGL_VERSION > 21
#warning "On MacOS X only core profile is supported for OpenGL >= 3.2"
#undef ACGL_OPENGL_PROFILE_FULL
#define ACGL_OPENGL_PROFILE_CORE
#endif
#endif #endif
#endif #ifdef ACGL_USE_GLEW
#ifdef ACGL_USE_GLEW // if GLEW_STATIC is defined, GLEW gets linked statically. GLEW itself needs this define
// if GLEW_STATIC is defined, GLEW gets linked statically. GLEW itself needs this define // but for us its the sign that a local version of GLEW gets used, so we find it on
// but for us its the sign that a local version of GLEW gets used, so we find it on // GL/glew.h on every system.
// GL/glew.h on every system. #ifdef GLEW_STATIC
#ifdef GLEW_STATIC #include "GL/glew.h"
#include "GL/glew.h" #else
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/glew.h>
#else
#include <GL/glew.h>
#endif
#endif // !GLEW_LOCAL_PATH
#else #else
#if defined(__APPLE__) || defined(MACOSX) // use the internal loader:
#include <OpenGL/glew.h> #define ACGL_EXTENSION_LOADER_GLLOADGEN
// prevent other GL headers from getting included and redefine GL:
#define __gl3_h_
//
// Include the right header which has just what is needed to catch compatibility problems at compiletime.
// The selection could also be done with some preprocessor magic but it confuses most IDEs.
//
#ifdef ACGL_OPENGL_PROFILE_CORE
#if defined (ACGL_OPENGL_INCLUDE_LATEST_GL) || defined (ACGL_OPENGL_VERSION_43)
#include <ACGL/OpenGL/glloaders/gl_core_43.hh>
#elif defined (ACGL_OPENGL_VERSION_32)
#include <ACGL/OpenGL/glloaders/gl_core_32.hh>
#elif defined (ACGL_OPENGL_VERSION_33)
#include <ACGL/OpenGL/glloaders/gl_core_33.hh>
#elif defined (ACGL_OPENGL_VERSION_40)
#include <ACGL/OpenGL/glloaders/gl_core_40.hh>
#elif defined (ACGL_OPENGL_VERSION_41)
#include <ACGL/OpenGL/glloaders/gl_core_41.hh>
#elif defined (ACGL_OPENGL_VERSION_42)
#include <ACGL/OpenGL/glloaders/gl_core_42.hh>
#endif
#else #else
#include <GL/glew.h> // compatibility profile:
#endif #if defined (ACGL_OPENGL_INCLUDE_LATEST_GL) || defined (ACGL_OPENGL_VERSION_43)
#endif // !GLEW_LOCAL_PATH #include <ACGL/OpenGL/glloaders/gl_compatibility_43.hh>
#elif defined (ACGL_OPENGL_VERSION_21)
#include <ACGL/OpenGL/glloaders/gl_21.hh>
#elif defined (ACGL_OPENGL_VERSION_30)
#include <ACGL/OpenGL/glloaders/gl_30.hh>
#elif defined (ACGL_OPENGL_VERSION_31)
#include <ACGL/OpenGL/glloaders/gl_31.hh>
#elif defined (ACGL_OPENGL_VERSION_32)
#include <ACGL/OpenGL/glloaders/gl_compatibility_32.hh>
#elif defined (ACGL_OPENGL_VERSION_33)
#include <ACGL/OpenGL/glloaders/gl_compatibility_33.hh>
#elif defined (ACGL_OPENGL_VERSION_40)
#include <ACGL/OpenGL/glloaders/gl_compatibility_40.hh>
#elif defined (ACGL_OPENGL_VERSION_41)
#include <ACGL/OpenGL/glloaders/gl_compatibility_41.hh>
#elif defined (ACGL_OPENGL_VERSION_42)
#include <ACGL/OpenGL/glloaders/gl_compatibility_42.hh>
#endif
#endif // ACGL_OPENGL_PROFILE_CORE
#endif // ACGL_USE_GLEW
#else #else
// use the internal loader: #define ACGL_USE_GLEW
#define ACGL_EXTENSION_LOADER_GLLOADGEN #endif // __GLEW__
// prevent other GL headers from getting included and redefine GL:
#define __gl3_h_
//
// Include the right header which has just what is needed to catch compatibility problems at compiletime.
// The selection could also be done with some preprocessor magic but it confuses most IDEs.
//
#ifdef ACGL_OPENGL_PROFILE_CORE
#if defined (ACGL_OPENGL_INCLUDE_LATEST_GL) || defined (ACGL_OPENGL_VERSION_43)
#include <ACGL/OpenGL/glloaders/gl_core_43.hh>
#elif defined (ACGL_OPENGL_VERSION_32)
#include <ACGL/OpenGL/glloaders/gl_core_32.hh>
#elif defined (ACGL_OPENGL_VERSION_33)
#include <ACGL/OpenGL/glloaders/gl_core_33.hh>
#elif defined (ACGL_OPENGL_VERSION_40)
#include <ACGL/OpenGL/glloaders/gl_core_40.hh>
#elif defined (ACGL_OPENGL_VERSION_41)
#include <ACGL/OpenGL/glloaders/gl_core_41.hh>
#elif defined (ACGL_OPENGL_VERSION_42)
#include <ACGL/OpenGL/glloaders/gl_core_42.hh>
#endif
#else
// compatibility profile:
#if defined (ACGL_OPENGL_INCLUDE_LATEST_GL) || defined (ACGL_OPENGL_VERSION_43)
#include <ACGL/OpenGL/glloaders/gl_compatibility_43.hh>
#elif defined (ACGL_OPENGL_VERSION_21)
#include <ACGL/OpenGL/glloaders/gl_21.hh>
#elif defined (ACGL_OPENGL_VERSION_30)
#include <ACGL/OpenGL/glloaders/gl_30.hh>
#elif defined (ACGL_OPENGL_VERSION_31)
#include <ACGL/OpenGL/glloaders/gl_31.hh>
#elif defined (ACGL_OPENGL_VERSION_32)
#include <ACGL/OpenGL/glloaders/gl_compatibility_32.hh>
#elif defined (ACGL_OPENGL_VERSION_33)
#include <ACGL/OpenGL/glloaders/gl_compatibility_33.hh>
#elif defined (ACGL_OPENGL_VERSION_40)
#include <ACGL/OpenGL/glloaders/gl_compatibility_40.hh>
#elif defined (ACGL_OPENGL_VERSION_41)
#include <ACGL/OpenGL/glloaders/gl_compatibility_41.hh>
#elif defined (ACGL_OPENGL_VERSION_42)
#include <ACGL/OpenGL/glloaders/gl_compatibility_42.hh>
#endif
#endif // ACGL_OPENGL_PROFILE_CORE
#endif // ACGL_USE_GLEW
#endif // ACGL_OPENGL_ES #endif // ACGL_OPENGL_ES
#endif // ACGL_OPENGL_GL_HH #endif // ACGL_OPENGL_GL_HH
...@@ -110,6 +110,8 @@ public: ...@@ -110,6 +110,8 @@ public:
inline GLenum getInternalFormat (void) const { return mInternalFormat; } inline GLenum getInternalFormat (void) const { return mInternalFormat; }
inline GLint getMinFilter (void) const { return getParameterI(GL_TEXTURE_MIN_FILTER); } inline GLint getMinFilter (void) const { return getParameterI(GL_TEXTURE_MIN_FILTER); }
inline GLint getMagFilter (void) const { return getParameterI(GL_TEXTURE_MAG_FILTER); } inline GLint getMagFilter (void) const { return getParameterI(GL_TEXTURE_MAG_FILTER); }
inline GLint getBaseLevel (void) const { return getParameterI(GL_TEXTURE_BASE_LEVEL); }
inline GLint getMaxLevel (void) const { return getParameterI(GL_TEXTURE_MAX_LEVEL); }
inline GLint getMinLOD (void) const { return getParameterI(GL_TEXTURE_MIN_LOD); } inline GLint getMinLOD (void) const { return getParameterI(GL_TEXTURE_MIN_LOD); }
inline GLint getMaxLOD (void) const { return getParameterI(GL_TEXTURE_MAX_LOD); } inline GLint getMaxLOD (void) const { return getParameterI(GL_TEXTURE_MAX_LOD); }
inline GLfloat getLODBias (void) const { return getParameterF(GL_TEXTURE_LOD_BIAS); } inline GLfloat getLODBias (void) const { return getParameterF(GL_TEXTURE_LOD_BIAS); }
...@@ -156,6 +158,12 @@ public: ...@@ -156,6 +158,12 @@ public:
void setWrap(GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0); void setWrap(GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0);
#endif #endif
//! lowest defined mipmap level
void setBaseLevel( GLint _level = -1000 );
//! highest defined mipmap level
void setMaxLevel( GLint _level = 1000 );
//! lowest mipmap level to use //! lowest mipmap level to use
void setMinLOD( GLint _lod = -1000 ); void setMinLOD( GLint _lod = -1000 );
......
#ifndef __NV_DDS_H__
#define __NV_DDS_H__
#ifndef NVDDS_PROJECT //defined if building nv_dds library
#if _MSC_VER >= 1300
#ifdef _DLL
#pragma message("Note: including lib: nv_dds.lib\n")
#pragma comment(lib, "nv_dds.lib")
#else
#error "Your project doesn't use the Multithreaded DLL Runtime"
#endif
#endif
#endif
#if defined(WIN32)
# include <windows.h>
#endif
#include <string>
#include <deque>
#include <assert.h>
#if defined(MACOS)
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#else
#include <GL/gl.h>
#include <GL/glext.h>
#endif
namespace nv_dds
{
// surface description flags
const uint32_t DDSF_CAPS = 0x00000001l;
const uint32_t DDSF_HEIGHT = 0x00000002l;
const uint32_t DDSF_WIDTH = 0x00000004l;
const uint32_t DDSF_PITCH = 0x00000008l;
const uint32_t DDSF_PIXELFORMAT = 0x00001000l;
const uint32_t DDSF_MIPMAPCOUNT = 0x00020000l;
const uint32_t DDSF_LINEARSIZE = 0x00080000l;
const uint32_t DDSF_DEPTH = 0x00800000l;
// pixel format flags
const uint32_t DDSF_ALPHAPIXELS = 0x00000001l;
const uint32_t DDSF_FOURCC = 0x00000004l;
const uint32_t DDSF_RGB = 0x00000040l;
const uint32_t DDSF_RGBA = 0x00000041l;
// dwCaps1 flags
const uint32_t DDSF_COMPLEX = 0x00000008l;
const uint32_t DDSF_TEXTURE = 0x00001000l;
const uint32_t DDSF_MIPMAP = 0x00400000l;
// dwCaps2 flags
const uint32_t DDSF_CUBEMAP = 0x00000200l;
const uint32_t DDSF_CUBEMAP_POSITIVEX = 0x00000400l;
const uint32_t DDSF_CUBEMAP_NEGATIVEX = 0x00000800l;
const uint32_t DDSF_CUBEMAP_POSITIVEY = 0x00001000l;
const uint32_t DDSF_CUBEMAP_NEGATIVEY = 0x00002000l;
const uint32_t DDSF_CUBEMAP_POSITIVEZ = 0x00004000l;
const uint32_t DDSF_CUBEMAP_NEGATIVEZ = 0x00008000l;
const uint32_t DDSF_CUBEMAP_ALL_FACES = 0x0000FC00l;
const uint32_t DDSF_VOLUME = 0x00200000l;
// compressed texture types
const uint32_t FOURCC_DXT1 = 0x31545844l; //(MAKEFOURCC('D','X','T','1'))
const uint32_t FOURCC_DXT3 = 0x33545844l; //(MAKEFOURCC('D','X','T','3'))
const uint32_t FOURCC_DXT5 = 0x35545844l; //(MAKEFOURCC('D','X','T','5'))
struct DXTColBlock
{
uint16_t col0;
uint16_t col1;
uint8_t row[4];
};
struct DXT3AlphaBlock
{
uint16_t row[4];
};
struct DXT5AlphaBlock
{
uint8_t alpha0;
uint8_t alpha1;
uint8_t row[6];
};
struct DDS_PIXELFORMAT
{
uint32_t dwSize;
uint32_t dwFlags;
uint32_t dwFourCC;
uint32_t dwRGBBitCount;
uint32_t dwRBitMask;
uint32_t dwGBitMask;
uint32_t dwBBitMask;
uint32_t dwABitMask;
};
struct DDS_HEADER
{
uint32_t dwSize;
uint32_t dwFlags;
uint32_t dwHeight;
uint32_t dwWidth;
uint32_t dwPitchOrLinearSize;
uint32_t dwDepth;
uint32_t dwMipMapCount;
uint32_t dwReserved1[11];
DDS_PIXELFORMAT ddspf;
uint32_t dwCaps1;
uint32_t dwCaps2;
uint32_t dwReserved2[3];
};
enum TextureType
{
TextureNone,
TextureFlat, // 1D, 2D, and rectangle textures
Texture3D,
TextureCubemap
};
class CSurface
{
public:
CSurface();
CSurface(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
CSurface(const CSurface &copy);
CSurface &operator= (const CSurface &rhs);
virtual ~CSurface();
operator unsigned char*() const;
virtual void create(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
virtual void clear();
inline unsigned int get_width() const { return m_width; }
inline unsigned int get_height() const { return m_height; }
inline unsigned int get_depth() const { return m_depth; }
inline unsigned int get_size() const { return m_size; }
private:
unsigned int m_width;
unsigned int m_height;
unsigned int m_depth;
unsigned int m_size;
unsigned char *m_pixels;
};
class CTexture : public CSurface
{
friend class CDDSImage;
public:
CTexture();
CTexture(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
CTexture(const CTexture &copy);
CTexture &operator= (const CTexture &rhs);
~CTexture();
void create(unsigned int w, unsigned int h, unsigned int d, unsigned int imgsize, const unsigned char *pixels);
void clear();
inline const CSurface &get_mipmap(unsigned int index) const
{
assert(!m_mipmaps.empty());
assert(index < m_mipmaps.size());
return m_mipmaps[index];
}
inline void add_mipmap(const CSurface &mipmap)
{
m_mipmaps.push_back(mipmap);
}
inline unsigned int get_num_mipmaps() const { return (unsigned int)m_mipmaps.size(); }
protected:
inline CSurface &get_mipmap(unsigned int index)
{
assert(!m_mipmaps.empty());
assert(index < m_mipmaps.size());
return m_mipmaps[index];
}
private:
std::deque<CSurface> m_mipmaps;
};
class CDDSImage
{
public:
CDDSImage();
~CDDSImage();
void create_textureFlat(unsigned int format, unsigned int components, const CTexture &baseImage);
void create_texture3D(unsigned int format, unsigned int components, const CTexture &baseImage);
void create_textureCubemap(unsigned int format, unsigned int components,
const CTexture &positiveX, const CTexture &negativeX,
const CTexture &positiveY, const CTexture &negativeY,
const CTexture &positiveZ, const CTexture &negativeZ);
void clear();
bool load(std::string filename, bool flipImage = true);
bool save(std::string filename, bool flipImage = true);
/*
bool upload_texture1D();
bool upload_texture2D(unsigned int imageIndex = 0, GLenum target = GL_TEXTURE_2D);
bool upload_texture3D();
bool upload_textureRectangle();
bool upload_textureCubemap();
*/
inline operator unsigned char*()
{
assert(m_valid);
assert(!m_images.empty());
return m_images[0];
}
inline unsigned int get_width()
{
assert(m_valid);
assert(!m_images.empty());
return m_images[0].get_width();
}
inline unsigned int get_height()
{
assert(m_valid);
assert(!m_images.empty());
return m_images[0].get_height();
}
inline unsigned int get_depth()
{
assert(m_valid);
assert(!m_images.empty());
return m_images[0].get_depth();
}
inline unsigned int get_size()
{
assert(m_valid);
assert(!m_images.empty());
return m_images[0].get_size();
}
inline unsigned int get_num_mipmaps()
{
assert(m_valid);
assert(!m_images.empty());
return m_images[0].get_num_mipmaps();
}
inline const CSurface &get_mipmap(unsigned int index) const
{
assert(m_valid);
assert(!m_images.empty());
assert(index < m_images[0].get_num_mipmaps());
return m_images[0].get_mipmap(index);
}
inline const CTexture &get_cubemap_face(unsigned int face) const
{
assert(m_valid);
assert(!m_images.empty());
assert(m_images.size() == 6);
assert(m_type == TextureCubemap);
assert(face < 6);
return m_images[face];
}
inline unsigned int get_components() { return m_components; }
inline unsigned int get_format() { return m_format; }
inline TextureType get_type() { return m_type; }
inline bool is_compressed()
{
if ((m_format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ||
(m_format == GL_COMPRESSED_RGBA_S3TC_DXT3_EXT) ||
(m_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT))
return true;
else
return false;
}
inline bool is_cubemap() { return (m_type == TextureCubemap); }
inline bool is_volume() { return (m_type == Texture3D); }
inline bool is_valid() { return m_valid; }
inline bool is_dword_aligned()
{
assert(m_valid);
int dwordLineSize = get_dword_aligned_linesize(get_width(), m_components*8);
int curLineSize = get_width() * m_components;
return (dwordLineSize == curLineSize);
}
private:
unsigned int clamp_size(unsigned int size);
unsigned int size_dxtc(unsigned int width, unsigned int height);
unsigned int size_rgb(unsigned int width, unsigned int height);
inline void swap_endian(void *val);
// calculates 4-byte aligned width of image
inline unsigned int get_dword_aligned_linesize(unsigned int width, unsigned int bpp)
{
return ((width * bpp + 31) & -32) >> 3;
}
void flip(CSurface &surface);
void flip_texture(CTexture &texture);
void swap(void *byte1, void *byte2, unsigned int size);
void flip_blocks_dxtc1(DXTColBlock *line, unsigned int numBlocks);
void flip_blocks_dxtc3(DXTColBlock *line, unsigned int numBlocks);
void flip_blocks_dxtc5(DXTColBlock *line, unsigned int numBlocks);
void flip_dxt5_alpha(DXT5AlphaBlock *block);
void write_texture(const CTexture &texture, FILE *fp);
unsigned int m_format;
unsigned int m_components;
TextureType m_type;
bool m_valid;
std::deque<CTexture> m_images;
};
}
#endif
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
**********************************************************************/ **********************************************************************/
#include <ACGL/OpenGL/Data/TextureLoadStore.hh> #include <ACGL/OpenGL/Data/TextureLoadStore.hh>
#include <ACGL/Base/FileHelpers.hh>
using namespace ACGL; using namespace ACGL;
using namespace ACGL::OpenGL; using namespace ACGL::OpenGL;
...@@ -15,17 +16,25 @@ namespace OpenGL{ ...@@ -15,17 +16,25 @@ namespace OpenGL{
SharedTexture2D loadTexture2D( const std::string &_filename ) SharedTexture2D loadTexture2D( const std::string &_filename )
{ {
SharedTexture2D texture = SharedTexture2D( new Texture2D() ); std::string fileEnding = Base::FileHelpers::getFileEnding(_filename);
SharedTextureData data = loadTextureData( _filename ); if(fileEnding == "dds")
if (!data) { {
ACGL::Utils::error() << "can't create Texture from file " << _filename << " creating small empty texture instead." << std::endl; return loadTexture2DFromDDS(_filename);
texture->resize( glm::uvec2(4,4) );
} else {
texture->setImageData( loadTextureData( _filename ) );
} }
texture->generateMipmaps(); // calculates all remaining mipmap levels else
{
SharedTexture2D texture = SharedTexture2D( new Texture2D() );
SharedTextureData data = loadTextureData( _filename );
if (!data) {
ACGL::Utils::error() << "can't create Texture from file " << _filename << " creating small empty texture instead." << std::endl;
texture->resize( glm::uvec2(4,4) );
} else {
texture->setImageData( loadTextureData( _filename ) );
}
texture->generateMipmaps(); // calculates all remaining mipmap levels
return texture; return texture;
}
} }
} }
......
/***********************************************************************
* Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *