Commit c51f9537 authored by Robert Menzel's avatar Robert Menzel

added reloading manager for textures

parent e4879315
/***********************************************************************
* Copyright 2011-2013 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#pragma once
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/SingleFileBasedCreator.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/Base/Settings.hh>
namespace ACGL{
namespace OpenGL{
class Texture2DCreator : public Resource::SingleFileBasedCreator<Texture2D>
{
public:
Texture2DCreator(const std::string& _filename)
: Resource::SingleFileBasedCreator<Texture2D>(_filename, Base::Settings::the()->getFullTexturePath() ) {}
virtual ~Texture2DCreator() {}
//! try to create a 2D mip-mapped texture
virtual SharedTexture2D create();
//! update the texture data, create mipmaps if mipmapping is on. Don't change any other settings
//! (e.g. filtering settings)
virtual bool update(SharedTexture2D& _texture);
};
} // OpenGL
} // ACGL
......@@ -24,6 +24,9 @@ typedef Resource::MultiFileManager<ShaderProgram> ShaderProgramFileManager;
// same for meshes:
typedef Resource::FileManager<VertexArrayObject> VAOFileManager;
// for simple 2D (mip-mapped) textures
typedef Resource::FileManager<Texture2D> Texture2DFileManager;
// used internally:
typedef Resource::FileManager<Shader> ShaderFileManager;
......
/***********************************************************************
* Copyright 2011-2013 Computer Graphics Group RWTH Aachen University. *
* All rights reserved. *
* Distributed under the terms of the MIT License (see LICENSE.TXT). *
**********************************************************************/
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
#include <ACGL/OpenGL/Data/TextureDataLoadStore.hh>
using namespace ACGL;
using namespace ACGL::OpenGL;
SharedTexture2D Texture2DCreator::create()
{
return loadTexture2D( getFullFilePath() );
}
bool Texture2DCreator::update(SharedTexture2D& _texture)
{
if (fileIsUpToDate() || !_texture)
return false;
SharedTextureData data = loadTextureData( getFullFilePath() );
if(!data)
return false;
_texture->setImageData( data );
// if the min filter is one of the mip-mapped filters, generate mipmaps:
GLenum minFilter = _texture->getMinFilter();
if ( minFilter == GL_NEAREST_MIPMAP_NEAREST || minFilter == GL_LINEAR_MIPMAP_NEAREST
||minFilter == GL_NEAREST_MIPMAP_LINEAR || minFilter == GL_LINEAR_MIPMAP_LINEAR) {
_texture->generateMipmaps();
}
updateFileModificationTime();
return true;
}
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