-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnanovg_command_buffer.hpp
1422 lines (1279 loc) · 58.9 KB
/
nanovg_command_buffer.hpp
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
#ifndef NANOVG_COMMAND_BUFFER_HPP
#define NANOVG_COMMAND_BUFFER_HPP
#include <cstdint>
#ifndef NCBH_STRING
#include <string>
#define NCBH_STRING std::string
#endif
#ifndef NCBH_VECTOR
#include <vector>
#define NCBH_VECTOR std::vector
#endif
#ifndef NCBH_PAGEQUEUE
#define NCBH_PAGEQUEUE NCBH_VECTOR
#ifndef NCBH_PAGEQUEUE_RANDOM_ACCESS
#define NCBH_PAGEQUEUE_RANDOM_ACCESS 1
#endif
#else
#ifndef NCBH_PAGEQUEUE_RANDOM_ACCESS
#define NCBH_PAGEQUEUE_RANDOM_ACCESS 0
#endif
#endif
#ifndef NCBH_BACKEND_IS_VG_RENDERER
#define NCBH_BACKEND_IS_VG_RENDERER 1
#endif
#ifndef NANOVG_BACKEND
#define NANOVG_BACKEND 1
#endif
#ifndef VGRENDERER_BACKEND
#define VGRENDERER_BACKEND 0
#endif
#ifndef NCBH_ABORT
#define NCBH_ABORT abort();
#endif
struct sttfont_formatted_text;
struct sttfont_format;
class NanoVgCommandBufferCustomCallbackI;
namespace vg {
struct Context;
struct GradientHandle;
}
struct NVGcontext;
struct NCB_Constants {
static constexpr int32_t NCB_unknown = 0;
// composite
static constexpr int32_t NCB_nvgGlobalCompositeOperation = 1;
static constexpr int32_t NCB_nvgGlobalCompositeBlendFunc = 2;
static constexpr int32_t NCB_nvgGlobalCompositeBlendFuncSeparate = 3;
// state
static constexpr int32_t NCB_nvgSave = 4;
static constexpr int32_t NCB_nvgRestore = 5;
static constexpr int32_t NCB_nvgReset = 6;
// style
static constexpr int32_t NCB_nvgShapeAntiAlias = 7;
static constexpr int32_t NCB_nvgStrokeColor = 8;
static constexpr int32_t NCB_nvgStrokePaint = 9;
static constexpr int32_t NCB_nvgFillColor = 10;
static constexpr int32_t NCB_nvgFillPaint = 11;
static constexpr int32_t NCB_nvgMiterLimit = 12;
static constexpr int32_t NCB_nvgStrokeWidth = 13;
static constexpr int32_t NCB_nvgLineCap = 14;
static constexpr int32_t NCB_nvgLineJoin = 15;
static constexpr int32_t NCB_nvgGlobalAlpha = 16;
// transform
static constexpr int32_t NCB_nvgResetTransform = 17;
static constexpr int32_t NCB_nvgTransform = 18;
static constexpr int32_t NCB_nvgTranslate = 19;
static constexpr int32_t NCB_nvgRotate = 49;
static constexpr int32_t NCB_nvgSkewX = 20;
static constexpr int32_t NCB_nvgSkewY = 21;
static constexpr int32_t NCB_nvgScale = 22;
// scissor
static constexpr int32_t NCB_nvgScissor = 23;
static constexpr int32_t NCB_nvgIntersectScissor = 24;
static constexpr int32_t NCB_nvgResetScissor = 25;
// path
static constexpr int32_t NCB_nvgBeginPath = 26;
static constexpr int32_t NCB_nvgMoveTo = 27;
static constexpr int32_t NCB_nvgLineTo = 28;
static constexpr int32_t NCB_nvgBezierTo = 29;
static constexpr int32_t NCB_nvgQuadTo = 30;
static constexpr int32_t NCB_nvgArcTo = 31;
static constexpr int32_t NCB_nvgClosePath = 32;
// stroke
static constexpr int32_t NCB_nvgPathWinding = 33;
static constexpr int32_t NCB_nvgArc = 34;
static constexpr int32_t NCB_nvgRect = 35;
static constexpr int32_t NCB_nvgRoundedRect = 36;
static constexpr int32_t NCB_nvgEllipse = 37;
static constexpr int32_t NCB_nvgCircle = 38;
static constexpr int32_t NCB_nvgFill = 39;
static constexpr int32_t NCB_nvgStroke = 40;
// text
static constexpr int32_t NCB_nvgFontSize = 41;
static constexpr int32_t NCB_nvgFontBlur = 42;
static constexpr int32_t NCB_nvgTextLetterSpacing = 43;
static constexpr int32_t NCB_nvgTextLineHeight = 44;
static constexpr int32_t NCB_nvgTextAlign = 45;
static constexpr int32_t NCB_nvgFontFaceId = 46;
static constexpr int32_t NCB_nvgText = 47;
static constexpr int32_t NCB_nvgTextBox = 48;
// gradiant
static constexpr int32_t NCB_nvgLinearGradient = 50;
static constexpr int32_t NCB_nvgBoxGradient = 51;
static constexpr int32_t NCB_nvgRadialGradient = 52;
// break
static constexpr int32_t NCB_pause = 1000;
// sdlStbFont Stuff
static constexpr int32_t SDL_STB_PRODUCER_CONSUMER_drawText = 1001;
static constexpr int32_t SDL_STB_PRODUCER_CONSUMER_drawPrerendered = 1002;
static constexpr int32_t SDL_STB_PRODUCER_CONSUMER_drawPrerenderedWColorMod = 1003;
static constexpr int32_t SDL_STB_PRODUCER_CONSUMER_drawTextDirectly = 1004;
static constexpr int32_t SSF_BGFX_SET_SCISSOR = 1004;
static constexpr int32_t SSF_BGFX_CLEAR_SCISSOR = 1005;
// custom engine stuff
};
struct NCBColor {
float r,g,b,a;
inline NCBColor() {}
inline NCBColor(const float _r, const float _g, const float _b, const float _a) : r(_r), g(_g), b(_b), a(_a) {}
#if NANOVG_BACKEND
inline NVGcolor toNVGcolor() const {
return ::nvgRGBAf(r,g,b,a);
}
#endif // NANOVG_BACKEND
#if VGRENDERER_BACKEND
inline vg::Color toVgColor() const {
return vg::color4f(r,g,b,a);
}
#endif // NANOVG_BACKEND
};
struct NCBGradientGenerator {
static constexpr int MODE_LINEAR_GRADIENT = 1;
static constexpr int MODE_BOX_GRADIENT = 2;
static constexpr int MODE_RADIAL_GRADIENT = 3;
int type;
float params[6];
NCBColor icol;
NCBColor ocol;
};
struct nvgw {
// For sttr registering with a namespace
inline static NCBColor nvgRGB(unsigned char r, unsigned char g, unsigned char b) {
return NCBColor(r/255.0,g/255.0,b/255.0,1.0f);
}
inline static NCBColor nvgRGBf(float r, float g, float b) {
return NCBColor(r, g, b, 1.0);
}
inline static NCBColor nvgRGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a) {
return NCBColor(r/255.0, g/255.0, b/255.0, a/255.0);
}
inline static NCBColor nvgRGBAf(float r, float g, float b, float a) {
return NCBColor(r, g, b, a);
}
inline static NCBColor nvgLerpRGBA(const NCBColor& c0, const NCBColor& c1, float u) {
const float um = 1.0f - u;
return NCBColor(c0.r*um + c1.r*u, c0.g*um + c1.g*u, c0.b*um + c1.b*u, c0.a*um + c1.a*u);
}
inline static NCBColor nvgTransRGBA(const NCBColor& c0, unsigned char a) {
return NCBColor(c0.r, c0.g, c0.b, a/255.0);
}
inline static NCBColor nvgTransRGBAf(const NCBColor& c0, float a) {
return NCBColor(c0.r, c0.g, c0.b, a);
}
static NCBColor nvgHSLA_worker(float h, float s, float l, unsigned char a);
inline static NCBColor nvgHSLA(float h, float s, float l, unsigned char a) {
return nvgHSLA_worker(h, s, l, a);
}
inline static NCBColor nvgHSL(float h, float s, float l) {
return nvgHSLA_worker(h, s, l, 255);
}
#if VGRENDERER_BACKEND
// no AA
static constexpr uint32_t VgStrokeFlag_ButtMiter = vg::StrokeFlags::ButtMiter;
static constexpr uint32_t VgStrokeFlag_ButtRound = vg::StrokeFlags::ButtRound;
static constexpr uint32_t VgStrokeFlag_ButtBevel = vg::StrokeFlags::ButtBevel;
static constexpr uint32_t VgStrokeFlag_RoundMiter = vg::StrokeFlags::RoundMiter;
static constexpr uint32_t VgStrokeFlag_RoundRound = vg::StrokeFlags::RoundRound;
static constexpr uint32_t VgStrokeFlag_RoundBevel = vg::StrokeFlags::RoundBevel;
static constexpr uint32_t VgStrokeFlag_SquareMiter = vg::StrokeFlags::SquareMiter;
static constexpr uint32_t VgStrokeFlag_SquareRound = vg::StrokeFlags::SquareRound;
static constexpr uint32_t VgStrokeFlag_SquareBevel = vg::StrokeFlags::SquareBevel;
// w/ AA
static constexpr uint32_t VgStrokeFlag_ButtMiterAA = vg::StrokeFlags::ButtMiterAA;
static constexpr uint32_t VgStrokeFlag_ButtRoundAA = vg::StrokeFlags::ButtRoundAA;
static constexpr uint32_t VgStrokeFlag_ButtBevelAA = vg::StrokeFlags::ButtBevelAA;
static constexpr uint32_t VgStrokeFlag_RoundMiterAA = vg::StrokeFlags::RoundMiterAA;
static constexpr uint32_t VgStrokeFlag_RoundRoundAA = vg::StrokeFlags::RoundRoundAA;
static constexpr uint32_t VgStrokeFlag_RoundBevelAA = vg::StrokeFlags::RoundBevelAA;
static constexpr uint32_t VgStrokeFlag_SquareMiterAA = vg::StrokeFlags::SquareMiterAA;
static constexpr uint32_t VgStrokeFlag_SquareRoundAA = vg::StrokeFlags::SquareRoundAA;
static constexpr uint32_t VgStrokeFlag_SquareBevelAA = vg::StrokeFlags::SquareBevelAA;
#endif
};
struct ncb_error_handler {
static void error(const char * msg) {
NCBH_ABORT;
}
static void not_found(const char* msg) {
NCBH_ABORT;
}
};
#ifdef SDL_STB_PRODUCER_CONSUMER
#if VGRENDERER_BACKEND
struct VgRendererSSFCustomCallbackWrapper {
struct textCallback {
int commandId;
int lastCommandId;
int nextCommandId;
int textId;
int x,y;
uint8_t r,g,b,a;
};
static void vgCustomCallback(vg::Context* ctx, void* usrPtr, const uint32_t a, const uint32_t b);
};
#endif // VGRENDERER_BACKEND
#endif // SDL_STB_PRODUCER_CONSUMER
class NanoVgCommandBuffer {
public:
struct dispatchState {
int32_t lastCommandId;
int32_t nextCommandId;
int aaEnabled; // 1 = on, 0 = off
int activePaintOrGradiantId; // -1 = disabled
NCBColor activeColour;
float strokeWidth;
int strokeFlags;
inline void initToZero() {
lastCommandId = NCB_Constants::NCB_unknown;;
nextCommandId = NCB_Constants::NCB_unknown;;
aaEnabled = 1;
activePaintOrGradiantId = -1;
activeColour = NCBColor(1.f, 1.f, 1.f, 1.f);
strokeWidth = 1.f;
strokeFlags = nvgw::VgStrokeFlag_ButtMiterAA;
}
};
struct command
{
int32_t functionIdx;
union
{
float (argsFloats) [7];
int32_t (argsInts) [7];
} data;
inline command () {}
inline command (const int32_t _id) : functionIdx(_id) {}
inline explicit command (const int32_t _id, const float f0) : functionIdx(_id) { data.argsFloats[0] = f0; }
inline explicit command (const int32_t _id, const float f0, const float f1) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2, const float f3) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; data.argsFloats[3] = f3; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2, const float f3, const float f4) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; data.argsFloats[3] = f3; data.argsFloats[4] = f4; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2, const float f3, const float f4, const float f5) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; data.argsFloats[3] = f3; data.argsFloats[4] = f4; data.argsFloats[5] = f5; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2, const float f3, const float f4, const int i5) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; data.argsFloats[3] = f3; data.argsFloats[4] = f4; data.argsInts[5] = i5; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2, const float f3, const int i4) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; data.argsFloats[3] = f3; data.argsInts[4] = i4; }
inline explicit command (const int32_t _id, const int i0) : functionIdx(_id) { data.argsInts[0] = i0; }
inline explicit command (const int32_t _id, const int i0, const float f1, const int i2) : functionIdx(_id) { data.argsInts[0] = i0; data.argsFloats[1] = f1; data.argsInts[2] = i2; }
inline explicit command (const int32_t _id, const int i0, const int i1) : functionIdx(_id) { data.argsInts[0] = i0; data.argsInts[1] = i1; }
inline explicit command (const int32_t _id, const int i0, const int i1, const int i2) : functionIdx(_id) { data.argsInts[0] = i0; data.argsInts[1] = i1; data.argsInts[2] = i2; }
inline explicit command (const int32_t _id, const int i0, const int i1, const int i2, const int i3) : functionIdx(_id) { data.argsInts[0] = i0; data.argsInts[1] = i1; data.argsInts[2] = i2; data.argsInts[3] = i3; }
inline explicit command (const int32_t _id, const int i0, const int i1, const int i2, const int i3, const int i4) : functionIdx(_id) { data.argsInts[0] = i0; data.argsInts[1] = i1; data.argsInts[2] = i2; data.argsInts[3] = i3; data.argsInts[4] = i4; }
inline explicit command (const int32_t _id, const int i0, const int i1, const int i2, const int i3, const int i4, const int i5) : functionIdx(_id) { data.argsInts[0] = i0; data.argsInts[1] = i1; data.argsInts[2] = i2; data.argsInts[3] = i3; data.argsInts[4] = i4; data.argsInts[5] = i5; }
inline explicit command (const int32_t _id, const int i0, const int i1, const int i2, const int i3, const int i4, const int i5, const int i6) : functionIdx(_id) { data.argsInts[0] = i0; data.argsInts[1] = i1; data.argsInts[2] = i2; data.argsInts[3] = i3; data.argsInts[4] = i4; data.argsInts[5] = i5; data.argsInts[6] = i6; }
inline explicit command (const int32_t _id, const float f0, const float f1, const int i2) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsInts[2] = i2; }
inline explicit command (const int32_t _id, const float f0, const float f1, const float f2, const int i3) : functionIdx(_id) { data.argsFloats[0] = f0; data.argsFloats[1] = f1; data.argsFloats[2] = f2; data.argsInts[3] = i3; }
};
// TBD - with std-stll integration supply a disposable bump allocator instead of this stuff
// this is not really a hotspot for allocations - its just a few reallocs per frame
NCBH_PAGEQUEUE <NanoVgCommandBuffer::command> mCommands;
NCBH_VECTOR <NCBGradientGenerator> mGradientGenerators;
NCBH_VECTOR <NCBH_STRING> mStrings;
#if VGRENDERER_BACKEND
NCBH_VECTOR <vg::GradientHandle> mGradients;
#endif
#if NANOVG_BACKEND
NCBH_VECTOR <NVGpaint> mPaints;
#endif
#ifdef SDL_STB_PRODUCER_CONSUMER
producer_consumer_font_cache* m_producer_consumer_font_cache;
#if VGRENDERER_BACKEND
NCBH_VECTOR <VgRendererSSFCustomCallbackWrapper::textCallback> mTextCallbacks;
#endif
#endif
NanoVgCommandBufferCustomCallbackI* customCommandHandler;
int pauseCode;
int instructionCounter;
protected:
int addPaintGenerator (NCBGradientGenerator const & paint);
int addString (char const * string, char const * end);
public:
NanoVgCommandBuffer();
void swap (NanoVgCommandBuffer & other);
void clear ();
void dispatchSingle (NVGcontext * ctx, vg::Context * vgCtx, NanoVgCommandBuffer::command const & c, NanoVgCommandBuffer::dispatchState & mDispatchState);
inline void dispatchSingle (NVGcontext * ctx, vg::Context * vgCtx, NanoVgCommandBuffer::command const & c) { dispatchState s; s.initToZero(); dispatchSingle(ctx, vgCtx, c, s); }
void dispatch (NVGcontext * ctx);
void dispatchVg (vg::Context * ctx);
protected:
void dispatch_worker (NVGcontext * ctx, vg::Context * vgCtx);
public:
static void sttr_register();
// Pauses rendering and sets this->pauseCode to _pauseCode
inline void pause(int _pauseCode) {
mCommands.push_back(command(NCB_Constants::NCB_pause, _pauseCode));
}
// nvg composite
inline void nvgGlobalCompositeOperation(int op) {
mCommands.push_back(command(NCB_Constants::NCB_nvgGlobalCompositeOperation, op));
}
inline void nvgGlobalCompositeBlendFunc(int sfactor, int dfactor) {
mCommands.push_back(command(NCB_Constants::NCB_nvgGlobalCompositeBlendFunc, sfactor, dfactor));
}
inline void nvgGlobalCompositeBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
mCommands.push_back(command(NCB_Constants::NCB_nvgGlobalCompositeBlendFuncSeparate, srcRGB, dstRGB, srcAlpha, dstAlpha));
}
// nvg state
inline void nvgSave() {
mCommands.push_back(command(NCB_Constants::NCB_nvgSave));
}
inline void nvgRestore() {
mCommands.push_back(command(NCB_Constants::NCB_nvgRestore));
}
inline void nvgReset() {
mCommands.push_back(command(NCB_Constants::NCB_nvgReset));
}
// nvg styles
inline void nvgShapeAntiAlias(int enabled) {
mCommands.push_back(command(NCB_Constants::NCB_nvgShapeAntiAlias, enabled));
}
inline void nvgStrokeColor(const NCBColor& color, const int vgStrokeFlags) {
// note that vg* only has effect with vgrenderer backend
mCommands.push_back(command(NCB_Constants::NCB_nvgStrokeColor, color.r, color.g, color.b, color.a, vgStrokeFlags));
}
inline void nvgStrokePaint(int paintIdx, const int vgStrokeFlags) {
// note that vg* only has effect with vgrenderer backend
mCommands.push_back(command(NCB_Constants::NCB_nvgStrokePaint, paintIdx, vgStrokeFlags));
}
//inline void nvgStrokePaint(const NCBGradientGenerator & constructionInfo) {
// int idx = addPaintGenerator(constructionInfo);
// mCommands.push_back(command(NCB_Constants::NCB_nvgStrokePaint, idx));
// }
inline void nvgFillColor(const NCBColor& color) {
mCommands.push_back(command(NCB_Constants::NCB_nvgFillColor, color.r, color.g, color.b, color.a));
}
//inline void nvgFillPaint(const NCBGradientGenerator & constructionInfo) {
// int idx = addPaintGenerator(constructionInfo);
// mCommands.push_back(command(NCB_Constants::NCB_nvgFillPaint, idx));
// }
inline void nvgFillPaint(int paintIdx) {
mCommands.push_back(command(NCB_Constants::NCB_nvgFillPaint, paintIdx));
}
inline void nvgMiterLimit(float limit) {
mCommands.push_back(command(NCB_Constants::NCB_nvgMiterLimit, limit));
}
inline void nvgStrokeWidth(float size) {
mCommands.push_back(command(NCB_Constants::NCB_nvgStrokeWidth, size));
}
inline void nvgLineCap(int cap) {
mCommands.push_back(command(NCB_Constants::NCB_nvgLineCap, cap));
}
inline void nvgLineJoin(int join) {
mCommands.push_back(command(NCB_Constants::NCB_nvgLineJoin, join));
}
inline void nvgGlobalAlpha(float alpha) {
mCommands.push_back(command(NCB_Constants::NCB_nvgGlobalAlpha, alpha));
}
// nvg transforms
inline void nvgResetTransform() {
mCommands.push_back(command(NCB_Constants::NCB_nvgResetTransform));
}
inline void nvgTransform(float a, float b, float c, float d, float e, float f) {
mCommands.push_back(command(NCB_Constants::NCB_nvgTransform, a, b, c, d, e, f));
}
inline void nvgTranslate(float x, float y) {
mCommands.push_back(command(NCB_Constants::NCB_nvgTranslate, x, y));
}
inline void nvgRotate(float angle) {
mCommands.push_back(command(NCB_Constants::NCB_nvgRotate, angle));
}
inline void nvgSkewX(float angle) {
mCommands.push_back(command(NCB_Constants::NCB_nvgSkewX, angle));
}
inline void nvgSkewY(float angle) {
mCommands.push_back(command(NCB_Constants::NCB_nvgSkewY, angle));
}
inline void nvgScale(float x, float y) {
mCommands.push_back(command(NCB_Constants::NCB_nvgScale, x, y));
}
// nvg scissor
inline void nvgScissor(float x, float y, float w, float h) {
mCommands.push_back(command(NCB_Constants::NCB_nvgScissor, x, y, w, h));
}
inline void nvgIntersectScissor(float x, float y, float w, float h) {
mCommands.push_back(command(NCB_Constants::NCB_nvgIntersectScissor, x, y, w, h));
}
inline void nvgResetScissor() {
mCommands.push_back(command(NCB_Constants::NCB_nvgResetScissor));
}
// nvg path
inline void nvgBeginPath() {
mCommands.push_back(command(NCB_Constants::NCB_nvgBeginPath));
}
inline void nvgMoveTo(float x, float y) {
mCommands.push_back(command(NCB_Constants::NCB_nvgMoveTo, x, y));
}
inline void nvgLineTo(float x, float y) {
mCommands.push_back(command(NCB_Constants::NCB_nvgLineTo, x, y));
}
inline void nvgBezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y) {
mCommands.push_back(command(NCB_Constants::NCB_nvgBezierTo, c1x, c1y, c2x, c2y, x, y));
}
inline void nvgQuadTo(float cx, float cy, float x, float y) {
mCommands.push_back(command(NCB_Constants::NCB_nvgQuadTo, cx, cy, x, y));
}
inline void nvgArcTo(float cx, float cy, float x, float y, float radius) {
mCommands.push_back(command(NCB_Constants::NCB_nvgArcTo, cx, cy, x, y, radius));
}
inline void nvgClosePath() {
mCommands.push_back(command(NCB_Constants::NCB_nvgClosePath));
}
inline void nvgPathWinding(int dir) {
mCommands.push_back(command(NCB_Constants::NCB_nvgPathWinding, dir));
}
inline void nvgArc(float cx, float cy, float r, float a0, float a1, int dir) {
mCommands.push_back(command(NCB_Constants::NCB_nvgArc, cx, cy, r, a0, a1, dir));
}
inline void nvgRect(float x, float y, float w, float h) {
mCommands.push_back(command(NCB_Constants::NCB_nvgRect, x, y, w, h));
}
inline void nvgRoundedRect(float x, float y, float w, float h, float r) {
mCommands.push_back(command(NCB_Constants::NCB_nvgRoundedRect, x, y, w, h, r));
}
//inline void nvgRoundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft) {
// abort();
// }
inline void nvgEllipse(float cx, float cy, float rx, float ry) {
mCommands.push_back(command(NCB_Constants::NCB_nvgEllipse, cx, cy, rx, ry));
}
inline void nvgCircle(float cx, float cy, float r) {
mCommands.push_back(command(NCB_Constants::NCB_nvgEllipse, cx, cy, r));
}
inline void nvgFill() {
mCommands.push_back(command(NCB_Constants::NCB_nvgFill));
}
inline void nvgStroke() {
mCommands.push_back(command(NCB_Constants::NCB_nvgStroke));
}
// text
inline void nvgFontSize(float size) {
mCommands.push_back(command(NCB_Constants::NCB_nvgFontSize, size));
}
inline void nvgFontBlur(float blur) {
mCommands.push_back(command(NCB_Constants::NCB_nvgFontBlur, blur));
}
inline void nvgTextLetterSpacing(float spacing) {
mCommands.push_back(command(NCB_Constants::NCB_nvgTextLetterSpacing, spacing));
}
inline void nvgTextLineHeight(float lineHeight) {
mCommands.push_back(command(NCB_Constants::NCB_nvgTextLineHeight, lineHeight));
}
inline void nvgTextAlign(int align) {
mCommands.push_back(command(NCB_Constants::NCB_nvgTextAlign, align));
}
inline void nvgFontFaceId(int font) {
mCommands.push_back(command(NCB_Constants::NCB_nvgFontFaceId, font));
}
//void nvgFontFace(const char* font) { // Don't use this, use nvgFontFaceId instead
// mCommands.push_back(command(NCB_Constants::NCB_nvgFontFace, font));
// }
inline void nvgText(float x, float y, const char* string, const char* end) {
int idx = addString(string, end);
mCommands.push_back(command(NCB_Constants::NCB_nvgText, x, y, idx));
}
inline void nvgTextBox(float x, float y, float breakRowWidth, const char* string, const char* end) {
int idx = addString(string, end);
mCommands.push_back(command(NCB_Constants::NCB_nvgTextBox, x, y, breakRowWidth, idx));
}
int nvgLinearGradient(float sx, float sy, float ex, float ey, const NCBColor& icol, const NCBColor& ocol);
int nvgBoxGradient(float x, float y, float w, float h, float r, float f, const NCBColor& icol, const NCBColor& ocol);
int nvgRadialGradient(float cx, float cy, float inr, float outr, const NCBColor& icol, const NCBColor& ocol);
#ifdef SDL_STB_PRODUCER_CONSUMER
// SDL_STB_PRODUCER_CONSUMER_Font functions to be used with producerConsumerFrontend
// https://github.com/SnapperTT/sdl_stb_font
inline void pushSsfText(const int h) {
mCommands.push_back(command(NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText, h));
}
void pushSsfText(const int x, const int y, const NCBH_STRING & s, int* xOut=NULL, int * widthOut=NULL, int* heightOut=NULL);
void pushSsfText(const int x, const int y, const sttfont_formatted_text & s, int* xOut=NULL, int * widthOut=NULL, int* heightOut=NULL);
void pushSsfText(const int x, const int y, const char* c, int* xOut=NULL, int * widthOut=NULL, int* heightOut=NULL);
void pushSsfText(const int x, const int y, const sttfont_format & format, const char* c, int* xOut=NULL, int * widthOut=NULL, int* heightOut=NULL);
void pushSsfText(const int x, const int y, const sttfont_format & format, const NCBH_STRING & s, int* xOut=NULL, int * widthOut=NULL, int* heightOut=NULL);
void pushSsfPrerendered(const int textHandle, const int x, const int y);
void pushSsfPrerenderedWColorMod(const int textHandle, const int x, const int y, const int r, const int g, const int b, const int a);
#endif
#ifdef BGFX
inline void ssfBgfxSetScissor(const float x, const float y, const float w, const float h) {
mCommands.push_back(command(NCB_Constants::SSF_BGFX_SET_SCISSOR, x, y, w, h));
}
inline void ssfBgfxClearScissor() {
mCommands.push_back(command(NCB_Constants::SSF_BGFX_CLEAR_SCISSOR));
}
#endif
inline void push_custom(command&& c) {
mCommands.push_back(std::move(c));
}
inline void push_custom(const command& c) {
mCommands.push_back(c);
}
};
class NanoVgCommandBufferCustomCallbackI {
public:
virtual inline bool handleCustomCallback(NanoVgCommandBuffer * NVG, NVGcontext * ctx, vg::Context * vgCtx, NanoVgCommandBuffer::command const & c) {
return true;
}
};
#endif
#ifdef NANOVG_COMMAND_BUFFER_IMPL
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Start Implementation
NCBColor nvgw::nvgHSLA_worker(float h, float s, float l, unsigned char a) {
float c = (1.0f - fabsf(2.0f * l - 1.0f)) * s; // Chroma
float x = c * (1.0f - fabsf(fmodf(h * 6.0f, 2.0f) - 1.0f));
float m = l - c / 2.0f;
float r1, g1, b1;
if (h < 1.0f / 6.0f) { r1 = c; g1 = x; b1 = 0; }
else if (h < 2.0f / 6.0f) { r1 = x; g1 = c; b1 = 0; }
else if (h < 3.0f / 6.0f) { r1 = 0; g1 = c; b1 = x; }
else if (h < 4.0f / 6.0f) { r1 = 0; g1 = x; b1 = c; }
else if (h < 5.0f / 6.0f) { r1 = x; g1 = 0; b1 = c; }
else { r1 = c; g1 = 0; b1 = x; }
return NCBColor(r1+m, g1+m, b1+m, a/255.0);
}
#ifdef SDL_STB_PRODUCER_CONSUMER
#if VGRENDERER_BACKEND
void VgRendererSSFCustomCallbackWrapper::vgCustomCallback(vg::Context* ctx, void* usrPtr, const uint32_t a, const uint32_t b) {
NanoVgCommandBuffer* NVG = (NanoVgCommandBuffer*) usrPtr;
const textCallback& cb = NVG->mTextCallbacks[a];
producer_consumer_font_cache* pcfc = NVG->m_producer_consumer_font_cache;
//Logger_ldbg("vgCustomCallback: {} {}", cb.commandId, cb.textId);
switch (cb.commandId) {
case NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText:
{
if (cb.lastCommandId != NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText) {
pcfc->consumer_font_cache->onStartDrawing(); // start batched text rendering
}
//Logger_ldbg("dispatch text: {}", cb.textId);
if (cb.commandId == NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText)
pcfc->dispatchSingleText(cb.textId);
//Logger_ldbg("text: {}", pcfc->getConsumerState()->text[cb.textId].text.getString());
if (cb.lastCommandId != NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText) {
pcfc->consumer_font_cache->onCompletedDrawing(); // finish batched text rendering
}
}
return;
case NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawPrerendered:
pcfc->dispatchSinglePrerendered(cb.textId, cb.x, cb.y);
return;
case NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawPrerenderedWColorMod:
pcfc->dispatchSinglePrerenderedWColorMod(cb.textId, cb.x, cb.y, cb.r, cb.g, cb.b, cb.a);
return;
default:
ncb_error_handler::not_found("unknown vgCustomCallback instruction");
return;
}
}
#endif // VGRENDERER_BACKEND
#endif // SDL_STB_PRODUCER_CONSUMER
NanoVgCommandBuffer::NanoVgCommandBuffer() {
#ifdef SDL_STB_PRODUCER_CONSUMER
m_producer_consumer_font_cache = NULL;
#endif
pauseCode = 0;
instructionCounter = 0;
customCommandHandler = NULL;
}
int NanoVgCommandBuffer::addPaintGenerator (NCBGradientGenerator const & paint) {
if (mGradientGenerators.size()) {
// easy out - resusue paint if its the same as previous
int sz = mGradientGenerators.size();
int iBegin = sz - 8; // check the last X paints so that we're not creating duplicates
if (iBegin < 0) iBegin = 0;
for (int i = iBegin; i < sz; ++i)
if (memcmp(&mGradientGenerators[i], &paint, sizeof(NCBGradientGenerator)) == 0)
return i;
}
mGradientGenerators.push_back(paint);
return mGradientGenerators.size() - 1;
}
int NanoVgCommandBuffer::addString (char const * string, char const * end) {
if (!string) return -1;
int sz = mStrings.size();
int iBegin = sz - 8;
if (iBegin < 0) iBegin = 0;
if (end) {
NCBH_STRING str(string, end - string);
for (int i = iBegin; i < sz; ++i)
if (mStrings[i] == str) return i;
mStrings.push_back(str);
}
else {
NCBH_STRING str(string);
for (int i = iBegin; i < sz; ++i)
if (mStrings[i] == str) return i;
mStrings.push_back(str);
}
return mStrings.size() - 1;
}
void NanoVgCommandBuffer::swap (NanoVgCommandBuffer & other) {
mCommands.swap(other.mCommands);
mGradientGenerators.swap(other.mGradientGenerators);
mStrings.swap(other.mStrings);
#if VGRENDERER_BACKEND
mGradients.swap(other.mGradients);
#ifdef SDL_STB_PRODUCER_CONSUMER
mTextCallbacks.swap(other.mTextCallbacks);
#endif
#endif
#if NANOVG_BACKEND
mPaints.swap(other.mPaints);
#endif
}
void NanoVgCommandBuffer::clear () {
mCommands.clear();
mGradientGenerators.clear();
mStrings.clear();
#if VGRENDERER_BACKEND
mGradients.clear();
#ifdef SDL_STB_PRODUCER_CONSUMER
mTextCallbacks.clear();
#endif
#endif
#if NANOVG_BACKEND
mPaints.clear();
#endif
}
void NanoVgCommandBuffer::dispatchSingle (NVGcontext * ctx, vg::Context * vgCtx, NanoVgCommandBuffer::command const & c, NanoVgCommandBuffer::dispatchState & mDispatchState) {
switch (c.functionIdx) {
// break
// used to pause execution
case NCB_Constants::NCB_pause:
pauseCode = c.data.argsInts[0];
instructionCounter = -1;
return;
// nvg composite
#if NANOVG_BACKEND
case NCB_Constants::NCB_nvgGlobalCompositeOperation:
return ::nvgGlobalCompositeOperation(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgGlobalCompositeBlendFunc:
return ::nvgGlobalCompositeBlendFunc(ctx, c.data.argsInts[0], c.data.argsInts[1]);
case NCB_Constants::NCB_nvgGlobalCompositeBlendFuncSeparate:
return ::nvgGlobalCompositeBlendFuncSeparate(ctx, c.data.argsInts[0], c.data.argsInts[1], c.data.argsInts[2], c.data.argsInts[3]);
// nvg state
case NCB_Constants::NCB_nvgSave:
return ::nvgSave(ctx);
case NCB_Constants::NCB_nvgRestore:
return ::nvgRestore(ctx);
case NCB_Constants::NCB_nvgReset:
return ::nvgReset(ctx);
// nvg style
case NCB_Constants::NCB_nvgShapeAntiAlias:
return ::nvgShapeAntiAlias(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgStrokeColor:
return ::nvgStrokeColor(ctx, nvgRGBAf(c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]) );
case NCB_Constants::NCB_nvgStrokePaint:
return ::nvgStrokePaint(ctx, mPaints[c.data.argsInts[0]]);
case NCB_Constants::NCB_nvgFillColor:
return ::nvgFillColor(ctx, nvgRGBAf(c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]) );
case NCB_Constants::NCB_nvgFillPaint:
return ::nvgFillPaint(ctx, mPaints[c.data.argsInts[0]]);
case NCB_Constants::NCB_nvgMiterLimit:
return ::nvgMiterLimit(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgStrokeWidth:
return ::nvgStrokeWidth(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgLineCap:
return ::nvgLineCap(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgLineJoin:
return ::nvgLineJoin(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgGlobalAlpha:
return ::nvgGlobalAlpha(ctx, c.data.argsFloats[0]);
// nvg transform
case NCB_Constants::NCB_nvgResetTransform:
return ::nvgResetTransform(ctx);
case NCB_Constants::NCB_nvgTransform:
return ::nvgTransform(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4], c.data.argsFloats[5]);
case NCB_Constants::NCB_nvgTranslate:
return ::nvgTranslate(ctx, c.data.argsFloats[0], c.data.argsFloats[1]);
case NCB_Constants::NCB_nvgRotate:
return ::nvgRotate(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgSkewX:
return ::nvgSkewX(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgSkewY:
return ::nvgSkewY(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgScale:
return ::nvgScale(ctx, c.data.argsFloats[0], c.data.argsFloats[1]);
// nvg scissor
case NCB_Constants::NCB_nvgScissor:
return ::nvgScissor(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgIntersectScissor:
return ::nvgIntersectScissor(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgResetScissor:
return ::nvgResetScissor(ctx);
// nvg path
case NCB_Constants::NCB_nvgBeginPath:
return ::nvgBeginPath(ctx);
case NCB_Constants::NCB_nvgMoveTo:
return ::nvgMoveTo(ctx, c.data.argsFloats[0], c.data.argsFloats[1]);
case NCB_Constants::NCB_nvgLineTo:
return ::nvgLineTo(ctx, c.data.argsFloats[0], c.data.argsFloats[1]);
case NCB_Constants::NCB_nvgBezierTo:
return ::nvgBezierTo(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4], c.data.argsFloats[5]);
case NCB_Constants::NCB_nvgQuadTo:
return ::nvgQuadTo(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgArcTo:
return ::nvgArcTo(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4]);
case NCB_Constants::NCB_nvgClosePath:
return ::nvgClosePath(ctx);
case NCB_Constants::NCB_nvgPathWinding:
return ::nvgPathWinding(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgArc:
return ::nvgArc(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4], c.data.argsInts[5]);
case NCB_Constants::NCB_nvgRect:
return ::nvgRect(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgRoundedRect:
return ::nvgRoundedRect(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4]);
//case NCB_Constants::NCB_nvgRoundedRectVarying:
// abort(); // to many args, unused
case NCB_Constants::NCB_nvgEllipse:
return ::nvgEllipse(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgCircle:
return ::nvgCircle(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2]);
case NCB_Constants::NCB_nvgFill:
return ::nvgFill(ctx);
case NCB_Constants::NCB_nvgStroke:
return ::nvgStroke(ctx);
// text
case NCB_Constants::NCB_nvgFontSize:
return ::nvgFontSize(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgFontBlur:
return ::nvgFontBlur(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgTextLetterSpacing:
return ::nvgTextLetterSpacing(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgTextLineHeight:
return ::nvgTextLineHeight(ctx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgTextAlign:
return ::nvgTextLineHeight(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgFontFaceId:
return ::nvgFontFaceId(ctx, c.data.argsInts[0]);
case NCB_Constants::NCB_nvgText:
{
const NCBH_STRING & str = c.data.argsInts[2] >= 0 ? mStrings[c.data.argsInts[2]].c_str() : NCBH_STRING("");
return (void) ::nvgText(ctx, c.data.argsFloats[0], c.data.argsFloats[1], str.c_str(), NULL);
}
case NCB_Constants::NCB_nvgTextBox:
{
const NCBH_STRING & str = c.data.argsInts[3] >= 0 ? mStrings[c.data.argsInts[3]].c_str() : NCBH_STRING("");
return (void) ::nvgTextBox(ctx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], str.c_str(), NULL);
}
// gradiants
case NCB_Constants::NCB_nvgLinearGradient:
{
unsigned int idx = c.data.argsInts[0];
if (idx < mGradientGenerators.size())
return ncb_error_handler::error("mGradientGenerators array index out of range");
NCBGradientGenerator & G = mGradientGenerators[idx];
NVGpaint GH = ::nvgLinearGradient(ctx, G.params[0], G.params[1], G.params[2], G.params[3], G.icol.toNVGcolor(), G.ocol.toNVGcolor());
mPaints[idx] = GH;
mDispatchState.activePaintOrGradiantId = idx;
}
return;
case NCB_Constants::NCB_nvgBoxGradient:
{
unsigned int idx = c.data.argsInts[0];
if (idx < mGradientGenerators.size())
return ncb_error_handler::error("mGradientGenerators array index out of range");
NCBGradientGenerator & G = mGradientGenerators[idx];
NVGpaint GH = ::nvgBoxGradient(ctx, G.params[0], G.params[1], G.params[2], G.params[3], G.params[4], G.params[5], G.icol.toNVGcolor(), G.ocol.toNVGcolor());
mPaints[idx] = GH;
mDispatchState.activePaintOrGradiantId = idx;
}
return;
case NCB_Constants::NCB_nvgRadialGradient:
{
unsigned int idx = c.data.argsInts[0];
if (idx < mGradientGenerators.size())
return ncb_error_handler::error("mGradientGenerators array index out of range");
NCBGradientGenerator & G = mGradientGenerators[idx];
NVGpaint GH = ::nvgRadialGradient(ctx, G.params[0], G.params[1], G.params[2], G.params[3], G.icol.toNVGcolor(), G.ocol.toNVGcolor());
mPaints[idx] = GH;
mDispatchState.activePaintOrGradiantId = idx;
}
return;
#ifdef SDL_STB_PRODUCER_CONSUMER
case NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText:
if (mDispatchState.lastCommandId != NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText) {
::nvgEndFrame(ctx);
m_producer_consumer_font_cache->consumer_font_cache->onStartDrawing(); // start batched text rendering
}
m_producer_consumer_font_cache->dispatchSingleText(c.data.argsInts[0]);
if (mDispatchState.nextCommandId != NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawText) {
m_producer_consumer_font_cache->consumer_font_cache->onCompletedDrawing(); // finish and draw the batch
}
return;
case NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawPrerendered:
::nvgEndFrame(ctx);
m_producer_consumer_font_cache->dispatchSinglePrerendered(c.data.argsInts[0], c.data.argsInts[1], c.data.argsInts[2]);
return;
case NCB_Constants::SDL_STB_PRODUCER_CONSUMER_drawPrerenderedWColorMod:
::nvgEndFrame(ctx);
m_producer_consumer_font_cache->dispatchSinglePrerenderedWColorMod(c.data.argsInts[0], c.data.argsInts[1], c.data.argsInts[2], c.data.argsInts[3], c.data.argsInts[4], c.data.argsInts[5], c.data.argsInts[6]);
return;
#endif //SDL_STB_PRODUCER_CONSUMER
#endif // NANOVG_BACKEND
#if VGRENDERER_BACKEND
case NCB_Constants::NCB_nvgGlobalCompositeOperation:
return ncb_error_handler::not_found("NCB_nvgGlobalCompositeOperation not defined for vg-renderer");
case NCB_Constants::NCB_nvgGlobalCompositeBlendFunc:
return ncb_error_handler::not_found("NCB_nvgGlobalCompositeBlendFunc not defined for vg-renderer");
case NCB_Constants::NCB_nvgGlobalCompositeBlendFuncSeparate:
return ncb_error_handler::not_found("NCB_nvgGlobalCompositeBlendFuncSeparate not defined for vg-renderer");
// nvg state
case NCB_Constants::NCB_nvgSave:
return vg::pushState(vgCtx);
case NCB_Constants::NCB_nvgRestore:
return vg::popState(vgCtx);
case NCB_Constants::NCB_nvgReset:
return ncb_error_handler::not_found("NCB_nvgReset not defined for vg-renderer");
// nvg style
case NCB_Constants::NCB_nvgShapeAntiAlias:
mDispatchState.aaEnabled = c.data.argsInts[0];
return;
case NCB_Constants::NCB_nvgStrokeColor:
mDispatchState.activeColour = NCBColor(c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
mDispatchState.activePaintOrGradiantId = -1;
return;
case NCB_Constants::NCB_nvgStrokePaint:
mDispatchState.activePaintOrGradiantId = c.data.argsInts[0];
return;
case NCB_Constants::NCB_nvgFillColor:
mDispatchState.activeColour = NCBColor(c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
mDispatchState.activePaintOrGradiantId = -1;
return;
case NCB_Constants::NCB_nvgFillPaint:
mDispatchState.activePaintOrGradiantId = c.data.argsInts[0];
return;
case NCB_Constants::NCB_nvgMiterLimit:
return ncb_error_handler::not_found("NCB_nvgMiterLimit not defined for vg-renderer");
case NCB_Constants::NCB_nvgStrokeWidth:
mDispatchState.strokeWidth = c.data.argsFloats[0];
case NCB_Constants::NCB_nvgLineCap:
return ncb_error_handler::not_found("NCB_nvgLineCap not defined for vg-renderer");
case NCB_Constants::NCB_nvgLineJoin:
return ncb_error_handler::not_found("NCB_nvgLineJoin not defined for vg-renderer");
case NCB_Constants::NCB_nvgGlobalAlpha:
return vg::setGlobalAlpha(vgCtx, c.data.argsFloats[0]);
// nvg transform
case NCB_Constants::NCB_nvgResetTransform:
return vg::transformIdentity(vgCtx);
case NCB_Constants::NCB_nvgTransform:
return vg::transformMult(vgCtx, &c.data.argsFloats[0] , vg::TransformOrder::Pre);
case NCB_Constants::NCB_nvgTranslate:
return vg::transformTranslate(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1]);
case NCB_Constants::NCB_nvgRotate:
return vg::transformRotate(vgCtx, c.data.argsFloats[0]);
case NCB_Constants::NCB_nvgSkewX:
return ncb_error_handler::not_found("NCB_nvgSkewX not defined for vg-renderer");
case NCB_Constants::NCB_nvgSkewY:
return ncb_error_handler::not_found("NCB_nvgSkewY not defined for vg-renderer");
case NCB_Constants::NCB_nvgScale:
return vg::transformScale(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1]);
// nvg scissor
case NCB_Constants::NCB_nvgScissor:
return vg::setScissor(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgIntersectScissor:
return (void) vg::intersectScissor(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgResetScissor:
return vg::resetScissor(vgCtx);
// nvg path
case NCB_Constants::NCB_nvgBeginPath:
return vg::beginPath(vgCtx);
case NCB_Constants::NCB_nvgMoveTo:
return vg::moveTo(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1]);
case NCB_Constants::NCB_nvgLineTo:
return vg::lineTo(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1]);
case NCB_Constants::NCB_nvgBezierTo:
return vg::cubicTo(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4], c.data.argsFloats[5]);
case NCB_Constants::NCB_nvgQuadTo:
return vg::quadraticTo(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3]);
case NCB_Constants::NCB_nvgArcTo:
return vg::arcTo(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4]);
case NCB_Constants::NCB_nvgClosePath:
return vg::closePath(vgCtx);
case NCB_Constants::NCB_nvgPathWinding:
return ncb_error_handler::not_found("NCB_nvgPathWinding not defined for vg-renderer. Just submit everything with CW winding");
case NCB_Constants::NCB_nvgArc:
// direction note: vg:CW/CCW = NVG::CW/CCW - 1
return vg::arc(vgCtx, c.data.argsFloats[0], c.data.argsFloats[1], c.data.argsFloats[2], c.data.argsFloats[3], c.data.argsFloats[4], (c.data.argsInts[5] - 1) ? vg::Winding::CW : vg::Winding::CCW);
case NCB_Constants::NCB_nvgRect: