rays 0.3.9 → 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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/.doc/ext/rays/bounds.cpp +1 -1
  3. data/.doc/ext/rays/font.cpp +23 -5
  4. data/.doc/ext/rays/image.cpp +1 -1
  5. data/.doc/ext/rays/native.cpp +1 -5
  6. data/.doc/ext/rays/painter.cpp +1 -1
  7. data/.doc/ext/rays/polygon.cpp +1 -1
  8. data/.github/workflows/release-gem.yml +1 -1
  9. data/.github/workflows/test.yml +4 -4
  10. data/CLAUDE.md +25 -0
  11. data/ChangeLog.md +17 -0
  12. data/Gemfile.lock +6 -5
  13. data/Rakefile +4 -2
  14. data/VERSION +1 -1
  15. data/ext/rays/bounds.cpp +1 -1
  16. data/ext/rays/extconf.rb +4 -3
  17. data/ext/rays/font.cpp +27 -7
  18. data/ext/rays/image.cpp +1 -1
  19. data/ext/rays/native.cpp +1 -5
  20. data/ext/rays/painter.cpp +1 -1
  21. data/ext/rays/polygon.cpp +1 -1
  22. data/include/rays/font.h +5 -1
  23. data/include/rays/painter.h +1 -1
  24. data/lib/rays/ext.rb +1 -1
  25. data/lib/rays/image.rb +5 -0
  26. data/rays.gemspec +2 -2
  27. data/src/bitmap.h +6 -1
  28. data/src/color_space.cpp +1 -41
  29. data/src/font.cpp +17 -1
  30. data/src/image.cpp +0 -1
  31. data/src/ios/bitmap.mm +20 -35
  32. data/src/ios/rays.mm +3 -3
  33. data/src/opengl/bitmap.cpp +41 -0
  34. data/src/opengl/color_space.cpp +51 -0
  35. data/src/{color_space.h → opengl/color_space.h} +2 -2
  36. data/src/{frame_buffer.cpp → opengl/frame_buffer.cpp} +1 -1
  37. data/src/{frame_buffer.h → opengl/frame_buffer.h} +2 -2
  38. data/src/{ios → opengl/ios}/opengl.mm +3 -3
  39. data/src/{opengl.h → opengl/opengl.h} +3 -7
  40. data/src/{osx → opengl/osx}/opengl.mm +3 -3
  41. data/src/opengl/painter.cpp +756 -0
  42. data/src/{render_buffer.h → opengl/render_buffer.h} +2 -2
  43. data/src/opengl/sdl/opengl.cpp +103 -0
  44. data/src/{shader.cpp → opengl/shader.cpp} +1 -2
  45. data/src/{shader.h → opengl/shader.h} +2 -2
  46. data/src/{shader_program.cpp → opengl/shader_program.cpp} +3 -3
  47. data/src/{shader_program.h → opengl/shader_program.h} +2 -2
  48. data/src/{shader_source.h → opengl/shader_source.h} +2 -2
  49. data/src/{texture.cpp → opengl/texture.cpp} +2 -3
  50. data/src/opengl/texture.h +21 -0
  51. data/src/{win32 → opengl/win32}/opengl.cpp +4 -4
  52. data/src/osx/bitmap.mm +20 -36
  53. data/src/osx/rays.mm +3 -3
  54. data/src/painter.cpp +28 -910
  55. data/src/painter.h +210 -11
  56. data/src/polygon.cpp +38 -13
  57. data/src/renderer.h +22 -0
  58. data/src/sdl/bitmap.cpp +304 -0
  59. data/src/sdl/camera.cpp +119 -0
  60. data/src/sdl/font.cpp +93 -0
  61. data/src/sdl/rays.cpp +50 -0
  62. data/src/texture.h +0 -3
  63. data/src/win32/bitmap.cpp +8 -35
  64. data/src/win32/rays.cpp +3 -3
  65. data/test/test_image.rb +1 -0
  66. metadata +34 -35
  67. /data/src/{opengl.cpp → opengl/opengl.cpp} +0 -0
  68. /data/src/{render_buffer.cpp → opengl/render_buffer.cpp} +0 -0
  69. /data/src/{shader_source.cpp → opengl/shader_source.cpp} +0 -0
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_RENDER_BUFFER_H__
4
- #define __RAYS_SRC_RENDER_BUFFER_H__
3
+ #ifndef __RAYS_SRC_OPENGL_RENDER_BUFFER_H__
4
+ #define __RAYS_SRC_OPENGL_RENDER_BUFFER_H__
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
@@ -0,0 +1,103 @@
1
+ #include "../../renderer.h"
2
+
3
+
4
+ #include <SDL.h>
5
+ #include "../opengl.h"
6
+ #include "rays/rays.h"
7
+ #include "rays/exception.h"
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ struct OffscreenContext
15
+ {
16
+
17
+ SDL_Window* window = NULL;
18
+
19
+ SDL_GLContext context = NULL;
20
+
21
+ OffscreenContext ()
22
+ {
23
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
24
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
25
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
26
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
27
+
28
+ window = SDL_CreateWindow(
29
+ "rays/offscreen", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1,
30
+ SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
31
+ if (!window)
32
+ rays_error(__FILE__, __LINE__, SDL_GetError());
33
+
34
+ context = SDL_GL_CreateContext(window);
35
+ if (!context)
36
+ rays_error(__FILE__, __LINE__, SDL_GetError());
37
+ }
38
+
39
+ ~OffscreenContext ()
40
+ {
41
+ if (context)
42
+ {
43
+ if (context == SDL_GL_GetCurrentContext())
44
+ SDL_GL_MakeCurrent(NULL, NULL);
45
+
46
+ SDL_GL_DeleteContext(context);
47
+ context = NULL;
48
+ }
49
+
50
+ if (window)
51
+ {
52
+ SDL_DestroyWindow(window);
53
+ window = NULL;
54
+ }
55
+ }
56
+
57
+ };// OffscreenContext
58
+
59
+
60
+ static OffscreenContext*
61
+ get_opengl_offscreen_context ()
62
+ {
63
+ static OffscreenContext* context = NULL;
64
+ if (!context) context = new OffscreenContext();
65
+ return context;
66
+ }
67
+
68
+
69
+ void
70
+ Renderer_init ()
71
+ {
72
+ activate_offscreen_context();
73
+
74
+ static bool glew_initialized = false;
75
+ if (!glew_initialized)
76
+ {
77
+ glew_initialized = true;
78
+ if (glewInit() != GLEW_OK)
79
+ opengl_error(__FILE__, __LINE__, "failed to initialize GLEW.");
80
+ }
81
+ }
82
+
83
+ void
84
+ Renderer_fin ()
85
+ {
86
+ }
87
+
88
+
89
+ Context
90
+ get_offscreen_context ()
91
+ {
92
+ return get_opengl_offscreen_context();
93
+ }
94
+
95
+ void
96
+ activate_offscreen_context ()
97
+ {
98
+ const auto* c = get_opengl_offscreen_context();
99
+ SDL_GL_MakeCurrent(c->window, c->context);
100
+ }
101
+
102
+
103
+ }// Rays
@@ -3,8 +3,7 @@
3
3
 
4
4
  #include <assert.h>
5
5
  #include "rays/exception.h"
6
- #include "opengl.h"
7
- #include "image.h"
6
+ #include "../image.h"
8
7
  #include "shader_program.h"
9
8
  #include "shader_source.h"
10
9
 
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_SHADER_H__
4
- #define __RAYS_SRC_SHADER_H__
3
+ #ifndef __RAYS_SRC_OPENGL_SHADER_H__
4
+ #define __RAYS_SRC_OPENGL_SHADER_H__
5
5
 
6
6
 
7
7
  #include "rays/shader.h"
@@ -7,9 +7,9 @@
7
7
  #include <algorithm>
8
8
  #include "rays/shader.h"
9
9
  #include "rays/exception.h"
10
- #include "shader_source.h"
10
+ #include "../painter.h"
11
11
  #include "texture.h"
12
- #include "painter.h"
12
+ #include "shader_source.h"
13
13
 
14
14
 
15
15
  namespace Rays
@@ -169,7 +169,7 @@ namespace Rays
169
169
  shader_error(__FILE__, __LINE__, "texture unit must be less than %d", max);
170
170
 
171
171
  glActiveTexture(GL_TEXTURE0 + unit);
172
- glBindTexture(GL_TEXTURE_2D, texture.id());
172
+ glBindTexture(GL_TEXTURE_2D, Texture_get_id(texture));
173
173
  glUniform1i(location, unit);
174
174
  return !OpenGL_has_error();
175
175
  }
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_SHADER_PROGRAM_H__
4
- #define __RAYS_SRC_SHADER_PROGRAM_H__
3
+ #ifndef __RAYS_SRC_OPENGL_SHADER_PROGRAM_H__
4
+ #define __RAYS_SRC_OPENGL_SHADER_PROGRAM_H__
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
@@ -1,7 +1,7 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_SRC_SHADER_SOURCE_H__
4
- #define __RAYS_SRC_SHADER_SOURCE_H__
3
+ #ifndef __RAYS_SRC_OPENGL_SHADER_SOURCE_H__
4
+ #define __RAYS_SRC_OPENGL_SHADER_SOURCE_H__
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
@@ -5,7 +5,6 @@
5
5
  #include "rays/exception.h"
6
6
  #include "rays/bitmap.h"
7
7
  #include "rays/debug.h"
8
- #include "opengl.h"
9
8
  #include "color_space.h"
10
9
  #include "frame_buffer.h"
11
10
 
@@ -320,9 +319,9 @@ namespace Rays
320
319
  }
321
320
 
322
321
  GLuint
323
- Texture::id () const
322
+ Texture_get_id (const Texture& texture)
324
323
  {
325
- return self->id;
324
+ return texture.self->id;
326
325
  }
327
326
 
328
327
  void
@@ -0,0 +1,21 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_SRC_OPENGL_TEXTURE_H__
4
+ #define __RAYS_SRC_OPENGL_TEXTURE_H__
5
+
6
+
7
+ #include "../texture.h"
8
+ #include "opengl.h"
9
+
10
+
11
+ namespace Rays
12
+ {
13
+
14
+
15
+ GLuint Texture_get_id (const Texture& texture);
16
+
17
+
18
+ }// Rays
19
+
20
+
21
+ #endif//EOH
@@ -1,7 +1,8 @@
1
- #include "../opengl.h"
1
+ #include "../../renderer.h"
2
2
 
3
3
 
4
4
  #include <xot/windows.h>
5
+ #include "../opengl.h"
5
6
  #include "rays/rays.h"
6
7
  #include "rays/exception.h"
7
8
 
@@ -62,7 +63,6 @@ namespace Rays
62
63
 
63
64
  ~OffscreenContext ()
64
65
  {
65
-
66
66
  if (hrc && hrc == wglGetCurrentContext())
67
67
  {
68
68
  if (!wglMakeCurrent(NULL, NULL))
@@ -91,7 +91,7 @@ namespace Rays
91
91
  }
92
92
 
93
93
  void
94
- OpenGL_init ()
94
+ Renderer_init ()
95
95
  {
96
96
  activate_offscreen_context();
97
97
 
@@ -105,7 +105,7 @@ namespace Rays
105
105
  }
106
106
 
107
107
  void
108
- OpenGL_fin ()
108
+ Renderer_fin ()
109
109
  {
110
110
  }
111
111
 
data/src/osx/bitmap.mm CHANGED
@@ -5,10 +5,8 @@
5
5
  #import <Cocoa/Cocoa.h>
6
6
  #include <xot/util.h>
7
7
  #include "rays/exception.h"
8
- #include "../color_space.h"
9
8
  #include "../font.h"
10
9
  #include "../texture.h"
11
- #include "../frame_buffer.h"
12
10
 
13
11
 
14
12
  namespace Rays
@@ -75,7 +73,7 @@ namespace Rays
75
73
  clear();
76
74
  }
77
75
 
78
- CGContextRef get_context ()
76
+ CGContextRef get_context (bool smooth = true)
79
77
  {
80
78
  if (context) return context;
81
79
 
@@ -94,6 +92,17 @@ namespace Rays
94
92
  context = CGBitmapContextCreate(
95
93
  pixels, width, height, bpc, pitch, cgcs, make_bitmapinfo(color_space));
96
94
  CGColorSpaceRelease(cgcs);
95
+
96
+ if (!smooth)
97
+ {
98
+ CGContextSetShouldAntialias( context, false);
99
+ CGContextSetShouldSmoothFonts( context, false);
100
+ CGContextSetInterpolationQuality( context, kCGInterpolationNone);
101
+ CGContextSetAllowsFontSmoothing( context, false);
102
+ CGContextSetShouldSubpixelPositionFonts(context, false);
103
+ CGContextSetShouldSubpixelQuantizeFonts(context, true);
104
+ }
105
+
97
106
  return context;
98
107
  }
99
108
 
@@ -119,11 +128,10 @@ namespace Rays
119
128
  };// Bitmap::Data
120
129
 
121
130
 
122
- static void
123
- setup_bitmap (
124
- Bitmap* bitmap,
125
- int w, int h, const ColorSpace& cs,
126
- const void* pixels = NULL, bool clear_pixels = true)
131
+ void
132
+ Bitmap_setup (
133
+ Bitmap* bitmap, int w, int h, const ColorSpace& cs,
134
+ const void* pixels, bool clear_pixels)
127
135
  {
128
136
  if (w <= 0)
129
137
  argument_error(__FILE__, __LINE__);
@@ -150,31 +158,6 @@ namespace Rays
150
158
  memset(self->pixels, 0, size);
151
159
  }
152
160
 
153
- Bitmap
154
- Bitmap_from (const Texture& tex)
155
- {
156
- if (!tex)
157
- argument_error(__FILE__, __LINE__);
158
-
159
- Bitmap bmp;
160
- setup_bitmap(
161
- &bmp, tex.width(), tex.height(), tex.color_space(), NULL, false);
162
-
163
- GLenum format, type;
164
- ColorSpace_get_gl_format_and_type(&format, &type, tex.color_space());
165
-
166
- FrameBuffer fb(tex);
167
- FrameBufferBinder binder(fb.id());
168
-
169
- for (int y = 0; y < bmp.height(); ++y)
170
- {
171
- GLvoid* ptr = (GLvoid*) bmp.at<uchar>(0, y);
172
- glReadPixels(0, y, bmp.width(), 1, format, type, ptr);
173
- }
174
-
175
- return bmp;
176
- }
177
-
178
161
  void
179
162
  Bitmap_draw_image (
180
163
  Bitmap* bitmap, CGImageRef image,
@@ -200,7 +183,8 @@ namespace Rays
200
183
 
201
184
  void
202
185
  Bitmap_draw_string (
203
- Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y)
186
+ Bitmap* bitmap, const RawFont& font,
187
+ const char* str, coord x, coord y, bool smooth)
204
188
  {
205
189
  if (!bitmap)
206
190
  argument_error(__FILE__, __LINE__);
@@ -213,7 +197,7 @@ namespace Rays
213
197
 
214
198
  if (*str == '\0') return;
215
199
 
216
- font.draw_string(bitmap->self->get_context(), bitmap->height(), str, x, y);
200
+ font.draw_string(bitmap->self->get_context(smooth), bitmap->height(), str, x, y);
217
201
  Bitmap_set_modified(bitmap);
218
202
  }
219
203
 
@@ -306,7 +290,7 @@ namespace Rays
306
290
  Bitmap::Bitmap (
307
291
  int width, int height, const ColorSpace& color_space, const void* pixels)
308
292
  {
309
- setup_bitmap(this, width, height, color_space, pixels);
293
+ Bitmap_setup(this, width, height, color_space, pixels);
310
294
  }
311
295
 
312
296
  Bitmap::~Bitmap ()
data/src/osx/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;