rays 0.3.2 → 0.3.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47cd1902082249b45167251a81932376ab40d2026963bb9161ed41a8036701b4
4
- data.tar.gz: 0a455ed272895e558e0adebffe42dfd539192942d9a3e7658ba49c6b8feef331
3
+ metadata.gz: adb5ee45e36c5154f27cbf72379fc6f01106268f3a6a611d5077ad152ba3cde6
4
+ data.tar.gz: 1714d7fb8853794a510f10d702472f62a14db985ca381e01091aefb3c74639e7
5
5
  SHA512:
6
- metadata.gz: ca5b45d58945bcfce469f1f01fc31073bf7ea548fab008493da1d254833cb49cf4dd3d038f8d67ae8ea55803ba8627a0dd8b6b7b252751b3831b76d27b499fe8
7
- data.tar.gz: 14f66b8b7ca66c4a2d7fdaac16d45930fc345c58abc529656c59167534e17ca4ac1a7fd330c5ff241d9743b01da8c1b11b6ca6c354bcca73614656c3d8f426e3
6
+ metadata.gz: 9092039de7061b0cb728bdff7674f2d564cbada64746d60ff712b27cfbee0ba43a9e8d208e7a86cf418e36692c252b6aa1202f38263a21dad69ab3aaf09bb4e4
7
+ data.tar.gz: 16cde6166d15d706af797a2f2a6d9195c483e26e91ebf408624f4114d497ba7e143bfe9ad5b10f5d280e150803fe440abd56d75e2c4cf1b813fd628fc898d77e
@@ -13,6 +13,79 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Color)
13
13
  #define CHECK RUCY_CHECK_OBJ(Rays::Color, self)
14
14
 
15
15
 
16
+ static const char* NIL_COLOR_NO = "no";
17
+ static const char* NIL_COLOR_NONE = "none";
18
+
19
+ typedef std::map<Rays::String, Rays::Color> ColorMap;
20
+
21
+ static ColorMap&
22
+ get_color_map ()
23
+ {
24
+ static ColorMap map;
25
+ if (map.empty())
26
+ {
27
+ map[NIL_COLOR_NO] =
28
+ map[NIL_COLOR_NONE] =
29
+ map["transp"] =
30
+ map["transparent"] = Rays::gray(0, 0);
31
+
32
+ map["black"] = Rays::rgb8( 0, 0, 0);
33
+ map["white"] = Rays::rgb8(255, 241, 232);
34
+ map["gray"] =
35
+ map["lightgray"] = Rays::rgb8(194, 195, 199);
36
+ map["darkgray"] = Rays::rgb8( 95, 87, 79);
37
+ map["brown"] = Rays::rgb8(171, 82, 54);
38
+ map["red"] = Rays::rgb8(255, 0, 77);
39
+ map["orange"] = Rays::rgb8(255, 163, 0);
40
+ map["yellow"] = Rays::rgb8(255, 236, 39);
41
+ map["green"] = Rays::rgb8( 0, 228, 54);
42
+ map["darkgreen"] = Rays::rgb8( 0, 135, 81);
43
+ map["blue"] = Rays::rgb8( 41, 173, 255);
44
+ map["darkblue"] = Rays::rgb8( 29, 43, 83);
45
+ map["indigo"] = Rays::rgb8(131, 118, 156);
46
+ map["pink"] = Rays::rgb8(255, 119, 168);
47
+ map["peach"] = Rays::rgb8(255, 204, 170);
48
+ map["darkpurple"] = Rays::rgb8(126, 37, 83);
49
+ }
50
+ return map;
51
+ }
52
+
53
+ static const Rays::String
54
+ to_color_name (const char* name)
55
+ {
56
+ return Rays::String(name).downcase();
57
+ }
58
+
59
+ static const Rays::Color&
60
+ find_color (const char* name)
61
+ {
62
+ assert(name);
63
+
64
+ const ColorMap& map = get_color_map();
65
+ ColorMap::const_iterator it = map.find(to_color_name(name));
66
+ if (it == map.end())
67
+ argument_error(__FILE__, __LINE__, "color '%s' is not found.", name);
68
+
69
+ return it->second;
70
+ }
71
+
72
+ bool
73
+ is_nil_color (Value value)
74
+ {
75
+ if (value.is_nil())
76
+ return true;
77
+
78
+ const char* name = NULL;
79
+ if (value.is_s()) name = value.as_s();
80
+ if (value.is_sym()) name = value.as_s(true);
81
+ if (!name) return false;
82
+
83
+ return
84
+ strcmp(name, NIL_COLOR_NO) == 0 ||
85
+ strcmp(name, NIL_COLOR_NONE) == 0;
86
+ }
87
+
88
+
16
89
  static
17
90
  VALUE alloc(VALUE klass)
18
91
  {
@@ -113,60 +186,6 @@ VALUE to_hsv(VALUE self)
113
186
  return array(h, s, v, THIS->alpha);
114
187
  }
115
188
 
116
-
117
- typedef std::map<Rays::String, Rays::Color> ColorMap;
118
-
119
- static ColorMap&
120
- get_color_map ()
121
- {
122
- static ColorMap map;
123
- if (map.empty())
124
- {
125
- map["no"] =
126
- map["none"] =
127
- map["transp"] =
128
- map["transparent"] = Rays::gray(0, 0);
129
-
130
- map["black"] = Rays::rgb8( 0, 0, 0);
131
- map["white"] = Rays::rgb8(255, 241, 232);
132
- map["gray"] =
133
- map["lightgray"] = Rays::rgb8(194, 195, 199);
134
- map["darkgray"] = Rays::rgb8( 95, 87, 79);
135
- map["brown"] = Rays::rgb8(171, 82, 54);
136
- map["red"] = Rays::rgb8(255, 0, 77);
137
- map["orange"] = Rays::rgb8(255, 163, 0);
138
- map["yellow"] = Rays::rgb8(255, 236, 39);
139
- map["green"] = Rays::rgb8( 0, 228, 54);
140
- map["darkgreen"] = Rays::rgb8( 0, 135, 81);
141
- map["blue"] = Rays::rgb8( 41, 173, 255);
142
- map["darkblue"] = Rays::rgb8( 29, 43, 83);
143
- map["indigo"] = Rays::rgb8(131, 118, 156);
144
- map["pink"] = Rays::rgb8(255, 119, 168);
145
- map["peach"] = Rays::rgb8(255, 204, 170);
146
- map["darkpurple"] = Rays::rgb8(126, 37, 83);
147
- }
148
- return map;
149
- }
150
-
151
- static const Rays::String
152
- to_color_name (const char* name)
153
- {
154
- return Rays::String(name).downcase();
155
- }
156
-
157
- static const Rays::Color&
158
- find_color (const char* name)
159
- {
160
- assert(name);
161
-
162
- const ColorMap& map = get_color_map();
163
- ColorMap::const_iterator it = map.find(to_color_name(name));
164
- if (it == map.end())
165
- argument_error(__FILE__, __LINE__, "color '%s' is not found.", name);
166
-
167
- return it->second;
168
- }
169
-
170
189
  static
171
190
  VALUE hsv(VALUE self)
172
191
  {
@@ -338,7 +338,10 @@ static
338
338
  VALUE set_fill(VALUE self)
339
339
  {
340
340
  CHECK;
341
- THIS->set_fill(to<Rays::Color>(argc, argv));
341
+ if (argc >= 1 && is_nil_color(argv[0]))
342
+ THIS->no_fill();
343
+ else
344
+ THIS->set_fill(to<Rays::Color>(argc, argv));
342
345
  return self;
343
346
  }
344
347
 
@@ -361,7 +364,10 @@ static
361
364
  VALUE set_stroke(VALUE self)
362
365
  {
363
366
  CHECK;
364
- THIS->set_stroke(to<Rays::Color>(argc, argv));
367
+ if (argc >= 1 && is_nil_color(argv[0]))
368
+ THIS->no_stroke();
369
+ else
370
+ THIS->set_stroke(to<Rays::Color>(argc, argv));
365
371
  return self;
366
372
  }
367
373
 
@@ -70,6 +70,12 @@ VALUE fin(VALUE self)
70
70
  return self;
71
71
  }
72
72
 
73
+ static
74
+ VALUE renderer_info(VALUE self)
75
+ {
76
+ return value(Rays::get_renderer_info());
77
+ }
78
+
73
79
 
74
80
  static Module mRays;
75
81
 
@@ -80,6 +86,7 @@ Init_rays ()
80
86
 
81
87
  mRays.define_singleton_method("init!", init);
82
88
  mRays.define_singleton_method("fin!", fin);
89
+ rb_define_singleton_method(mRays, "renderer_info", RUBY_METHOD_FUNC(renderer_info), 0);
83
90
 
84
91
  for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
85
92
  mRays.define_const(it->name, it->value);
@@ -128,7 +135,7 @@ namespace Rucy
128
135
  int type = value_to<int>(*argv, convert);
129
136
  if (type < 0)
130
137
  argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
131
- if (type >= Rays::CAP_MAX)
138
+ if (type >= Rays::CAP_TYPE_MAX)
132
139
  argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
133
140
 
134
141
  return (Rays::CapType) type;
@@ -161,7 +168,7 @@ namespace Rucy
161
168
  int type = value_to<int>(*argv, convert);
162
169
  if (type < 0)
163
170
  argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
164
- if (type >= Rays::JOIN_MAX)
171
+ if (type >= Rays::JOIN_TYPE_MAX)
165
172
  argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
166
173
 
167
174
  return (Rays::JoinType) type;
@@ -194,7 +201,7 @@ namespace Rucy
194
201
  int mode = value_to<int>(*argv, convert);
195
202
  if (mode < 0)
196
203
  argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
197
- if (mode >= Rays::BLEND_MAX)
204
+ if (mode >= Rays::BLEND_MODE_MAX)
198
205
  argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
199
206
 
200
207
  return (Rays::BlendMode) mode;
data/ChangeLog.md CHANGED
@@ -1,6 +1,27 @@
1
1
  # rays ChangeLog
2
2
 
3
3
 
4
+ ## [v0.3.4] - 2025-03-07
5
+
6
+ - Add msys2_mingw_dependencies for openal and glew
7
+
8
+ - Update glm library
9
+ - Painter: no stroke by default
10
+ - Passing :no or :none to Painter::set_fill()/set_stroke() is equivalent to calling no_fill()/no_stroke()
11
+ - BLEND_REPLACE disables fill/stroke only on calling no_fill/no_stroke (alpha 0 does not mean to no_fill/no_stroke)
12
+
13
+ - Fix a bug that both fill and stroke were drawn even with blend_mode REPLACE, no_fill, and no_stroke combinations
14
+ - Fix problem of not drawing when BLEND_REPLACE is combined with alpha 0
15
+
16
+
17
+ ## [v0.3.3] - 2025-01-23
18
+
19
+ - Add '#version 120' line to shader source
20
+ - Add Rays.renderer_info
21
+
22
+ - Fix shader error on Intel GPU
23
+
24
+
4
25
  ## [v0.3.2] - 2025-01-14
5
26
 
6
27
  - Update workflow files
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ TESTS_ALONE = ['test/test_rays_init.rb']
17
17
  install_packages win32: %w[MINGW_PACKAGE_PREFIX-glew]
18
18
 
19
19
  use_external_library 'https://github.com/g-truc/glm',
20
- tag: '0.9.9.8',
20
+ tag: '1.0.1',
21
21
  srcdirs: 'NOSRC'
22
22
 
23
23
  use_external_library 'https://github.com/skyrpex/clipper',
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.4
data/ext/rays/color.cpp CHANGED
@@ -13,6 +13,79 @@ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(RAYS_EXPORT, Rays::Color)
13
13
  #define CHECK RUCY_CHECK_OBJ(Rays::Color, self)
14
14
 
15
15
 
16
+ static const char* NIL_COLOR_NO = "no";
17
+ static const char* NIL_COLOR_NONE = "none";
18
+
19
+ typedef std::map<Rays::String, Rays::Color> ColorMap;
20
+
21
+ static ColorMap&
22
+ get_color_map ()
23
+ {
24
+ static ColorMap map;
25
+ if (map.empty())
26
+ {
27
+ map[NIL_COLOR_NO] =
28
+ map[NIL_COLOR_NONE] =
29
+ map["transp"] =
30
+ map["transparent"] = Rays::gray(0, 0);
31
+
32
+ map["black"] = Rays::rgb8( 0, 0, 0);
33
+ map["white"] = Rays::rgb8(255, 241, 232);
34
+ map["gray"] =
35
+ map["lightgray"] = Rays::rgb8(194, 195, 199);
36
+ map["darkgray"] = Rays::rgb8( 95, 87, 79);
37
+ map["brown"] = Rays::rgb8(171, 82, 54);
38
+ map["red"] = Rays::rgb8(255, 0, 77);
39
+ map["orange"] = Rays::rgb8(255, 163, 0);
40
+ map["yellow"] = Rays::rgb8(255, 236, 39);
41
+ map["green"] = Rays::rgb8( 0, 228, 54);
42
+ map["darkgreen"] = Rays::rgb8( 0, 135, 81);
43
+ map["blue"] = Rays::rgb8( 41, 173, 255);
44
+ map["darkblue"] = Rays::rgb8( 29, 43, 83);
45
+ map["indigo"] = Rays::rgb8(131, 118, 156);
46
+ map["pink"] = Rays::rgb8(255, 119, 168);
47
+ map["peach"] = Rays::rgb8(255, 204, 170);
48
+ map["darkpurple"] = Rays::rgb8(126, 37, 83);
49
+ }
50
+ return map;
51
+ }
52
+
53
+ static const Rays::String
54
+ to_color_name (const char* name)
55
+ {
56
+ return Rays::String(name).downcase();
57
+ }
58
+
59
+ static const Rays::Color&
60
+ find_color (const char* name)
61
+ {
62
+ assert(name);
63
+
64
+ const ColorMap& map = get_color_map();
65
+ ColorMap::const_iterator it = map.find(to_color_name(name));
66
+ if (it == map.end())
67
+ argument_error(__FILE__, __LINE__, "color '%s' is not found.", name);
68
+
69
+ return it->second;
70
+ }
71
+
72
+ bool
73
+ is_nil_color (Value value)
74
+ {
75
+ if (value.is_nil())
76
+ return true;
77
+
78
+ const char* name = NULL;
79
+ if (value.is_s()) name = value.as_s();
80
+ if (value.is_sym()) name = value.as_s(true);
81
+ if (!name) return false;
82
+
83
+ return
84
+ strcmp(name, NIL_COLOR_NO) == 0 ||
85
+ strcmp(name, NIL_COLOR_NONE) == 0;
86
+ }
87
+
88
+
16
89
  static
17
90
  RUCY_DEF_ALLOC(alloc, klass)
18
91
  {
@@ -125,60 +198,6 @@ RUCY_DEF0(to_hsv)
125
198
  }
126
199
  RUCY_END
127
200
 
128
-
129
- typedef std::map<Rays::String, Rays::Color> ColorMap;
130
-
131
- static ColorMap&
132
- get_color_map ()
133
- {
134
- static ColorMap map;
135
- if (map.empty())
136
- {
137
- map["no"] =
138
- map["none"] =
139
- map["transp"] =
140
- map["transparent"] = Rays::gray(0, 0);
141
-
142
- map["black"] = Rays::rgb8( 0, 0, 0);
143
- map["white"] = Rays::rgb8(255, 241, 232);
144
- map["gray"] =
145
- map["lightgray"] = Rays::rgb8(194, 195, 199);
146
- map["darkgray"] = Rays::rgb8( 95, 87, 79);
147
- map["brown"] = Rays::rgb8(171, 82, 54);
148
- map["red"] = Rays::rgb8(255, 0, 77);
149
- map["orange"] = Rays::rgb8(255, 163, 0);
150
- map["yellow"] = Rays::rgb8(255, 236, 39);
151
- map["green"] = Rays::rgb8( 0, 228, 54);
152
- map["darkgreen"] = Rays::rgb8( 0, 135, 81);
153
- map["blue"] = Rays::rgb8( 41, 173, 255);
154
- map["darkblue"] = Rays::rgb8( 29, 43, 83);
155
- map["indigo"] = Rays::rgb8(131, 118, 156);
156
- map["pink"] = Rays::rgb8(255, 119, 168);
157
- map["peach"] = Rays::rgb8(255, 204, 170);
158
- map["darkpurple"] = Rays::rgb8(126, 37, 83);
159
- }
160
- return map;
161
- }
162
-
163
- static const Rays::String
164
- to_color_name (const char* name)
165
- {
166
- return Rays::String(name).downcase();
167
- }
168
-
169
- static const Rays::Color&
170
- find_color (const char* name)
171
- {
172
- assert(name);
173
-
174
- const ColorMap& map = get_color_map();
175
- ColorMap::const_iterator it = map.find(to_color_name(name));
176
- if (it == map.end())
177
- argument_error(__FILE__, __LINE__, "color '%s' is not found.", name);
178
-
179
- return it->second;
180
- }
181
-
182
201
  static
183
202
  RUCY_DEFN(hsv)
184
203
  {
data/ext/rays/defs.h CHANGED
@@ -19,6 +19,9 @@ using namespace Rucy;
19
19
  using Rays::coord;
20
20
 
21
21
 
22
+ bool is_nil_color (Value value);
23
+
24
+
22
25
  void get_points (std::vector<Rays::Point>* points, int argc, const Value* argv);
23
26
 
24
27
  void get_colors (std::vector<Rays::Color>* colors, int argc, const Value* argv);
data/ext/rays/painter.cpp CHANGED
@@ -359,7 +359,10 @@ static
359
359
  RUCY_DEFN(set_fill)
360
360
  {
361
361
  CHECK;
362
- THIS->set_fill(to<Rays::Color>(argc, argv));
362
+ if (argc >= 1 && is_nil_color(argv[0]))
363
+ THIS->no_fill();
364
+ else
365
+ THIS->set_fill(to<Rays::Color>(argc, argv));
363
366
  return self;
364
367
  }
365
368
  RUCY_END
@@ -385,7 +388,10 @@ static
385
388
  RUCY_DEFN(set_stroke)
386
389
  {
387
390
  CHECK;
388
- THIS->set_stroke(to<Rays::Color>(argc, argv));
391
+ if (argc >= 1 && is_nil_color(argv[0]))
392
+ THIS->no_stroke();
393
+ else
394
+ THIS->set_stroke(to<Rays::Color>(argc, argv));
389
395
  return self;
390
396
  }
391
397
  RUCY_END
data/ext/rays/rays.cpp CHANGED
@@ -72,6 +72,13 @@ RUCY_DEF0(fin)
72
72
  }
73
73
  RUCY_END
74
74
 
75
+ static
76
+ RUCY_DEF0(renderer_info)
77
+ {
78
+ return value(Rays::get_renderer_info());
79
+ }
80
+ RUCY_END
81
+
75
82
 
76
83
  static Module mRays;
77
84
 
@@ -82,6 +89,7 @@ Init_rays ()
82
89
 
83
90
  mRays.define_singleton_method("init!", init);
84
91
  mRays.define_singleton_method("fin!", fin);
92
+ mRays.define_singleton_method("renderer_info", renderer_info);
85
93
 
86
94
  for (auto it = CAP_TYPES.begin(); it != CAP_TYPES.end(); ++it)
87
95
  mRays.define_const(it->name, it->value);
@@ -130,7 +138,7 @@ namespace Rucy
130
138
  int type = value_to<int>(*argv, convert);
131
139
  if (type < 0)
132
140
  argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
133
- if (type >= Rays::CAP_MAX)
141
+ if (type >= Rays::CAP_TYPE_MAX)
134
142
  argument_error(__FILE__, __LINE__, "invalid cap type -- %d", type);
135
143
 
136
144
  return (Rays::CapType) type;
@@ -163,7 +171,7 @@ namespace Rucy
163
171
  int type = value_to<int>(*argv, convert);
164
172
  if (type < 0)
165
173
  argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
166
- if (type >= Rays::JOIN_MAX)
174
+ if (type >= Rays::JOIN_TYPE_MAX)
167
175
  argument_error(__FILE__, __LINE__, "invalid join type -- %d", type);
168
176
 
169
177
  return (Rays::JoinType) type;
@@ -196,7 +204,7 @@ namespace Rucy
196
204
  int mode = value_to<int>(*argv, convert);
197
205
  if (mode < 0)
198
206
  argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
199
- if (mode >= Rays::BLEND_MAX)
207
+ if (mode >= Rays::BLEND_MODE_MAX)
200
208
  argument_error(__FILE__, __LINE__, "invalid blend mode -- %d", mode);
201
209
 
202
210
  return (Rays::BlendMode) mode;
data/include/rays/defs.h CHANGED
@@ -39,7 +39,7 @@ namespace Rays
39
39
 
40
40
  CAP_SQUARE,
41
41
 
42
- CAP_MAX,
42
+ CAP_TYPE_MAX,
43
43
 
44
44
  CAP_DEFAULT = CAP_BUTT
45
45
 
@@ -55,7 +55,7 @@ namespace Rays
55
55
 
56
56
  JOIN_SQUARE,
57
57
 
58
- JOIN_MAX,
58
+ JOIN_TYPE_MAX,
59
59
 
60
60
  JOIN_DEFAULT = JOIN_MITER,
61
61
  JOIN_DEFAULT_MITER_LIMIT = 2
@@ -84,7 +84,7 @@ namespace Rays
84
84
 
85
85
  BLEND_REPLACE,
86
86
 
87
- BLEND_MAX
87
+ BLEND_MODE_MAX
88
88
 
89
89
  };// BlendMode
90
90
 
data/include/rays/rays.h CHANGED
@@ -23,6 +23,8 @@ namespace Rays
23
23
 
24
24
  void activate_offscreen_context ();
25
25
 
26
+ String get_renderer_info ();
27
+
26
28
 
27
29
  }// Rays
28
30
 
data/rays.gemspec CHANGED
@@ -25,8 +25,8 @@ Gem::Specification.new do |s|
25
25
  s.platform = Gem::Platform::RUBY
26
26
  s.required_ruby_version = '>= 3.0.0'
27
27
 
28
- s.add_dependency 'xot', '~> 0.3.2', '>= 0.3.2'
29
- s.add_dependency 'rucy', '~> 0.3.2', '>= 0.3.2'
28
+ s.add_dependency 'xot', '~> 0.3.4', '>= 0.3.4'
29
+ s.add_dependency 'rucy', '~> 0.3.4', '>= 0.3.4'
30
30
 
31
31
  s.files = `git ls-files`.split $/
32
32
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -34,5 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.extra_rdoc_files = rdocs.to_a
35
35
  s.has_rdoc = true
36
36
 
37
+ s.metadata['msys2_mingw_dependencies'] = 'glew'
38
+
37
39
  s.extensions << 'Rakefile'
38
40
  end
data/src/color.cpp CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
 
4
4
  #include <limits.h>
5
- #include <glm/gtx/color_space.hpp>
6
5
  #include <xot/util.h>
7
6
  #include "rays/exception.h"
8
7
  #include "rays/color_space.h"
8
+ #include "glm.h"
9
9
  #include "coord.h"
10
10
 
11
11
 
data/src/coord.h CHANGED
@@ -4,8 +4,7 @@
4
4
  #define __RAYS_SRC_COORD_H__
5
5
 
6
6
 
7
- #include <glm/vec2.hpp>
8
- #include <glm/vec3.hpp>
7
+ #include "glm.h"
9
8
  #include "rays/coord.h"
10
9
 
11
10
 
data/src/glm.h ADDED
@@ -0,0 +1,18 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_SRC_GLM_H__
4
+ #define __RAYS_SRC_GLM_H__
5
+
6
+
7
+ #define GLM_ENABLE_EXPERIMENTAL
8
+ #include <glm/vec2.hpp>
9
+ #include <glm/vec3.hpp>
10
+ #include <glm/mat4x4.hpp>
11
+ #include <glm/geometric.hpp>
12
+ #include <glm/gtc/matrix_transform.hpp>
13
+ #include <glm/gtc/noise.hpp>
14
+ #include <glm/gtx/color_space.hpp>
15
+ #include <glm/gtx/rotate_vector.hpp>
16
+
17
+
18
+ #endif//EOH
data/src/matrix.cpp CHANGED
@@ -1,8 +1,6 @@
1
1
  #include "matrix.h"
2
2
 
3
3
 
4
- #include <glm/mat4x4.hpp>
5
- #include <glm/gtc/matrix_transform.hpp>
6
4
  #include <xot/util.h>
7
5
  #include "rays/exception.h"
8
6
  #include "rays/point.h"
data/src/matrix.h CHANGED
@@ -4,8 +4,8 @@
4
4
  #define __RAYS_SRC_MATRIX_H__
5
5
 
6
6
 
7
- #include <glm/mat4x4.hpp>
8
7
  #include "rays/matrix.h"
8
+ #include "glm.h"
9
9
 
10
10
 
11
11
  namespace Rays
data/src/opengl.cpp CHANGED
@@ -56,4 +56,16 @@ namespace Rays
56
56
  }
57
57
 
58
58
 
59
+ String
60
+ get_renderer_info ()
61
+ {
62
+ return Xot::stringf(
63
+ "{\"OpenGL Version\":\"%s\",\"GLSL Version\":\"%s\",\"Renderer\":\"%s\",\"Vendor\":\"%s\"}",
64
+ glGetString(GL_VERSION),
65
+ glGetString(GL_SHADING_LANGUAGE_VERSION),
66
+ glGetString(GL_RENDERER),
67
+ glGetString(GL_VENDOR));
68
+ }
69
+
70
+
59
71
  }// Rays
data/src/painter.cpp CHANGED
@@ -8,13 +8,13 @@
8
8
  #include <vector>
9
9
  #include <algorithm>
10
10
  #include <functional>
11
- #include <glm/gtc/matrix_transform.hpp>
12
11
  #include "rays/exception.h"
13
12
  #include "rays/point.h"
14
13
  #include "rays/bounds.h"
15
14
  #include "rays/color.h"
16
15
  #include "rays/debug.h"
17
16
  #include "opengl.h"
17
+ #include "glm.h"
18
18
  #include "matrix.h"
19
19
  #include "polygon.h"
20
20
  #include "bitmap.h"
@@ -37,8 +37,7 @@ namespace Rays
37
37
  FILL = 0,
38
38
  STROKE,
39
39
 
40
- COLOR_TYPE_END,
41
- COLOR_TYPE_BEGIN = 0
40
+ COLOR_TYPE_MAX
42
41
 
43
42
  };// ColorType
44
43
 
@@ -46,7 +45,9 @@ namespace Rays
46
45
  struct State
47
46
  {
48
47
 
49
- Color background, colors[2];
48
+ Color background, colors[COLOR_TYPE_MAX];
49
+
50
+ bool nocolors[COLOR_TYPE_MAX];
50
51
 
51
52
  coord stroke_width;
52
53
 
@@ -78,28 +79,43 @@ namespace Rays
78
79
 
79
80
  void init ()
80
81
  {
81
- background .reset(0, 0);
82
- colors[FILL] .reset(1, 1);
83
- colors[STROKE] .reset(1, 0);
84
- stroke_width = 0;
85
- stroke_outset = 0;
86
- stroke_cap = CAP_DEFAULT;
87
- stroke_join = JOIN_DEFAULT;
88
- miter_limit = JOIN_DEFAULT_MITER_LIMIT;
89
- nsegment = 0;
90
- line_height = -1;
91
- blend_mode = BLEND_NORMAL;
92
- clip .reset(-1);
93
- font = get_default_font();
94
- texture = Image();
95
- texcoord_mode = TEXCOORD_IMAGE;
96
- texcoord_wrap = TEXCOORD_CLAMP;
97
- shader = Shader();
82
+ background .reset(0, 0);
83
+ colors[FILL] .reset(1, 1);
84
+ colors[STROKE] .reset(1, 0);
85
+ nocolors[FILL] = false;
86
+ nocolors[STROKE] = true;
87
+ stroke_width = 0;
88
+ stroke_outset = 0;
89
+ stroke_cap = CAP_DEFAULT;
90
+ stroke_join = JOIN_DEFAULT;
91
+ miter_limit = JOIN_DEFAULT_MITER_LIMIT;
92
+ nsegment = 0;
93
+ line_height = -1;
94
+ blend_mode = BLEND_NORMAL;
95
+ clip .reset(-1);
96
+ font = get_default_font();
97
+ texture = Image();
98
+ texcoord_mode = TEXCOORD_IMAGE;
99
+ texcoord_wrap = TEXCOORD_CLAMP;
100
+ shader = Shader();
101
+ }
102
+
103
+ bool get_color (Color* color, ColorType type) const
104
+ {
105
+ const Color& c = colors[type];
106
+ if (blend_mode == BLEND_REPLACE ? nocolors[type] : !c)
107
+ return false;
108
+
109
+ *color = c;
110
+ return true;
98
111
  }
99
112
 
100
- bool has_color ()
113
+ bool has_color () const
101
114
  {
102
- return colors[FILL] || colors[STROKE];
115
+ if (blend_mode == BLEND_REPLACE)
116
+ return !nocolors[FILL] || !nocolors[STROKE];
117
+ else
118
+ return colors[FILL] || colors[STROKE];
103
119
  }
104
120
 
105
121
  };// State
@@ -314,15 +330,6 @@ namespace Rays
314
330
  OpenGL_check_error(__FILE__, __LINE__);
315
331
  }
316
332
 
317
- bool get_color (Color* color, ColorType type)
318
- {
319
- const Color& c = state.colors[type];
320
- if (!c) return false;
321
-
322
- *color = c;
323
- return true;
324
- }
325
-
326
333
  void draw (
327
334
  GLenum mode, const Color* color,
328
335
  const Coord3* points, size_t npoints,
@@ -861,13 +868,13 @@ namespace Rays
861
868
 
862
869
  Color color;
863
870
 
864
- if (self->get_color(&color, FILL))
871
+ if (self->state.get_color(&color, FILL))
865
872
  {
866
873
  Polygon_fill(polygon, painter, color);
867
874
  debug_draw_triangulation(painter, polygon, color);
868
875
  }
869
876
 
870
- if (self->get_color(&color, STROKE))
877
+ if (self->state.get_color(&color, STROKE))
871
878
  Polygon_stroke(polygon, painter, color);
872
879
 
873
880
  if (backup)
@@ -1098,12 +1105,12 @@ namespace Rays
1098
1105
  TextureInfo texinfo(texture, src_x, src_y, src_x + src_w, src_y + src_h);
1099
1106
 
1100
1107
  Color color;
1101
- for (int type = COLOR_TYPE_BEGIN; type < COLOR_TYPE_END; ++type)
1108
+ for (int type = 0; type < COLOR_TYPE_MAX; ++type)
1102
1109
  {
1103
1110
  if ((nofill && type == FILL) || (nostroke && type == STROKE))
1104
1111
  continue;
1105
1112
 
1106
- if (!painter->self->get_color(&color, (ColorType) type))
1113
+ if (!painter->self->state.get_color(&color, (ColorType) type))
1107
1114
  continue;
1108
1115
 
1109
1116
  painter->self->draw(
@@ -1392,13 +1399,15 @@ namespace Rays
1392
1399
  void
1393
1400
  Painter::set_fill (const Color& color)
1394
1401
  {
1395
- self->state.colors[FILL] = color;
1402
+ self->state. colors[FILL] = color;
1403
+ self->state.nocolors[FILL] = false;
1396
1404
  }
1397
1405
 
1398
1406
  void
1399
1407
  Painter::no_fill ()
1400
1408
  {
1401
- self->state.colors[FILL].alpha = 0;
1409
+ self->state. colors[FILL].alpha = 0;
1410
+ self->state.nocolors[FILL] = true;
1402
1411
  }
1403
1412
 
1404
1413
  const Color&
@@ -1416,13 +1425,15 @@ namespace Rays
1416
1425
  void
1417
1426
  Painter::set_stroke (const Color& color)
1418
1427
  {
1419
- self->state.colors[STROKE] = color;
1428
+ self->state. colors[STROKE] = color;
1429
+ self->state.nocolors[STROKE] = false;
1420
1430
  }
1421
1431
 
1422
1432
  void
1423
1433
  Painter::no_stroke ()
1424
1434
  {
1425
- self->state.colors[STROKE].alpha = 0;
1435
+ self->state. colors[STROKE].alpha = 0;
1436
+ self->state.nocolors[STROKE] = true;
1426
1437
  }
1427
1438
 
1428
1439
  const Color&
data/src/point.cpp CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
 
4
4
  #include <math.h>
5
- #include <glm/geometric.hpp>
6
- #include <glm/gtx/rotate_vector.hpp>
7
5
  #include <xot/util.h>
8
6
  #include "rays/exception.h"
7
+ #include "glm.h"
9
8
  #include "coord.h"
10
9
 
11
10
 
data/src/polygon.cpp CHANGED
@@ -1454,7 +1454,7 @@ namespace Rays
1454
1454
  if (!painter)
1455
1455
  argument_error(__FILE__, __LINE__);
1456
1456
 
1457
- if (!color || !polygon || polygon.empty())
1457
+ if (!polygon || polygon.empty())
1458
1458
  return;
1459
1459
 
1460
1460
  polygon.self->fill(painter, color);
@@ -1466,7 +1466,7 @@ namespace Rays
1466
1466
  if (!painter)
1467
1467
  argument_error(__FILE__, __LINE__);
1468
1468
 
1469
- if (!color || !polygon || polygon.empty())
1469
+ if (!polygon || polygon.empty())
1470
1470
  return;
1471
1471
 
1472
1472
  polygon.self->stroke(polygon, painter, color);
data/src/shader.cpp CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
 
4
4
  #include <assert.h>
5
- #include <regex>
6
5
  #include "rays/exception.h"
7
6
  #include "opengl.h"
8
7
  #include "image.h"
@@ -50,7 +49,7 @@ namespace Rays
50
49
 
51
50
  program.reset(new ShaderProgram(
52
51
  make_vertex_shader_source(vertex_shader_source),
53
- make_fragment_shader_source(fragment_shader_source),
52
+ ShaderSource(GL_FRAGMENT_SHADER, fragment_shader_source),
54
53
  env_ ? ShaderEnv_get_flags(*env_) : 0));
55
54
  }
56
55
 
@@ -65,21 +64,6 @@ namespace Rays
65
64
  }
66
65
  }
67
66
 
68
- ShaderSource make_fragment_shader_source (const char* source)
69
- {
70
- #ifdef IOS
71
- static const String SHARED_HEADER = "precision highp float;\n";
72
- static const std::regex PRECISION(R"(^\s*precision\s+\w+p\s+float\s*;)");
73
-
74
- if (!std::regex_search(source, PRECISION))
75
- return ShaderSource(GL_FRAGMENT_SHADER, SHARED_HEADER + source);
76
- else
77
- return ShaderSource(GL_FRAGMENT_SHADER, source);
78
- #else
79
- return ShaderSource(GL_FRAGMENT_SHADER, source);
80
- #endif
81
- }
82
-
83
67
  };// Shader::Data
84
68
 
85
69
 
@@ -110,12 +94,12 @@ namespace Rays
110
94
  "uniform sampler2D " + U_TEXTURE + ";\n"
111
95
  "void main ()\n"
112
96
  "{\n"
113
- " vec2 texcoord__ = clamp(" +
97
+ " vec2 _rays_texcoord = clamp(" +
114
98
  V_TEXCOORD + ".xy, " +
115
99
  U_TEXCOORD_MIN + ".xy, " +
116
100
  U_TEXCOORD_MAX + ".xy - " + U_TEXCOORD_OFFSET + ".xy);\n"
117
- " vec4 color__ = texture2D(" + U_TEXTURE + ", texcoord__);\n"
118
- " gl_FragColor = " + V_COLOR + " * color__;\n"
101
+ " vec4 _rays_color = texture2D(" + U_TEXTURE + ", _rays_texcoord);\n"
102
+ " gl_FragColor = " + V_COLOR + " * _rays_color;\n"
119
103
  "}\n");
120
104
  }
121
105
 
@@ -132,11 +116,11 @@ namespace Rays
132
116
  "uniform sampler2D " + U_TEXTURE + ";\n"
133
117
  "void main ()\n"
134
118
  "{\n"
135
- " vec2 min__ = " + U_TEXCOORD_MIN + ".xy;\n"
136
- " vec2 len__ = " + U_TEXCOORD_MAX + ".xy - min__;\n"
137
- " vec2 texcoord__ = mod(" + V_TEXCOORD + ".xy - min__, len__) + min__;\n"
138
- " vec4 color__ = texture2D(" + U_TEXTURE + ", texcoord__);\n"
139
- " gl_FragColor = " + V_COLOR + " * color__;\n"
119
+ " vec2 _rays_min = " + U_TEXCOORD_MIN + ".xy;\n"
120
+ " vec2 _rays_len = " + U_TEXCOORD_MAX + ".xy - _rays_min;\n"
121
+ " vec2 _rays_texcoord = mod(" + V_TEXCOORD + ".xy - _rays_min, _rays_len) + _rays_min;\n"
122
+ " vec4 _rays_color = texture2D(" + U_TEXTURE + ", _rays_texcoord);\n"
123
+ " gl_FragColor = " + V_COLOR + " * _rays_color;\n"
140
124
  "}\n");
141
125
  }
142
126
 
@@ -151,16 +135,16 @@ namespace Rays
151
135
  "uniform sampler2D " + U_TEXTURE + ";\n"
152
136
  "void main ()\n"
153
137
  "{\n"
154
- " vec4 col__ = texture2D(" + U_TEXTURE + ", " + V_TEXCOORD + ".xy);\n"
138
+ " vec4 _rays_col = texture2D(" + U_TEXTURE + ", " + V_TEXCOORD + ".xy);\n"
155
139
  #if defined(OSX) || defined(IOS)
156
140
  // restore premultiplied rgb values
157
- " vec3 rgb__ = col__.a != 0.0 ? col__.rgb / col__.a : col__.rgb;\n"
158
- " gl_FragColor = " + V_COLOR + " * vec4(rgb__, col__.a);\n"
141
+ " vec3 _rays_rgb = _rays_col.a != 0.0 ? _rays_col.rgb / _rays_col.a : _rays_col.rgb;\n"
142
+ " gl_FragColor = " + V_COLOR + " * vec4(_rays_rgb, _rays_col.a);\n"
159
143
  #elif defined(WIN32)
160
- " float a__ = (col__.r + col__.g + col__.b) / 3.0;\n"
161
- " gl_FragColor = " + V_COLOR + " * vec4(1.0, 1.0, 1.0, a__);\n"
144
+ " float _rays_a = (_rays_col.r + _rays_col.g + _rays_col.b) / 3.0;\n"
145
+ " gl_FragColor = " + V_COLOR + " * vec4(1.0, 1.0, 1.0, _rays_a);\n"
162
146
  #else
163
- " gl_FragColor = " + V_COLOR + " * col__;\n"
147
+ " gl_FragColor = " + V_COLOR + " * _rays_col;\n"
164
148
  #endif
165
149
  "}\n");
166
150
  }
@@ -422,12 +406,12 @@ namespace Rays
422
406
  "uniform mat4 " + U_TEXCOORD_MATRIX + ";\n"
423
407
  "void main ()\n"
424
408
  "{\n"
425
- " vec4 pos__ = vec4(" + A_POSITION + ", 1.0);\n"
426
- " vec4 texcoord__ = vec4(" + A_TEXCOORD + ", 1.0);\n"
427
- " " + V_POSITION + " = pos__;\n"
428
- " " + V_TEXCOORD + " = " + U_TEXCOORD_MATRIX + " * texcoord__;\n"
409
+ " vec4 _rays_pos = vec4(" + A_POSITION + ", 1.0);\n"
410
+ " vec4 _rays_texcoord = vec4(" + A_TEXCOORD + ", 1.0);\n"
411
+ " " + V_POSITION + " = _rays_pos;\n"
412
+ " " + V_TEXCOORD + " = " + U_TEXCOORD_MATRIX + " * _rays_texcoord;\n"
429
413
  " " + V_COLOR + " = " + A_COLOR + ";\n"
430
- " gl_Position = " + U_POSITION_MATRIX + " * pos__;\n"
414
+ " gl_Position = " + U_POSITION_MATRIX + " * _rays_pos;\n"
431
415
  "}\n";
432
416
  }
433
417
 
@@ -1,6 +1,7 @@
1
1
  #include "shader_source.h"
2
2
 
3
3
 
4
+ #include <regex>
4
5
  #include "rays/exception.h"
5
6
  #include "rays/debug.h"
6
7
 
@@ -39,8 +40,11 @@ namespace Rays
39
40
  if (is_valid())
40
41
  invalid_state_error(__FILE__, __LINE__);
41
42
 
43
+ String buffer;
44
+ const char* src = add_headers(type_, source_, &buffer);
45
+
42
46
  id = glCreateShader(type_);
43
- glShaderSource(id, 1, &source_, NULL);
47
+ glShaderSource(id, 1, &src, NULL);
44
48
  glCompileShader(id);
45
49
 
46
50
  GLint status = GL_FALSE;
@@ -52,6 +56,32 @@ namespace Rays
52
56
  source = source_;
53
57
  }
54
58
 
59
+ const char* add_headers (GLenum type, const char* source, String* buffer)
60
+ {
61
+ #ifdef IOS
62
+ if (type == GL_FRAGMENT_SHADER)
63
+ {
64
+ static const std::regex PRECISION(R"(^\s*precision\s+\w+p\s+float\s*;)");
65
+ if (!std::regex_search(source, PRECISION))
66
+ {
67
+ static const String PRECISION_HEADER = "precision highp float;\n";
68
+ *buffer = PRECISION_HEADER + source;
69
+ source = buffer->c_str();
70
+ }
71
+ }
72
+ #endif
73
+
74
+ static const std::regex VERSION(R"(^\s*#\s*version\s+\d+)");
75
+ if (!std::regex_search(source, VERSION))
76
+ {
77
+ static const String VERSION_HEADER = "#version 120\n";
78
+ *buffer = VERSION_HEADER + source;
79
+ source = buffer->c_str();
80
+ }
81
+
82
+ return source;
83
+ }
84
+
55
85
  String get_compile_log () const
56
86
  {
57
87
  GLsizei len = 0;
data/src/util.cpp CHANGED
@@ -1,7 +1,7 @@
1
1
  #include "rays/util.h"
2
2
 
3
3
 
4
- #include <glm/gtc/noise.hpp>
4
+ #include "glm.h"
5
5
  #include "coord.h"
6
6
 
7
7
 
data/test/test_painter.rb CHANGED
@@ -21,19 +21,19 @@ class TestPainter < Test::Unit::TestCase
21
21
  .tap {|img| img.paint(&block) if block}
22
22
  end
23
23
 
24
- def assert_gray(expected, actual)
25
- assert_in_epsilon expected, actual, 0.02
24
+ def assert_gray(expected, actual, message = nil)
25
+ assert_in_epsilon expected, actual, 0.02, message
26
26
  end
27
27
 
28
28
  def assert_rgb(expected, actual)
29
29
  (0..2).each do |i|
30
- assert_gray expected[i], actual[i]
30
+ assert_gray expected[i], actual[i], "Expected: #{expected}, Actual: #{actual}"
31
31
  end
32
32
  end
33
33
 
34
34
  def assert_rgba(expected, actual)
35
35
  (0..3).each do |i|
36
- assert_gray expected[i], actual[i]
36
+ assert_gray expected[i], actual[i], "Expected: #{expected}, Actual: #{actual}"
37
37
  end
38
38
  end
39
39
 
@@ -347,14 +347,16 @@ class TestPainter < Test::Unit::TestCase
347
347
 
348
348
  def test_blend_mode_replace()
349
349
  i = image bg: 1 do
350
- fill 0.1, 0.2, 0.3, 0.4
350
+ fill 0.1, 0.2, 0.3
351
351
  rect 0, 0, 2
352
352
  blend_mode :replace
353
- fill 0.5, 0.6, 0.7, 0.8
353
+ no_stroke
354
+ fill 0.4, 0.5, 0.6, 0.7
354
355
  rect 1, 0, 2
355
356
  end
356
- assert_rgba [0.5, 0.6, 0.7, 0.8], i[1, 0]
357
- assert_rgba [0.5, 0.6, 0.7, 0.8], i[2, 0]
357
+ assert_rgba [0.1, 0.2, 0.3, 1.0], i[0, 0]
358
+ assert_rgba [0.4, 0.5, 0.6, 0.7], i[1, 0]
359
+ assert_rgba [0.4, 0.5, 0.6, 0.7], i[2, 0]
358
360
  end
359
361
 
360
362
  def test_blend_mode_invalid()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-13 00:00:00.000000000 Z
11
+ date: 2025-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.2
19
+ version: 0.3.4
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.3.2
22
+ version: 0.3.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 0.3.2
29
+ version: 0.3.4
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.3.2
32
+ version: 0.3.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rucy
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.3.2
39
+ version: 0.3.4
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 0.3.2
42
+ version: 0.3.4
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 0.3.2
49
+ version: 0.3.4
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.3.2
52
+ version: 0.3.4
53
53
  description: This library helps you to develop graphics application with OpenGL.
54
54
  email: xordog@gmail.com
55
55
  executables: []
@@ -191,6 +191,7 @@ files:
191
191
  - src/font.h
192
192
  - src/frame_buffer.cpp
193
193
  - src/frame_buffer.h
194
+ - src/glm.h
194
195
  - src/image.cpp
195
196
  - src/image.h
196
197
  - src/ios/bitmap.h
@@ -256,7 +257,8 @@ files:
256
257
  homepage: https://github.com/xord/rays
257
258
  licenses:
258
259
  - MIT
259
- metadata: {}
260
+ metadata:
261
+ msys2_mingw_dependencies: glew
260
262
  post_install_message:
261
263
  rdoc_options: []
262
264
  require_paths: