opengl: Let OpenGL implementation handle if preprocessor directive
It's less error prone and handles cases like if/elif/else better, etc. CCBUG: 479279
This commit is contained in:
parent
0284610eff
commit
7ba7ddfee8
2 changed files with 2 additions and 39 deletions
|
@ -37,7 +37,7 @@ vec3 srgbToLinear(vec3 color) {
|
|||
bvec3 isLow = lessThanEqual(color, vec3(0.04045f));
|
||||
vec3 loPart = color / 12.92f;
|
||||
vec3 hiPart = pow((color + 0.055f) / 1.055f, vec3(12.0f / 5.0f));
|
||||
#if glslVersion >= 1.30
|
||||
#if __VERSION__ >= 130
|
||||
return mix(hiPart, loPart, isLow);
|
||||
#else
|
||||
return mix(hiPart, loPart, vec3(isLow.r ? 1.0 : 0.0, isLow.g ? 1.0 : 0.0, isLow.b ? 1.0 : 0.0));
|
||||
|
@ -48,7 +48,7 @@ vec3 linearToSrgb(vec3 color) {
|
|||
bvec3 isLow = lessThanEqual(color, vec3(0.0031308f));
|
||||
vec3 loPart = color * 12.92f;
|
||||
vec3 hiPart = pow(color, vec3(5.0f / 12.0f)) * 1.055f - 0.055f;
|
||||
#if glslVersion >= 1.30
|
||||
#if __VERSION__ >= 130
|
||||
return mix(hiPart, loPart, isLow);
|
||||
#else
|
||||
return mix(hiPart, loPart, vec3(isLow.r ? 1.0 : 0.0, isLow.g ? 1.0 : 0.0, isLow.b ? 1.0 : 0.0));
|
||||
|
|
|
@ -234,43 +234,6 @@ std::optional<QByteArray> ShaderManager::preprocess(const QByteArray &src, int r
|
|||
return std::nullopt;
|
||||
}
|
||||
ret.append(*processed);
|
||||
} else if (line.startsWith("#if glslVersion ")) {
|
||||
static constexpr ssize_t ifLength = QByteArrayView("#if glslVersion ").size();
|
||||
if (line.size() < ifLength + 3) {
|
||||
qCWarning(KWIN_OPENGL, "failed parsing #if condition in line %s", qPrintable(line));
|
||||
return std::nullopt;
|
||||
}
|
||||
const QByteArray condition = line.mid(ifLength);
|
||||
const QByteArray versionString = line.mid(ifLength + 2);
|
||||
if (!condition.startsWith(">=")) {
|
||||
qCWarning(KWIN_OPENGL, "unsupported comparison operator in line %s", qPrintable(line));
|
||||
return std::nullopt;
|
||||
}
|
||||
const Version version = Version::parseString(versionString);
|
||||
if (!version.isValid()) {
|
||||
qCWarning(KWIN_OPENGL, "invalid version in line %s", qPrintable(line));
|
||||
return std::nullopt;
|
||||
}
|
||||
const bool keep = GLPlatform::instance()->glslVersion() >= version;
|
||||
for (it = it + 1; it != split.end(); it++) {
|
||||
if (it->startsWith("#endif")) {
|
||||
break;
|
||||
} else if (it->startsWith("#else")) {
|
||||
it++;
|
||||
for (; it != split.end(); it++) {
|
||||
if (it->startsWith("#endif")) {
|
||||
break;
|
||||
} else if (!keep) {
|
||||
ret.append(*it);
|
||||
ret.append('\n');
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (keep) {
|
||||
ret.append(*it);
|
||||
ret.append('\n');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret.append(line);
|
||||
ret.append('\n');
|
||||
|
|
Loading…
Reference in a new issue