sfml.js 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +40 -48
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/native/shader-binding.cc
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
#include "graphics-state.h"
|
|
2
|
-
#include "exception-boundary.h"
|
|
3
|
-
#include "shared-handle.h"
|
|
4
|
-
|
|
5
|
-
#include <SFML/Window/Context.hpp>
|
|
6
1
|
#define GL_SILENCE_DEPRECATION
|
|
7
|
-
#include <SFML/OpenGL.hpp>
|
|
8
2
|
|
|
9
3
|
#include <array>
|
|
10
4
|
#include <exception>
|
|
@@ -13,6 +7,12 @@
|
|
|
13
7
|
#include <string>
|
|
14
8
|
#include <vector>
|
|
15
9
|
|
|
10
|
+
#include "exception-boundary.h"
|
|
11
|
+
#include "graphics-state.h"
|
|
12
|
+
#include "shared-handle.h"
|
|
13
|
+
#include <SFML/OpenGL.hpp>
|
|
14
|
+
#include <SFML/Window/Context.hpp>
|
|
15
|
+
|
|
16
16
|
namespace {
|
|
17
17
|
|
|
18
18
|
using State = sfmljs::ShaderState;
|
|
@@ -29,12 +29,16 @@ NAN_METHOD(CreateShader) {
|
|
|
29
29
|
auto state = sfmljs::MakeThreadOwned<State>(owner, id);
|
|
30
30
|
owner->shaders.emplace(id, state);
|
|
31
31
|
auto result = Nan::New<v8::Object>();
|
|
32
|
-
Nan::Set(result, Nan::New("handle").ToLocalChecked(),
|
|
33
|
-
|
|
32
|
+
Nan::Set(result, Nan::New("handle").ToLocalChecked(), Handle::Create(state))
|
|
33
|
+
.FromJust();
|
|
34
34
|
Nan::Set(result, Nan::New("id").ToLocalChecked(), Nan::New(id)).FromJust();
|
|
35
|
-
Nan::Set(result,
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
Nan::Set(result,
|
|
36
|
+
Nan::New("buffer").ToLocalChecked(),
|
|
37
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
38
|
+
state,
|
|
39
|
+
&state->programId,
|
|
40
|
+
sizeof(state->programId)))
|
|
41
|
+
.FromJust();
|
|
38
42
|
info.GetReturnValue().Set(result);
|
|
39
43
|
} catch (const std::exception& error) {
|
|
40
44
|
sfmljs::ThrowError(error.what());
|
|
@@ -46,7 +50,8 @@ using Sources = std::array<std::optional<std::string>, 3>;
|
|
|
46
50
|
class CompileWorker final : public sfmljs::AsyncWorker {
|
|
47
51
|
public:
|
|
48
52
|
CompileWorker(Nan::Callback* callback, bool memory, Sources sources)
|
|
49
|
-
: sfmljs::AsyncWorker(callback, "sfml:Shader"),
|
|
53
|
+
: sfmljs::AsyncWorker(callback, "sfml:Shader"),
|
|
54
|
+
memory_(memory),
|
|
50
55
|
sources_(std::move(sources)) {}
|
|
51
56
|
|
|
52
57
|
void ExecuteWork() override {
|
|
@@ -58,12 +63,13 @@ class CompileWorker final : public sfmljs::AsyncWorker {
|
|
|
58
63
|
for (std::size_t i = 0; i < paths.size(); ++i) {
|
|
59
64
|
if (sources_[i]) {
|
|
60
65
|
const auto& text = *sources_[i];
|
|
61
|
-
paths[i] =
|
|
66
|
+
paths[i] =
|
|
67
|
+
std::filesystem::path(std::u8string(text.begin(), text.end()));
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
const auto count = static_cast<unsigned>(sources_[0].has_value()) +
|
|
66
|
-
|
|
72
|
+
sources_[1].has_value() + sources_[2].has_value();
|
|
67
73
|
if (count == 1) {
|
|
68
74
|
const unsigned i = sources_[0] ? 0 : sources_[1] ? 1 : 2;
|
|
69
75
|
const auto type = static_cast<sf::Shader::Type>(i);
|
|
@@ -74,7 +80,7 @@ class CompileWorker final : public sfmljs::AsyncWorker {
|
|
|
74
80
|
: program_->loadFromFile(paths[0], paths[2]);
|
|
75
81
|
} else {
|
|
76
82
|
ok_ = memory_ ? program_->loadFromMemory(
|
|
77
|
-
|
|
83
|
+
*sources_[0], *sources_[1], *sources_[2])
|
|
78
84
|
: program_->loadFromFile(paths[0], paths[1], paths[2]);
|
|
79
85
|
}
|
|
80
86
|
} catch (const std::exception& error) {
|
|
@@ -104,19 +110,21 @@ NAN_METHOD(CompileShader) {
|
|
|
104
110
|
return Nan::ThrowTypeError("Expected shader sources and callback");
|
|
105
111
|
}
|
|
106
112
|
auto array = info[1].As<v8::Array>();
|
|
107
|
-
if (array->Length() != 3)
|
|
113
|
+
if (array->Length() != 3)
|
|
114
|
+
return Nan::ThrowTypeError("Expected three shader stages");
|
|
108
115
|
try {
|
|
109
116
|
Sources sources;
|
|
110
117
|
for (unsigned i = 0; i < sources.size(); ++i) {
|
|
111
118
|
v8::Local<v8::Value> value;
|
|
112
119
|
if (!Nan::Get(array, i).ToLocal(&value)) return;
|
|
113
120
|
if (value->IsNull()) continue;
|
|
114
|
-
if (!value->IsString())
|
|
121
|
+
if (!value->IsString())
|
|
122
|
+
return Nan::ThrowTypeError("Expected shader source");
|
|
115
123
|
Nan::Utf8String text(value);
|
|
116
124
|
sources[i] = std::string(*text, text.length());
|
|
117
125
|
}
|
|
118
126
|
const unsigned count = static_cast<unsigned>(sources[0].has_value()) +
|
|
119
|
-
|
|
127
|
+
sources[1].has_value() + sources[2].has_value();
|
|
120
128
|
if (count == 0 || (count == 2 && (!sources[0] || !sources[2]))) {
|
|
121
129
|
return Nan::ThrowTypeError("Invalid shader stage combination");
|
|
122
130
|
}
|
|
@@ -141,15 +149,21 @@ NAN_METHOD(CommitShader) {
|
|
|
141
149
|
}
|
|
142
150
|
|
|
143
151
|
template <typename T, std::size_t Size>
|
|
144
|
-
void SetArray(sf::Shader& shader,
|
|
152
|
+
void SetArray(sf::Shader& shader, // NOLINT(runtime/references)
|
|
153
|
+
const std::string& name,
|
|
154
|
+
const float* data,
|
|
145
155
|
std::size_t count) {
|
|
146
156
|
std::vector<T> values;
|
|
147
157
|
values.reserve(count);
|
|
148
158
|
for (std::size_t i = 0; i < count; ++i, data += Size) {
|
|
149
|
-
if constexpr (Size == 2)
|
|
150
|
-
|
|
151
|
-
else if constexpr (Size ==
|
|
152
|
-
|
|
159
|
+
if constexpr (Size == 2)
|
|
160
|
+
values.emplace_back(data[0], data[1]);
|
|
161
|
+
else if constexpr (Size == 3)
|
|
162
|
+
values.emplace_back(data[0], data[1], data[2]);
|
|
163
|
+
else if constexpr (Size == 4)
|
|
164
|
+
values.emplace_back(data[0], data[1], data[2], data[3]);
|
|
165
|
+
else
|
|
166
|
+
values.emplace_back(data);
|
|
153
167
|
}
|
|
154
168
|
shader.setUniformArray(name, values.data(), values.size());
|
|
155
169
|
}
|
|
@@ -158,10 +172,12 @@ NAN_METHOD(SetShaderUniform) {
|
|
|
158
172
|
auto* handle = Handle::From(info[0]);
|
|
159
173
|
if (!handle) return;
|
|
160
174
|
if (!info[1]->IsString() || !info[2]->IsUint32() || !info[4]->IsBoolean()) {
|
|
161
|
-
return Nan::ThrowTypeError(
|
|
175
|
+
return Nan::ThrowTypeError(
|
|
176
|
+
"Expected a uniform name, type, data and array flag");
|
|
162
177
|
}
|
|
163
178
|
const auto type = Nan::To<unsigned>(info[2]).FromJust();
|
|
164
|
-
constexpr std::array<std::size_t, 14> sizes{
|
|
179
|
+
constexpr std::array<std::size_t, 14> sizes{
|
|
180
|
+
1, 1, 1, 2, 3, 4, 2, 3, 4, 2, 3, 4, 9, 16};
|
|
165
181
|
if (type >= sizes.size()) return Nan::ThrowRangeError("Invalid uniform type");
|
|
166
182
|
const bool floating = type == 0 || (type >= 3 && type <= 5) || type >= 12;
|
|
167
183
|
const bool array = info[4]->IsTrue();
|
|
@@ -184,35 +200,78 @@ NAN_METHOD(SetShaderUniform) {
|
|
|
184
200
|
if (array) {
|
|
185
201
|
const auto count = length / sizes[type];
|
|
186
202
|
switch (type) {
|
|
187
|
-
case 0:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
case
|
|
191
|
-
|
|
192
|
-
|
|
203
|
+
case 0:
|
|
204
|
+
shader.setUniformArray(name, v, count);
|
|
205
|
+
break;
|
|
206
|
+
case 3:
|
|
207
|
+
SetArray<sf::Glsl::Vec2, 2>(shader, name, v, count);
|
|
208
|
+
break;
|
|
209
|
+
case 4:
|
|
210
|
+
SetArray<sf::Glsl::Vec3, 3>(shader, name, v, count);
|
|
211
|
+
break;
|
|
212
|
+
case 5:
|
|
213
|
+
SetArray<sf::Glsl::Vec4, 4>(shader, name, v, count);
|
|
214
|
+
break;
|
|
215
|
+
case 12:
|
|
216
|
+
SetArray<sf::Glsl::Mat3, 9>(shader, name, v, count);
|
|
217
|
+
break;
|
|
218
|
+
case 13:
|
|
219
|
+
SetArray<sf::Glsl::Mat4, 16>(shader, name, v, count);
|
|
220
|
+
break;
|
|
193
221
|
}
|
|
194
222
|
} else {
|
|
195
223
|
switch (type) {
|
|
196
|
-
case 0:
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
case
|
|
200
|
-
|
|
201
|
-
|
|
224
|
+
case 0:
|
|
225
|
+
shader.setUniform(name, v[0]);
|
|
226
|
+
break;
|
|
227
|
+
case 3:
|
|
228
|
+
shader.setUniform(name, sf::Glsl::Vec2(v[0], v[1]));
|
|
229
|
+
break;
|
|
230
|
+
case 4:
|
|
231
|
+
shader.setUniform(name, sf::Glsl::Vec3(v[0], v[1], v[2]));
|
|
232
|
+
break;
|
|
233
|
+
case 5:
|
|
234
|
+
shader.setUniform(name, sf::Glsl::Vec4(v[0], v[1], v[2], v[3]));
|
|
235
|
+
break;
|
|
236
|
+
case 12:
|
|
237
|
+
shader.setUniform(name, sf::Glsl::Mat3(v));
|
|
238
|
+
break;
|
|
239
|
+
case 13:
|
|
240
|
+
shader.setUniform(name, sf::Glsl::Mat4(v));
|
|
241
|
+
break;
|
|
202
242
|
}
|
|
203
243
|
}
|
|
204
244
|
} else {
|
|
205
245
|
Nan::TypedArrayContents<int> values(info[3]);
|
|
206
246
|
const auto* v = *values;
|
|
207
247
|
switch (type) {
|
|
208
|
-
case 1:
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
case
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
case
|
|
215
|
-
|
|
248
|
+
case 1:
|
|
249
|
+
shader.setUniform(name, v[0]);
|
|
250
|
+
break;
|
|
251
|
+
case 2:
|
|
252
|
+
shader.setUniform(name, v[0] != 0);
|
|
253
|
+
break;
|
|
254
|
+
case 6:
|
|
255
|
+
shader.setUniform(name, sf::Glsl::Ivec2(v[0], v[1]));
|
|
256
|
+
break;
|
|
257
|
+
case 7:
|
|
258
|
+
shader.setUniform(name, sf::Glsl::Ivec3(v[0], v[1], v[2]));
|
|
259
|
+
break;
|
|
260
|
+
case 8:
|
|
261
|
+
shader.setUniform(name, sf::Glsl::Ivec4(v[0], v[1], v[2], v[3]));
|
|
262
|
+
break;
|
|
263
|
+
case 9:
|
|
264
|
+
shader.setUniform(name, sf::Glsl::Bvec2(v[0] != 0, v[1] != 0));
|
|
265
|
+
break;
|
|
266
|
+
case 10:
|
|
267
|
+
shader.setUniform(name,
|
|
268
|
+
sf::Glsl::Bvec3(v[0] != 0, v[1] != 0, v[2] != 0));
|
|
269
|
+
break;
|
|
270
|
+
case 11:
|
|
271
|
+
shader.setUniform(
|
|
272
|
+
name,
|
|
273
|
+
sf::Glsl::Bvec4(v[0] != 0, v[1] != 0, v[2] != 0, v[3] != 0));
|
|
274
|
+
break;
|
|
216
275
|
}
|
|
217
276
|
}
|
|
218
277
|
} catch (const std::exception& error) {
|
|
@@ -223,7 +282,8 @@ NAN_METHOD(SetShaderUniform) {
|
|
|
223
282
|
NAN_METHOD(SetShaderTexture) {
|
|
224
283
|
auto* handle = Handle::From(info[0]);
|
|
225
284
|
if (!handle) return;
|
|
226
|
-
if (!info[1]->IsString())
|
|
285
|
+
if (!info[1]->IsString())
|
|
286
|
+
return Nan::ThrowTypeError("Expected a uniform name");
|
|
227
287
|
Nan::Utf8String text(info[1]);
|
|
228
288
|
const std::string name(*text, text.length());
|
|
229
289
|
auto& state = *handle->owner();
|
|
@@ -238,7 +298,8 @@ NAN_METHOD(SetShaderTexture) {
|
|
|
238
298
|
// Keep its pointer table alive even when CurrentTexture or a scalar is set.
|
|
239
299
|
const State::Lock lock;
|
|
240
300
|
#ifdef SFML_SYSTEM_WINDOWS
|
|
241
|
-
|
|
301
|
+
// Function-pointer type, not a C-style cast.
|
|
302
|
+
using Location = int(__stdcall*)(unsigned, const char*); // NOLINT
|
|
242
303
|
#else
|
|
243
304
|
using Location = int (*)(unsigned, const char*);
|
|
244
305
|
#endif
|
|
@@ -249,7 +310,8 @@ NAN_METHOD(SetShaderTexture) {
|
|
|
249
310
|
const int location = locationFunction(program, name.c_str());
|
|
250
311
|
GLint maximum{};
|
|
251
312
|
glGetIntegerv(0x8B4D /* GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS */, &maximum);
|
|
252
|
-
const bool accepted =
|
|
313
|
+
const bool accepted =
|
|
314
|
+
location >= 0 &&
|
|
253
315
|
(state.textures.contains(location) ||
|
|
254
316
|
state.textures.size() + 1 < static_cast<std::size_t>(maximum));
|
|
255
317
|
state.current->setUniform(name, *texture);
|
|
@@ -264,7 +326,9 @@ NAN_METHOD(SetShaderTexture) {
|
|
|
264
326
|
|
|
265
327
|
NAN_METHOD(GetShaderNativeHandle) {
|
|
266
328
|
auto* handle = Handle::From(info[0]);
|
|
267
|
-
if (handle)
|
|
329
|
+
if (handle)
|
|
330
|
+
info.GetReturnValue().Set(
|
|
331
|
+
Nan::New(handle->owner()->current->getNativeHandle()));
|
|
268
332
|
}
|
|
269
333
|
|
|
270
334
|
NAN_METHOD(BindShader) {
|
|
@@ -275,7 +339,8 @@ NAN_METHOD(BindShader) {
|
|
|
275
339
|
|
|
276
340
|
NAN_METHOD(IsShaderAvailable) {
|
|
277
341
|
info.GetReturnValue().Set(info[0]->IsTrue()
|
|
278
|
-
|
|
342
|
+
? sf::Shader::isGeometryAvailable()
|
|
343
|
+
: sf::Shader::isAvailable());
|
|
279
344
|
}
|
|
280
345
|
|
|
281
346
|
} // namespace
|
package/native/shape-binding.cc
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
#include
|
|
1
|
+
#include <cmath>
|
|
2
|
+
#include <limits>
|
|
3
|
+
|
|
2
4
|
#include "exception-boundary.h"
|
|
5
|
+
#include "shape-state.h"
|
|
3
6
|
#include "value-binding.h"
|
|
4
7
|
#include "window-event.h"
|
|
5
|
-
#include <cmath>
|
|
6
|
-
#include <limits>
|
|
7
8
|
|
|
8
9
|
namespace {
|
|
9
10
|
using State = sfmljs::ShapeState;
|
|
10
11
|
using Handle = sfmljs::SharedHandle<State>;
|
|
11
12
|
constexpr std::uint32_t maxPoints = 0x7fffffff / (6 * sizeof(sf::Vertex)) - 2;
|
|
12
13
|
|
|
13
|
-
bool Number(v8::Local<v8::Value> input,
|
|
14
|
+
bool Number(v8::Local<v8::Value> input,
|
|
15
|
+
float& value) { // NOLINT(runtime/references)
|
|
14
16
|
if (!input->IsNumber()) {
|
|
15
17
|
Nan::ThrowTypeError("Expected a number");
|
|
16
18
|
return false;
|
|
@@ -23,7 +25,8 @@ bool Number(v8::Local<v8::Value> input, float& value) {
|
|
|
23
25
|
return true;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
bool Count(v8::Local<v8::Value> input,
|
|
28
|
+
bool Count(v8::Local<v8::Value> input,
|
|
29
|
+
std::uint32_t& count) { // NOLINT(runtime/references)
|
|
27
30
|
if (!input->IsUint32() ||
|
|
28
31
|
(count = Nan::To<std::uint32_t>(input).FromJust()) > maxPoints) {
|
|
29
32
|
Nan::ThrowRangeError("Shape point count exceeds the buffer limit");
|
|
@@ -33,25 +36,28 @@ bool Count(v8::Local<v8::Value> input, std::uint32_t& count) {
|
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
v8::Local<v8::Object> MapShape(const std::shared_ptr<State>& state) {
|
|
36
|
-
using namespace sfmljs;
|
|
37
39
|
auto& shape = *state->shape;
|
|
38
|
-
const auto& bounds = Field<ShapeBounds>(shape);
|
|
39
|
-
NumericFields fields;
|
|
40
|
-
fields.Add("left", bounds.position.x)
|
|
41
|
-
.Add("
|
|
42
|
-
.Add("
|
|
43
|
-
.Add("
|
|
40
|
+
const auto& bounds = sfmljs::Field<sfmljs::ShapeBounds>(shape);
|
|
41
|
+
sfmljs::NumericFields fields;
|
|
42
|
+
fields.Add("left", bounds.position.x)
|
|
43
|
+
.Add("top", bounds.position.y)
|
|
44
|
+
.Add("boundsWidth", bounds.size.x)
|
|
45
|
+
.Add("boundsHeight", bounds.size.y)
|
|
46
|
+
.Add("thickness", sfmljs::Field<sfmljs::ShapeThickness>(shape))
|
|
47
|
+
.Add("miterLimit", sfmljs::Field<sfmljs::ShapeMiterLimit>(shape));
|
|
44
48
|
if (state->kind == 1) {
|
|
45
49
|
auto& circle = static_cast<sf::CircleShape&>(shape);
|
|
46
|
-
fields.Add("radius", Field<CircleRadius>(circle))
|
|
47
|
-
.Add("count",
|
|
50
|
+
fields.Add("radius", sfmljs::Field<sfmljs::CircleRadius>(circle))
|
|
51
|
+
.Add("count",
|
|
52
|
+
sfmljs::Field<sfmljs::CircleCount>(circle),
|
|
48
53
|
sizeof(std::size_t) == 8 ? "size64" : "u32");
|
|
49
54
|
} else {
|
|
50
55
|
state->pointCount = static_cast<std::uint32_t>(shape.getPointCount());
|
|
51
56
|
fields.Add("count", state->pointCount);
|
|
52
57
|
}
|
|
53
58
|
if (state->kind == 2) {
|
|
54
|
-
const auto& size = Field<RectangleSize>(
|
|
59
|
+
const auto& size = sfmljs::Field<sfmljs::RectangleSize>(
|
|
60
|
+
static_cast<sf::RectangleShape&>(shape));
|
|
55
61
|
fields.Add("width", size.x).Add("height", size.y);
|
|
56
62
|
}
|
|
57
63
|
return fields.Map(state);
|
|
@@ -88,26 +94,41 @@ NAN_METHOD(CreateShape) {
|
|
|
88
94
|
if (source) {
|
|
89
95
|
const auto& raw = *source->owner()->shape;
|
|
90
96
|
switch (kind) {
|
|
91
|
-
case 0:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
case
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
case 0:
|
|
98
|
+
shape = std::make_unique<sfmljs::PointShape>(
|
|
99
|
+
static_cast<const sfmljs::PointShape&>(raw));
|
|
100
|
+
break;
|
|
101
|
+
case 1:
|
|
102
|
+
shape = std::make_unique<sf::CircleShape>(
|
|
103
|
+
static_cast<const sf::CircleShape&>(raw));
|
|
104
|
+
break;
|
|
105
|
+
case 2:
|
|
106
|
+
shape = std::make_unique<sf::RectangleShape>(
|
|
107
|
+
static_cast<const sf::RectangleShape&>(raw));
|
|
108
|
+
break;
|
|
109
|
+
case 3:
|
|
110
|
+
shape = std::make_unique<sf::ConvexShape>(
|
|
111
|
+
static_cast<const sf::ConvexShape&>(raw));
|
|
112
|
+
break;
|
|
99
113
|
}
|
|
100
114
|
} else {
|
|
101
115
|
switch (kind) {
|
|
102
|
-
case 0:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
116
|
+
case 0:
|
|
117
|
+
shape = std::make_unique<sfmljs::PointShape>();
|
|
118
|
+
break;
|
|
119
|
+
case 1:
|
|
120
|
+
shape = std::make_unique<sf::CircleShape>(x, count);
|
|
121
|
+
break;
|
|
122
|
+
case 2:
|
|
123
|
+
shape = std::make_unique<sf::RectangleShape>(sf::Vector2f{x, y});
|
|
124
|
+
break;
|
|
125
|
+
case 3:
|
|
126
|
+
shape = std::make_unique<sf::ConvexShape>(count);
|
|
127
|
+
break;
|
|
107
128
|
}
|
|
108
129
|
}
|
|
109
|
-
auto state = sfmljs::MakeThreadOwned<State>(
|
|
110
|
-
context->owner()->nextId++, kind, std::move(shape));
|
|
130
|
+
auto state = sfmljs::MakeThreadOwned<State>(
|
|
131
|
+
context->owner(), context->owner()->nextId++, kind, std::move(shape));
|
|
111
132
|
if (source) {
|
|
112
133
|
state->values = source->owner()->values;
|
|
113
134
|
state->appearance = source->owner()->appearance;
|
|
@@ -116,16 +137,22 @@ NAN_METHOD(CreateShape) {
|
|
|
116
137
|
}
|
|
117
138
|
state->context->shapes.emplace(state->id, state);
|
|
118
139
|
auto result = Nan::New<v8::Object>();
|
|
119
|
-
#define MAP(name, value)
|
|
120
|
-
|
|
140
|
+
#define MAP(name, value) \
|
|
141
|
+
Nan::Set(result, Nan::New(name).ToLocalChecked(), value).FromJust()
|
|
121
142
|
MAP("handle", Handle::Create(state));
|
|
122
143
|
MAP("id", Nan::New(state->id));
|
|
123
144
|
MAP("info", MapShape(state));
|
|
124
145
|
MAP("transformable", sfmljs::TransformableHandle(state));
|
|
125
|
-
MAP("buffer",
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
146
|
+
MAP("buffer",
|
|
147
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
148
|
+
state,
|
|
149
|
+
state->values.data(),
|
|
150
|
+
sizeof(state->values)));
|
|
151
|
+
MAP("appearance",
|
|
152
|
+
sfmljs::MapShared(info.GetIsolate(),
|
|
153
|
+
state,
|
|
154
|
+
&state->appearance,
|
|
155
|
+
sizeof(state->appearance)));
|
|
129
156
|
#undef MAP
|
|
130
157
|
info.GetReturnValue().Set(result);
|
|
131
158
|
} catch (const std::exception& error) {
|
|
@@ -170,17 +197,30 @@ NAN_METHOD(ChangeShapeGeometry) {
|
|
|
170
197
|
try {
|
|
171
198
|
state.SyncShape();
|
|
172
199
|
switch (operation) {
|
|
173
|
-
case 0:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
case
|
|
200
|
+
case 0:
|
|
201
|
+
shape.setOutlineThickness(x);
|
|
202
|
+
break;
|
|
203
|
+
case 1:
|
|
204
|
+
shape.setMiterLimit(x);
|
|
205
|
+
break;
|
|
206
|
+
case 2:
|
|
207
|
+
static_cast<sf::CircleShape&>(shape).setRadius(x);
|
|
208
|
+
break;
|
|
209
|
+
case 3:
|
|
210
|
+
static_cast<sf::RectangleShape&>(shape).setSize({x, y});
|
|
211
|
+
break;
|
|
177
212
|
case 4:
|
|
178
213
|
if (state.kind == 1) {
|
|
179
214
|
static_cast<sf::CircleShape&>(shape).setPointCount(count);
|
|
180
|
-
} else
|
|
215
|
+
} else {
|
|
216
|
+
static_cast<sf::ConvexShape&>(shape).setPointCount(count);
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
case 5:
|
|
220
|
+
static_cast<sf::ConvexShape&>(shape).setPoint(count, {x, y});
|
|
181
221
|
break;
|
|
182
|
-
|
|
183
|
-
|
|
222
|
+
default:
|
|
223
|
+
return Nan::ThrowRangeError("Unknown shape operation");
|
|
184
224
|
}
|
|
185
225
|
state.pointCount = static_cast<std::uint32_t>(shape.getPointCount());
|
|
186
226
|
} catch (const std::exception& error) {
|
|
@@ -238,8 +278,9 @@ NAN_METHOD(GetShapePoint) {
|
|
|
238
278
|
|
|
239
279
|
NAN_METHOD(GetShapeCenter) {
|
|
240
280
|
auto* handle = Handle::From(info[0]);
|
|
241
|
-
if (handle)
|
|
242
|
-
|
|
281
|
+
if (handle)
|
|
282
|
+
info.GetReturnValue().Set(
|
|
283
|
+
sfmljs::EventValue(handle->owner()->shape->getGeometricCenter()));
|
|
243
284
|
}
|
|
244
285
|
|
|
245
286
|
NAN_METHOD(SetShapeTexture) {
|
|
@@ -258,16 +299,20 @@ NAN_METHOD(SetShapeTexture) {
|
|
|
258
299
|
found->second.lock() != texture) {
|
|
259
300
|
return Nan::ThrowTypeError("Texture does not belong to this context");
|
|
260
301
|
}
|
|
261
|
-
} else if (id != 0)
|
|
302
|
+
} else if (id != 0) {
|
|
303
|
+
return Nan::ThrowTypeError("Expected zero texture ID");
|
|
304
|
+
}
|
|
262
305
|
handle->owner()->texture = std::move(texture);
|
|
263
306
|
handle->owner()->appearance.textureId = id;
|
|
264
307
|
}
|
|
265
308
|
|
|
266
309
|
NAN_METHOD(ShapeTextureRect) {
|
|
267
310
|
auto* handle = Handle::From(info[0]);
|
|
268
|
-
if (handle)
|
|
269
|
-
|
|
270
|
-
|
|
311
|
+
if (handle)
|
|
312
|
+
sfmljs::values::ReturnMapped(
|
|
313
|
+
info,
|
|
314
|
+
std::shared_ptr<sf::IntRect>(handle->owner(),
|
|
315
|
+
&handle->owner()->appearance.rectangle));
|
|
271
316
|
}
|
|
272
317
|
|
|
273
318
|
} // namespace
|
package/native/shape-state.h
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
#include "graphics-state.h"
|
|
4
4
|
#include <SFML/Graphics/CircleShape.hpp>
|
|
5
|
-
#include <SFML/Graphics/RectangleShape.hpp>
|
|
6
5
|
#include <SFML/Graphics/ConvexShape.hpp>
|
|
6
|
+
#include <SFML/Graphics/RectangleShape.hpp>
|
|
7
7
|
|
|
8
8
|
namespace sfmljs {
|
|
9
9
|
|
|
@@ -18,7 +18,9 @@ SFMLJS_MEMBER(RectangleSize, sf::RectangleShape, sf::Vector2f, m_size);
|
|
|
18
18
|
struct PointShape : sf::Shape {
|
|
19
19
|
std::vector<sf::Vector2f> points;
|
|
20
20
|
std::size_t getPointCount() const override { return points.size(); }
|
|
21
|
-
sf::Vector2f getPoint(std::size_t index) const override {
|
|
21
|
+
sf::Vector2f getPoint(std::size_t index) const override {
|
|
22
|
+
return points[index];
|
|
23
|
+
}
|
|
22
24
|
void Replace(std::vector<sf::Vector2f> input) {
|
|
23
25
|
points = std::move(input);
|
|
24
26
|
update();
|
|
@@ -35,8 +37,10 @@ struct ShapeAppearance {
|
|
|
35
37
|
static_assert(sizeof(ShapeAppearance) == 28);
|
|
36
38
|
static_assert(offsetof(ShapeAppearance, rectangle) == 12);
|
|
37
39
|
|
|
38
|
-
inline void ApplyShapeAppearance(
|
|
39
|
-
|
|
40
|
+
inline void ApplyShapeAppearance(
|
|
41
|
+
sf::Shape& shape, // NOLINT(runtime/references)
|
|
42
|
+
const sf::Texture* texture,
|
|
43
|
+
const ShapeAppearance& appearance) {
|
|
40
44
|
shape.setTexture(texture);
|
|
41
45
|
shape.setTextureRect(appearance.rectangle);
|
|
42
46
|
shape.setFillColor(sf::Color(appearance.fill));
|
|
@@ -44,10 +48,15 @@ inline void ApplyShapeAppearance(sf::Shape& shape, const sf::Texture* texture,
|
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
struct ShapeState : TransformableState {
|
|
47
|
-
ShapeState(std::shared_ptr<GraphicsContext> context,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
ShapeState(std::shared_ptr<GraphicsContext> context,
|
|
52
|
+
std::uint32_t id,
|
|
53
|
+
unsigned kind,
|
|
54
|
+
std::unique_ptr<sf::Shape> shape)
|
|
55
|
+
: TransformableState(shape.get()),
|
|
56
|
+
context(std::move(context)),
|
|
57
|
+
id(id),
|
|
58
|
+
kind(kind),
|
|
59
|
+
shape(std::move(shape)) {}
|
|
51
60
|
~ShapeState() { context->shapes.erase(id); }
|
|
52
61
|
|
|
53
62
|
void SyncShape() {
|
|
@@ -57,7 +66,7 @@ struct ShapeState : TransformableState {
|
|
|
57
66
|
|
|
58
67
|
std::shared_ptr<GraphicsContext> context;
|
|
59
68
|
std::uint32_t id;
|
|
60
|
-
unsigned kind;
|
|
69
|
+
unsigned kind; // 0 custom, 1 circle, 2 rectangle, 3 convex
|
|
61
70
|
std::unique_ptr<sf::Shape> shape;
|
|
62
71
|
std::shared_ptr<const sf::Texture> texture;
|
|
63
72
|
ShapeAppearance appearance;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
-
#include <SFML/Graphics/Text.hpp>
|
|
4
|
-
|
|
5
3
|
#include <cstddef>
|
|
6
4
|
#include <cstdint>
|
|
7
5
|
#include <type_traits>
|
|
8
6
|
#include <vector>
|
|
9
7
|
|
|
8
|
+
#include <SFML/Graphics/Text.hpp>
|
|
9
|
+
|
|
10
10
|
namespace sfmljs {
|
|
11
11
|
|
|
12
12
|
// Fixed wire layout across 32/64-bit targets. Vertex indices are doubles,
|
|
@@ -21,9 +21,12 @@ struct ShapedGlyphData {
|
|
|
21
21
|
double vertexCount;
|
|
22
22
|
|
|
23
23
|
explicit ShapedGlyphData(const sf::Text::ShapedGlyph& source)
|
|
24
|
-
: glyph(source.glyph),
|
|
24
|
+
: glyph(source.glyph),
|
|
25
|
+
position(source.position),
|
|
26
|
+
cluster(source.cluster),
|
|
25
27
|
textDirection(static_cast<std::uint32_t>(source.textDirection)),
|
|
26
|
-
baseline(source.baseline),
|
|
28
|
+
baseline(source.baseline),
|
|
29
|
+
vertexOffset(source.vertexOffset),
|
|
27
30
|
vertexCount(source.vertexCount) {}
|
|
28
31
|
};
|
|
29
32
|
|
|
@@ -39,7 +42,8 @@ static_assert(offsetof(ShapedGlyphData, vertexOffset) == 64);
|
|
|
39
42
|
static_assert(offsetof(ShapedGlyphData, vertexCount) == 72);
|
|
40
43
|
|
|
41
44
|
// Never mutate or resize an allocation after publishing its mapped buffer.
|
|
42
|
-
// New layouts replace the allocation; escaped buffers/members retain the old
|
|
45
|
+
// New layouts replace the allocation; escaped buffers/members retain the old
|
|
46
|
+
// one.
|
|
43
47
|
using ShapedGlyphStorage = std::vector<ShapedGlyphData>;
|
|
44
48
|
|
|
45
49
|
} // namespace sfmljs
|