javascript - 带有 gnome 扩展的 ClutterShaderEffect

标签 javascript gnome clutter gnome-shell gnome-shell-extensions

我的项目的目的是实现一个着色器并将其附加到舞台上。我想要使​​用 JS gnome 扩展系统对整个屏幕进行变形。 (我在 C 中完成并重新编译 gnome,但我想使用一种不需要任何编译的技术)。

然后,我正在寻找实现并将自定义 ShaderEffect 附加到舞台。 我试着用下面的代码来做,但整个屏幕都卡住了:

fx = new Clutter.ShaderEffect({
        shader_type: Clutter.ShaderType.FRAGMENT_SHADER });
fx.set_shader_source(shader);
fx.set_uniform_value('height', this._actor.get_height());
fx.set_uniform_value('width', this._actor.get_width());
this._actor.add_effect_with_name('shader', fx);

this._actor = global.stage。这是有效的,但屏幕卡住。所以我阅读了文档并找到了这个 Doc link :

Implementing a ClutterOffscreenEffect Creating a sub-class of ClutterOffscreenEffect requires, in case of overriding the ClutterEffect virtual functions, to chain up to the ClutterOffscreenEffect's implementation. On top of the ClutterEffect's virtual functions, ClutterOffscreenEffect also provides a ClutterOffscreenEffectClass.paint_target() function, which encapsulates the effective painting of the texture that contains the result of the offscreen redirection.

但是我应该如何在 JS 中做到这一点?

const ClutterShaderEffectCustom = new Lang.Class({
  Name : 'ClutterShaderEffectCustom',
  Extends : Clutter.ShaderEffect,

  _init : function(shader_type, actor, shaderSource) {
      // some stuff 
  },

  paint_target : function() {
     // TODO but how ? :/
  }
});

因为我有一些 C 文件在做它,但我不知道如何在 JS 中实现它。非官方 JS 文档没有帮助。

我还用 Clutter.Shader 尝试了其他东西:

fx = new Clutter.Shader();
fx.set_fragment_source(shader, shader.lenght);
fx.set_uniform('height', this._actor.get_height());
fx.set_uniform('width', this._actor.get_width());
this._actor.set_shader(fx);

但是着色器只应用于 child ,而不是舞台。 this._actor = global.stage。这是使用第二种方法的结果的概述。我的着色器正在复制纹理,只是为了测试。但是为什么只在图标上而不是在整个屏幕上,因为我将它附加到舞台上?

Overview of the second method using Clutter.Shader

最佳答案

我使用以下源代码解决了我的非刷新问题:

myFunction : function() {
    fx = new Clutter.ShaderEffect({
        shader_type: Clutter.ShaderType.FRAGMENT_SHADER });
    fx.set_shader_source(shader);
    fx.set_uniform_value('height', this._actor.get_height());
    fx.set_uniform_value('width', this._actor.get_width());
    this._actor.add_effect_with_name('shader', fx); 
    this._timeline = new Clutter.Timeline({ duration: 1, repeat_count: -1 });
    this._timeline.connect('new-frame', Lang.bind(this, this._newFrame));
    this._timeline.start();
}

_newFrame: function() {
    this._actor.scale_y = 1.0;
}

关于javascript - 带有 gnome 扩展的 ClutterShaderEffect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33873236/

相关文章:

javascript - 在 Redis 中检索集合并将其插入到数组中

<body> 中的 JavaScript

gtk - 如何使用 Vala 从字符串生成二维码图像?

使用 bluetooth_client_connect_service() 连接到蓝牙设备 - gnome-bluetooth 3.8.2.1

c++ - 在 Clutter API 中使用 child Actor

javascript - 使用观察检测 Javascript 数组中的更改,但不与另一个数组进行比较

javascript - 如何在 Angular 中使用 Datatables.Net 创建自定义打印预览屏幕

linux - Fedora 20 - 如何安装应用程序?

杂乱工具包依赖项 - Ubuntu 11.04

C++ - Clutter 1.0 - 从线程调用函数导致段错误