xbintsc 0.7.0 → 0.7.7
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.
- package/dist/src/ast/common.d.ts +10 -0
- package/dist/src/binder/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +4 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +82 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +10 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +4 -24
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- package/dist/src/codegen/generator/state.js +4 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.js +11 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +2 -2
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +11 -5
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +3 -0
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +4 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +53 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +20 -0
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/parser/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +13 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- package/dist/tests/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +13 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
- package/dist/tests/e2e/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +66 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- package/dist/tests/e2e/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +35 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +43 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +1 -1
- package/doc/implemented/checker.md +9 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/parser.md +2 -1
- package/doc/implemented/runtime-core.md +9 -2
- package/doc/implemented/stdlib.md +10 -2
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/zh-CN/gui/api.md +27 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +30 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +1 -1
- package/doc/zh-CN/implemented/checker.md +7 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/parser.md +2 -1
- package/doc/zh-CN/implemented/runtime-core.md +9 -2
- package/doc/zh-CN/implemented/stdlib.md +6 -2
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +11 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +11 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +6 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +8 -1
- package/runtime/ext_gui/gui_engine.h +20 -2
- package/runtime/ext_gui/gui_events.cpp +31 -126
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +26 -170
- package/runtime/ext_gui/webgl_context.cpp +119 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl.h +4 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +18 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_shader.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +11 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/runtime/rt.h +27 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +52 -60
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +88 -133
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_builtins.c +3 -1
- package/runtime/xt_constructors.c +1 -0
- package/runtime/xt_containers/access.inc +96 -11
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +47 -79
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +4 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +1 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +32 -6
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_stdlib/dispatch.inc +7 -1
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/json_stringify.inc +1 -2
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/src/ast/common.ts +10 -0
- package/src/binder/references.ts +13 -7
- package/src/checker/source.ts +3 -0
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +5 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +87 -1
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +11 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/primary.ts +4 -27
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/state.ts +5 -0
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/concatenate.ts +12 -5
- package/src/driver/bundler/graph.ts +2 -2
- package/src/driver/bundler/merge.ts +11 -4
- package/src/driver/bundler/reexport-resolution.ts +2 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/frontend.ts +3 -4
- package/src/driver/runtime-objects.ts +4 -0
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +55 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
package/runtime/ext_gui/webgl.h
CHANGED
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
* blending all execute on the GPU.
|
|
9
9
|
*
|
|
10
10
|
* WebGL's origin is bottom-left while SDL_GPU render targets use a top-left
|
|
11
|
-
* origin (its Vulkan backend flips the viewport)
|
|
12
|
-
* top-down
|
|
13
|
-
*
|
|
11
|
+
* origin (its Vulkan backend flips the viewport). The default drawing buffer is
|
|
12
|
+
* stored top-down, because the page compositor presents its texture with the
|
|
13
|
+
* origin at the top: its `viewport`/`scissor` are converted and `readPixels`
|
|
14
|
+
* flips rows back. A user framebuffer's attachments are stored bottom-up, the
|
|
15
|
+
* way a texture is sampled, so `v = 0` is its bottom row; blits between the two
|
|
16
|
+
* conventions go through a sampling pass (`SDL_BlitGPUTexture` cannot flip).
|
|
17
|
+
* See `webgl_target_top_down`.
|
|
14
18
|
*
|
|
15
19
|
* Shaders are translated to SPIR-V by `webgl_glsl.cpp` (glslang). Pipeline
|
|
16
20
|
* objects depend on the vertex layout and fixed-function state, so they are
|
|
@@ -39,6 +43,31 @@
|
|
|
39
43
|
|
|
40
44
|
namespace xtgui {
|
|
41
45
|
|
|
46
|
+
/** Whether framebuffer `id`'s attachments are stored top-down, with SDL_GPU's
|
|
47
|
+
* row 0 at the top, instead of WebGL's bottom-up texture convention.
|
|
48
|
+
*
|
|
49
|
+
* Only the default drawing buffer is top-down: the page compositor samples its
|
|
50
|
+
* texture with (0, 0) at the top-left, so its first row has to be the image's
|
|
51
|
+
* top. A user framebuffer's colour/depth texture is sampled by shaders, where
|
|
52
|
+
* `v = 0` is the framebuffer's bottom row, so those targets are stored
|
|
53
|
+
* bottom-up and a draw into one maps GL window y straight to a texture row. */
|
|
54
|
+
inline bool webgl_target_top_down(uint32_t framebuffer_id) { return framebuffer_id == 0; }
|
|
55
|
+
|
|
56
|
+
/** The SDL row boundary of GL window coordinate `y` inside a target of
|
|
57
|
+
* `height` rows, for the target's storage convention. GL's y counts from the
|
|
58
|
+
* bottom, so a top-down target maps it to `height - y`; a bottom-up target maps
|
|
59
|
+
* it straight through. */
|
|
60
|
+
inline int webgl_target_row(bool top_down, int height, int y) {
|
|
61
|
+
return top_down ? height - y : y;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The first (top-most) SDL row covered by the GL window rectangle `[y, y + h)`
|
|
65
|
+
* — the origin an `SDL_GPUTextureRegion`, `SDL_GPUBlitRegion` or scissor rect
|
|
66
|
+
* needs. */
|
|
67
|
+
inline int webgl_target_rect_y(bool top_down, int height, int y, int h) {
|
|
68
|
+
return top_down ? height - (y + h) : y;
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
struct WebGLShader {
|
|
43
72
|
uint32_t id = 0;
|
|
44
73
|
int type = 0; // GL_VERTEX_SHADER / GL_FRAGMENT_SHADER
|
|
@@ -89,13 +118,21 @@ struct WebGLProgram {
|
|
|
89
118
|
|
|
90
119
|
class WebGLContext {
|
|
91
120
|
public:
|
|
92
|
-
WebGLContext(uint64_t id, int width, int height, bool webgl2);
|
|
121
|
+
WebGLContext(uint64_t id, int width, int height, bool webgl2, bool antialias);
|
|
93
122
|
~WebGLContext();
|
|
94
123
|
|
|
95
124
|
uint64_t id() const { return id_; }
|
|
96
125
|
bool is_webgl2() const { return webgl2_; }
|
|
97
126
|
int width() const { return width_; }
|
|
98
127
|
int height() const { return height_; }
|
|
128
|
+
/** Whether the drawing buffer is multisampled (`antialias` and a backend
|
|
129
|
+
* whose resolve is reliable). */
|
|
130
|
+
bool antialias() const { return default_samples_ > 1; }
|
|
131
|
+
int default_samples() const { return default_samples_; }
|
|
132
|
+
/** Highest sample count this context can allocate (0 when unsupported). */
|
|
133
|
+
int max_samples() const { return multisample_supported_ ? kWebGLMaxSamples : 0; }
|
|
134
|
+
/** Sample count of the colour attachment a draw would render into. */
|
|
135
|
+
int target_samples();
|
|
99
136
|
/** Resize the drawing buffer; GL semantics discard its contents. */
|
|
100
137
|
void resize(int width, int height);
|
|
101
138
|
|
|
@@ -257,6 +294,10 @@ class WebGLContext {
|
|
|
257
294
|
bool tex_storage_2d(uint32_t id, int levels, int width, int height);
|
|
258
295
|
bool tex_storage_format(uint32_t id, int levels, int width, int height,
|
|
259
296
|
SDL_GPUTextureFormat format);
|
|
297
|
+
/** `texStorage2DMultisample` / `texImage2DMultisample`: a render-target-only
|
|
298
|
+
* texture with `samples` samples per texel. */
|
|
299
|
+
bool tex_storage_2d_multisample(uint32_t id, int samples, SDL_GPUTextureFormat format,
|
|
300
|
+
int width, int height);
|
|
260
301
|
/** Allocate (and optionally upload) a 3D or 2D-array texture. */
|
|
261
302
|
bool tex_storage_3d(uint32_t id, int levels, int width, int height, int depth,
|
|
262
303
|
SDL_GPUTextureFormat format, int target);
|
|
@@ -289,7 +330,8 @@ class WebGLContext {
|
|
|
289
330
|
int attachment = GL_COLOR_ATTACHMENT0);
|
|
290
331
|
bool framebuffer_texture_layer(uint32_t framebuffer, uint32_t texture, int attachment,
|
|
291
332
|
int layer);
|
|
292
|
-
|
|
333
|
+
/** The `checkFramebufferStatus` enum for `id` (COMPLETE, INCOMPLETE_*). */
|
|
334
|
+
int framebuffer_status(uint32_t id);
|
|
293
335
|
/** WebGL 2 `drawBuffers` / `readBuffer`. */
|
|
294
336
|
void draw_buffers(int count, const int *buffers);
|
|
295
337
|
void read_buffer(int mode) { read_buffer_ = mode; }
|
|
@@ -298,8 +340,8 @@ class WebGLContext {
|
|
|
298
340
|
uint32_t create_renderbuffer();
|
|
299
341
|
void delete_renderbuffer(uint32_t id);
|
|
300
342
|
void bind_renderbuffer(uint32_t id) { bound_renderbuffer_ = id; }
|
|
301
|
-
bool renderbuffer_storage(uint32_t id, int width, int height,
|
|
302
|
-
bool framebuffer_renderbuffer(uint32_t framebuffer, uint32_t renderbuffer);
|
|
343
|
+
bool renderbuffer_storage(uint32_t id, int width, int height, int internalformat, int samples);
|
|
344
|
+
bool framebuffer_renderbuffer(uint32_t framebuffer, int attachment, uint32_t renderbuffer);
|
|
303
345
|
|
|
304
346
|
/* -- drawing ----------------------------------------------------------- */
|
|
305
347
|
void draw_arrays(int mode, int first, int count);
|
|
@@ -316,6 +358,9 @@ class WebGLContext {
|
|
|
316
358
|
std::string string_parameter(int pname);
|
|
317
359
|
uint32_t bound_buffer(int target) const;
|
|
318
360
|
uint32_t bound_texture(int unit) const;
|
|
361
|
+
/** The texture bound to the *active* unit: `texImage2D`, `texParameteri` and
|
|
362
|
+
* `generateMipmap` mutate the binding of the active unit, not unit 0. */
|
|
363
|
+
uint32_t bound_texture() const;
|
|
319
364
|
uint32_t bound_cube_texture(int unit) const;
|
|
320
365
|
uint32_t bound_array_texture(int unit) const;
|
|
321
366
|
uint32_t bound_3d_texture(int unit) const;
|
|
@@ -347,6 +392,32 @@ class WebGLContext {
|
|
|
347
392
|
SDL_GPUTexture *framebuffer_color(uint32_t id);
|
|
348
393
|
SDL_GPUTexture *framebuffer_depth(uint32_t id);
|
|
349
394
|
void framebuffer_size(uint32_t id, int *width, int *height);
|
|
395
|
+
/** Sample count of one draw-buffer slot's attachment (1 when none). */
|
|
396
|
+
int draw_color_samples(int slot);
|
|
397
|
+
/** Sample count of `id`'s colour attachment (the bound one for 0). */
|
|
398
|
+
int framebuffer_samples(uint32_t id);
|
|
399
|
+
/** Colour attachment `index` of `id`: its GPU texture, format, samples and
|
|
400
|
+
* size. Returns null when nothing is attached. */
|
|
401
|
+
SDL_GPUTexture *color_attachment(uint32_t id, int index, int *format, int *samples,
|
|
402
|
+
int *width, int *height);
|
|
403
|
+
/** The single-sampled texture holding the read buffer's current pixels:
|
|
404
|
+
* the resolved drawing buffer, a colour attachment, or a resolved copy. */
|
|
405
|
+
SDL_GPUTexture *read_color_texture(uint32_t id, int *width, int *height, int *format);
|
|
406
|
+
/** One scratch texture that receives a multisampled colour resolve. */
|
|
407
|
+
SDL_GPUTexture *ensure_resolve_target(int width, int height, SDL_GPUTextureFormat format);
|
|
408
|
+
/** Resolve `source` (multisampled) into `destination` (1×1-sampled) with a
|
|
409
|
+
* render pass that draws nothing and resolves on store. */
|
|
410
|
+
bool resolve_color_pass(SDL_GPUTexture *source, SDL_GPUTexture *destination);
|
|
411
|
+
/** Draw a textured quad from a GL rectangle of `source` into the bound
|
|
412
|
+
* framebuffer. `source_rect` and `destination` are GL window rectangles
|
|
413
|
+
* (`{x0, y0, x1, y1}`, bottom-left origin) and are mapped through each
|
|
414
|
+
* target's storage convention, so a copy between a top-down and a bottom-up
|
|
415
|
+
* target comes out the right way up. Used for a scissored clear into a
|
|
416
|
+
* multisampled target, a float-format resolve and a blit whose targets
|
|
417
|
+
* disagree on orientation (`SDL_BlitGPUTexture` cannot flip). */
|
|
418
|
+
bool draw_color_quad(SDL_GPUTexture *source, bool source_top_down,
|
|
419
|
+
const int source_rect[4], int source_width, int source_height,
|
|
420
|
+
const int destination[4], bool linear = false);
|
|
350
421
|
/** Release every GPU handle this context owns, keeping the CPU-side object
|
|
351
422
|
* table. Used by the destructor and by `lose_context`. */
|
|
352
423
|
void release_gpu_resources();
|
|
@@ -419,6 +490,18 @@ class WebGLContext {
|
|
|
419
490
|
|
|
420
491
|
SDL_GPUTexture *color_ = nullptr;
|
|
421
492
|
SDL_GPUTexture *depth_ = nullptr;
|
|
493
|
+
/** The multisampled colour target the default framebuffer draws into; every
|
|
494
|
+
* pass resolves it into `color_`, which the page composites. */
|
|
495
|
+
SDL_GPUTexture *color_msaa_ = nullptr;
|
|
496
|
+
/** Scratch resolve destination for a multisampled user framebuffer. */
|
|
497
|
+
SDL_GPUTexture *resolve_texture_ = nullptr;
|
|
498
|
+
int resolve_width_ = 0;
|
|
499
|
+
int resolve_height_ = 0;
|
|
500
|
+
SDL_GPUTextureFormat resolve_format_ = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
501
|
+
/** `antialias` context attribute actually granted; 1 when single-sampled. */
|
|
502
|
+
int default_samples_ = 1;
|
|
503
|
+
/** Whether SDL_GPU can allocate and reliably resolve multisampled targets. */
|
|
504
|
+
bool multisample_supported_ = false;
|
|
422
505
|
SDL_GPUTexture *fallback_texture_ = nullptr;
|
|
423
506
|
SDL_GPUSampler *fallback_sampler_ = nullptr;
|
|
424
507
|
/** 1×1 RGBA8 source for a scissored colour clear. */
|
|
@@ -430,6 +513,10 @@ class WebGLContext {
|
|
|
430
513
|
uint32_t blit_program_ = 0;
|
|
431
514
|
uint32_t blit_buffer_ = 0;
|
|
432
515
|
SDL_GPUSampler *blit_sampler_ = nullptr;
|
|
516
|
+
/** The same sampler with linear filtering, for a scaled blit. */
|
|
517
|
+
SDL_GPUSampler *blit_sampler_linear_ = nullptr;
|
|
518
|
+
/** Internal program for a colour blit into a multisampled target. */
|
|
519
|
+
uint32_t blit_color_program_ = 0;
|
|
433
520
|
|
|
434
521
|
float clear_color_[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
435
522
|
float clear_depth_ = 1.0f;
|
|
@@ -497,6 +584,14 @@ SDL_GPUTextureFormat webgl_storage_format(int internalformat);
|
|
|
497
584
|
* `SDL_GPU_TEXTUREFORMAT_INVALID` for anything else. */
|
|
498
585
|
SDL_GPUTextureFormat webgl_compressed_format(int internalformat);
|
|
499
586
|
|
|
587
|
+
/** Map a WebGL sample count to the backend enum (`1` when unsupported). */
|
|
588
|
+
inline SDL_GPUSampleCount webgl_sample_count(int samples) {
|
|
589
|
+
if (samples >= 8) return SDL_GPU_SAMPLECOUNT_8;
|
|
590
|
+
if (samples >= 4) return SDL_GPU_SAMPLECOUNT_4;
|
|
591
|
+
if (samples >= 2) return SDL_GPU_SAMPLECOUNT_2;
|
|
592
|
+
return SDL_GPU_SAMPLECOUNT_1;
|
|
593
|
+
}
|
|
594
|
+
|
|
500
595
|
} // namespace xtgui
|
|
501
596
|
|
|
502
597
|
#endif /* XT_GUI_WEBGL_H */
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
struct XtGuiWindow;
|
|
19
19
|
|
|
20
20
|
struct XtWebglApi {
|
|
21
|
-
/** Create/find the context of a canvas; `node` is a `xtgui::Node*`.
|
|
22
|
-
|
|
21
|
+
/** Create/find the context of a canvas; `node` is a `xtgui::Node*`.
|
|
22
|
+
* `antialias` is the context-creation attribute (WebGL defaults it to true). */
|
|
23
|
+
void *(*get)(XtGuiWindow *win, const void *node, bool webgl2, bool antialias);
|
|
23
24
|
/** The existing context of a canvas, or null (no side effects). */
|
|
24
25
|
void *(*find)(XtGuiWindow *win, const void *node);
|
|
25
26
|
/** Drop a canvas's context (called when its handle is forgotten). */
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* xbintsc GUI engine — `blitFramebuffer`.
|
|
3
3
|
*
|
|
4
|
-
* SDL_GPU's blit copies a colour texture region to another
|
|
5
|
-
* the colour bit maps directly.
|
|
4
|
+
* SDL_GPU's blit copies a single-sampled colour texture region to another
|
|
5
|
+
* single-sampled colour texture, so the colour bit maps directly. A
|
|
6
|
+
* multisampled source is first resolved into an internal single-sampled
|
|
7
|
+
* texture (the drawing buffer is already resolved, so the default framebuffer
|
|
8
|
+
* needs no extra pass); a multisampled *destination* is an error, as
|
|
9
|
+
* OpenGL ES 3.0 requires. Depth/stencil blits are not supported by the
|
|
6
10
|
* backend; those bits are ignored (the call is still accepted, like a driver
|
|
7
|
-
* that cannot expand the blit).
|
|
8
|
-
* this engine allocates today.
|
|
11
|
+
* that cannot expand the blit).
|
|
9
12
|
*/
|
|
10
13
|
|
|
11
14
|
#include "webgl.h"
|
|
@@ -16,6 +19,18 @@
|
|
|
16
19
|
#include "gui_internal.h"
|
|
17
20
|
|
|
18
21
|
namespace xtgui {
|
|
22
|
+
namespace {
|
|
23
|
+
|
|
24
|
+
bool trace_enabled() {
|
|
25
|
+
static int value = -1;
|
|
26
|
+
if (value < 0) {
|
|
27
|
+
const char *env = SDL_getenv("XT_GUI_TRACE");
|
|
28
|
+
value = (env != nullptr && env[0] != '\0' && env[0] != '0') ? 1 : 0;
|
|
29
|
+
}
|
|
30
|
+
return value != 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
} // namespace
|
|
19
34
|
|
|
20
35
|
bool WebGLContext::blit_framebuffer(const int source[4], const int destination[4], int mask,
|
|
21
36
|
int filter) {
|
|
@@ -25,6 +40,28 @@ bool WebGLContext::blit_framebuffer(const int source[4], const int destination[4
|
|
|
25
40
|
end_pass();
|
|
26
41
|
ensure_command();
|
|
27
42
|
if (cmd_ == nullptr) return false;
|
|
43
|
+
|
|
44
|
+
const int source_samples = framebuffer_samples(read_framebuffer_);
|
|
45
|
+
const int destination_samples = framebuffer_samples(bound_framebuffer_);
|
|
46
|
+
/* GL window rows map to SDL rows differently for the top-down composited
|
|
47
|
+
* drawing buffer and a bottom-up user framebuffer; a copy between the two
|
|
48
|
+
* needs the rows reversed. */
|
|
49
|
+
const bool source_top_down = webgl_target_top_down(read_framebuffer_);
|
|
50
|
+
const bool destination_top_down = webgl_target_top_down(bound_framebuffer_);
|
|
51
|
+
if (trace_enabled()) {
|
|
52
|
+
fprintf(stderr,
|
|
53
|
+
"xt_gui: blit read=%u draw=%u mask=%d samples=%d->%d rects=%d,%d,%d,%d -> %d,%d,%d,%d\n",
|
|
54
|
+
read_framebuffer_, bound_framebuffer_, mask, source_samples, destination_samples,
|
|
55
|
+
source[0], source[1], source[2], source[3], destination[0], destination[1],
|
|
56
|
+
destination[2], destination[3]);
|
|
57
|
+
}
|
|
58
|
+
if (destination_samples > 1) {
|
|
59
|
+
/* ES 3.0 §4.3.2: an INVALID_OPERATION is generated when the draw
|
|
60
|
+
* framebuffer is multisampled, so a page renders into its own resolve
|
|
61
|
+
* target instead of the antialiased canvas. */
|
|
62
|
+
set_error(GL_INVALID_OPERATION);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
28
65
|
if (depth_bit) {
|
|
29
66
|
/* SDL_GPU's blit API is colour-only; the depth copy is a sampling pass that
|
|
30
67
|
* writes `gl_FragDepth`. Stencil bits have no sampleable representation and
|
|
@@ -34,22 +71,41 @@ bool WebGLContext::blit_framebuffer(const int source[4], const int destination[4
|
|
|
34
71
|
ensure_command();
|
|
35
72
|
}
|
|
36
73
|
if (!color_bit) return true;
|
|
37
|
-
|
|
38
|
-
SDL_GPUTexture *destination_texture = framebuffer_color(bound_framebuffer_);
|
|
39
|
-
if (source_texture == nullptr || destination_texture == nullptr ||
|
|
40
|
-
source_texture == destination_texture) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
74
|
+
|
|
43
75
|
int source_width = 0;
|
|
44
76
|
int source_height = 0;
|
|
77
|
+
int source_format = 0;
|
|
45
78
|
int destination_width = 0;
|
|
46
79
|
int destination_height = 0;
|
|
47
|
-
|
|
48
|
-
|
|
80
|
+
int destination_format = 0;
|
|
81
|
+
int destination_samples_unused = 1;
|
|
82
|
+
SDL_GPUTexture *source_texture = read_color_texture(read_framebuffer_, &source_width,
|
|
83
|
+
&source_height, &source_format);
|
|
84
|
+
SDL_GPUTexture *destination_texture =
|
|
85
|
+
color_attachment(bound_framebuffer_, 0, &destination_format, &destination_samples_unused,
|
|
86
|
+
&destination_width, &destination_height);
|
|
87
|
+
if (source_texture == nullptr || destination_texture == nullptr ||
|
|
88
|
+
source_texture == destination_texture) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
49
91
|
if (source_width <= 0 || source_height <= 0 || destination_width <= 0 ||
|
|
50
92
|
destination_height <= 0) {
|
|
51
93
|
return false;
|
|
52
94
|
}
|
|
95
|
+
if (source_samples > 1) {
|
|
96
|
+
/* Resolving is only defined for identical rectangles and identical colour
|
|
97
|
+
* formats; with a different rectangle or format the ES 3.0 spec raises
|
|
98
|
+
* INVALID_OPERATION instead of filtering the samples. */
|
|
99
|
+
if (source[0] != destination[0] || source[1] != destination[1] ||
|
|
100
|
+
source[2] != destination[2] || source[3] != destination[3]) {
|
|
101
|
+
set_error(GL_INVALID_OPERATION);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (source_format != destination_format || filter != GL_NEAREST) {
|
|
105
|
+
set_error(GL_INVALID_OPERATION);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
53
109
|
int sx0 = source[0];
|
|
54
110
|
int sy0 = source[1];
|
|
55
111
|
int sx1 = source[2];
|
|
@@ -72,12 +128,41 @@ bool WebGLContext::blit_framebuffer(const int source[4], const int destination[4
|
|
|
72
128
|
dy1 = std::max(0, std::min(dy1, destination_height));
|
|
73
129
|
if (sx1 <= sx0 || sy1 <= sy0 || dx1 <= dx0 || dy1 <= dy0) return true;
|
|
74
130
|
|
|
131
|
+
/* `SDL_BlitGPUTexture` is implemented with `vkCmdBlitImage`, which requires
|
|
132
|
+
* the source and destination formats to advertise BLIT_SRC/BLIT_DST. The
|
|
133
|
+
* half-float formats a three.js scene render target uses do not, and the
|
|
134
|
+
* invalid command loses the Vulkan device. Copy the resolved image with a
|
|
135
|
+
* sampling pass instead; a full-rectangle resolve is the common case (the
|
|
136
|
+
* ES 3.0 resolve path already requires identical source/destination
|
|
137
|
+
* rectangles). */
|
|
138
|
+
const bool full_rect = sx0 == 0 && sy0 == 0 && sx1 == source_width && sy1 == source_height &&
|
|
139
|
+
dx0 == 0 && dy0 == 0 && dx1 == destination_width &&
|
|
140
|
+
dy1 == destination_height;
|
|
141
|
+
const bool float_format =
|
|
142
|
+
source_format == SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT ||
|
|
143
|
+
source_format == SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT ||
|
|
144
|
+
source_format == SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT ||
|
|
145
|
+
source_format == SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT ||
|
|
146
|
+
source_format == SDL_GPU_TEXTUREFORMAT_R16_FLOAT ||
|
|
147
|
+
source_format == SDL_GPU_TEXTUREFORMAT_R32_FLOAT;
|
|
148
|
+
/* `SDL_BlitGPUTexture` copies rows in storage order and cannot invert them, so
|
|
149
|
+
* a blit between a top-down and a bottom-up target is a sampling pass that
|
|
150
|
+
* maps GL rows through each target's convention. The same pass copies a
|
|
151
|
+
* float-format multisampled resolve (see below). */
|
|
152
|
+
const int source_rect[4] = {sx0, sy0, sx1, sy1};
|
|
153
|
+
if (source_top_down != destination_top_down ||
|
|
154
|
+
(full_rect && float_format && source_samples > 1)) {
|
|
155
|
+
if (draw_color_quad(source_texture, source_top_down, source_rect, source_width,
|
|
156
|
+
source_height, destination, filter == GL_LINEAR)) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
75
161
|
SDL_GPUBlitRegion source_region;
|
|
76
162
|
memset(&source_region, 0, sizeof(source_region));
|
|
77
163
|
source_region.texture = source_texture;
|
|
78
164
|
source_region.x = (Uint32)sx0;
|
|
79
|
-
|
|
80
|
-
source_region.y = (Uint32)(source_height - sy1);
|
|
165
|
+
source_region.y = (Uint32)webgl_target_rect_y(source_top_down, source_height, sy0, sy1 - sy0);
|
|
81
166
|
source_region.w = (Uint32)(sx1 - sx0);
|
|
82
167
|
source_region.h = (Uint32)(sy1 - sy0);
|
|
83
168
|
|
|
@@ -85,7 +170,8 @@ bool WebGLContext::blit_framebuffer(const int source[4], const int destination[4
|
|
|
85
170
|
memset(&destination_region, 0, sizeof(destination_region));
|
|
86
171
|
destination_region.texture = destination_texture;
|
|
87
172
|
destination_region.x = (Uint32)dx0;
|
|
88
|
-
destination_region.y = (Uint32)(destination_height
|
|
173
|
+
destination_region.y = (Uint32)webgl_target_rect_y(destination_top_down, destination_height,
|
|
174
|
+
dy0, dy1 - dy0);
|
|
89
175
|
destination_region.w = (Uint32)(dx1 - dx0);
|
|
90
176
|
destination_region.h = (Uint32)(dy1 - dy0);
|
|
91
177
|
|
|
@@ -99,7 +185,15 @@ bool WebGLContext::blit_framebuffer(const int source[4], const int destination[4
|
|
|
99
185
|
* those pixels undefined, so load it. */
|
|
100
186
|
info.load_op = SDL_GPU_LOADOP_LOAD;
|
|
101
187
|
info.filter = filter == GL_LINEAR ? SDL_GPU_FILTER_LINEAR : SDL_GPU_FILTER_NEAREST;
|
|
188
|
+
SDL_ClearError();
|
|
102
189
|
SDL_BlitGPUTexture(cmd_, &info);
|
|
190
|
+
if (trace_enabled()) {
|
|
191
|
+
const char *error = SDL_GetError();
|
|
192
|
+
if (error != nullptr && error[0] != '\0') {
|
|
193
|
+
fprintf(stderr, "xt_gui: blit failed (%d -> %d, format %d -> %d): %s\n", source_samples,
|
|
194
|
+
destination_samples, source_format, destination_format, error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
103
197
|
return true;
|
|
104
198
|
}
|
|
105
199
|
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — textured quad copies into a render target.
|
|
3
|
+
*
|
|
4
|
+
* `SDL_BlitGPUTexture` cannot target a multisampled texture (its helper
|
|
5
|
+
* pipeline is single-sampled) and cannot invert rows, so a scissored colour
|
|
6
|
+
* clear on an antialiased drawing buffer, a float-format resolve, and a copy
|
|
7
|
+
* between targets that disagree on storage orientation (the top-down composited
|
|
8
|
+
* drawing buffer versus a bottom-up user framebuffer) are all a textured quad
|
|
9
|
+
* drawn into the current pass instead. The quad covers exactly the destination
|
|
10
|
+
* rectangle and its edges fall on pixel boundaries, so the MSAA rasteriser
|
|
11
|
+
* gives every covered pixel full coverage.
|
|
12
|
+
*
|
|
13
|
+
* The internal program, quad buffer and samplers are ordinary engine objects and
|
|
14
|
+
* live for the context's lifetime. The caller's GL state is saved/restored
|
|
15
|
+
* around the draw.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "webgl.h"
|
|
19
|
+
|
|
20
|
+
#include <algorithm>
|
|
21
|
+
#include <cstring>
|
|
22
|
+
#include <string>
|
|
23
|
+
|
|
24
|
+
#include "gui_internal.h"
|
|
25
|
+
|
|
26
|
+
namespace xtgui {
|
|
27
|
+
namespace {
|
|
28
|
+
|
|
29
|
+
const char *kColorBlitVertexShader =
|
|
30
|
+
"#version 300 es\n"
|
|
31
|
+
"uniform highp vec4 u_dst;\n"
|
|
32
|
+
"uniform highp vec4 u_uv;\n"
|
|
33
|
+
"in highp vec2 a_pos;\n"
|
|
34
|
+
"out highp vec2 v_uv;\n"
|
|
35
|
+
"void main() {\n"
|
|
36
|
+
" v_uv = mix(u_uv.xy, u_uv.zw, a_pos);\n"
|
|
37
|
+
" gl_Position = vec4(mix(u_dst.xy, u_dst.zw, a_pos), 0.0, 1.0);\n"
|
|
38
|
+
"}\n";
|
|
39
|
+
|
|
40
|
+
const char *kColorBlitFragmentShader =
|
|
41
|
+
"#version 300 es\n"
|
|
42
|
+
"precision highp float;\n"
|
|
43
|
+
"uniform highp sampler2D u_color;\n"
|
|
44
|
+
"in highp vec2 v_uv;\n"
|
|
45
|
+
"out highp vec4 fragColor;\n"
|
|
46
|
+
"void main() { fragColor = texture(u_color, v_uv); }\n";
|
|
47
|
+
|
|
48
|
+
} // namespace
|
|
49
|
+
|
|
50
|
+
bool WebGLContext::draw_color_quad(SDL_GPUTexture *source, bool source_top_down,
|
|
51
|
+
const int source_rect[4], int source_width,
|
|
52
|
+
int source_height, const int destination[4],
|
|
53
|
+
bool linear) {
|
|
54
|
+
if (guidev::g_device == nullptr || source == nullptr || source_rect == nullptr) return false;
|
|
55
|
+
if (source_width <= 0 || source_height <= 0) return false;
|
|
56
|
+
int target_width = 0;
|
|
57
|
+
int target_height = 0;
|
|
58
|
+
framebuffer_size(bound_framebuffer_, &target_width, &target_height);
|
|
59
|
+
if (target_width <= 0 || target_height <= 0) return false;
|
|
60
|
+
|
|
61
|
+
if (blit_color_program_ == 0) {
|
|
62
|
+
const uint32_t vs = create_shader(GL_VERTEX_SHADER);
|
|
63
|
+
shader_source(vs, kColorBlitVertexShader);
|
|
64
|
+
const uint32_t fs = create_shader(GL_FRAGMENT_SHADER);
|
|
65
|
+
shader_source(fs, kColorBlitFragmentShader);
|
|
66
|
+
if (compile_shader(vs) && compile_shader(fs)) {
|
|
67
|
+
const uint32_t program_id = create_program();
|
|
68
|
+
attach_shader(program_id, vs);
|
|
69
|
+
attach_shader(program_id, fs);
|
|
70
|
+
bind_attrib_location(program_id, 0, "a_pos");
|
|
71
|
+
if (link_program(program_id)) {
|
|
72
|
+
blit_color_program_ = program_id;
|
|
73
|
+
} else {
|
|
74
|
+
delete_program(program_id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (blit_color_program_ == 0) {
|
|
78
|
+
delete_shader(vs);
|
|
79
|
+
delete_shader(fs);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (blit_buffer_ == 0) {
|
|
84
|
+
blit_buffer_ = create_buffer();
|
|
85
|
+
bind_buffer(GL_ARRAY_BUFFER, blit_buffer_);
|
|
86
|
+
const float vertices[8] = {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
|
|
87
|
+
buffer_data(blit_buffer_, (const uint8_t *)vertices, (uint32_t)sizeof(vertices),
|
|
88
|
+
GL_STATIC_DRAW);
|
|
89
|
+
}
|
|
90
|
+
if (blit_sampler_ == nullptr) {
|
|
91
|
+
SDL_GPUSamplerCreateInfo sampler_info;
|
|
92
|
+
memset(&sampler_info, 0, sizeof(sampler_info));
|
|
93
|
+
sampler_info.min_filter = SDL_GPU_FILTER_NEAREST;
|
|
94
|
+
sampler_info.mag_filter = SDL_GPU_FILTER_NEAREST;
|
|
95
|
+
sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST;
|
|
96
|
+
sampler_info.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
|
97
|
+
sampler_info.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
|
98
|
+
sampler_info.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
|
99
|
+
sampler_info.max_lod = 0.0f;
|
|
100
|
+
blit_sampler_ = SDL_CreateGPUSampler(guidev::g_device, &sampler_info);
|
|
101
|
+
}
|
|
102
|
+
if (linear && blit_sampler_linear_ == nullptr) {
|
|
103
|
+
SDL_GPUSamplerCreateInfo sampler_info;
|
|
104
|
+
memset(&sampler_info, 0, sizeof(sampler_info));
|
|
105
|
+
sampler_info.min_filter = SDL_GPU_FILTER_LINEAR;
|
|
106
|
+
sampler_info.mag_filter = SDL_GPU_FILTER_LINEAR;
|
|
107
|
+
sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST;
|
|
108
|
+
sampler_info.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
|
109
|
+
sampler_info.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
|
110
|
+
sampler_info.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
|
|
111
|
+
sampler_info.max_lod = 0.0f;
|
|
112
|
+
blit_sampler_linear_ = SDL_CreateGPUSampler(guidev::g_device, &sampler_info);
|
|
113
|
+
}
|
|
114
|
+
SDL_GPUSampler *sampler = linear ? blit_sampler_linear_ : blit_sampler_;
|
|
115
|
+
WebGLProgram *program = this->program(blit_color_program_);
|
|
116
|
+
WebGLBuffer *quad_buffer = buffer(blit_buffer_);
|
|
117
|
+
SDL_GPUBuffer *quad_gpu = quad_buffer != nullptr ? ensure_buffer_gpu(quad_buffer) : nullptr;
|
|
118
|
+
if (program == nullptr || program->vs_shader == nullptr || program->fs_shader == nullptr ||
|
|
119
|
+
quad_gpu == nullptr || sampler == nullptr) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
int x0 = destination[0];
|
|
124
|
+
int y0 = destination[1];
|
|
125
|
+
int x1 = destination[2];
|
|
126
|
+
int y1 = destination[3];
|
|
127
|
+
if (x1 < x0) std::swap(x0, x1);
|
|
128
|
+
if (y1 < y0) std::swap(y0, y1);
|
|
129
|
+
x0 = std::max(0, std::min(x0, target_width));
|
|
130
|
+
x1 = std::max(0, std::min(x1, target_width));
|
|
131
|
+
y0 = std::max(0, std::min(y0, target_height));
|
|
132
|
+
y1 = std::max(0, std::min(y1, target_height));
|
|
133
|
+
if (x1 <= x0 || y1 <= y0) return true;
|
|
134
|
+
|
|
135
|
+
/* Both rectangles are in GL window coordinates. `a_pos.y = 0` is the
|
|
136
|
+
* destination rectangle's GL bottom edge (y0), whose SDL row depends on
|
|
137
|
+
* whether the bound framebuffer is stored top-down (the composited drawing
|
|
138
|
+
* buffer) or bottom-up (a user framebuffer sampled by shaders); `a_pos.y = 1`
|
|
139
|
+
* is its GL top edge (y1). The source V follows the source's own convention,
|
|
140
|
+
* so the GL rows line up on both sides and a copy between the two conventions
|
|
141
|
+
* comes out with the correct orientation. */
|
|
142
|
+
const bool destination_top_down = webgl_target_top_down(bound_framebuffer_);
|
|
143
|
+
const int row_bottom = webgl_target_row(destination_top_down, target_height, y0);
|
|
144
|
+
const int row_top = webgl_target_row(destination_top_down, target_height, y1);
|
|
145
|
+
double dst[4] = {(double)x0 / (double)target_width * 2.0 - 1.0,
|
|
146
|
+
1.0 - (double)row_bottom / (double)target_height * 2.0,
|
|
147
|
+
(double)x1 / (double)target_width * 2.0 - 1.0,
|
|
148
|
+
1.0 - (double)row_top / (double)target_height * 2.0};
|
|
149
|
+
const int sx0 = std::max(0, std::min(source_rect[0], source_width));
|
|
150
|
+
const int sx1 = std::max(sx0, std::min(source_rect[2], source_width));
|
|
151
|
+
const int sy0 = std::max(0, std::min(source_rect[1], source_height));
|
|
152
|
+
const int sy1 = std::max(sy0, std::min(source_rect[3], source_height));
|
|
153
|
+
/* Source V at the rectangle's GL bottom edge (sy0) and top edge (sy1). */
|
|
154
|
+
const int source_row0 = webgl_target_row(source_top_down, source_height, sy0);
|
|
155
|
+
const int source_row1 = webgl_target_row(source_top_down, source_height, sy1);
|
|
156
|
+
double uv[4] = {(double)sx0 / (double)source_width,
|
|
157
|
+
(double)source_row0 / (double)source_height,
|
|
158
|
+
(double)sx1 / (double)source_width,
|
|
159
|
+
(double)source_row1 / (double)source_height};
|
|
160
|
+
|
|
161
|
+
const WebGLDrawState saved_state = state_;
|
|
162
|
+
const uint32_t saved_program = current_program_;
|
|
163
|
+
state_.blend = false;
|
|
164
|
+
state_.cull = false;
|
|
165
|
+
state_.stencil = false;
|
|
166
|
+
state_.depth_test = false;
|
|
167
|
+
state_.depth_write = false;
|
|
168
|
+
state_.depth_func = GL_ALWAYS;
|
|
169
|
+
for (bool &channel : state_.color_mask) channel = true;
|
|
170
|
+
state_.color_target_count = 0;
|
|
171
|
+
for (int slot = 0; slot < kWebGLMaxDrawBuffers; slot++) {
|
|
172
|
+
if (draw_color_texture(slot) == nullptr) continue;
|
|
173
|
+
state_.color_formats[state_.color_target_count++] = draw_color_format(slot);
|
|
174
|
+
}
|
|
175
|
+
if (state_.color_target_count == 0) state_.color_target_count = 1;
|
|
176
|
+
state_.depth_format = target_depth_format();
|
|
177
|
+
state_.sample_count = target_samples();
|
|
178
|
+
current_program_ = blit_color_program_;
|
|
179
|
+
|
|
180
|
+
std::string key = "blit-color/";
|
|
181
|
+
for (int i = 0; i < state_.color_target_count; i++) {
|
|
182
|
+
key += std::to_string(state_.color_formats[i]) + ",";
|
|
183
|
+
}
|
|
184
|
+
key += std::to_string(state_.depth_format) + "/" + std::to_string(state_.sample_count);
|
|
185
|
+
SDL_GPUVertexAttribute attribute;
|
|
186
|
+
memset(&attribute, 0, sizeof(attribute));
|
|
187
|
+
attribute.location = 0;
|
|
188
|
+
attribute.buffer_slot = 0;
|
|
189
|
+
attribute.format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
|
|
190
|
+
attribute.offset = 0;
|
|
191
|
+
SDL_GPUVertexBufferDescription buffer_description;
|
|
192
|
+
memset(&buffer_description, 0, sizeof(buffer_description));
|
|
193
|
+
buffer_description.slot = 0;
|
|
194
|
+
buffer_description.pitch = 8;
|
|
195
|
+
buffer_description.input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
|
|
196
|
+
SDL_GPUGraphicsPipeline *pipeline = nullptr;
|
|
197
|
+
auto cached = internal_pipelines_.find(key);
|
|
198
|
+
if (cached != internal_pipelines_.end()) {
|
|
199
|
+
pipeline = cached->second;
|
|
200
|
+
} else {
|
|
201
|
+
pipeline = create_pipeline(program, GL_TRIANGLE_STRIP, 1, 1, &attribute,
|
|
202
|
+
&buffer_description);
|
|
203
|
+
if (pipeline != nullptr) internal_pipelines_[key] = pipeline;
|
|
204
|
+
}
|
|
205
|
+
bool ok = pipeline != nullptr;
|
|
206
|
+
if (ok) {
|
|
207
|
+
begin_pass(false, false, false);
|
|
208
|
+
ok = pass_ != nullptr;
|
|
209
|
+
}
|
|
210
|
+
if (ok) {
|
|
211
|
+
SDL_GPUViewport viewport;
|
|
212
|
+
memset(&viewport, 0, sizeof(viewport));
|
|
213
|
+
viewport.x = 0;
|
|
214
|
+
viewport.y = 0;
|
|
215
|
+
viewport.w = (float)target_width;
|
|
216
|
+
viewport.h = (float)target_height;
|
|
217
|
+
viewport.min_depth = 0.0f;
|
|
218
|
+
viewport.max_depth = 1.0f;
|
|
219
|
+
SDL_SetGPUViewport(pass_, &viewport);
|
|
220
|
+
SDL_Rect scissor;
|
|
221
|
+
scissor.x = x0;
|
|
222
|
+
/* The rectangle covers the rows between the two corners; for a top-down
|
|
223
|
+
* target GL y0 is below y1, for a bottom-up target above it. */
|
|
224
|
+
scissor.y = std::min(row_bottom, row_top);
|
|
225
|
+
scissor.w = x1 - x0;
|
|
226
|
+
scissor.h = y1 - y0;
|
|
227
|
+
SDL_SetGPUScissor(pass_, &scissor);
|
|
228
|
+
|
|
229
|
+
SDL_BindGPUGraphicsPipeline(pass_, pipeline);
|
|
230
|
+
SDL_GPUBufferBinding binding;
|
|
231
|
+
memset(&binding, 0, sizeof(binding));
|
|
232
|
+
binding.buffer = quad_gpu;
|
|
233
|
+
SDL_BindGPUVertexBuffers(pass_, 0, &binding, 1);
|
|
234
|
+
const int dst_location = uniform_location(blit_color_program_, "u_dst");
|
|
235
|
+
const int uv_location = uniform_location(blit_color_program_, "u_uv");
|
|
236
|
+
if (dst_location >= 0) uniform_floats(blit_color_program_, dst_location, 4, dst, 1);
|
|
237
|
+
if (uv_location >= 0) uniform_floats(blit_color_program_, uv_location, 4, uv, 1);
|
|
238
|
+
if (program->block_size > 0) {
|
|
239
|
+
if (program->vs_has_block) {
|
|
240
|
+
SDL_PushGPUVertexUniformData(cmd_, 0, program->block.data(),
|
|
241
|
+
(Uint32)program->block.size());
|
|
242
|
+
}
|
|
243
|
+
if (program->fs_has_block) {
|
|
244
|
+
SDL_PushGPUFragmentUniformData(cmd_, 0, program->block.data(),
|
|
245
|
+
(Uint32)program->block.size());
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
SDL_GPUTextureSamplerBinding sampler_binding;
|
|
249
|
+
sampler_binding.texture = source;
|
|
250
|
+
sampler_binding.sampler = sampler;
|
|
251
|
+
SDL_BindGPUFragmentSamplers(pass_, 0, &sampler_binding, 1);
|
|
252
|
+
SDL_DrawGPUPrimitives(pass_, 4, 1, 0, 0);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
state_ = saved_state;
|
|
256
|
+
current_program_ = saved_program;
|
|
257
|
+
/* This pass bound the blit pipeline directly, outside the prepared-draw
|
|
258
|
+
* cache; a later draw in the same pass must bind its own pipeline again. */
|
|
259
|
+
last_setup_ = nullptr;
|
|
260
|
+
last_pipeline_ = nullptr;
|
|
261
|
+
return ok;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
} // namespace xtgui
|