Merge branch 'main' into feature/incinerate
This commit is contained in:
+15
-19
@@ -76,6 +76,10 @@ var Shader = GObject.registerClass(
|
||||
// This is called once each time the shader is used.
|
||||
beginAnimation(settings, forOpening, actor) {
|
||||
|
||||
// Reset progress values.
|
||||
this._progress = 0;
|
||||
this._time = 0;
|
||||
|
||||
// This is not necessarily symmetric, but I haven't figured out a way to
|
||||
// get the actual values...
|
||||
const padding = (actor.width - actor.meta_window.get_frame_rect().width) / 2;
|
||||
@@ -89,11 +93,8 @@ var Shader = GObject.registerClass(
|
||||
|
||||
// This is called at each frame during the animation.
|
||||
updateAnimation(progress, time) {
|
||||
this.set_uniform_float(this._uProgress, 1, [progress]);
|
||||
this.set_uniform_float(this._uTime, 1, [time]);
|
||||
|
||||
// Store the current time and progress values. The corresponding signal is emitted a
|
||||
// but later in vfunc_paint_target.
|
||||
// Store the current time and progress values. The corresponding signal is emitted
|
||||
// each frame in vfunc_paint_target.
|
||||
this._progress = progress;
|
||||
this._time = time;
|
||||
}
|
||||
@@ -105,7 +106,7 @@ var Shader = GObject.registerClass(
|
||||
// Shell.GLSLEffect requires the declarations and the main source code as separate
|
||||
// strings. As it's more convenient to store the in one GLSL file, we use a regex
|
||||
// here to split the source code in two parts.
|
||||
const code = this._loadGLSLResource(`/shaders/${this._nick}.glsl`);
|
||||
const code = this._loadShaderResource(`/shaders/${this._nick}.frag`);
|
||||
|
||||
// Match anything between the curly brackets of "void main() {...}".
|
||||
const regex = RegExp('void main *\\(\\) *\\{([\\S\\s]+)\\}');
|
||||
@@ -121,6 +122,8 @@ var Shader = GObject.registerClass(
|
||||
// the handler. This could still be null if called from the updateAnimation() above.
|
||||
vfunc_paint_target(...params) {
|
||||
this.emit('update-animation', this._progress, this._time);
|
||||
this.set_uniform_float(this._uProgress, 1, [this._progress]);
|
||||
this.set_uniform_float(this._uTime, 1, [this._time]);
|
||||
super.vfunc_paint_target(...params);
|
||||
}
|
||||
|
||||
@@ -133,20 +136,13 @@ var Shader = GObject.registerClass(
|
||||
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.
|
||||
_loadGLSLResource(path) {
|
||||
let code = this._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 this._loadStringResource('/shaders/' + file);
|
||||
});
|
||||
// This loads a GLSL file from the extension's resources to a JavaScript string. The
|
||||
// code from "common.glsl" is prepended automatically.
|
||||
_loadShaderResource(path) {
|
||||
let common = this._loadStringResource('/shaders/common.glsl');
|
||||
let code = this._loadStringResource(path);
|
||||
|
||||
// Add a trailing newline. Else the GLSL compiler complains...
|
||||
return code + '\n';
|
||||
return common + '\n' + code + '\n';
|
||||
}
|
||||
});
|
||||
|
||||
+9
-1
@@ -13,7 +13,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const {Gtk} = imports.gi;
|
||||
const {Gtk, Gio} = imports.gi;
|
||||
const ByteArray = imports.byteArray;
|
||||
|
||||
// Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3,
|
||||
// -2, and -1 are returned respectively.
|
||||
@@ -83,4 +84,11 @@ function shellVersionIsAtLeast(major, minor) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reads the contents of a file contained in the global resources archive. The data
|
||||
// is returned as a string.
|
||||
function getStringResource(path) {
|
||||
const data = Gio.resources_lookup_data(path, 0);
|
||||
return ByteArray.toString(ByteArray.fromGBytes(data));
|
||||
}
|
||||
Reference in New Issue
Block a user