# Ruby Opengl Speed

**URL:** <https://www.ruby-forum.com/t/ruby-opengl-speed/134999>\
**Category:** Ruby\
**Created:** [April 16, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999 "2008-04-16T23:44:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 16, 2008, 11:44pm UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/1 "2008-04-16T23:44:49Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 17, 2008, 12:20am UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/2 "2008-04-17T00:20:00Z")

</div>

On Wed, Apr 16, 2008 at 5:44 PM, Diego B.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 17, 2008, 12:29am UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/3 "2008-04-17T00:29:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 17, 2008, 2:08am UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/4 "2008-04-17T02:08:14Z")

</div>

Yea, this is what i want to know, thanks Jan 🙂  
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

> **[ActiveState Community](https://community.activestate.com)**
>
> Community support for users of the ActiveState Platform.

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 17, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/5 "2008-04-17T13:25:38Z")

</div>

On Wed, Apr 16, 2008 at 8:52 PM, Bill K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 17, 2008, 2:53am UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/6 "2008-04-17T02:53:14Z")

</div>

From: “Diego B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> link about the gears demo  
> [ActiveState Community - Boosting coder and team productivity with ready-to-use open source languages and tools.](http://aspn.activestate.com/ASPN/Mail/Message/ruby-talk/2574414)

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

[http://ogrerb.rubyforge.org/](http://ogrerb.rubyforge.org/)

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![di3go](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9a28c/32.png) [@di3go](https://www.ruby-forum.com/u/di3go)\
**Post date:** [April 18, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/ruby-opengl-speed/134999/7 "2008-04-18T23:05:49Z")

</div>

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

> Yea, this is what i want to know, thanks Jan 🙂  
> 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
