Ruby Opengl Speed

Ruby has a Opengl binding, but well, its kind slow compared to c or
java, this is because of the language or the binding? If ruby get more
fast the overall performance gonna increase? or the bottleneck its the
binding?

Thanks :slight_smile:

On Wed, Apr 16, 2008 at 5:44 PM, Diego B.
[email protected] wrote:

The binding layer doesn’t really add much to the execution time, the
majority of slowdown comes from the Ruby code itself outside of the
OpenGL calls.

Jason

On Wednesday 16 April 2008 23:44:51 Diego B. wrote:

Ruby has a Opengl binding, but well, its kind slow compared to c or
java, this is because of the language or the binding? If ruby get more
fast the overall performance gonna increase? or the bottleneck its the
binding?

In short: language and/or interpreter is the bottleneck.

The OpenGL API is mostly straightforward, and while ruby-opengl
bindings do
additional state checks, most functions just boils down to:

  1. convert data between ruby a C types (simple shift for Fixnum, pointer
    access for Float)
  2. call OpenGL function
  3. convert return parameter the same way (most OpenGL function does not
    return
    anything)

The overhead is fairly small, to the point that when in ruby-opengl 0.60
we
added glGetError() call (and raise on error) after each OpenGL function
call,
there was no measurable slowdown.

With ruby 1.9 the bindings are about 2x-5x faster than with ruby1.8, and
basically the performance is the same as Perl’s POGL bindings (as
measured by
trislam benchmark), and few times faster than Python’s. That is probably
as
fast as it gets with interpreted languages.

Of course when you talk about fast/slow, you need to put that in context

computing all data on CPU and calling glVertex* milion times will be
always
much slower than in C (or Java), but does that mean anything ? If it’s
possible to offload anything on GPU, do it. With today’s videocards with
SM4.0 and all, it is possible to write applications where the CPU is not
bottleneck, and so they can be as fast as if written in C/Java.

Jan

Yea, this is what i want to know, thanks Jan :slight_smile:
I already made some 2d games in ruby using gosu and now im going to 3d
Just another question, i’m dont know opengl already, i’m just starting
my studies, you said “offload anything on GPU”, how can this offload can
be done?

There is a Gears demo made in ruby with opengl comparing with c, it uses
display lists, so get almost the same speed of c, this is what you say
about “offload anything on GPU”?

link about the gears demo

On Wed, Apr 16, 2008 at 8:52 PM, Bill K. [email protected] wrote:

There is a Gears demo made in ruby with opengl comparing with c, it uses

Regards,

Bill

Heh, yes, there is that, but I didn’t mention it because it’s woefully
incomplete (based on SWIG and I just ran into too many problems). I’m
working on a framework like python-ogre to replace SWIG (rbgccxml /
rb++) and will then use that for Ogre.rb and should have a much better
wrapper in usability and maintainability.

But for now, Ogre.rb will serve as a good starting point into using
Ogre.

Jason

From: “Diego B.” [email protected]

link about the gears demo
ActiveState Community - Boosting coder and team productivity with ready-to-use open source languages and tools.

You might be interested in the ruby bindings for the Ogre3D engine:

http://ogrerb.rubyforge.org/

Regards,

Bill

On Thursday 17 April 2008 02:08:16 Diego B. wrote:

Yea, this is what i want to know, thanks Jan :slight_smile:
I already made some 2d games in ruby using gosu and now im going to 3d
Just another question, i’m dont know opengl already, i’m just starting
my studies, you said “offload anything on GPU”, how can this offload can
be done?

There is a Gears demo made in ruby with opengl comparing with c, it uses
display lists, so get almost the same speed of c, this is what you say
about “offload anything on GPU”?

Yes, display lists and vertex arrays/VBO for static objects are good
start,
but you can do any general per-vertex or per-pixel processing on GPU via
shaders. Common example in games is skeletal-bone animation done in
vertex
shader (a.k.a. hardware skinning) where you send only mesh’s base pose
in
array/VBO and bone matrices as uniform variables or attributes and the
shader
computes the desired pose.

Jan