Commit 0aa3296f authored by Robert Menzel's avatar Robert Menzel
Browse files

started on geometry loading from files

parent 489831af
......@@ -27,12 +27,11 @@
#include <ACGL/OpenGL/Controller/ShaderControlFile.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramControlFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramObjectControl.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.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/ViewportControl.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILE_HH
/**
* Basetemplate for file loading.
*
* TextureDataControlFile and GeometryDataControlFile are typedefs below
*
* To support another filetype, derive from those and implement load() and registerType() methods.
* Also: add a call to the InitStaticFileTypes to register the file type globally.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Data/TextureData.hh>
#include <ACGL/OpenGL/Data/GeometryData.hh>
namespace ACGL{
namespace OpenGL{
class TextureDataControlFile : public Resource::FileController<TextureData>
template<class DATA_FILE_TYPE>
class DataControlFile : public Resource::FileController<DATA_FILE_TYPE>
{
private:
typedef ptr::shared_ptr< DATA_FILE_TYPE > SharedDATA_FILE_TYPE;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
TextureDataControlFile(const std::string& _filename)
: Resource::FileController<TextureData>(_filename, Base::Settings::the()->getFullTexturePath())
DataControlFile(const std::string& _filename)
: Resource::FileController<DATA_FILE_TYPE>(_filename, Base::Settings::the()->getFullTexturePath())
{}
virtual ~TextureDataControlFile(void) {}
virtual ~DataControlFile(void) {}
// ====================================================================================================== \/
// ============================================================================================ INTERFACE \/
// ====================================================================================================== \/
private:
virtual bool load(SharedTextureData& texture) const = 0;
virtual bool load(SharedDATA_FILE_TYPE& texture) const = 0;
// ====================================================================================================== \/
// ============================================================================================= OVERRIDE \/
// ====================================================================================================== \/
public:
virtual SharedTextureData create(void);
virtual bool update(SharedTextureData& _texture);
virtual SharedDATA_FILE_TYPE create(void)
{
Resource::FileController<DATA_FILE_TYPE>::updateFileModificationTime();
SharedDATA_FILE_TYPE texture(new DATA_FILE_TYPE());
if(load(texture))
return texture;
return SharedDATA_FILE_TYPE();
}
virtual bool update(SharedDATA_FILE_TYPE& _texture)
{
if (Resource::FileController<DATA_FILE_TYPE>::fileIsUpToDate())
return false;
if(!load(_texture))
return false;
Resource::FileController<DATA_FILE_TYPE>::updateFileModificationTime();
return true;
}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
static int_t sTypeID;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFile)
typedef DataControlFile< TextureData > TextureDataControlFile;
ACGL_SMARTPOINTER_TYPEDEFS( TextureDataControlFile )
typedef DataControlFile< GeometryData > GeometryDataControlFile;
ACGL_SMARTPOINTER_TYPEDEFS( GeometryDataControlFile )
} // OpenGL
} // ACGL
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILEJPG_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILEJPG_HH
#ifndef ACGL_OPENGL_CONTROLLER_DATACONTROLFILEFACTORY_HH
#define ACGL_OPENGL_CONTROLLER_DATACONTROLFILEFACTORY_HH
/**
* Image loaders can register the supported types at TextureDataControlFileFactory so a call like
* ... = TextureControlFile("bunny.ppm").create();
* will find the correct loader of the given file ending.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/Base/Singleton.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/Base/StringOperations.hh>
#include <map>
#include <string>
namespace ACGL{
namespace OpenGL{
class TextureControlFileJPG : public Resource::FileController<Texture>
//
// Generic FileFactories:
//
template<class DATA_CONTROL_FILE_TYPE>
class DataControlFileFactory : public Base::Singleton< DataControlFileFactory<DATA_CONTROL_FILE_TYPE> >
{
ACGL_SINGLETON(DataControlFileFactory)
// ========================================================================================================= \/
// ================================================================================================ TYPEDEFS \/
// ========================================================================================================= \/
private:
typedef DATA_CONTROL_FILE_TYPE (*factoryCreate)(const std::string&);
typedef std::map<std::string, factoryCreate> FactoryMap;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
protected:
DataControlFileFactory(void) : mRegisteredTypes(0), mFactoryMap() {}
public:
TextureControlFileJPG(const std::string& _filename)
: Resource::FileController<Texture>(_filename, Base::Settings::the()->getFullTexturePath()),
mMinFilter(0),
mMagFilter(0),
mAnisotropicFilter(0.0f),
mWrapS(0),
mWrapT(0),
mWrapR(0)
{}
virtual ~TextureControlFileJPG(void) {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
virtual ~DataControlFileFactory(void) {}
// ========================================================================================================= \/
// ================================================================================================= METHODS \/
// ========================================================================================================= \/
public:
inline TextureControlFileJPG& minFilter (GLint _minFilter) { mMinFilter = _minFilter; return *this; }
inline TextureControlFileJPG& magFilter (GLint _magFilter) { mMagFilter = _magFilter; return *this; }
inline TextureControlFileJPG& anisotropicFilter (GLfloat _anisotropicFilter) { mAnisotropicFilter = _anisotropicFilter; return *this; }
int_t getRegisteredTypes(void) const { return mRegisteredTypes; }
inline TextureControlFileJPG& wrap (GLenum _wrapS, GLenum _wrapT = 0, GLenum _wrapR = 0)
int_t registerType(const std::string& _type, factoryCreate _creator)
{
mWrapS = _wrapS;
mWrapT = _wrapT;
mWrapR = _wrapR;
return *this;
ACGL::Utils::debug() << "DataControlFileFactory register type: " << _type << " with id " << mRegisteredTypes << std::endl;
mFactoryMap[_type] = _creator;
return mRegisteredTypes++;
}
private:
bool loadJPG(SharedTexture& texture);
DATA_CONTROL_FILE_TYPE create(const std::string& _filename) const
{
std::string file;
std::string extension;
ACGL::Base::StringOperations::splitFileExtension(_filename, file, extension);
typename FactoryMap::const_iterator existingCreator = mFactoryMap.find(extension);
if (existingCreator != mFactoryMap.end()) {
return existingCreator->second(_filename);
}
return DATA_CONTROL_FILE_TYPE();
}
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedTexture create(void);
virtual bool update(SharedTexture& texture);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
GLint mMinFilter;
GLint mMagFilter;
GLfloat mAnisotropicFilter;
GLenum mWrapS;
GLenum mWrapT;
GLenum mWrapR;
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
private:
int_t mRegisteredTypes;
FactoryMap mFactoryMap;
};
//
// Individual FileFactories:
//
typedef DataControlFileFactory< SharedTextureDataControlFile > TextureDataControlFileFactory;
typedef DataControlFileFactory< SharedGeometryDataControlFile > GeometryDataControlFileFactory;
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTURECONTROLFILEJPG_HH
#endif // ACGL_OPENGL_CONTROLLER_DATACONTROLFILEFACTORY_HH
......@@ -6,6 +6,11 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROL_HH
/**
* Can create an empty texture, if a texture should get loaded from a file,
* see TextureControlFile.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
......
......@@ -6,6 +6,10 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTURECONTROLCUBEMAP_HH
#define ACGL_OPENGL_CONTROLLER_TEXTURECONTROLCUBEMAP_HH
/**
* Can set up a cube map out of multiple TextureData objects.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
......
......@@ -9,7 +9,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
namespace ACGL{
......
......@@ -8,7 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/OpenGL/InitStaticFileTypes.hh>
namespace ACGL{
......@@ -35,20 +35,8 @@ public:
private:
virtual bool load(SharedTextureData& texture) const;
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
private:
static int_t registerType(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
private:
static int_t sTypeID;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFileJPG)
......
......@@ -8,7 +8,7 @@
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/OpenGL/InitStaticFileTypes.hh>
namespace ACGL{
......@@ -35,20 +35,8 @@ public:
private:
virtual bool load(SharedTextureData& texture) const;
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
private:
static int_t registerType(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
private:
static int_t sTypeID;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFilePNG)
......
......@@ -6,9 +6,14 @@
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPPM_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEPPM_HH
/**
* A minimal ppm loader (with some bugs). No external dependencies, so this is at least
* one image type that can be loaded without extra libs.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
#include <ACGL/OpenGL/InitStaticFileTypes.hh>
namespace ACGL{
......@@ -35,20 +40,8 @@ public:
private:
virtual bool load(SharedTextureData& texture) const;
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
static int_t getTypeID(void) { return sTypeID; }
private:
static int_t registerType(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
private:
static int_t sTypeID;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureDataControlFilePPM)
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEFACTORY_HH
#define ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEFACTORY_HH
#ifndef ACGL_OPENGL_DATA_GEOMETRYDATA_HH
#define ACGL_OPENGL_DATA_GEOMETRYDATA_HH
#include <ACGL/ACGL.hh>
/**
*/
#include <ACGL/Base/Singleton.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/ACGL.hh>
#include <map>
#include <string>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh> // get Attribute definition
namespace ACGL{
namespace OpenGL{
class TextureDataControlFileFactory : public Base::Singleton< TextureDataControlFileFactory >
class GeometryData
{
ACGL_SINGLETON(TextureDataControlFileFactory)
// ========================================================================================================= \/
// ================================================================================================ TYPEDEFS \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
private:
typedef SharedTextureDataControlFile (*factoryCreate)(const std::string&);
typedef std::map<std::string, factoryCreate> FactoryMap;
public:
GeometryData(void)
: mpData(NULL),
mSize(0),
mStrideSize(0)
{}
virtual ~GeometryData(void)
{
delete[] mpData;
}
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ================================================================================================= GETTERS \/
// ========================================================================================================= \/
protected:
TextureDataControlFileFactory(void) : mRegisteredTypes(0), mFactoryMap() {}
public:
virtual ~TextureDataControlFileFactory(void) {}
GLubyte *getData (void) const { return mpData; }
GLsizei getSize (void) const { return mSize; }
GLsizei getStrideSize (void) const { return mStrideSize; }
// ========================================================================================================= \/
// ================================================================================================= METHODS \/
// ================================================================================================= SETTERS \/
// ========================================================================================================= \/
public:
int_t getRegisteredTypes(void) const { return mRegisteredTypes; }
int_t registerType(const std::string& _type, factoryCreate _creator);
SharedTextureDataControlFile create(const std::string& _filename) const;
void setData (GLubyte *_pData) { mpData = _pData; }
void setSize (GLsizei _size) { mSize = _size; }
void setStrideSize(GLsizei _strideSize) { mStrideSize = _strideSize; }
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
// ========================================================================================================= \/
private:
int_t mRegisteredTypes;
FactoryMap mFactoryMap;
GLubyte *mpData; // raw data, just cast the pointer as needed
GLsizei mSize; // size in bytes
GLsizei mStrideSize; // size in bytes of a stride
public:
ArrayBuffer::AttributeVec mAttributes;
};
ACGL_SMARTPOINTER_TYPEDEFS(GeometryData)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_TEXTUREDATACONTROLFILEFACTORY_HH
#endif // ACGL_OPENGL_DATA_GEOMETRYDATA_HH
......@@ -153,7 +153,7 @@ public:
mAttributes.clear();
}
//! Set data for this buffer for a given number of elements
//! Set data for this buffer for a given number of elements (_elements*mStride == size in bytes)
//! Use only after all attributes have been defined
inline void setDataElements( uint_t _elements, const GLvoid *_pData = NULL, GLenum _usage = GL_STATIC_DRAW ) {
setData( mTarget, _elements * mStride, _pData, _usage );
......
......@@ -9,7 +9,7 @@
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
#include <ACGL/OpenGL/InitStaticFileTypes.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileJPG.hh>
namespace ACGL
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// Copyright (c) 2011, 2012 Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureDataControlFile.hh>
#include <ACGL/OpenGL/Controller/DataControlFile.hh>
using namespace ACGL;
using namespace ACGL::OpenGL;
using namespace ACGL::Utils;
SharedTextureData TextureDataControlFile::create(void)
{
updateFileModificationTime();
template<> int_t TextureDataControlFile::sTypeID = -1;
template<> int_t GeometryDataControlFile::sTypeID = -1;
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;
}
......@@ -4,7 +4,7 @@
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureControlFile.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>
#include <ACGL/OpenGL/Controller/DataControlFileFactory.hh>
using namespace ACGL::OpenGL;
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/TextureControlFileJPG.hh>
using namespace ACGL::OpenGL;
SharedTexture TextureControlFileJPG::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.0f)
texture->setAnisotropicFilter(mAnisotropicFilter);
if(loadJPG(texture))
return texture;
return SharedTexture();
}
bool TextureControlFileJPG::update(SharedTexture& texture)
{