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
@@ -21,7 +21,7 @@ namespace Rays
21
21
  }// Rays
22
22
 
23
23
 
24
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Matrix)
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Matrix)
25
25
 
26
26
 
27
27
  namespace Rucy
@@ -22,7 +22,7 @@ namespace Rays
22
22
  }// Rays
23
23
 
24
24
 
25
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Point)
25
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Point)
26
26
 
27
27
 
28
28
  namespace Rucy
@@ -0,0 +1,52 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_POLYGON_H__
4
+ #define __RAYS_RUBY_POLYGON_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rays/polygon.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ Rucy::Class polygon_class ();
18
+ // class Rays::Polygon
19
+
20
+ Rucy::Class polygon_line_class ();
21
+ // class Rays::Polygon::Line
22
+
23
+
24
+ }// Rays
25
+
26
+
27
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon)
28
+
29
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon::Line)
30
+
31
+
32
+ namespace Rucy
33
+ {
34
+
35
+
36
+ template <> inline Class
37
+ get_ruby_class<Rays::Polygon> ()
38
+ {
39
+ return Rays::polygon_class();
40
+ }
41
+
42
+ template <> inline Class
43
+ get_ruby_class<Rays::Polygon::Line> ()
44
+ {
45
+ return Rays::polygon_line_class();
46
+ }
47
+
48
+
49
+ }// Rucy
50
+
51
+
52
+ #endif//EOH
@@ -0,0 +1,41 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_POLYLINE_H__
4
+ #define __RAYS_RUBY_POLYLINE_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rays/polyline.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ Rucy::Class polyline_class ();
18
+ // class Rays::Polyline
19
+
20
+
21
+ }// Rays
22
+
23
+
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Polyline)
25
+
26
+
27
+ namespace Rucy
28
+ {
29
+
30
+
31
+ template <> inline Class
32
+ get_ruby_class<Rays::Polyline> ()
33
+ {
34
+ return Rays::polyline_class();
35
+ }
36
+
37
+
38
+ }// Rucy
39
+
40
+
41
+ #endif//EOH
@@ -21,7 +21,7 @@ namespace Rays
21
21
  }// Rays
22
22
 
23
23
 
24
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Shader)
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Shader)
25
25
 
26
26
 
27
27
  namespace Rucy
@@ -5,13 +5,17 @@
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
8
- #include "rays/opengl.h"
8
+ #include <rays/defs.h>
9
+ #include <rays/coord.h>
9
10
 
10
11
 
11
12
  namespace Rays
12
13
  {
13
14
 
14
15
 
16
+ class Image;
17
+
18
+
15
19
  class Shader
16
20
  {
17
21
 
@@ -19,25 +23,49 @@ namespace Rays
19
23
 
20
24
  public:
21
25
 
22
- Shader ();
23
-
24
- Shader (const char* source);
26
+ Shader (const char* source = NULL);
25
27
 
26
28
  ~Shader ();
27
29
 
28
- GLuint id () const;
30
+ void set_uniform (const char* name, int arg1);
31
+
32
+ void set_uniform (const char* name, int arg1, int arg2);
33
+
34
+ void set_uniform (const char* name, int arg1, int arg2, int arg3);
35
+
36
+ void set_uniform (const char* name, int arg1, int arg2, int arg3, int arg4);
37
+
38
+ void set_uniform (const char* name, const int* args, size_t size);
39
+
40
+ void set_uniform (const char* name, float arg1);
29
41
 
30
- bool operator == (const Shader& rhs) const;
42
+ void set_uniform (const char* name, float arg1, float arg2);
31
43
 
32
- bool operator != (const Shader& rhs) const;
44
+ void set_uniform (const char* name, float arg1, float arg2, float arg3);
45
+
46
+ void set_uniform (const char* name, float arg1, float arg2, float arg3, float arg4);
47
+
48
+ void set_uniform (const char* name, const float* args, size_t size);
49
+
50
+ void set_uniform (const char* name, const Coord2& vec2);
51
+
52
+ void set_uniform (const char* name, const Coord3& vec3);
53
+
54
+ void set_uniform (const char* name, const Coord4& vec4);
55
+
56
+ void set_uniform (const char* name, const Image& texture);
33
57
 
34
58
  operator bool () const;
35
59
 
36
60
  bool operator ! () const;
37
61
 
62
+ friend bool operator == (const This& lhs, const This& rhs);
63
+
64
+ friend bool operator != (const This& lhs, const This& rhs);
65
+
38
66
  struct Data;
39
67
 
40
- Xot::PImpl<Data, true> self;
68
+ Xot::PSharedImpl<Data> self;
41
69
 
42
70
  };// Shader
43
71
 
@@ -8,9 +8,14 @@ require 'rays/point'
8
8
  require 'rays/bounds'
9
9
  require 'rays/color'
10
10
  require 'rays/color_space'
11
+ require 'rays/matrix'
12
+
13
+ require 'rays/polyline'
14
+ require 'rays/polygon'
15
+ require 'rays/polygon_line'
11
16
  require 'rays/bitmap'
12
- require 'rays/texture'
13
17
  require 'rays/image'
14
18
  require 'rays/font'
15
19
  require 'rays/shader'
20
+
16
21
  require 'rays/painter'
@@ -2,7 +2,6 @@
2
2
 
3
3
 
4
4
  require 'rays/ext'
5
- require 'rays/color_space'
6
5
 
7
6
 
8
7
  module Rays
@@ -12,10 +11,6 @@ module Rays
12
11
 
13
12
  include Enumerable
14
13
 
15
- def initialize (width, height, color_space = :RGBA)
16
- setup width, height, ColorSpace.get_color_space(color_space)
17
- end
18
-
19
14
  def each ()
20
15
  height.times do |y|
21
16
  width.times do |x|
@@ -32,16 +27,6 @@ module Rays
32
27
  map {|o| o}
33
28
  end
34
29
 
35
- def []= (x, y, *args)
36
- args.flatten!
37
- case args[0]
38
- when Color
39
- set_at x, y, args[0]
40
- when Numeric
41
- set_at x, y, *args
42
- end
43
- end
44
-
45
30
  end# Bitmap
46
31
 
47
32
 
@@ -11,40 +11,29 @@ module Rays
11
11
  class Bounds
12
12
 
13
13
  include Comparable
14
+ include Enumerable
14
15
 
15
- alias w width
16
16
  alias w= width=
17
+ alias w width
17
18
 
18
- alias h height
19
19
  alias h= height=
20
+ alias h height
20
21
 
21
- alias d depth
22
22
  alias d= depth=
23
+ alias d depth
23
24
 
24
- def position= (*args)
25
- set_position *Point.from(*args).to_a(3)
26
- end
27
-
28
- alias pos position
29
25
  alias pos= position=
26
+ alias pos position
30
27
 
31
- def size= (*args)
32
- set_size *Point.from(*args).to_a(3)
33
- end
34
-
35
- def center= (*args)
36
- set_center *Point.from(*args).to_a(3)
37
- end
38
-
39
- alias left_top position
40
- def right_top () position.move_by w - 1, 0 end
41
- def left_bottom () position.move_by 0, h - 1 end
28
+ alias left_top position
29
+ def right_top () position .move_by w - 1, 0 end
30
+ def left_bottom () position .move_by 0, h - 1 end
42
31
  def right_bottom () (position + size).move_by! -1, -1 end
43
32
 
44
- def left_top= (*args) p = Point.from *args; self.left, self.top = p.x, p.y; left_top end
45
- def right_top= (*args) p = Point.from *args; self.right, self.top = p.x, p.y; right_top end
46
- def left_bottom= (*args) p = Point.from *args; self.left, self.bottom = p.x, p.y; left_bottom end
47
- def right_bottom= (*args) p = Point.from *args; self.right, self.bottom = p.x, p.y; right_bottom end
33
+ def left_top= (*args) p = Point.new *args; self.left, self.top = p.x, p.y; left_top end
34
+ def right_top= (*args) p = Point.new *args; self.right, self.top = p.x, p.y; right_top end
35
+ def left_bottom= (*args) p = Point.new *args; self.left, self.bottom = p.x, p.y; left_bottom end
36
+ def right_bottom= (*args) p = Point.new *args; self.right, self.bottom = p.x, p.y; right_bottom end
48
37
 
49
38
  alias lt left_top
50
39
  alias lt= left_top=
@@ -75,7 +64,12 @@ module Rays
75
64
  dup.inset_by! *args
76
65
  end
77
66
 
67
+ def each (dimension = 2, &block)
68
+ to_a(dimension).each &block
69
+ end
70
+
78
71
  def to_a (dimension = 2)
72
+ # TODO: return [lt, rb]
79
73
  case dimension
80
74
  when 1 then [x, w]
81
75
  when 2 then [x, y, w, h]
@@ -10,24 +10,19 @@ module Rays
10
10
  class Color
11
11
 
12
12
  include Comparable
13
+ include Enumerable
13
14
 
14
- def self.color (*args)
15
- c = case arg0 = args[0]
16
- when Color then arg0
17
- when Symbol then COLORS[arg0]
18
- when /^\s*#[\da-fA-F]+\s*$/ then Color.new arg0
19
- when String then COLORS[arg0.intern]
20
- else Color.new *args
21
- end
22
- raise ArgumentError, "invalid argument '#{args}.'" unless c
23
- c
24
- end
15
+ alias r= red=
16
+ alias r red
25
17
 
26
- def initialize (*args)
27
- arg0 = args[0]
28
- args = parse arg0 if arg0 && arg0.kind_of?(String)
29
- setup *args
30
- end
18
+ alias g= green=
19
+ alias g green
20
+
21
+ alias b= blue=
22
+ alias b blue
23
+
24
+ alias a= alpha=
25
+ alias a alpha
31
26
 
32
27
  def opaque? ()
33
28
  alpha >= 1
@@ -42,12 +37,16 @@ module Rays
42
37
  0 < a && a < 1
43
38
  end
44
39
 
40
+ def each (&block)
41
+ to_a.each &block
42
+ end
43
+
45
44
  def to_a ()
46
45
  [red, green, blue, alpha]
47
46
  end
48
47
 
49
48
  def to_s ()
50
- to_a.map {|o| o.to_s}
49
+ to_a.to_s
51
50
  end
52
51
 
53
52
  def [] (index)
@@ -77,6 +76,10 @@ module Rays
77
76
  alpha <=> o.alpha
78
77
  end
79
78
 
79
+ def hash ()
80
+ red.hash + green.hash + blue.hash + alpha.hash
81
+ end
82
+
80
83
  def eql? (o)
81
84
  self == o
82
85
  end
@@ -85,36 +88,6 @@ module Rays
85
88
  "#<#{self.class.name} #{to_s}>"
86
89
  end
87
90
 
88
- COLORS = {
89
- black: [0, 0, 0],
90
- red: [1, 0, 0],
91
- green: [0, 1, 0],
92
- blue: [0, 0, 1],
93
- yellow: [1, 1, 0],
94
- cyan: [0, 1, 1],
95
- magenta: [1, 0, 1],
96
- white: [1, 1, 1],
97
- gray: [0.5, 0.5, 0.5],
98
- no: [0, 0],
99
- none: [0, 0],
100
- nil: [0, 0],
101
- }.inject({}) {|h, (k, v)| h[k] = Color.new *v; h}
102
-
103
- private
104
-
105
- RE_RGBA = /^\s*##{'([\da-fA-F]{1})' * 4}?\s*$/
106
- RE_RRGGBBAA = /^\s*##{'([\da-fA-F]{2})' * 4}?\s*$/
107
-
108
- def parse (str)
109
- case str
110
- when RE_RGBA
111
- [$1, $2, $3, $4 || 'f' ].map {|s| s.to_i(16) / 15.0}
112
- when RE_RRGGBBAA
113
- [$1, $2, $3, $4 || 'ff'].map {|s| s.to_i(16) / 255.0}
114
- else raise ArgumentError, "can not parse '#{str}'."
115
- end
116
- end
117
-
118
91
  end# Color
119
92
 
120
93
 
@@ -9,25 +9,25 @@ module Rays
9
9
 
10
10
  class ColorSpace
11
11
 
12
- def initialize (type = :RGBA, premultiplied = true)
13
- setup self.class.get_type(type), premultiplied
12
+ include Comparable
13
+
14
+ def <=> (o)
15
+ type <=> o.type
16
+ end
17
+
18
+ def hash ()
19
+ type.hash
14
20
  end
15
21
 
16
- def self.get_type (obj)
17
- case obj
18
- when Integer then obj
19
- when String, Symbol then const_get obj
20
- else raise ArgumentError, "can not convert '#{obj}' to ColorSpace type."
21
- end
22
- rescue NameError
23
- raise "ColoeSpace::#{obj} is not found."
22
+ def eql? (o)
23
+ self == o
24
24
  end
25
25
 
26
- def self.get_color_space (obj)
27
- (ColorSpace === obj) ? obj : (ColorSpace.new get_type(obj))
26
+ def inspect ()
27
+ "#<#{self.class.name} #{to_s}>"
28
28
  end
29
29
 
30
- end# ColorSpace
30
+ end# Color
31
31
 
32
32
 
33
33
  end# Rays