glslkit-webgl 0.1.0.pre → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +101 -48
- data/glslkit-webgl.gemspec +8 -5
- data/lib/glslkit/webgl/version.rb +1 -1
- data/lib/glslkit/webgl.rb +23 -2
- data/sample/generated/cube_shaders.rb +1 -1
- data/sample/generated/neon_shaders.rb +1 -1
- data/sample/generated-broken/neon-broken_shaders.rb +1 -1
- data/shim/glslkit-webgl.js +21 -0
- metadata +5 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18dde294abf04720f5ff6bf189c482bce2bb960b1ee538ddbae9e3de8f1bd974
|
|
4
|
+
data.tar.gz: 615c0d0e5c142b4fe7061e5508fb7f6c2fb9b5deb2bdd5bf8c9102f534b7828a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ee0a2fdc0131b5ea1e3a8d2a2066af9624c07ccb787aced1a27cd9a4d2e009ee546fba4e7079458bea4bc619e898bed98799c88a69ed34f1f21042f2cd04f5d
|
|
7
|
+
data.tar.gz: d2db73d0147589a1e58cbf84bee2d68469c791e882fb3bc1bbeaf7bba2f1747a2b4db9b9a059226a59c54f3b0d97aae5480457f1a04e1d569aabcc0e44eb4cea
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
# glslkit-webgl
|
|
2
2
|
|
|
3
|
-
`glslkit-webgl`
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
`glslkit-webgl` は、ruby.wasmでブラウザ上で動くRubyプログラム向けのWebGL2
|
|
4
|
+
ランタイム。`glslkit`のリフレクションマニフェストを読み込み、WebGLの参照を
|
|
5
|
+
キャッシュし、シェーダのコンパイルエラーをRubyの例外として報告する。
|
|
6
|
+
|
|
7
|
+
## HTTP経由で開くこと
|
|
8
|
+
|
|
9
|
+
**`glslkit-webgl`を使うページは`file://`ではなくHTTP経由で開くこと。**
|
|
10
|
+
ruby.wasmはRubyのエントリファイルを`fetch()`で読み込むため、ブラウザは
|
|
11
|
+
`file://`オリジンに対してこれを制限する:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Cross origin requests are only supported for HTTP.
|
|
15
|
+
Fetch API cannot load file:///.../neon.rb due to access control checks.
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Safariはこのエラーで確実に失敗する。Chromeは現状`file://`でも動くが、
|
|
19
|
+
将来にわたって保証されているわけではない。ローカルでディレクトリを配信し、
|
|
20
|
+
`http://`として開くこと:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
python3 -m http.server 8000
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`http://localhost:8000/webgl/sample/index.html`として開く。
|
|
27
|
+
`glslkit-webgl.js`自身も`file://`オリジンを検出し、同じ警告をページ上に表示する。
|
|
6
28
|
|
|
7
29
|
## Quick start
|
|
8
30
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
`webgl/sample/neon-error.html
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
このリポジトリをHTTP経由で配信し(上記参照)、`webgl/sample/index.html`を開く。
|
|
32
|
+
このサンプルは、`webgl/sample/shaders/cube.{vert,frag}`から`rake glslkit:embed`
|
|
33
|
+
で生成された、アプリケーション側のJavaScriptを使わない回転するテクスチャ付き
|
|
34
|
+
キューブを描画する。`webgl/sample/neon.html`は同じ方法で生成された、
|
|
35
|
+
アニメーションするフラグメントシェーダのレイマーチングデモ。
|
|
36
|
+
`webgl/sample/neon-error.html`は`common/sdf.glsl`(`#include`されるファイルで
|
|
37
|
+
あり、トップレベルのシェーダではない)を意図的に壊し、`CompileError`が
|
|
38
|
+
元のincludeされたファイルと行番号を報告することを実演する。正常なシェーダに
|
|
39
|
+
戻して描画を開始するボタンも付いている。
|
|
18
40
|
|
|
19
41
|
```html
|
|
20
42
|
<canvas id="canvas" width="640" height="480"></canvas>
|
|
@@ -22,11 +44,42 @@ the working shaders and start rendering.
|
|
|
22
44
|
data-ruby-version="4.0" data-wasm-wasi-version="2.10.1"></script>
|
|
23
45
|
```
|
|
24
46
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
47
|
+
このシムはruby.wasmを起動するだけ。`JS::RequireRemote`がRubyファイルを
|
|
48
|
+
fetchし、描画ロジックはすべてRuby側に残る。`window.glslkitWebGLReady`は
|
|
49
|
+
エントリファイルの読み込みが終わった時点で確定する。パッケージ化したwasm
|
|
50
|
+
ビルドでは、両方のgemを通常通りインストールすればよい。
|
|
51
|
+
|
|
52
|
+
## 単体のruby.wasmビルドへのパッケージング(rbwasm)
|
|
53
|
+
|
|
54
|
+
上記のQuick Startは`DefaultRubyVM`/`JS::RequireRemote`を使っており、実行時に
|
|
55
|
+
HTTP経由で`.rb`ソースファイルをfetchするためビルド手順は不要。代わりに
|
|
56
|
+
`glslkit-webgl`(と依存する`glslkit`)を単一の`.wasm`バイナリに事前にバンドル
|
|
57
|
+
したい場合、想定している経路は[`ruby_wasm`][ruby_wasm] gemの`rbwasm build`
|
|
58
|
+
CLIを使う方法:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
gem install ruby_wasm
|
|
62
|
+
# Gemfile: gem "glslkit-webgl"
|
|
63
|
+
bundle exec rbwasm build -o app.wasm
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
これは`ruby_wasm`/`rbwasm`の標準的な手順であり、`glslkit-webgl`固有の追加の
|
|
67
|
+
パッケージング要件は無い。通常の`bundle install`だけで`glslkit-webgl`と
|
|
68
|
+
依存する`glslkit`がRubyGemsから正しく解決される。
|
|
69
|
+
|
|
70
|
+
**このリリースを準備したサンドボックス環境では、著者は`rbwasm build`を最後
|
|
71
|
+
まで実行できなかった。** ただしこの障害は`glslkit-webgl`とは無関係:
|
|
72
|
+
`rbwasm build`は最初にネイティブの「baseruby」ツールチェーンをビルドするが、
|
|
73
|
+
このサンドボックスのカーネル拡張へのアクセスが制限されていたため、CRuby
|
|
74
|
+
自身の`dtrace`/`probes.d`のコンパイルで失敗した(`Failed to query kext info
|
|
75
|
+
(MAC policy error 0x1)`、`error: unable to open output file '/dev/fd/7':
|
|
76
|
+
'Operation not permitted'`)。これはどのgemのコードにも到達する遥か手前で
|
|
77
|
+
起きており、この環境でバンドルするどんなgemでも同様に失敗するはず。
|
|
78
|
+
制約の無いマシンで成功した場合は報告してもらえるとありがたい。
|
|
79
|
+
|
|
80
|
+
[ruby_wasm]: https://github.com/ruby/ruby.wasm
|
|
28
81
|
|
|
29
|
-
##
|
|
82
|
+
## ランタイムAPI
|
|
30
83
|
|
|
31
84
|
```ruby
|
|
32
85
|
require "glslkit/webgl"
|
|
@@ -52,47 +105,47 @@ ctx.loop do |seconds|
|
|
|
52
105
|
end
|
|
53
106
|
```
|
|
54
107
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
108
|
+
未知のuniformや不正な`element_count`は即座に例外を投げる。GLSLの最適化で
|
|
109
|
+
削除されたlocationは黙って無視される。ジオメトリデータは型付き配列の`from`で
|
|
110
|
+
一度だけアップロードされ、意図的にミューテーションAPIは無い。
|
|
58
111
|
|
|
59
|
-
##
|
|
112
|
+
## シェーダエラーとソースマップ
|
|
60
113
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
`
|
|
64
|
-
`file
|
|
65
|
-
|
|
114
|
+
各ステージの`Glslkit::SourceMap`を`source_maps:`に渡す。認識できたドライバの
|
|
115
|
+
行番号は元のincludeされたファイルに解決される。`CompileError`は`stage`・
|
|
116
|
+
`file`・`line`・`raw_log`を公開する。未知のログ形式でも例外は投げるが、
|
|
117
|
+
`file`と`line`は`nil`になる。リンク失敗は`LinkError`を投げる。JSのログの値は
|
|
118
|
+
パース前に`#to_s`で変換する。
|
|
66
119
|
|
|
67
|
-
##
|
|
120
|
+
## デバッグモード
|
|
68
121
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
122
|
+
`Glslkit::WebGL.debug = true`にすると、各フレームの終わりに`getError`を
|
|
123
|
+
1回呼ぶ。デフォルトは`false`で、`getError`はWebGLのコマンドキューを同期
|
|
124
|
+
させるため、有効なままにしないこと。
|
|
72
125
|
|
|
73
|
-
##
|
|
126
|
+
## 性能とスコープの制限
|
|
74
127
|
|
|
75
|
-
|
|
128
|
+
以下のCPU側のワークロードはv0.1では未対応:
|
|
76
129
|
|
|
77
|
-
-
|
|
78
|
-
- CPU
|
|
79
|
-
- CPU
|
|
80
|
-
- CPU
|
|
130
|
+
- 毎フレームの頂点データ差し替え
|
|
131
|
+
- CPUスキニング
|
|
132
|
+
- モーフターゲットのCPU補間
|
|
133
|
+
- パーティクル(CPU側で毎フレーム更新するもの)
|
|
81
134
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
135
|
+
設計時の計測では、100,000要素のfloatの転送だけで18.8msかかり、60fpsの
|
|
136
|
+
フレーム予算を超える。ジオメトリは静的に保ち、頂点の変形はシェーダ側で行い、
|
|
137
|
+
行列とウェイトだけをuniformとして送ること。フレームごとのボーン行列計算の
|
|
138
|
+
コストは未計測。
|
|
86
139
|
|
|
87
|
-
|
|
88
|
-
|
|
140
|
+
このランタイムはWebGL2専用。WebGL1へのフォールバック、シーングラフ、
|
|
141
|
+
マテリアルシステム、glTF/VRMローダーは無い。
|
|
89
142
|
|
|
90
|
-
## JS
|
|
143
|
+
## JSの値の安全な扱い(R6)
|
|
91
144
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
145
|
+
`JS::Object`かもしれない値に対して`#class`を呼ばないこと。JavaScriptの
|
|
146
|
+
プリミティブは`Reflect.has`で例外になることがある。判定には`is_a?(JS::Object)`
|
|
147
|
+
を、表示には`#inspect`・`#typeof`・`#to_s`を使う。実装のRubyファイルに対して
|
|
148
|
+
意図しない`.class`呼び出しをスキャンするテストがある。
|
|
96
149
|
|
|
97
|
-
|
|
98
|
-
|
|
150
|
+
通常のCRubyでは、ruby.wasmの`js`ライブラリが必要なため、即座に明確な
|
|
151
|
+
メッセージ付きで失敗する。
|
data/glslkit-webgl.gemspec
CHANGED
|
@@ -25,13 +25,16 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
spec.metadata["source_code_uri"] = "#{spec.homepage}/tree/main/webgl"
|
|
26
26
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/webgl/CHANGELOG.md"
|
|
27
27
|
|
|
28
|
+
# M12c: sample/ を丸ごと同梱する(README のQuick Startが
|
|
29
|
+
# `webgl/sample/index.html` を開く前提になっており、gem展開後もそのまま
|
|
30
|
+
# 動く一次資料として扱うため)。sample/shaders-broken/・
|
|
31
|
+
# sample/generated-broken/ を含む点は当初 `Dir.glob("sample/**/*")` の
|
|
32
|
+
# 幅広さによる偶然の同梱だったが、これらはneon-error.htmlの動作に必須
|
|
33
|
+
# (CompileErrorが元ファイル名・行番号を指すという中核機能の実演)であり、
|
|
34
|
+
# ディレクトリ名も自明なので、除外せず同梱を意図的な判断とする。
|
|
28
35
|
spec.files = Dir.glob("lib/**/*.rb") + Dir.glob("shim/**/*.js") + Dir.glob("sample/**/*") +
|
|
29
36
|
["glslkit-webgl.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"]
|
|
30
37
|
spec.require_paths = ["lib"]
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
# 満たさない(`"~> 0.1.0".satisfied_by?("0.1.0.pre")` は常にfalse)。
|
|
34
|
-
# 0.1.0.pre のリリース期間中だけこの範囲にし、正式な0.1.0を切ったら
|
|
35
|
-
# `~> 0.1.0` に戻すこと。
|
|
36
|
-
spec.add_dependency "glslkit", ">= 0.1.0.pre", "< 0.2.0"
|
|
39
|
+
spec.add_dependency "glslkit", "~> 0.1.0"
|
|
37
40
|
end
|
data/lib/glslkit/webgl.rb
CHANGED
|
@@ -20,8 +20,29 @@ begin
|
|
|
20
20
|
rescue LoadError => error
|
|
21
21
|
raise unless error.path == "glslkit/runtime"
|
|
22
22
|
|
|
23
|
-
#
|
|
24
|
-
#
|
|
23
|
+
# M12d: このフォールバックは、このリポジトリ(webgl/sample/*)を
|
|
24
|
+
# チェックアウトしたまま `JS::RequireRemote` でブラウザから直接読んだ
|
|
25
|
+
# 場合専用(`glslkit`がgemとしてインストールされていないため上のrequireが
|
|
26
|
+
# 必ず失敗する)。パスは `webgl/lib/glslkit/webgl.rb` から見て
|
|
27
|
+
# `core/lib/glslkit/runtime.rb` への3階層上がりの相対パスで、
|
|
28
|
+
# このリポジトリのディレクトリ構成に固定的に依存する。
|
|
29
|
+
#
|
|
30
|
+
# gemとして正しくインストールされた環境(rbwasmでのバンドル含む)では
|
|
31
|
+
# 通常のrequireが必ず成功するため、この分岐には絶対に入らないはず。
|
|
32
|
+
# `Glslkit::WebGL.debug`はまだ定義される前(このファイルの読み込み中)
|
|
33
|
+
# なので、フラグに関わらず無条件でログを出す。ただし `webgl/sample/*` や
|
|
34
|
+
# `examples/rails-demo/` を開くたびに毎回このログが出るのは正常な動作
|
|
35
|
+
# なので、`console.warn`(黄色い警告アイコン)ではなく`console.info`に
|
|
36
|
+
# している — 動画・スクリーンショットに映っても「エラーが起きている」
|
|
37
|
+
# ように見えないようにするため。
|
|
38
|
+
JS.global[:console].call(:info,
|
|
39
|
+
"glslkit-webgl: using the repository-relative core fallback " \
|
|
40
|
+
"(require_relative ../../../core/lib/glslkit/runtime) instead of " \
|
|
41
|
+
"\"require 'glslkit/runtime'\" (LoadError: #{error.message}). This is " \
|
|
42
|
+
"expected and normal when running this repository's own samples " \
|
|
43
|
+
"(webgl/sample, examples/rails-demo) via JS::RequireRemote — glslkit " \
|
|
44
|
+
"is not installed as a real gem there. If you see this message while " \
|
|
45
|
+
"using an installed glslkit-webgl gem, that IS a bug — please report it.")
|
|
25
46
|
require_relative "../../../core/lib/glslkit/runtime"
|
|
26
47
|
end
|
|
27
48
|
|
data/shim/glslkit-webgl.js
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
if (location.protocol === "file:") {
|
|
5
|
+
const message =
|
|
6
|
+
"glslkit-webgl: this page was opened as a file:// URL. ruby.wasm loads " +
|
|
7
|
+
"its Ruby entry file via fetch(), which browsers restrict for file:// " +
|
|
8
|
+
'origins (Safari fails outright: "Fetch API cannot load file:///... due ' +
|
|
9
|
+
'to access control checks."; Chrome currently tolerates it but may stop). ' +
|
|
10
|
+
"Serve this directory over HTTP instead, e.g.:\n" +
|
|
11
|
+
" python3 -m http.server 8000\n" +
|
|
12
|
+
"and open it as http://localhost:8000/... instead of file://.";
|
|
13
|
+
const banner = document.createElement("pre");
|
|
14
|
+
banner.textContent = message;
|
|
15
|
+
banner.style.cssText =
|
|
16
|
+
"position:fixed;inset:0;z-index:2147483647;margin:0;padding:24px;" +
|
|
17
|
+
"background:#1a0d0d;color:#ffb4b4;font:14px/1.6 monospace;" +
|
|
18
|
+
"white-space:pre-wrap;overflow:auto;";
|
|
19
|
+
(document.body || document.documentElement).appendChild(banner);
|
|
20
|
+
console.error(message);
|
|
21
|
+
window.glslkitWebGLReady = Promise.reject(new Error(message));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
4
25
|
const script = document.currentScript;
|
|
5
26
|
const entry = script && script.dataset.entry;
|
|
6
27
|
const rubyVersion = (script && script.dataset.rubyVersion) || "4.0";
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: glslkit-webgl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- kyubey1228
|
|
@@ -13,22 +13,16 @@ dependencies:
|
|
|
13
13
|
name: glslkit
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.1.0
|
|
19
|
-
- - "<"
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: 0.2.0
|
|
18
|
+
version: 0.1.0
|
|
22
19
|
type: :runtime
|
|
23
20
|
prerelease: false
|
|
24
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
22
|
requirements:
|
|
26
|
-
- - "
|
|
27
|
-
- !ruby/object:Gem::Version
|
|
28
|
-
version: 0.1.0.pre
|
|
29
|
-
- - "<"
|
|
23
|
+
- - "~>"
|
|
30
24
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: 0.
|
|
25
|
+
version: 0.1.0
|
|
32
26
|
description: Lets you write WebGL2 rendering code entirely in Ruby, running under
|
|
33
27
|
ruby.wasm in the browser. Resolves uniform/attribute locations from a glslkit reflection
|
|
34
28
|
manifest instead of calling getActiveUniform, and surfaces shader compile errors
|