rays 0.3.10 → 0.3.12

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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/image.cpp +10 -0
  3. data/.doc/ext/rays/painter.cpp +49 -1
  4. data/.doc/ext/rays/polygon.cpp +1 -1
  5. data/.doc/ext/rays/shader.cpp +8 -6
  6. data/.github/workflows/release-gem.yml +4 -1
  7. data/.github/workflows/test.yml +4 -4
  8. data/.github/workflows/utils.rb +88 -17
  9. data/ChangeLog.md +24 -0
  10. data/Gemfile.lock +6 -5
  11. data/Rakefile +3 -3
  12. data/VERSION +1 -1
  13. data/ext/rays/extconf.rb +3 -4
  14. data/ext/rays/image.cpp +11 -0
  15. data/ext/rays/painter.cpp +53 -1
  16. data/ext/rays/polygon.cpp +1 -1
  17. data/ext/rays/shader.cpp +8 -6
  18. data/include/rays/coord.h +6 -6
  19. data/include/rays/defs.h +2 -0
  20. data/include/rays/image.h +11 -1
  21. data/include/rays/painter.h +19 -0
  22. data/include/rays/ruby.h +2 -2
  23. data/include/rays/shader.h +5 -3
  24. data/include/rays.h +2 -2
  25. data/lib/rays/extension.rb +8 -2
  26. data/lib/rays/image.rb +2 -1
  27. data/lib/rays/shader.rb +13 -4
  28. data/rays.gemspec +3 -4
  29. data/src/bitmap.h +4 -0
  30. data/src/color_space.cpp +2 -42
  31. data/src/coord.h +10 -0
  32. data/src/font.cpp +1 -1
  33. data/src/image.cpp +85 -11
  34. data/src/ios/bitmap.mm +5 -32
  35. data/src/ios/rays.mm +3 -3
  36. data/src/opengl/bitmap.cpp +41 -0
  37. data/src/opengl/color_space.cpp +51 -0
  38. data/src/{color_space.h → opengl/color_space.h} +2 -2
  39. data/src/{frame_buffer.cpp → opengl/frame_buffer.cpp} +1 -1
  40. data/src/{frame_buffer.h → opengl/frame_buffer.h} +2 -2
  41. data/src/{ios → opengl/ios}/opengl.mm +3 -3
  42. data/src/{opengl.h → opengl/opengl.h} +2 -6
  43. data/src/{osx → opengl/osx}/opengl.mm +3 -3
  44. data/src/opengl/painter.cpp +1020 -0
  45. data/src/{render_buffer.cpp → opengl/render_buffer.cpp} +1 -1
  46. data/src/{render_buffer.h → opengl/render_buffer.h} +2 -2
  47. data/src/{sdl → opengl/sdl}/opengl.cpp +10 -3
  48. data/src/{shader.cpp → opengl/shader.cpp} +69 -53
  49. data/src/{shader.h → opengl/shader.h} +12 -8
  50. data/src/{shader_program.cpp → opengl/shader_program.cpp} +24 -10
  51. data/src/{shader_program.h → opengl/shader_program.h} +4 -3
  52. data/src/{shader_source.cpp → opengl/shader_source.cpp} +2 -4
  53. data/src/{shader_source.h → opengl/shader_source.h} +2 -2
  54. data/src/{texture.cpp → opengl/texture.cpp} +18 -7
  55. data/src/opengl/texture.h +21 -0
  56. data/src/{win32 → opengl/win32}/opengl.cpp +4 -3
  57. data/src/osx/bitmap.mm +6 -34
  58. data/src/osx/rays.mm +3 -3
  59. data/src/painter.cpp +96 -925
  60. data/src/painter.h +223 -11
  61. data/src/polygon.cpp +38 -13
  62. data/src/renderer.h +22 -0
  63. data/src/sdl/bitmap.cpp +5 -33
  64. data/src/sdl/font.cpp +358 -9
  65. data/src/sdl/rays.cpp +8 -3
  66. data/src/texture.h +6 -3
  67. data/src/win32/bitmap.cpp +6 -34
  68. data/src/win32/rays.cpp +3 -3
  69. data/test/test_painter.rb +36 -25
  70. data/test/test_painter_batch.rb +254 -0
  71. metadata +31 -24
  72. /data/src/{opengl.cpp → opengl/opengl.cpp} +0 -0
@@ -0,0 +1,254 @@
1
+ require_relative 'helper'
2
+
3
+
4
+ class TestPainterBatch < Test::Unit::TestCase
5
+
6
+ def image(w = 16, h = 16, bg: 0, &block)
7
+ Rays::Image.new(w, h)
8
+ .paint {background bg}
9
+ .tap {|img| img.paint {stroke nil; instance_eval(&block)} if block}
10
+ end
11
+
12
+ def assert_gray(expected, actual, message = nil)
13
+ assert_in_epsilon expected, actual, 0.02, message
14
+ end
15
+
16
+ def assert_rgb(expected, actual)
17
+ (0..2).each do |i|
18
+ assert_gray expected[i], actual[i], "Expected: #{expected}, Actual: #{actual}"
19
+ end
20
+ end
21
+
22
+ def assert_equal_batched_and_unbatched(w, h, &block)
23
+ batched = image(w, h, bg: 0, &block)
24
+ unbatched = image(w, h, bg: 0) {|p| p.debug = true; p.instance_eval(&block)}
25
+ assert_equal unbatched.bitmap.pixels, batched.bitmap.pixels, "Pixel mismatch"
26
+ end
27
+
28
+ def test_match_fill_rects()
29
+ assert_equal_batched_and_unbatched(16, 16) do
30
+ fill 1, 0, 0
31
+ rect 0, 0, 8, 16
32
+ fill 0, 1, 0
33
+ rect 8, 0, 8, 16
34
+ end
35
+ end
36
+
37
+ def test_match_stroke_rects()
38
+ assert_equal_batched_and_unbatched(16, 16) do
39
+ no_fill
40
+ stroke 1, 0, 0
41
+ rect 0, 0, 8, 16
42
+ stroke 0, 1, 0
43
+ rect 8, 0, 8, 16
44
+ end
45
+ end
46
+
47
+ def test_match_translated_rects()
48
+ assert_equal_batched_and_unbatched(16, 16) do
49
+ fill 1, 0, 0
50
+ rect 0, 0, 8, 16
51
+ translate 8, 0
52
+ fill 0, 1, 0
53
+ rect 0, 0, 8, 16
54
+ end
55
+ end
56
+
57
+ def test_match_scaled_rects()
58
+ assert_equal_batched_and_unbatched(16, 16) do
59
+ scale 2, 1
60
+ fill 1, 0, 0
61
+ rect 0, 0, 4, 16
62
+ fill 0, 1, 0
63
+ rect 4, 0, 4, 16
64
+ end
65
+ end
66
+
67
+ def test_match_rotated_rects()
68
+ assert_equal_batched_and_unbatched(16, 16) do
69
+ fill 1, 0, 0
70
+ rect 0, 0, 16, 8
71
+ translate 8, 8
72
+ rotate 180
73
+ translate(-8, -8)
74
+ fill 0, 1, 0
75
+ rect 0, 0, 16, 8
76
+ end
77
+ end
78
+
79
+ def test_match_many_rects()
80
+ assert_equal_batched_and_unbatched(16, 16) do
81
+ 8.times do |x|
82
+ fill x / 7.0, 0, 0
83
+ rect x * 2, 0, 2, 16
84
+ end
85
+ end
86
+ end
87
+
88
+ def test_match_image_draw()
89
+ img = image(4, 4) {fill 1, 0, 0; rect 0, 0, 4, 4}
90
+ assert_equal_batched_and_unbatched(8, 8) do
91
+ fill 1
92
+ image img, 2, 2, 4, 4
93
+ end
94
+ end
95
+
96
+ def test_match_image_partial_draw()
97
+ img = image(4, 4) {
98
+ fill 1, 0, 0; rect 0, 0, 2, 4
99
+ fill 0, 1, 0; rect 2, 0, 2, 4
100
+ }
101
+ assert_equal_batched_and_unbatched(2, 4) do
102
+ fill 1
103
+ image img, 0, 0, 2, 4, 0, 0, 2, 4
104
+ end
105
+ end
106
+
107
+ def test_match_image_multiple()
108
+ r = image(4, 4) {fill 1, 0, 0; rect 0, 0, 4, 4}
109
+ g = image(4, 4) {fill 0, 1, 0; rect 0, 0, 4, 4}
110
+ assert_equal_batched_and_unbatched(8, 4) do
111
+ fill 1
112
+ image r, 0, 0
113
+ image g, 4, 0
114
+ end
115
+ end
116
+
117
+ def test_match_image_translated()
118
+ img = image(4, 4) {fill 1, 0, 0; rect 0, 0, 4, 4}
119
+ assert_equal_batched_and_unbatched(8, 8) do
120
+ fill 1
121
+ translate 4, 0
122
+ image img, 0, 0
123
+ end
124
+ end
125
+
126
+ def test_match_atlas_sub_regions()
127
+ atlas = image(8, 4) do
128
+ fill 1, 0, 0; rect 0, 0, 4, 4
129
+ fill 0, 1, 0; rect 4, 0, 4, 4
130
+ end
131
+ assert_equal_batched_and_unbatched(8, 4) do
132
+ fill 1
133
+ image atlas, 0, 0, 4, 4, 0, 0, 4, 4
134
+ image atlas, 4, 0, 4, 4, 4, 0, 4, 4
135
+ end
136
+ end
137
+
138
+ def test_match_atlas_sub_regions_reversed_order()
139
+ atlas = image(8, 4) do
140
+ fill 1, 0, 0; rect 0, 0, 4, 4
141
+ fill 0, 1, 0; rect 4, 0, 4, 4
142
+ end
143
+ assert_equal_batched_and_unbatched(8, 4) do
144
+ fill 1
145
+ image atlas, 4, 0, 4, 4, 0, 0, 4, 4
146
+ image atlas, 0, 0, 4, 4, 4, 0, 4, 4
147
+ end
148
+ end
149
+
150
+ def test_match_atlas_four_regions()
151
+ atlas = image(4, 4) do
152
+ fill 1, 0, 0; rect 0, 0, 2, 2
153
+ fill 0, 1, 0; rect 2, 0, 2, 2
154
+ fill 0, 0, 1; rect 0, 2, 2, 2
155
+ fill 1, 1, 0; rect 2, 2, 2, 2
156
+ end
157
+ assert_equal_batched_and_unbatched(8, 8) do
158
+ fill 1
159
+ image atlas, 0, 0, 2, 2, 0, 0, 4, 4
160
+ image atlas, 2, 0, 2, 2, 4, 0, 4, 4
161
+ image atlas, 0, 2, 2, 2, 0, 4, 4, 4
162
+ image atlas, 2, 2, 2, 2, 4, 4, 4, 4
163
+ end
164
+ end
165
+
166
+ def test_match_atlas_scaled_draw()
167
+ atlas = image(4, 4) do
168
+ fill 1, 0, 0; rect 0, 0, 2, 4
169
+ fill 0, 1, 0; rect 2, 0, 2, 4
170
+ end
171
+ assert_equal_batched_and_unbatched(16, 8) do
172
+ fill 1
173
+ image atlas, 0, 0, 2, 4, 0, 0, 8, 8
174
+ image atlas, 2, 0, 2, 4, 8, 0, 8, 8
175
+ end
176
+ end
177
+
178
+ def test_match_atlas_with_translate()
179
+ atlas = image(8, 4) do
180
+ fill 1, 0, 0; rect 0, 0, 4, 4
181
+ fill 0, 1, 0; rect 4, 0, 4, 4
182
+ end
183
+ assert_equal_batched_and_unbatched(8, 4) do
184
+ fill 1
185
+ translate 4, 0
186
+ image atlas, 0, 0, 4, 4, 0, 0, 4, 4
187
+ end
188
+ end
189
+
190
+ def test_match_rects_and_images_interleaved()
191
+ img = image(4, 4) {fill 0, 0, 1; rect 0, 0, 4, 4}
192
+ assert_equal_batched_and_unbatched(16, 4) do
193
+ fill 1, 0, 0
194
+ rect 0, 0, 4, 4
195
+ fill 1
196
+ image img, 4, 0
197
+ fill 0, 1, 0
198
+ rect 8, 0, 4, 4
199
+ end
200
+ end
201
+
202
+ def test_match_blend_mode()
203
+ assert_equal_batched_and_unbatched(16, 16) do
204
+ fill 0.5
205
+ rect 0, 0, 16, 16
206
+ blend_mode :add
207
+ fill 0.2
208
+ rect 0, 0, 8, 16
209
+ end
210
+ end
211
+
212
+ def test_match_clip()
213
+ assert_equal_batched_and_unbatched(16, 16) do
214
+ fill 1, 0, 0
215
+ clip 0, 0, 8, 16
216
+ rect 0, 0, 16, 16
217
+ end
218
+ end
219
+
220
+ def test_match_push_pop_state()
221
+ assert_equal_batched_and_unbatched(16, 16) do
222
+ fill 1, 0, 0
223
+ rect 0, 0, 8, 16
224
+ push fill: [0, 1, 0] do
225
+ rect 8, 0, 8, 16
226
+ end
227
+ end
228
+ end
229
+
230
+ def test_match_shader()
231
+ assert_equal_batched_and_unbatched(16, 16) do
232
+ fill 1, 0, 0
233
+ rect 0, 0, 8, 16
234
+ shader "void main() {gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);}"
235
+ fill 1
236
+ rect 8, 0, 8, 16
237
+ end
238
+ end
239
+
240
+ def test_atlas_no_bleed()
241
+ atlas = image(4, 2) do
242
+ fill 1, 0, 0; rect 0, 0, 2, 2
243
+ fill 0, 0, 1; rect 2, 0, 2, 2
244
+ end
245
+ img = image(8, 8, bg: 0) do
246
+ fill 1
247
+ image atlas, 0, 0, 2, 2, 0, 0, 8, 8
248
+ end
249
+ assert_rgb [1, 0, 0], img[1, 1]
250
+ assert_rgb [1, 0, 0], img[6, 4]
251
+ assert_rgb [1, 0, 0], img[7, 7]
252
+ end
253
+
254
+ end# TestPainterBatch
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.10
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-09 00:00:00.000000000 Z
11
+ date: 2026-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.10
19
+ version: 0.3.12
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.10
26
+ version: 0.3.12
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.10
33
+ version: 0.3.12
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.3.10
40
+ version: 0.3.12
41
41
  description: This library helps you to develop graphics application with OpenGL.
42
42
  email: xordog@gmail.com
43
43
  executables: []
@@ -174,14 +174,11 @@ files:
174
174
  - src/bounds.cpp
175
175
  - src/color.cpp
176
176
  - src/color_space.cpp
177
- - src/color_space.h
178
177
  - src/coord.cpp
179
178
  - src/coord.h
180
179
  - src/exception.cpp
181
180
  - src/font.cpp
182
181
  - src/font.h
183
- - src/frame_buffer.cpp
184
- - src/frame_buffer.h
185
182
  - src/glm.h
186
183
  - src/image.cpp
187
184
  - src/image.h
@@ -189,17 +186,35 @@ files:
189
186
  - src/ios/bitmap.mm
190
187
  - src/ios/camera.mm
191
188
  - src/ios/font.mm
192
- - src/ios/opengl.mm
193
189
  - src/ios/rays.mm
194
190
  - src/matrix.cpp
195
191
  - src/matrix.h
196
- - src/opengl.cpp
197
- - src/opengl.h
192
+ - src/opengl/bitmap.cpp
193
+ - src/opengl/color_space.cpp
194
+ - src/opengl/color_space.h
195
+ - src/opengl/frame_buffer.cpp
196
+ - src/opengl/frame_buffer.h
197
+ - src/opengl/ios/opengl.mm
198
+ - src/opengl/opengl.cpp
199
+ - src/opengl/opengl.h
200
+ - src/opengl/osx/opengl.mm
201
+ - src/opengl/painter.cpp
202
+ - src/opengl/render_buffer.cpp
203
+ - src/opengl/render_buffer.h
204
+ - src/opengl/sdl/opengl.cpp
205
+ - src/opengl/shader.cpp
206
+ - src/opengl/shader.h
207
+ - src/opengl/shader_program.cpp
208
+ - src/opengl/shader_program.h
209
+ - src/opengl/shader_source.cpp
210
+ - src/opengl/shader_source.h
211
+ - src/opengl/texture.cpp
212
+ - src/opengl/texture.h
213
+ - src/opengl/win32/opengl.cpp
198
214
  - src/osx/bitmap.h
199
215
  - src/osx/bitmap.mm
200
216
  - src/osx/camera.mm
201
217
  - src/osx/font.mm
202
- - src/osx/opengl.mm
203
218
  - src/osx/rays.mm
204
219
  - src/painter.cpp
205
220
  - src/painter.h
@@ -208,20 +223,11 @@ files:
208
223
  - src/polygon.h
209
224
  - src/polyline.cpp
210
225
  - src/polyline.h
211
- - src/render_buffer.cpp
212
- - src/render_buffer.h
226
+ - src/renderer.h
213
227
  - src/sdl/bitmap.cpp
214
228
  - src/sdl/camera.cpp
215
229
  - src/sdl/font.cpp
216
- - src/sdl/opengl.cpp
217
230
  - src/sdl/rays.cpp
218
- - src/shader.cpp
219
- - src/shader.h
220
- - src/shader_program.cpp
221
- - src/shader_program.h
222
- - src/shader_source.cpp
223
- - src/shader_source.h
224
- - src/texture.cpp
225
231
  - src/texture.h
226
232
  - src/util.cpp
227
233
  - src/win32/bitmap.cpp
@@ -229,7 +235,6 @@ files:
229
235
  - src/win32/font.cpp
230
236
  - src/win32/gdi.cpp
231
237
  - src/win32/gdi.h
232
- - src/win32/opengl.cpp
233
238
  - src/win32/rays.cpp
234
239
  - test/helper.rb
235
240
  - test/test_bitmap.rb
@@ -240,6 +245,7 @@ files:
240
245
  - test/test_image.rb
241
246
  - test/test_matrix.rb
242
247
  - test/test_painter.rb
248
+ - test/test_painter_batch.rb
243
249
  - test/test_painter_shape.rb
244
250
  - test/test_point.rb
245
251
  - test/test_polygon.rb
@@ -280,6 +286,7 @@ test_files:
280
286
  - test/test_image.rb
281
287
  - test/test_matrix.rb
282
288
  - test/test_painter.rb
289
+ - test/test_painter_batch.rb
283
290
  - test/test_painter_shape.rb
284
291
  - test/test_point.rb
285
292
  - test/test_polygon.rb
File without changes