23    , m_locationsResolved(false)
 
   24    , m_explicitLinking(flags & ExplicitLinking)
 
   26    m_program = glCreateProgram();
 
 
   31    , m_locationsResolved(false)
 
   32    , m_explicitLinking(flags & ExplicitLinking)
 
   34    m_program = glCreateProgram();
 
 
   41        glDeleteProgram(m_program);
 
 
   48    if (!vf.open(QIODevice::ReadOnly)) {
 
   49        qCCritical(KWIN_OPENGL) << 
"Couldn't open" << vertexFile << 
"for reading!";
 
   52    const QByteArray vertexSource = vf.readAll();
 
   54    QFile ff(fragmentFile);
 
   55    if (!ff.open(QIODevice::ReadOnly)) {
 
   56        qCCritical(KWIN_OPENGL) << 
"Couldn't open" << fragmentFile << 
"for reading!";
 
   59    const QByteArray fragmentSource = ff.readAll();
 
   61    return load(vertexSource, fragmentSource);
 
 
   69    glLinkProgram(m_program);
 
   72    int maxLength, length;
 
   73    glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &maxLength);
 
   75    QByteArray log(maxLength, 0);
 
   76    glGetProgramInfoLog(m_program, maxLength, &length, log.data());
 
   80    glGetProgramiv(m_program, GL_LINK_STATUS, &status);
 
   83        qCCritical(KWIN_OPENGL) << 
"Failed to link shader:" 
   87    } 
else if (length > 0) {
 
   88        qCDebug(KWIN_OPENGL) << 
"Shader link log:" << log;
 
 
   99        ba.append(
"precision highp float;\n");
 
  103        ba.replace(
"#version 140", 
"#version 300 es\n\nprecision highp float;\n");
 
 
  111    GLuint shader = glCreateShader(shaderType);
 
  113    QByteArray preparedSource = 
prepareSource(shaderType, source);
 
  114    const char *src = preparedSource.constData();
 
  115    glShaderSource(shader, 1, &src, 
nullptr);
 
  118    glCompileShader(shader);
 
  121    int maxLength, length;
 
  122    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
 
  124    QByteArray log(maxLength, 0);
 
  125    glGetShaderInfoLog(shader, maxLength, &length, log.data());
 
  129    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
 
  132        const char *typeName = (shaderType == GL_VERTEX_SHADER ? 
"vertex" : 
"fragment");
 
  133        qCCritical(KWIN_OPENGL) << 
"Failed to compile" << typeName << 
"shader:" 
  137        const auto split = source.split(
'\n');
 
  138        for (
const auto &l : split) {
 
  139            qCCritical(KWIN_OPENGL).nospace() << 
"line " << line++ << 
":" << l;
 
  141    } 
else if (length > 0) {
 
  142        qCDebug(KWIN_OPENGL) << 
"Shader compile log:" << log;
 
  146        glAttachShader(program, shader);
 
  149    glDeleteShader(shader);
 
 
  153bool GLShader::load(
const QByteArray &vertexSource, 
const QByteArray &fragmentSource)
 
  158    if (!vertexSource.isEmpty()) {
 
  159        bool success = 
compile(m_program, GL_VERTEX_SHADER, vertexSource);
 
  167    if (!fragmentSource.isEmpty()) {
 
  168        bool success = 
compile(m_program, GL_FRAGMENT_SHADER, fragmentSource);
 
  175    if (m_explicitLinking) {
 
 
  185    glBindAttribLocation(m_program, index, name);
 
 
  191        glBindFragDataLocation(m_program, index, name);
 
 
  197    glUseProgram(m_program);
 
 
  207    if (m_locationsResolved) {
 
  238    m_locationsResolved = 
true;
 
 
  243    const int location = glGetUniformLocation(m_program, name);
 
 
  250    return setUniform(m_matrix3Locations[uniform], value);
 
 
  256    return setUniform(m_matrix4Locations[uniform], matrix);
 
 
  262    return setUniform(m_vec2Locations[uniform], value);
 
 
  268    return setUniform(m_vec3Locations[uniform], value);
 
 
  274    return setUniform(m_vec4Locations[uniform], value);
 
 
  280    return setUniform(m_floatLocations[uniform], value);
 
 
  286    return setUniform(m_intLocations[uniform], value);
 
 
  292    return setUniform(m_colorLocations[uniform], value);
 
 
  298    return setUniform(m_colorLocations[uniform], value);
 
 
  346        glUniform1f(location, value);
 
  348    return (location >= 0);
 
 
  354        glUniform1i(location, value);
 
  356    return (location >= 0);
 
 
  362        glUniform3i(location, xValue, yValue, zValue);
 
  364    return location >= 0;
 
 
  370        glUniform2fv(location, 1, (
const GLfloat *)&value);
 
  372    return (location >= 0);
 
 
  378        glUniform3fv(location, 1, (
const GLfloat *)&value);
 
  380    return (location >= 0);
 
 
  386        glUniform4fv(location, 1, (
const GLfloat *)&value);
 
  388    return (location >= 0);
 
 
  394        glUniformMatrix3fv(location, 1, GL_FALSE, value.constData());
 
  396    return location >= 0;
 
 
  402        glUniformMatrix4fv(location, 1, GL_FALSE, value.constData());
 
  404    return (location >= 0);
 
 
  410        glUniform4f(location, color.redF(), color.greenF(), color.blueF(), color.alphaF());
 
  412    return (location >= 0);
 
 
  417    int location = glGetAttribLocation(m_program, name);
 
 
  425        glVertexAttrib1f(location, value);
 
  427    return (location >= 0);
 
 
  436        QMatrix4x4 matrix(m[0], m[4], m[8], m[12],
 
  437                          m[1], m[5], m[9], m[13],
 
  438                          m[2], m[6], m[10], m[14],
 
  439                          m[3], m[7], m[11], m[15]);
 
 
NamedTransferFunction transferFunction() const
static const ColorDescription sRGB
double maxHdrHighlightBrightness() const
const Colorimetry & colorimetry() const
const Colorimetry & sdrColorimetry() const
double sdrBrightness() const
QMatrix4x4 toOther(const Colorimetry &colorimetry) const
bool load(const QByteArray &vertexSource, const QByteArray &fragmentSource)
bool setColorspaceUniformsFromSRGB(const ColorDescription &dst)
@ ModelViewProjectionMatrix
@ ColorimetryTransformation
bool setColorspaceUniformsToSRGB(const ColorDescription &src)
bool loadFromFiles(const QString &vertexfile, const QString &fragmentfile)
const QByteArray prepareSource(GLenum shaderType, const QByteArray &sourceCode) const
QMatrix4x4 getUniformMatrix4x4(const char *name)
int uniformLocation(const char *name)
@ DestinationNamedTransferFunction
@ SourceNamedTransferFunction
bool setAttribute(const char *name, float value)
void bindAttributeLocation(const char *name, int index)
void bindFragDataLocation(const char *name, int index)
bool compile(GLuint program, GLenum shaderType, const QByteArray &sourceCode) const
GLShader(const QString &vertexfile, const QString &fragmentfile, unsigned int flags=NoFlags)
int attributeLocation(const char *name)
bool setUniform(const char *name, float value)
bool setColorspaceUniforms(const ColorDescription &src, const ColorDescription &dst)
glGetnUniformfv_func glGetnUniformfv
bool hasGLVersion(int major, int minor, int release)
bool hasGLExtension(const QByteArray &extension)