rays 0.1.29 → 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d598cf8c5059a425c7f26881d6a5f411969ed3ad46f07c331372d398f17bf9e6
4
- data.tar.gz: 7f87f57fbaf8deee511e248ce2d8fea4b1e445cda91ec324fd85b9f3959a8e16
3
+ metadata.gz: 88387a7d63567dd0f87d5c28708d1c666b7bd41df31ae34d676a9fcfeb4b19b5
4
+ data.tar.gz: 6a05891d8c4aee2b2ffbdc11fd9d6acc9dee8678f7e98180d399f6a64b04383b
5
5
  SHA512:
6
- metadata.gz: 3e82501e4410fdb429f04cc8acd33a56eeff585ba918a9bfed05ef59db5db61997e279557ec5c3f7e329af285a439f5c49d94be4a4cf7de909f299926e584d2a
7
- data.tar.gz: 8f27df0f080dc97f0f22bbc45abd6a0355d39190a3ff6d48a53abe0c947ca6bc92a5304a214680c7c9871dfa7fde426ef65acc361de594fb113e9ed0c19615fe
6
+ metadata.gz: 14ec81d1d115983f66e39432af1f98d29efe759bf891412fb67e85b09801c89fa6702e4970fd56fcb29cc1d2dfacbeb7d5edc8fb43aaa17accf964bca2b4df30
7
+ data.tar.gz: 4d07ba7e7280e7aba01eed8b483978e750a6bfc5201a345e062977cf379c10f12ca1d75b38ef00677bc0bd0798245050cc14c5f0aa33e70fd93dcca5aa58d920
@@ -94,7 +94,7 @@ VALUE get_at(VALUE self, VALUE x, VALUE y)
94
94
  static Class cBitmap;
95
95
 
96
96
  void
97
- Init_bitmap ()
97
+ Init_rays_bitmap ()
98
98
  {
99
99
  Module mRays = rb_define_module("Rays");
100
100
 
@@ -522,7 +522,7 @@ VALUE invalid(VALUE self)
522
522
  static Class cBounds;
523
523
 
524
524
  void
525
- Init_bounds ()
525
+ Init_rays_bounds ()
526
526
  {
527
527
  Module mRays = rb_define_module("Rays");
528
528
 
@@ -134,7 +134,7 @@ VALUE device_names(VALUE self)
134
134
  static Class cCamera;
135
135
 
136
136
  void
137
- Init_camera ()
137
+ Init_rays_camera ()
138
138
  {
139
139
  Module mRays = rb_define_module("Rays");
140
140
 
@@ -182,7 +182,7 @@ VALUE set_palette_color(VALUE self)
182
182
  static Class cColor;
183
183
 
184
184
  void
185
- Init_color ()
185
+ Init_rays_color ()
186
186
  {
187
187
  Module mRays = rb_define_module("Rays");
188
188
 
@@ -177,7 +177,7 @@ VALUE to_s(VALUE self)
177
177
  static Class cColorSpace;
178
178
 
179
179
  void
180
- Init_color_space ()
180
+ Init_rays_color_space ()
181
181
  {
182
182
  Module mRays = rb_define_module("Rays");
183
183
 
@@ -9,7 +9,7 @@ static Class cOpenGLError;
9
9
  static Class cShaderError;
10
10
 
11
11
  void
12
- Init_exception ()
12
+ Init_rays_exception ()
13
13
  {
14
14
  Module mRays = rb_define_module("Rays");
15
15
 
@@ -86,7 +86,7 @@ VALUE leading(VALUE self)
86
86
  static Class cFont;
87
87
 
88
88
  void
89
- Init_font ()
89
+ Init_rays_font ()
90
90
  {
91
91
  Module mRays = rb_define_module("Rays");
92
92
 
@@ -123,7 +123,7 @@ VALUE load(VALUE self)
123
123
  static Class cImage;
124
124
 
125
125
  void
126
- Init_image ()
126
+ Init_rays_image ()
127
127
  {
128
128
  Module mRays = rb_define_module("Rays");
129
129
 
@@ -193,7 +193,7 @@ VALUE s_rotate(VALUE self)
193
193
  static Class cMatrix;
194
194
 
195
195
  void
196
- Init_matrix ()
196
+ Init_rays_matrix ()
197
197
  {
198
198
  Module mRays = rb_define_module("Rays");
199
199
 
@@ -2,25 +2,25 @@
2
2
 
3
3
 
4
4
  void Init_rays ();
5
- void Init_exception ();
5
+ void Init_rays_exception ();
6
6
 
7
- void Init_point ();
8
- void Init_bounds ();
9
- void Init_color ();
10
- void Init_color_space ();
11
- void Init_matrix ();
7
+ void Init_rays_point ();
8
+ void Init_rays_bounds ();
9
+ void Init_rays_color ();
10
+ void Init_rays_color_space ();
11
+ void Init_rays_matrix ();
12
12
 
13
- void Init_painter ();
14
- void Init_polyline ();
15
- void Init_polygon_line ();
16
- void Init_polygon ();
17
- void Init_bitmap ();
18
- void Init_image ();
19
- void Init_font ();
20
- void Init_shader ();
21
- void Init_camera ();
13
+ void Init_rays_painter ();
14
+ void Init_rays_polyline ();
15
+ void Init_rays_polygon_line ();
16
+ void Init_rays_polygon ();
17
+ void Init_rays_bitmap ();
18
+ void Init_rays_image ();
19
+ void Init_rays_font ();
20
+ void Init_rays_shader ();
21
+ void Init_rays_camera ();
22
22
 
23
- void Init_noise ();
23
+ void Init_rays_noise ();
24
24
 
25
25
 
26
26
  extern "C" void
@@ -35,25 +35,25 @@ extern "C" void
35
35
  Rucy::init();
36
36
 
37
37
  Init_rays();
38
- Init_exception();
39
-
40
- Init_point();
41
- Init_bounds();
42
- Init_color();
43
- Init_color_space();
44
- Init_matrix();
45
-
46
- Init_painter();
47
- Init_polyline();
48
- Init_polygon_line();
49
- Init_polygon();
50
- Init_bitmap();
51
- Init_image();
52
- Init_font();
53
- Init_shader();
54
- Init_camera();
55
-
56
- Init_noise();
38
+ Init_rays_exception();
39
+
40
+ Init_rays_point();
41
+ Init_rays_bounds();
42
+ Init_rays_color();
43
+ Init_rays_color_space();
44
+ Init_rays_matrix();
45
+
46
+ Init_rays_painter();
47
+ Init_rays_polyline();
48
+ Init_rays_polygon_line();
49
+ Init_rays_polygon();
50
+ Init_rays_bitmap();
51
+ Init_rays_image();
52
+ Init_rays_font();
53
+ Init_rays_shader();
54
+ Init_rays_camera();
55
+
56
+ Init_rays_noise();
57
57
 
58
58
  RUCY_CATCH
59
59
  }
@@ -45,7 +45,7 @@ VALUE simplex(VALUE self)
45
45
 
46
46
 
47
47
  void
48
- Init_noise ()
48
+ Init_rays_noise ()
49
49
  {
50
50
  Module mRays = rb_define_module("Rays");
51
51
  rb_define_singleton_method(mRays, "perlin", RUBY_METHOD_FUNC(perlin), -1);
@@ -602,7 +602,7 @@ VALUE pop_matrix(VALUE self)
602
602
  static Class cPainter;
603
603
 
604
604
  void
605
- Init_painter ()
605
+ Init_rays_painter ()
606
606
  {
607
607
  Module mRays = rb_define_module("Rays");
608
608
 
@@ -247,7 +247,7 @@ VALUE cross(VALUE self, VALUE p1, VALUE p2)
247
247
  static Class cPoint;
248
248
 
249
249
  void
250
- Init_point ()
250
+ Init_rays_point ()
251
251
  {
252
252
  Module mRays = rb_define_module("Rays");
253
253
 
@@ -233,7 +233,7 @@ VALUE create_bezier(VALUE self, VALUE args, VALUE loop)
233
233
  static Class cPolygon;
234
234
 
235
235
  void
236
- Init_polygon ()
236
+ Init_rays_polygon ()
237
237
  {
238
238
  Module mRays = rb_define_module("Rays");
239
239
 
@@ -39,7 +39,7 @@ VALUE hole(VALUE self)
39
39
  static Class cPolygonLine;
40
40
 
41
41
  void
42
- Init_polygon_line ()
42
+ Init_rays_polygon_line ()
43
43
  {
44
44
  Module mRays = rb_define_module("Rays");
45
45
  Class cPolygon = rb_define_class_under(mRays, "Polygon", rb_cObject);
@@ -105,7 +105,7 @@ VALUE each(VALUE self)
105
105
  static Class cPolyline;
106
106
 
107
107
  void
108
- Init_polyline ()
108
+ Init_rays_polyline ()
109
109
  {
110
110
  Module mRays = rb_define_module("Rays");
111
111
 
@@ -171,7 +171,7 @@ VALUE get_fragment_shader_source(VALUE self)
171
171
  static Class cShader;
172
172
 
173
173
  void
174
- Init_shader ()
174
+ Init_rays_shader ()
175
175
  {
176
176
  Module mRays = rb_define_module("Rays");
177
177
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.29
1
+ 0.1.30
data/ext/rays/bitmap.cpp CHANGED
@@ -102,7 +102,7 @@ RUCY_END
102
102
  static Class cBitmap;
103
103
 
104
104
  void
105
- Init_bitmap ()
105
+ Init_rays_bitmap ()
106
106
  {
107
107
  Module mRays = define_module("Rays");
108
108
 
data/ext/rays/bounds.cpp CHANGED
@@ -569,7 +569,7 @@ RUCY_END
569
569
  static Class cBounds;
570
570
 
571
571
  void
572
- Init_bounds ()
572
+ Init_rays_bounds ()
573
573
  {
574
574
  Module mRays = define_module("Rays");
575
575
 
data/ext/rays/camera.cpp CHANGED
@@ -149,7 +149,7 @@ RUCY_END
149
149
  static Class cCamera;
150
150
 
151
151
  void
152
- Init_camera ()
152
+ Init_rays_camera ()
153
153
  {
154
154
  Module mRays = define_module("Rays");
155
155
 
data/ext/rays/color.cpp CHANGED
@@ -195,7 +195,7 @@ RUCY_END
195
195
  static Class cColor;
196
196
 
197
197
  void
198
- Init_color ()
198
+ Init_rays_color ()
199
199
  {
200
200
  Module mRays = define_module("Rays");
201
201
 
@@ -190,7 +190,7 @@ RUCY_END
190
190
  static Class cColorSpace;
191
191
 
192
192
  void
193
- Init_color_space ()
193
+ Init_rays_color_space ()
194
194
  {
195
195
  Module mRays = define_module("Rays");
196
196
 
@@ -9,7 +9,7 @@ static Class cOpenGLError;
9
9
  static Class cShaderError;
10
10
 
11
11
  void
12
- Init_exception ()
12
+ Init_rays_exception ()
13
13
  {
14
14
  Module mRays = define_module("Rays");
15
15
 
data/ext/rays/extconf.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  %w[../xot ../rucy .]
5
- .map {|s| File.expand_path "../../../#{s}/lib", __FILE__}
5
+ .map {|s| File.expand_path "../../#{s}/lib", __dir__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
8
  require 'mkmf'
data/ext/rays/font.cpp CHANGED
@@ -95,7 +95,7 @@ RUCY_END
95
95
  static Class cFont;
96
96
 
97
97
  void
98
- Init_font ()
98
+ Init_rays_font ()
99
99
  {
100
100
  Module mRays = define_module("Rays");
101
101
 
data/ext/rays/image.cpp CHANGED
@@ -134,7 +134,7 @@ RUCY_END
134
134
  static Class cImage;
135
135
 
136
136
  void
137
- Init_image ()
137
+ Init_rays_image ()
138
138
  {
139
139
  Module mRays = define_module("Rays");
140
140
 
data/ext/rays/matrix.cpp CHANGED
@@ -209,7 +209,7 @@ RUCY_END
209
209
  static Class cMatrix;
210
210
 
211
211
  void
212
- Init_matrix ()
212
+ Init_rays_matrix ()
213
213
  {
214
214
  Module mRays = define_module("Rays");
215
215
 
data/ext/rays/native.cpp CHANGED
@@ -2,25 +2,25 @@
2
2
 
3
3
 
4
4
  void Init_rays ();
5
- void Init_exception ();
5
+ void Init_rays_exception ();
6
6
 
7
- void Init_point ();
8
- void Init_bounds ();
9
- void Init_color ();
10
- void Init_color_space ();
11
- void Init_matrix ();
7
+ void Init_rays_point ();
8
+ void Init_rays_bounds ();
9
+ void Init_rays_color ();
10
+ void Init_rays_color_space ();
11
+ void Init_rays_matrix ();
12
12
 
13
- void Init_painter ();
14
- void Init_polyline ();
15
- void Init_polygon_line ();
16
- void Init_polygon ();
17
- void Init_bitmap ();
18
- void Init_image ();
19
- void Init_font ();
20
- void Init_shader ();
21
- void Init_camera ();
13
+ void Init_rays_painter ();
14
+ void Init_rays_polyline ();
15
+ void Init_rays_polygon_line ();
16
+ void Init_rays_polygon ();
17
+ void Init_rays_bitmap ();
18
+ void Init_rays_image ();
19
+ void Init_rays_font ();
20
+ void Init_rays_shader ();
21
+ void Init_rays_camera ();
22
22
 
23
- void Init_noise ();
23
+ void Init_rays_noise ();
24
24
 
25
25
 
26
26
  extern "C" void
@@ -35,25 +35,25 @@ extern "C" void
35
35
  Rucy::init();
36
36
 
37
37
  Init_rays();
38
- Init_exception();
39
-
40
- Init_point();
41
- Init_bounds();
42
- Init_color();
43
- Init_color_space();
44
- Init_matrix();
45
-
46
- Init_painter();
47
- Init_polyline();
48
- Init_polygon_line();
49
- Init_polygon();
50
- Init_bitmap();
51
- Init_image();
52
- Init_font();
53
- Init_shader();
54
- Init_camera();
55
-
56
- Init_noise();
38
+ Init_rays_exception();
39
+
40
+ Init_rays_point();
41
+ Init_rays_bounds();
42
+ Init_rays_color();
43
+ Init_rays_color_space();
44
+ Init_rays_matrix();
45
+
46
+ Init_rays_painter();
47
+ Init_rays_polyline();
48
+ Init_rays_polygon_line();
49
+ Init_rays_polygon();
50
+ Init_rays_bitmap();
51
+ Init_rays_image();
52
+ Init_rays_font();
53
+ Init_rays_shader();
54
+ Init_rays_camera();
55
+
56
+ Init_rays_noise();
57
57
 
58
58
  RUCY_CATCH
59
59
  }
data/ext/rays/noise.cpp CHANGED
@@ -47,7 +47,7 @@ RUCY_END
47
47
 
48
48
 
49
49
  void
50
- Init_noise ()
50
+ Init_rays_noise ()
51
51
  {
52
52
  Module mRays = define_module("Rays");
53
53
  mRays.define_singleton_method("perlin", perlin);
data/ext/rays/painter.cpp CHANGED
@@ -656,7 +656,7 @@ RUCY_END
656
656
  static Class cPainter;
657
657
 
658
658
  void
659
- Init_painter ()
659
+ Init_rays_painter ()
660
660
  {
661
661
  Module mRays = define_module("Rays");
662
662
 
data/ext/rays/point.cpp CHANGED
@@ -272,7 +272,7 @@ RUCY_END
272
272
  static Class cPoint;
273
273
 
274
274
  void
275
- Init_point ()
275
+ Init_rays_point ()
276
276
  {
277
277
  Module mRays = define_module("Rays");
278
278
 
data/ext/rays/polygon.cpp CHANGED
@@ -249,7 +249,7 @@ RUCY_END
249
249
  static Class cPolygon;
250
250
 
251
251
  void
252
- Init_polygon ()
252
+ Init_rays_polygon ()
253
253
  {
254
254
  Module mRays = define_module("Rays");
255
255
 
@@ -42,7 +42,7 @@ RUCY_END
42
42
  static Class cPolygonLine;
43
43
 
44
44
  void
45
- Init_polygon_line ()
45
+ Init_rays_polygon_line ()
46
46
  {
47
47
  Module mRays = define_module("Rays");
48
48
  Class cPolygon = mRays.define_class("Polygon");
@@ -114,7 +114,7 @@ RUCY_END
114
114
  static Class cPolyline;
115
115
 
116
116
  void
117
- Init_polyline ()
117
+ Init_rays_polyline ()
118
118
  {
119
119
  Module mRays = define_module("Rays");
120
120
 
data/ext/rays/shader.cpp CHANGED
@@ -176,7 +176,7 @@ RUCY_END
176
176
  static Class cShader;
177
177
 
178
178
  void
179
- Init_shader ()
179
+ Init_rays_shader ()
180
180
  {
181
181
  Module mRays = define_module("Rays");
182
182
 
data/rays.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
- File.expand_path('../lib', __FILE__)
4
+ File.expand_path('lib', __dir__)
5
5
  .tap {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
6
6
 
7
7
  require 'rays/module'
@@ -28,8 +28,8 @@ Gem::Specification.new do |s|
28
28
  s.platform = Gem::Platform::RUBY
29
29
  s.required_ruby_version = '>= 2.6.0'
30
30
 
31
- s.add_runtime_dependency 'xot', '~> 0.1.29'
32
- s.add_runtime_dependency 'rucy', '~> 0.1.29'
31
+ s.add_runtime_dependency 'xot', '~> 0.1.30'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1.30'
33
33
 
34
34
  s.files = `git ls-files`.split $/
35
35
  s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
data/src/opengl.cpp CHANGED
@@ -24,7 +24,7 @@ namespace Rays
24
24
  case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
25
25
  case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
26
26
  case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
27
- #if !defined(GL_VERSION_3_0)
27
+ #if !defined(GL_VERSION_3_0) && !defined(GL_ES_VERSION_2_0)
28
28
  case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW";
29
29
  case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW";
30
30
  case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
@@ -45,11 +45,10 @@ namespace Rays
45
45
  void
46
46
  OpenGL_check_error (const char* file, int line, const char* format, ...)
47
47
  {
48
- XOT_STRINGF(format, s);
49
-
50
48
  GLenum e = glGetError();
51
49
  if (e != GL_NO_ERROR)
52
50
  {
51
+ XOT_STRINGF(format, s);
53
52
  opengl_error(
54
53
  file, line,
55
54
  "OpenGL error %s: %s", get_error_name(e).c_str(), s.c_str());
data/src/painter.cpp CHANGED
@@ -329,16 +329,18 @@ namespace Rays
329
329
 
330
330
  const auto& names = Shader_get_builtin_variable_names(shader);
331
331
  apply_builtin_uniforms(*program, names, texinfo);
332
- apply_attributes(*program, names, points, npoints, texcoords, color, [&]() {
333
- draw_indices(mode, indices, nindices, npoints);
334
- });
332
+ apply_attributes(*program, names, points, npoints, texcoords, color);
333
+ draw_indices(mode, indices, nindices, npoints);
334
+ cleanup();
335
335
 
336
336
  ShaderProgram_deactivate();
337
337
  }
338
338
 
339
339
  private:
340
340
 
341
- typedef std::vector<GLint> LocationList;
341
+ std::vector<GLint> locations;
342
+
343
+ std::vector<GLuint> buffers;
342
344
 
343
345
  void apply_builtin_uniforms (
344
346
  const ShaderProgram& program, const ShaderBuiltinVariableNames& names,
@@ -406,21 +408,16 @@ namespace Rays
406
408
 
407
409
  void apply_attributes (
408
410
  const ShaderProgram& program, const ShaderBuiltinVariableNames& names,
409
- const Coord3* points, size_t npoints, const Coord3* texcoords, const Color& color,
410
- std::function<void()> draw_fun)
411
+ const Coord3* points, size_t npoints, const Coord3* texcoords,
412
+ const Color& color)
411
413
  {
412
414
  assert(points && npoints > 0);
413
415
 
414
- std::vector<GLuint> buffers;
415
- LocationList locations;
416
-
417
416
  apply_attribute(
418
- &buffers, &locations,
419
417
  program, names.attribute_position_names,
420
418
  points, npoints);
421
419
 
422
420
  apply_attribute(
423
- &buffers, &locations,
424
421
  program, names.attribute_texcoord_names,
425
422
  texcoords ? texcoords : points, npoints);
426
423
 
@@ -429,54 +426,44 @@ namespace Rays
429
426
  // with specific glsl 'attribute' name.
430
427
  std::vector<Color> colors(npoints, color);
431
428
  apply_attribute(
432
- &buffers, &locations,
433
429
  program, names.attribute_color_names,
434
430
  (const Coord4*) &colors[0], npoints);
435
431
  #else
436
432
  for (const auto& name : names.attribute_color_names)
437
433
  {
438
- apply_attribute(NULL, program, name, [&](GLint loc) {
434
+ apply_attribute(program, name, [&](GLint loc) {
439
435
  glVertexAttrib4fv(loc, color.array);
440
436
  });
441
437
  }
442
438
  #endif
443
-
444
- draw_fun();
445
-
446
- for (auto loc : locations)
447
- {
448
- glDisableVertexAttribArray(loc);
449
- OpenGL_check_error(__FILE__, __LINE__);
450
- }
451
-
452
- glDeleteBuffers((GLsizei) buffers.size(), &buffers[0]);
453
- OpenGL_check_error(__FILE__, __LINE__);
454
439
  }
455
440
 
456
441
  template <typename CoordN>
457
442
  void apply_attribute(
458
- auto* buffers, LocationList* locations,
459
443
  const ShaderProgram& program, const auto& names,
460
444
  const CoordN* values, size_t nvalues)
461
445
  {
462
- assert(buffers);
463
-
464
446
  GLuint buffer = 0;
465
447
  for (const auto& name : names)
466
448
  {
467
- apply_attribute(locations, program, name, [&](GLint loc) {
449
+ #ifndef IOS
468
450
  if (buffer == 0)
469
451
  {
470
- buffer = create_and_bind_coordn_buffer(values, nvalues);
471
- buffers->push_back(buffer);
452
+ buffer = create_and_bind_buffer(
453
+ GL_ARRAY_BUFFER, values, sizeof(CoordN) * nvalues);
454
+ values = 0;
472
455
  }
456
+ #endif
473
457
 
458
+ apply_attribute(program, name, [&](GLint loc) {
474
459
  glEnableVertexAttribArray(loc);
475
- OpenGL_check_error(__FILE__, __LINE__, "loc: %d %s\n", loc, name.c_str());
460
+ OpenGL_check_error(
461
+ __FILE__, __LINE__, "loc: %d %s\n", loc, name.c_str());
476
462
 
477
463
  glVertexAttribPointer(
478
- loc, CoordN::SIZE, get_gl_type<coord>(),
479
- GL_FALSE, sizeof(CoordN), NULL);
464
+ loc, CoordN::SIZE, get_gl_type<coord>(), GL_FALSE, 0, values);
465
+
466
+ locations.push_back(loc);
480
467
  });
481
468
  }
482
469
 
@@ -485,26 +472,24 @@ namespace Rays
485
472
  }
486
473
 
487
474
  void apply_attribute (
488
- LocationList* locations, const ShaderProgram& program, const char* name,
489
- std::function<void(GLint)> apply)
475
+ const ShaderProgram& program, const char* name,
476
+ std::function<void(GLint)> apply_fun)
490
477
  {
491
478
  GLint loc = glGetAttribLocation(program.id(), name);
492
479
  if (loc < 0) return;
493
480
 
494
- apply(loc);
481
+ apply_fun(loc);
495
482
  OpenGL_check_error(__FILE__, __LINE__);
496
-
497
- if (locations) locations->push_back(loc);
498
483
  }
499
484
 
500
485
  void apply_uniform (
501
486
  const ShaderProgram& program, const char* name,
502
- std::function<void(GLint)> apply)
487
+ std::function<void(GLint)> apply_fun)
503
488
  {
504
489
  GLint loc = glGetUniformLocation(program.id(), name);
505
490
  if (loc < 0) return;
506
491
 
507
- apply(loc);
492
+ apply_fun(loc);
508
493
  OpenGL_check_error(__FILE__, __LINE__);
509
494
  }
510
495
 
@@ -518,75 +503,52 @@ namespace Rays
518
503
  nindices = npoints;
519
504
  }
520
505
 
521
- GLuint buffer = create_buffer();
522
- size_t size = sizeof(uint) * nindices;
523
-
524
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
525
- OpenGL_check_error(__FILE__, __LINE__);
526
-
527
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STREAM_DRAW);
528
- OpenGL_check_error(__FILE__, __LINE__);
506
+ #ifdef IOS
507
+ glDrawElements(mode, (GLsizei) nindices, GL_UNSIGNED_INT, indices);
508
+ OpenGL_check_error(__FILE__, __LINE__);
509
+ #else
510
+ create_and_bind_buffer(
511
+ GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(uint) * nindices);
529
512
 
530
- glDrawElements(mode, (GLsizei) nindices, GL_UNSIGNED_INT, NULL);
531
- OpenGL_check_error(__FILE__, __LINE__);
513
+ glDrawElements(mode, (GLsizei) nindices, GL_UNSIGNED_INT, 0);
514
+ OpenGL_check_error(__FILE__, __LINE__);
532
515
 
533
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
534
- OpenGL_check_error(__FILE__, __LINE__);
516
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
517
+ OpenGL_check_error(__FILE__, __LINE__);
518
+ #endif
535
519
  }
536
520
 
537
- template <typename CoordN>
538
- GLuint create_and_bind_coordn_buffer (const CoordN* values, size_t nvalues)
521
+ GLuint create_and_bind_buffer (
522
+ GLenum target, const void* data, GLsizeiptr size)
539
523
  {
540
- GLuint id = create_buffer();
541
- size_t size = sizeof(CoordN) * nvalues;
542
-
543
- glBindBuffer(GL_ARRAY_BUFFER, id);
524
+ GLuint id = 0;
525
+ glGenBuffers(1, &id);
544
526
  OpenGL_check_error(__FILE__, __LINE__);
545
527
 
546
- glBufferData(GL_ARRAY_BUFFER, size, values, GL_STREAM_DRAW);
547
- OpenGL_check_error(__FILE__, __LINE__);
528
+ buffers.push_back(id);
548
529
 
549
- return id;
550
- }
530
+ glBindBuffer(target, id);
531
+ OpenGL_check_error(__FILE__, __LINE__);
551
532
 
552
- GLuint create_buffer ()
553
- {
554
- GLuint id;
555
- glGenBuffers(1, &id);
533
+ glBufferData(target, size, data, GL_STREAM_DRAW);
556
534
  OpenGL_check_error(__FILE__, __LINE__);
535
+
557
536
  return id;
558
537
  }
559
538
 
560
- void activate_texture (const Texture* texture)
539
+ void cleanup ()
561
540
  {
562
- if (!texture)
541
+ for (auto loc : locations)
563
542
  {
564
- glDisable(GL_TEXTURE_2D);
565
- return;
543
+ glDisableVertexAttribArray(loc);
544
+ OpenGL_check_error(__FILE__, __LINE__);
566
545
  }
567
546
 
568
- if (!*texture)
569
- argument_error(__FILE__, __LINE__, "invalid texture.");
570
-
571
- GLuint id = texture->id();
572
- if (id != get_current_texture_id())
573
- glBindTexture(GL_TEXTURE_2D, id);
574
-
575
- glEnable(GL_TEXTURE_2D);
576
- }
577
-
578
- GLuint get_current_texture_id ()
579
- {
580
- GLint id = 0;
581
- glGetIntegerv(GL_TEXTURE_BINDING_2D, &id);
582
- return (GLuint) id;
583
- }
584
-
585
- void deactivate_texture (const Texture* texture)
586
- {
587
- if (!texture) return;
547
+ glDeleteBuffers((GLsizei) buffers.size(), &buffers[0]);
548
+ OpenGL_check_error(__FILE__, __LINE__);
588
549
 
589
- glDisable(GL_TEXTURE_2D);
550
+ locations.clear();
551
+ buffers.clear();
590
552
  }
591
553
 
592
554
  };// Painter::Data
data/src/shader.cpp CHANGED
@@ -67,7 +67,7 @@ namespace Rays
67
67
  ShaderSource make_fragment_shader_source (const char* source)
68
68
  {
69
69
  #ifdef IOS
70
- static const String SHARED_HEADER = "precision mediump float;\n";
70
+ static const String SHARED_HEADER = "precision highp float;\n";
71
71
  static const std::regex PRECISION(R"(^\s*precision\s+\w+p\s+float\s*;)");
72
72
 
73
73
  if (!std::regex_search(source, PRECISION))
@@ -128,7 +128,7 @@ namespace Rays
128
128
  "void main ()\n"
129
129
  "{\n"
130
130
  " vec4 col__ = texture2D(" + U_TEXTURE + ", " + V_TEXCOORD + ".xy);\n"
131
- #ifdef OSX
131
+ #if defined(OSX) || defined(IOS)
132
132
  // restore premultiplied rgb values
133
133
  " vec3 rgb__ = col__.a != 0.0 ? col__.rgb / col__.a : col__.rgb;\n"
134
134
  " gl_FragColor = " + V_COLOR + " * vec4(rgb__, col__.a);\n"
@@ -386,8 +386,8 @@ namespace Rays
386
386
  "uniform mat4 " + U_TEXCOORD_MATRIX + ";\n"
387
387
  "void main ()\n"
388
388
  "{\n"
389
- " vec4 pos__ = vec4(" + A_POSITION + ", 1.0);\n"
390
- " vec4 texcoord__ = vec4(" + A_TEXCOORD + ", 1.0);\n"
389
+ " vec4 pos__ = vec4(" + A_POSITION + ", 1.0);\n"
390
+ " vec4 texcoord__ = vec4(" + A_TEXCOORD + ", 1.0);\n"
391
391
  " " + V_POSITION + " = pos__;\n"
392
392
  " " + V_TEXCOORD + " = " + U_TEXCOORD_MATRIX + " * texcoord__;\n"
393
393
  " " + V_COLOR + " = " + A_COLOR + ";\n"
data/src/texture.cpp CHANGED
@@ -181,7 +181,7 @@ namespace Rays
181
181
  static void
182
182
  setup_texture (
183
183
  Texture::Data* self, int width, int height, const ColorSpace& cs,
184
- const Bitmap* bitmap = NULL)
184
+ const Bitmap* bitmap = NULL, bool npot = false)
185
185
  {
186
186
  assert(self && !self->has_id());
187
187
 
@@ -205,11 +205,16 @@ namespace Rays
205
205
  GLenum format, type;
206
206
  ColorSpace_get_gl_format_and_type(&format, &type, cs);
207
207
 
208
- // create non-power-of-two texture
209
- glTexImage2D(
210
- GL_TEXTURE_2D, 0, format, width, height, 0, format, type,
211
- bitmap ? bitmap->pixels() : NULL);
212
- if (OpenGL_has_error())
208
+ if (npot)
209
+ {
210
+ // create non-power-of-two texture
211
+ glTexImage2D(
212
+ GL_TEXTURE_2D, 0, format, width, height, 0, format, type,
213
+ bitmap ? bitmap->pixels() : NULL);
214
+ npot = OpenGL_has_error();
215
+ }
216
+
217
+ if (!npot)
213
218
  {
214
219
  // create power-of-two texture
215
220
  int width_pow2 = min_pow2(width);
data/test/helper.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  %w[../xot ../rucy .]
5
- .map {|s| File.expand_path "../../#{s}/lib", __FILE__}
5
+ .map {|s| File.expand_path "../#{s}/lib", __dir__}
6
6
  .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
7
 
8
8
  require 'test/unit'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-13 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.29
19
+ version: 0.1.30
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.29
26
+ version: 0.1.30
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.29
33
+ version: 0.1.30
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.29
40
+ version: 0.1.30
41
41
  description: This library helps you to develop graphics application with OpenGL.
42
42
  email: xordog@gmail.com
43
43
  executables: []
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  - !ruby/object:Gem::Version
258
258
  version: '0'
259
259
  requirements: []
260
- rubygems_version: 3.2.33
260
+ rubygems_version: 3.4.1
261
261
  signing_key:
262
262
  specification_version: 4
263
263
  summary: A Drawing Engine using OpenGL.