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
......@@ -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,