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
@@ -1,13 +1,32 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'xot/block_util'
4
5
  require 'rays/ext'
5
6
 
6
7
 
7
8
  module Rays
8
9
 
9
10
 
10
- #class Shader
11
+ class Shader
12
+
13
+ def initialize (source = nil, **uniforms, &block)
14
+ if source
15
+ setup source
16
+ uniform **uniforms unless uniforms.empty?
17
+ end
18
+
19
+ Xot::BlockUtil.instance_eval_or_block_call self, &block if block
20
+ end
21
+
22
+ def uniform (name = nil, *args, **uniforms)
23
+ set_uniform name, *args if name
24
+ uniforms.each do |key, value|
25
+ set_uniform key, value
26
+ end
27
+ end
28
+
29
+ end# Shader
11
30
 
12
31
 
13
32
  end# Rays
@@ -21,17 +21,15 @@ Gem::Specification.new do |s|
21
21
  s.description = 'This library helps you to develop graphics application with OpenGL.'
22
22
  s.version = mod.version
23
23
 
24
- s.authors = %w[snori]
25
- s.email = 'snori@xord.org'
24
+ s.authors = %w[xordog]
25
+ s.email = 'xordog@gmail.com'
26
26
  s.homepage = "https://github.com/xord/rays"
27
27
 
28
28
  s.platform = Gem::Platform::RUBY
29
- s.required_ruby_version = '>=1.9.0'
29
+ s.required_ruby_version = '~> 2'
30
30
 
31
- s.add_runtime_dependency 'rake'
32
- s.add_runtime_dependency 'xot'
33
- s.add_runtime_dependency 'rucy'
34
- s.add_development_dependency 'gemcutter'
31
+ s.add_runtime_dependency 'xot', '~> 0.1'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1'
35
33
 
36
34
  s.files = `git ls-files`.split $/
37
35
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
@@ -0,0 +1,36 @@
1
+ // -*- c++ -*-
2
+ #pragma once
3
+ #ifndef __RAYS_SRC_BITMAP_H__
4
+ #define __RAYS_SRC_BITMAP_H__
5
+
6
+
7
+ #include <rays/bitmap.h>
8
+
9
+
10
+ namespace Rays
11
+ {
12
+
13
+
14
+ class Texture;
15
+
16
+ class RawFont;
17
+
18
+
19
+ Bitmap Bitmap_from (const Texture& texture);
20
+
21
+ void Bitmap_draw_string (
22
+ Bitmap* bitmap, const RawFont& font, const char* str, coord x, coord y);
23
+
24
+ void Bitmap_set_modified (Bitmap* bitmap, bool modified = true);
25
+
26
+ bool Bitmap_get_modified (const Bitmap& bitmap);
27
+
28
+ void Bitmap_save (const Bitmap& bitmap, const char* path);
29
+
30
+ Bitmap Bitmap_load (const char* path);
31
+
32
+
33
+ }// Rays
34
+
35
+
36
+ #endif//EOH
@@ -1,6 +1,7 @@
1
1
  #include "rays/bounds.h"
2
2
 
3
3
 
4
+ #include <float.h>
4
5
  #include <algorithm>
5
6
  #include "rays/exception.h"
6
7
 
@@ -293,6 +294,22 @@ namespace Rays
293
294
  return z + d - 1;
294
295
  }
295
296
 
297
+ void
298
+ Bounds::set_position (coord x, coord y, coord z)
299
+ {
300
+ this->x = x;
301
+ this->y = y;
302
+ this->z = z;
303
+ }
304
+
305
+ void
306
+ Bounds::set_position (const Point& position)
307
+ {
308
+ x = position.x;
309
+ y = position.y;
310
+ z = position.z;
311
+ }
312
+
296
313
  Point&
297
314
  Bounds::position ()
298
315
  {
@@ -305,6 +322,20 @@ namespace Rays
305
322
  return const_cast<This*>(this)->position();
306
323
  }
307
324
 
325
+ void
326
+ Bounds::set_size (coord width, coord height, coord depth)
327
+ {
328
+ w = width;
329
+ h = height;
330
+ d = depth;
331
+ }
332
+
333
+ void
334
+ Bounds::set_size (const Point& size)
335
+ {
336
+ set_size(size.x, size.y, size.z);
337
+ }
338
+
308
339
  Point&
309
340
  Bounds::size ()
310
341
  {
@@ -326,9 +357,9 @@ namespace Rays
326
357
  }
327
358
 
328
359
  void
329
- Bounds::set_center (const Point& point)
360
+ Bounds::set_center (const Point& center)
330
361
  {
331
- set_center(point.x, point.y, point.z);
362
+ set_center(center.x, center.y, center.z);
332
363
  }
333
364
 
334
365
  Point
@@ -372,12 +403,15 @@ namespace Rays
372
403
  Bounds&
373
404
  Bounds::operator &= (const Bounds& rhs)
374
405
  {
375
- if (!*this || !rhs)
406
+ if (!rhs)
376
407
  argument_error(__FILE__, __LINE__);
377
408
 
378
- coord x = std::max(this->x, rhs.x);
379
- coord y = std::max(this->y, rhs.y);
380
- coord z = std::max(this->z, rhs.z);
409
+ if (!*this)
410
+ invalid_state_error(__FILE__, __LINE__);
411
+
412
+ coord x = std::max(this->x, rhs.x);
413
+ coord y = std::max(this->y, rhs.y);
414
+ coord z = std::max(this->z, rhs.z);
381
415
  coord w = std::min(this->x + this->w, rhs.x + rhs.w) - x;
382
416
  coord h = std::min(this->y + this->h, rhs.y + rhs.h) - y;
383
417
  coord d = std::min(this->z + this->d, rhs.z + rhs.d) - z;
@@ -392,12 +426,11 @@ namespace Rays
392
426
  Bounds&
393
427
  Bounds::operator |= (const Bounds& rhs)
394
428
  {
395
- if (!*this || !rhs)
396
- argument_error(__FILE__, __LINE__);
429
+ if (!rhs) return *this;
397
430
 
398
- coord x = std::min(this->x, rhs.x);
399
- coord y = std::min(this->y, rhs.y);
400
- coord z = std::min(this->z, rhs.z);
431
+ coord x = std::min(this->x, rhs.x);
432
+ coord y = std::min(this->y, rhs.y);
433
+ coord z = std::min(this->z, rhs.z);
401
434
  coord w = std::max(this->x + this->w, rhs.x + rhs.w) - x;
402
435
  coord h = std::max(this->y + this->h, rhs.y + rhs.h) - y;
403
436
  coord d = std::max(this->z + this->d, rhs.z + rhs.d) - z;
@@ -405,6 +438,19 @@ namespace Rays
405
438
  return reset(x, y, z, w, h, d);
406
439
  }
407
440
 
441
+ Bounds&
442
+ Bounds::operator |= (const Point& rhs)
443
+ {
444
+ coord x = std::min(this->x, rhs.x);
445
+ coord y = std::min(this->y, rhs.y);
446
+ coord z = std::min(this->z, rhs.z);
447
+ coord w = std::max(this->x + this->w, rhs.x) - x;
448
+ coord h = std::max(this->y + this->h, rhs.y) - y;
449
+ coord d = std::max(this->z + this->d, rhs.z) - z;
450
+
451
+ return reset(x, y, z, w, h, d);
452
+ }
453
+
408
454
  bool
409
455
  operator == (const Bounds& lhs, const Bounds& rhs)
410
456
  {
@@ -439,5 +485,22 @@ namespace Rays
439
485
  return t;
440
486
  }
441
487
 
488
+ Bounds
489
+ operator | (const Bounds& lhs, const Point& rhs)
490
+ {
491
+ Bounds t = lhs;
492
+ t |= rhs;
493
+ return t;
494
+ }
495
+
496
+
497
+ Bounds
498
+ invalid_bounds ()
499
+ {
500
+ coord max = FLT_MAX / 2;
501
+ coord size = -FLT_MAX;
502
+ return Bounds(max, max, max, size, size, size);
503
+ }
504
+
442
505
 
443
506
  }// Rays
@@ -2,44 +2,69 @@
2
2
 
3
3
 
4
4
  #include <limits.h>
5
+ #include <glm/gtx/color_space.hpp>
5
6
  #include <xot/util.h>
6
7
  #include "rays/exception.h"
7
8
  #include "rays/color_space.h"
9
+ #include "coord.h"
8
10
 
9
11
 
10
12
  namespace Rays
11
13
  {
12
14
 
13
15
 
14
- Color::Color (float gray, float alpha)
16
+ Color
17
+ gray (float gray, float alpha)
15
18
  {
16
- reset(gray, alpha);
19
+ return Color(gray, alpha);
17
20
  }
18
21
 
19
- Color::Color (float red, float green, float blue, float alpha)
22
+ Color
23
+ gray8 (int gray, int alpha)
20
24
  {
21
- reset(red, green, blue, alpha);
25
+ Color c;
26
+ c.reset8(gray, alpha);
27
+ return c;
22
28
  }
23
29
 
24
- Color::Color (void* pixel, const ColorSpace& cs)
30
+ Color
31
+ rgb (float red, float green, float blue, float alpha)
25
32
  {
26
- reset(pixel, cs);
33
+ return Color(red, green, blue, alpha);
27
34
  }
28
35
 
29
36
  Color
30
- Color8 (uchar gray, uchar alpha)
37
+ rgb8 (int red, int green, int blue, int alpha)
31
38
  {
32
39
  Color c;
33
- c.reset8(gray, alpha);
40
+ c.reset8(red, green, blue, alpha);
34
41
  return c;
35
42
  }
36
43
 
37
44
  Color
38
- Color8 (uchar red, uchar green, uchar blue, uchar alpha)
45
+ hsv (float hue, float saturation, float value, float alpha)
39
46
  {
40
- Color c;
41
- c.reset8(red, green, blue, alpha);
42
- return c;
47
+ hue = fmod(hue, 1.f);
48
+ if (hue < 0) hue += 1.f;
49
+
50
+ auto c = glm::rgbColor(Vec3(hue * 360.f, saturation, value));
51
+ return Color(c[0], c[1], c[2], alpha);
52
+ }
53
+
54
+
55
+ Color::Color (float gray, float alpha)
56
+ {
57
+ reset(gray, alpha);
58
+ }
59
+
60
+ Color::Color (float red, float green, float blue, float alpha)
61
+ {
62
+ reset(red, green, blue, alpha);
63
+ }
64
+
65
+ Color::Color (void* pixel, const ColorSpace& cs)
66
+ {
67
+ reset(pixel, cs);
43
68
  }
44
69
 
45
70
  Color
@@ -57,15 +82,12 @@ namespace Rays
57
82
  Color&
58
83
  Color::reset (float red, float green, float blue, float alpha)
59
84
  {
60
- this->red = red;
61
- this->green = green;
62
- this->blue = blue;
63
- this->alpha = alpha;
85
+ Super::reset(red, green, blue, alpha);
64
86
  return *this;
65
87
  }
66
88
 
67
89
  Color&
68
- Color::reset8 (uchar gray, uchar alpha)
90
+ Color::reset8 (int gray, int alpha)
69
91
  {
70
92
  float g = uchar2float(gray);
71
93
  float a = uchar2float(alpha);
@@ -73,12 +95,13 @@ namespace Rays
73
95
  }
74
96
 
75
97
  Color&
76
- Color::reset8 (uchar red, uchar green, uchar blue, uchar alpha)
98
+ Color::reset8 (int red, int green, int blue, int alpha)
77
99
  {
78
- this->red = uchar2float(red);
79
- this->green = uchar2float(green);
80
- this->blue = uchar2float(blue);
81
- this->alpha = uchar2float(alpha);
100
+ Super::reset(
101
+ uchar2float(red),
102
+ uchar2float(green),
103
+ uchar2float(blue),
104
+ uchar2float(alpha));
82
105
  return *this;
83
106
  }
84
107
 
@@ -211,7 +234,7 @@ namespace Rays
211
234
 
212
235
  Color::operator bool () const
213
236
  {
214
- return red >= 0 && green >= 0 && blue >= 0 && alpha >= 0;
237
+ return alpha > 0;
215
238
  }
216
239
 
217
240
  bool
@@ -220,5 +243,17 @@ namespace Rays
220
243
  return !operator bool();
221
244
  }
222
245
 
246
+ bool
247
+ operator == (const Color& lhs, const Color& rhs)
248
+ {
249
+ return lhs.r == rhs.r && lhs.g == rhs.g && lhs.b == rhs.b && lhs.a == rhs.a;
250
+ }
251
+
252
+ bool
253
+ operator != (const Color& lhs, const Color& rhs)
254
+ {
255
+ return !operator==(lhs, rhs);
256
+ }
257
+
223
258
 
224
259
  }// Rays
@@ -1,4 +1,4 @@
1
- #include "rays/color_space.h"
1
+ #include "color_space.h"
2
2
 
3
3
 
4
4
  #include <assert.h>
@@ -13,13 +13,15 @@ namespace Rays
13
13
  enum
14
14
  {
15
15
 
16
- FIRST = GRAY_8, LAST = ABGR_float,
16
+ FIRST = GRAY_8, LAST = ABGR_float,
17
17
 
18
- GRAY_FIRST = GRAY_8, GRAY_LAST = GRAY_float,
18
+ GRAY_FIRST = GRAY_8, GRAY_LAST = GRAY_float,
19
19
 
20
- RGB_FIRST = RGB_888, RGB_LAST = ABGR_float,
20
+ ALPHA_FIRST = ALPHA_8, ALPHA_LAST = ALPHA_float,
21
21
 
22
- FLOAT_SECOND = RGB_float, FLOAT_LAST = ABGR_float,
22
+ RGB_FIRST = RGB_888, RGB_LAST = ABGR_float,
23
+
24
+ RGB_FLOAT_FIRST = RGB_float, RGB_FLOAT_LAST = ABGR_float,
23
25
 
24
26
  };
25
27
 
@@ -45,10 +47,13 @@ namespace Rays
45
47
  {
46
48
  static const int BPPS[] =
47
49
  {
48
- 0, // UNKNOWN
49
- 8, 16, 24, 32, 32, // GRAY
50
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, // RGB(A), BGR(A)
51
- 32, 32, 32, 32, 32, 32, // RGB(A), BGR(A) float
50
+ 0, // UNKNOWN
51
+ 8, 16, 24, 32, 32, // GRAY
52
+ 8, 16, 24, 32, 32, // ALPHA
53
+ 8, 8, 8, 8, 8, // RGB(A),
54
+ 8, 8, 8, 8, 8, // BGR(A)
55
+ 32, 32, 32, // RGB(A) float
56
+ 32, 32, 32, // BGR(A) float
52
57
  };
53
58
  if (type_ < 0 || COLORSPACE_LAST <= type_) return BPPS[COLORSPACE_UNKNOWN];
54
59
  return BPPS[type_];
@@ -67,6 +72,7 @@ namespace Rays
67
72
  {
68
73
  0, // UNKNOWN
69
74
  8, 16, 24, 32, 32, // GRAY
75
+ 8, 16, 24, 32, 32, // ALPHA
70
76
  24, 32, 32, 32, 32, // RGB(A)
71
77
  24, 32, 32, 32, 32, // BGR(A)
72
78
  96, 128, 128, // RGB(A) float
@@ -91,7 +97,13 @@ namespace Rays
91
97
  bool
92
98
  ColorSpace::is_gray () const
93
99
  {
94
- return GRAY_FIRST <= (int) type_ && (int) type_ <= GRAY_LAST;
100
+ return GRAY_FIRST <= (int) type_ && (int) type_ <= GRAY_LAST;
101
+ }
102
+
103
+ bool
104
+ ColorSpace::is_alpha () const
105
+ {
106
+ return ALPHA_FIRST <= (int) type_ && (int) type_ <= ALPHA_LAST;
95
107
  }
96
108
 
97
109
  bool
@@ -114,14 +126,15 @@ namespace Rays
114
126
  ColorSpace::is_float () const
115
127
  {
116
128
  return
117
- type_ == GRAY_float ||
118
- (FLOAT_SECOND <= (int) type_ && (int) type_ <= FLOAT_LAST);
129
+ type_ == GRAY_float || type_ == ALPHA_float ||
130
+ (RGB_FLOAT_FIRST <= (int) type_ && (int) type_ <= RGB_FLOAT_LAST);
119
131
  }
120
132
 
121
133
  bool
122
134
  ColorSpace::has_alpha () const
123
135
  {
124
136
  return
137
+ (ALPHA_FIRST <= type_ && type_ <= ALPHA_LAST) ||
125
138
  type_ == RGBA_8888 || type_ == ARGB_8888 ||
126
139
  type_ == BGRA_8888 || type_ == ABGR_8888 ||
127
140
  type_ == RGBA_float || type_ == ARGB_float ||
@@ -170,51 +183,56 @@ namespace Rays
170
183
  return premult;
171
184
  }
172
185
 
186
+ ColorSpace::operator bool () const
187
+ {
188
+ return FIRST <= (int) type_ && (int) type_ <= LAST;
189
+ }
190
+
191
+ bool
192
+ ColorSpace::operator ! () const
193
+ {
194
+ return !operator bool();
195
+ }
196
+
197
+
173
198
  void
174
- ColorSpace::get_gl_enums (GLenum* format, GLenum* type, bool alpha_only) const
199
+ ColorSpace_get_gl_format_and_type (
200
+ GLenum* format, GLenum* type, const ColorSpace& cs)
175
201
  {
176
202
  if (!format && !type)
177
203
  argument_error(__FILE__, __LINE__);
178
204
 
179
- if (!*this)
205
+ if (!cs)
180
206
  invalid_state_error(__FILE__, __LINE__);
181
207
 
182
208
  if (format)
183
209
  {
184
- if (is_rgb()) *format = has_alpha() ? GL_RGBA : GL_RGB;
210
+ if (cs.is_rgb()) *format = cs.has_alpha() ? GL_RGBA : GL_RGB;
185
211
  #ifndef IOS
186
- else if (is_bgr()) *format = has_alpha() ? GL_BGRA : GL_BGR;
212
+ else if (cs.is_bgr()) *format = cs.has_alpha() ? GL_BGRA : GL_BGR;
187
213
  #endif
188
- else if (is_gray()) *format = alpha_only ? GL_ALPHA : GL_LUMINANCE;
189
- else rays_error(__FILE__, __LINE__, "invalid color space.");
214
+ else if (cs.is_gray()) *format = GL_LUMINANCE;
215
+ else if (cs.is_alpha()) *format = GL_ALPHA;
216
+ else
217
+ rays_error(__FILE__, __LINE__, "invalid color space.");
190
218
  }
191
219
 
192
220
  if (type)
193
221
  {
194
- if (is_float())
222
+ if (cs.is_float())
195
223
  *type = GL_FLOAT;
196
- else switch (bpc())
224
+ else switch (cs.bpc())
197
225
  {
198
226
  case 8: *type = GL_UNSIGNED_BYTE; break;
199
227
  case 16: *type = GL_UNSIGNED_SHORT; break;
200
228
  #ifndef IOS
201
229
  case 32: *type = GL_UNSIGNED_INT; break;
202
230
  #endif
203
- default: rays_error(__FILE__, __LINE__, "invalid bpc.");
231
+ default:
232
+ rays_error(__FILE__, __LINE__, "invalid bpc.");
204
233
  }
205
234
  }
206
235
  }
207
236
 
208
- ColorSpace::operator bool () const
209
- {
210
- return FIRST <= (int) type_ && (int) type_ <= LAST;
211
- }
212
-
213
- bool
214
- ColorSpace::operator ! () const
215
- {
216
- return !operator bool();
217
- }
218
-
219
237
 
220
238
  }// Rays