rays 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -0,0 +1,99 @@
1
+ #include "rays/ruby/polygon.h"
2
+
3
+
4
+ #include "rays/ruby/polyline.h"
5
+ #include "defs.h"
6
+
7
+
8
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon::Line)
9
+
10
+ #define THIS to<Rays::Polygon::Line*>(self)
11
+
12
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Polygon::Line, self)
13
+
14
+
15
+ static
16
+ RUCY_DEF_ALLOC(alloc, klass)
17
+ {
18
+ return new_type<Rays::Polygon::Line>(klass);
19
+ }
20
+ RUCY_END
21
+
22
+ static
23
+ RUCY_DEF3(setup, points, loop, hole)
24
+ {
25
+ CHECK;
26
+
27
+ std::vector<Rays::Point> array;
28
+ get_line_args(&array, points.size(), points.as_array());
29
+ *THIS = Rays::Polygon::Line(&array[0], array.size(), loop, hole);
30
+ }
31
+ RUCY_END
32
+
33
+ static
34
+ RUCY_DEF0(hole)
35
+ {
36
+ CHECK;
37
+ return value(THIS->hole());
38
+ }
39
+ RUCY_END
40
+
41
+
42
+ static Class cPolygonLine;
43
+
44
+ void
45
+ Init_polygon_line ()
46
+ {
47
+ Module mRays = define_module("Rays");
48
+ Class cPolygon = mRays.define_class("Polygon");
49
+
50
+ cPolygonLine = cPolygon.define_class("Line", Rays::polyline_class());
51
+ cPolygonLine.define_alloc_func(alloc);
52
+ cPolygonLine.define_private_method("setup", setup);
53
+ cPolygonLine.define_method("hole?", hole);
54
+ }
55
+
56
+
57
+ namespace Rucy
58
+ {
59
+
60
+
61
+ template <> Rays::Polygon::Line
62
+ value_to<Rays::Polygon::Line> (int argc, const Value* argv, bool convert)
63
+ {
64
+ assert(argc == 0 || (argc > 0 && argv));
65
+
66
+ if (convert)
67
+ {
68
+ if (argc <= 0)
69
+ return Rays::Polygon::Line();
70
+ else if (argv->is_num() || argv->is_array())
71
+ {
72
+ std::vector<Rays::Point> points;
73
+ get_line_args(&points, argc, argv);
74
+ return Rays::Polygon::Line(&points[0], points.size());
75
+ }
76
+ }
77
+
78
+ if (argc != 1)
79
+ argument_error(__FILE__, __LINE__);
80
+
81
+ return value_to<Rays::Polygon::Line&>(*argv, convert);
82
+ }
83
+
84
+
85
+ }// Rucy
86
+
87
+
88
+ namespace Rays
89
+ {
90
+
91
+
92
+ Class
93
+ polygon_line_class ()
94
+ {
95
+ return cPolygonLine;
96
+ }
97
+
98
+
99
+ }// Rays
@@ -0,0 +1,170 @@
1
+ #include "rays/ruby/polyline.h"
2
+
3
+
4
+ #include <vector>
5
+ #include "rays/ruby/point.h"
6
+ #include "rays/ruby/bounds.h"
7
+ #include "rays/ruby/polygon.h"
8
+ #include "defs.h"
9
+
10
+
11
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Polyline)
12
+
13
+ #define THIS to<Rays::Polyline*>(self)
14
+
15
+ #define CHECK RUCY_CHECK_OBJECT(Rays::Polyline, self)
16
+
17
+
18
+ static
19
+ RUCY_DEF_ALLOC(alloc, klass)
20
+ {
21
+ return new_type<Rays::Polyline>(klass);
22
+ }
23
+ RUCY_END
24
+
25
+ static
26
+ RUCY_DEF2(setup, points, loop)
27
+ {
28
+ CHECK;
29
+
30
+ std::vector<Rays::Point> array;
31
+ get_line_args(&array, points.size(), points.as_array());
32
+ *THIS = Rays::Polyline(&array[0], array.size(), loop);
33
+ }
34
+ RUCY_END
35
+
36
+ static
37
+ RUCY_DEF1(expand, width)
38
+ {
39
+ CHECK;
40
+
41
+ Rays::Polygon polygon;
42
+ THIS->expand(&polygon, to<coord>(width));
43
+ return value(polygon);
44
+ }
45
+ RUCY_END
46
+
47
+ static
48
+ RUCY_DEF0(bounds)
49
+ {
50
+ CHECK;
51
+ return value(THIS->bounds());
52
+ }
53
+ RUCY_END
54
+
55
+ static
56
+ RUCY_DEF0(loop)
57
+ {
58
+ CHECK;
59
+ return value(THIS->loop());
60
+ }
61
+ RUCY_END
62
+
63
+ static
64
+ RUCY_DEF0(size)
65
+ {
66
+ CHECK;
67
+ return value(THIS->size());
68
+ }
69
+ RUCY_END
70
+
71
+ static
72
+ RUCY_DEF0(empty)
73
+ {
74
+ CHECK;
75
+ return value(THIS->empty());
76
+ }
77
+ RUCY_END
78
+
79
+ static
80
+ RUCY_DEF1(at, index)
81
+ {
82
+ CHECK;
83
+
84
+ int size = (int) THIS->size();
85
+ int i = to<int>(index);
86
+ if (i < 0) i += size;
87
+
88
+ if (i < 0 || size <= i)
89
+ index_error(__FILE__, __LINE__);
90
+
91
+ return value((*THIS)[i]);
92
+ }
93
+ RUCY_END
94
+
95
+ static
96
+ RUCY_DEF0(each)
97
+ {
98
+ CHECK;
99
+
100
+ Value ret;
101
+ for (const auto& point : *THIS)
102
+ ret = rb_yield(value(point));
103
+ return ret;
104
+ }
105
+ RUCY_END
106
+
107
+
108
+ static Class cPolyline;
109
+
110
+ void
111
+ Init_polyline ()
112
+ {
113
+ Module mRays = define_module("Rays");
114
+
115
+ cPolyline = mRays.define_class("Polyline");
116
+ cPolyline.define_alloc_func(alloc);
117
+ cPolyline.define_private_method("setup", setup);
118
+ cPolyline.define_method("expand", expand);
119
+ cPolyline.define_method("bounds", bounds);
120
+ cPolyline.define_method("loop?", loop);
121
+ cPolyline.define_method("size", size);
122
+ cPolyline.define_method("empty?", empty);
123
+ cPolyline.define_method("[]", at);
124
+ cPolyline.define_method("each", each);
125
+ }
126
+
127
+
128
+ namespace Rucy
129
+ {
130
+
131
+
132
+ template <> Rays::Polyline
133
+ value_to<Rays::Polyline> (int argc, const Value* argv, bool convert)
134
+ {
135
+ assert(argc == 0 || (argc > 0 && argv));
136
+
137
+ if (convert)
138
+ {
139
+ if (argc <= 0)
140
+ return Rays::Polyline();
141
+ else if (argv->is_num() || argv->is_array())
142
+ {
143
+ std::vector<Rays::Point> points;
144
+ get_line_args(&points, argc, argv);
145
+ return Rays::Polyline(&points[0], points.size());
146
+ }
147
+ }
148
+
149
+ if (argc != 1)
150
+ argument_error(__FILE__, __LINE__);
151
+
152
+ return value_to<Rays::Polyline&>(*argv, convert);
153
+ }
154
+
155
+
156
+ }// Rucy
157
+
158
+
159
+ namespace Rays
160
+ {
161
+
162
+
163
+ Class
164
+ polyline_class ()
165
+ {
166
+ return cPolyline;
167
+ }
168
+
169
+
170
+ }// Rays
@@ -1,12 +1,7 @@
1
- #include <rucy.h>
2
1
  #include "rays/rays.h"
3
- #include "rays/opengl.h"
4
2
  #include "defs.h"
5
3
 
6
4
 
7
- using namespace Rucy;
8
-
9
-
10
5
  static
11
6
  RUCY_DEF0(init)
12
7
  {
@@ -23,14 +18,6 @@ RUCY_DEF0(fin)
23
18
  }
24
19
  RUCY_END
25
20
 
26
- static
27
- RUCY_DEF0(init_offscreen_context)
28
- {
29
- Rays::init_offscreen_context();
30
- return self;
31
- }
32
- RUCY_END
33
-
34
21
 
35
22
  static Module mRays;
36
23
 
@@ -40,7 +27,6 @@ Init_rays ()
40
27
  mRays = define_module("Rays");
41
28
  mRays.define_singleton_method("init!", init);
42
29
  mRays.define_singleton_method("fin!", fin);
43
- mRays.define_singleton_method("init_offscreen_context", init_offscreen_context);
44
30
  }
45
31
 
46
32
 
@@ -1,14 +1,10 @@
1
1
  #include "rays/ruby/shader.h"
2
2
 
3
3
 
4
- #include <rucy.h>
5
4
  #include "defs.h"
6
5
 
7
6
 
8
- using namespace Rucy;
9
-
10
-
11
- RUCY_DEFINE_VALUE_FROM_TO(Rays::Shader)
7
+ RUCY_DEFINE_VALUE_OR_ARRAY_FROM_TO(Rays::Shader)
12
8
 
13
9
  #define THIS to<Rays::Shader*>(self)
14
10
 
@@ -23,14 +19,61 @@ RUCY_DEF_ALLOC(alloc, klass)
23
19
  RUCY_END
24
20
 
25
21
  static
26
- RUCY_DEF1(initialize, source)
22
+ RUCY_DEF1(setup, source)
27
23
  {
28
24
  RUCY_CHECK_OBJ(Rays::Shader, self);
29
25
 
30
- if (!source.is_s())
26
+ *THIS = to<Rays::Shader>(source);
27
+ }
28
+ RUCY_END
29
+
30
+ static
31
+ RUCY_DEFN(set_uniform)
32
+ {
33
+ CHECK;
34
+ check_arg_count(__FILE__, __LINE__, "Painter#set_uniform", argc, 2, 3, 4, 5);
35
+
36
+ #define Ai(n) (argv[n].as_i())
37
+ #define Af(n) ((float) argv[n].as_f())
38
+
39
+ const char* name = argv[0].c_str();
40
+ if (argv[1].is_array())
41
+ {
42
+ argc = argv[1].size();
43
+ argv = argv[1].as_array();
44
+ }
45
+ else
46
+ {
47
+ argc -= 1;
48
+ argv += 1;
49
+ }
50
+
51
+ if (argv[0].is_i())
52
+ {
53
+ switch (argc)
54
+ {
55
+ case 1: THIS->set_uniform(name, Ai(0)); break;
56
+ case 2: THIS->set_uniform(name, Ai(0), Ai(1)); break;
57
+ case 3: THIS->set_uniform(name, Ai(0), Ai(1), Ai(2)); break;
58
+ case 4: THIS->set_uniform(name, Ai(0), Ai(1), Ai(2), Ai(3)); break;
59
+ }
60
+ }
61
+ else if (argv[0].is_f())
62
+ {
63
+ switch (argc)
64
+ {
65
+ case 1: THIS->set_uniform(name, Af(0)); break;
66
+ case 2: THIS->set_uniform(name, Af(0), Af(1)); break;
67
+ case 3: THIS->set_uniform(name, Af(0), Af(1), Af(2)); break;
68
+ case 4: THIS->set_uniform(name, Af(0), Af(1), Af(2), Af(3)); break;
69
+ }
70
+ }
71
+ else
31
72
  argument_error(__FILE__, __LINE__);
32
73
 
33
- *THIS = Rays::Shader(source.c_str());
74
+ #undef Ai
75
+ #undef Af
76
+
34
77
  return self;
35
78
  }
36
79
  RUCY_END
@@ -45,10 +88,42 @@ Init_shader ()
45
88
 
46
89
  cShader = mRays.define_class("Shader");
47
90
  cShader.define_alloc_func(alloc);
48
- cShader.define_private_method("initialize", initialize);
91
+ cShader.define_private_method("setup", setup);
92
+ cShader.define_private_method("set_uniform", set_uniform);
49
93
  }
50
94
 
51
95
 
96
+ namespace Rucy
97
+ {
98
+
99
+
100
+ template <> Rays::Shader
101
+ value_to<Rays::Shader> (int argc, const Value* argv, bool convert)
102
+ {
103
+ if (argc == 1 && argv->is_array())
104
+ {
105
+ argc = argv->size();
106
+ argv = argv->as_array();
107
+ }
108
+
109
+ assert(argc > 0 && argv);
110
+
111
+ if (convert)
112
+ {
113
+ if (argv->is_s())
114
+ return Rays::Shader(argv[0].c_str());
115
+ }
116
+
117
+ if (argc != 1)
118
+ argument_error(__FILE__, __LINE__);
119
+
120
+ return value_to<Rays::Shader&>(*argv, convert);
121
+ }
122
+
123
+
124
+ }// Rucy
125
+
126
+
52
127
  namespace Rays
53
128
  {
54
129
 
@@ -7,15 +7,23 @@
7
7
  #include <rays/defs.h>
8
8
  #include <rays/rays.h>
9
9
  #include <rays/exception.h>
10
+ #include <rays/debug.h>
11
+
12
+ #include <rays/coord.h>
10
13
  #include <rays/point.h>
14
+ #include <rays/bounds.h>
15
+ #include <rays/color.h>
11
16
  #include <rays/color_space.h>
17
+ #include <rays/matrix.h>
18
+
19
+ #include <rays/polyline.h>
20
+ #include <rays/polygon.h>
12
21
  #include <rays/bitmap.h>
13
- #include <rays/texture.h>
14
22
  #include <rays/image.h>
15
23
  #include <rays/font.h>
16
24
  #include <rays/shader.h>
25
+
17
26
  #include <rays/painter.h>
18
- #include <rays/opengl.h>
19
27
 
20
28
 
21
29
  #endif//EOH