♻️ Add base classes for the effects and shaders

This commit is contained in:
Simon Schneegans
2022-05-13 20:39:45 +02:00
parent 1ccc34f766
commit cb4b87811e
17 changed files with 955 additions and 1349 deletions
+1 -26
View File
@@ -13,8 +13,7 @@
'use strict';
const {Gtk, Gio} = imports.gi;
const ByteArray = imports.byteArray;
const {Gtk} = imports.gi;
// Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3,
// -2, and -1 are returned respectively.
@@ -90,28 +89,4 @@ function shellVersionIsAtLeast(major, minor) {
}
return false;
}
// This loads the file at 'path' contained in the extension's resources to a JavaScript
// string.
function loadStringResource(path) {
const data = Gio.resources_lookup_data(path, 0);
return ByteArray.toString(ByteArray.fromGBytes(data));
}
// This loads a GLSL file from the extension's resources to a JavaScript string. Any
// #include statements in this file are replaced with the corresponding file contents.
function loadGLSLResource(path) {
let code = loadStringResource(path);
// This regex matches either #include "..." or #include <...>. The part between the
// brackets is captured in the capture group.
const regex = RegExp('#include ["<](.+)[">]', 'g');
code = code.replace(regex, (m, file) => {
return loadStringResource('/shaders/' + file);
});
// Add a trailing newline. Else the GLSL compiler complains...
return code + '\n';
}