rays 0.1.11 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) 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/camera.cpp +88 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +22 -80
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +94 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +49 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +21 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +21 -0
  107. data/src/ios/bitmap.mm +129 -110
  108. data/src/ios/camera.mm +236 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +2 -2
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +21 -0
  119. data/src/osx/bitmap.mm +129 -110
  120. data/src/osx/camera.mm +236 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -0,0 +1,64 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_SRC_FONT_H__
4
+ #define __RAYS_SRC_FONT_H__
5
+
6
+
7
+ #include <rays/defs.h>
8
+ #include <rays/font.h>
9
+
10
+
11
+ namespace Rays
12
+ {
13
+
14
+
15
+ class RawFont
16
+ {
17
+
18
+ public:
19
+
20
+ RawFont ();
21
+
22
+ RawFont (const char* name, coord size = 0);
23
+
24
+ ~RawFont ();
25
+
26
+ void draw_string (
27
+ void* context, coord context_height,
28
+ const char* str, coord x, coord y) const;
29
+
30
+ String name () const;
31
+
32
+ coord size () const;
33
+
34
+ coord get_width (const char* str) const;
35
+
36
+ coord get_height (
37
+ coord* ascent = NULL,
38
+ coord* descent = NULL,
39
+ coord* leading = NULL) const;
40
+
41
+ operator bool () const;
42
+
43
+ bool operator ! () const;
44
+
45
+ struct Data;
46
+
47
+ Xot::PSharedImpl<Data> self;
48
+
49
+ };// RawFont
50
+
51
+
52
+ const RawFont& Font_get_raw (const Font& font, float pixel_density);
53
+
54
+ coord Font_get_width (const Font& font, float pixel_density, const char* str);
55
+
56
+ coord Font_get_height (
57
+ const Font& font, float pixel_density,
58
+ coord* ascent = NULL, coord* descent = NULL, coord* leading = NULL);
59
+
60
+
61
+ }// Rays
62
+
63
+
64
+ #endif//EOH
@@ -3,8 +3,8 @@
3
3
 
4
4
  #include <vector>
5
5
  #include "rays/exception.h"
6
- #include "rays/texture.h"
7
- #include "rays/opengl.h"
6
+ #include "rays/debug.h"
7
+ #include "texture.h"
8
8
  #include "render_buffer.h"
9
9
 
10
10
 
@@ -15,17 +15,12 @@ namespace Rays
15
15
  struct FrameBuffer::Data
16
16
  {
17
17
 
18
- int id;
18
+ int id = -1;
19
19
 
20
20
  Texture texture;
21
21
 
22
22
  RenderBuffer render_buffer;
23
23
 
24
- Data ()
25
- : id(-1)
26
- {
27
- }
28
-
29
24
  ~Data ()
30
25
  {
31
26
  clear();
@@ -37,7 +32,7 @@ namespace Rays
37
32
 
38
33
  GLuint id_ = 0;
39
34
  glGenFramebuffers(1, &id_);
40
- check_error(__FILE__, __LINE__);
35
+ OpenGL_check_error(__FILE__, __LINE__);
41
36
 
42
37
  id = id_;
43
38
  }
@@ -51,7 +46,7 @@ namespace Rays
51
46
  {
52
47
  GLuint id_ = id;
53
48
  glDeleteFramebuffers(1, &id_);
54
- check_error(__FILE__, __LINE__);
49
+ OpenGL_check_error(__FILE__, __LINE__);
55
50
  }
56
51
 
57
52
  id = -1;
@@ -83,21 +78,17 @@ namespace Rays
83
78
  {
84
79
  switch (status)
85
80
  {
81
+ case GL_FRAMEBUFFER_UNSUPPORTED: return "GL_FRAMEBUFFER_UNSUPPORTED";
82
+ case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
83
+ case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
84
+ case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
86
85
  #ifdef IOS
87
- case GL_FRAMEBUFFER_UNSUPPORTED_OES: return "GL_FRAMEBUFFER_UNSUPPORTED_OES";
88
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES";
89
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES";
90
- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES: return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES";
91
- case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES: return "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_OES";
86
+ case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS: return "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS";
92
87
  #else
93
- case GL_FRAMEBUFFER_UNDEFINED: return "GL_FRAMEBUFFER_UNDEFINED";
94
- case GL_FRAMEBUFFER_UNSUPPORTED: return "GL_FRAMEBUFFER_UNSUPPORTED";
95
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT";
96
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: return "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";
97
- case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
98
- case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
99
- case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: return "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
100
- //case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
88
+ case GL_FRAMEBUFFER_UNDEFINED: return "GL_FRAMEBUFFER_UNDEFINED";
89
+ case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER";
90
+ case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: return "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER";
91
+ //case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: return "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
101
92
  #endif
102
93
  }
103
94
  return "UNKNOWN STATUS";
@@ -114,14 +105,13 @@ namespace Rays
114
105
  FrameBufferBinder binder(id());
115
106
 
116
107
  glFramebufferTexture2D(
117
- GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
118
- GL_TEXTURE_2D, texture.id(), 0);
119
- check_error(__FILE__, __LINE__);
108
+ GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id(), 0);
109
+ OpenGL_check_error(__FILE__, __LINE__);
120
110
 
121
111
  self->texture = texture;
122
112
 
123
113
  #if 0
124
- int w = texture.width(), h = texture.height();
114
+ int w = texture.reserved_width(), h = texture.reserved_height();
125
115
  if (
126
116
  w != self->render_buffer.width() ||
127
117
  h != self->render_buffer.height())
@@ -131,7 +121,7 @@ namespace Rays
131
121
  glFramebufferRenderbuffer(
132
122
  GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
133
123
  GL_RENDERBUFFER, rb.id());
134
- check_error(__FILE__, __LINE__);
124
+ OpenGL_check_error(__FILE__, __LINE__);
135
125
 
136
126
  self->render_buffer = rb;
137
127
  }
@@ -185,7 +175,9 @@ namespace Rays
185
175
  return false;
186
176
 
187
177
  const RenderBuffer& r = self->render_buffer;
188
- if (r && (t.width() != r.width() || t.height() != r.height()))
178
+ int w = t.reserved_width();
179
+ int h = t.reserved_height();
180
+ if (r && (r.width() != w || r.height() != h))
189
181
  return false;
190
182
 
191
183
  return true;
@@ -201,12 +193,12 @@ namespace Rays
201
193
  FrameBufferBinder::FrameBufferBinder (GLuint id)
202
194
  : id(id)
203
195
  {
204
- bind_frame_buffer(id);
196
+ FrameBuffer_bind(id);
205
197
  }
206
198
 
207
199
  FrameBufferBinder::~FrameBufferBinder ()
208
200
  {
209
- unbind_frame_buffer();
201
+ FrameBuffer_unbind();
210
202
  }
211
203
 
212
204
  GLuint
@@ -216,59 +208,33 @@ namespace Rays
216
208
  }
217
209
 
218
210
 
219
- struct FrameBufferID
220
- {
221
-
222
- GLuint draw, read;
223
-
224
- FrameBufferID ()
225
- : draw(0), read(0)
226
- {
227
- }
228
-
229
- FrameBufferID (GLuint draw, GLuint read)
230
- : draw(draw), read(read)
231
- {
232
- }
233
-
234
- };// FrameBufferID
211
+ static std::vector<GLuint> frame_buffer_bind_stack;
235
212
 
236
- static std::vector<FrameBufferID> frame_buffer_bind_stack;
237
213
 
238
-
239
- static void
240
- bind_frame_buffer (GLuint draw, GLuint read)
214
+ void
215
+ FrameBuffer_bind (GLuint id)
241
216
  {
242
- FrameBufferID id;
243
- glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, (GLint*) &id.draw);
244
- glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, (GLint*) &id.read);
245
- check_error(__FILE__, __LINE__);
217
+ GLuint current = 0;
218
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*) &current);
219
+ OpenGL_check_error(__FILE__, __LINE__);
246
220
 
247
- frame_buffer_bind_stack.push_back(id);
221
+ frame_buffer_bind_stack.push_back(current);
248
222
 
249
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, draw);
250
- glBindFramebuffer(GL_READ_FRAMEBUFFER, read);
251
- check_error(__FILE__, __LINE__);
252
- }
253
-
254
- void
255
- bind_frame_buffer (GLuint id)
256
- {
257
- bind_frame_buffer(id, id);
223
+ glBindFramebuffer(GL_FRAMEBUFFER, id);
224
+ OpenGL_check_error(__FILE__, __LINE__);
258
225
  }
259
226
 
260
227
  void
261
- unbind_frame_buffer ()
228
+ FrameBuffer_unbind ()
262
229
  {
263
230
  if (frame_buffer_bind_stack.empty())
264
- rays_error(__FILE__, __LINE__, "frame_buffer_bind_stack is empty.");
231
+ rays_error(__FILE__, __LINE__, "frame_buffer_bind_stack underflow.");
265
232
 
266
- FrameBufferID id = frame_buffer_bind_stack.back();
233
+ GLuint id = frame_buffer_bind_stack.back();
267
234
  frame_buffer_bind_stack.pop_back();
268
235
 
269
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, id.draw);
270
- glBindFramebuffer(GL_READ_FRAMEBUFFER, id.read);
271
- check_error(__FILE__, __LINE__);
236
+ glBindFramebuffer(GL_FRAMEBUFFER, id);
237
+ OpenGL_check_error(__FILE__, __LINE__);
272
238
  }
273
239
 
274
240
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  #include <xot/pimpl.h>
8
8
  #include <rays/defs.h>
9
- #include <rays/opengl.h>
9
+ #include "opengl.h"
10
10
 
11
11
 
12
12
  namespace Rays
@@ -45,7 +45,7 @@ namespace Rays
45
45
 
46
46
  struct Data;
47
47
 
48
- Xot::PImpl<Data, true> self;
48
+ Xot::PSharedImpl<Data> self;
49
49
 
50
50
  };// FrameBuffer
51
51
 
@@ -68,9 +68,9 @@ namespace Rays
68
68
  };// FrameBufferBinder
69
69
 
70
70
 
71
- void bind_frame_buffer (GLuint id);
71
+ void FrameBuffer_bind (GLuint id);
72
72
 
73
- void unbind_frame_buffer ();
73
+ void FrameBuffer_unbind ();
74
74
 
75
75
 
76
76
  }// Rays
@@ -1,9 +1,13 @@
1
- #include "rays/image.h"
1
+ #include "image.h"
2
2
 
3
3
 
4
+ #include <math.h>
5
+ #include <assert.h>
4
6
  #include "rays/exception.h"
5
- #include "rays/bitmap.h"
6
- #include "rays/texture.h"
7
+ #include "rays/debug.h"
8
+ #include "opengl.h"
9
+ #include "bitmap.h"
10
+ #include "texture.h"
7
11
 
8
12
 
9
13
  namespace Rays
@@ -13,171 +17,241 @@ namespace Rays
13
17
  struct Image::Data
14
18
  {
15
19
 
16
- int width, height;
20
+ int width = 0, height = 0;
17
21
 
18
22
  ColorSpace color_space;
19
23
 
20
- bool alpha_only;
24
+ float pixel_density = 1;
21
25
 
22
26
  mutable Bitmap bitmap;
23
27
 
24
28
  mutable Texture texture;
25
29
 
26
- Data ()
27
- : width(0), height(0), alpha_only(false)
28
- {
29
- }
30
-
31
30
  };// Image::Data
32
31
 
33
32
 
34
- Image::Image ()
33
+ static void
34
+ invalidate_texture (Image* image)
35
35
  {
36
+ image->bitmap();// update bitmap
37
+ image->self->texture = Texture();
36
38
  }
37
39
 
38
- Image::Image (int width, int height, const ColorSpace& cs, bool alpha_only)
40
+ static void
41
+ invalidate_texture_for_another_context (Image* image)
39
42
  {
40
- self->width = width;
41
- self->height = height;
42
- self->color_space = cs;
43
- self->alpha_only = alpha_only;
44
- }
43
+ assert(image);
45
44
 
46
- Image::Image (const Bitmap& bitmap, bool alpha_only)
47
- {
48
- self->width = bitmap.width();
49
- self->height = bitmap.height();
50
- self->color_space = bitmap.color_space();
51
- self->alpha_only = alpha_only;
52
- self->bitmap = bitmap;
53
- }
45
+ const Texture& tex = image->self->texture;
46
+ if (!tex) return;
54
47
 
55
- Image::~Image ()
56
- {
57
- }
48
+ Context tex_context = tex.context();
49
+ if (!tex_context) return;
58
50
 
59
- Image
60
- Image::copy () const
61
- {
62
- return Image(width(), height(), color_space(), alpha_only());
63
- }
51
+ Context current_context = OpenGL_get_context();
52
+ if (tex_context == current_context)
53
+ return;
64
54
 
65
- Painter
66
- Image::painter ()
67
- {
68
- Painter p;
69
- p.bind(texture());
70
- return p;
71
- }
72
-
73
- int
74
- Image::width () const
75
- {
76
- return self->width;
55
+ OpenGL_set_context(tex_context);
56
+ invalidate_texture(image);
57
+ OpenGL_set_context(current_context);
77
58
  }
78
59
 
79
- int
80
- Image::height () const
60
+ static Bitmap&
61
+ get_bitmap (Image& image)
81
62
  {
82
- return self->height;
83
- }
63
+ Image::Data* self = image.self.get();
84
64
 
85
- const ColorSpace&
86
- Image::color_space () const
87
- {
88
- return self->color_space;
89
- }
90
-
91
- bool
92
- Image::alpha_only () const
93
- {
94
- return self->alpha_only;
95
- }
65
+ if (!image)
66
+ {
67
+ assert(!self->bitmap);
68
+ return self->bitmap;
69
+ }
96
70
 
97
- Bitmap&
98
- Image::bitmap ()
99
- {
100
71
  if (!self->bitmap)
101
72
  {
102
73
  if (self->texture)
103
- self->bitmap = Bitmap(self->texture);
74
+ self->bitmap = Bitmap_from(self->texture);
104
75
  else
105
76
  self->bitmap = Bitmap(self->width, self->height, self->color_space);
106
77
  }
107
- else if (self->texture && !self->bitmap.dirty() && self->texture.dirty())
108
- self->bitmap = Bitmap(self->texture);
78
+ else if (
79
+ self->texture &&
80
+ self->texture.modified() &&
81
+ !Bitmap_get_modified(self->bitmap))
82
+ {
83
+ self->bitmap = Bitmap_from(self->texture);
84
+ }
109
85
 
110
- if (self->bitmap) self->bitmap.set_dirty(false);
111
- if (self->texture) self->texture.set_dirty(false);
86
+ if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
87
+ if (self->texture) self->texture.set_modified(false);
112
88
 
113
89
  return self->bitmap;
114
90
  }
115
91
 
116
- const Bitmap&
117
- Image::bitmap () const
118
- {
119
- return const_cast<This*>(this)->bitmap();
120
- }
121
-
122
92
  Texture&
123
- Image::texture ()
93
+ Image_get_texture (Image& image)
124
94
  {
95
+ Image::Data* self = image.self.get();
96
+
97
+ if (!image)
98
+ {
99
+ assert(!self->texture);
100
+ return self->texture;
101
+ }
102
+
103
+ invalidate_texture_for_another_context(&image);
104
+
125
105
  if (!self->texture)
126
106
  {
127
107
  if (self->bitmap)
128
- self->texture = Texture(self->bitmap, self->alpha_only);
108
+ self->texture = Texture(self->bitmap);
129
109
  else
130
110
  {
131
- self->texture = Texture(
132
- self->width, self->height, self->color_space, self->alpha_only);
111
+ self->texture = Texture(self->width, self->height, self->color_space);
133
112
 
134
- Painter p;
135
- p.bind(self->texture);
113
+ Painter p = image.painter();
136
114
  p.begin();
137
115
  p.clear();
138
116
  p.end();
139
117
  }
140
118
  }
141
- else if (self->bitmap && !self->texture.dirty() && self->bitmap.dirty())
142
- self->texture = Texture(self->bitmap, self->alpha_only);
119
+ else if (
120
+ self->bitmap &&
121
+ Bitmap_get_modified(self->bitmap) &&
122
+ !self->texture.modified())
123
+ {
124
+ self->texture = Texture(self->bitmap);
125
+ }
143
126
 
144
- if (self->bitmap) self->bitmap.set_dirty(false);
145
- if (self->texture) self->texture.set_dirty(false);
127
+ if (self->bitmap) Bitmap_set_modified(&self->bitmap, false);
128
+ if (self->texture) self->texture.set_modified(false);
146
129
 
147
130
  return self->texture;
148
131
  }
149
132
 
150
133
  const Texture&
151
- Image::texture () const
134
+ Image_get_texture (const Image& image)
152
135
  {
153
- return const_cast<This*>(this)->texture();
136
+ return Image_get_texture(const_cast<Image&>(image));
154
137
  }
155
138
 
156
- Image::operator bool () const
139
+ void
140
+ save_image (const Image& image, const char* path)
157
141
  {
158
- return self->width > 0 && self->height > 0 && self->color_space;
142
+ if (!image)
143
+ argument_error(__FILE__, __LINE__);
144
+
145
+ return Bitmap_save(image.bitmap(), path);
159
146
  }
160
147
 
161
- bool
162
- Image::operator ! () const
148
+ Image
149
+ load_image (const char* path)
150
+ {
151
+ return Image(Bitmap_load(path));
152
+ }
153
+
154
+
155
+ Image::Image ()
163
156
  {
164
- return !operator bool();
165
157
  }
166
158
 
159
+ Image::Image (
160
+ int width, int height, const ColorSpace& cs, float pixel_density)
161
+ {
162
+ if (pixel_density <= 0)
163
+ argument_error(__FILE__, __LINE__, "invalid pixel_density.");
164
+
165
+ coord w = width * pixel_density;
166
+ coord h = height * pixel_density;
167
+ if ((w - (int) w) != 0 || (h - (int) h) != 0)
168
+ argument_error(__FILE__, __LINE__, "invalid size for image.");
169
+
170
+ self->width = w;
171
+ self->height = h;
172
+ self->color_space = cs;
173
+ self->pixel_density = pixel_density;
174
+ }
175
+
176
+ Image::Image (const Bitmap& bitmap, float pixel_density)
177
+ {
178
+ if (pixel_density <= 0)
179
+ argument_error(__FILE__, __LINE__, "invalid pixel_density.");
180
+
181
+ self->bitmap = bitmap;
182
+ self->width = bitmap.width();
183
+ self->height = bitmap.height();
184
+ self->color_space = bitmap.color_space();
185
+ self->pixel_density = pixel_density;
186
+ }
187
+
188
+ Image::~Image ()
189
+ {
190
+ }
167
191
 
168
192
  Image
169
- load_image (const char* path, bool alphatex)
193
+ Image::dup () const
170
194
  {
171
- return Image(load_bitmap(path), alphatex);
195
+ return Image(bitmap().dup(), pixel_density());
172
196
  }
173
197
 
174
- void
175
- save_image (const Image& image, const char* path)
198
+ coord
199
+ Image::width () const
176
200
  {
177
- if (!image)
178
- argument_error(__FILE__, __LINE__);
201
+ return self->width / self->pixel_density;
202
+ }
179
203
 
180
- return save_bitmap(image.bitmap(), path);
204
+ coord
205
+ Image::height () const
206
+ {
207
+ return self->height / self->pixel_density;
208
+ }
209
+
210
+ const ColorSpace&
211
+ Image::color_space () const
212
+ {
213
+ return self->color_space;
214
+ }
215
+
216
+ float
217
+ Image::pixel_density () const
218
+ {
219
+ return self->pixel_density;
220
+ }
221
+
222
+ Painter
223
+ Image::painter ()
224
+ {
225
+ Painter p;
226
+ p.bind(*this);
227
+ return p;
228
+ }
229
+
230
+ Bitmap&
231
+ Image::bitmap ()
232
+ {
233
+ return get_bitmap(*this);
234
+ }
235
+
236
+ const Bitmap&
237
+ Image::bitmap () const
238
+ {
239
+ return get_bitmap(const_cast<Image&>(*this));
240
+ }
241
+
242
+ Image::operator bool () const
243
+ {
244
+ return
245
+ self->width > 0 &&
246
+ self->height > 0 &&
247
+ self->pixel_density > 0 &&
248
+ self->color_space;
249
+ }
250
+
251
+ bool
252
+ Image::operator ! () const
253
+ {
254
+ return !operator bool();
181
255
  }
182
256
 
183
257