rays 0.3.11 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/src/painter.cpp CHANGED
@@ -49,7 +49,7 @@ namespace Rays
49
49
  if (!viewport)
50
50
  argument_error(__FILE__, __LINE__);
51
51
 
52
- if (self->painting)
52
+ if (self->is_painting())
53
53
  invalid_state_error(__FILE__, __LINE__, "painting flag should be false.");
54
54
 
55
55
  self->viewport = viewport;
@@ -71,7 +71,7 @@ namespace Rays
71
71
  bool
72
72
  Painter::painting () const
73
73
  {
74
- return self->painting;
74
+ return self->is_painting();
75
75
  }
76
76
 
77
77
  static inline void
@@ -102,7 +102,7 @@ namespace Rays
102
102
  {
103
103
  Painter::Data* self = painter->self.get();
104
104
 
105
- if (!self->painting)
105
+ if (!self->is_painting())
106
106
  invalid_state_error(__FILE__, __LINE__, "painting flag should be true.");
107
107
 
108
108
  if (!self->state.has_color())
@@ -328,19 +328,17 @@ namespace Rays
328
328
  Painter* painter, const Image& image,
329
329
  coord src_x, coord src_y, coord src_w, coord src_h,
330
330
  coord dst_x, coord dst_y, coord dst_w, coord dst_h,
331
- bool nofill, bool nostroke,
332
331
  const Shader* shader)
333
332
  {
334
- static const PrimitiveMode MODES[] = {MODE_TRIANGLE_FAN, MODE_LINE_LOOP};
335
-
336
333
  assert(painter && image);
337
334
 
338
335
  Painter::Data* self = painter->self.get();
339
336
 
340
- if (!self->painting)
337
+ if (!self->is_painting())
341
338
  invalid_state_error(__FILE__, __LINE__, "painting flag should be true.");
342
339
 
343
- if (!self->state.has_color())
340
+ Color color;
341
+ if (!self->state.get_color(&color, FILL))
344
342
  return;
345
343
 
346
344
  const Texture& texture = Image_get_texture(image);
@@ -365,19 +363,9 @@ namespace Rays
365
363
 
366
364
  TextureInfo texinfo(texture, src_x, src_y, src_x + src_w, src_y + src_h);
367
365
 
368
- Color color;
369
- for (int type = 0; type < COLOR_TYPE_MAX; ++type)
370
- {
371
- if ((nofill && type == FILL) || (nostroke && type == STROKE))
372
- continue;
373
-
374
- if (!painter->self->state.get_color(&color, (ColorType) type))
375
- continue;
376
-
377
- Painter_draw(
378
- painter, MODES[type], &color, points, 4, NULL, 0, NULL, texcoords,
379
- &texinfo, shader);
380
- }
366
+ Painter_draw(
367
+ painter, MODE_TRIANGLE_FAN, &color, points, 4, NULL, 0, NULL, texcoords,
368
+ &texinfo, shader);
381
369
  }
382
370
 
383
371
  void
@@ -477,7 +465,7 @@ namespace Rays
477
465
 
478
466
  Painter::Data* self = painter->self.get();
479
467
 
480
- if (!self->painting)
468
+ if (!self->is_painting())
481
469
  invalid_state_error(__FILE__, __LINE__, "painting flag should be true.");
482
470
 
483
471
  if (!self->state.has_color())
@@ -489,7 +477,7 @@ namespace Rays
489
477
  {
490
478
  coord line_height = painter->line_height();
491
479
 
492
- Xot::StringList lines;
480
+ StringList lines;
493
481
  split(&lines, str, '\n');
494
482
  for (const auto& line : lines)
495
483
  {
@@ -553,7 +541,7 @@ namespace Rays
553
541
  {
554
542
  self->state.background = color;
555
543
 
556
- if (self->painting && clear) this->clear();
544
+ if (self->is_painting() && clear) this->clear();
557
545
  }
558
546
 
559
547
  void
@@ -710,6 +698,15 @@ namespace Rays
710
698
  return height;
711
699
  }
712
700
 
701
+ void
702
+ Painter::set_blend_mode (BlendMode mode)
703
+ {
704
+ if (self->state.blend_mode == mode) return;
705
+
706
+ self->state.blend_mode = mode;
707
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
708
+ }
709
+
713
710
  BlendMode
714
711
  Painter::blend_mode () const
715
712
  {
@@ -725,8 +722,11 @@ namespace Rays
725
722
  void
726
723
  Painter::set_clip (const Bounds& bounds)
727
724
  {
725
+ if (bounds == self->state.clip)
726
+ return;
727
+
728
728
  self->state.clip = bounds;
729
- Painter_update_clip(this);
729
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
730
730
  }
731
731
 
732
732
  void
@@ -773,13 +773,20 @@ namespace Rays
773
773
  void
774
774
  Painter::set_texture (const Image& image)
775
775
  {
776
+ if (image == self->state.texture)
777
+ return;
778
+
776
779
  self->state.texture = image;
780
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
777
781
  }
778
782
 
779
783
  void
780
784
  Painter::no_texture ()
781
785
  {
786
+ if (!self->state.texture) return;
787
+
782
788
  self->state.texture = Image();
789
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
783
790
  }
784
791
 
785
792
  const Image&
@@ -791,7 +798,11 @@ namespace Rays
791
798
  void
792
799
  Painter::set_texcoord_mode (TexCoordMode mode)
793
800
  {
801
+ if (mode == self->state.texcoord_mode)
802
+ return;
803
+
794
804
  self->state.texcoord_mode = mode;
805
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
795
806
  }
796
807
 
797
808
  TexCoordMode
@@ -803,7 +814,11 @@ namespace Rays
803
814
  void
804
815
  Painter::set_texcoord_wrap (TexCoordWrap wrap)
805
816
  {
817
+ if (wrap == self->state.texcoord_wrap)
818
+ return;
819
+
806
820
  self->state.texcoord_wrap = wrap;
821
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
807
822
  }
808
823
 
809
824
  TexCoordWrap
@@ -815,13 +830,20 @@ namespace Rays
815
830
  void
816
831
  Painter::set_shader (const Shader& shader)
817
832
  {
833
+ if (shader == self->state.shader)
834
+ return;
835
+
818
836
  self->state.shader = shader;
837
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
819
838
  }
820
839
 
821
840
  void
822
841
  Painter::no_shader ()
823
842
  {
843
+ if (!self->state.shader) return;
844
+
824
845
  self->state.shader = Shader();
846
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
825
847
  }
826
848
 
827
849
  const Shader&
@@ -844,7 +866,7 @@ namespace Rays
844
866
 
845
867
  self->state = self->state_stack.back();
846
868
  self->state_stack.pop_back();
847
- Painter_update_clip(this);
869
+ Xot::add_flag(&self->flags, Painter::Data::UNBATCHABLE_STATE_CHANGED);
848
870
  }
849
871
 
850
872
  void
@@ -937,6 +959,24 @@ namespace Rays
937
959
  self->position_matrix_stack.pop_back();
938
960
  }
939
961
 
962
+ void
963
+ Painter::add_flag (uint flags)
964
+ {
965
+ Xot::add_flag(&self->flags, flags);
966
+ }
967
+
968
+ void
969
+ Painter::remove_flag (uint flags)
970
+ {
971
+ Xot::remove_flag(&self->flags, flags);
972
+ }
973
+
974
+ bool
975
+ Painter::has_flag (uint flags) const
976
+ {
977
+ return Xot::has_flag(self->flags, flags);
978
+ }
979
+
940
980
  Painter::operator bool () const
941
981
  {
942
982
  return self->viewport;
@@ -948,5 +988,19 @@ namespace Rays
948
988
  return !operator bool();
949
989
  }
950
990
 
991
+ static bool g_debug = false;
992
+
993
+ void
994
+ Painter::set_debug (bool debug)
995
+ {
996
+ g_debug = debug;
997
+ }
998
+
999
+ bool
1000
+ Painter::debug ()
1001
+ {
1002
+ return g_debug;
1003
+ }
1004
+
951
1005
 
952
1006
  }// Rays
data/src/painter.h CHANGED
@@ -59,7 +59,7 @@ namespace Rays
59
59
  };// PrimitiveMode
60
60
 
61
61
 
62
- struct State
62
+ struct PainterState
63
63
  {
64
64
 
65
65
  Color background, colors[COLOR_TYPE_MAX];
@@ -82,16 +82,16 @@ namespace Rays
82
82
 
83
83
  BlendMode blend_mode;
84
84
 
85
+ TexCoordMode texcoord_mode;
86
+
87
+ TexCoordWrap texcoord_wrap;
88
+
85
89
  Bounds clip;
86
90
 
87
91
  Font font;
88
92
 
89
93
  Image texture;
90
94
 
91
- TexCoordMode texcoord_mode;
92
-
93
- TexCoordWrap texcoord_wrap;
94
-
95
95
  Shader shader;
96
96
 
97
97
  void init ()
@@ -109,11 +109,11 @@ namespace Rays
109
109
  nsegment = 0;
110
110
  line_height = -1;
111
111
  blend_mode = BLEND_NORMAL;
112
+ texcoord_mode = TEXCOORD_IMAGE;
113
+ texcoord_wrap = TEXCOORD_CLAMP;
112
114
  clip .reset(-1);
113
115
  font = get_default_font();
114
116
  texture = Image();
115
- texcoord_mode = TEXCOORD_IMAGE;
116
- texcoord_wrap = TEXCOORD_CLAMP;
117
117
  shader = Shader();
118
118
  }
119
119
 
@@ -135,7 +135,7 @@ namespace Rays
135
135
  return colors[FILL] || colors[STROKE];
136
136
  }
137
137
 
138
- };// State
138
+ };// PainterState
139
139
 
140
140
 
141
141
  struct TextureInfo
@@ -174,15 +174,24 @@ namespace Rays
174
174
  struct Painter::Data
175
175
  {
176
176
 
177
- bool painting = false;
177
+ enum Flag
178
+ {
179
+
180
+ PAINTING = Xot::bit(1, Painter::FLAG_LAST),
181
+
182
+ UNBATCHABLE_STATE_CHANGED = Xot::bit(2, Painter::FLAG_LAST),
183
+
184
+ };// Flag
185
+
186
+ uint flags = Painter::FLAG_BATCHING;
178
187
 
179
188
  float pixel_density = 1;
180
189
 
181
190
  Bounds viewport;
182
191
 
183
- State state;
192
+ PainterState state;
184
193
 
185
- std::vector<State> state_stack;
194
+ std::vector<PainterState> state_stack;
186
195
 
187
196
  Matrix position_matrix;
188
197
 
@@ -197,12 +206,17 @@ namespace Rays
197
206
 
198
207
  virtual ~Data () = default;
199
208
 
209
+ bool is_painting () const
210
+ {
211
+ return Xot::has_flag(flags, PAINTING);
212
+ }
213
+
200
214
  void set_pixel_density (float density);
201
215
 
202
216
  };// Painter::Data
203
217
 
204
218
 
205
- void Painter_update_clip (Painter* painter);
219
+ void Painter_flush (Painter* painter);
206
220
 
207
221
  void Painter_draw (
208
222
  Painter* painter, PrimitiveMode mode, const Color* color,
@@ -217,7 +231,6 @@ namespace Rays
217
231
  Painter* painter, const Image& image,
218
232
  coord src_x, coord src_y, coord src_w, coord src_h,
219
233
  coord dst_x, coord dst_y, coord dst_w, coord dst_h,
220
- bool nofill = false, bool nostroke = false,
221
234
  const Shader* shader = NULL);
222
235
 
223
236
  void Painter_draw_text_line (