rays 0.3.10 → 0.3.11

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/polygon.cpp +1 -1
  3. data/.github/workflows/release-gem.yml +1 -1
  4. data/.github/workflows/test.yml +4 -4
  5. data/ChangeLog.md +7 -0
  6. data/Gemfile.lock +6 -5
  7. data/VERSION +1 -1
  8. data/ext/rays/polygon.cpp +1 -1
  9. data/rays.gemspec +2 -2
  10. data/src/bitmap.h +4 -0
  11. data/src/color_space.cpp +1 -41
  12. data/src/image.cpp +0 -1
  13. data/src/ios/bitmap.mm +5 -32
  14. data/src/ios/rays.mm +3 -3
  15. data/src/opengl/bitmap.cpp +41 -0
  16. data/src/opengl/color_space.cpp +51 -0
  17. data/src/{color_space.h → opengl/color_space.h} +2 -2
  18. data/src/{frame_buffer.cpp → opengl/frame_buffer.cpp} +1 -1
  19. data/src/{frame_buffer.h → opengl/frame_buffer.h} +2 -2
  20. data/src/{ios → opengl/ios}/opengl.mm +3 -3
  21. data/src/{opengl.h → opengl/opengl.h} +2 -6
  22. data/src/{osx → opengl/osx}/opengl.mm +3 -3
  23. data/src/opengl/painter.cpp +756 -0
  24. data/src/{render_buffer.h → opengl/render_buffer.h} +2 -2
  25. data/src/{sdl → opengl/sdl}/opengl.cpp +4 -3
  26. data/src/{shader.cpp → opengl/shader.cpp} +1 -2
  27. data/src/{shader.h → opengl/shader.h} +2 -2
  28. data/src/{shader_program.cpp → opengl/shader_program.cpp} +3 -3
  29. data/src/{shader_program.h → opengl/shader_program.h} +2 -2
  30. data/src/{shader_source.h → opengl/shader_source.h} +2 -2
  31. data/src/{texture.cpp → opengl/texture.cpp} +2 -3
  32. data/src/opengl/texture.h +21 -0
  33. data/src/{win32 → opengl/win32}/opengl.cpp +4 -3
  34. data/src/osx/bitmap.mm +5 -33
  35. data/src/osx/rays.mm +3 -3
  36. data/src/painter.cpp +21 -905
  37. data/src/painter.h +210 -11
  38. data/src/polygon.cpp +38 -13
  39. data/src/renderer.h +22 -0
  40. data/src/sdl/bitmap.cpp +5 -33
  41. data/src/sdl/rays.cpp +3 -3
  42. data/src/texture.h +0 -3
  43. data/src/win32/bitmap.cpp +6 -34
  44. data/src/win32/rays.cpp +3 -3
  45. metadata +29 -24
  46. /data/src/{opengl.cpp → opengl/opengl.cpp} +0 -0
  47. /data/src/{render_buffer.cpp → opengl/render_buffer.cpp} +0 -0
  48. /data/src/{shader_source.cpp → opengl/shader_source.cpp} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9945125d1f082492c730846c72a485b8fdcf055a571e9402dde1a704a0253057
4
- data.tar.gz: dfe5c15614856cf100383b706f11b25a9fca0a32cb09443e606d470a8a8e093c
3
+ metadata.gz: 9ccc3b9eda8d2da41df31850e7ab6a6e480936ad80dfff07adaf35e5d12c8eee
4
+ data.tar.gz: 46785a8507b11be71d877a87fb8f7a42478d19190086701e748978e040a16ad3
5
5
  SHA512:
6
- metadata.gz: 9ba9ee244cc1a6d800e417aa2406a05d646567b2358371f98fe0f8ec19402dc98864e19233979eafe2e6bb9e7dbafbc7d4d7266cfbb700d69cadf6f92609c38f
7
- data.tar.gz: f88ea6b92aae82285bfaf7edd9d12af10da4e305f3d83e158737075747585f15ce7073fe4af90567d6948b089f6a5911d8c10324e585c61f167d4a74ca9d2a3d
6
+ metadata.gz: 505a1f2e9a2e3a1aea29b4e69528c4741ce0ad956f9c2e7fafa67bf528b6b25c51e6d7371624d52f3a4a8e0e8fa8aab1388d76775b03445f4882af49dd3b18d0
7
+ data.tar.gz: 51d70c57b927a3b8564718170962d41d36ca7f9a5b209f71c6d72e23bcd6278b8bbf73181909084bb973d2fb72aa4d7172e8ee218407ebf7236c74bb46530e6f
@@ -26,7 +26,7 @@ VALUE setup(VALUE self, VALUE args, VALUE loop, VALUE colors, VALUE texcoords)
26
26
  {
27
27
  CHECK;
28
28
 
29
- if (args[0].is_a(Rays::polyline_class()))
29
+ if (args.size() >= 1 && args[0].is_a(Rays::polyline_class()))
30
30
  *THIS = to<Rays::Polygon>(args.size(), args.as_array());
31
31
  else
32
32
  {
@@ -24,7 +24,7 @@ jobs:
24
24
  run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
25
25
 
26
26
  - name: test
27
- run: bundle exec rake quiet packages test
27
+ run: bundle exec rake packages test
28
28
 
29
29
  - name: create gem
30
30
  id: gem
@@ -25,13 +25,13 @@ jobs:
25
25
  run: "ruby -I.github/workflows -rutils -e 'setup_dependencies'"
26
26
 
27
27
  - name: packages
28
- run: bundle exec rake packages
28
+ run: bundle exec rake verbose packages
29
29
 
30
30
  - name: lib
31
- run: bundle exec rake lib
31
+ run: bundle exec rake verbose lib
32
32
 
33
33
  - name: ext
34
- run: bundle exec rake ext
34
+ run: bundle exec rake verbose ext
35
35
 
36
36
  - name: test
37
- run: bundle exec rake test
37
+ run: bundle exec rake verbose test
data/ChangeLog.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # rays ChangeLog
2
2
 
3
3
 
4
+ ## [v0.3.11] - 2026-04-17
5
+
6
+ - Move OpenGL code into src/opengl/ and introduce Renderer abstraction
7
+
8
+ - Fix Polygon#initialize crash on empty args
9
+
10
+
4
11
  ## [v0.3.10] - 2026-04-09
5
12
 
6
13
  - Add Font::smooth
data/Gemfile.lock CHANGED
@@ -1,15 +1,16 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- power_assert (2.0.3)
5
- rake (13.1.0)
6
- test-unit (3.6.1)
4
+ power_assert (3.0.1)
5
+ rake (13.3.1)
6
+ test-unit (3.7.7)
7
7
  power_assert
8
- yard (0.9.34)
8
+ yard (0.9.39)
9
9
 
10
10
  PLATFORMS
11
11
  arm64-darwin-21
12
12
  arm64-darwin-23
13
+ arm64-darwin-24
13
14
 
14
15
  DEPENDENCIES
15
16
  rake
@@ -17,4 +18,4 @@ DEPENDENCIES
17
18
  yard
18
19
 
19
20
  BUNDLED WITH
20
- 2.4.13
21
+ 2.4.19
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.10
1
+ 0.3.11
data/ext/rays/polygon.cpp CHANGED
@@ -27,7 +27,7 @@ RUCY_DEF4(setup, args, loop, colors, texcoords)
27
27
  {
28
28
  CHECK;
29
29
 
30
- if (args[0].is_a(Rays::polyline_class()))
30
+ if (args.size() >= 1 && args[0].is_a(Rays::polyline_class()))
31
31
  *THIS = to<Rays::Polygon>(args.size(), args.as_array());
32
32
  else
33
33
  {
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.10'
29
- s.add_dependency 'rucy', '~> 0.3.10'
28
+ s.add_dependency 'xot', '~> 0.3.11'
29
+ s.add_dependency 'rucy', '~> 0.3.11'
30
30
 
31
31
  s.files = `git ls-files`.split $/
32
32
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
data/src/bitmap.h CHANGED
@@ -16,6 +16,10 @@ namespace Rays
16
16
  class RawFont;
17
17
 
18
18
 
19
+ void Bitmap_setup (
20
+ Bitmap* bitmap, int w, int h, const ColorSpace& cs,
21
+ const void* pixels = NULL, bool clear_pixels = true);
22
+
19
23
  Bitmap Bitmap_from (const Texture& texture);
20
24
 
21
25
  void Bitmap_draw_string (
data/src/color_space.cpp CHANGED
@@ -1,4 +1,4 @@
1
- #include "color_space.h"
1
+ #include "rays/color_space.h"
2
2
 
3
3
 
4
4
  #include <xot/util.h>
@@ -194,44 +194,4 @@ namespace Rays
194
194
  }
195
195
 
196
196
 
197
- void
198
- ColorSpace_get_gl_format_and_type (
199
- GLenum* format, GLenum* type, const ColorSpace& cs)
200
- {
201
- if (!format && !type)
202
- argument_error(__FILE__, __LINE__);
203
-
204
- if (!cs)
205
- invalid_state_error(__FILE__, __LINE__);
206
-
207
- if (format)
208
- {
209
- if (cs.is_rgb()) *format = cs.has_alpha() ? GL_RGBA : GL_RGB;
210
- #ifndef IOS
211
- else if (cs.is_bgr()) *format = cs.has_alpha() ? GL_BGRA : GL_BGR;
212
- #endif
213
- else if (cs.is_gray()) *format = GL_LUMINANCE;
214
- else if (cs.is_alpha()) *format = GL_ALPHA;
215
- else
216
- rays_error(__FILE__, __LINE__, "invalid color space.");
217
- }
218
-
219
- if (type)
220
- {
221
- if (cs.is_float())
222
- *type = GL_FLOAT;
223
- else switch (cs.bpc())
224
- {
225
- case 8: *type = GL_UNSIGNED_BYTE; break;
226
- case 16: *type = GL_UNSIGNED_SHORT; break;
227
- #ifndef IOS
228
- case 32: *type = GL_UNSIGNED_INT; break;
229
- #endif
230
- default:
231
- rays_error(__FILE__, __LINE__, "invalid bpc.");
232
- }
233
- }
234
- }
235
-
236
-
237
197
  }// Rays
data/src/image.cpp CHANGED
@@ -5,7 +5,6 @@
5
5
  #include <assert.h>
6
6
  #include "rays/exception.h"
7
7
  #include "rays/debug.h"
8
- #include "opengl.h"
9
8
  #include "bitmap.h"
10
9
  #include "texture.h"
11
10
 
data/src/ios/bitmap.mm CHANGED
@@ -6,10 +6,8 @@
6
6
  #import <MobileCoreServices/UTCoreTypes.h>
7
7
  #include <xot/util.h>
8
8
  #include "rays/exception.h"
9
- #include "../color_space.h"
10
9
  #include "../font.h"
11
10
  #include "../texture.h"
12
- #include "../frame_buffer.h"
13
11
 
14
12
 
15
13
  namespace Rays
@@ -131,11 +129,10 @@ namespace Rays
131
129
  };// Bitmap::Data
132
130
 
133
131
 
134
- static void
135
- setup_bitmap (
136
- Bitmap* bitmap,
137
- int w, int h, const ColorSpace& cs,
138
- const void* pixels = NULL, bool clear_pixels = true)
132
+ void
133
+ Bitmap_setup (
134
+ Bitmap* bitmap, int w, int h, const ColorSpace& cs,
135
+ const void* pixels, bool clear_pixels)
139
136
  {
140
137
  if (w <= 0)
141
138
  argument_error(__FILE__, __LINE__);
@@ -162,30 +159,6 @@ namespace Rays
162
159
  memset(self->pixels, 0, size);
163
160
  }
164
161
 
165
- Bitmap
166
- Bitmap_from (const Texture& tex)
167
- {
168
- if (!tex)
169
- argument_error(__FILE__, __LINE__);
170
-
171
- Bitmap bmp;
172
- setup_bitmap(
173
- &bmp, tex.width(), tex.height(), tex.color_space(), NULL, false);
174
-
175
- GLenum format, type;
176
- ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
177
-
178
- FrameBuffer fb(tex);
179
- FrameBufferBinder binder(fb.id());
180
-
181
- for (int y = 0; y < bmp.height(); ++y)
182
- {
183
- GLvoid* ptr = (GLvoid*) bmp.at<uchar>(0, y);
184
- glReadPixels(0, y, bmp.width(), 1, format, type, ptr);
185
- }
186
-
187
- return bmp;
188
- }
189
162
 
190
163
  void
191
164
  Bitmap_draw_image (
@@ -318,7 +291,7 @@ namespace Rays
318
291
  Bitmap::Bitmap (
319
292
  int width, int height, const ColorSpace& color_space, const void* pixels)
320
293
  {
321
- setup_bitmap(this, width, height, color_space, pixels);
294
+ Bitmap_setup(this, width, height, color_space, pixels);
322
295
  }
323
296
 
324
297
  Bitmap::~Bitmap ()
data/src/ios/rays.mm CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  #import <Foundation/Foundation.h>
6
6
  #include "rays/exception.h"
7
- #include "../opengl.h"
7
+ #include "../renderer.h"
8
8
 
9
9
 
10
10
  namespace Rays
@@ -29,7 +29,7 @@ namespace Rays
29
29
 
30
30
  global::pool = [[NSAutoreleasePool alloc] init];
31
31
 
32
- OpenGL_init();
32
+ Renderer_init();
33
33
  }
34
34
 
35
35
  void
@@ -38,7 +38,7 @@ namespace Rays
38
38
  if (!global::pool)
39
39
  rays_error(__FILE__, __LINE__, "not initialized.");
40
40
 
41
- OpenGL_fin();
41
+ Renderer_fin();
42
42
 
43
43
  [global::pool release];
44
44
  global::pool = nil;
@@ -0,0 +1,41 @@
1
+ #include "../bitmap.h"
2
+
3
+
4
+ #include "rays/exception.h"
5
+ #include "../texture.h"
6
+ #include "opengl.h"
7
+ #include "color_space.h"
8
+ #include "frame_buffer.h"
9
+
10
+
11
+ namespace Rays
12
+ {
13
+
14
+
15
+ Bitmap
16
+ Bitmap_from (const Texture& tex)
17
+ {
18
+ if (!tex)
19
+ argument_error(__FILE__, __LINE__);
20
+
21
+ Bitmap bmp;
22
+ Bitmap_setup(
23
+ &bmp, tex.width(), tex.height(), tex.color_space(), NULL, false);
24
+
25
+ GLenum format, type;
26
+ ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
27
+
28
+ FrameBuffer fb(tex);
29
+ FrameBufferBinder binder(fb.id());
30
+
31
+ for (int y = 0; y < bmp.height(); ++y)
32
+ {
33
+ GLvoid* ptr = (GLvoid*) bmp.at<uchar>(0, y);
34
+ glReadPixels(0, y, bmp.width(), 1, format, type, ptr);
35
+ }
36
+
37
+ return bmp;
38
+ }
39
+
40
+
41
+ }// Rays
@@ -0,0 +1,51 @@
1
+ #include "color_space.h"
2
+
3
+
4
+ #include "rays/exception.h"
5
+
6
+
7
+ namespace Rays
8
+ {
9
+
10
+
11
+ void
12
+ ColorSpace_get_gl_format_and_type (
13
+ GLenum* format, GLenum* type, const ColorSpace& cs)
14
+ {
15
+ if (!format && !type)
16
+ argument_error(__FILE__, __LINE__);
17
+
18
+ if (!cs)
19
+ invalid_state_error(__FILE__, __LINE__);
20
+
21
+ if (format)
22
+ {
23
+ if (cs.is_rgb()) *format = cs.has_alpha() ? GL_RGBA : GL_RGB;
24
+ #ifndef IOS
25
+ else if (cs.is_bgr()) *format = cs.has_alpha() ? GL_BGRA : GL_BGR;
26
+ #endif
27
+ else if (cs.is_gray()) *format = GL_LUMINANCE;
28
+ else if (cs.is_alpha()) *format = GL_ALPHA;
29
+ else
30
+ rays_error(__FILE__, __LINE__, "invalid color space.");
31
+ }
32
+
33
+ if (type)
34
+ {
35
+ if (cs.is_float())
36
+ *type = GL_FLOAT;
37
+ else switch (cs.bpc())
38
+ {
39
+ case 8: *type = GL_UNSIGNED_BYTE; break;
40
+ case 16: *type = GL_UNSIGNED_SHORT; break;
41
+ #ifndef IOS
42
+ case 32: *type = GL_UNSIGNED_INT; break;
43
+ #endif
44
+ default:
45
+ rays_error(__FILE__, __LINE__, "invalid bpc.");
46
+ }
47
+ }
48
+ }
49
+
50
+
51
+ }// Rays
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_COLOR_SPACE_H__
4
- #define __RAYS_SRC_COLOR_SPACE_H__
3
+ #ifndef __RAYS_SRC_OPENGL_COLOR_SPACE_H__
4
+ #define __RAYS_SRC_OPENGL_COLOR_SPACE_H__
5
5
 
6
6
 
7
7
  #include "rays/color_space.h"
@@ -105,7 +105,7 @@ namespace Rays
105
105
  FrameBufferBinder binder(id());
106
106
 
107
107
  glFramebufferTexture2D(
108
- GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0);
108
+ GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, Texture_get_id(texture), 0);
109
109
  OpenGL_check_error(__FILE__, __LINE__);
110
110
 
111
111
  self->texture = texture;
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_FRAME_BUFFER_H__
4
- #define __RAYS_SRC_FRAME_BUFFER_H__
3
+ #ifndef __RAYS_SRC_OPENGL_FRAME_BUFFER_H__
4
+ #define __RAYS_SRC_OPENGL_FRAME_BUFFER_H__
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
@@ -1,5 +1,5 @@
1
1
  // -*- objc -*-
2
- #include "../opengl.h"
2
+ #include "../../renderer.h"
3
3
 
4
4
 
5
5
  #import <OpenGLES/EAGL.h>
@@ -22,13 +22,13 @@ namespace Rays
22
22
 
23
23
 
24
24
  void
25
- OpenGL_init ()
25
+ Renderer_init ()
26
26
  {
27
27
  activate_offscreen_context();
28
28
  }
29
29
 
30
30
  void
31
- OpenGL_fin ()
31
+ Renderer_fin ()
32
32
  {
33
33
  }
34
34
 
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_OPENGL_H__
4
- #define __RAYS_SRC_OPENGL_H__
3
+ #ifndef __RAYS_SRC_OPENGL_OPENGL_H__
4
+ #define __RAYS_SRC_OPENGL_OPENGL_H__
5
5
 
6
6
 
7
7
  #if defined(OSX)
@@ -21,10 +21,6 @@ namespace Rays
21
21
  {
22
22
 
23
23
 
24
- void OpenGL_init ();
25
-
26
- void OpenGL_fin ();
27
-
28
24
  bool OpenGL_has_error ();
29
25
 
30
26
  void OpenGL_check_error (const char* file, int line);
@@ -1,5 +1,5 @@
1
1
  // -*- objc -*-
2
- #include "../opengl.h"
2
+ #include "../../renderer.h"
3
3
 
4
4
 
5
5
  #import <AppKit/AppKit.h>
@@ -39,13 +39,13 @@ namespace Rays
39
39
 
40
40
 
41
41
  void
42
- OpenGL_init ()
42
+ Renderer_init ()
43
43
  {
44
44
  activate_offscreen_context();
45
45
  }
46
46
 
47
47
  void
48
- OpenGL_fin ()
48
+ Renderer_fin ()
49
49
  {
50
50
  }
51
51