Skip to content
Snippets Groups Projects
Commit 0a93e8ed authored by Lars Krecklau's avatar Lars Krecklau
Browse files

* Added new structure to load textures from a file using a new data class as interface.

* Furthermore introduced a factory to register new file types (currently jpg and png).
* Added support for cube mapping

This commit closes #106, #107
parent bab20910
No related branches found
No related tags found
No related merge requests found
Showing
with 901 additions and 20 deletions
......@@ -43,6 +43,12 @@ private:
template<typename CLASS>
std::tr1::shared_ptr<CLASS> Singleton<CLASS>::spInstance = std::tr1::shared_ptr<CLASS>();
#define ACGL_SINGLETON(Class) \
friend class Base::Singleton< Class >; \
private:\
Class(const Class& ){ }\
void operator=(Class& ){ }
} // Base
} // ACGL
......
......@@ -27,7 +27,11 @@
#include <ACGL/OpenGL/Controller/ShaderProgramControlAutoFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramControlFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramObjectControl.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/TextureControl.hh>
#include <ACGL/OpenGL/Controller/TextureControlCubeMap.hh>
#include <ACGL/OpenGL/Controller/TextureControlFile.hh>
#include <ACGL/OpenGL/Controller/TextureControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/UniformControl.hh>
#include <ACGL/OpenGL/Controller/VertexBufferObjectControl.hh>
......
......@@ -9,7 +9,6 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/Resource/BasicUpdateController.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/GL.hh>
......@@ -23,7 +22,8 @@ class TextureControl : public Resource::BasicCreateController<Texture>
// ========================================================================================================= \/
public:
TextureControl(void)
: mWidth(0),
: Resource::BasicCreateController<Texture>(),
mWidth(0),
mHeight(0),
mDepth(0),
mInternalFormat(GL_RGBA),
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROLCUBEMAP_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROLCUBEMAP_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Data/TextureData.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class TextureControlCubeMap : public Resource::BasicCreateController<Texture>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureControlCubeMap(void)
: Resource::BasicCreateController<Texture>(),
mPositiveX(),
mNegativeX(),
mPositiveY(),
mNegativeY(),
mPositiveZ(),
mNegativeZ(),
mSize(0),
mInternalFormat(GL_RGBA),
mFormat(GL_RGBA),
mType(GL_UNSIGNED_BYTE),
mMinFilter(GL_LINEAR),
mMagFilter(GL_LINEAR),
mAnisotropicFilter(0.0),
mWrapS(GL_CLAMP_TO_EDGE),
mWrapT(GL_CLAMP_TO_EDGE),
mWrapR(GL_CLAMP_TO_EDGE)
{}
virtual ~TextureControlCubeMap(void) {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline TextureControlCubeMap& positiveX (const SharedTextureData& _data) { mPositiveX = _data; return *this; }
inline TextureControlCubeMap& negativeX (const SharedTextureData& _data) { mNegativeX = _data; return *this; }
inline TextureControlCubeMap& positiveY (const SharedTextureData& _data) { mPositiveY = _data; return *this; }
inline TextureControlCubeMap& negativeY (const SharedTextureData& _data) { mNegativeY = _data; return *this; }
inline TextureControlCubeMap& positiveZ (const SharedTextureData& _data) { mPositiveZ = _data; return *this; }
inline TextureControlCubeMap& negativeZ (const SharedTextureData& _data) { mNegativeZ = _data; return *this; }
inline TextureControlCubeMap& wrap (GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0)
{
mWrapS = _wrapS;
mWrapT = _wrapT;
mWrapR = _wrapR;
return *this;
}
inline TextureControlCubeMap& size (GLsizei _size) { mSize = _size; return *this; }
inline TextureControlCubeMap& internalFormat (GLenum _internalFormat) { mInternalFormat = _internalFormat; return *this; }
inline TextureControlCubeMap& format (GLenum _format) { mFormat = _format; return *this; }
inline TextureControlCubeMap& type (GLenum type) { mType = type; return *this; }
inline TextureControlCubeMap& minFilter (GLint _minFilter) { mMinFilter = _minFilter; return *this; }
inline TextureControlCubeMap& magFilter (GLint _magFilter) { mMagFilter = _magFilter; return *this; }
inline TextureControlCubeMap& anisotropicFilter (GLint _anisotropicFilter) { mAnisotropicFilter = _anisotropicFilter; return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedTexture create(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
SharedTextureData mPositiveX;
SharedTextureData mNegativeX;
SharedTextureData mPositiveY;
SharedTextureData mNegativeY;
SharedTextureData mPositiveZ;
SharedTextureData mNegativeZ;
GLsizei mSize;
GLenum mInternalFormat;
GLenum mFormat;
GLenum mType;
GLint mMinFilter;
GLint mMagFilter;
GLfloat mAnisotropicFilter;
GLenum mWrapS;
GLenum mWrapT;
GLenum mWrapR;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILE_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
namespace ACGL{
namespace OpenGL{
class TextureControlFile : public Resource::FileController<Texture>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureControlFile(const std::string& _filename);
TextureControlFile(const char* _filename);
template<typename CONTROLLER>
TextureControlFile(const CONTROLLER& _fileController)
: Resource::FileController<Texture>(_fileController.getFilename(), Base::Settings::the()->getFullTexturePath()),
mDataController(new CONTROLLER(_fileController)),
mMinFilter(0),
mMagFilter(0),
mAnisotropicFilter(0.0),
mWrapS(0),
mWrapT(0),
mWrapR(0)
{}
virtual ~TextureControlFile(void) {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline TextureControlFile& minFilter (GLint _minFilter) { mMinFilter = _minFilter; return *this; }
inline TextureControlFile& magFilter (GLint _magFilter) { mMagFilter = _magFilter; return *this; }
inline TextureControlFile& anisotropicFilter (GLfloat _anisotropicFilter) { mAnisotropicFilter = _anisotropicFilter; return *this; }
inline TextureControlFile& wrap (GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0)
{
mWrapS = _wrapS;
mWrapT = _wrapT;
mWrapR = _wrapR;
return *this;
}
private:
bool load(SharedTexture& texture);
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedTexture create(void);
virtual bool update(SharedTexture& texture);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
SharedTextureDataControlFile mDataController;
GLint mMinFilter;
GLint mMagFilter;
GLfloat mAnisotropicFilter;
GLenum mWrapS;
GLenum mWrapT;
GLenum mWrapR;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILE_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Data/TextureData.hh>
namespace ACGL{
namespace OpenGL{
class TextureDataControlFile : public Resource::FileController<TextureData>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureDataControlFile(const std::string& _filename)
: Resource::FileController<TextureData>(_filename, Base::Settings::the()->getFullTexturePath())
{}
virtual ~TextureDataControlFile(void) {}
// ====================================================================================================== \/
// ============================================================================================ INTERFACE \/
// ====================================================================================================== \/
private:
virtual bool load(SharedTextureData& texture) const = 0;
// ====================================================================================================== \/
// ============================================================================================= OVERRIDE \/
// ====================================================================================================== \/
public:
virtual SharedTextureData create(void);
virtual bool update(SharedTextureData& _texture);
};
ACGL_SHARED_TYPEDEF(TextureDataControlFile)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEFACTORY_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEFACTORY_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Singleton.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <map>
#include <string>
namespace ACGL{
namespace OpenGL{
class TextureDataControlFileFactory : public Base::Singleton< TextureDataControlFileFactory >
{
ACGL_SINGLETON(TextureDataControlFileFactory)
// ========================================================================================================= \/
// ================================================================================================ TYPEDEFS \/
// ========================================================================================================= \/
private:
typedef SharedTextureDataControlFile (*factoryCreate)(const std::string&);
typedef std::map<std::string, factoryCreate> FactoryMap;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
protected:
TextureDataControlFileFactory(void) : mRegisteredTypes(0), mFactoryMap() {}
public:
virtual ~TextureDataControlFileFactory(void) {}
// ========================================================================================================= \/
// ================================================================================================= METHODS \/
// ========================================================================================================= \/
public:
int_t getRegisteredTypes(void) const { return mRegisteredTypes; }
int_t registerType(const std::string& _type, factoryCreate _creator);
SharedTextureDataControlFile create(const std::string& _filename) const;
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
private:
int_t mRegisteredTypes;
FactoryMap mFactoryMap;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEFACTORY_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEJPG_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEJPG_HH
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
namespace ACGL{
namespace OpenGL{
class TextureDataControlFileJPG : public TextureDataControlFile
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureDataControlFileJPG(const std::string& _filename)
: TextureDataControlFile(_filename)
{}
virtual ~TextureDataControlFileJPG(void) {}
static SharedTextureDataControlFile creator(const std::string& _filename) { return SharedTextureDataControlFile(new TextureDataControlFileJPG(_filename)); }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
private:
virtual bool load(SharedTextureData& texture) const;
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
private:
static int_t sTypeID;
};
ACGL_SHARED_TYPEDEF(TextureDataControlFileJPG)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEJPG_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNG_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNG_HH
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
namespace ACGL{
namespace OpenGL{
class TextureDataControlFilePNG : public TextureDataControlFile
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureDataControlFilePNG(const std::string& _filename)
: TextureDataControlFile(_filename)
{}
virtual ~TextureDataControlFilePNG(void) {}
static SharedTextureDataControlFile creator(const std::string& _filename) { return SharedTextureDataControlFile(new TextureDataControlFilePNG(_filename)); }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
private:
virtual bool load(SharedTextureData& texture) const;
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
private:
static int_t sTypeID;
};
ACGL_SHARED_TYPEDEF(TextureDataControlFilePNG)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPNG_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_DATA_TEXTUREDATA_HH
#define ACGL_OPENGL_DATA_TEXTUREDATA_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class TextureData
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureData(void)
: pData(NULL),
width(0),
height(0),
depth(0),
format(GL_RGBA),
type(GL_UNSIGNED_BYTE)
{}
virtual ~TextureData(void)
{
delete[] pData;
}
// ========================================================================================================= \/
// ================================================================================================= GETTERS \/
// ========================================================================================================= \/
public:
GLubyte* getData (void) const { return pData; }
GLsizei getWidth (void) const { return width; }
GLsizei getHeight (void) const { return height; }
GLsizei getDepth (void) const { return depth; }
GLenum getFormat (void) const { return format; }
GLenum getType (void) const { return type; }
// ========================================================================================================= \/
// ================================================================================================= SETTERS \/
// ========================================================================================================= \/
public:
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) { type = _type; }
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
private:
GLubyte* pData;
GLsizei width;
GLsizei height;
GLsizei depth;
GLenum format;
GLenum type;
};
ACGL_SHARED_TYPEDEF(TextureData)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_DATA_TEXTUREDATA_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_INITSTATICFILETYPES_HH
#define ACGL_OPENGL_INITSTATICFILETYPES_HH
namespace ACGL{
namespace OpenGL{
/*
* Here is a citation from stack overflow, why we need the initStaticFileTypes function:
*
* If you have an object in a static library that is not EXPLICITLY used in the application.
* Then the linker will not pull that object from the lib into the application.
*
* There is a big difference between static and dynamic libraries.
*
* Dynamic Library:
* At compile time nothing is pulled from the dynamic library. Extra code is added to
* explicitly load and resolve the symbols at run-time. At run time the whole library is
* loaded and thus object initializers are called (though when is implementation detail).
*
* Static libraries are handled very differently:
* When you link against a static library it pulls all the items that are not defined in
* application that are defined in the library into the application. This is repeated until
* there are no more dependencies that the library can resolve. The side effect of this is
* that objects/functions not explicitly used are not pulled form the library (thus global
* variables that are not directly accessed will not be pulled).
*/
void initStaticFileTypes(void);
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_INITSTATICFILETYPES_HH
......@@ -40,6 +40,9 @@ typedef Resource::NameManager<ShaderProgramObject> ShaderProgramObjectNameManage
typedef Resource::NameManager<Texture> TextureNameManager;
typedef Resource::FileManager<Texture> TextureFileManager;
typedef Resource::NameManager<TextureData> TextureDataNameManager;
typedef Resource::FileManager<TextureData> TextureDataFileManager;
typedef Resource::NameManager<Uniform1f> Uniform1fNameManager;
typedef Resource::NameManager<Uniform2f> Uniform2fNameManager;
typedef Resource::NameManager<Uniform3f> Uniform3fNameManager;
......
......@@ -259,25 +259,58 @@ public:
setImageData2D( _pData );
}
//! Set texture data
//! Set texture data using the specified target for uploading the data
inline void setImageData2D(const GLvoid* _pData = NULL)
{
glBindTexture(mTarget, mObjectName);
glTexImage2D(
mTarget,
0,
mInternalFormat,
mWidth,
mHeight,
0,//no border
mFormat,
mType,
_pData);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
setImageData2D(mTarget, mFormat, mType, _pData);
}
//! Set format for the cube maps that are uploaded
inline void setCubeMapFormat(
GLsizei _size,
GLenum _internalFormat)
{
mWidth = _size;
mHeight = _size;
mDepth = 0;
mInternalFormat = _internalFormat;
}
//! Set format for the cube maps that are uploaded including a default format and type
inline void setCubeMapFormat(
GLsizei _size,
GLenum _internalFormat,
GLenum _format,
GLenum _type)
{
mWidth = _size;
mHeight = _size;
mDepth = 0;
mInternalFormat = _internalFormat;
mFormat = _format;
mType = _type;
}
//! Set texture data for cube maps using the default format and type
/// @{
inline void setImageDataCubeMapPositiveX(const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, mFormat, mType, _pData); }
inline void setImageDataCubeMapNegativeX(const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, mFormat, mType, _pData); }
inline void setImageDataCubeMapPositiveY(const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, mFormat, mType, _pData); }
inline void setImageDataCubeMapNegativeY(const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, mFormat, mType, _pData); }
inline void setImageDataCubeMapPositiveZ(const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, mFormat, mType, _pData); }
inline void setImageDataCubeMapNegativeZ(const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, mFormat, mType, _pData); }
/// @}
//! Set texture data for cube maps using a specific upload format and type per face
/// @{
inline void setImageDataCubeMapPositiveX(GLenum _format, GLenum _type, const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, _format, _type, _pData); }
inline void setImageDataCubeMapNegativeX(GLenum _format, GLenum _type, const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, _format, _type, _pData); }
inline void setImageDataCubeMapPositiveY(GLenum _format, GLenum _type, const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, _format, _type, _pData); }
inline void setImageDataCubeMapNegativeY(GLenum _format, GLenum _type, const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, _format, _type, _pData); }
inline void setImageDataCubeMapPositiveZ(GLenum _format, GLenum _type, const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, _format, _type, _pData); }
inline void setImageDataCubeMapNegativeZ(GLenum _format, GLenum _type, const GLvoid* _pData = NULL) { setImageData2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, _format, _type, _pData); }
/// @}
//! Set texture data for some mipmap level.
/*!
If you upload a texture for a higher mipmap level, the function will automatically determine
......@@ -372,6 +405,26 @@ public:
openGLRareError();
}
private:
//! Set texture data
inline void setImageData2D(GLenum _uploadTarget, GLenum _uploadFormat, GLenum _uploadType, const GLvoid* _pData = NULL)
{
glBindTexture(mTarget, mObjectName);
glTexImage2D(
_uploadTarget,
0,
mInternalFormat,
mWidth,
mHeight,
0,//no border
_uploadFormat,
_uploadType,
_pData);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
}
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
......
......@@ -21,7 +21,7 @@ namespace Resource{
template<typename RESOURCE>
class FileManager : public Base::Singleton< FileManager<RESOURCE> >
{
friend class Base::Singleton< FileManager<RESOURCE> >;
ACGL_SINGLETON(FileManager<RESOURCE>)
public:
typedef std::tr1::shared_ptr< FileController<RESOURCE> > SharedController;
......@@ -53,8 +53,6 @@ protected:
FileManager(void)
: mResourceMap()
{}
private:
FileManager(const FileManager&) {}
private:
ResourceMap mResourceMap;
......
......@@ -7,6 +7,10 @@
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
#include <ACGL/OpenGL/InitStaticFileTypes.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh>
namespace ACGL
{
......@@ -47,6 +51,14 @@ bool init(void)
// (using the extension versions or our own (slower) emulation)
//
OpenGL::initDirectStateAccessFunctions();
//
// Register file types for loading. This has to be done if the library is
// linked statically, because otherwise, the static registration of the
// file types is not performed.
//
OpenGL::initStaticFileTypes();
return true;
}
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureControlCubeMap.hh>
using namespace ACGL::Utils;
using namespace ACGL::OpenGL;
SharedTexture TextureControlCubeMap::create(void)
{
SharedTexture texture(new Texture(GL_TEXTURE_CUBE_MAP));
texture->bind();
texture->setMinFilter(mMinFilter);
texture->setMagFilter(mMagFilter);
texture->setWrap(mWrapS, mWrapT, mWrapR);
if(mAnisotropicFilter > 0.0) texture->setAnisotropicFilter(mAnisotropicFilter);
texture->setCubeMapFormat(
mSize,
mInternalFormat,
mFormat,
mType);
if(mPositiveX)
{
if(mPositiveX->getWidth() != mSize || mPositiveX->getHeight() != mSize)
{
error() << "Size of positive x does not match the definition in the cube map!" << std::endl;
texture->setImageDataCubeMapPositiveX();
}
else
{
texture->setImageDataCubeMapPositiveX(mPositiveX->getFormat(), mPositiveX->getType(), mPositiveX->getData());
}
}
if(mNegativeX)
{
if(mNegativeX->getWidth() != mSize || mNegativeX->getHeight() != mSize)
{
error() << "Size of negative x does not match the definition in the cube map!" << std::endl;
texture->setImageDataCubeMapNegativeX();
}
else
{
texture->setImageDataCubeMapNegativeX(mNegativeX->getFormat(), mNegativeX->getType(), mNegativeX->getData());
}
}
if(mPositiveY)
{
if(mPositiveY->getWidth() != mSize || mPositiveY->getHeight() != mSize)
{
error() << "Size of positive y does not match the definition in the cube map!" << std::endl;
texture->setImageDataCubeMapPositiveY();
}
else
{
texture->setImageDataCubeMapPositiveY(mPositiveY->getFormat(), mPositiveY->getType(), mPositiveY->getData());
}
}
if(mNegativeY)
{
if(mNegativeY->getWidth() != mSize || mNegativeY->getHeight() != mSize)
{
error() << "Size of negative y does not match the definition in the cube map!" << std::endl;
texture->setImageDataCubeMapNegativeY();
}
else
{
texture->setImageDataCubeMapNegativeY(mNegativeY->getFormat(), mNegativeY->getType(), mNegativeY->getData());
}
}
if(mPositiveZ)
{
if(mPositiveZ->getWidth() != mSize || mPositiveZ->getHeight() != mSize)
{
error() << "Size of positive z does not match the definition in the cube map!" << std::endl;
texture->setImageDataCubeMapPositiveZ();
}
else
{
texture->setImageDataCubeMapPositiveZ(mPositiveZ->getFormat(), mPositiveZ->getType(), mPositiveZ->getData());
}
}
if(mNegativeZ)
{
if(mNegativeZ->getWidth() != mSize || mNegativeZ->getHeight() != mSize)
{
error() << "Size of negative z does not match the definition in the cube map!" << std::endl;
texture->setImageDataCubeMapNegativeZ();
}
else
{
texture->setImageDataCubeMapNegativeZ(mNegativeZ->getFormat(), mNegativeZ->getType(), mNegativeZ->getData());
}
}
return texture;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureControlFile.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
using namespace ACGL::OpenGL;
TextureControlFile::TextureControlFile(const std::string& _filename)
: Resource::FileController<Texture>(_filename, Base::Settings::the()->getFullTexturePath()),
mDataController(TextureDataControlFileFactory::the()->create(_filename)),
mMinFilter(0),
mMagFilter(0),
mAnisotropicFilter(0.0),
mWrapS(0),
mWrapT(0),
mWrapR(0)
{
if(!mDataController)
ACGL::Utils::error() << "No valid texture controller to load the image. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}
TextureControlFile::TextureControlFile(const char* _filename)
: Resource::FileController<Texture>(std::string(_filename), Base::Settings::the()->getFullTexturePath()),
mDataController(TextureDataControlFileFactory::the()->create(std::string(_filename))),
mMinFilter(0),
mMagFilter(0),
mAnisotropicFilter(0.0),
mWrapS(0),
mWrapT(0),
mWrapR(0)
{
if(!mDataController)
ACGL::Utils::error() << "No valid texture controller to load the image. Perhaps there is no loader for that file extension: " << _filename << std::endl;
}
bool TextureControlFile::load(SharedTexture& texture)
{
if(!mDataController)
return false;
SharedTextureData tempData = mDataController->create();
if(!tempData)
return false;
texture->bind();
texture->setImageData2D(
tempData->getData(),
tempData->getWidth(),
tempData->getHeight(),
tempData->getFormat(),
tempData->getFormat(),
tempData->getType());
texture->generateMipmaps();
return true;
}
SharedTexture TextureControlFile::create(void)
{
updateFileModificationTime();
SharedTexture texture(new Texture(GL_TEXTURE_2D));
texture->bind();
texture->setMinFilter(mMinFilter == 0 ? GL_LINEAR_MIPMAP_LINEAR : mMinFilter);
texture->setMagFilter(mMagFilter == 0 ? GL_LINEAR : mMagFilter);
if(mWrapS > 0) texture->setWrap(mWrapS, mWrapT, mWrapR);
if(mAnisotropicFilter > 0.0)
texture->setAnisotropicFilter(mAnisotropicFilter);
if(!load(texture))
return SharedTexture();
return texture;
}
bool TextureControlFile::update(SharedTexture& texture)
{
if(fileIsUpToDate())
return false;
if(!load(texture))
return false;
updateFileModificationTime();
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
using namespace ACGL::OpenGL;
SharedTextureData TextureDataControlFile::create(void)
{
updateFileModificationTime();
SharedTextureData texture(new TextureData());
if(load(texture))
return texture;
return SharedTextureData();
}
bool TextureDataControlFile::update(SharedTextureData& _texture)
{
if(fileIsUpToDate())
return false;
if(!load(_texture))
return false;
updateFileModificationTime();
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/Base/StringOperations.hh>
using namespace ACGL;
using namespace ACGL::OpenGL;
using namespace ACGL::Base::StringOperations;
int_t TextureDataControlFileFactory::registerType(const std::string& _type, factoryCreate _creator)
{
ACGL::Utils::debug() << "TextureDataControlFileFactory register type: " << _type << std::endl;
mFactoryMap[_type] = _creator;
return mRegisteredTypes++;
}
SharedTextureDataControlFile TextureDataControlFileFactory::create(const std::string& _filename) const
{
std::string file;
std::string extension;
splitFileExtension(_filename, file, extension);
typename FactoryMap::const_iterator existingCreator = mFactoryMap.find(extension);
if(existingCreator != mFactoryMap.end())
return existingCreator->second(_filename);
return SharedTextureDataControlFile();
}
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <QtGui/QImage>
#include <QtOpenGL/QGLWidget>
using namespace ACGL;
using namespace ACGL::OpenGL;
bool TextureDataControlFileJPG::load(SharedTextureData& texture) const
{
QImage image = QImage(QString(getFullFilePath().c_str()));
if(image.isNull())
{
ACGL::Utils::error() << "Loading image " << getFullFilePath() << " has failed!" << std::endl;
return false;
}
image = QGLWidget::convertToGLFormat(image);
GLubyte *pImageData = new GLubyte[image.byteCount()];
memcpy(pImageData, image.bits(), image.byteCount());
texture->setData(pImageData);
texture->setWidth(image.width());
texture->setHeight(image.height());
return true;
}
int_t TextureDataControlFileJPG::sTypeID = TextureDataControlFileFactory::the()->registerType("jpg", &TextureDataControlFileJPG::creator);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment