Commit ed7977c0 authored by Martin Schultz's avatar Martin Schultz
Browse files

* implemented (un)register function to register functionpointers for textureloading

parent 4c32adee
......@@ -17,6 +17,8 @@
#include <ACGL/OpenGL/Tools.hh>
#include <string>
#include <map>
#include <vector>
namespace ACGL{
namespace OpenGL{
......@@ -25,6 +27,18 @@ namespace OpenGL{
// generic load/save
///////////////////////////////////////////////////////////////////////////////////////////////////
//! functionpointer which can be used for generic Texture loading
typedef SharedTextureData (*TextureLoadFuncPtr)(const std::string&);
//! map to associate functionpointers with file endings
extern std::map<std::string,TextureLoadFuncPtr> textureLoadFunctions;
//! registers a functionpointer to be used for loading specified file types (E.G. provide a load function which loads compressed)
void registerTextureLoadFunction(std::vector<std::string> _endings, TextureLoadFuncPtr _function);
//! remove a registered functionpointer (if you want to use the stock ones again
void unregisterTextureLoadFunction(TextureLoadFuncPtr _function);
//! generic load function that will use one of the loading functions below based on the file ending
SharedTextureData loadTextureData(const std::string &_filename);
......
......@@ -54,11 +54,38 @@ namespace OpenGL{
// generic load/save
///////////////////////////////////////////////////////////////////////////////////////////////////
std::map<std::string,TextureLoadFuncPtr> textureLoadFunctions = std::map<std::string,TextureLoadFuncPtr>();
void registerTextureLoadFunction(std::vector<std::string> _endings, TextureLoadFuncPtr _function)
{
if(_function != nullptr)
{
std::vector<std::string>::iterator n = _endings.end();
for(std::vector<std::string>::iterator i = _endings.begin() ; i != n ; i++ )
{
textureLoadFunctions.insert( std::pair<std::string,TextureLoadFuncPtr>(*i ,_function) );
}
}
}
void unregisterTextureLoadFunction(TextureLoadFuncPtr _function)
{
std::map<std::string,TextureLoadFuncPtr>::iterator n = textureLoadFunctions.end();
for(std::map<std::string,TextureLoadFuncPtr>::iterator i = textureLoadFunctions.begin() ; i != n ; i++)
{
if(i->second == _function)
textureLoadFunctions.erase(i);
}
}
SharedTextureData loadTextureData(const std::string &_filename)
{
// lower case file ending:
std::string fileEnding = getFileEnding( _filename );
if(textureLoadFunctions.find(fileEnding) != textureLoadFunctions.end())
return textureLoadFunctions[fileEnding](_filename);
if (fileEnding == "png") {
return loadTextureDataFromLodepng( _filename );
} else if (fileEnding == "hdr") {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment