xbintsc 0.5.31 → 0.5.36
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/README.md +25 -16
- package/README.zh-CN.md +10 -8
- package/dist/scripts/check-version.d.ts +27 -0
- package/dist/scripts/check-version.js +71 -0
- package/dist/scripts/check-version.js.map +1 -0
- package/dist/scripts/package-platform.d.ts +58 -0
- package/dist/scripts/package-platform.js +142 -0
- package/dist/scripts/package-platform.js.map +1 -0
- package/dist/scripts/verify-platform-package.d.ts +34 -0
- package/dist/scripts/verify-platform-package.js +161 -0
- package/dist/scripts/verify-platform-package.js.map +1 -0
- package/dist/src/binder/references.js +14 -1
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +3 -1
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/module.d.ts +1 -0
- package/dist/src/codegen/generator/module.js +54 -0
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/statements/variables.js +6 -4
- package/dist/src/codegen/generator/statements/variables.js.map +1 -1
- package/dist/src/driver/runtime-lib.d.ts +29 -4
- package/dist/src/driver/runtime-lib.js +68 -10
- package/dist/src/driver/runtime-lib.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/css.d.ts +26 -0
- package/dist/src/extensions/gui/css.js +100 -0
- package/dist/src/extensions/gui/css.js.map +1 -0
- package/dist/src/extensions/gui/html.js +9 -2
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +22 -7
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/gui/three.d.ts +16 -0
- package/dist/src/extensions/gui/three.js +22 -0
- package/dist/src/extensions/gui/three.js.map +1 -0
- package/dist/src/extensions/media/index.d.ts +6 -5
- package/dist/src/extensions/media/index.js +15 -16
- package/dist/src/extensions/media/index.js.map +1 -1
- package/dist/src/parser/context.d.ts +41 -0
- package/dist/src/parser/context.js +89 -4
- package/dist/src/parser/context.js.map +1 -1
- package/dist/src/parser/literals.js +6 -12
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/driver/platform-package.test.d.ts +1 -0
- package/dist/tests/driver/platform-package.test.js +49 -0
- package/dist/tests/driver/platform-package.test.js.map +1 -0
- package/dist/tests/driver/runtime-lib.test.js +51 -4
- package/dist/tests/driver/runtime-lib.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +24 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js +23 -0
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio.test.d.ts +14 -0
- package/dist/tests/e2e/gui-audio.test.js +287 -0
- package/dist/tests/e2e/gui-audio.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +1 -1
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-effects.test.d.ts +6 -0
- package/dist/tests/e2e/gui-effects.test.js +262 -0
- package/dist/tests/e2e/gui-effects.test.js.map +1 -0
- package/dist/tests/e2e/gui-example-webgl.test.d.ts +10 -0
- package/dist/tests/e2e/gui-example-webgl.test.js +75 -0
- package/dist/tests/e2e/gui-example-webgl.test.js.map +1 -0
- package/dist/tests/e2e/gui-example-webgl2.test.d.ts +8 -0
- package/dist/tests/e2e/gui-example-webgl2.test.js +72 -0
- package/dist/tests/e2e/gui-example-webgl2.test.js.map +1 -0
- package/dist/tests/e2e/gui-helpers.d.ts +7 -0
- package/dist/tests/e2e/gui-helpers.js +1 -0
- package/dist/tests/e2e/gui-helpers.js.map +1 -1
- package/dist/tests/e2e/gui-layout.test.js +48 -0
- package/dist/tests/e2e/gui-layout.test.js.map +1 -1
- package/dist/tests/e2e/gui-media.test.js +83 -4
- package/dist/tests/e2e/gui-media.test.js.map +1 -1
- package/dist/tests/e2e/gui-style.test.js +55 -0
- package/dist/tests/e2e/gui-style.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl.test.js +437 -0
- package/dist/tests/e2e/gui-webgl.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-3d.test.d.ts +4 -0
- package/dist/tests/e2e/gui-webgl2-3d.test.js +264 -0
- package/dist/tests/e2e/gui-webgl2-3d.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +262 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-formats.test.d.ts +6 -0
- package/dist/tests/e2e/gui-webgl2-formats.test.js +395 -0
- package/dist/tests/e2e/gui-webgl2-formats.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-mrt.test.d.ts +4 -0
- package/dist/tests/e2e/gui-webgl2-mrt.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-mrt.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-ubo.test.d.ts +8 -0
- package/dist/tests/e2e/gui-webgl2-ubo.test.js +112 -0
- package/dist/tests/e2e/gui-webgl2-ubo.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2.test.js +282 -0
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -0
- package/dist/tests/extensions/gui-index.test.js +1 -0
- package/dist/tests/extensions/gui-index.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +41 -0
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/extensions/media.test.js +8 -3
- package/dist/tests/extensions/media.test.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +30 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/dist/tests/platform-tarball.test.d.ts +1 -0
- package/dist/tests/platform-tarball.test.js +111 -0
- package/dist/tests/platform-tarball.test.js.map +1 -0
- package/dist/tests/version.test.js +6 -0
- package/dist/tests/version.test.js.map +1 -1
- package/doc/ai/contributing.md +11 -0
- package/doc/ai/extensions.md +35 -12
- package/doc/ai/troubleshooting.md +17 -11
- package/doc/ai/zh-CN/contributing.md +9 -0
- package/doc/ai/zh-CN/extensions.md +30 -10
- package/doc/ai/zh-CN/troubleshooting.md +14 -8
- package/doc/gui/api.md +63 -14
- package/doc/gui/build.md +79 -16
- package/doc/gui/canvas.md +11 -3
- package/doc/gui/dom.md +35 -17
- package/doc/gui/known-issues.md +57 -24
- package/doc/gui/layout.md +18 -0
- package/doc/gui/media.md +21 -13
- package/doc/gui/rendering.md +50 -3
- package/doc/gui/webgl.md +315 -0
- package/doc/gui.md +113 -18
- package/doc/npm-package.md +59 -29
- package/doc/requirements.md +24 -11
- package/doc/zh-CN/gui/api.md +53 -11
- package/doc/zh-CN/gui/build.md +70 -16
- package/doc/zh-CN/gui/canvas.md +9 -2
- package/doc/zh-CN/gui/dom.md +22 -7
- package/doc/zh-CN/gui/known-issues.md +45 -19
- package/doc/zh-CN/gui/layout.md +14 -0
- package/doc/zh-CN/gui/media.md +18 -11
- package/doc/zh-CN/gui/rendering.md +41 -4
- package/doc/zh-CN/gui/webgl.md +121 -0
- package/doc/zh-CN/gui.md +91 -15
- package/doc/zh-CN/npm-package.md +48 -24
- package/doc/zh-CN/requirements.md +16 -7
- package/llms.txt +2 -0
- package/package.json +17 -1
- package/runtime/ext_gui/audio.cpp +365 -153
- package/runtime/ext_gui/audio_buffer.cpp +166 -0
- package/runtime/ext_gui/audio_buffer.h +37 -0
- package/runtime/ext_gui/audio_decode.cpp +219 -0
- package/runtime/ext_gui/audio_decode.h +39 -0
- package/runtime/ext_gui/audio_device.cpp +87 -0
- package/runtime/ext_gui/audio_effects.cpp +163 -0
- package/runtime/ext_gui/audio_effects.h +25 -0
- package/runtime/ext_gui/audio_internal.h +30 -0
- package/runtime/ext_gui/audio_mixer.cpp +494 -0
- package/runtime/ext_gui/audio_mixer.h +238 -0
- package/runtime/ext_gui/audio_param.cpp +104 -0
- package/runtime/ext_gui/audio_param_object.cpp +155 -0
- package/runtime/ext_gui/browser.cpp +50 -14
- package/runtime/ext_gui/canvas.cpp +3 -18
- package/runtime/ext_gui/canvas_internal.h +10 -0
- package/runtime/ext_gui/canvas_raster.cpp +60 -0
- package/runtime/ext_gui/clip_values.cpp +246 -0
- package/runtime/ext_gui/css.cpp +94 -0
- package/runtime/ext_gui/css.h +22 -1
- package/runtime/ext_gui/css_match.cpp +3 -0
- package/runtime/ext_gui/css_selector.cpp +30 -3
- package/runtime/ext_gui/css_sheet.cpp +89 -45
- package/runtime/ext_gui/document.cpp +4 -1
- package/runtime/ext_gui/document.h +2 -0
- package/runtime/ext_gui/dom.h +16 -0
- package/runtime/ext_gui/dom_api.cpp +1 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +17 -80
- package/runtime/ext_gui/dom_api_canvas_extra.cpp +130 -1
- package/runtime/ext_gui/dom_api_canvas_pending.cpp +41 -0
- package/runtime/ext_gui/dom_api_internal.h +275 -0
- package/runtime/ext_gui/dom_api_webgl.cpp +383 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +549 -0
- package/runtime/ext_gui/dom_api_webgl2_draw.cpp +269 -0
- package/runtime/ext_gui/dom_api_webgl_buffer.cpp +216 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +167 -0
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +160 -0
- package/runtime/ext_gui/dom_api_webgl_rt.h +30 -0
- package/runtime/ext_gui/dom_api_webgl_shader.cpp +443 -0
- package/runtime/ext_gui/dom_api_webgl_source.cpp +161 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +590 -0
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +485 -0
- package/runtime/ext_gui/dom_api_webgl_ubo.cpp +81 -0
- package/runtime/ext_gui/effect_values.cpp +312 -0
- package/runtime/ext_gui/gradient_values.cpp +476 -0
- package/runtime/ext_gui/grid_values.cpp +230 -0
- package/runtime/ext_gui/gui.cpp +44 -9
- package/runtime/ext_gui/gui_canvas.cpp +50 -2
- package/runtime/ext_gui/gui_engine.h +36 -4
- package/runtime/ext_gui/gui_events.cpp +4 -1
- package/runtime/ext_gui/gui_media.cpp +1 -1
- package/runtime/ext_gui/gui_webgl.cpp +83 -0
- package/runtime/ext_gui/image_bitmap.cpp +28 -0
- package/runtime/ext_gui/image_bitmap.h +26 -0
- package/runtime/ext_gui/image_bitmap_browser.cpp +136 -0
- package/runtime/ext_gui/layout.cpp +21 -0
- package/runtime/ext_gui/layout_flow.cpp +81 -4
- package/runtime/ext_gui/layout_flow_internal.h +31 -0
- package/runtime/ext_gui/layout_grid.cpp +374 -0
- package/runtime/ext_gui/media.cpp +32 -0
- package/runtime/ext_gui/media.h +14 -1
- package/runtime/ext_gui/media_api.h +25 -2
- package/runtime/ext_gui/media_query.cpp +211 -0
- package/runtime/ext_gui/paint.cpp +111 -77
- package/runtime/ext_gui/paint.h +33 -3
- package/runtime/ext_gui/paint_background.cpp +229 -0
- package/runtime/ext_gui/paint_clip.cpp +268 -0
- package/runtime/ext_gui/paint_effects.cpp +324 -0
- package/runtime/ext_gui/paint_internal.h +85 -0
- package/runtime/ext_gui/renderer.cpp +8 -31
- package/runtime/ext_gui/renderer_clip.cpp +196 -0
- package/runtime/ext_gui/renderer_image.cpp +13 -8
- package/runtime/ext_gui/renderer_internal.h +15 -8
- package/runtime/ext_gui/renderer_text.cpp +6 -31
- package/runtime/ext_gui/style.cpp +343 -20
- package/runtime/ext_gui/style.h +144 -3
- package/runtime/ext_gui/style_print.cpp +134 -1
- package/runtime/ext_gui/style_values.cpp +152 -126
- package/runtime/ext_gui/style_values_internal.h +35 -0
- package/runtime/ext_gui/webgl.h +600 -0
- package/runtime/ext_gui/webgl2_constants.h +274 -0
- package/runtime/ext_gui/webgl_blit.cpp +95 -0
- package/runtime/ext_gui/webgl_buffer.cpp +480 -0
- package/runtime/ext_gui/webgl_buffer_objects.cpp +270 -0
- package/runtime/ext_gui/webgl_clear.cpp +142 -0
- package/runtime/ext_gui/webgl_compressed.cpp +180 -0
- package/runtime/ext_gui/webgl_constants.h +317 -0
- package/runtime/ext_gui/webgl_context.cpp +551 -0
- package/runtime/ext_gui/webgl_draw.cpp +560 -0
- package/runtime/ext_gui/webgl_draw_buffers.cpp +75 -0
- package/runtime/ext_gui/webgl_glsl.h +165 -0
- package/runtime/ext_gui/webgl_glsl_compile.cpp +437 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +367 -0
- package/runtime/ext_gui/webgl_glsl_scan.cpp +590 -0
- package/runtime/ext_gui/webgl_glsl_scan_block.cpp +126 -0
- package/runtime/ext_gui/webgl_glsl_tokens.h +28 -0
- package/runtime/ext_gui/webgl_msl.cpp +62 -0
- package/runtime/ext_gui/webgl_msl.h +33 -0
- package/runtime/ext_gui/webgl_pipeline.cpp +326 -0
- package/runtime/ext_gui/webgl_program_blocks.cpp +58 -0
- package/runtime/ext_gui/webgl_program_internal.h +24 -0
- package/runtime/ext_gui/webgl_shader.cpp +594 -0
- package/runtime/ext_gui/webgl_state.cpp +228 -0
- package/runtime/ext_gui/webgl_texture.cpp +420 -0
- package/runtime/ext_gui/webgl_texture_3d.cpp +215 -0
- package/runtime/ext_gui/webgl_uniform.cpp +167 -0
- package/runtime/ext_gui/webgl_uniform_block.h +31 -0
- package/runtime/ext_gui/webgl_webgl2.cpp +277 -0
- package/runtime/ext_media/decode_audio.cpp +308 -0
- package/runtime/ext_media/media.cpp +1 -1
- package/runtime/ext_media/media_bridge.c +11 -3
- package/runtime/rt.h +17 -0
- package/runtime/rt_internal.h +1 -0
- package/runtime/xt_array_buffer.c +30 -0
- package/runtime/xt_containers/access.inc +8 -0
- package/runtime/xt_regex/api.inc +2 -0
- package/runtime/xt_regex/matcher.inc +16 -3
- package/runtime/xt_regex/parser.inc +8 -2
- package/runtime/xt_regex/types.inc +3 -0
- package/runtime/xt_stdlib2/regexp-match.inc +60 -21
- package/runtime/xt_stdlib2/regexp.inc +1 -0
- package/runtime/xt_typed_array/elements.inc +13 -0
- package/runtime/xt_typed_array.c +1 -1
- package/scripts/build-gui.ts +90 -3
- package/scripts/build-media.ts +335 -62
- package/scripts/build-runtime.ts +21 -16
- package/scripts/check-version.ts +39 -9
- package/scripts/package-platform.ts +183 -0
- package/scripts/set-platform-version.ts +62 -0
- package/scripts/setup-vs-toolchain.ps1 +152 -0
- package/scripts/verify-platform-package.ts +182 -0
- package/src/binder/references.ts +13 -1
- package/src/cli/main.ts +5 -1
- package/src/codegen/generator/module.ts +50 -0
- package/src/codegen/generator/statements/variables.ts +6 -3
- package/src/driver/runtime-lib.ts +73 -9
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/css.ts +113 -0
- package/src/extensions/gui/html.ts +9 -2
- package/src/extensions/gui/index.ts +22 -7
- package/src/extensions/gui/three.ts +25 -0
- package/src/extensions/media/index.ts +16 -18
- package/src/parser/context.ts +99 -4
- package/src/parser/literals.ts +6 -12
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — WebGL fixed-function state.
|
|
3
|
+
*
|
|
4
|
+
* SDL_GPU bakes blend/depth/stencil/rasterisation into a pipeline, so these
|
|
5
|
+
* setters only record the values; `webgl_draw.cpp` hashes them into the
|
|
6
|
+
* pipeline cache key and `webgl_pipeline.cpp` builds the matching state.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "webgl.h"
|
|
10
|
+
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <cstring>
|
|
13
|
+
|
|
14
|
+
#include "gui_internal.h"
|
|
15
|
+
|
|
16
|
+
namespace xtgui {
|
|
17
|
+
|
|
18
|
+
/* -- state --------------------------------------------------------------- */
|
|
19
|
+
|
|
20
|
+
void WebGLContext::enable(int cap) {
|
|
21
|
+
if (cap == GL_BLEND) state_.blend = true;
|
|
22
|
+
if (cap == GL_DEPTH_TEST) state_.depth_test = true;
|
|
23
|
+
if (cap == GL_CULL_FACE) state_.cull = true;
|
|
24
|
+
if (cap == GL_SCISSOR_TEST) scissor_test_ = true;
|
|
25
|
+
if (cap == GL_STENCIL_TEST) state_.stencil = true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void WebGLContext::disable(int cap) {
|
|
29
|
+
if (cap == GL_BLEND) state_.blend = false;
|
|
30
|
+
if (cap == GL_DEPTH_TEST) state_.depth_test = false;
|
|
31
|
+
if (cap == GL_CULL_FACE) state_.cull = false;
|
|
32
|
+
if (cap == GL_SCISSOR_TEST) scissor_test_ = false;
|
|
33
|
+
if (cap == GL_STENCIL_TEST) state_.stencil = false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bool WebGLContext::is_enabled(int cap) const {
|
|
37
|
+
if (cap == GL_BLEND) return state_.blend;
|
|
38
|
+
if (cap == GL_DEPTH_TEST) return state_.depth_test;
|
|
39
|
+
if (cap == GL_CULL_FACE) return state_.cull;
|
|
40
|
+
if (cap == GL_SCISSOR_TEST) return scissor_test_;
|
|
41
|
+
if (cap == GL_STENCIL_TEST) return state_.stencil;
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void WebGLContext::clear_color(float r, float g, float b, float a) {
|
|
46
|
+
clear_color_[0] = r;
|
|
47
|
+
clear_color_[1] = g;
|
|
48
|
+
clear_color_[2] = b;
|
|
49
|
+
clear_color_[3] = a;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void WebGLContext::color_mask(bool r, bool g, bool b, bool a) {
|
|
53
|
+
state_.color_mask[0] = r;
|
|
54
|
+
state_.color_mask[1] = g;
|
|
55
|
+
state_.color_mask[2] = b;
|
|
56
|
+
state_.color_mask[3] = a;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void WebGLContext::blend_func(int src, int dst) {
|
|
60
|
+
state_.blend_src_rgb = src;
|
|
61
|
+
state_.blend_dst_rgb = dst;
|
|
62
|
+
state_.blend_src_alpha = src;
|
|
63
|
+
state_.blend_dst_alpha = dst;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
void WebGLContext::blend_func_separate(int src_rgb, int dst_rgb, int src_alpha, int dst_alpha) {
|
|
67
|
+
state_.blend_src_rgb = src_rgb;
|
|
68
|
+
state_.blend_dst_rgb = dst_rgb;
|
|
69
|
+
state_.blend_src_alpha = src_alpha;
|
|
70
|
+
state_.blend_dst_alpha = dst_alpha;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
void WebGLContext::blend_equation(int mode) {
|
|
74
|
+
state_.blend_eq_rgb = mode;
|
|
75
|
+
state_.blend_eq_alpha = mode;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
void WebGLContext::blend_equation_separate(int rgb, int alpha) {
|
|
79
|
+
state_.blend_eq_rgb = rgb;
|
|
80
|
+
state_.blend_eq_alpha = alpha;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void WebGLContext::blend_color(float r, float g, float b, float a) {
|
|
84
|
+
blend_color_[0] = r;
|
|
85
|
+
blend_color_[1] = g;
|
|
86
|
+
blend_color_[2] = b;
|
|
87
|
+
blend_color_[3] = a;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void WebGLContext::blend_color_value(float out[4]) const {
|
|
91
|
+
for (int i = 0; i < 4; i++) out[i] = blend_color_[i];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void WebGLContext::cull_face(int mode) { state_.cull_face = mode; }
|
|
95
|
+
|
|
96
|
+
void WebGLContext::front_face(int mode) { state_.front_face = mode; }
|
|
97
|
+
|
|
98
|
+
void WebGLContext::stencil_func(int func, int ref, uint32_t mask) {
|
|
99
|
+
stencil_func_separate(GL_FRONT_AND_BACK, func, ref, mask);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void WebGLContext::stencil_func_separate(int face, int func, int ref, uint32_t mask) {
|
|
103
|
+
if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
|
|
104
|
+
state_.stencil_front.func = func;
|
|
105
|
+
state_.stencil_front.ref = ref;
|
|
106
|
+
state_.stencil_front.value_mask = mask;
|
|
107
|
+
}
|
|
108
|
+
if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
|
|
109
|
+
state_.stencil_back.func = func;
|
|
110
|
+
state_.stencil_back.ref = ref;
|
|
111
|
+
state_.stencil_back.value_mask = mask;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
void WebGLContext::stencil_op(int fail, int zfail, int zpass) {
|
|
116
|
+
stencil_op_separate(GL_FRONT_AND_BACK, fail, zfail, zpass);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
void WebGLContext::stencil_op_separate(int face, int fail, int zfail, int zpass) {
|
|
120
|
+
if (face == GL_FRONT || face == GL_FRONT_AND_BACK) {
|
|
121
|
+
state_.stencil_front.fail = fail;
|
|
122
|
+
state_.stencil_front.zfail = zfail;
|
|
123
|
+
state_.stencil_front.zpass = zpass;
|
|
124
|
+
}
|
|
125
|
+
if (face == GL_BACK || face == GL_FRONT_AND_BACK) {
|
|
126
|
+
state_.stencil_back.fail = fail;
|
|
127
|
+
state_.stencil_back.zfail = zfail;
|
|
128
|
+
state_.stencil_back.zpass = zpass;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
void WebGLContext::stencil_mask(uint32_t mask) {
|
|
133
|
+
stencil_mask_separate(GL_FRONT_AND_BACK, mask);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
void WebGLContext::stencil_mask_separate(int face, uint32_t mask) {
|
|
137
|
+
if (face == GL_FRONT || face == GL_FRONT_AND_BACK) state_.stencil_front.write_mask = mask;
|
|
138
|
+
if (face == GL_BACK || face == GL_FRONT_AND_BACK) state_.stencil_back.write_mask = mask;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const WebGLStencilFace &WebGLContext::stencil_face(int face) const {
|
|
142
|
+
return face == GL_FRONT ? state_.stencil_front : state_.stencil_back;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
int WebGLContext::stencil_reference() const {
|
|
146
|
+
/* SDL_GPU has one stencil reference for a draw; the front value is the
|
|
147
|
+
* WebGL default for both faces. */
|
|
148
|
+
return state_.stencil_front.ref;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void WebGLContext::viewport(int x, int y, int w, int h) {
|
|
152
|
+
viewport_[0] = x;
|
|
153
|
+
viewport_[1] = y;
|
|
154
|
+
viewport_[2] = w;
|
|
155
|
+
viewport_[3] = h;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
void WebGLContext::scissor(int x, int y, int w, int h) {
|
|
159
|
+
scissor_box_[0] = x;
|
|
160
|
+
scissor_box_[1] = y;
|
|
161
|
+
scissor_box_[2] = w;
|
|
162
|
+
scissor_box_[3] = h;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
void WebGLContext::clear(int mask) {
|
|
166
|
+
if (guidev::g_device == nullptr) return;
|
|
167
|
+
const bool color_bit = (mask & GL_COLOR_BUFFER_BIT) != 0;
|
|
168
|
+
const bool depth_bit = (mask & GL_DEPTH_BUFFER_BIT) != 0;
|
|
169
|
+
const bool stencil_bit = (mask & GL_STENCIL_BUFFER_BIT) != 0;
|
|
170
|
+
const bool scissored = scissor_test_ && scissor_box_[2] > 0 && scissor_box_[3] > 0;
|
|
171
|
+
if (!scissored) {
|
|
172
|
+
begin_pass(color_bit, depth_bit, stencil_bit);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (color_bit) {
|
|
176
|
+
SDL_GPUTexture *source = clear_color_texture();
|
|
177
|
+
SDL_GPUTexture *destination = target_color();
|
|
178
|
+
int target_width = 0;
|
|
179
|
+
int target_height = 0;
|
|
180
|
+
framebuffer_size(bound_framebuffer_, &target_width, &target_height);
|
|
181
|
+
if (source != nullptr && destination != nullptr && target_width > 0 && target_height > 0) {
|
|
182
|
+
end_pass();
|
|
183
|
+
ensure_command();
|
|
184
|
+
if (cmd_ != nullptr) {
|
|
185
|
+
int x = std::max(0, scissor_box_[0]);
|
|
186
|
+
int y = std::max(0, scissor_box_[1]);
|
|
187
|
+
int w = scissor_box_[2];
|
|
188
|
+
int h = scissor_box_[3];
|
|
189
|
+
if (x + w > target_width) w = target_width - x;
|
|
190
|
+
if (y + h > target_height) h = target_height - y;
|
|
191
|
+
if (w > 0 && h > 0) {
|
|
192
|
+
SDL_GPUBlitRegion source_region;
|
|
193
|
+
memset(&source_region, 0, sizeof(source_region));
|
|
194
|
+
source_region.texture = source;
|
|
195
|
+
source_region.w = 1;
|
|
196
|
+
source_region.h = 1;
|
|
197
|
+
SDL_GPUBlitRegion destination_region;
|
|
198
|
+
memset(&destination_region, 0, sizeof(destination_region));
|
|
199
|
+
destination_region.texture = destination;
|
|
200
|
+
destination_region.x = (Uint32)x;
|
|
201
|
+
destination_region.y = (Uint32)(target_height - (y + h));
|
|
202
|
+
destination_region.w = (Uint32)w;
|
|
203
|
+
destination_region.h = (Uint32)h;
|
|
204
|
+
SDL_GPUBlitInfo info;
|
|
205
|
+
memset(&info, 0, sizeof(info));
|
|
206
|
+
info.source = source_region;
|
|
207
|
+
info.destination = destination_region;
|
|
208
|
+
/* The pixels outside the scissor rectangle must survive the clear, so
|
|
209
|
+
* the blit has to load the destination. DONT_CARE maps to Metal's
|
|
210
|
+
* MTLLoadActionDontCare, which discards the whole attachment before
|
|
211
|
+
* the blit writes its region and leaves the rest undefined (Vulkan
|
|
212
|
+
* happened to preserve it, which hid this in CI on Linux). */
|
|
213
|
+
info.load_op = SDL_GPU_LOADOP_LOAD;
|
|
214
|
+
info.filter = SDL_GPU_FILTER_NEAREST;
|
|
215
|
+
SDL_BlitGPUTexture(cmd_, &info);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (depth_bit || stencil_bit) scissored_clear(mask);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
void WebGLContext::finish() {
|
|
224
|
+
submit();
|
|
225
|
+
if (guidev::g_device != nullptr) SDL_WaitForGPUIdle(guidev::g_device);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
} // namespace xtgui
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc GUI engine — WebGL texture uploads, mipmaps and `readPixels`.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "webgl.h"
|
|
6
|
+
|
|
7
|
+
#include <algorithm>
|
|
8
|
+
#include <cstring>
|
|
9
|
+
|
|
10
|
+
#include "gui_internal.h"
|
|
11
|
+
|
|
12
|
+
namespace xtgui {
|
|
13
|
+
namespace {
|
|
14
|
+
|
|
15
|
+
bool depth_texture_format(SDL_GPUTextureFormat format) {
|
|
16
|
+
return format == SDL_GPU_TEXTUREFORMAT_D16_UNORM ||
|
|
17
|
+
format == SDL_GPU_TEXTUREFORMAT_D24_UNORM ||
|
|
18
|
+
format == SDL_GPU_TEXTUREFORMAT_D32_FLOAT ||
|
|
19
|
+
format == SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT ||
|
|
20
|
+
format == SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
int texel_bytes(SDL_GPUTextureFormat format) {
|
|
24
|
+
if (format == SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT) return 8;
|
|
25
|
+
if (format == SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT) return 16;
|
|
26
|
+
return 4;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Upload a rectangle of tightly packed texels into level 0 of `gpu`. `pixels`
|
|
30
|
+
* may be null, which uploads zeros. */
|
|
31
|
+
bool upload_region(SDL_GPUDevice *device, SDL_GPUCommandBuffer *cmd, SDL_GPUTexture *gpu, int x,
|
|
32
|
+
int y, int width, int height, const uint8_t *pixels, int bytes_per_texel,
|
|
33
|
+
int layer = 0) {
|
|
34
|
+
const uint32_t bytes = (uint32_t)(width * height * bytes_per_texel);
|
|
35
|
+
if (bytes == 0) return true;
|
|
36
|
+
std::vector<uint8_t> zeros;
|
|
37
|
+
if (pixels == nullptr) {
|
|
38
|
+
zeros.assign(bytes, 0);
|
|
39
|
+
pixels = zeros.data();
|
|
40
|
+
}
|
|
41
|
+
SDL_GPUTransferBufferCreateInfo info;
|
|
42
|
+
memset(&info, 0, sizeof(info));
|
|
43
|
+
info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
|
|
44
|
+
info.size = bytes;
|
|
45
|
+
SDL_GPUTransferBuffer *transfer = SDL_CreateGPUTransferBuffer(device, &info);
|
|
46
|
+
if (transfer == nullptr) return false;
|
|
47
|
+
void *mapped = SDL_MapGPUTransferBuffer(device, transfer, false);
|
|
48
|
+
if (mapped == nullptr) {
|
|
49
|
+
SDL_ReleaseGPUTransferBuffer(device, transfer);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
memcpy(mapped, pixels, bytes);
|
|
53
|
+
SDL_UnmapGPUTransferBuffer(device, transfer);
|
|
54
|
+
SDL_GPUTextureTransferInfo source;
|
|
55
|
+
memset(&source, 0, sizeof(source));
|
|
56
|
+
source.transfer_buffer = transfer;
|
|
57
|
+
source.pixels_per_row = (Uint32)width;
|
|
58
|
+
source.rows_per_layer = (Uint32)height;
|
|
59
|
+
SDL_GPUTextureRegion region;
|
|
60
|
+
memset(®ion, 0, sizeof(region));
|
|
61
|
+
region.texture = gpu;
|
|
62
|
+
region.x = (Uint32)x;
|
|
63
|
+
region.y = (Uint32)y;
|
|
64
|
+
region.layer = (Uint32)layer;
|
|
65
|
+
region.w = (Uint32)width;
|
|
66
|
+
region.h = (Uint32)height;
|
|
67
|
+
region.d = 1;
|
|
68
|
+
SDL_GPUCopyPass *copy = SDL_BeginGPUCopyPass(cmd);
|
|
69
|
+
SDL_UploadToGPUTexture(copy, &source, ®ion, false);
|
|
70
|
+
SDL_EndGPUCopyPass(copy);
|
|
71
|
+
SDL_ReleaseGPUTransferBuffer(device, transfer);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // namespace
|
|
76
|
+
|
|
77
|
+
SDL_GPUTexture *WebGLContext::clear_color_texture() {
|
|
78
|
+
if (guidev::g_device == nullptr) return nullptr;
|
|
79
|
+
if (clear_texture_ == nullptr) {
|
|
80
|
+
end_pass();
|
|
81
|
+
ensure_command();
|
|
82
|
+
SDL_GPUTextureCreateInfo info;
|
|
83
|
+
memset(&info, 0, sizeof(info));
|
|
84
|
+
info.type = SDL_GPU_TEXTURETYPE_2D;
|
|
85
|
+
info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
86
|
+
info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
|
|
87
|
+
info.width = 1;
|
|
88
|
+
info.height = 1;
|
|
89
|
+
info.layer_count_or_depth = 1;
|
|
90
|
+
info.num_levels = 1;
|
|
91
|
+
info.sample_count = SDL_GPU_SAMPLECOUNT_1;
|
|
92
|
+
clear_texture_ = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
93
|
+
if (clear_texture_ == nullptr) {
|
|
94
|
+
set_error(GL_OUT_OF_MEMORY);
|
|
95
|
+
return nullptr;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
end_pass();
|
|
99
|
+
ensure_command();
|
|
100
|
+
if (cmd_ == nullptr) return clear_texture_;
|
|
101
|
+
uint8_t rgba[4];
|
|
102
|
+
for (int i = 0; i < 4; i++) {
|
|
103
|
+
float value = clear_color_[i];
|
|
104
|
+
if (value < 0.0f) value = 0.0f;
|
|
105
|
+
if (value > 1.0f) value = 1.0f;
|
|
106
|
+
rgba[i] = (uint8_t)(value * 255.0f + 0.5f);
|
|
107
|
+
}
|
|
108
|
+
upload_region(guidev::g_device, cmd_, clear_texture_, 0, 0, 1, 1, rgba, 4);
|
|
109
|
+
return clear_texture_;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
bool WebGLContext::tex_image_format(uint32_t id, int width, int height,
|
|
113
|
+
SDL_GPUTextureFormat format, const uint8_t *pixels,
|
|
114
|
+
int layer) {
|
|
115
|
+
WebGLTexture *record = texture(id);
|
|
116
|
+
if (record == nullptr || width <= 0 || height <= 0) {
|
|
117
|
+
set_error(GL_INVALID_VALUE);
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
end_pass();
|
|
121
|
+
ensure_command();
|
|
122
|
+
if (cmd_ == nullptr) return false;
|
|
123
|
+
if (record->width != width || record->height != height || record->format != format) {
|
|
124
|
+
if (record->gpu != nullptr) {
|
|
125
|
+
SDL_WaitForGPUIdle(guidev::g_device);
|
|
126
|
+
SDL_ReleaseGPUTexture(guidev::g_device, record->gpu);
|
|
127
|
+
record->gpu = nullptr;
|
|
128
|
+
record->usage = 0;
|
|
129
|
+
}
|
|
130
|
+
record->width = width;
|
|
131
|
+
record->height = height;
|
|
132
|
+
record->format = format;
|
|
133
|
+
record->layers = 1;
|
|
134
|
+
record->target = layer >= 0 ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
|
|
135
|
+
record->compressed = false;
|
|
136
|
+
record->has_mipmaps = false;
|
|
137
|
+
if (record->sampler != nullptr) {
|
|
138
|
+
SDL_ReleaseGPUSampler(guidev::g_device, record->sampler);
|
|
139
|
+
record->sampler = nullptr;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (ensure_texture_gpu(record, record->as_target || record->as_depth_target) == nullptr) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
record->defined = true;
|
|
146
|
+
if (layer >= 0) {
|
|
147
|
+
record->target = GL_TEXTURE_CUBE_MAP;
|
|
148
|
+
record->layers = 6;
|
|
149
|
+
}
|
|
150
|
+
return upload_region(guidev::g_device, cmd_, record->gpu, 0, 0, width, height, pixels,
|
|
151
|
+
texel_bytes(format), layer >= 0 ? layer : 0);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
bool WebGLContext::tex_image_rgba(uint32_t id, int width, int height, const uint8_t *rgba) {
|
|
155
|
+
return tex_image_format(id, width, height, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, rgba);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
bool WebGLContext::tex_sub_image_format(uint32_t id, int x, int y, int width, int height,
|
|
159
|
+
const uint8_t *pixels, int layer) {
|
|
160
|
+
WebGLTexture *record = texture(id);
|
|
161
|
+
if (record == nullptr || !record->defined || record->gpu == nullptr) {
|
|
162
|
+
set_error(GL_INVALID_OPERATION);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (x < 0 || y < 0 || width <= 0 || height <= 0 || x + width > record->width ||
|
|
166
|
+
y + height > record->height) {
|
|
167
|
+
set_error(GL_INVALID_VALUE);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
end_pass();
|
|
171
|
+
ensure_command();
|
|
172
|
+
if (cmd_ == nullptr) return false;
|
|
173
|
+
return upload_region(guidev::g_device, cmd_, record->gpu, x, y, width, height, pixels,
|
|
174
|
+
texel_bytes(record->format), layer);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
bool WebGLContext::tex_sub_image_rgba(uint32_t id, int x, int y, int width, int height,
|
|
178
|
+
const uint8_t *rgba) {
|
|
179
|
+
return tex_sub_image_format(id, x, y, width, height, rgba);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
bool WebGLContext::generate_mipmap(uint32_t id) {
|
|
183
|
+
WebGLTexture *record = texture(id);
|
|
184
|
+
if (record == nullptr || record->gpu == nullptr) {
|
|
185
|
+
set_error(GL_INVALID_OPERATION);
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
if (record->depth) {
|
|
189
|
+
/* Depth textures have no mip chain in this backend. */
|
|
190
|
+
set_error(GL_INVALID_OPERATION);
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
end_pass();
|
|
194
|
+
ensure_command();
|
|
195
|
+
if (cmd_ == nullptr || record->levels <= 1) return false;
|
|
196
|
+
SDL_GenerateMipmapsForGPUTexture(cmd_, record->gpu);
|
|
197
|
+
record->has_mipmaps = true;
|
|
198
|
+
if (record->sampler != nullptr) {
|
|
199
|
+
SDL_ReleaseGPUSampler(guidev::g_device, record->sampler);
|
|
200
|
+
record->sampler = nullptr;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
bool WebGLContext::read_pixels(int x, int y, int width, int height, uint8_t *out) {
|
|
206
|
+
if (out == nullptr || width <= 0 || height <= 0) return false;
|
|
207
|
+
if (target_color_format() != (int)SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM) {
|
|
208
|
+
/* The only readback this surface offers is RGBA8; a float/half colour
|
|
209
|
+
* target is read by rendering it into an RGBA8 target instead. */
|
|
210
|
+
set_error(GL_INVALID_OPERATION);
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
SDL_GPUTexture *target = target_color();
|
|
214
|
+
if (bound_framebuffer_ != 0) {
|
|
215
|
+
WebGLFramebuffer *framebuffer = this->framebuffer(bound_framebuffer_);
|
|
216
|
+
if (framebuffer != nullptr) {
|
|
217
|
+
int index = read_buffer_ - GL_COLOR_ATTACHMENT0;
|
|
218
|
+
if (index < 0 || index >= kWebGLMaxDrawBuffers ||
|
|
219
|
+
framebuffer->color_textures[index] == 0) {
|
|
220
|
+
index = 0;
|
|
221
|
+
}
|
|
222
|
+
WebGLTexture *read_texture = texture(framebuffer->color_textures[index]);
|
|
223
|
+
target = read_texture != nullptr ? ensure_texture_gpu(read_texture, true) : nullptr;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
int target_width = bound_framebuffer_ == 0 ? width_ : 0;
|
|
227
|
+
int target_height = bound_framebuffer_ == 0 ? height_ : 0;
|
|
228
|
+
if (bound_framebuffer_ != 0) {
|
|
229
|
+
WebGLFramebuffer *framebuffer_ = framebuffer(bound_framebuffer_);
|
|
230
|
+
if (framebuffer_ == nullptr) return false;
|
|
231
|
+
target_width = framebuffer_->width;
|
|
232
|
+
target_height = framebuffer_->height;
|
|
233
|
+
}
|
|
234
|
+
if (target == nullptr || target_width <= 0 || target_height <= 0) return false;
|
|
235
|
+
/* Clamp to the target; pixels outside are transparent black. */
|
|
236
|
+
const int px = std::max(0, x);
|
|
237
|
+
const int py = std::max(0, y);
|
|
238
|
+
const int pw = std::min(width, target_width - px);
|
|
239
|
+
const int ph = std::min(height, target_height - py);
|
|
240
|
+
memset(out, 0, (size_t)width * height * 4);
|
|
241
|
+
if (pw <= 0 || ph <= 0) return true;
|
|
242
|
+
|
|
243
|
+
submit();
|
|
244
|
+
if (guidev::g_device == nullptr) return false;
|
|
245
|
+
SDL_GPUCommandBuffer *cmd = SDL_AcquireGPUCommandBuffer(guidev::g_device);
|
|
246
|
+
if (cmd == nullptr) return false;
|
|
247
|
+
const uint32_t bytes = (uint32_t)(pw * ph * 4);
|
|
248
|
+
SDL_GPUTransferBufferCreateInfo info;
|
|
249
|
+
memset(&info, 0, sizeof(info));
|
|
250
|
+
info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD;
|
|
251
|
+
info.size = bytes;
|
|
252
|
+
SDL_GPUTransferBuffer *transfer = SDL_CreateGPUTransferBuffer(guidev::g_device, &info);
|
|
253
|
+
if (transfer == nullptr) {
|
|
254
|
+
SDL_SubmitGPUCommandBuffer(cmd);
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
SDL_GPUTextureRegion region;
|
|
258
|
+
memset(®ion, 0, sizeof(region));
|
|
259
|
+
region.texture = target;
|
|
260
|
+
/* The framebuffer is stored top-down; GL's y counts from the bottom. */
|
|
261
|
+
region.x = (Uint32)px;
|
|
262
|
+
region.y = (Uint32)(target_height - (py + ph));
|
|
263
|
+
region.w = (Uint32)pw;
|
|
264
|
+
region.h = (Uint32)ph;
|
|
265
|
+
region.d = 1;
|
|
266
|
+
SDL_GPUTextureTransferInfo destination;
|
|
267
|
+
memset(&destination, 0, sizeof(destination));
|
|
268
|
+
destination.transfer_buffer = transfer;
|
|
269
|
+
destination.pixels_per_row = (Uint32)pw;
|
|
270
|
+
destination.rows_per_layer = (Uint32)ph;
|
|
271
|
+
SDL_GPUCopyPass *copy = SDL_BeginGPUCopyPass(cmd);
|
|
272
|
+
SDL_DownloadFromGPUTexture(copy, ®ion, &destination);
|
|
273
|
+
SDL_EndGPUCopyPass(copy);
|
|
274
|
+
SDL_GPUFence *fence = SDL_SubmitGPUCommandBufferAndAcquireFence(cmd);
|
|
275
|
+
if (fence == nullptr) {
|
|
276
|
+
SDL_ReleaseGPUTransferBuffer(guidev::g_device, transfer);
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
SDL_WaitForGPUFences(guidev::g_device, true, &fence, 1);
|
|
280
|
+
SDL_ReleaseGPUFence(guidev::g_device, fence);
|
|
281
|
+
const uint8_t *mapped =
|
|
282
|
+
(const uint8_t *)SDL_MapGPUTransferBuffer(guidev::g_device, transfer, false);
|
|
283
|
+
if (mapped == nullptr) {
|
|
284
|
+
SDL_ReleaseGPUTransferBuffer(guidev::g_device, transfer);
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
for (int row = 0; row < ph; row++) {
|
|
288
|
+
const uint8_t *source = mapped + (size_t)(ph - 1 - row) * pw * 4;
|
|
289
|
+
uint8_t *line = out + ((size_t)(py - y + row) * width + (px - x)) * 4;
|
|
290
|
+
memcpy(line, source, (size_t)pw * 4);
|
|
291
|
+
}
|
|
292
|
+
SDL_UnmapGPUTransferBuffer(guidev::g_device, transfer);
|
|
293
|
+
SDL_ReleaseGPUTransferBuffer(guidev::g_device, transfer);
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
bool WebGLContext::tex_storage_format(uint32_t id, int levels, int width, int height,
|
|
298
|
+
SDL_GPUTextureFormat format) {
|
|
299
|
+
(void)levels; // the backend always allocates the full mip chain
|
|
300
|
+
WebGLTexture *record = texture(id);
|
|
301
|
+
if (record == nullptr || width <= 0 || height <= 0) {
|
|
302
|
+
set_error(GL_INVALID_VALUE);
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
end_pass();
|
|
306
|
+
ensure_command();
|
|
307
|
+
if (record->gpu != nullptr) {
|
|
308
|
+
submit();
|
|
309
|
+
SDL_WaitForGPUIdle(guidev::g_device);
|
|
310
|
+
SDL_ReleaseGPUTexture(guidev::g_device, record->gpu);
|
|
311
|
+
record->gpu = nullptr;
|
|
312
|
+
record->usage = 0;
|
|
313
|
+
}
|
|
314
|
+
record->width = width;
|
|
315
|
+
record->height = height;
|
|
316
|
+
record->format = format;
|
|
317
|
+
record->layers = 1;
|
|
318
|
+
record->target = GL_TEXTURE_2D;
|
|
319
|
+
record->compressed = false;
|
|
320
|
+
record->has_mipmaps = false;
|
|
321
|
+
if (record->sampler != nullptr && guidev::g_device != nullptr) {
|
|
322
|
+
SDL_ReleaseGPUSampler(guidev::g_device, record->sampler);
|
|
323
|
+
record->sampler = nullptr;
|
|
324
|
+
}
|
|
325
|
+
record->defined = true;
|
|
326
|
+
return ensure_texture_gpu(record, record->as_target || record->as_depth_target) != nullptr;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
bool WebGLContext::tex_storage_2d(uint32_t id, int levels, int width, int height) {
|
|
330
|
+
return tex_storage_format(id, levels, width, height,
|
|
331
|
+
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/* -- WebGL 2 clearBuffer* ------------------------------------------------ */
|
|
335
|
+
void WebGLContext::clear_buffer_float(int buffer, int drawbuffer, const float *values,
|
|
336
|
+
int count) {
|
|
337
|
+
if (buffer == GL_COLOR) {
|
|
338
|
+
if (drawbuffer != 0) return;
|
|
339
|
+
clear_color(values[0], count > 1 ? values[1] : 0.0f, count > 2 ? values[2] : 0.0f,
|
|
340
|
+
count > 3 ? values[3] : 1.0f);
|
|
341
|
+
clear(GL_COLOR_BUFFER_BIT);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (buffer == GL_DEPTH) {
|
|
345
|
+
clear_depth(values[0]);
|
|
346
|
+
clear(GL_DEPTH_BUFFER_BIT);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (buffer == GL_STENCIL) {
|
|
350
|
+
clear_stencil((int)values[0]);
|
|
351
|
+
clear(GL_STENCIL_BUFFER_BIT);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
void WebGLContext::clear_buffer_int(int buffer, int drawbuffer, const int *values, int count) {
|
|
356
|
+
if (buffer == GL_STENCIL) {
|
|
357
|
+
clear_stencil(values[0]);
|
|
358
|
+
clear(GL_STENCIL_BUFFER_BIT);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (buffer == GL_COLOR) {
|
|
362
|
+
if (drawbuffer != 0) return;
|
|
363
|
+
clear_color((float)values[0], count > 1 ? (float)values[1] : 0.0f,
|
|
364
|
+
count > 2 ? (float)values[2] : 0.0f, count > 3 ? (float)values[3] : 1.0f);
|
|
365
|
+
clear(GL_COLOR_BUFFER_BIT);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
void WebGLContext::clear_buffer_uint(int buffer, int drawbuffer, const unsigned int *values,
|
|
370
|
+
int count) {
|
|
371
|
+
if (buffer == GL_STENCIL) {
|
|
372
|
+
clear_stencil((int)values[0]);
|
|
373
|
+
clear(GL_STENCIL_BUFFER_BIT);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (buffer == GL_COLOR) {
|
|
377
|
+
if (drawbuffer != 0) return;
|
|
378
|
+
clear_color((float)values[0], count > 1 ? (float)values[1] : 0.0f,
|
|
379
|
+
count > 2 ? (float)values[2] : 0.0f, count > 3 ? (float)values[3] : 1.0f);
|
|
380
|
+
clear(GL_COLOR_BUFFER_BIT);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
void WebGLContext::clear_buffer_fi(int buffer, int drawbuffer, float depth, int stencil) {
|
|
385
|
+
(void)drawbuffer;
|
|
386
|
+
if (buffer == GL_DEPTH_STENCIL) {
|
|
387
|
+
clear_depth(depth);
|
|
388
|
+
clear_stencil(stencil);
|
|
389
|
+
clear(GL_DEPTH_BUFFER_BIT);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (buffer == GL_DEPTH) {
|
|
393
|
+
clear_depth(depth);
|
|
394
|
+
clear(GL_DEPTH_BUFFER_BIT);
|
|
395
|
+
} else if (buffer == GL_STENCIL) {
|
|
396
|
+
clear_stencil(stencil);
|
|
397
|
+
clear(GL_STENCIL_BUFFER_BIT);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
SDL_GPUTextureFormat webgl_storage_format(int internalformat) {
|
|
402
|
+
if (internalformat == GL_DEPTH_COMPONENT16 || internalformat == GL_DEPTH_COMPONENT24 ||
|
|
403
|
+
internalformat == GL_DEPTH_COMPONENT32F) {
|
|
404
|
+
return SDL_GPU_TEXTUREFORMAT_D32_FLOAT;
|
|
405
|
+
}
|
|
406
|
+
if (internalformat == GL_DEPTH_STENCIL || internalformat == GL_DEPTH24_STENCIL8) {
|
|
407
|
+
return SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
408
|
+
}
|
|
409
|
+
if (internalformat == GL_RGBA32F || internalformat == GL_RGB32F ||
|
|
410
|
+
internalformat == GL_RG32F || internalformat == GL_R32F) {
|
|
411
|
+
return SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT;
|
|
412
|
+
}
|
|
413
|
+
if (internalformat == GL_RGBA16F || internalformat == GL_RGB16F ||
|
|
414
|
+
internalformat == GL_RG16F || internalformat == GL_R16F) {
|
|
415
|
+
return SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT;
|
|
416
|
+
}
|
|
417
|
+
return SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
} // namespace xtgui
|