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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ae64d28127a6a9f72c2c3017ba1b7e11739e7f374634be7e2a6a6eecbf663a7
4
- data.tar.gz: 152a82f8f5be95b90b2d15a8c9b5976d55737164e7d6b69060b89433cfcb56da
3
+ metadata.gz: 18dde294abf04720f5ff6bf189c482bce2bb960b1ee538ddbae9e3de8f1bd974
4
+ data.tar.gz: 615c0d0e5c142b4fe7061e5508fb7f6c2fb9b5deb2bdd5bf8c9102f534b7828a
5
5
  SHA512:
6
- metadata.gz: c97c9dcbd8d95bd2257241915974ee053994659281f49da8e78df7a4a2b594e377587410d31a7008f6ec994a3ee0b8c91be93a05339e93aecce6ad881409053b
7
- data.tar.gz: 16c71ae9f9f16e146c5d82b4e4e8fbdab1af3ca6e584ab263576c87a929d88503d02d729758ff5ae18ead15a67dcdb75a627e40fb0ea68e5c0675b0e971ea5a1
6
+ metadata.gz: 6ee0a2fdc0131b5ea1e3a8d2a2066af9624c07ccb787aced1a27cd9a4d2e009ee546fba4e7079458bea4bc619e898bed98799c88a69ed34f1f21042f2cd04f5d
7
+ data.tar.gz: d2db73d0147589a1e58cbf84bee2d68469c791e882fb3bc1bbeaf7bba2f1747a2b4db9b9a059226a59c54f3b0d97aae5480457f1a04e1d569aabcc0e44eb4cea
data/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased]
3
+ ## [0.1.0] - 2026-08-24
4
4
 
5
5
  初回リリース (v0.1)。**ruby.wasm 環境専用。** 通常の CRuby/JRuby/TruffleRuby
6
6
  にはインストールできるが、`require "js"` に依存するため実行できない。
data/README.md CHANGED
@@ -1,20 +1,42 @@
1
1
  # glslkit-webgl
2
2
 
3
- `glslkit-webgl` is a WebGL2 runtime for Ruby programs running in a browser with
4
- ruby.wasm. It consumes a `glslkit` reflection manifest, caches WebGL references,
5
- and reports shader compiler errors as Ruby exceptions.
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
- Serve this repository over HTTP and open `webgl/sample/index.html`. The sample
10
- draws a rotating, textured cube without application JavaScript, built from
11
- `webgl/sample/shaders/cube.{vert,frag}` via `rake glslkit:embed`.
12
- `webgl/sample/neon.html` is an animated fragment-shader raymarching demo, built
13
- from `webgl/sample/shaders/neon.*` the same way.
14
- `webgl/sample/neon-error.html` intentionally breaks `common/sdf.glsl` (an
15
- `#include`d file, not the top-level shader) to demonstrate that `CompileError`
16
- reports the original included file and line, with a button to switch back to
17
- the working shaders and start rendering.
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
- The shim only starts ruby.wasm. `JS::RequireRemote` fetches Ruby files and all
26
- rendering logic remains in Ruby. `window.glslkitWebGLReady` settles when the entry
27
- file finishes loading. Packaged wasm builds should install both gems normally.
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
- ## Runtime API
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
- Unknown uniforms and incorrect `element_count` values raise immediately.
56
- Locations optimized away by GLSL are silently ignored. Geometry data is uploaded
57
- once with typed-array `from`; there is intentionally no mutation API.
108
+ 未知のuniformや不正な`element_count`は即座に例外を投げる。GLSLの最適化で
109
+ 削除されたlocationは黙って無視される。ジオメトリデータは型付き配列の`from`で
110
+ 一度だけアップロードされ、意図的にミューテーションAPIは無い。
58
111
 
59
- ## Shader errors and source maps
112
+ ## シェーダエラーとソースマップ
60
113
 
61
- Pass each stage's `Glslkit::SourceMap` through `source_maps:`. Recognized driver
62
- line numbers are resolved to the original included file. `CompileError` exposes
63
- `stage`, `file`, `line`, and `raw_log`. Unknown log formats still raise, with
64
- `file` and `line` set to `nil`. Link failures raise `LinkError`. JS log values are
65
- converted with `#to_s` before parsing.
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
- ## Debug mode
120
+ ## デバッグモード
68
121
 
69
- Set `Glslkit::WebGL.debug = true` to call `getError` once at each frame end. It
70
- defaults to `false` and should not remain enabled because `getError` synchronizes
71
- the WebGL command queue.
122
+ `Glslkit::WebGL.debug = true`にすると、各フレームの終わりに`getError`を
123
+ 1回呼ぶ。デフォルトは`false`で、`getError`はWebGLのコマンドキューを同期
124
+ させるため、有効なままにしないこと。
72
125
 
73
- ## Performance and scope limits
126
+ ## 性能とスコープの制限
74
127
 
75
- The following CPU-side workloads are unsupported in v0.1:
128
+ 以下のCPU側のワークロードはv0.1では未対応:
76
129
 
77
- - replacing vertex data every frame;
78
- - CPU skinning;
79
- - CPU morph-target interpolation;
80
- - CPU-updated particle geometry.
130
+ - 毎フレームの頂点データ差し替え
131
+ - CPUスキニング
132
+ - モーフターゲットのCPU補間
133
+ - パーティクル(CPU側で毎フレーム更新するもの)
81
134
 
82
- Transferring 100,000 floats took 18.8 ms in the design measurements, exceeding a
83
- 60 fps frame budget. Keep geometry static, deform vertices in shaders, and send
84
- only matrices and weights through uniforms. Per-frame bone-matrix calculation
85
- cost remains unmeasured.
135
+ 設計時の計測では、100,000要素のfloatの転送だけで18.8msかかり、60fpsの
136
+ フレーム予算を超える。ジオメトリは静的に保ち、頂点の変形はシェーダ側で行い、
137
+ 行列とウェイトだけをuniformとして送ること。フレームごとのボーン行列計算の
138
+ コストは未計測。
86
139
 
87
- The runtime is WebGL2-only. It has no WebGL1 fallback, scene graph, material
88
- system, or glTF/VRM loader.
140
+ このランタイムはWebGL2専用。WebGL1へのフォールバック、シーングラフ、
141
+ マテリアルシステム、glTF/VRMローダーは無い。
89
142
 
90
- ## JS value safety (R6)
143
+ ## JSの値の安全な扱い(R6)
91
144
 
92
- Never call `#class` on a value that may be a `JS::Object`; JavaScript primitives
93
- can fail in `Reflect.has`. Use `is_a?(JS::Object)` for checks and `#inspect`,
94
- `#typeof`, or `#to_s` for display. A test scans implementation Ruby files for
95
- accidental `.class` calls.
145
+ `JS::Object`かもしれない値に対して`#class`を呼ばないこと。JavaScript
146
+ プリミティブは`Reflect.has`で例外になることがある。判定には`is_a?(JS::Object)`
147
+ を、表示には`#inspect`・`#typeof`・`#to_s`を使う。実装のRubyファイルに対して
148
+ 意図しない`.class`呼び出しをスキャンするテストがある。
96
149
 
97
- Normal CRuby fails immediately with a clear message because ruby.wasm's `js`
98
- library is required.
150
+ 通常のCRubyでは、ruby.wasmの`js`ライブラリが必要なため、即座に明確な
151
+ メッセージ付きで失敗する。
@@ -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
- # M12c: `~> 0.1.0` は `Gem::Requirement` の仕様上プレリリース版を一切
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Glslkit
4
4
  module WebGL
5
- VERSION = "0.1.0.pre"
5
+ VERSION = "0.1.0"
6
6
  end
7
7
  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
- # Source-tree browser samples are loaded by JS::RequireRemote rather than an
24
- # installed gem. Packaged users take the normal require path above.
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
 
@@ -34,7 +34,7 @@ GLSLKIT_FRAGMENT_SRC
34
34
 
35
35
  MANIFEST = {"schema_version"=>1,
36
36
  "generated_at"=>"1970-01-01T00:00:00Z",
37
- "generator"=>"glslkit/0.1.0.pre",
37
+ "generator"=>"glslkit/0.1.0",
38
38
  "programs"=>
39
39
  {"cube"=>
40
40
  {"digest"=>
@@ -113,7 +113,7 @@ GLSLKIT_FRAGMENT_SRC
113
113
 
114
114
  MANIFEST = {"schema_version"=>1,
115
115
  "generated_at"=>"1970-01-01T00:00:00Z",
116
- "generator"=>"glslkit/0.1.0.pre",
116
+ "generator"=>"glslkit/0.1.0",
117
117
  "programs"=>
118
118
  {"neon"=>
119
119
  {"digest"=>
@@ -113,7 +113,7 @@ GLSLKIT_FRAGMENT_SRC
113
113
 
114
114
  MANIFEST = {"schema_version"=>1,
115
115
  "generated_at"=>"1970-01-01T00:00:00Z",
116
- "generator"=>"glslkit/0.1.0.pre",
116
+ "generator"=>"glslkit/0.1.0",
117
117
  "programs"=>
118
118
  {"neon-broken"=>
119
119
  {"digest"=>
@@ -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.pre
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.pre
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.2.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