ShaderControlFile.cc 1.33 KB
Newer Older
Robert Menzel's avatar
Robert Menzel committed
1
2
3
4
5
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University         //
// All rights reserved.                                                       //
////////////////////////////////////////////////////////////////////////////////

Robert Menzel's avatar
Robert Menzel committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <ACGL/Resource/ShaderControlFile.hh>
#include <ACGL/Utils/StringOperations.hh>

using namespace ACGL::Utils;
using namespace ACGL::Resource;

SharedShader ShaderControlFile::create(void)
{
    updateFileModificationTime();

    if(mType == Shader::ShaderTypeInvalid)
    {
        std::string filename;
        std::string extension;
        if(!StringOperations::splitFileExtension(mFilename, filename, extension))
            return SharedShader();

        if(extension == "vsh")
            mType = Shader::ShaderTypeVertex;
        else if(extension == "fsh")
            mType = Shader::ShaderTypeFragment;
        else
            return SharedShader();
    }

    SharedShader shader(new Shader(mType));
    if(shader->setFromFile(mFullFilePath))
        return shader;
    return SharedShader();
}

bool ShaderControlFile::update(SharedShader& shader)
{
    if(fileIsUpToDate())
        return false;

    if(!shader->setFromFile(mFullFilePath))
        return false;

    updateFileModificationTime();
    return true;
}