ShaderControlFile.cc 1.39 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

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

16
    if(mType == GL_INVALID_ENUM)
Robert Menzel's avatar
Robert Menzel committed
17
18
19
20
21
22
23
    {
        std::string filename;
        std::string extension;
        if(!StringOperations::splitFileExtension(mFilename, filename, extension))
            return SharedShader();

        if(extension == "vsh")
24
            mType = GL_VERTEX_SHADER;
25
26
        else if(extension == "gsh")
            mType = GL_GEOMETRY_SHADER;
Robert Menzel's avatar
Robert Menzel committed
27
        else if(extension == "fsh")
28
            mType = GL_FRAGMENT_SHADER;
Robert Menzel's avatar
Robert Menzel committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        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;
}