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
@@ -6,6 +6,8 @@
6
6
 
7
7
  #include <rucy/rucy.h>
8
8
  #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rucy/exception.h>
9
11
  #include <rays/point.h>
10
12
 
11
13
 
@@ -20,22 +22,7 @@ namespace Rays
20
22
  }// Rays
21
23
 
22
24
 
23
- namespace Rucy
24
- {
25
-
26
-
27
- Value value (const Rays::Point& obj);
28
-
29
- Value value (const Rays::Point* obj);
30
-
31
- template <> inline Rays::Point*
32
- value_to<Rays::Point*> (Value val, bool)
33
- {
34
- return get_type_ptr<Rays::Point>(val, Rays::point_class());
35
- }
36
-
37
-
38
- }// Rucy
25
+ RUCY_DECLARE_VALUE_FROM_TO(Rays::Point)
39
26
 
40
27
 
41
28
  #endif//EOH
@@ -0,0 +1,27 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_RUBY_SHADER_H__
4
+ #define __RAYS_RUBY_SHADER_H__
5
+
6
+
7
+ #include <rucy/rucy.h>
8
+ #include <rucy/class.h>
9
+ #include <rucy/extension.h>
10
+ #include <rays/shader.h>
11
+
12
+
13
+ namespace Rays
14
+ {
15
+
16
+
17
+ Rucy::Class shader_class ();
18
+ // class Rays::Shader
19
+
20
+
21
+ }// Rays
22
+
23
+
24
+ RUCY_DECLARE_VALUE_FROM_TO(Rays::Shader)
25
+
26
+
27
+ #endif//EOH
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include <rucy/rucy.h>
8
8
  #include <rucy/class.h>
9
+ #include <rucy/extension.h>
9
10
  #include <rays/texture.h>
10
11
 
11
12
 
@@ -20,22 +21,7 @@ namespace Rays
20
21
  }// Rays
21
22
 
22
23
 
23
- namespace Rucy
24
- {
25
-
26
-
27
- Value value (const Rays::Texture& obj);
28
-
29
- Value value (const Rays::Texture* obj);
30
-
31
- template <> inline Rays::Texture*
32
- value_to<Rays::Texture*> (Value val, bool)
33
- {
34
- return get_type_ptr<Rays::Texture>(val, Rays::texture_class());
35
- }
36
-
37
-
38
- }// Rucy
24
+ RUCY_DECLARE_VALUE_FROM_TO(Rays::Texture)
39
25
 
40
26
 
41
27
  #endif//EOH
data/include/rays/ruby.h CHANGED
@@ -12,6 +12,7 @@
12
12
  #include <rays/ruby/texture.h>
13
13
  #include <rays/ruby/image.h>
14
14
  #include <rays/ruby/font.h>
15
+ #include <rays/ruby/shader.h>
15
16
  #include <rays/ruby/painter.h>
16
17
 
17
18
 
@@ -0,0 +1,48 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_SHADER_H__
4
+ #define __RAYS_SHADER_H__
5
+
6
+
7
+ #include <xot/pimpl.h>
8
+ #include "rays/opengl.h"
9
+
10
+
11
+ namespace Rays
12
+ {
13
+
14
+
15
+ class Shader
16
+ {
17
+
18
+ typedef Shader This;
19
+
20
+ public:
21
+
22
+ Shader ();
23
+
24
+ Shader (const char* source);
25
+
26
+ ~Shader ();
27
+
28
+ GLuint id () const;
29
+
30
+ bool operator == (const Shader& rhs) const;
31
+
32
+ bool operator != (const Shader& rhs) const;
33
+
34
+ operator bool () const;
35
+
36
+ bool operator ! () const;
37
+
38
+ struct Data;
39
+
40
+ Xot::PImpl<Data, true> self;
41
+
42
+ };// Shader
43
+
44
+
45
+ }// Rays
46
+
47
+
48
+ #endif//EOH
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include <xot/pimpl.h>
8
8
  #include <rays/defs.h>
9
+ #include <rays/color_space.h>
9
10
  #include <rays/opengl.h>
10
11
 
11
12
 
@@ -23,7 +24,11 @@ namespace Rays
23
24
 
24
25
  Texture ();
25
26
 
26
- Texture (const Bitmap& bitmap, bool alphaonly = false);
27
+ Texture (
28
+ int width, int height, const ColorSpace& cs = RGBA,
29
+ bool alpha_only = false);
30
+
31
+ Texture (const Bitmap& bitmap, bool alpha_only = false);
27
32
 
28
33
  ~Texture ();
29
34
 
@@ -33,6 +38,10 @@ namespace Rays
33
38
 
34
39
  int height () const;
35
40
 
41
+ const ColorSpace& color_space () const;
42
+
43
+ bool alpha_only () const;
44
+
36
45
  float s (float x) const;
37
46
 
38
47
  float t (float y) const;
@@ -41,7 +50,9 @@ namespace Rays
41
50
 
42
51
  float t_max () const;
43
52
 
44
- const Bitmap& bitmap () const;
53
+ bool dirty () const;
54
+
55
+ void set_dirty (bool b = true);
45
56
 
46
57
  operator bool () const;
47
58
 
data/include/rays.h CHANGED
@@ -8,11 +8,12 @@
8
8
  #include <rays/rays.h>
9
9
  #include <rays/exception.h>
10
10
  #include <rays/point.h>
11
- #include <rays/colorspace.h>
11
+ #include <rays/color_space.h>
12
12
  #include <rays/bitmap.h>
13
13
  #include <rays/texture.h>
14
14
  #include <rays/image.h>
15
15
  #include <rays/font.h>
16
+ #include <rays/shader.h>
16
17
  #include <rays/painter.h>
17
18
  #include <rays/opengl.h>
18
19
 
data/lib/rays/bitmap.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
  require 'rays/ext'
5
+ require 'rays/color_space'
5
6
 
6
7
 
7
8
  module Rays
@@ -11,26 +12,34 @@ module Rays
11
12
 
12
13
  include Enumerable
13
14
 
14
- def initialize (width, height, colorspace = RGBA)
15
- colorspace = case colorspace
16
- when :GRAY then GRAY
17
- when :RGB then RGB
18
- when :RGBA then RGBA
19
- else colorspace
20
- end
21
- setup width, height, colorspace
15
+ def initialize (width, height, color_space = :RGBA)
16
+ setup width, height, ColorSpace.get_color_space(color_space)
22
17
  end
23
18
 
24
19
  def each ()
25
20
  height.times do |y|
26
21
  width.times do |x|
27
- yield x, y, at(x, y)
22
+ yield self[x, y], x, y
28
23
  end
29
24
  end
30
25
  end
31
26
 
32
- def size ()
33
- [width, height]
27
+ def bounds ()
28
+ Bounds.new 0, 0, width, height
29
+ end
30
+
31
+ def to_a ()
32
+ map {|o| o}
33
+ end
34
+
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
34
43
  end
35
44
 
36
45
  end# Bitmap
data/lib/rays/bounds.rb CHANGED
@@ -21,79 +21,60 @@ module Rays
21
21
  alias d depth
22
22
  alias d= depth=
23
23
 
24
+ def position= (*args)
25
+ set_position *Point.from(*args).to_a(3)
26
+ end
27
+
24
28
  alias pos position
25
29
  alias pos= position=
26
30
 
27
- def move_to! (*args)
28
- case args.size
29
- when 1 then self.x = self.y = args[0]
30
- when 2 then self.x, self.y = args
31
- when 3 then self.x, self.y, self.z = args
32
- else raise ArgumentError
33
- end
34
- self
31
+ def size= (*args)
32
+ set_size *Point.from(*args).to_a(3)
35
33
  end
36
34
 
37
- def move_to (*args)
38
- dup.move_to! *args
35
+ def center= (*args)
36
+ set_center *Point.from(*args).to_a(3)
39
37
  end
40
38
 
41
- def move_by! (*args)
42
- case args.size
43
- when 1 then self.x += args[0]; self.y += args[0]
44
- when 2 then self.x += args[0]; self.y += args[1]
45
- when 3 then self.x += args[0]; self.y += args[1]; self.z += args[2]
46
- else raise ArgumentError
47
- end
48
- self
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
42
+ def right_bottom () (position + size).move_by! -1, -1 end
43
+
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
48
+
49
+ alias lt left_top
50
+ alias lt= left_top=
51
+ alias rt right_top
52
+ alias rt= right_top=
53
+ alias lb left_bottom
54
+ alias lb= left_bottom=
55
+ alias rb right_bottom
56
+ alias rb= right_bottom=
57
+
58
+ def move_to (*args)
59
+ dup.move_to! *args
49
60
  end
50
61
 
51
62
  def move_by (*args)
52
63
  dup.move_by! *args
53
64
  end
54
65
 
55
- def resize_to! (*args)
56
- case args.size
57
- when 1 then self.w = self.h = args[0]
58
- when 2 then self.w, self.h = args
59
- when 3 then self.w, self.h, self.d = args
60
- else raise ArgumentError
61
- end
62
- self
63
- end
64
-
65
66
  def resize_to (*args)
66
67
  dup.resize_to! *args
67
68
  end
68
69
 
69
- def resize_by! (*args)
70
- case args.size
71
- when 1 then self.w += args[0]; self.h += args[0]
72
- when 2 then self.w += args[0]; self.h += args[1]
73
- when 3 then self.w += args[0]; self.h += args[1]; self.d += args[2]
74
- else raise ArgumentError
75
- end
76
- self
77
- end
78
-
79
70
  def resize_by (*args)
80
71
  dup.resize_by! *args
81
72
  end
82
73
 
83
- def inset_by! (*args)
84
- move_by! *args
85
- resize_by! *args.map {|n| -n * 2}
86
- self
87
- end
88
-
89
74
  def inset_by (*args)
90
75
  dup.inset_by! *args
91
76
  end
92
77
 
93
- def center ()
94
- Point.new (x + w / 2).round, (y + h / 2).round
95
- end
96
-
97
78
  def to_a (dimension = 2)
98
79
  case dimension
99
80
  when 1 then [x, w]
@@ -103,22 +84,6 @@ module Rays
103
84
  end
104
85
  end
105
86
 
106
- def [] (index)
107
- case index
108
- when 0 then Point.new(left, top, back)
109
- when 1 then Point.new(right, bottom, front)
110
- else raise IndexError
111
- end
112
- end
113
-
114
- def []= (index, point)
115
- case index
116
- when 0 then self.left, self.top, self.back = point.to_a(3)
117
- when 1 then self.right, self.bottom, self.front = point.to_a(3)
118
- else raise IndexError
119
- end
120
- end
121
-
122
87
  def <=> (o)
123
88
  ret = x <=> o.x; return ret if ret != 0
124
89
  ret = y <=> o.y; return ret if ret != 0
@@ -128,10 +93,6 @@ module Rays
128
93
  d <=> o.d
129
94
  end
130
95
 
131
- def inspect ()
132
- "#<Rays::Bounds x=#{x}, y=#{y}, z=#{z}, width=#{w}, height=#{h}, depth=#{d}>"
133
- end
134
-
135
96
  end# Bounds
136
97
 
137
98
 
data/lib/rays/color.rb CHANGED
@@ -11,6 +11,29 @@ module Rays
11
11
 
12
12
  include Comparable
13
13
 
14
+ def self.parse (str)
15
+ Color.new str
16
+ end
17
+
18
+ def initialize (*args)
19
+ arg0 = args[0]
20
+ args = parse arg0 if arg0 && arg0.kind_of?(String)
21
+ setup *args
22
+ end
23
+
24
+ def opaque? ()
25
+ alpha >= 1
26
+ end
27
+
28
+ def transparent? ()
29
+ alpha <= 0
30
+ end
31
+
32
+ def translucent? ()
33
+ a = alpha
34
+ 0 < a && a < 1
35
+ end
36
+
14
37
  def to_a ()
15
38
  [red, green, blue, alpha]
16
39
  end
@@ -42,10 +65,26 @@ module Rays
42
65
  alpha <=> o.alpha
43
66
  end
44
67
 
68
+ def eql? (o)
69
+ self == o
70
+ end
71
+
45
72
  def inspect ()
46
73
  "#<Rays::Color r=#{red}, g=#{green}, b=#{blue}, a=#{alpha}>"
47
74
  end
48
75
 
76
+ private
77
+
78
+ def parse (str)
79
+ case str
80
+ when /^\s*##{'([\da-fA-F]{1})' * 4}?\s*$/
81
+ [$1, $2, $3, $4 || 'f' ].map {|s| s.to_i(16) / 15.0}
82
+ when /^\s*##{'([\da-fA-F]{2})' * 4}?\s*$/
83
+ [$1, $2, $3, $4 || 'ff'].map {|s| s.to_i(16) / 255.0}
84
+ else raise ArgumentError, "can not parse '#{str}'."
85
+ end
86
+ end
87
+
49
88
  end# Color
50
89
 
51
90
 
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class ColorSpace
11
+
12
+ def initialize (type = :RGBA, premultiplied = true)
13
+ setup self.class.get_type(type), premultiplied
14
+ end
15
+
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."
24
+ end
25
+
26
+ def self.get_color_space (obj)
27
+ (ColorSpace === obj) ? obj : (ColorSpace.new get_type(obj))
28
+ end
29
+
30
+ end# ColorSpace
31
+
32
+
33
+ end# Rays
data/lib/rays/font.rb ADDED
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require 'rays/ext'
5
+
6
+
7
+ module Rays
8
+
9
+
10
+ class Font
11
+
12
+ include Comparable
13
+
14
+ alias w width
15
+ alias h height
16
+
17
+ def <=> (o)
18
+ ret = name <=> o.name; return ret if ret != 0
19
+ size <=> o.size
20
+ end
21
+
22
+ def inspect ()
23
+ "#<Rays::Font name=#{name}, size=#{size}>"
24
+ end
25
+
26
+ end# Font
27
+
28
+
29
+ end# Rays
data/lib/rays/image.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'forwardable'
4
5
  require 'rays/ext'
5
6
 
6
7
 
@@ -9,6 +10,27 @@ module Rays
9
10
 
10
11
  class Image
11
12
 
13
+ extend Forwardable
14
+
15
+ def_delegators :bitmap, :draw_string, :[], :[]=
16
+
17
+ def paint (&block)
18
+ painter.begin self, &block
19
+ self
20
+ end
21
+
22
+ def size ()
23
+ return width, height
24
+ end
25
+
26
+ def bounds ()
27
+ Bounds.new 0, 0, *size
28
+ end
29
+
30
+ def self.load (path, alpha_only = false)
31
+ load_image path, alpha_only
32
+ end
33
+
12
34
  end# Image
13
35
 
14
36
 
data/lib/rays/module.rb CHANGED
@@ -4,7 +4,11 @@
4
4
  module Rays
5
5
 
6
6
 
7
- extend module ModuleInfo
7
+ module Module
8
+
9
+ def name ()
10
+ super.split('::')[-2]
11
+ end
8
12
 
9
13
  def version ()
10
14
  open(root_dir 'VERSION') {|f| f.readline.chomp}
@@ -14,12 +18,12 @@ module Rays
14
18
  File.expand_path "../../../#{path}", __FILE__
15
19
  end
16
20
 
17
- def include_dirs ()
18
- %w[include].map {|dir| root_dir dir}
21
+ def include_dir ()
22
+ root_dir 'include'
19
23
  end
20
24
 
21
- def lib_dirs ()
22
- %w[lib].map {|dir| root_dir dir}
25
+ def lib_dir ()
26
+ root_dir 'lib'
23
27
  end
24
28
 
25
29
  def task_dir ()
@@ -37,9 +41,9 @@ module Rays
37
41
  end
38
42
  end
39
43
 
40
- self
44
+ extend self
41
45
 
42
- end# ModuleInfo
46
+ end# Module
43
47
 
44
48
 
45
49
  end# Rays