Skip to content

Commit

Permalink
🔀 Merge pull request #165 from Schneegans/fix/#162
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans authored Apr 9, 2024
2 parents 35497c3 + 5c2ed45 commit 9bd0b48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ SPDX-License-Identifier: CC-BY-4.0

# Changelog of the Desktop Cube Extension

## [unreleased]

**Release Date:** TBD

#### Bug Fixes

- Fixed a crash on GNOME 46 when using background panoramas.

## [Desktop Cube 23 [backport release]](https://github.com/schneegans/Desktop-Cube/releases/tag/v23)

**Release Date:** 2024-02-27
Expand Down
42 changes: 16 additions & 26 deletions src/Skybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import Gio from 'gi://Gio';
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import Shell from 'gi://Shell';
import GdkPixbuf from 'gi://GdkPixbuf';
import Cogl from 'gi://Cogl';

Expand All @@ -39,7 +40,7 @@ var SkyboxEffect = GObject.registerClass({
'pitch': GObject.ParamSpec.double('pitch', 'pitch', 'pitch', GObject.ParamFlags.READWRITE,
-0.5 * Math.PI, 0.5 * Math.PI, 0),
},
}, class SkyboxEffect extends Clutter.Effect {
}, class SkyboxEffect extends Shell.GLSLEffect {
// clang-format on
_init(file) {
super._init();
Expand All @@ -59,16 +60,14 @@ var SkyboxEffect = GObject.registerClass({
// Redraw if either the pitch or the yaw changes.
this.connect('notify::yaw', () => {this.queue_repaint()});
this.connect('notify::pitch', () => {this.queue_repaint()});
};

const backend = Clutter.get_default_backend();
const coglContext = backend.get_cogl_context();

this._pipeline = new Cogl.Pipeline(coglContext);
// This is called once to setup the Cogl.Pipeline.
vfunc_build_pipeline() {

// In the vertex shader, we compute the view space position of the actor's corners.
this._pipeline.add_snippet(
Cogl.Snippet.new(Cogl.SnippetHook.VERTEX, 'varying vec4 vsPos;',
'vsPos = cogl_modelview_matrix * cogl_position_in;'));
this.add_glsl_snippet(Shell.SnippetHook.VERTEX, 'varying vec4 vsPos;',
'vsPos = cogl_modelview_matrix * cogl_position_in;', false);

const fragmentDeclares = `
varying vec4 vsPos;
Expand Down Expand Up @@ -103,28 +102,19 @@ var SkyboxEffect = GObject.registerClass({
cogl_color_out = texture2D(uTexture, vec2(x, y));
`;

this._pipeline.add_snippet(
Cogl.Snippet.new(Cogl.SnippetHook.FRAGMENT, fragmentDeclares, fragmentCode));
};
this.add_glsl_snippet(Shell.SnippetHook.FRAGMENT, fragmentDeclares, fragmentCode,
false);
}

// For each draw call, we have to set some uniform values.
vfunc_paint_node(node, paintContext) {
vfunc_paint_target(node, paintContext) {
if (this._texture) {
this._pipeline.set_layer_texture(0, this._texture.get_texture());

this._pipeline.set_uniform_1i(this._pipeline.get_uniform_location('uTexture'), 0);
this._pipeline.set_uniform_1f(this._pipeline.get_uniform_location('uPitch'),
this.pitch);
this._pipeline.set_uniform_1f(this._pipeline.get_uniform_location('uYaw'),
this.yaw);

const pipelineNode = new Clutter.PipelineNode(this._pipeline);
pipelineNode.set_name('Dekstop-Cube Skybox');
node.add_child(pipelineNode);
this.get_pipeline().set_layer_texture(0, this._texture.get_texture());
this.set_uniform_float(this.get_uniform_location('uTexture'), 1, [0]);
this.set_uniform_float(this.get_uniform_location('uPitch'), 1, [this.pitch]);
this.set_uniform_float(this.get_uniform_location('uYaw'), 1, [this.yaw]);

const actor = this.get_actor();
const alloc = actor.get_allocation_box();
pipelineNode.add_texture_rectangle(alloc, 0, 0, 1, 1);
super.vfunc_paint_target(node, paintContext);
}
}

Expand Down

0 comments on commit 9bd0b48

Please sign in to comment.