Module: Ray::GL

Defined in:
lib/ray/gl/vertex.rb,
lib/ray/gl/int_array.rb,
ext/gl.c

Defined Under Namespace

Classes: Buffer, IndexBuffer, IntArray, Vertex

Constant Summary collapse

Primitives =

Returns Available primitives.

Returns:

  • (Hash)

    Available primitives.

ray_gl_primitives

Class Method Summary collapse

Class Method Details

.callback=(proc) ⇒ Object

Sets the proc called by OpenGL for debugging purpose The given proc will be called upon some events (errors or warnings about performance and undifined behaviors) with the following arguments:

  1. A source (:api, :window_system, :shader_compiler, :third_party, :application, :other).

  2. A type (:error, :depreacted_behavior, :undefined_behavior, :portability, :performance, :other).

  3. An integer identifier.

  4. A severity (:high, :medium, :low).

  5. A human-readable message.

Notice the debugging proc is only called if the context has been created in debug mode.

Examples:

Ray::GL.debug = true # required

Ray::GL.callback = proc do |source, type, _, severity, msg|
  puts "[#{source}][#{type}][#{severity}] #{msg}"
end

Parameters:

  • proc (Proc, nil)

    A proc, or nil to disable debugging

See Also:



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'ext/gl.c', line 301

static
VALUE ray_gl_set_callback(VALUE self, VALUE proc) {
  say_context_ensure();

  if (!glDebugMessageCallbackARB)
    rb_raise(rb_eRuntimeError, "setting the debug proc isn't supported");

  rb_iv_set(rb_path2class("Ray::GL"), "@callback", proc);
  if (RTEST(proc))
    glDebugMessageCallbackARB(ray_gl_debug_proc, NULL);
  else
    glDebugMessageCallbackARB(NULL, NULL);

  return proc;
}

.core_profile=(val) ⇒ Object

See Also:



188
189
190
191
192
# File 'ext/gl.c', line 188

static
VALUE ray_gl_set_core_profile(VALUE self, VALUE val) {
  say_context_get_config()->core_profile = RTEST(val);
  return val;
}

.core_profile?Bollean

Returns True when a core OpenGL profile must be used.

Returns:

  • (Bollean)

    True when a core OpenGL profile must be used



154
155
156
157
# File 'ext/gl.c', line 154

static
VALUE ray_gl_core_profile(VALUE self) {
  return say_context_get_config()->core_profile ? Qtrue : Qfalse;
}

.debug=(val) ⇒ Object

See Also:



201
202
203
204
205
# File 'ext/gl.c', line 201

static
VALUE ray_gl_set_debug(VALUE self, VALUE val) {
  say_context_get_config()->debug = RTEST(val);
  return val;
}

.debug?true, false

Returns True if debugging mode is enabled.

Returns:

  • (true, false)

    True if debugging mode is enabled



195
196
197
198
# File 'ext/gl.c', line 195

static
VALUE ray_gl_debug(VALUE self) {
  return say_context_get_config()->debug ? Qtrue : Qfalse;
}

.depth_sizeInteger

Returns Size of the depth buffer, in bits.

Returns:

  • (Integer)

    Size of the depth buffer, in bits



130
131
132
133
# File 'ext/gl.c', line 130

static
VALUE ray_gl_depth_size(VALUE self) {
  return ULONG2NUM(say_context_get_config()->depth_size);
}

.depth_size=(val) ⇒ Object

See Also:



160
161
162
163
164
# File 'ext/gl.c', line 160

static
VALUE ray_gl_set_depth_size(VALUE self, VALUE val) {
  say_context_get_config()->depth_size = NUM2ULONG(val);
  return val;
}

.draw_arrays(primitive, first, count) ⇒ Object

Parameters:

  • primitive (Symbol)

    Primitive to draw. Must be one of the folowing: points, line_strip, line_loop, lines, triangle_strip, triangle_fan, triangles.

  • first (Integer)

    Identifier of the first vertex to draw.

  • count (Integer)

    Amount of vertices to draw.



15
16
17
18
19
20
21
# File 'ext/gl.c', line 15

static
VALUE ray_gl_draw_arrays(VALUE self, VALUE primitive, VALUE first,
                         VALUE count) {
  glDrawArrays(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
               NUM2ULONG(first), NUM2ULONG(count));
  return Qnil;
}

.draw_arrays_instanced(primitive, first, count, instance_count) ⇒ Object

Parameters:

  • primitive (Symbol)

    (see #draw_arrays)

  • first (Integer)

    (see #draw_arrays)

  • count (Integer)

    (see #draw_arrays)

  • instance_count (Integer)

    Amount of instances to draw



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'ext/gl.c', line 45

static
VALUE ray_gl_draw_arrays_instanced(VALUE self, VALUE primitive, VALUE first,
                                   VALUE count, VALUE instance_count) {
  say_context_ensure();
  if (glDrawArraysInstanced) {
    glDrawArraysInstanced(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
                          NUM2ULONG(first), NUM2ULONG(count),
                          NUM2ULONG(instance_count));
  }
  else
    rb_raise(rb_eRuntimeError, "GL_ARB_draw_instanced is not supported");

  return Qnil;
}

.draw_elements(primitive, count, index) ⇒ Object

Parameters:

  • index

    First index from the element array.



29
30
31
32
33
34
35
36
# File 'ext/gl.c', line 29

static
VALUE ray_gl_draw_elements(VALUE self, VALUE primitive, VALUE count,
                           VALUE index) {
  glDrawElements(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
                 NUM2ULONG(count),
                 GL_UNSIGNED_INT, (void*)NUM2ULONG(index));
  return Qnil;
}

.draw_elements_instanced(primitive, count, index, instance_count) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/gl.c', line 67

static
VALUE ray_gl_draw_elements_instanced(VALUE self, VALUE primitive, VALUE count,
                                     VALUE index, VALUE instance_count) {
  say_context_ensure();
  if (glDrawElementsInstanced) {
    glDrawElementsInstanced(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
                            NUM2ULONG(count),
                            GL_UNSIGNED_INT, (void*)NUM2ULONG(index),
                            NUM2ULONG(instance_count));
  }
  else
    rb_raise(rb_eRuntimeError, "GL_ARB_draw_instanced is not supported");

  return Qnil;
}

.ensure_contextObject

Ensures an OpenGL context is active for the current thread



320
321
322
323
324
# File 'ext/gl.c', line 320

static
VALUE ray_gl_ensure_context(VALUE self) {
  say_context_ensure();
  return Qnil;
}

.has_callback?True, False

Returns True if a callback proc can be set.

Returns:

  • (True, False)

    True if a callback proc can be set



267
268
269
270
271
# File 'ext/gl.c', line 267

static
VALUE ray_gl_has_callback(VALUE self) {
  say_context_ensure();
  return glDebugMessageCallbackARB ? Qtrue : Qfalse;
}

.major_versionInteger

Returns Major version number. Ignored if less than 3.

Returns:

  • (Integer)

    Major version number. Ignored if less than 3.



142
143
144
145
# File 'ext/gl.c', line 142

static
VALUE ray_gl_major_version(VALUE self) {
  return ULONG2NUM(say_context_get_config()->major_version);
}

.major_version=(val) ⇒ Object

See Also:



174
175
176
177
178
# File 'ext/gl.c', line 174

static
VALUE ray_gl_set_major_version(VALUE self, VALUE val) {
  say_context_get_config()->major_version = NUM2ULONG(val);
  return val;
}

.minor_versionInteger

Returns Minor version number.

Returns:

  • (Integer)

    Minor version number



148
149
150
151
# File 'ext/gl.c', line 148

static
VALUE ray_gl_minor_version(VALUE self) {
  return ULONG2NUM(say_context_get_config()->minor_version);
}

.minor_version=(val) ⇒ Object

See Also:



181
182
183
184
185
# File 'ext/gl.c', line 181

static
VALUE ray_gl_set_minor_version(VALUE self, VALUE val) {
  say_context_get_config()->minor_version = NUM2ULONG(val);
  return val;
}

.multi_draw_arrays(primitive, first, count) ⇒ Object

Parameters:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'ext/gl.c', line 90

static
VALUE ray_gl_multi_draw_arrays(VALUE self, VALUE primitive, VALUE rb_first,
                               VALUE rb_count) {
  mo_array *first = ray_rb2int_array(rb_first);
  mo_array *count = ray_rb2int_array(rb_count);

  if (first->size != count->size)
    rb_raise(rb_eArgError, "first and count arrays should have the same size");

  glMultiDrawArrays(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
                    mo_array_at(first, 0), mo_array_at(count, 0),
                    first->size);

  return Qnil;
}

.multi_draw_elements(primitive, count, index) ⇒ Object

Parameters:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'ext/gl.c', line 113

static
VALUE ray_gl_multi_draw_elements(VALUE self, VALUE primitive, VALUE rb_count,
                                 VALUE rb_index) {
  mo_array *index = ray_rb2int_array(rb_index);
  mo_array *count = ray_rb2int_array(rb_count);

  if (index->size != count->size)
    rb_raise(rb_eArgError, "index and count arrays should have the same size");

  glMultiDrawElements(NUM2INT(rb_hash_aref(ray_gl_primitives, primitive)),
                      mo_array_at(count, 0),
                      GL_UNSIGNED_INT, (const GLvoid**)mo_array_at(index, 0),
                      index->size);
  return Qnil;
}

.stencil_sizeInteger

Returns Size of the stencil buffer, in bits.

Returns:

  • (Integer)

    Size of the stencil buffer, in bits



136
137
138
139
# File 'ext/gl.c', line 136

static
VALUE ray_gl_stencil_size(VALUE self) {
  return ULONG2NUM(say_context_get_config()->stencil_size);
}

.stencil_size=(val) ⇒ Object

See Also:



167
168
169
170
171
# File 'ext/gl.c', line 167

static
VALUE ray_gl_set_stencil_size(VALUE self, VALUE val) {
  say_context_get_config()->stencil_size = NUM2ULONG(val);
  return val;
}