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
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — WebGL framebuffer and renderbuffer objects.
|
|
3
|
+
*
|
|
4
|
+
* A framebuffer is a set of up to four colour attachments (texture or
|
|
5
|
+
* renderbuffer), an optional depth/stencil attachment and the draw-buffer
|
|
6
|
+
* table, plus an auto-created depth buffer when the page attaches none.
|
|
7
|
+
* Renderbuffers are engine-owned render targets so a page can ask for a
|
|
8
|
+
* multisampled colour or depth buffer without a texture. Completeness
|
|
9
|
+
* (dimensions and sample counts) is reported with the exact GL status enum.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "webgl.h"
|
|
13
|
+
|
|
14
|
+
#include <cstdio>
|
|
15
|
+
#include <cstring>
|
|
16
|
+
|
|
17
|
+
#include "gui_internal.h"
|
|
18
|
+
|
|
19
|
+
namespace xtgui {
|
|
20
|
+
namespace {
|
|
21
|
+
|
|
22
|
+
/** `XT_GUI_TRACE=1` explains an incomplete framebuffer. */
|
|
23
|
+
bool trace_enabled() {
|
|
24
|
+
static int value = -1;
|
|
25
|
+
if (value < 0) {
|
|
26
|
+
const char *env = SDL_getenv("XT_GUI_TRACE");
|
|
27
|
+
value = (env != nullptr && env[0] != '\0' && env[0] != '0') ? 1 : 0;
|
|
28
|
+
}
|
|
29
|
+
return value != 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
} // namespace
|
|
33
|
+
|
|
34
|
+
/* -- framebuffers -------------------------------------------------------- */
|
|
35
|
+
|
|
36
|
+
uint32_t WebGLContext::create_framebuffer() {
|
|
37
|
+
auto record = std::make_unique<WebGLFramebuffer>();
|
|
38
|
+
record->id = next_object_id_++;
|
|
39
|
+
const uint32_t id = record->id;
|
|
40
|
+
framebuffers_[id] = std::move(record);
|
|
41
|
+
return id;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
void WebGLContext::delete_framebuffer(uint32_t id) {
|
|
45
|
+
auto found = framebuffers_.find(id);
|
|
46
|
+
if (found == framebuffers_.end()) return;
|
|
47
|
+
if (bound_framebuffer_ == id) bind_framebuffer(GL_FRAMEBUFFER, 0);
|
|
48
|
+
if (read_framebuffer_ == id) read_framebuffer_ = 0;
|
|
49
|
+
if (found->second->depth != nullptr && found->second->depth_renderbuffer == 0 &&
|
|
50
|
+
guidev::g_device != nullptr) {
|
|
51
|
+
submit(); SDL_WaitForGPUIdle(guidev::g_device);
|
|
52
|
+
SDL_ReleaseGPUTexture(guidev::g_device, found->second->depth);
|
|
53
|
+
}
|
|
54
|
+
framebuffers_.erase(found);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void WebGLContext::bind_framebuffer(int target, uint32_t id) {
|
|
58
|
+
if (id != 0 && framebuffers_.find(id) == framebuffers_.end()) return;
|
|
59
|
+
if (target == GL_READ_FRAMEBUFFER) {
|
|
60
|
+
read_framebuffer_ = id;
|
|
61
|
+
read_buffer_ = id == 0 ? GL_BACK : GL_COLOR_ATTACHMENT0;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (target != GL_FRAMEBUFFER && target != GL_DRAW_FRAMEBUFFER) return;
|
|
65
|
+
if (id != bound_framebuffer_) end_pass();
|
|
66
|
+
bound_framebuffer_ = id;
|
|
67
|
+
framebuffer_version_ += 1;
|
|
68
|
+
if (target == GL_FRAMEBUFFER) read_framebuffer_ = id;
|
|
69
|
+
read_buffer_ = id == 0 ? GL_BACK : GL_COLOR_ATTACHMENT0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
bool WebGLContext::framebuffer_texture(uint32_t framebuffer_id, uint32_t texture_id,
|
|
73
|
+
int attachment) {
|
|
74
|
+
framebuffer_version_ += 1;
|
|
75
|
+
WebGLFramebuffer *record_framebuffer = framebuffer(framebuffer_id);
|
|
76
|
+
WebGLTexture *record = texture(texture_id);
|
|
77
|
+
if (record_framebuffer == nullptr) return false;
|
|
78
|
+
if (texture_id != 0 && record == nullptr) return false;
|
|
79
|
+
if (attachment == GL_DEPTH_ATTACHMENT || attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
|
|
80
|
+
record_framebuffer->depth_texture = texture_id;
|
|
81
|
+
record_framebuffer->depth_renderbuffer = 0;
|
|
82
|
+
if (record_framebuffer->depth != nullptr) {
|
|
83
|
+
submit(); SDL_WaitForGPUIdle(guidev::g_device);
|
|
84
|
+
SDL_ReleaseGPUTexture(guidev::g_device, record_framebuffer->depth);
|
|
85
|
+
record_framebuffer->depth = nullptr;
|
|
86
|
+
}
|
|
87
|
+
if (record != nullptr) {
|
|
88
|
+
record->as_depth_target = true;
|
|
89
|
+
ensure_texture_gpu(record, true);
|
|
90
|
+
/* Storage may not exist yet; color_attachment and framebuffer_size re-read
|
|
91
|
+
* the real size once it does, so never clobber a known size with 0. */
|
|
92
|
+
if (record->width > 0 && record->height > 0) {
|
|
93
|
+
record_framebuffer->width = record->width;
|
|
94
|
+
record_framebuffer->height = record->height;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const int color_index = attachment - GL_COLOR_ATTACHMENT0;
|
|
100
|
+
if (color_index < 0 || color_index >= kWebGLMaxDrawBuffers) return false;
|
|
101
|
+
record_framebuffer->color_textures[color_index] = texture_id;
|
|
102
|
+
record_framebuffer->color_renderbuffers[color_index] = 0;
|
|
103
|
+
if (record != nullptr) {
|
|
104
|
+
if (record->width > 0 && record->height > 0) {
|
|
105
|
+
record_framebuffer->width = record->width;
|
|
106
|
+
record_framebuffer->height = record->height;
|
|
107
|
+
}
|
|
108
|
+
ensure_texture_gpu(record, true);
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
bool WebGLContext::framebuffer_texture_layer(uint32_t framebuffer_id, uint32_t texture_id,
|
|
114
|
+
int attachment, int layer) {
|
|
115
|
+
if (!framebuffer_texture(framebuffer_id, texture_id, attachment)) return false;
|
|
116
|
+
const int index = attachment - GL_COLOR_ATTACHMENT0;
|
|
117
|
+
WebGLFramebuffer *record = framebuffer(framebuffer_id);
|
|
118
|
+
if (record != nullptr && index >= 0 && index < kWebGLMaxDrawBuffers) {
|
|
119
|
+
record->color_layers[index] = layer;
|
|
120
|
+
}
|
|
121
|
+
/* SDL_GPU 3.2 depth-stencil targets have no layer selector; the depth
|
|
122
|
+
* attachment still binds, without per-layer rendering. */
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
int WebGLContext::framebuffer_status(uint32_t id) {
|
|
127
|
+
WebGLFramebuffer *framebuffer_ = framebuffer(id);
|
|
128
|
+
if (framebuffer_ == nullptr) return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
129
|
+
auto incomplete = [&](int status, const char *why, int slot, uint32_t attachment) {
|
|
130
|
+
if (trace_enabled()) {
|
|
131
|
+
WebGLTexture *attachment_texture = attachment != 0 ? texture(attachment) : nullptr;
|
|
132
|
+
fprintf(stderr,
|
|
133
|
+
"xt_gui: fb %u incomplete (%d): %s slot=%d attachment=%u texture=%p texsize=%dx%d "
|
|
134
|
+
"texgpu=%p fbsize=%dx%d\n",
|
|
135
|
+
id, status, why, slot, attachment, (void *)attachment_texture,
|
|
136
|
+
attachment_texture != nullptr ? attachment_texture->width : -1,
|
|
137
|
+
attachment_texture != nullptr ? attachment_texture->height : -1,
|
|
138
|
+
attachment_texture != nullptr ? (void *)attachment_texture->gpu : nullptr,
|
|
139
|
+
framebuffer_->width, framebuffer_->height);
|
|
140
|
+
}
|
|
141
|
+
return status;
|
|
142
|
+
};
|
|
143
|
+
bool attached = false;
|
|
144
|
+
int width = 0;
|
|
145
|
+
int height = 0;
|
|
146
|
+
int samples = 1;
|
|
147
|
+
if (trace_enabled()) {
|
|
148
|
+
fprintf(stderr,
|
|
149
|
+
"xt_gui: fb %u status: color=[%u,%u,%u,%u] rb=[%u,%u,%u,%u] depth=%u/%u size=%dx%d\n",
|
|
150
|
+
id, framebuffer_->color_textures[0], framebuffer_->color_textures[1],
|
|
151
|
+
framebuffer_->color_textures[2], framebuffer_->color_textures[3],
|
|
152
|
+
framebuffer_->color_renderbuffers[0], framebuffer_->color_renderbuffers[1],
|
|
153
|
+
framebuffer_->color_renderbuffers[2], framebuffer_->color_renderbuffers[3],
|
|
154
|
+
framebuffer_->depth_texture, framebuffer_->depth_renderbuffer, framebuffer_->width,
|
|
155
|
+
framebuffer_->height);
|
|
156
|
+
}
|
|
157
|
+
for (int index = 0; index < kWebGLMaxDrawBuffers; index++) {
|
|
158
|
+
if (framebuffer_->color_textures[index] == 0 &&
|
|
159
|
+
framebuffer_->color_renderbuffers[index] == 0) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
int format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
163
|
+
int attachment_samples = 1;
|
|
164
|
+
int attachment_width = 0;
|
|
165
|
+
int attachment_height = 0;
|
|
166
|
+
if (color_attachment(id, index, &format, &attachment_samples, &attachment_width,
|
|
167
|
+
&attachment_height) == nullptr) {
|
|
168
|
+
return incomplete(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, "colour attachment unresolved",
|
|
169
|
+
index, framebuffer_->color_textures[index]);
|
|
170
|
+
}
|
|
171
|
+
if (!attached) {
|
|
172
|
+
attached = true;
|
|
173
|
+
width = attachment_width;
|
|
174
|
+
height = attachment_height;
|
|
175
|
+
samples = attachment_samples;
|
|
176
|
+
} else if (attachment_samples != samples) {
|
|
177
|
+
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
|
|
178
|
+
} else if (attachment_width != width || attachment_height != height) {
|
|
179
|
+
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (framebuffer_->depth_renderbuffer != 0 || framebuffer_->depth_texture != 0 ||
|
|
183
|
+
framebuffer_->depth != nullptr) {
|
|
184
|
+
int depth_samples = 1;
|
|
185
|
+
int depth_width = framebuffer_->width;
|
|
186
|
+
int depth_height = framebuffer_->height;
|
|
187
|
+
if (framebuffer_->depth_renderbuffer != 0) {
|
|
188
|
+
WebGLRenderbuffer *renderbuffer_ = renderbuffer(framebuffer_->depth_renderbuffer);
|
|
189
|
+
if (renderbuffer_ == nullptr) return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
190
|
+
depth_samples = renderbuffer_->samples;
|
|
191
|
+
depth_width = renderbuffer_->width;
|
|
192
|
+
depth_height = renderbuffer_->height;
|
|
193
|
+
} else if (framebuffer_->depth_texture != 0) {
|
|
194
|
+
WebGLTexture *texture_ = texture(framebuffer_->depth_texture);
|
|
195
|
+
if (texture_ == nullptr) return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
196
|
+
depth_samples = texture_->samples;
|
|
197
|
+
depth_width = texture_->width;
|
|
198
|
+
depth_height = texture_->height;
|
|
199
|
+
}
|
|
200
|
+
if (!attached) {
|
|
201
|
+
attached = true;
|
|
202
|
+
width = depth_width;
|
|
203
|
+
height = depth_height;
|
|
204
|
+
samples = depth_samples;
|
|
205
|
+
} else if (depth_samples != samples) {
|
|
206
|
+
return GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
|
|
207
|
+
} else if (depth_width != width || depth_height != height) {
|
|
208
|
+
return GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (!attached) return GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
212
|
+
if (width <= 0 || height <= 0) return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
213
|
+
return GL_FRAMEBUFFER_COMPLETE;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
uint32_t WebGLContext::create_renderbuffer() {
|
|
217
|
+
auto record = std::make_unique<WebGLRenderbuffer>();
|
|
218
|
+
record->id = next_object_id_++;
|
|
219
|
+
const uint32_t id = record->id;
|
|
220
|
+
renderbuffers_[id] = std::move(record);
|
|
221
|
+
return id;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
void WebGLContext::delete_renderbuffer(uint32_t id) {
|
|
225
|
+
auto found = renderbuffers_.find(id);
|
|
226
|
+
if (found == renderbuffers_.end()) return;
|
|
227
|
+
if (bound_renderbuffer_ == id) bound_renderbuffer_ = 0;
|
|
228
|
+
for (auto &entry : framebuffers_) {
|
|
229
|
+
if (entry.second->depth_renderbuffer == id) {
|
|
230
|
+
entry.second->depth_renderbuffer = 0;
|
|
231
|
+
entry.second->depth = nullptr;
|
|
232
|
+
}
|
|
233
|
+
for (uint32_t &color : entry.second->color_renderbuffers) {
|
|
234
|
+
if (color == id) color = 0;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (found->second->gpu != nullptr && guidev::g_device != nullptr) {
|
|
238
|
+
submit(); SDL_WaitForGPUIdle(guidev::g_device);
|
|
239
|
+
SDL_ReleaseGPUTexture(guidev::g_device, found->second->gpu);
|
|
240
|
+
}
|
|
241
|
+
renderbuffers_.erase(found);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
bool WebGLContext::renderbuffer_storage(uint32_t id, int width, int height, int internalformat,
|
|
245
|
+
int samples) {
|
|
246
|
+
WebGLRenderbuffer *record = renderbuffer(id);
|
|
247
|
+
if (record == nullptr) return false;
|
|
248
|
+
if (width <= 0 || height <= 0) {
|
|
249
|
+
set_error(GL_INVALID_VALUE);
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
if (samples != 0 && samples != 1 && samples != 2 && samples != kWebGLMaxSamples) {
|
|
253
|
+
set_error(GL_INVALID_VALUE);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
const bool depth = internalformat == GL_DEPTH_COMPONENT ||
|
|
257
|
+
internalformat == GL_DEPTH_COMPONENT16 ||
|
|
258
|
+
internalformat == GL_DEPTH_COMPONENT24 ||
|
|
259
|
+
internalformat == GL_DEPTH_COMPONENT32F ||
|
|
260
|
+
internalformat == GL_DEPTH_STENCIL ||
|
|
261
|
+
internalformat == GL_DEPTH24_STENCIL8 ||
|
|
262
|
+
internalformat == GL_DEPTH32F_STENCIL8 ||
|
|
263
|
+
internalformat == GL_STENCIL_INDEX8;
|
|
264
|
+
/* One depth-stencil format serves every depth renderbuffer, so a pipeline
|
|
265
|
+
* built for the default framebuffer also renders into a user one. */
|
|
266
|
+
const SDL_GPUTextureFormat format =
|
|
267
|
+
depth ? SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT : webgl_storage_format(internalformat);
|
|
268
|
+
int granted_samples = samples > 1 ? samples : 1;
|
|
269
|
+
if (granted_samples > 1 &&
|
|
270
|
+
(!multisample_supported_ ||
|
|
271
|
+
!SDL_GPUTextureSupportsSampleCount(guidev::g_device, format,
|
|
272
|
+
webgl_sample_count(granted_samples)))) {
|
|
273
|
+
/* The backend cannot multisample this target. Degrade to the same
|
|
274
|
+
* single-sampled storage a plain `renderbufferStorage` would allocate, so a
|
|
275
|
+
* page that asks for MSAA still renders (without antialiasing) instead of
|
|
276
|
+
* losing the attachment; `RENDERBUFFER_SAMPLES` then reports 0. */
|
|
277
|
+
granted_samples = 1;
|
|
278
|
+
}
|
|
279
|
+
if (record->gpu != nullptr) {
|
|
280
|
+
submit(); SDL_WaitForGPUIdle(guidev::g_device);
|
|
281
|
+
SDL_ReleaseGPUTexture(guidev::g_device, record->gpu);
|
|
282
|
+
record->gpu = nullptr;
|
|
283
|
+
}
|
|
284
|
+
record->width = width;
|
|
285
|
+
record->height = height;
|
|
286
|
+
record->internalformat = internalformat;
|
|
287
|
+
record->samples = granted_samples;
|
|
288
|
+
record->depth = depth;
|
|
289
|
+
record->format = format;
|
|
290
|
+
SDL_GPUTextureCreateInfo info;
|
|
291
|
+
memset(&info, 0, sizeof(info));
|
|
292
|
+
info.type = SDL_GPU_TEXTURETYPE_2D;
|
|
293
|
+
info.format = format;
|
|
294
|
+
/* A single-sampled colour renderbuffer is also a valid blit source, so it
|
|
295
|
+
* carries SAMPLER usage; a multisampled one cannot be sampled and is
|
|
296
|
+
* resolved through a render pass instead. */
|
|
297
|
+
info.usage = depth ? SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET
|
|
298
|
+
: (SDL_GPU_TEXTUREUSAGE_COLOR_TARGET |
|
|
299
|
+
(record->samples > 1 ? 0 : SDL_GPU_TEXTUREUSAGE_SAMPLER));
|
|
300
|
+
info.width = (Uint32)width;
|
|
301
|
+
info.height = (Uint32)height;
|
|
302
|
+
info.layer_count_or_depth = 1;
|
|
303
|
+
info.num_levels = 1;
|
|
304
|
+
info.sample_count = webgl_sample_count(record->samples);
|
|
305
|
+
record->gpu = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
306
|
+
if (record->gpu == nullptr) {
|
|
307
|
+
set_error(GL_OUT_OF_MEMORY);
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
bool WebGLContext::framebuffer_renderbuffer(uint32_t framebuffer_id, int attachment,
|
|
314
|
+
uint32_t renderbuffer_id) {
|
|
315
|
+
framebuffer_version_ += 1;
|
|
316
|
+
WebGLFramebuffer *framebuffer_ = framebuffer(framebuffer_id);
|
|
317
|
+
WebGLRenderbuffer *record = renderbuffer(renderbuffer_id);
|
|
318
|
+
if (framebuffer_ == nullptr) return false;
|
|
319
|
+
if (renderbuffer_id != 0 && record == nullptr) return false;
|
|
320
|
+
if (attachment == GL_DEPTH_ATTACHMENT || attachment == GL_DEPTH_STENCIL_ATTACHMENT ||
|
|
321
|
+
attachment == GL_STENCIL_ATTACHMENT) {
|
|
322
|
+
framebuffer_->depth_renderbuffer = renderbuffer_id;
|
|
323
|
+
framebuffer_->depth_texture = 0;
|
|
324
|
+
if (framebuffer_->depth != nullptr) {
|
|
325
|
+
submit(); SDL_WaitForGPUIdle(guidev::g_device);
|
|
326
|
+
SDL_ReleaseGPUTexture(guidev::g_device, framebuffer_->depth);
|
|
327
|
+
framebuffer_->depth = nullptr;
|
|
328
|
+
}
|
|
329
|
+
if (record != nullptr && record->width > 0 && record->height > 0) {
|
|
330
|
+
framebuffer_->width = record->width;
|
|
331
|
+
framebuffer_->height = record->height;
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
const int index = attachment - GL_COLOR_ATTACHMENT0;
|
|
336
|
+
if (index < 0 || index >= kWebGLMaxDrawBuffers) return false;
|
|
337
|
+
framebuffer_->color_renderbuffers[index] = renderbuffer_id;
|
|
338
|
+
framebuffer_->color_textures[index] = 0;
|
|
339
|
+
if (record != nullptr && record->width > 0 && record->height > 0) {
|
|
340
|
+
framebuffer_->width = record->width;
|
|
341
|
+
framebuffer_->height = record->height;
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
} // namespace xtgui
|
|
@@ -132,6 +132,10 @@ std::string unroll_glsl_pragmas(const std::string &source);
|
|
|
132
132
|
/** Scan `source` for the declarations WebGL needs to know about. */
|
|
133
133
|
void scan_glsl(const std::string &source, bool fragment, GlslShaderInfo *info);
|
|
134
134
|
|
|
135
|
+
/** Element count of a declaration's array suffix (`"[4]"`, `"[N]"`); arrays
|
|
136
|
+
* whose size is a macro cannot be counted here, so they report one. */
|
|
137
|
+
int glsl_array_size(const std::string &array);
|
|
138
|
+
|
|
135
139
|
/** Rewrite `source` into Vulkan GLSL ES 3.10 (`layout` added everywhere). */
|
|
136
140
|
std::string rewrite_glsl(const std::string &source, bool fragment, const GlslLinkLayout &layout,
|
|
137
141
|
const GlslShaderInfo &info);
|
|
@@ -232,58 +232,89 @@ std::string rewrite_glsl(const std::string &source, bool fragment, const GlslLin
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
int fragment_output = 0;
|
|
235
|
+
/* One source statement can declare several names (`uniform sampler2D a, b;`,
|
|
236
|
+
* `uniform float uNear, uFar;`). The scanner records one site per declarator
|
|
237
|
+
* but they share the statement's span, so the replacements must be emitted
|
|
238
|
+
* once per *statement*, joined together: a rewritten sampler declaration owns
|
|
239
|
+
* a single binding, so each declarator becomes its own statement. */
|
|
240
|
+
struct DeclGroup {
|
|
241
|
+
size_t begin = 0;
|
|
242
|
+
size_t end = 0;
|
|
243
|
+
std::vector<const GlslDeclSite *> sites;
|
|
244
|
+
};
|
|
245
|
+
std::vector<DeclGroup> groups;
|
|
246
|
+
std::unordered_map<size_t, size_t> group_of_begin;
|
|
235
247
|
for (const GlslDeclSite &site : info.sites) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
} else if (site.kind == GlslDeclSite::FragmentOut) {
|
|
269
|
-
location = fragment_output;
|
|
270
|
-
}
|
|
248
|
+
auto found = group_of_begin.find(site.begin);
|
|
249
|
+
if (found == group_of_begin.end()) {
|
|
250
|
+
DeclGroup group;
|
|
251
|
+
group.begin = site.begin;
|
|
252
|
+
group.end = site.end;
|
|
253
|
+
group.sites.push_back(&site);
|
|
254
|
+
group_of_begin.emplace(site.begin, groups.size());
|
|
255
|
+
groups.push_back(std::move(group));
|
|
256
|
+
} else {
|
|
257
|
+
groups[found->second].sites.push_back(&site);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
for (const DeclGroup &group : groups) {
|
|
261
|
+
std::string text;
|
|
262
|
+
for (const GlslDeclSite *site : group.sites) {
|
|
263
|
+
switch (site->kind) {
|
|
264
|
+
case GlslDeclSite::Uniform:
|
|
265
|
+
/* The members moved into the generated block. */
|
|
266
|
+
continue;
|
|
267
|
+
case GlslDeclSite::Sampler: {
|
|
268
|
+
int binding = 0;
|
|
269
|
+
auto found = layout.samplers.find(site->decl.name);
|
|
270
|
+
if (found != layout.samplers.end()) binding = found->second;
|
|
271
|
+
if (!text.empty()) text += "\n";
|
|
272
|
+
text += "layout(set = ";
|
|
273
|
+
text += fragment ? "2" : "0";
|
|
274
|
+
text += ", binding = ";
|
|
275
|
+
text += std::to_string(binding);
|
|
276
|
+
text += ") uniform ";
|
|
277
|
+
text += qualified_declarator_text(site->decl);
|
|
278
|
+
text += ";";
|
|
279
|
+
break;
|
|
271
280
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
281
|
+
case GlslDeclSite::Attribute:
|
|
282
|
+
case GlslDeclSite::Varying:
|
|
283
|
+
case GlslDeclSite::FragmentOut: {
|
|
284
|
+
int location = site->existing_location;
|
|
285
|
+
if (location < 0) {
|
|
286
|
+
if (site->kind == GlslDeclSite::Attribute) {
|
|
287
|
+
auto found = layout.attributes.find(site->decl.name);
|
|
288
|
+
if (found != layout.attributes.end()) location = found->second;
|
|
289
|
+
} else if (site->kind == GlslDeclSite::Varying) {
|
|
290
|
+
auto found = layout.varyings.find(site->decl.name);
|
|
291
|
+
if (found != layout.varyings.end()) location = found->second;
|
|
292
|
+
} else if (site->kind == GlslDeclSite::FragmentOut) {
|
|
293
|
+
location = fragment_output;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (location < 0) location = 0;
|
|
297
|
+
if (site->kind == GlslDeclSite::FragmentOut) {
|
|
298
|
+
fragment_output = location + 1;
|
|
299
|
+
}
|
|
300
|
+
const char *direction = "in";
|
|
301
|
+
if (site->kind == GlslDeclSite::Varying) direction = fragment ? "in" : "out";
|
|
302
|
+
if (site->kind == GlslDeclSite::FragmentOut) direction = "out";
|
|
303
|
+
if (!text.empty()) text += "\n";
|
|
304
|
+
text += "layout(location = " + std::to_string(location) + ") ";
|
|
305
|
+
text += direction;
|
|
306
|
+
text += " ";
|
|
307
|
+
text += qualified_declarator_text(site->decl);
|
|
308
|
+
text += ";";
|
|
309
|
+
break;
|
|
275
310
|
}
|
|
276
|
-
const char *direction = "in";
|
|
277
|
-
if (site.kind == GlslDeclSite::Varying) direction = fragment ? "in" : "out";
|
|
278
|
-
if (site.kind == GlslDeclSite::FragmentOut) direction = "out";
|
|
279
|
-
edit.text = "layout(location = " + std::to_string(location) + ") ";
|
|
280
|
-
edit.text += direction;
|
|
281
|
-
edit.text += " ";
|
|
282
|
-
edit.text += qualified_declarator_text(site.decl);
|
|
283
|
-
edit.text += ";";
|
|
284
|
-
break;
|
|
285
311
|
}
|
|
286
312
|
}
|
|
313
|
+
Edit edit;
|
|
314
|
+
edit.begin = group.begin;
|
|
315
|
+
edit.end = group.end;
|
|
316
|
+
edit.text = text;
|
|
317
|
+
edit.order = 3;
|
|
287
318
|
edits.push_back(edit);
|
|
288
319
|
}
|
|
289
320
|
|
|
@@ -359,6 +359,20 @@ ConditionValue evaluate_condition(const std::string &directive,
|
|
|
359
359
|
|
|
360
360
|
} // namespace
|
|
361
361
|
|
|
362
|
+
int glsl_array_size(const std::string &array) {
|
|
363
|
+
int size = 0;
|
|
364
|
+
bool numeric = true;
|
|
365
|
+
for (char ch : array) {
|
|
366
|
+
if (ch == ' ' || ch == '\t' || ch == '[' || ch == ']') continue;
|
|
367
|
+
if (ch < '0' || ch > '9') {
|
|
368
|
+
numeric = false;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
size = size * 10 + (ch - '0');
|
|
372
|
+
}
|
|
373
|
+
return numeric && size > 0 ? size : 1;
|
|
374
|
+
}
|
|
375
|
+
|
|
362
376
|
void scan_glsl(const std::string &source, bool fragment, GlslShaderInfo *info) {
|
|
363
377
|
*info = GlslShaderInfo();
|
|
364
378
|
const std::vector<Token> tokens = tokenize(source);
|
|
@@ -39,6 +39,9 @@ struct WebGLBuffer {
|
|
|
39
39
|
int usage = GL_STATIC_DRAW;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
+
/** Samples per texel of a texture or renderbuffer. 1 means single-sampled. */
|
|
43
|
+
constexpr int kWebGLMaxSamples = 4;
|
|
44
|
+
|
|
42
45
|
struct WebGLTexture {
|
|
43
46
|
uint32_t id = 0;
|
|
44
47
|
int width = 0;
|
|
@@ -61,6 +64,8 @@ struct WebGLTexture {
|
|
|
61
64
|
bool has_mipmaps = false;
|
|
62
65
|
int min_filter = 0;
|
|
63
66
|
int mag_filter = 0;
|
|
67
|
+
/** `TEXTURE_MAX_ANISOTROPY_EXT`; 1 disables anisotropic filtering. */
|
|
68
|
+
int anisotropy = 1;
|
|
64
69
|
int wrap_s = 0;
|
|
65
70
|
int wrap_t = 0;
|
|
66
71
|
SDL_GPUSampler *sampler = nullptr;
|
|
@@ -70,19 +75,30 @@ struct WebGLTexture {
|
|
|
70
75
|
int compare_func = GL_LEQUAL;
|
|
71
76
|
bool dirty = false;
|
|
72
77
|
bool defined = false;
|
|
78
|
+
/** >1 for a texture allocated with `texStorage2DMultisample`: it is a
|
|
79
|
+
* render target only (SDL_GPU cannot bind a multisampled texture to a
|
|
80
|
+
* sampler), and its contents are resolved with `blitFramebuffer`. */
|
|
81
|
+
int samples = 1;
|
|
73
82
|
};
|
|
74
83
|
|
|
75
84
|
struct WebGLRenderbuffer {
|
|
76
85
|
uint32_t id = 0;
|
|
77
86
|
int width = 0;
|
|
78
87
|
int height = 0;
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
/** The GL internal format the page asked for, reported back by
|
|
89
|
+
* `getRenderbufferParameter`. */
|
|
90
|
+
int internalformat = GL_RGBA8;
|
|
91
|
+
int samples = 1;
|
|
92
|
+
bool depth = false;
|
|
93
|
+
SDL_GPUTextureFormat format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
94
|
+
SDL_GPUTexture *gpu = nullptr;
|
|
81
95
|
};
|
|
82
96
|
|
|
83
97
|
struct WebGLFramebuffer {
|
|
84
98
|
uint32_t id = 0;
|
|
85
99
|
uint32_t color_textures[kWebGLMaxDrawBuffers] = {};
|
|
100
|
+
/** Colour renderbuffer attached to `COLOR_ATTACHMENTi` (0 when a texture is). */
|
|
101
|
+
uint32_t color_renderbuffers[kWebGLMaxDrawBuffers] = {};
|
|
86
102
|
/** Layer rendered to for an array/cube colour attachment. */
|
|
87
103
|
int color_layers[kWebGLMaxDrawBuffers] = {};
|
|
88
104
|
/** `COLOR_ATTACHMENTi` or `NONE` per draw-buffer slot. */
|
|
@@ -295,7 +295,7 @@ SDL_GPUGraphicsPipeline *WebGLContext::create_pipeline(
|
|
|
295
295
|
info.rasterizer_state.front_face =
|
|
296
296
|
state_.front_face == GL_CW ? SDL_GPU_FRONTFACE_CLOCKWISE
|
|
297
297
|
: SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
|
|
298
|
-
info.multisample_state.sample_count =
|
|
298
|
+
info.multisample_state.sample_count = webgl_sample_count(state_.sample_count);
|
|
299
299
|
info.depth_stencil_state.enable_depth_test = state_.depth_test;
|
|
300
300
|
info.depth_stencil_state.enable_depth_write = state_.depth_write;
|
|
301
301
|
info.depth_stencil_state.compare_op = compare_op(state_.depth_func);
|
|
@@ -452,6 +452,7 @@ bool WebGLContext::link_program(uint32_t id) {
|
|
|
452
452
|
uniform.compare = compare;
|
|
453
453
|
uniform.unit = 0;
|
|
454
454
|
uniform.layout.gl_type = gl_type_of(decl.type);
|
|
455
|
+
if (!decl.array.empty()) { uniform.layout.is_array = true; uniform.layout.array_size = glsl_array_size(decl.array); }
|
|
455
456
|
index = (int)program->uniforms.size();
|
|
456
457
|
program->uniform_index[decl.name] = index;
|
|
457
458
|
program->uniforms.push_back(uniform);
|
|
@@ -460,7 +461,6 @@ bool WebGLContext::link_program(uint32_t id) {
|
|
|
460
461
|
};
|
|
461
462
|
for (const GlslUniformDecl &decl : vs_info.samplers) add_sampler(record, &record->vs_sampler_uniforms, decl);
|
|
462
463
|
for (const GlslUniformDecl &decl : fs_info.samplers) add_sampler(record, &record->fs_sampler_uniforms, decl);
|
|
463
|
-
|
|
464
464
|
webgl_detail::build_uniform_blocks(record, vs_info.blocks, fs_info.blocks, members);
|
|
465
465
|
|
|
466
466
|
/* (Re)create the SDL shaders. */
|