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,7 +6,7 @@
6
6
 
7
7
  #include <xot/pimpl.h>
8
8
  #include <rays/defs.h>
9
- #include <rays/colorspace.h>
9
+ #include <rays/color_space.h>
10
10
  #include <rays/font.h>
11
11
 
12
12
 
@@ -14,6 +14,9 @@ namespace Rays
14
14
  {
15
15
 
16
16
 
17
+ class Texture;
18
+
19
+
17
20
  class Bitmap
18
21
  {
19
22
 
@@ -23,10 +26,16 @@ namespace Rays
23
26
 
24
27
  Bitmap ();
25
28
 
26
- Bitmap (int width, int height, const ColorSpace& cs = RGBA);
29
+ Bitmap (
30
+ int width, int height, const ColorSpace& cs = RGBA,
31
+ const void* pixels = NULL);
32
+
33
+ Bitmap (const Texture& texture);
27
34
 
28
35
  ~Bitmap ();
29
36
 
37
+ Bitmap copy () const;
38
+
30
39
  int width () const;
31
40
 
32
41
  int height () const;
@@ -37,17 +46,13 @@ namespace Rays
37
46
 
38
47
  size_t size () const;
39
48
 
40
- bool dirty () const;
41
-
42
- void set_dirty (bool b = true);
43
-
44
- void* data ();
49
+ void* pixels ();
45
50
 
46
- const void* data () const;
51
+ const void* pixels () const;
47
52
 
48
53
  template <typename T> T* at (int x, int y)
49
54
  {
50
- return (T*) (((char*) data()) + pitch() * y + x * color_space().Bpp());
55
+ return (T*) (((char*) pixels()) + pitch() * y + x * color_space().Bpp());
51
56
  }
52
57
 
53
58
  template <typename T> const T* at (int x, int y) const
@@ -55,6 +60,10 @@ namespace Rays
55
60
  return const_cast<This*>(this)->at<T>(x, y);
56
61
  }
57
62
 
63
+ bool dirty () const;
64
+
65
+ void set_dirty (bool b = true);
66
+
58
67
  operator bool () const;
59
68
 
60
69
  bool operator ! () const;
@@ -66,12 +75,12 @@ namespace Rays
66
75
  };// Bitmap
67
76
 
68
77
 
69
- bool load_bitmap (Bitmap* bitmap, const char* path);
78
+ Bitmap load_bitmap (const char* path);
70
79
 
71
- bool save_bitmap (const Bitmap& bitmap, const char* path);
80
+ void save_bitmap (const Bitmap& bitmap, const char* path);
72
81
 
73
82
 
74
- bool draw_string (
83
+ void draw_string (
75
84
  Bitmap* bitmap, const char* str,
76
85
  coord x = 0, coord y = 0, const Font& font = default_font());
77
86
 
@@ -17,7 +17,19 @@ namespace Rays
17
17
 
18
18
  typedef Bounds This;
19
19
 
20
- coord x, y, z, width, height, depth;
20
+ union
21
+ {
22
+ struct
23
+ {
24
+ coord x, y, z;
25
+ union
26
+ {
27
+ struct {coord width, height, depth;};
28
+ struct {coord w, h, d;};
29
+ };
30
+ };
31
+ coord array[6];
32
+ };
21
33
 
22
34
  Bounds (coord size = 0);
23
35
 
@@ -27,19 +39,49 @@ namespace Rays
27
39
 
28
40
  Bounds (coord x, coord y, coord z, coord width, coord height, coord depth);
29
41
 
42
+ Bounds (const Point& size);
43
+
44
+ Bounds (const Point& position, const Point& size);
45
+
30
46
  Bounds dup () const;
31
47
 
32
- Bounds& set (coord size = 0);
48
+ bool is_intersect (const Bounds& other, int dimension = 2) const;
49
+
50
+ bool is_include (coord x, coord y, coord z = 0, int dimension = 2) const;
51
+
52
+ bool is_include (const Point& p, int dimension = 2) const;
53
+
54
+ Bounds& reset (coord size = 0);
55
+
56
+ Bounds& reset ( coord width, coord height, coord depth = 0);
57
+
58
+ Bounds& reset (coord x, coord y, coord width, coord height);
59
+
60
+ Bounds& reset (coord x, coord y, coord z, coord width, coord height, coord depth);
61
+
62
+ Bounds& reset (const Point& size);
63
+
64
+ Bounds& reset (const Point& position, const Point& size);
65
+
66
+ Bounds& move_to (coord x, coord y, coord z = 0);
67
+
68
+ Bounds& move_to (const Point& point);
33
69
 
34
- Bounds& set ( coord width, coord height, coord depth = 0);
70
+ Bounds& move_by (coord x, coord y, coord z = 0);
35
71
 
36
- Bounds& set (coord x, coord y, coord width, coord height);
72
+ Bounds& move_by (const Point& point);
37
73
 
38
- Bounds& set (coord x, coord y, coord z, coord width, coord height, coord depth);
74
+ Bounds& resize_to (coord x, coord y, coord z = 0);
39
75
 
40
- bool get (coord* x, coord* y, coord* width, coord* height) const;
76
+ Bounds& resize_to (const Point& point);
41
77
 
42
- bool get (coord* x, coord* y, coord* z, coord* width, coord* height, coord* depth) const;
78
+ Bounds& resize_by (coord x, coord y, coord z = 0);
79
+
80
+ Bounds& resize_by (const Point& point);
81
+
82
+ Bounds& inset_by (coord x, coord y, coord z = 0);
83
+
84
+ Bounds& inset_by (const Point& point);
43
85
 
44
86
  void set_left (coord left);
45
87
 
@@ -65,6 +107,12 @@ namespace Rays
65
107
 
66
108
  coord front () const;
67
109
 
110
+ void set_center (coord x, coord y, coord z = 0);
111
+
112
+ void set_center (const Point& point);
113
+
114
+ Point center () const;
115
+
68
116
  Point& position ();
69
117
 
70
118
  const Point& position () const;
@@ -73,18 +121,28 @@ namespace Rays
73
121
 
74
122
  const Point& size () const;
75
123
 
76
- coord* array ();
124
+ String inspect () const;
77
125
 
78
- const coord* array () const;
126
+ Point& operator [] (size_t index);
127
+
128
+ const Point& operator [] (size_t index) const;
79
129
 
80
130
  operator bool () const;
81
131
 
82
132
  bool operator ! () const;
83
133
 
134
+ Bounds& operator &= (const Bounds& rhs);
135
+
136
+ Bounds& operator |= (const Bounds& rhs);
137
+
84
138
  friend bool operator == (const Bounds& lhs, const Bounds& rhs);
85
139
 
86
140
  friend bool operator != (const Bounds& lhs, const Bounds& rhs);
87
141
 
142
+ friend Bounds operator & (const Bounds& lhs, const Bounds& rhs);
143
+
144
+ friend Bounds operator | (const Bounds& lhs, const Bounds& rhs);
145
+
88
146
  };// Bounds
89
147
 
90
148
 
data/include/rays/color.h CHANGED
@@ -13,28 +13,39 @@ namespace Rays
13
13
  {
14
14
 
15
15
 
16
+ class ColorSpace;
17
+
18
+
16
19
  struct Color
17
20
  {
18
21
 
19
22
  typedef Color This;
20
23
 
21
- float red, green, blue, alpha;
24
+ union
25
+ {
26
+ struct {float red, green, blue, alpha;};
27
+ float array[4];
28
+ };
22
29
 
23
- Color (float value = 0, float alpha = 1);
30
+ Color (float gray = 0, float alpha = 1);
24
31
 
25
32
  Color (float red, float green, float blue, float alpha = 1);
26
33
 
34
+ Color (void* pixel, const ColorSpace& cs);
35
+
27
36
  Color dup () const;
28
37
 
29
- Color& set (float value = 0, float alpha = 1);
38
+ Color& reset (float gray = 0, float alpha = 1);
39
+
40
+ Color& reset (float red, float green, float blue, float alpha = 1);
30
41
 
31
- Color& set (float red, float green, float blue, float alpha = 1);
42
+ Color& reset8 (uchar gray = 0, uchar alpha = 255);
32
43
 
33
- bool get (float* red, float* green, float* blue, float* alpha = NULL) const;
44
+ Color& reset8 (uchar red, uchar green, uchar blue, uchar alpha = 255);
34
45
 
35
- float* array ();
46
+ Color& reset (const void* pixel, const ColorSpace& cs);
36
47
 
37
- const float* array () const;
48
+ void get ( void* pixel, const ColorSpace& cs) const;
38
49
 
39
50
  operator bool () const;
40
51
 
@@ -47,6 +58,11 @@ namespace Rays
47
58
  };// Color
48
59
 
49
60
 
61
+ Color Color8 (uchar gray = 0, uchar alpha = 255);
62
+
63
+ Color Color8 (uchar red, uchar green, uchar blue, uchar alpha = 255);
64
+
65
+
50
66
  }// Rays
51
67
 
52
68
 
@@ -1,10 +1,11 @@
1
1
  // -*- c++ -*-
2
2
  #pragma once
3
- #ifndef __RAYS_COLORSPACE_H__
4
- #define __RAYS_COLORSPACE_H__
3
+ #ifndef __RAYS_COLOR_SPACE_H__
4
+ #define __RAYS_COLOR_SPACE_H__
5
5
 
6
6
 
7
7
  #include <rays/defs.h>
8
+ #include <rays/opengl.h>
8
9
 
9
10
 
10
11
  namespace Rays
@@ -46,7 +47,7 @@ namespace Rays
46
47
 
47
48
  ColorSpace ();
48
49
 
49
- ColorSpace (ColorSpaceType type, bool premultiplied = false);
50
+ ColorSpace (ColorSpaceType type, bool premultiplied = true);
50
51
 
51
52
  ColorSpaceType type () const;
52
53
 
@@ -82,6 +83,8 @@ namespace Rays
82
83
 
83
84
  bool is_premult () const;
84
85
 
86
+ void get_gl_enums (GLenum* format, GLenum* type, bool alpha_only) const;
87
+
85
88
  operator bool () const;
86
89
 
87
90
  bool operator ! () const;
@@ -4,7 +4,7 @@
4
4
  #define __RAYS_EXCEPTION_H__
5
5
 
6
6
 
7
- #include <stdexcept>
7
+ #include <xot/exception.h>
8
8
  #include <rays/defs.h>
9
9
 
10
10
 
@@ -12,27 +12,33 @@ namespace Rays
12
12
  {
13
13
 
14
14
 
15
- class RaysException : public std::runtime_error
15
+ class RaysError : public Xot::XotError
16
16
  {
17
+ typedef Xot::XotError Super;
18
+ public: RaysError (const char* str = NULL);
19
+ };
17
20
 
18
- typedef std::runtime_error Super;
19
21
 
20
- public:
22
+ class OpenGLError : public RaysError
23
+ {
24
+ typedef RaysError Super;
25
+ public: OpenGLError (const char* str = NULL);
26
+ };
21
27
 
22
- RaysException (const char* format = NULL, ...);
23
28
 
24
- ~RaysException () throw();
29
+ namespace ErrorFunctions
30
+ {
25
31
 
26
- const char* what () const throw();
32
+ using namespace Xot::ErrorFunctions;
27
33
 
28
- private:
34
+ void rays_error (const char* file, int line, const char* format = NULL, ...);
29
35
 
30
- String text;
36
+ void opengl_error (const char* file, int line, const char* format = NULL, ...);
31
37
 
32
- };// RaysException
38
+ }// ErrorFunctions
33
39
 
34
40
 
35
- void rays_error (const char* format = NULL, ...);
41
+ using namespace ErrorFunctions;
36
42
 
37
43
 
38
44
  }// Rays
data/include/rays/font.h CHANGED
@@ -23,14 +23,15 @@ namespace Rays
23
23
 
24
24
  ~Font ();
25
25
 
26
+ Font copy () const;
27
+
26
28
  String name () const;
27
29
 
28
30
  coord size () const;
29
31
 
30
- bool get_width (coord* width, const char* str) const;
32
+ coord get_width (const char* str) const;
31
33
 
32
- bool get_height (
33
- coord* height,
34
+ coord get_height (
34
35
  coord* ascent = NULL, coord* descent = NULL, coord* leading = NULL) const;
35
36
 
36
37
  operator bool () const;
data/include/rays/image.h CHANGED
@@ -5,7 +5,8 @@
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
8
- #include <rays/colorspace.h>
8
+ #include <rays/color_space.h>
9
+ #include <rays/painter.h>
9
10
 
10
11
 
11
12
  namespace Rays
@@ -28,19 +29,23 @@ namespace Rays
28
29
 
29
30
  Image (
30
31
  int width, int height, const ColorSpace& cs = RGBA,
31
- bool alphatexture = false);
32
+ bool alpha_only = false);
32
33
 
33
- Image (const Bitmap& bitmap, bool alphatexture = false);
34
+ Image (const Bitmap& bitmap, bool alpha_only = false);
34
35
 
35
36
  ~Image ();
36
37
 
38
+ Image copy () const;
39
+
40
+ Painter painter ();
41
+
37
42
  int width () const;
38
43
 
39
44
  int height () const;
40
45
 
41
46
  const ColorSpace& color_space () const;
42
47
 
43
- bool alpha_texture () const;
48
+ bool alpha_only () const;
44
49
 
45
50
  Bitmap& bitmap ();
46
51
 
@@ -61,9 +66,9 @@ namespace Rays
61
66
  };// Image
62
67
 
63
68
 
64
- bool load_image (Image* image, const char* path, bool alphatexture = false);
69
+ Image load_image (const char* path, bool alphatexture = false);
65
70
 
66
- bool save_image (const Image& image, const char* path);
71
+ void save_image (const Image& image, const char* path);
67
72
 
68
73
 
69
74
  }// Rays
@@ -14,11 +14,18 @@ namespace Rays
14
14
  struct Matrix
15
15
  {
16
16
 
17
- float
18
- a1, a2, a3, a4,
19
- b1, b2, b3, b4,
20
- c1, c2, c3, c4,
21
- d1, d2, d3, d4;
17
+ union
18
+ {
19
+ struct
20
+ {
21
+ float
22
+ a1, a2, a3, a4,
23
+ b1, b2, b3, b4,
24
+ c1, c2, c3, c4,
25
+ d1, d2, d3, d4;
26
+ };
27
+ float array[16];
28
+ };
22
29
 
23
30
  Matrix (float value = 1);
24
31
 
@@ -32,24 +39,20 @@ namespace Rays
32
39
 
33
40
  Matrix dup () const;
34
41
 
35
- Matrix& set (float value = 1);
42
+ Matrix& reset (float value = 1);
36
43
 
37
- Matrix& set (
44
+ Matrix& reset (
38
45
  float a1, float a2, float a3, float a4,
39
46
  float b1, float b2, float b3, float b4,
40
47
  float c1, float c2, float c3, float c4,
41
48
  float d1, float d2, float d3, float d4);
42
49
 
43
- Matrix& set (const float* elements, size_t size);
50
+ Matrix& reset (const float* elements, size_t size);
44
51
 
45
52
  float& at (int row, int column);
46
53
 
47
54
  float at (int row, int column) const;
48
55
 
49
- float* array ();
50
-
51
- const float* array () const;
52
-
53
56
  float& operator [] (int index);
54
57
 
55
58
  float operator [] (int index) const;
@@ -4,12 +4,65 @@
4
4
  #define __RAYS_GL_H__
5
5
 
6
6
 
7
- #if defined(COCOA)
7
+ #if defined(OSX)
8
8
  #include <OpenGL/gl.h>
9
+ #include <OpenGL/glext.h>
10
+ #elif defined(IOS)
11
+ #include <OpenGLES/ES1/gl.h>
12
+ #include <OpenGLES/ES1/glext.h>
9
13
  #elif defined(WIN32)
10
14
  #include <GL/gl.h>
11
15
  #include <GL/glext.h>
12
16
  #endif
13
17
 
14
18
 
19
+ namespace Rays
20
+ {
21
+
22
+
23
+ GLenum get_error ();
24
+
25
+ bool no_error ();
26
+
27
+ bool is_error (GLenum err);
28
+
29
+ void check_error(const char* file, int line);
30
+
31
+ void clear_error ();
32
+
33
+
34
+ void init_offscreen_context ();
35
+
36
+
37
+ }// Rays
38
+
39
+
40
+ #ifdef IOS
41
+
42
+ #define glGenFramebuffers glGenFramebuffersOES
43
+ #define glGenRenderbuffers glGenRenderbuffersOES
44
+ #define glDeleteFramebuffers glDeleteFramebuffersOES
45
+ #define glDeleteRenderbuffers glDeleteRenderbuffersOES
46
+ #define glBindFramebuffer glBindFramebufferOES
47
+ #define glBindRenderbuffer glBindRenderbufferOES
48
+ #define glCheckFramebufferStatus glCheckFramebufferStatusOES
49
+ #define glFramebufferTexture2D glFramebufferTexture2DOES
50
+ #define glRenderbufferStorage glRenderbufferStorageOES
51
+ #define glOrtho glOrthox
52
+
53
+ #define GL_UNSIGNED_INT GL_UNSIGNED_INT_OES
54
+ #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
55
+ #define GL_RENDERBUFFER GL_RENDERBUFFER_OES
56
+ #define GL_DRAW_FRAMEBUFFER GL_DRAW_FRAMEBUFFER_APPLE
57
+ #define GL_READ_FRAMEBUFFER GL_READ_FRAMEBUFFER_APPLE
58
+ #define GL_DRAW_FRAMEBUFFER_BINDING GL_DRAW_FRAMEBUFFER_BINDING_APPLE
59
+ #define GL_READ_FRAMEBUFFER_BINDING GL_READ_FRAMEBUFFER_BINDING_APPLE
60
+ #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
61
+ #define GL_DEPTH_ATTACHMENT GL_DEPTH_ATTACHMENT_OES
62
+ #define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES
63
+ #define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES
64
+
65
+ #endif// IOS
66
+
67
+
15
68
  #endif//EOH