ShaderProgram.cc 1.54 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/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/Tools.hh>
Robert Menzel's avatar
Robert Menzel committed
8

Robert Menzel's avatar
Robert Menzel committed
9
10
using namespace ACGL::OpenGL;
using namespace ACGL::Base;
Robert Menzel's avatar
Robert Menzel committed
11
12
13
14
15
16
using namespace ACGL::Utils;

bool ShaderProgram::link(void) const
{
    glLinkProgram(mContext);

17
#ifdef ACGL_CHECK_CRITICAL_GL_ERRORS
Robert Menzel's avatar
Robert Menzel committed
18
19
    if ( openGLRareErrorOccured() )
    {
20
21
        // it's uncommon that glLinkProgram creates errors,
        // linking errors create no gl errors but a GL_LINK_STATUS of GL_FALSE
Robert Menzel's avatar
Robert Menzel committed
22
23
24
        return false;
    }

25
26
27
    // check for program link errors:
    GLint programError;
    glGetProgramiv(mContext, GL_LINK_STATUS, &programError);
Robert Menzel's avatar
Robert Menzel committed
28

29
    if (programError != GL_TRUE)
Robert Menzel's avatar
Robert Menzel committed
30
31
    {
        // yes, errors :-(
32
33
34
35
36
37
38
39
40
41
42
43
44
45
        error() << "Program could not get linked:" << std::endl;
    }

    GLsizei length = 0;
    glGetProgramiv(mContext, GL_INFO_LOG_LENGTH, &length);
    if (length > 1)
    {
        // error log or warnings:
        GLchar* pInfo = new char[length + 1];
        glGetProgramInfoLog(mContext,  length, &length, pInfo);
        openGLRareError();
        warning() << "Linker log: " << std::string(pInfo) << std::endl;
        delete[] pInfo;
        return (programError == GL_TRUE); // if the log contains only warnings we return true
Robert Menzel's avatar
Robert Menzel committed
46
    }
47
#endif
Robert Menzel's avatar
Robert Menzel committed
48
49
    return true;
}