-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbind-nanovg.cpp
1581 lines (1437 loc) · 80.9 KB
/
bind-nanovg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "nanovg.h"
#include <emscripten/bind.h>
#define FUNCTION(RET, ARGS, CODE...) \
emscripten::optional_override([] ARGS -> RET { CODE })
#include <malloc.h>
emscripten::val get_mallinfo() {
const auto& i = mallinfo();
emscripten::val rv(emscripten::val::object());
rv.set("arena", emscripten::val(i.arena));
rv.set("ordblks", emscripten::val(i.ordblks));
rv.set("smblks", emscripten::val(i.smblks));
rv.set("hblks", emscripten::val(i.hblks));
rv.set("hblkhd", emscripten::val(i.hblkhd));
rv.set("usmblks", emscripten::val(i.usmblks));
rv.set("fsmblks", emscripten::val(i.fsmblks));
rv.set("uordblks", emscripten::val(i.uordblks));
rv.set("fordblks", emscripten::val(i.fordblks));
rv.set("keepcost", emscripten::val(i.keepcost));
return rv;
}
EMSCRIPTEN_BINDINGS(mallinfo) {
emscripten::function("mallinfo", &get_mallinfo);
}
#include <GLES2/gl2.h>
// #include <EGL/egl.h>
#define NANOVG_GLES2_IMPLEMENTATION
#include "nanovg_gl.h"
#include "nanovg_gl_utils.h"
template <typename T, T NONE>
class ValueCache {
public:
emscripten::val array = emscripten::val::array();
ValueCache() {
if (0 <= NONE) {
array.set(NONE, emscripten::val::null());
}
}
T hold(emscripten::val value) {
if (value.isNull()) { return NONE; }
T index = array["length"].template as<T>();
array.set(index, value);
return index;
}
emscripten::val drop(T index) {
if (index == NONE) { return emscripten::val::null(); }
emscripten::val value = array[index];
array.delete_(index);
return value;
}
emscripten::val find(T index) {
if (index == NONE) { return emscripten::val::null(); }
return array[index];
}
T findIndex(emscripten::val value) {
if (value.isNull()) { return NONE; }
for (T index = 0, length = array["length"].template as<T>(); index < length; ++index) {
if (value.strictlyEquals(array[index])) {
return index;
}
}
return NONE;
}
};
class WrapWebGL {
public:
emscripten::val _gl;
ValueCache<GLuint, 0> _buffers;
ValueCache<GLuint, 0> _textures;
ValueCache<GLuint, 0> _shaders;
ValueCache<GLuint, 0> _programs;
ValueCache<GLint, -1> _uniforms;
ValueCache<GLuint, 0> _framebuffers;
ValueCache<GLuint, 0> _renderbuffers;
WrapWebGL(emscripten::val gl): _gl(gl) {}
};
WrapWebGL* wrap_gl = NULL;
static size_t _gl_format_count(GLenum format) {
switch (format) {
case GL_RGB: // A ignored
case GL_RGBA:
case GL_ALPHA: // RGB ignored
return 4;
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_DEPTH_COMPONENT:
return 1;
}
return 0;
}
static size_t _gl_type_size(GLenum type) {
switch (type) {
case GL_BYTE:
case GL_UNSIGNED_BYTE:
return 1;
case GL_SHORT:
case GL_UNSIGNED_SHORT:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
#if defined(GL_HALF_FLOAT)
case GL_HALF_FLOAT:
#endif
return 2;
case GL_INT:
case GL_UNSIGNED_INT:
case GL_FIXED:
case GL_FLOAT:
return 4;
#if defined(GL_DOUBLE)
case GL_DOUBLE:
return 8;
#endif
}
return 0;
}
static size_t _gl_format_type_size(GLenum format, GLenum type) {
return _gl_format_count(format) * _gl_type_size(type);
}
GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture) {
wrap_gl->_gl.call<void>("activeTexture", texture);
}
GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader) {
wrap_gl->_gl.call<void>("attachShader", wrap_gl->_programs.find(program), wrap_gl->_shaders.find(shader));
}
GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar *name) {
wrap_gl->_gl.call<void>("bindAttribLocation", wrap_gl->_programs.find(program), index, emscripten::val(name));
}
GL_APICALL void GL_APIENTRY glBindBuffer (GLenum target, GLuint buffer) {
wrap_gl->_gl.call<void>("bindBuffer", target, wrap_gl->_buffers.find(buffer));
}
GL_APICALL void GL_APIENTRY glBindFramebuffer (GLenum target, GLuint framebuffer) {
wrap_gl->_gl.call<void>("bindFramebuffer", target, wrap_gl->_framebuffers.find(framebuffer));
}
GL_APICALL void GL_APIENTRY glBindRenderbuffer (GLenum target, GLuint renderbuffer) {
wrap_gl->_gl.call<void>("bindRenderbuffer", target, wrap_gl->_renderbuffers.find(renderbuffer));
}
GL_APICALL void GL_APIENTRY glBindTexture (GLenum target, GLuint texture) {
wrap_gl->_gl.call<void>("bindTexture", target, wrap_gl->_textures.find(texture));
}
GL_APICALL void GL_APIENTRY glBlendColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
wrap_gl->_gl.call<void>("blendColor", red, green, blue, alpha);
}
GL_APICALL void GL_APIENTRY glBlendEquation (GLenum mode) {
wrap_gl->_gl.call<void>("blendEquation", mode);
}
GL_APICALL void GL_APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha) {
wrap_gl->_gl.call<void>("blendEquationSeparate", modeRGB, modeAlpha);
}
GL_APICALL void GL_APIENTRY glBlendFunc (GLenum sfactor, GLenum dfactor) {
wrap_gl->_gl.call<void>("blendFunc", sfactor, dfactor);
}
GL_APICALL void GL_APIENTRY glBlendFuncSeparate (GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) {
wrap_gl->_gl.call<void>("blendFuncSeparate", srcRGB, dstRGB, srcAlpha, dstAlpha);
}
GL_APICALL void GL_APIENTRY glBufferData (GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) {
wrap_gl->_gl.call<void>("bufferData", target, emscripten::typed_memory_view<char>(size, (char*) data), usage);
}
GL_APICALL void GL_APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data) {
wrap_gl->_gl.call<void>("bufferSubData", target, offset, emscripten::typed_memory_view<char>(size, (char*) data));
}
GL_APICALL GLenum GL_APIENTRY glCheckFramebufferStatus (GLenum target) {
return wrap_gl->_gl.call<GLenum>("checkFramebufferStatus", target);
}
GL_APICALL void GL_APIENTRY glClear (GLbitfield mask) {
wrap_gl->_gl.call<void>("clear", mask);
}
GL_APICALL void GL_APIENTRY glClearColor (GLclampf r, GLclampf g, GLclampf b, GLclampf a) {
wrap_gl->_gl.call<void>("clearColor", r, g, b, a);
}
GL_APICALL void GL_APIENTRY glClearDepthf (GLfloat d) {
wrap_gl->_gl.call<void>("clearDepth", d);
}
GL_APICALL void GL_APIENTRY glClearStencil (GLint s) {
wrap_gl->_gl.call<void>("clearStencil", s);
}
GL_APICALL void GL_APIENTRY glColorMask (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
wrap_gl->_gl.call<void>("colorMask", red, green, blue, alpha);
}
GL_APICALL void GL_APIENTRY glCompileShader (GLuint shader) {
wrap_gl->_gl.call<void>("compileShader", wrap_gl->_shaders.find(shader));
}
// GL_APICALL void GL_APIENTRY glCompressedTexImage2D (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data);
// GL_APICALL void GL_APIENTRY glCompressedTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data);
// GL_APICALL void GL_APIENTRY glCopyTexImage2D (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
// GL_APICALL void GL_APIENTRY glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
GL_APICALL GLuint GL_APIENTRY glCreateProgram () {
return wrap_gl->_programs.hold(wrap_gl->_gl.call<emscripten::val>("createProgram"));
}
GL_APICALL GLuint GL_APIENTRY glCreateShader (GLenum shaderType) {
return wrap_gl->_shaders.hold(wrap_gl->_gl.call<emscripten::val>("createShader", shaderType));
}
GL_APICALL void GL_APIENTRY glCullFace (GLenum mode) {
wrap_gl->_gl.call<void>("cullFace", mode);
}
GL_APICALL void GL_APIENTRY glDeleteBuffers (GLsizei n, const GLuint * buffers) {
for (GLsizei i = 0; i < n; ++i) {
wrap_gl->_gl.call<void>("deleteBuffer", wrap_gl->_buffers.drop(buffers[i]));
}
}
GL_APICALL void GL_APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers) {
for (GLsizei i = 0; i < n; ++i) {
wrap_gl->_gl.call<void>("deleteFramebuffer", wrap_gl->_framebuffers.drop(framebuffers[i]));
}
}
GL_APICALL void GL_APIENTRY glDeleteProgram (GLuint program) {
wrap_gl->_gl.call<void>("deleteProgram", wrap_gl->_programs.drop(program));
}
GL_APICALL void GL_APIENTRY glDeleteRenderbuffers (GLsizei n, const GLuint *renderbuffers) {
for (GLsizei i = 0; i < n; ++i) {
wrap_gl->_gl.call<void>("deleteRenderbuffer", wrap_gl->_renderbuffers.drop(renderbuffers[i]));
}
}
GL_APICALL void GL_APIENTRY glDeleteShader (GLuint shader) {
wrap_gl->_gl.call<void>("deleteShader", wrap_gl->_shaders.drop(shader));
}
GL_APICALL void GL_APIENTRY glDeleteTextures (GLsizei n, const GLuint * textures) {
for (GLsizei i = 0; i < n; ++i) {
wrap_gl->_gl.call<void>("deleteTexture", wrap_gl->_textures.drop(textures[i]));
}
}
GL_APICALL void GL_APIENTRY glDepthFunc (GLenum func) {
wrap_gl->_gl.call<void>("depthFunc", func);
}
GL_APICALL void GL_APIENTRY glDepthMask (GLboolean flag) {
wrap_gl->_gl.call<void>("depthMask", flag);
}
GL_APICALL void GL_APIENTRY glDepthRangef (GLfloat n, GLfloat f) {
wrap_gl->_gl.call<void>("depthRange", n, f);
}
GL_APICALL void GL_APIENTRY glDetachShader (GLuint program, GLuint shader) {
wrap_gl->_gl.call<void>("detachShader", wrap_gl->_programs.find(program), wrap_gl->_shaders.find(shader));
}
GL_APICALL void GL_APIENTRY glDisable (GLenum cap) {
wrap_gl->_gl.call<void>("disable", cap);
}
GL_APICALL void GL_APIENTRY glDisableVertexAttribArray (GLuint index) {
wrap_gl->_gl.call<void>("disableVertexAttribArray", index);
}
GL_APICALL void GL_APIENTRY glDrawArrays (GLenum mode, GLint first, GLsizei count) {
wrap_gl->_gl.call<void>("drawArrays", mode, first, count);
}
GL_APICALL void GL_APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices) {
wrap_gl->_gl.call<void>("drawElements", mode, count, type, (GLintptr) indices);
}
GL_APICALL void GL_APIENTRY glEnable (GLenum cap) {
wrap_gl->_gl.call<void>("enable", cap);
}
GL_APICALL void GL_APIENTRY glEnableVertexAttribArray (GLuint index) {
wrap_gl->_gl.call<void>("enableVertexAttribArray", index);
}
GL_APICALL void GL_APIENTRY glFinish () {
wrap_gl->_gl.call<void>("finish");
}
GL_APICALL void GL_APIENTRY glFlush (void) {
wrap_gl->_gl.call<void>("flush");
}
GL_APICALL void GL_APIENTRY glFramebufferRenderbuffer (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) {
wrap_gl->_gl.call<void>("framebufferRenderbuffer", target, attachment, renderbuffertarget, wrap_gl->_renderbuffers.find(renderbuffer));
}
GL_APICALL void GL_APIENTRY glFramebufferTexture2D (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) {
wrap_gl->_gl.call<void>("framebufferTexture2D", target, attachment, textarget, wrap_gl->_textures.find(texture), level);
}
GL_APICALL void GL_APIENTRY glFrontFace (GLenum mode) {
wrap_gl->_gl.call<void>("frontFace", mode);
}
GL_APICALL void GL_APIENTRY glGenBuffers (GLsizei n, GLuint * buffers) {
for (GLsizei i = 0; i < n; ++i) {
buffers[i] = wrap_gl->_buffers.hold(wrap_gl->_gl.call<emscripten::val>("createBuffer"));
}
}
GL_APICALL void GL_APIENTRY glGenerateMipmap (GLenum target) {
wrap_gl->_gl.call<void>("generateMipmap");
}
GL_APICALL void GL_APIENTRY glGenFramebuffers (GLsizei n, GLuint* textures) {
for (GLsizei i = 0; i < n; ++i) {
textures[i] = wrap_gl->_framebuffers.hold(wrap_gl->_gl.call<emscripten::val>("createFramebuffer"));
}
}
GL_APICALL void GL_APIENTRY glGenRenderbuffers (GLsizei n, GLuint* textures) {
for (GLsizei i = 0; i < n; ++i) {
textures[i] = wrap_gl->_renderbuffers.hold(wrap_gl->_gl.call<emscripten::val>("createRenderbuffer"));
}
}
GL_APICALL void GL_APIENTRY glGenTextures (GLsizei n, GLuint* textures) {
for (GLsizei i = 0; i < n; ++i) {
textures[i] = wrap_gl->_textures.hold(wrap_gl->_gl.call<emscripten::val>("createTexture"));
}
}
// GL_APICALL void GL_APIENTRY glGetActiveAttrib (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
// GL_APICALL void GL_APIENTRY glGetActiveUniform (GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);
// GL_APICALL void GL_APIENTRY glGetAttachedShaders (GLuint program, GLsizei maxCount, GLsizei *count, GLuint *shaders);
GL_APICALL GLint GL_APIENTRY glGetAttribLocation (GLuint program, const GLchar *name) {
return wrap_gl->_gl.call<GLint>("getAttribLocation", wrap_gl->_programs.find(program), emscripten::val(name));
}
// GL_APICALL void GL_APIENTRY glGetBooleanv (GLenum pname, GLboolean *data);
// GL_APICALL void GL_APIENTRY glGetBufferParameteriv (GLenum target, GLenum pname, GLint *params);
GL_APICALL GLenum GL_APIENTRY glGetError () {
return wrap_gl->_gl.call<GLenum>("getError");
}
// GL_APICALL void GL_APIENTRY glGetFloatv (GLenum pname, GLfloat *data);
// GL_APICALL void GL_APIENTRY glGetFramebufferAttachmentParameteriv (GLenum target, GLenum attachment, GLenum pname, GLint *params);
GL_APICALL void GL_APIENTRY glGetIntegerv (GLenum pname, GLint *data) {
emscripten::val value = wrap_gl->_gl.call<emscripten::val>("getParameter", pname);
switch (pname) {
case GL_FRAMEBUFFER_BINDING:
*data = value.isNull() ? 0 : value.as<GLint>();
break;
case GL_RENDERBUFFER_BINDING:
*data = value.isNull() ? 0 : value.as<GLint>();
break;
}
}
GL_APICALL void GL_APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params) {
emscripten::val value = wrap_gl->_gl.call<emscripten::val>("getProgramParameter", wrap_gl->_programs.find(program), pname);
switch (pname) {
// case GL_DELETE_STATUS: // params returns GL_TRUE if program is currently flagged for deletion, and GL_FALSE otherwise.
case GL_LINK_STATUS: // params returns GL_TRUE if the last link operation on program was successful, and GL_FALSE otherwise.
*params = value.as<GLboolean>() ? GL_TRUE : GL_FALSE;
break;
// case GL_VALIDATE_STATUS: // params returns GL_TRUE or if the last validation operation on program was successful, and GL_FALSE otherwise.
// case GL_INFO_LOG_LENGTH: // params returns the number of characters in the information log for program including the null termination character (i.e., the size of the character buffer required to store the information log). If program has no information log, a value of 0 is returned.
// case GL_ATTACHED_SHADERS: // params returns the number of shader objects attached to program.
// case GL_ACTIVE_ATTRIBUTES: // params returns the number of active attribute variables for program.
// case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: // params returns the length of the longest active attribute name for program, including the null termination character (i.e., the size of the character buffer required to store the longest attribute name). If no active attributes exist, 0 is returned.
// case GL_ACTIVE_UNIFORMS: // params returns the number of active uniform variables for program.
// case GL_ACTIVE_UNIFORM_MAX_LENGTH: // params returns the length of the longest active uniform variable name for program, including the null termination character (i.e., the size of the character buffer required to store the longest uniform variable name). If no active uniform variables exist, 0 is returned.
}
}
GL_APICALL void GL_APIENTRY glGetProgramInfoLog (GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog) {
std::string log = wrap_gl->_gl.call<emscripten::val>("getProgramInfoLog", wrap_gl->_programs.find(program)).as<std::string>();
*length = log.length();
strncpy(infoLog, log.c_str(), maxLength);
}
// GL_APICALL void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint *params);
GL_APICALL void GL_APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params) {
emscripten::val value = wrap_gl->_gl.call<emscripten::val>("getShaderParameter", wrap_gl->_shaders.find(shader), pname);
switch (pname) {
// case GL_SHADER_TYPE: // params returns GL_VERTEX_SHADER if shader is a vertex shader object, and GL_FRAGMENT_SHADER if shader is a fragment shader object.
// case GL_DELETE_STATUS: // params returns GL_TRUE if shader is currently flagged for deletion, and GL_FALSE otherwise.
case GL_COMPILE_STATUS: // For implementations that support a shader compiler, params returns GL_TRUE if the last compile operation on shader was successful, and GL_FALSE otherwise.
*params = value.as<GLboolean>() ? GL_TRUE : GL_FALSE;
break;
// case GL_INFO_LOG_LENGTH: // For implementations that support a shader compiler, params returns the number of characters in the information log for shader including the null termination character (i.e., the size of the character buffer required to store the information log). If shader has no information log, a value of 0 is returned.
// case GL_SHADER_SOURCE_LENGTH: // For implementations that support a shader compiler, params returns the length of the concatenation of the source strings that make up the shader source for the shader, including the null termination character. (i.e., the size of the character buffer required to store the shader source). If no source code exists, 0 is returned.
}
}
GL_APICALL void GL_APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog) {
std::string log = wrap_gl->_gl.call<emscripten::val>("getShaderInfoLog", wrap_gl->_shaders.find(shader)).as<std::string>();
*length = log.length();
strncpy(infoLog, log.c_str(), maxLength);
}
// GL_APICALL void GL_APIENTRY glGetShaderPrecisionFormat (GLenum shadertype, GLenum precisiontype, GLint *range, GLint *precision);
// GL_APICALL void GL_APIENTRY glGetShaderSource (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source);
// GL_APICALL const GLubyte *GL_APIENTRY glGetString (GLenum name);
// GL_APICALL void GL_APIENTRY glGetTexParameterfv (GLenum target, GLenum pname, GLfloat *params);
// GL_APICALL void GL_APIENTRY glGetTexParameteriv (GLenum target, GLenum pname, GLint *params);
// GL_APICALL void GL_APIENTRY glGetUniformfv (GLuint program, GLint location, GLfloat *params);
// GL_APICALL void GL_APIENTRY glGetUniformiv (GLuint program, GLint location, GLint *params);
GL_APICALL GLint GL_APIENTRY glGetUniformLocation (GLuint program, const GLchar *name) {
// return wrap_gl->_uniforms.hold(wrap_gl->_gl.call<emscripten::val>("getUniformLocation", wrap_gl->_programs.find(program), emscripten::val(name)));
emscripten::val value = wrap_gl->_gl.call<emscripten::val>("getUniformLocation", wrap_gl->_programs.find(program), emscripten::val(name));
if (value.isNull()) { return -1; }
return wrap_gl->_uniforms.hold(value);
}
// GL_APICALL void GL_APIENTRY glGetVertexAttribfv (GLuint index, GLenum pname, GLfloat *params);
// GL_APICALL void GL_APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
// GL_APICALL void GL_APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
GL_APICALL void GL_APIENTRY glHint (GLenum target, GLenum mode) {
wrap_gl->_gl.call<void>("hint", target, mode);
}
GL_APICALL GLboolean GL_APIENTRY glIsBuffer (GLuint buffer) {
return wrap_gl->_gl.call<GLboolean>("isBuffer", wrap_gl->_buffers.find(buffer));
}
GL_APICALL GLboolean GL_APIENTRY glIsEnabled (GLenum cap) {
return wrap_gl->_gl.call<GLboolean>("isEnabled", cap);
}
GL_APICALL GLboolean GL_APIENTRY glIsFramebuffer (GLuint framebuffer) {
return wrap_gl->_gl.call<GLboolean>("isFramebuffer", wrap_gl->_framebuffers.find(framebuffer));
}
GL_APICALL GLboolean GL_APIENTRY glIsProgram (GLuint program) {
return wrap_gl->_gl.call<GLboolean>("isProgram", wrap_gl->_programs.find(program));
}
GL_APICALL GLboolean GL_APIENTRY glIsRenderbuffer (GLuint renderbuffer) {
return wrap_gl->_gl.call<GLboolean>("isRenderbuffer", wrap_gl->_renderbuffers.find(renderbuffer));
}
GL_APICALL GLboolean GL_APIENTRY glIsShader (GLuint shader) {
return wrap_gl->_gl.call<GLboolean>("isShader", wrap_gl->_shaders.find(shader));
}
GL_APICALL GLboolean GL_APIENTRY glIsTexture (GLuint texture) {
return wrap_gl->_gl.call<GLboolean>("isTexture", wrap_gl->_textures.find(texture));
}
GL_APICALL void GL_APIENTRY glLineWidth (GLfloat width) {
wrap_gl->_gl.call<void>("lineWidth", width);
}
GL_APICALL void GL_APIENTRY glLinkProgram (GLuint program) {
wrap_gl->_gl.call<void>("linkProgram", wrap_gl->_programs.find(program));
}
GL_APICALL void GL_APIENTRY glPixelStorei (GLenum pname, GLint param) {
wrap_gl->_gl.call<void>("pixelStorei", pname, param);
}
GL_APICALL void GL_APIENTRY glPolygonOffset (GLfloat factor, GLfloat units) {
wrap_gl->_gl.call<void>("polygonOffset", factor, units);
}
GL_APICALL void GL_APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) {
size_t _size = width * height * _gl_format_type_size(format, type);
wrap_gl->_gl.call<void>("readPixels", x, y, width, height, format, type, emscripten::typed_memory_view<char>(_size, (char*) pixels));
}
GL_APICALL void GL_APIENTRY glReleaseShaderCompiler (void) {
// not implemented
}
GL_APICALL void GL_APIENTRY glRenderbufferStorage (GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {
wrap_gl->_gl.call<void>("renderbufferStorage", target, internalformat, width, height);
}
GL_APICALL void GL_APIENTRY glSampleCoverage (GLfloat value, GLboolean invert) {
wrap_gl->_gl.call<void>("sampleCoverage", value, invert);
}
GL_APICALL void GL_APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height) {
wrap_gl->_gl.call<void>("scissor", x, y, width, height);
}
GL_APICALL void GL_APIENTRY glShaderBinary (GLsizei count, const GLuint *shaders, GLenum binaryformat, const void *binary, GLsizei length) {
// not implemented
}
GL_APICALL void GL_APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar * const *string, const GLint *length) {
std::string source;
for (GLsizei index = 0; index < count; ++index) {
source += string[index];
}
wrap_gl->_gl.call<void>("shaderSource", wrap_gl->_shaders.find(shader), source);
}
GL_APICALL void GL_APIENTRY glStencilFunc (GLenum func, GLint ref, GLuint mask) {
wrap_gl->_gl.call<void>("stencilFunc", func, ref, mask);
}
GL_APICALL void GL_APIENTRY glStencilFuncSeparate (GLenum face, GLenum func, GLint ref, GLuint mask) {
wrap_gl->_gl.call<void>("stencilFuncSeparate", face, func, ref, mask);
}
GL_APICALL void GL_APIENTRY glStencilMask (GLuint mask) {
wrap_gl->_gl.call<void>("stencilMask", mask);
}
GL_APICALL void GL_APIENTRY glStencilMaskSeparate (GLenum face, GLuint mask) {
wrap_gl->_gl.call<void>("stencilMaskSeparate", face, mask);
}
GL_APICALL void GL_APIENTRY glStencilOp (GLenum sfail, GLenum dpfail, GLenum dppass) {
wrap_gl->_gl.call<void>("stencilOp", sfail, dpfail, dppass);
}
GL_APICALL void GL_APIENTRY glStencilOpSeparate (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) {
wrap_gl->_gl.call<void>("stencilOpSeparate", face, sfail, dpfail, dppass);
}
GL_APICALL void GL_APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * data) {
size_t _size = width * height * _gl_format_type_size(format, type);
emscripten::val _data = (data == NULL) ? emscripten::val::null() : emscripten::val(emscripten::typed_memory_view<unsigned char>(_size, (unsigned char*) data));
wrap_gl->_gl.call<void>("texImage2D", target, level, internalformat, width, height, border, format, type, _data);
}
GL_APICALL void GL_APIENTRY glTexParameterf (GLenum target, GLenum pname, GLfloat param) {
wrap_gl->_gl.call<void>("texParameterf", target, pname, param);
}
// GL_APICALL void GL_APIENTRY glTexParameterfv (GLenum target, GLenum pname, const GLfloat *params);
GL_APICALL void GL_APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param) {
wrap_gl->_gl.call<void>("texParameteri", target, pname, param);
}
// GL_APICALL void GL_APIENTRY glTexParameteriv (GLenum target, GLenum pname, const GLint *params);
GL_APICALL void GL_APIENTRY glTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid * data) {
size_t _size = width * height * _gl_format_type_size(format, type);
emscripten::val _data = (data == NULL) ? emscripten::val::null() : emscripten::val(emscripten::typed_memory_view<unsigned char>(_size, (unsigned char*) data));
wrap_gl->_gl.call<void>("texSubImage2D", target, level, xoffset, yoffset, width, height, format, type, _data);
}
GL_APICALL void GL_APIENTRY glUniform1f (GLint location, GLfloat v0) {
wrap_gl->_gl.call<void>("uniform1f", wrap_gl->_uniforms.find(location), v0);
}
GL_APICALL void GL_APIENTRY glUniform1fv (GLint location, GLsizei count, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniform1fv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<float>(count, value));
}
GL_APICALL void GL_APIENTRY glUniform1i (GLint location, GLint v0) {
wrap_gl->_gl.call<void>("uniform1i", wrap_gl->_uniforms.find(location), v0);
}
GL_APICALL void GL_APIENTRY glUniform1iv (GLint location, GLsizei count, const GLint *value) {
wrap_gl->_gl.call<void>("uniform1iv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<int>(count, value));
}
GL_APICALL void GL_APIENTRY glUniform2f (GLint location, GLfloat v0, GLfloat v1) {
wrap_gl->_gl.call<void>("uniform2f", wrap_gl->_uniforms.find(location), v0, v1);
}
GL_APICALL void GL_APIENTRY glUniform2fv (GLint location, GLsizei count, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniform2fv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<float>(count*2, value));
}
GL_APICALL void GL_APIENTRY glUniform2i (GLint location, GLint v0, GLint v1) {
wrap_gl->_gl.call<void>("uniform2i", wrap_gl->_uniforms.find(location), v0, v1);
}
GL_APICALL void GL_APIENTRY glUniform2iv (GLint location, GLsizei count, const GLint *value) {
wrap_gl->_gl.call<void>("uniform2iv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<int>(count*2, value));
}
GL_APICALL void GL_APIENTRY glUniform3f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {
wrap_gl->_gl.call<void>("uniform3f", wrap_gl->_uniforms.find(location), v0, v1, v2);
}
GL_APICALL void GL_APIENTRY glUniform3fv (GLint location, GLsizei count, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniform3fv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<float>(count*3, value));
}
GL_APICALL void GL_APIENTRY glUniform3i (GLint location, GLint v0, GLint v1, GLint v2) {
wrap_gl->_gl.call<void>("uniform3i", wrap_gl->_uniforms.find(location), v0, v1, v2);
}
GL_APICALL void GL_APIENTRY glUniform3iv (GLint location, GLsizei count, const GLint *value) {
wrap_gl->_gl.call<void>("uniform3iv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<int>(count*3, value));
}
GL_APICALL void GL_APIENTRY glUniform4f (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
wrap_gl->_gl.call<void>("uniform4f", wrap_gl->_uniforms.find(location), v0, v1, v2, v3);
}
GL_APICALL void GL_APIENTRY glUniform4fv (GLint location, GLsizei count, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniform4fv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<float>(count*4, value));
}
GL_APICALL void GL_APIENTRY glUniform4i (GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {
wrap_gl->_gl.call<void>("uniform4i", wrap_gl->_uniforms.find(location), v0, v1, v2, v3);
}
GL_APICALL void GL_APIENTRY glUniform4iv (GLint location, GLsizei count, const GLint *value) {
wrap_gl->_gl.call<void>("uniform4iv", wrap_gl->_uniforms.find(location), emscripten::typed_memory_view<int>(count*4, value));
}
GL_APICALL void GL_APIENTRY glUniformMatrix2fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniformMatrix2fv", wrap_gl->_uniforms.find(location), transpose, emscripten::typed_memory_view<float>(count, value));
}
GL_APICALL void GL_APIENTRY glUniformMatrix3fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniformMatrix3fv", wrap_gl->_uniforms.find(location), transpose, emscripten::typed_memory_view<float>(count, value));
}
GL_APICALL void GL_APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) {
wrap_gl->_gl.call<void>("uniformMatrix4fv", wrap_gl->_uniforms.find(location), transpose, emscripten::typed_memory_view<float>(count, value));
}
GL_APICALL void GL_APIENTRY glUseProgram (GLuint program) {
wrap_gl->_gl.call<void>("useProgram", wrap_gl->_programs.find(program));
}
GL_APICALL void GL_APIENTRY glValidateProgram (GLuint program) {
wrap_gl->_gl.call<void>("validateProgram", wrap_gl->_programs.find(program));
}
GL_APICALL void GL_APIENTRY glVertexAttrib1f (GLuint index, GLfloat x) {
wrap_gl->_gl.call<void>("vertexAttrib1f", index, x);
}
GL_APICALL void GL_APIENTRY glVertexAttrib1fv (GLuint index, const GLfloat *v) {
wrap_gl->_gl.call<void>("vertexAttrib1fv", index, emscripten::typed_memory_view<float>(1, v));
}
GL_APICALL void GL_APIENTRY glVertexAttrib2f (GLuint index, GLfloat x, GLfloat y) {
wrap_gl->_gl.call<void>("vertexAttrib2f", index, x, y);
}
GL_APICALL void GL_APIENTRY glVertexAttrib2fv (GLuint index, const GLfloat *v) {
wrap_gl->_gl.call<void>("vertexAttrib2fv", index, emscripten::typed_memory_view<float>(2, v));
}
GL_APICALL void GL_APIENTRY glVertexAttrib3f (GLuint index, GLfloat x, GLfloat y, GLfloat z) {
wrap_gl->_gl.call<void>("vertexAttrib3f", index, x, y, z);
}
GL_APICALL void GL_APIENTRY glVertexAttrib3fv (GLuint index, const GLfloat *v) {
wrap_gl->_gl.call<void>("vertexAttrib3fv", index, emscripten::typed_memory_view<float>(3, v));
}
GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) {
wrap_gl->_gl.call<void>("vertexAttrib4f", index, x, y, z, w);
}
GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint index, const GLfloat *v) {
wrap_gl->_gl.call<void>("vertexAttrib4fv", index, emscripten::typed_memory_view<float>(4, v));
}
GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid * pointer) {
wrap_gl->_gl.call<void>("vertexAttribPointer", index, size, type, normalized, stride, (GLintptr) pointer);
}
GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLuint w, GLuint h) {
wrap_gl->_gl.call<void>("viewport", x, y, w, h);
}
class WrapNVGcontext {
public:
NVGcontext* ctx;
WrapNVGcontext(emscripten::val gl, int flags) {
wrap_gl = new WrapWebGL(gl);
ctx = nvgCreateGLES2(flags);
}
~WrapNVGcontext() {
nvgDeleteGLES2(ctx); ctx = NULL;
delete wrap_gl; wrap_gl = NULL;
}
};
EMSCRIPTEN_BINDINGS(WrapNVGcontext) {
emscripten::class_<WrapNVGcontext>("WrapNVGcontext")
;
}
EMSCRIPTEN_BINDINGS(NanoVG_GL) {
emscripten::function("nvgCreateWebGL", FUNCTION(WrapNVGcontext*, (emscripten::val gl, int flags), {
return new WrapNVGcontext(gl, flags);
}), emscripten::allow_raw_pointers());
emscripten::function("nvgDeleteWebGL", FUNCTION(void, (WrapNVGcontext* wrap), {
delete wrap;
}), emscripten::allow_raw_pointers());
// int nvglCreateImageFromHandleGLES2(NVGcontext* ctx, GLuint textureId, int w, int h, int flags);
// nvglCreateImageFromHandleWebGL(ctx: NVGcontext, textureId: WebGLTexture | null, w: number, h: number, flags: number): number;
emscripten::function("nvglCreateImageFromHandleWebGL", FUNCTION(int, (WrapNVGcontext* wrap, emscripten::val textureId, int w, int h, int flags), {
GLuint index = wrap_gl->_textures.findIndex(textureId);
return nvglCreateImageFromHandleGLES2(wrap->ctx, index, w, h, flags);
}), emscripten::allow_raw_pointers());
// GLuint nvglImageHandleGLES2(NVGcontext* ctx, int image);
// nvglImageHandleWebGL(ctx: NVGcontext, image: number): WebGLTexture | null;
emscripten::function("nvglImageHandleWebGL", FUNCTION(emscripten::val, (WrapNVGcontext* wrap, int image), {
GLuint texture = nvglImageHandleGLES2(wrap->ctx, image);
return wrap_gl->_textures.find(texture);
}), emscripten::allow_raw_pointers());
}
class WrapNVGLUframebuffer {
public:
NVGLUframebuffer* fb;
WrapNVGLUframebuffer(NVGcontext* ctx, int w, int h, int imageFlags) {
fb = nvgluCreateFramebuffer(ctx, w, h, imageFlags);
}
~WrapNVGLUframebuffer() {
nvgluDeleteFramebuffer(fb); fb = NULL;
}
};
EMSCRIPTEN_BINDINGS(WrapNVGLUframebuffer) {
emscripten::class_<WrapNVGLUframebuffer>("WrapNVGLUframebuffer")
// NVGcontext* ctx;
// GLuint fbo;
.property("fbo", FUNCTION(emscripten::val, (const WrapNVGLUframebuffer& that), {
return wrap_gl->_framebuffers.find(that.fb->fbo);
}))
// GLuint rbo;
.property("rbo", FUNCTION(emscripten::val, (const WrapNVGLUframebuffer& that), {
return wrap_gl->_renderbuffers.find(that.fb->rbo);
}))
// GLuint texture;
.property("texture", FUNCTION(emscripten::val, (const WrapNVGLUframebuffer& that), {
return wrap_gl->_textures.find(that.fb->texture);
}))
// int image;
.property("image", FUNCTION(int, (const WrapNVGLUframebuffer& that), {
return that.fb->image;
}))
;
}
EMSCRIPTEN_BINDINGS(NanoVG_GLU) {
// void nvgluBindFramebuffer(NVGLUframebuffer* fb);
// nvgluBindFramebuffer(fb: NVGLUframebuffer): void;
emscripten::function("nvgluBindFramebuffer", FUNCTION(void, (WrapNVGLUframebuffer* wrap), {
nvgluBindFramebuffer(wrap == NULL ? NULL : wrap->fb);
}), emscripten::allow_raw_pointers());
// NVGLUframebuffer* nvgluCreateFramebuffer(NVGcontext* ctx, int w, int h, int imageFlags);
// nvgluCreateFramebuffer(ctx: NVGcontext, w: number, h: number, imageFlags: NVGimageFlags): NVGLUframebuffer;
emscripten::function("nvgluCreateFramebuffer", FUNCTION(WrapNVGLUframebuffer*, (WrapNVGcontext* wrap_ctx, int w, int h, int imageFlags), {
return new WrapNVGLUframebuffer(wrap_ctx->ctx, w, h, imageFlags);
}), emscripten::allow_raw_pointers());
// void nvgluDeleteFramebuffer(NVGLUframebuffer* fb);
// nvgluDeleteFramebuffer(fb: NVGLUframebuffer): void;
emscripten::function("nvgluDeleteFramebuffer", FUNCTION(void, (WrapNVGLUframebuffer* wrap), {
delete wrap;
}), emscripten::allow_raw_pointers());
}
static NVGcolor import_NVGcolor(emscripten::val value) {
NVGcolor color;
color.r = value["r"].as<float>();
color.g = value["g"].as<float>();
color.b = value["b"].as<float>();
color.a = value["a"].as<float>();
return color;
}
static emscripten::val export_NVGcolor(const NVGcolor& color, emscripten::val value) {
value.set("r", emscripten::val(color.r));
value.set("g", emscripten::val(color.g));
value.set("b", emscripten::val(color.b));
value.set("a", emscripten::val(color.a));
return value;
}
EMSCRIPTEN_BINDINGS(NVGcolor) {
emscripten::class_<NVGcolor>("NVGcolor")
.property("rgba", FUNCTION(emscripten::val, (const NVGcolor& that), {
return emscripten::val(emscripten::typed_memory_view<float>(4, that.rgba));
}))
.property("r", &NVGcolor::r)
.property("g", &NVGcolor::g)
.property("b", &NVGcolor::b)
.property("a", &NVGcolor::a)
;
}
static NVGpaint import_NVGpaint(emscripten::val value) {
NVGpaint paint;
emscripten::val xform = value["xform"];
for (int i = 0; i < 6; ++i) {
paint.xform[i] = xform[i].as<float>();
}
emscripten::val extent = value["extent"];
for (int i = 0; i < 2; ++i) {
paint.extent[i] = extent[i].as<float>();
}
paint.radius = value["radius"].as<int>();
paint.feather = value["feather"].as<int>();
paint.innerColor = import_NVGcolor(value["innerColor"]);
paint.outerColor = import_NVGcolor(value["outerColor"]);
paint.image = value["image"].as<int>();
return paint;
}
static emscripten::val export_NVGpaint(const NVGpaint& paint, emscripten::val value) {
emscripten::val xform = value["xform"];
for (int i = 0; i < 6; ++i) {
xform.set(i, emscripten::val(paint.xform[i]));
}
emscripten::val extent = value["extent"];
for (int i = 0; i < 2; ++i) {
extent.set(i, emscripten::val(paint.extent[i]));
}
value.set("radius", emscripten::val(paint.radius));
value.set("feather", emscripten::val(paint.feather));
export_NVGcolor(paint.innerColor, value["innerColor"]);
export_NVGcolor(paint.outerColor, value["outerColor"]);
value.set("image", emscripten::val(paint.image));
return value;
}
EMSCRIPTEN_BINDINGS(NVGpaint) {
emscripten::class_<NVGpaint>("NVGpaint")
.property("xform", FUNCTION(emscripten::val, (const NVGpaint& that), {
return emscripten::val(emscripten::typed_memory_view<float>(6, that.xform));
}))
.property("extent", FUNCTION(emscripten::val, (const NVGpaint& that), {
return emscripten::val(emscripten::typed_memory_view<float>(2, that.extent));
}))
.property("radius", &NVGpaint::radius)
.property("feather", &NVGpaint::feather)
.property("innerColor", &NVGpaint::innerColor)
.property("outerColor", &NVGpaint::outerColor)
.property("image", &NVGpaint::image)
;
}
EMSCRIPTEN_BINDINGS(NVGcompositeOperationState) {
emscripten::class_<NVGcompositeOperationState>("NVGcompositeOperationState")
.property("srcRGB", &NVGcompositeOperationState::srcRGB)
.property("dstRGB", &NVGcompositeOperationState::dstRGB)
.property("srcAlpha", &NVGcompositeOperationState::srcAlpha)
.property("dstAlpha", &NVGcompositeOperationState::dstAlpha)
;
}
EMSCRIPTEN_BINDINGS(NVGscissor) {
emscripten::class_<NVGscissor>("NVGscissor")
.property("xform", FUNCTION(emscripten::val, (const NVGscissor& that), {
return emscripten::val(emscripten::typed_memory_view<float>(6, that.xform));
}))
.property("extent", FUNCTION(emscripten::val, (const NVGscissor& that), {
return emscripten::val(emscripten::typed_memory_view<float>(2, that.extent));
}))
;
}
EMSCRIPTEN_BINDINGS(NanoVG) {
// Begin drawing a new frame
// Calls to nanovg drawing API should be wrapped in nvgBeginFrame() & nvgEndFrame()
// nvgBeginFrame() defines the size of the window to render to in relation currently
// set viewport (i.e. glViewport on GL backends). Device pixel ration allows to
// control the rendering on Hi-DPI devices.
// For example, GLFW returns two dimension for an opened window: window size and
// frame buffer size. In that case you would set windowWidth/Height to the window size
// devicePixelRatio to: frameBufferWidth / windowWidth.
// // void nvgBeginFrame(NVGcontext* ctx, float windowWidth, float windowHeight, float devicePixelRatio);
emscripten::function("nvgBeginFrame", FUNCTION(void, (WrapNVGcontext* wrap, float windowWidth, float windowHeight, float devicePixelRatio), {
nvgBeginFrame(wrap->ctx, windowWidth, windowHeight, devicePixelRatio);
}), emscripten::allow_raw_pointers());
// Cancels drawing the current frame.
// void nvgCancelFrame(NVGcontext* ctx);
emscripten::function("nvgCancelFrame", FUNCTION(void, (WrapNVGcontext* wrap), {
nvgCancelFrame(wrap->ctx);
}), emscripten::allow_raw_pointers());
// Ends drawing flushing remaining render state.
// void nvgEndFrame(NVGcontext* ctx);
emscripten::function("nvgEndFrame", FUNCTION(void, (WrapNVGcontext* wrap), {
nvgEndFrame(wrap->ctx);
}), emscripten::allow_raw_pointers());
//
// Composite operation
//
// The composite operations in NanoVG are modeled after HTML Canvas API, and
// the blend func is based on OpenGL (see corresponding manuals for more info).
// The colors in the blending state have premultiplied alpha.
// Sets the composite operation. The op parameter should be one of NVGcompositeOperation.
// void nvgGlobalCompositeOperation(NVGcontext* ctx, int op);
emscripten::function("nvgGlobalCompositeOperation", FUNCTION(void, (WrapNVGcontext* wrap, int op), {
nvgGlobalCompositeOperation(wrap->ctx, op);
}), emscripten::allow_raw_pointers());
// Sets the composite operation with custom pixel arithmetic. The parameters should be one of NVGblendFactor.
// void nvgGlobalCompositeBlendFunc(NVGcontext* ctx, int sfactor, int dfactor);
emscripten::function("nvgGlobalCompositeBlendFunc", FUNCTION(void, (WrapNVGcontext* wrap, int sfactor, int dfactor), {
nvgGlobalCompositeBlendFunc(wrap->ctx, sfactor, dfactor);
}), emscripten::allow_raw_pointers());
// Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately. The parameters should be one of NVGblendFactor.
// void nvgGlobalCompositeBlendFuncSeparate(NVGcontext* ctx, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha);
emscripten::function("nvgGlobalCompositeBlendFuncSeparate", FUNCTION(void, (WrapNVGcontext* wrap, int srcRGB, int dstRGB, int srcAlpha, int dstAlpha), {
nvgGlobalCompositeBlendFuncSeparate(wrap->ctx, srcRGB, dstRGB, srcAlpha, dstAlpha);
}), emscripten::allow_raw_pointers());
//
// Color utils
//
// Colors in NanoVG are stored as unsigned ints in ABGR format.
// Returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).
// NVGcolor nvgRGB(unsigned char r, unsigned char g, unsigned char b);
// Returns a color value from red, green, blue values. Alpha will be set to 1.0f.
// NVGcolor nvgRGBf(float r, float g, float b);
// Returns a color value from red, green, blue and alpha values.
// NVGcolor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
// Returns a color value from red, green, blue and alpha values.
// NVGcolor nvgRGBAf(float r, float g, float b, float a);
// Linearly interpolates from color c0 to c1, and returns resulting color value.
// NVGcolor nvgLerpRGBA(NVGcolor c0, NVGcolor c1, float u);
// Sets transparency of a color value.
// NVGcolor nvgTransRGBA(NVGcolor c0, unsigned char a);
// Sets transparency of a color value.
// NVGcolor nvgTransRGBAf(NVGcolor c0, float a);
// Returns color value specified by hue, saturation and lightness.
// HSL values are all in range [0..1], alpha will be set to 255.
// NVGcolor nvgHSL(float h, float s, float l);
// Returns color value specified by hue, saturation and lightness and alpha.
// HSL values are all in range [0..1], alpha in range [0..255]
// NVGcolor nvgHSLA(float h, float s, float l, unsigned char a);
//
// State Handling
//
// NanoVG contains state which represents how paths will be rendered.
// The state contains transform, fill and stroke styles, text and font styles,
// and scissor clipping.
// Pushes and saves the current render state into a state stack.
// A matching nvgRestore() must be used to restore the state.
// void nvgSave(NVGcontext* ctx);
emscripten::function("nvgSave", FUNCTION(void, (WrapNVGcontext* wrap), {
nvgSave(wrap->ctx);
}), emscripten::allow_raw_pointers());
// Pops and restores current render state.
// void nvgRestore(NVGcontext* ctx);
emscripten::function("nvgRestore", FUNCTION(void, (WrapNVGcontext* wrap), {
nvgRestore(wrap->ctx);
}), emscripten::allow_raw_pointers());
// Resets current render state to default values. Does not affect the render state stack.
// void nvgReset(NVGcontext* ctx);
emscripten::function("nvgReset", FUNCTION(void, (WrapNVGcontext* wrap), {
nvgReset(wrap->ctx);
}), emscripten::allow_raw_pointers());
//
// Render styles
//
// Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern.
// Solid color is simply defined as a color value, different kinds of paints can be created
// using nvgLinearGradient(), nvgBoxGradient(), nvgRadialGradient() and nvgImagePattern().
//
// Current render style can be saved and restored using nvgSave() and nvgRestore().
// Sets whether to draw antialias for nvgStroke() and nvgFill(). It's enabled by default.
// void nvgShapeAntiAlias(NVGcontext* ctx, int enabled);
emscripten::function("nvgShapeAntiAlias", FUNCTION(void, (WrapNVGcontext* wrap, int enabled), {
nvgShapeAntiAlias(wrap->ctx, enabled);
}), emscripten::allow_raw_pointers());
// Sets current stroke style to a solid color.
// void nvgStrokeColor(NVGcontext* ctx, NVGcolor color);
emscripten::function("nvgStrokeColor", FUNCTION(void, (WrapNVGcontext* wrap, emscripten::val color), {
nvgStrokeColor(wrap->ctx, import_NVGcolor(color));
}), emscripten::allow_raw_pointers());
// Sets current stroke style to a paint, which can be a one of the gradients or a pattern.
// void nvgStrokePaint(NVGcontext* ctx, NVGpaint paint);
emscripten::function("nvgStrokePaint", FUNCTION(void, (WrapNVGcontext* wrap, emscripten::val paint), {
nvgStrokePaint(wrap->ctx, import_NVGpaint(paint));
}), emscripten::allow_raw_pointers());
// Sets current fill style to a solid color.
// void nvgFillColor(NVGcontext* ctx, NVGcolor color);
emscripten::function("nvgFillColor", FUNCTION(void, (WrapNVGcontext* wrap, emscripten::val color), {
nvgFillColor(wrap->ctx, import_NVGcolor(color));
}), emscripten::allow_raw_pointers());
// Sets current fill style to a paint, which can be a one of the gradients or a pattern.
// void nvgFillPaint(NVGcontext* ctx, NVGpaint paint);
emscripten::function("nvgFillPaint", FUNCTION(void, (WrapNVGcontext* wrap, emscripten::val paint), {
nvgFillPaint(wrap->ctx, import_NVGpaint(paint));
}), emscripten::allow_raw_pointers());
// Sets the miter limit of the stroke style.
// Miter limit controls when a sharp corner is beveled.
// void nvgMiterLimit(NVGcontext* ctx, float limit);
emscripten::function("nvgMiterLimit", FUNCTION(void, (WrapNVGcontext* wrap, float limit), {
nvgMiterLimit(wrap->ctx, limit);
}), emscripten::allow_raw_pointers());
// Sets the stroke width of the stroke style.
// void nvgStrokeWidth(NVGcontext* ctx, float size);
emscripten::function("nvgStrokeWidth", FUNCTION(void, (WrapNVGcontext* wrap, float size), {
nvgStrokeWidth(wrap->ctx, size);
}), emscripten::allow_raw_pointers());
// Sets how the end of the line (cap) is drawn,
// Can be one of: NVG_BUTT (default), NVG_ROUND, NVG_SQUARE.
// void nvgLineCap(NVGcontext* ctx, int cap);
emscripten::function("nvgLineCap", FUNCTION(void, (WrapNVGcontext* wrap, int cap), {
nvgLineCap(wrap->ctx, cap);
}), emscripten::allow_raw_pointers());
// Sets how sharp path corners are drawn.
// Can be one of NVG_MITER (default), NVG_ROUND, NVG_BEVEL.
// void nvgLineJoin(NVGcontext* ctx, int join);
emscripten::function("nvgLineJoin", FUNCTION(void, (WrapNVGcontext* wrap, int join), {
nvgLineJoin(wrap->ctx, join);
}), emscripten::allow_raw_pointers());
// Sets the transparency applied to all rendered shapes.
// Already transparent paths will get proportionally more transparent as well.
// void nvgGlobalAlpha(NVGcontext* ctx, float alpha);
emscripten::function("nvgGlobalAlpha", FUNCTION(void, (WrapNVGcontext* wrap, float alpha), {
nvgGlobalAlpha(wrap->ctx, alpha);
}), emscripten::allow_raw_pointers());
//
// Transforms
//
// The paths, gradients, patterns and scissor region are transformed by an transformation
// matrix at the time when they are passed to the API.
// The current transformation matrix is a affine matrix:
// [sx kx tx]
// [ky sy ty]
// [ 0 0 1]
// Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation.
// The last row is assumed to be 0,0,1 and is not stored.
//
// Apart from nvgResetTransform(), each transformation function first creates
// specific transformation matrix and pre-multiplies the current transformation by it.
//
// Current coordinate system (transformation) can be saved and restored using nvgSave() and nvgRestore().
// Resets current transform to a identity matrix.
// void nvgResetTransform(NVGcontext* ctx);
emscripten::function("nvgResetTransform", FUNCTION(void, (WrapNVGcontext* wrap), {
nvgResetTransform(wrap->ctx);
}), emscripten::allow_raw_pointers());
// Premultiplies current coordinate system by specified matrix.
// The parameters are interpreted as matrix as follows:
// [a c e]
// [b d f]
// [0 0 1]
// void nvgTransform(NVGcontext* ctx, float a, float b, float c, float d, float e, float f);
emscripten::function("nvgTransform", FUNCTION(void, (WrapNVGcontext* wrap, float a, float b, float c, float d, float e, float f), {
nvgTransform(wrap->ctx, a, b, c, d, e, f);
}), emscripten::allow_raw_pointers());
// Translates current coordinate system.
// void nvgTranslate(NVGcontext* ctx, float x, float y);
emscripten::function("nvgTranslate", FUNCTION(void, (WrapNVGcontext* wrap, float x, float y), {
nvgTranslate(wrap->ctx, x, y);
}), emscripten::allow_raw_pointers());
// Rotates current coordinate system. Angle is specified in radians.
// void nvgRotate(NVGcontext* ctx, float angle);
emscripten::function("nvgRotate", FUNCTION(void, (WrapNVGcontext* wrap, float angle), {
nvgRotate(wrap->ctx, angle);
}), emscripten::allow_raw_pointers());
// Skews the current coordinate system along X axis. Angle is specified in radians.
// void nvgSkewX(NVGcontext* ctx, float angle);
emscripten::function("nvgSkewX", FUNCTION(void, (WrapNVGcontext* wrap, float angle), {
nvgSkewX(wrap->ctx, angle);