rays 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/.doc/ext/rays/bitmap.cpp +70 -233
  3. data/.doc/ext/rays/bounds.cpp +339 -57
  4. data/.doc/ext/rays/color.cpp +58 -48
  5. data/.doc/ext/rays/color_space.cpp +174 -0
  6. data/.doc/ext/rays/font.cpp +31 -53
  7. data/.doc/ext/rays/image.cpp +64 -67
  8. data/.doc/ext/rays/matrix.cpp +22 -50
  9. data/.doc/ext/rays/native.cpp +9 -2
  10. data/.doc/ext/rays/painter.cpp +276 -259
  11. data/.doc/ext/rays/point.cpp +186 -52
  12. data/.doc/ext/rays/rays.cpp +25 -20
  13. data/.doc/ext/rays/shader.cpp +61 -0
  14. data/.doc/ext/rays/texture.cpp +47 -59
  15. data/{README → README.md} +0 -0
  16. data/Rakefile +6 -5
  17. data/VERSION +1 -1
  18. data/ext/rays/bitmap.cpp +88 -248
  19. data/ext/rays/bounds.cpp +437 -141
  20. data/ext/rays/color.cpp +79 -69
  21. data/ext/rays/color_space.cpp +185 -0
  22. data/ext/rays/extconf.rb +14 -63
  23. data/ext/rays/font.cpp +44 -65
  24. data/ext/rays/image.cpp +82 -81
  25. data/ext/rays/matrix.cpp +32 -60
  26. data/ext/rays/native.cpp +9 -2
  27. data/ext/rays/painter.cpp +345 -321
  28. data/ext/rays/point.cpp +212 -69
  29. data/ext/rays/rays.cpp +29 -23
  30. data/ext/rays/shader.cpp +63 -0
  31. data/ext/rays/texture.cpp +64 -74
  32. data/include/rays/bitmap.h +21 -12
  33. data/include/rays/bounds.h +67 -9
  34. data/include/rays/color.h +23 -7
  35. data/include/rays/{colorspace.h → color_space.h} +6 -3
  36. data/include/rays/exception.h +17 -11
  37. data/include/rays/font.h +4 -3
  38. data/include/rays/image.h +11 -6
  39. data/include/rays/matrix.h +15 -12
  40. data/include/rays/opengl.h +54 -1
  41. data/include/rays/painter.h +98 -108
  42. data/include/rays/point.h +45 -5
  43. data/include/rays/rays.h +2 -2
  44. data/include/rays/ruby/bitmap.h +2 -16
  45. data/include/rays/ruby/bounds.h +4 -16
  46. data/include/rays/ruby/color.h +3 -16
  47. data/include/rays/ruby/color_space.h +27 -0
  48. data/include/rays/ruby/font.h +2 -16
  49. data/include/rays/ruby/image.h +2 -16
  50. data/include/rays/ruby/matrix.h +2 -16
  51. data/include/rays/ruby/painter.h +2 -16
  52. data/include/rays/ruby/point.h +3 -16
  53. data/include/rays/ruby/shader.h +27 -0
  54. data/include/rays/ruby/texture.h +2 -16
  55. data/include/rays/ruby.h +1 -0
  56. data/include/rays/shader.h +48 -0
  57. data/include/rays/texture.h +13 -2
  58. data/include/rays.h +2 -1
  59. data/lib/rays/bitmap.rb +20 -11
  60. data/lib/rays/bounds.rb +29 -68
  61. data/lib/rays/color.rb +39 -0
  62. data/lib/rays/color_space.rb +33 -0
  63. data/lib/rays/font.rb +29 -0
  64. data/lib/rays/image.rb +22 -0
  65. data/lib/rays/module.rb +11 -7
  66. data/lib/rays/painter.rb +103 -40
  67. data/lib/rays/point.rb +19 -36
  68. data/lib/rays/shader.rb +13 -0
  69. data/lib/rays/texture.rb +9 -0
  70. data/lib/rays.rb +4 -0
  71. data/rays.gemspec +3 -4
  72. data/src/bounds.cpp +272 -63
  73. data/src/color.cpp +168 -21
  74. data/src/{colorspace.cpp → color_space.cpp} +38 -1
  75. data/src/exception.cpp +24 -15
  76. data/src/frame_buffer.cpp +275 -0
  77. data/src/frame_buffer.h +79 -0
  78. data/src/image.cpp +80 -36
  79. data/src/ios/bitmap.mm +340 -0
  80. data/src/ios/font.mm +206 -0
  81. data/src/{cocoa → ios}/helper.h +2 -2
  82. data/src/{cocoa → ios}/helper.mm +0 -0
  83. data/src/ios/opengl.mm +21 -0
  84. data/src/ios/program.cpp +122 -0
  85. data/src/{cocoa → ios}/rays.mm +8 -7
  86. data/src/matrix.cpp +10 -22
  87. data/src/opengl.cpp +64 -0
  88. data/src/{cocoa → osx}/bitmap.mm +121 -70
  89. data/src/{cocoa → osx}/font.mm +32 -24
  90. data/src/osx/helper.h +26 -0
  91. data/src/osx/helper.mm +25 -0
  92. data/src/osx/opengl.mm +103 -0
  93. data/src/osx/rays.mm +43 -0
  94. data/src/painter.cpp +596 -422
  95. data/src/point.cpp +154 -11
  96. data/src/program.cpp +513 -0
  97. data/src/program.h +73 -0
  98. data/src/render_buffer.cpp +120 -0
  99. data/src/render_buffer.h +47 -0
  100. data/src/shader.cpp +117 -0
  101. data/src/texture.cpp +104 -134
  102. data/test/helper.rb +10 -3
  103. data/test/test_bitmap.rb +18 -0
  104. data/test/test_bounds.rb +81 -35
  105. data/test/test_color.rb +29 -2
  106. data/test/test_image.rb +63 -0
  107. data/test/test_painter.rb +120 -0
  108. data/test/test_point.rb +30 -9
  109. data/test/test_shader.rb +37 -0
  110. data/test/test_texture.rb +18 -0
  111. metadata +75 -58
  112. data/.gitignore +0 -14
  113. data/ChangeLog +0 -8
data/ext/rays/image.cpp CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
 
4
4
  #include <rucy.h>
5
- #include <rays/ruby/bitmap.h>
6
- #include <rays/ruby/texture.h>
5
+ #include "rays/ruby/color_space.h"
6
+ #include "rays/ruby/bitmap.h"
7
+ #include "rays/ruby/texture.h"
8
+ #include "rays/ruby/painter.h"
7
9
  #include "defs.h"
8
10
 
9
11
 
@@ -14,73 +16,37 @@ using Rays::coord;
14
16
 
15
17
  static Class cImage;
16
18
 
19
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Image, cImage)
17
20
 
18
- namespace Rays
19
- {
20
-
21
-
22
- Class
23
- image_class ()
24
- {
25
- return cImage;
26
- }
27
-
28
-
29
- }// Rays
30
-
31
-
32
- namespace Rucy
33
- {
34
-
35
-
36
- Value
37
- value (const Rays::Image& obj)
38
- {
39
- return new_type(cImage, new Rays::Image(obj));
40
- }
41
-
42
- Value
43
- value (const Rays::Image* obj)
44
- {
45
- return obj ? value(*obj) : nil();
46
- }
47
-
48
-
49
- }// Rucy
50
-
51
-
52
- #define THIS to<Rays::Image*>(self)
21
+ #define THIS to<Rays::Image*>(self)
53
22
 
54
- #define CHECK RUCY_CHECK_OBJECT(self, Rays::Image, cImage)
23
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Image, cImage, self)
55
24
 
56
25
 
57
26
  static
58
- RUBY_DEF_ALLOC(alloc, klass)
27
+ RUCY_DEF_ALLOC(alloc, klass)
59
28
  {
60
29
  return new_type<Rays::Image>(klass);
61
30
  }
62
- RUBY_END
31
+ RUCY_END
63
32
 
64
33
  static
65
- RUBY_DEFN(initialize)
34
+ RUCY_DEFN(initialize)
66
35
  {
67
- RUCY_CHECK_OBJ(self, Rays::Image, cImage);
68
-
69
- if (argc < 1 || 3 < argc)
70
- arg_count_error("Image#initialize", argc, 1, 2, 3);
36
+ RUCY_CHECK_OBJ(Rays::Image, cImage, self);
37
+ check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2, 3);
71
38
 
72
39
  if (argc == 0) return self;
73
40
 
74
41
  if (argv[0].is_kind_of(Rays::bitmap_class()))
75
42
  {
76
- if (argc < 1 || 2 < argc)
77
- arg_count_error("Image#initialize", argc, 1, 2);
43
+ check_arg_count(__FILE__, __LINE__, "Image#initialize", argc, 1, 2);
78
44
 
79
45
  const Rays::Bitmap* bitmap = to<Rays::Bitmap*>(argv[0]);
80
- if (!bitmap) argument_error();
46
+ if (!bitmap) argument_error(__FILE__, __LINE__);
81
47
 
82
- bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
83
- *THIS = Rays::Image(*bitmap, alphaonly);
48
+ bool alpha_only = (argc == 2) ? to<bool>(argv[1]) : false;
49
+ *THIS = Rays::Image(*bitmap, alpha_only);
84
50
  }
85
51
  else
86
52
  {
@@ -92,73 +58,90 @@ RUBY_DEFN(initialize)
92
58
 
93
59
  return self;
94
60
  }
95
- RUBY_END
61
+ RUCY_END
62
+
63
+ static
64
+ RUCY_DEF1(initialize_copy, obj)
65
+ {
66
+ RUCY_CHECK_OBJ(Rays::Image, cImage, self);
67
+
68
+ *THIS = to<Rays::Image&>(obj).copy();
69
+ return self;
70
+ }
71
+ RUCY_END
96
72
 
97
73
  static
98
- RUBY_DEF0(width)
74
+ RUCY_DEF0(painter)
99
75
  {
100
76
  CHECK;
77
+ return value(THIS->painter());
78
+ }
79
+ RUCY_END
101
80
 
81
+ static
82
+ RUCY_DEF0(width)
83
+ {
84
+ CHECK;
102
85
  return value(THIS->width());
103
86
  }
104
- RUBY_END
87
+ RUCY_END
105
88
 
106
89
  static
107
- RUBY_DEF0(height)
90
+ RUCY_DEF0(height)
108
91
  {
109
92
  CHECK;
110
-
111
93
  return value(THIS->height());
112
94
  }
113
- RUBY_END
95
+ RUCY_END
114
96
 
115
97
  static
116
- RUBY_DEF0(color_space)
98
+ RUCY_DEF0(color_space)
117
99
  {
118
100
  CHECK;
119
-
120
- return value(THIS->color_space().type());
101
+ return value(THIS->color_space());
121
102
  }
122
- RUBY_END
103
+ RUCY_END
123
104
 
124
105
  static
125
- RUBY_DEF0(bitmap)
106
+ RUCY_DEF0(alpha_only)
126
107
  {
127
108
  CHECK;
109
+ return value(THIS->alpha_only());
110
+ }
111
+ RUCY_END
128
112
 
113
+ static
114
+ RUCY_DEF0(bitmap)
115
+ {
116
+ CHECK;
129
117
  return value(THIS->bitmap());
130
118
  }
131
- RUBY_END
119
+ RUCY_END
132
120
 
133
121
  static
134
- RUBY_DEF0(texture)
122
+ RUCY_DEF0(texture)
135
123
  {
136
124
  CHECK;
137
-
138
125
  return value(THIS->texture());
139
126
  }
140
- RUBY_END
141
-
127
+ RUCY_END
142
128
 
143
129
  static
144
- RUBY_DEFN(load)
130
+ RUCY_DEF1(save, path)
145
131
  {
146
- if (argc != 1 && argc != 2) arg_count_error("Image.load", argc, 1, 2);
147
-
148
- Rays::String path = argv[0].c_str();
149
- bool alphaonly = (argc == 2) ? to<bool>(argv[1]) : false;
132
+ CHECK;
133
+ Rays::save_image(*THIS, path.c_str());
134
+ return self;
135
+ }
136
+ RUCY_END
150
137
 
151
- Rays::Image img;
152
- if (!Rays::load_image(&img, path.c_str(), alphaonly))
153
- {
154
- rays_error(
155
- "Image.load('%s', %s) failed.",
156
- path.c_str(), alphaonly ? "true" : "false");
157
- }
158
138
 
159
- return value(img);
139
+ static
140
+ RUCY_DEF2(load, path, alpha_only)
141
+ {
142
+ return value(Rays::load_image(path.c_str(), to<bool>(alpha_only)));
160
143
  }
161
- RUBY_END
144
+ RUCY_END
162
145
 
163
146
 
164
147
  void
@@ -169,10 +152,28 @@ Init_image ()
169
152
  cImage = mRays.define_class("Image");
170
153
  cImage.define_alloc_func(alloc);
171
154
  cImage.define_private_method("initialize", initialize);
155
+ cImage.define_private_method("initialize_copy", initialize_copy);
156
+ cImage.define_method("painter", painter);
172
157
  cImage.define_method("width", width);
173
158
  cImage.define_method("height", height);
174
159
  cImage.define_method("color_space", color_space);
160
+ cImage.define_method("alpha_only", alpha_only);
175
161
  cImage.define_method("bitmap", bitmap);
176
162
  cImage.define_method("texture", texture);
177
- cImage.define_function("load", load);
163
+ cImage.define_method("save", save);
164
+ cImage.define_function("load_image", load);
178
165
  }
166
+
167
+
168
+ namespace Rays
169
+ {
170
+
171
+
172
+ Class
173
+ image_class ()
174
+ {
175
+ return cImage;
176
+ }
177
+
178
+
179
+ }// Rays
data/ext/rays/matrix.cpp CHANGED
@@ -10,60 +10,25 @@ using namespace Rucy;
10
10
 
11
11
  static Class cMatrix;
12
12
 
13
+ RUCY_DEFINE_VALUE_FROM_TO(Rays::Matrix, cMatrix)
13
14
 
14
- namespace Rays
15
- {
16
-
17
-
18
- Class
19
- matrix_class ()
20
- {
21
- return cMatrix;
22
- }
23
-
24
-
25
- }// Rays
26
-
27
-
28
- namespace Rucy
29
- {
30
-
31
-
32
- Value
33
- value (const Rays::Matrix& obj)
34
- {
35
- return new_type(cMatrix, new Rays::Matrix(obj));
36
- }
37
-
38
- Value
39
- value (const Rays::Matrix* obj)
40
- {
41
- return obj ? value(*obj) : nil();
42
- }
43
-
44
-
45
- }// Rucy
15
+ #define THIS to<Rays::Matrix*>(self)
46
16
 
47
-
48
- #define THIS to<Rays::Matrix*>(self)
49
-
50
- #define CHECK RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix)
17
+ #define CHECK RUCY_CHECK_OBJ(Rays::Matrix, cMatrix, self)
51
18
 
52
19
 
53
20
  static
54
- RUBY_DEF_ALLOC(alloc, klass)
21
+ RUCY_DEF_ALLOC(alloc, klass)
55
22
  {
56
23
  return new_type<Rays::Matrix>(klass);
57
24
  }
58
- RUBY_END
25
+ RUCY_END
59
26
 
60
27
  static
61
- RUBY_DEFN(initialize)
28
+ RUCY_DEFN(initialize)
62
29
  {
63
- RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix);
64
-
65
- if (argc != 0 && argc != 1 && argc != 16)
66
- arg_count_error("Matrix#initialize", argc, 0, 1, 16);
30
+ CHECK;
31
+ check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
67
32
 
68
33
  if (argc == 0) return self;
69
34
 
@@ -84,28 +49,22 @@ RUBY_DEFN(initialize)
84
49
 
85
50
  return self;
86
51
  }
87
- RUBY_END
52
+ RUCY_END
88
53
 
89
54
  static
90
- RUBY_DEF1(initialize_copy, obj)
55
+ RUCY_DEF1(initialize_copy, obj)
91
56
  {
92
- RUCY_CHECK_OBJ(self, Rays::Matrix, cMatrix);
93
-
94
- Rays::Matrix* matrix = to<Rays::Matrix*>(obj);
95
- if (!matrix) argument_error();
96
-
97
- *THIS = *matrix;
57
+ CHECK;
58
+ *THIS = to<Rays::Matrix&>(obj);
98
59
  return self;
99
60
  }
100
- RUBY_END
61
+ RUCY_END
101
62
 
102
63
  static
103
- RUBY_DEFN(set)
64
+ RUCY_DEFN(set)
104
65
  {
105
66
  CHECK;
106
-
107
- if (argc != 0 && argc != 1 && argc != 16)
108
- arg_count_error("Matrix#initialize", argc, 0, 1, 16);
67
+ check_arg_count(__FILE__, __LINE__, "Matrix#initialize", argc, 0, 1, 16);
109
68
 
110
69
  switch (argc)
111
70
  {
@@ -128,16 +87,15 @@ RUBY_DEFN(set)
128
87
 
129
88
  return self;
130
89
  }
131
- RUBY_END
90
+ RUCY_END
132
91
 
133
92
  static
134
- RUBY_DEF2(at, row, column)
93
+ RUCY_DEF2(at, row, column)
135
94
  {
136
95
  CHECK;
137
-
138
96
  return value(THIS->at(row.as_i(), column.as_i()));
139
97
  }
140
- RUBY_END
98
+ RUCY_END
141
99
 
142
100
 
143
101
  void
@@ -152,3 +110,17 @@ Init_matrix ()
152
110
  cMatrix.define_method("set", set);
153
111
  cMatrix.define_method("at", at);
154
112
  }
113
+
114
+
115
+ namespace Rays
116
+ {
117
+
118
+
119
+ Class
120
+ matrix_class ()
121
+ {
122
+ return cMatrix;
123
+ }
124
+
125
+
126
+ }// Rays
data/ext/rays/native.cpp CHANGED
@@ -9,26 +9,33 @@ void Init_rays ();
9
9
  void Init_point ();
10
10
  void Init_bounds ();
11
11
  void Init_color ();
12
+ void Init_color_space ();
12
13
  void Init_bitmap ();
13
14
  void Init_texture ();
14
15
  void Init_image ();
15
16
  void Init_font ();
17
+ void Init_shader ();
16
18
  void Init_painter ();
17
19
 
18
20
 
19
21
  extern "C" void
20
22
  Init_native ()
21
23
  {
22
- if (!Rucy::init())
23
- raise(rb_eLoadError, "Rucy::init() failed.");
24
+ RUCY_TRY
25
+
26
+ Rucy::init();
24
27
 
25
28
  Init_rays();
26
29
  Init_point();
27
30
  Init_bounds();
28
31
  Init_color();
32
+ Init_color_space();
29
33
  Init_bitmap();
30
34
  Init_texture();
31
35
  Init_image();
32
36
  Init_font();
37
+ Init_shader();
33
38
  Init_painter();
39
+
40
+ RUCY_CATCH
34
41
  }