Method: Ray::GL::Buffer#update

Defined in:
ext/gl_buffer.c

#update(range = 0...size) ⇒ Object #update(first, size) ⇒ Object

Overloads:

  • #update(range = 0...size) ⇒ Object

    Updates a part of the buffer.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'ext/gl_buffer.c', line 137

static
VALUE ray_gl_buffer_update(int argc, VALUE *argv, VALUE self) {
  say_buffer *buf       = ray_rb2buffer(self);
  size_t      max_index = say_buffer_get_size(buf);

  if (argc == 0)
    say_buffer_update(buf);
  else if (argc == 2) {
    size_t begin = NUM2ULONG(argv[0]);
    size_t end   = NUM2ULONG(argv[1]);

    if (end > max_index)
      end = max_index;

    if (begin > end || begin > max_index)
      return self;

    size_t size = (end - begin) + 1;

    say_buffer_update_part(buf, begin, size);
  }
  else {
    VALUE range;
    rb_scan_args(argc, argv, "1", &range); /* raise exception */

    size_t begin = NUM2ULONG(rb_funcall(range, RAY_METH("begin"), 0));
    size_t end   = NUM2ULONG(rb_funcall(range, RAY_METH("end"), 0));

    if (end > max_index)
      end = max_index;

    if (begin > end || begin > max_index)
      return self;

    size_t size = (end - begin) + 1;

    say_buffer_update_part(buf, begin, size);
  }

  return self;
}