TextureLoadStore.cc 1.79 KB
Newer Older
1
2
3
4
5
6
7
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/

#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
8
#include <ACGL/OpenGL/Data/TextureDataLoadStore.hh>
9
10
#include <ACGL/Utils/FileHelpers.hh>
#include <ACGL/Utils/StringHelpers.hh>
11
12
13
14
15
16
17
18

using namespace ACGL;
using namespace ACGL::OpenGL;
using namespace ACGL::Utils;

namespace ACGL{
namespace OpenGL{

19
SharedTexture2D loadTexture2D(const std::string& _filename, ColorSpace _colorSpace)
20
{
21
    std::string fileEnding = StringHelpers::getFileEnding(_filename);
22
23
    if(fileEnding == "dds")
    {
24
        return loadTexture2DFromDDS(_filename, _colorSpace);
25
    }
26
27
    else
    {
28
29
30
        SharedTextureData data = loadTextureData(_filename, _colorSpace);

        if (data) {
31
32
            //SharedTexture2D texture = std::make_shared<Texture2D>(data->getRecommendedInternalFormat());
            SharedTexture2D texture = SharedTexture2D( new Texture2D(data->getRecommendedInternalFormat()) );
Robert Menzel's avatar
Robert Menzel committed
33
            texture->setImageData( data );
34
            texture->generateMipmaps(); // calculates all remaining mipmap levels
35
36
            texture->setObjectLabel( _filename );

37
38
39
            return texture;
        } else {
            ACGL::Utils::error() << "can't create Texture from file " << _filename << " creating small empty texture instead." << std::endl;
40
            //SharedTexture2D dummy = std::make_shared<Texture2D>();
41
            SharedTexture2D dummy = SharedTexture2D(new Texture2D);
42
43
            dummy->resize( glm::uvec2(4,4) );
            return dummy;
44
45
        }
    }
46
47
48
49
}

}
}