mirror of
https://github.com/penpot/penpot.git
synced 2025-12-12 06:24:17 +01:00
Merge pull request #7504 from penpot/azazeln28-feat-webgl-error
🎉 Add debug and alert when WebGL is unsupported
This commit is contained in:
@@ -296,8 +296,9 @@
|
|||||||
(->> wasm.api/module
|
(->> wasm.api/module
|
||||||
(p/fmap (fn [ready?]
|
(p/fmap (fn [ready?]
|
||||||
(when ready?
|
(when ready?
|
||||||
(reset! canvas-init? true)
|
(let [init? (wasm.api/init-canvas-context canvas)]
|
||||||
(wasm.api/assign-canvas canvas)))))
|
(reset! canvas-init? init?)
|
||||||
|
(when-not init? (js/alert "WebGL not supported")))))))
|
||||||
(fn []
|
(fn []
|
||||||
(wasm.api/clear-canvas))))
|
(wasm.api/clear-canvas))))
|
||||||
|
|
||||||
|
|||||||
@@ -954,7 +954,7 @@
|
|||||||
(h/call wasm/internal-module "_init_shapes_pool" total-shapes)
|
(h/call wasm/internal-module "_init_shapes_pool" total-shapes)
|
||||||
(set-objects base-objects)))
|
(set-objects base-objects)))
|
||||||
|
|
||||||
(def ^:private canvas-options
|
(def ^:private context-options
|
||||||
#js {:antialias false
|
#js {:antialias false
|
||||||
:depth true
|
:depth true
|
||||||
:stencil true
|
:stencil true
|
||||||
@@ -971,13 +971,20 @@
|
|||||||
(dbg/enabled? :wasm-viewbox)
|
(dbg/enabled? :wasm-viewbox)
|
||||||
(bit-or 2r00000000000000000000000000000001)))
|
(bit-or 2r00000000000000000000000000000001)))
|
||||||
|
|
||||||
(defn assign-canvas
|
(defn set-canvas-size
|
||||||
|
[canvas]
|
||||||
|
(set! (.-width canvas) (* dpr (.-clientWidth ^js canvas)))
|
||||||
|
(set! (.-height canvas) (* dpr (.-clientHeight ^js canvas))))
|
||||||
|
|
||||||
|
(defn init-canvas-context
|
||||||
[canvas]
|
[canvas]
|
||||||
(let [gl (unchecked-get wasm/internal-module "GL")
|
(let [gl (unchecked-get wasm/internal-module "GL")
|
||||||
flags (debug-flags)
|
flags (debug-flags)
|
||||||
context (.getContext ^js canvas "webgl2" canvas-options)
|
context-id (if (dbg/enabled? :wasm-gl-context-init-error) "fail" "webgl2")
|
||||||
;; Register the context with emscripten
|
context (.getContext ^js canvas context-id context-options)
|
||||||
handle (.registerContext ^js gl context #js {"majorVersion" 2})]
|
context-init? (not (nil? context))]
|
||||||
|
(when-not (nil? context)
|
||||||
|
(let [handle (.registerContext ^js gl context #js {"majorVersion" 2})]
|
||||||
(.makeContextCurrent ^js gl handle)
|
(.makeContextCurrent ^js gl handle)
|
||||||
|
|
||||||
;; Force the WEBGL_debug_renderer_info extension as emscripten does not enable it
|
;; Force the WEBGL_debug_renderer_info extension as emscripten does not enable it
|
||||||
@@ -985,9 +992,9 @@
|
|||||||
|
|
||||||
;; Initialize Wasm Render Engine
|
;; Initialize Wasm Render Engine
|
||||||
(h/call wasm/internal-module "_init" (/ (.-width ^js canvas) dpr) (/ (.-height ^js canvas) dpr))
|
(h/call wasm/internal-module "_init" (/ (.-width ^js canvas) dpr) (/ (.-height ^js canvas) dpr))
|
||||||
(h/call wasm/internal-module "_set_render_options" flags dpr))
|
(h/call wasm/internal-module "_set_render_options" flags dpr)))
|
||||||
(set! (.-width canvas) (* dpr (.-clientWidth ^js canvas)))
|
(set-canvas-size canvas)
|
||||||
(set! (.-height canvas) (* dpr (.-clientHeight ^js canvas))))
|
context-init?))
|
||||||
|
|
||||||
(defn clear-canvas
|
(defn clear-canvas
|
||||||
[]
|
[]
|
||||||
|
|||||||
@@ -96,9 +96,12 @@
|
|||||||
;; Show some information about the WebGL context.
|
;; Show some information about the WebGL context.
|
||||||
:gl-context
|
:gl-context
|
||||||
|
|
||||||
;; Show viewbox
|
;; Show viewbox.
|
||||||
:wasm-viewbox
|
:wasm-viewbox
|
||||||
|
|
||||||
|
;; Makes the GL context to fail on initialization.
|
||||||
|
:wasm-gl-context-init-error
|
||||||
|
|
||||||
;; Event times
|
;; Event times
|
||||||
:events-times})
|
:events-times})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user