Class: Ray::BufferRenderer

Inherits:
Object
  • Object
show all
Defined in:
ext/buffer_renderer.c,
lib/ray/buffer_renderer.rb,
ext/buffer_renderer.c

Overview

Buffer renderers are a way to draw many drawable quickly, assuming they are not updated too often. It makes things quite faster if you have many drawables that won’t need to be updated for a loong time.

It simply uses drawables to fill its own buffer, and ask those drawables to draw themselves from it.

Instance Method Summary collapse

Constructor Details

#initialize(type, vtype) ⇒ Object

Creates a new buffer renderer.

The type argument indicates how often you may need to update the buffer. Stream, working in most cases, means you are going to update the stream once and use it once. Static means you will just push your data once and use them many times. Dynamic, lastly, means your data will be both updated and drawn often.

Parameters:

  • type (Symbol)

    Type of the buffer (:static, :stream, :dynamic).

  • vtype (Class)

    Class of vertices.



59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/buffer_renderer.c', line 59

static
VALUE ray_buffer_renderer_init(VALUE self, VALUE type, VALUE vtype) {
  rb_iv_set(self, "@drawables", rb_ary_new());

  say_buffer_renderer **ptr;
  Data_Get_Struct(self, say_buffer_renderer*, ptr);

  *ptr = say_buffer_renderer_create(ray_buf_type(type),
                                    ray_get_vtype(vtype));

  return self;
}

Instance Method Details

#clearObject

Removes all the drawables from the renderer.



73
74
75
76
77
78
# File 'ext/buffer_renderer.c', line 73

static
VALUE ray_buffer_renderer_clear(VALUE self) {
  say_buffer_renderer_clear(ray_rb2buf_renderer(self));
  rb_ary_clear(rb_iv_get(self, "@drawables"));
  return self;
}

#drawablesObject



5
6
7
# File 'lib/ray/buffer_renderer.rb', line 5

def drawables
  @drawables.dup # don't let evil users touch this!
end

#push(object) ⇒ Object Also known as: <<

Adds a drawable to render. It won’t be rendered correctly until you call update.

Parameters:



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'ext/buffer_renderer.c', line 87

static
VALUE ray_buffer_renderer_push(VALUE self, VALUE obj) {
  rb_check_frozen(self);

  if (!say_buffer_renderer_push(ray_rb2buf_renderer(self),
                                ray_rb2drawable(obj))) {
    rb_raise(rb_eRuntimeError, "%s", say_error_get_last());
  }

  rb_ary_push(rb_iv_get(self, "@drawables"), obj);

  return self;
}

#updateObject

Upadates the buffer



102
103
104
105
106
# File 'ext/buffer_renderer.c', line 102

static
VALUE ray_buffer_renderer_update(VALUE self) {
  say_buffer_renderer_update(ray_rb2buf_renderer(self));
  return self;
}