ShaderControlFile.cc 1.34 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
#include <ACGL/OpenGL/Controller/ShaderControlFile.hh>
#include <ACGL/Base/StringOperations.hh>
Robert Menzel's avatar
Robert Menzel committed
8

Robert Menzel's avatar
Robert Menzel committed
9
10
using namespace ACGL::Base;
using namespace ACGL::OpenGL;
Robert Menzel's avatar
Robert Menzel committed
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

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;
}