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,96 @@
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
+ VALUE alloc(VALUE klass)
17
+ {
18
+ return new_type<Rays::Polygon::Line>(klass);
19
+ }
20
+
21
+ static
22
+ VALUE setup(VALUE self, VALUE points, VALUE loop, VALUE hole)
23
+ {
24
+ CHECK;
25
+
26
+ std::vector<Rays::Point> array;
27
+ get_line_args(&array, points.size(), points.as_array());
28
+ *THIS = Rays::Polygon::Line(&array[0], array.size(), loop, hole);
29
+ }
30
+
31
+ static
32
+ VALUE hole(VALUE self)
33
+ {
34
+ CHECK;
35
+ return value(THIS->hole());
36
+ }
37
+
38
+
39
+ static Class cPolygonLine;
40
+
41
+ void
42
+ Init_polygon_line ()
43
+ {
44
+ Module mRays = rb_define_module("Rays");
45
+ Class cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
46
+
47
+ cPolygonLine = cPolygon.define_class("Line", Rays::polyline_class());
48
+ rb_define_alloc_func(cPolygonLine, alloc);
49
+ rb_define_private_method(cPolygonLine, "setup", RUBY_METHOD_FUNC(setup), 3);
50
+ cPolygonLine.define_method("hole?", hole);
51
+ }
52
+
53
+
54
+ namespace Rucy
55
+ {
56
+
57
+
58
+ template <> Rays::Polygon::Line
59
+ value_to<Rays::Polygon::Line> (int argc, const Value* argv, bool convert)
60
+ {
61
+ assert(argc == 0 || (argc > 0 && argv));
62
+
63
+ if (convert)
64
+ {
65
+ if (argc <= 0)
66
+ return Rays::Polygon::Line();
67
+ else if (argv->is_num() || argv->is_array())
68
+ {
69
+ std::vector<Rays::Point> points;
70
+ get_line_args(&points, argc, argv);
71
+ return Rays::Polygon::Line(&points[0], points.size());
72
+ }
73
+ }
74
+
75
+ if (argc != 1)
76
+ argument_error(__FILE__, __LINE__);
77
+
78
+ return value_to<Rays::Polygon::Line&>(*argv, convert);
79
+ }
80
+
81
+
82
+ }// Rucy
83
+
84
+
85
+ namespace Rays
86
+ {
87
+
88
+
89
+ Class
90
+ polygon_line_class ()
91
+ {
92
+ return cPolygonLine;
93
+ }
94
+
95
+
96
+ }// Rays
@@ -0,0 +1,161 @@
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
+ VALUE alloc(VALUE klass)
20
+ {
21
+ return new_type<Rays::Polyline>(klass);
22
+ }
23
+
24
+ static
25
+ VALUE setup(VALUE self, VALUE points, VALUE loop)
26
+ {
27
+ CHECK;
28
+
29
+ std::vector<Rays::Point> array;
30
+ get_line_args(&array, points.size(), points.as_array());
31
+ *THIS = Rays::Polyline(&array[0], array.size(), loop);
32
+ }
33
+
34
+ static
35
+ VALUE expand(VALUE self, VALUE width)
36
+ {
37
+ CHECK;
38
+
39
+ Rays::Polygon polygon;
40
+ THIS->expand(&polygon, to<coord>(width));
41
+ return value(polygon);
42
+ }
43
+
44
+ static
45
+ VALUE bounds(VALUE self)
46
+ {
47
+ CHECK;
48
+ return value(THIS->bounds());
49
+ }
50
+
51
+ static
52
+ VALUE loop(VALUE self)
53
+ {
54
+ CHECK;
55
+ return value(THIS->loop());
56
+ }
57
+
58
+ static
59
+ VALUE size(VALUE self)
60
+ {
61
+ CHECK;
62
+ return value(THIS->size());
63
+ }
64
+
65
+ static
66
+ VALUE empty(VALUE self)
67
+ {
68
+ CHECK;
69
+ return value(THIS->empty());
70
+ }
71
+
72
+ static
73
+ VALUE at(VALUE self, VALUE index)
74
+ {
75
+ CHECK;
76
+
77
+ int size = (int) THIS->size();
78
+ int i = to<int>(index);
79
+ if (i < 0) i += size;
80
+
81
+ if (i < 0 || size <= i)
82
+ index_error(__FILE__, __LINE__);
83
+
84
+ return value((*THIS)[i]);
85
+ }
86
+
87
+ static
88
+ VALUE each(VALUE self)
89
+ {
90
+ CHECK;
91
+
92
+ Value ret;
93
+ for (const auto& point : *THIS)
94
+ ret = rb_yield(value(point));
95
+ return ret;
96
+ }
97
+
98
+
99
+ static Class cPolyline;
100
+
101
+ void
102
+ Init_polyline ()
103
+ {
104
+ Module mRays = rb_define_module("Rays");
105
+
106
+ cPolyline = rb_define_class_under(mRays, "Polyline", rb_cObject);
107
+ rb_define_alloc_func(cPolyline, alloc);
108
+ rb_define_private_method(cPolyline, "setup", RUBY_METHOD_FUNC(setup), 2);
109
+ rb_define_method(cPolyline, "expand", RUBY_METHOD_FUNC(expand), 1);
110
+ rb_define_method(cPolyline, "bounds", RUBY_METHOD_FUNC(bounds), 0);
111
+ cPolyline.define_method("loop?", loop);
112
+ rb_define_method(cPolyline, "size", RUBY_METHOD_FUNC(size), 0);
113
+ cPolyline.define_method("empty?", empty);
114
+ cPolyline.define_method("[]", at);
115
+ rb_define_method(cPolyline, "each", RUBY_METHOD_FUNC(each), 0);
116
+ }
117
+
118
+
119
+ namespace Rucy
120
+ {
121
+
122
+
123
+ template <> Rays::Polyline
124
+ value_to<Rays::Polyline> (int argc, const Value* argv, bool convert)
125
+ {
126
+ assert(argc == 0 || (argc > 0 && argv));
127
+
128
+ if (convert)
129
+ {
130
+ if (argc <= 0)
131
+ return Rays::Polyline();
132
+ else if (argv->is_num() || argv->is_array())
133
+ {
134
+ std::vector<Rays::Point> points;
135
+ get_line_args(&points, argc, argv);
136
+ return Rays::Polyline(&points[0], points.size());
137
+ }
138
+ }
139
+
140
+ if (argc != 1)
141
+ argument_error(__FILE__, __LINE__);
142
+
143
+ return value_to<Rays::Polyline&>(*argv, convert);
144
+ }
145
+
146
+
147
+ }// Rucy
148
+
149
+
150
+ namespace Rays
151
+ {
152
+
153
+
154
+ Class
155
+ polyline_class ()
156
+ {
157
+ return cPolyline;
158
+ }
159
+
160
+
161
+ }// 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
  VALUE init(VALUE self)
12
7
  {
@@ -21,13 +16,6 @@ VALUE fin(VALUE self)
21
16
  return self;
22
17
  }
23
18
 
24
- static
25
- VALUE init_offscreen_context(VALUE self)
26
- {
27
- Rays::init_offscreen_context();
28
- return self;
29
- }
30
-
31
19
 
32
20
  static Module mRays;
33
21
 
@@ -37,7 +25,6 @@ Init_rays ()
37
25
  mRays = rb_define_module("Rays");
38
26
  mRays.define_singleton_method("init!", init);
39
27
  mRays.define_singleton_method("fin!", fin);
40
- rb_define_singleton_method(mRays, "init_offscreen_context", RUBY_METHOD_FUNC(init_offscreen_context), 0);
41
28
  }
42
29
 
43
30
 
@@ -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
 
@@ -22,14 +18,60 @@ VALUE alloc(VALUE klass)
22
18
  }
23
19
 
24
20
  static
25
- VALUE initialize(VALUE self, VALUE source)
21
+ VALUE setup(VALUE self, VALUE source)
26
22
  {
27
23
  RUCY_CHECK_OBJ(Rays::Shader, self);
28
24
 
29
- if (!source.is_s())
25
+ *THIS = to<Rays::Shader>(source);
26
+ }
27
+
28
+ static
29
+ VALUE set_uniform(VALUE self)
30
+ {
31
+ CHECK;
32
+ check_arg_count(__FILE__, __LINE__, "Painter#set_uniform", argc, 2, 3, 4, 5);
33
+
34
+ #define Ai(n) (argv[n].as_i())
35
+ #define Af(n) ((float) argv[n].as_f())
36
+
37
+ const char* name = argv[0].c_str();
38
+ if (argv[1].is_array())
39
+ {
40
+ argc = argv[1].size();
41
+ argv = argv[1].as_array();
42
+ }
43
+ else
44
+ {
45
+ argc -= 1;
46
+ argv += 1;
47
+ }
48
+
49
+ if (argv[0].is_i())
50
+ {
51
+ switch (argc)
52
+ {
53
+ case 1: THIS->set_uniform(name, Ai(0)); break;
54
+ case 2: THIS->set_uniform(name, Ai(0), Ai(1)); break;
55
+ case 3: THIS->set_uniform(name, Ai(0), Ai(1), Ai(2)); break;
56
+ case 4: THIS->set_uniform(name, Ai(0), Ai(1), Ai(2), Ai(3)); break;
57
+ }
58
+ }
59
+ else if (argv[0].is_f())
60
+ {
61
+ switch (argc)
62
+ {
63
+ case 1: THIS->set_uniform(name, Af(0)); break;
64
+ case 2: THIS->set_uniform(name, Af(0), Af(1)); break;
65
+ case 3: THIS->set_uniform(name, Af(0), Af(1), Af(2)); break;
66
+ case 4: THIS->set_uniform(name, Af(0), Af(1), Af(2), Af(3)); break;
67
+ }
68
+ }
69
+ else
30
70
  argument_error(__FILE__, __LINE__);
31
71
 
32
- *THIS = Rays::Shader(source.c_str());
72
+ #undef Ai
73
+ #undef Af
74
+
33
75
  return self;
34
76
  }
35
77
 
@@ -43,10 +85,42 @@ Init_shader ()
43
85
 
44
86
  cShader = rb_define_class_under(mRays, "Shader", rb_cObject);
45
87
  rb_define_alloc_func(cShader, alloc);
46
- rb_define_private_method(cShader, "initialize", RUBY_METHOD_FUNC(initialize), 1);
88
+ rb_define_private_method(cShader, "setup", RUBY_METHOD_FUNC(setup), 1);
89
+ rb_define_private_method(cShader, "set_uniform", RUBY_METHOD_FUNC(set_uniform), -1);
47
90
  }
48
91
 
49
92
 
93
+ namespace Rucy
94
+ {
95
+
96
+
97
+ template <> Rays::Shader
98
+ value_to<Rays::Shader> (int argc, const Value* argv, bool convert)
99
+ {
100
+ if (argc == 1 && argv->is_array())
101
+ {
102
+ argc = argv->size();
103
+ argv = argv->as_array();
104
+ }
105
+
106
+ assert(argc > 0 && argv);
107
+
108
+ if (convert)
109
+ {
110
+ if (argv->is_s())
111
+ return Rays::Shader(argv[0].c_str());
112
+ }
113
+
114
+ if (argc != 1)
115
+ argument_error(__FILE__, __LINE__);
116
+
117
+ return value_to<Rays::Shader&>(*argv, convert);
118
+ }
119
+
120
+
121
+ }// Rucy
122
+
123
+
50
124
  namespace Rays
51
125
  {
52
126
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  # Rays - A Drawing Engine using OpenGL.
3
3
 
4
- by snori@xord.org
4
+ by xordog@gmail.com
data/Rakefile CHANGED
@@ -2,25 +2,37 @@
2
2
 
3
3
 
4
4
  %w[../xot ../rucy .]
5
- .map {|s| File.expand_path "../#{s}/lib", __FILE__}
5
+ .map {|s| File.expand_path "#{s}/lib", __dir__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
- require 'xot/rake'
8
+ require 'rucy/rake'
9
+
9
10
  require 'xot/module'
10
11
  require 'rucy/module'
11
12
  require 'rays/module'
12
13
 
13
- include Xot::Rake
14
-
15
14
 
16
- MODULES = [Xot, Rucy, Rays].map {|m| m.const_get :Module}
17
- MODULE = MODULES.last
15
+ MODULES = [Xot, Rucy, Rays]
18
16
  TESTS_ALONE = ['test/test_rays.rb']
19
17
 
18
+ use_external_library 'https://github.com/g-truc/glm',
19
+ tag: '0.9.8.5',
20
+ srcdir: 'NOSRC'
20
21
 
21
- task :default => :build
22
+ use_external_library 'https://github.com/skyrpex/clipper',
23
+ tag: '6.4.2',
24
+ incdir: 'cpp',
25
+ srcdir: 'cpp',
26
+ excludes: 'clipper/cpp/cpp_'
22
27
 
23
- task :build => :ext
28
+ use_external_library 'https://github.com/greenm01/poly2tri',
29
+ incdir: 'poly2tri',
30
+ srcdir: 'poly2tri'
24
31
 
32
+ build_native_library
33
+ build_ruby_extension
34
+ test_ruby_extension
35
+ generate_documents
36
+ build_ruby_gem
25
37
 
26
- MODULES.each {|m| m.load_tasks :lib, :ext, :test, :doc, :gem}
38
+ task :default => :test