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.
- checksums.yaml +4 -4
- data/.doc/ext/rays/image.cpp +10 -0
- data/.doc/ext/rays/painter.cpp +49 -1
- data/.doc/ext/rays/shader.cpp +8 -6
- data/.github/workflows/release-gem.yml +5 -16
- data/.github/workflows/utils.rb +88 -17
- data/ChangeLog.md +26 -0
- data/README.md +164 -5
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/ext/rays/extconf.rb +3 -4
- data/ext/rays/image.cpp +11 -0
- data/ext/rays/painter.cpp +53 -1
- data/ext/rays/shader.cpp +8 -6
- data/include/rays/coord.h +6 -6
- data/include/rays/defs.h +2 -0
- data/include/rays/image.h +11 -1
- data/include/rays/painter.h +19 -0
- data/include/rays/ruby.h +2 -2
- data/include/rays/shader.h +5 -3
- data/include/rays.h +2 -2
- data/lib/rays/extension.rb +8 -2
- data/lib/rays/image.rb +2 -1
- data/lib/rays/shader.rb +13 -4
- data/rays.gemspec +3 -4
- data/src/color_space.cpp +1 -1
- data/src/coord.h +10 -0
- data/src/font.cpp +1 -1
- data/src/image.cpp +85 -10
- data/src/opengl/painter.cpp +559 -214
- data/src/opengl/render_buffer.cpp +1 -1
- data/src/opengl/sdl/opengl.cpp +6 -0
- data/src/opengl/shader.cpp +68 -51
- data/src/opengl/shader.h +10 -6
- data/src/opengl/shader_program.cpp +21 -7
- data/src/opengl/shader_program.h +2 -1
- data/src/opengl/shader_source.cpp +2 -4
- data/src/opengl/texture.cpp +18 -6
- data/src/osx/bitmap.mm +1 -1
- data/src/painter.cpp +80 -26
- data/src/painter.h +26 -13
- data/src/sdl/font.cpp +358 -9
- data/src/sdl/rays.cpp +5 -0
- data/src/texture.h +6 -0
- data/test/test_painter.rb +36 -25
- data/test/test_painter_batch.rb +254 -0
- metadata +8 -6
|
@@ -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.
|
|
4
|
+
version: 0.3.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- xordog
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-16 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.
|
|
19
|
+
version: 0.3.13
|
|
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.
|
|
26
|
+
version: 0.3.13
|
|
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.
|
|
33
|
+
version: 0.3.13
|
|
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.
|
|
40
|
+
version: 0.3.13
|
|
41
41
|
description: This library helps you to develop graphics application with OpenGL.
|
|
42
42
|
email: xordog@gmail.com
|
|
43
43
|
executables: []
|
|
@@ -245,6 +245,7 @@ files:
|
|
|
245
245
|
- test/test_image.rb
|
|
246
246
|
- test/test_matrix.rb
|
|
247
247
|
- test/test_painter.rb
|
|
248
|
+
- test/test_painter_batch.rb
|
|
248
249
|
- test/test_painter_shape.rb
|
|
249
250
|
- test/test_point.rb
|
|
250
251
|
- test/test_polygon.rb
|
|
@@ -285,6 +286,7 @@ test_files:
|
|
|
285
286
|
- test/test_image.rb
|
|
286
287
|
- test/test_matrix.rb
|
|
287
288
|
- test/test_painter.rb
|
|
289
|
+
- test/test_painter_batch.rb
|
|
288
290
|
- test/test_painter_shape.rb
|
|
289
291
|
- test/test_point.rb
|
|
290
292
|
- test/test_polygon.rb
|