[MacRuby] #1112: Allowing pointers to be created and initialised directly with an integer

MacRuby ruby-noreply at macosforge.org
Wed Jan 12 13:49:53 PST 2011


#1112: Allowing pointers to be created and initialised directly with an integer
----------------------------------------+-----------------------------------
 Reporter:  dave.baldwin@…              |       Owner:  lsansonetti@…        
     Type:  enhancement                 |      Status:  new                  
 Priority:  minor                       |   Milestone:                       
Component:  MacRuby                     |    Keywords:                       
----------------------------------------+-----------------------------------
 In OpenGL some functions take pointers and these are easily handled via

 v = Pointer.new('f', 20)
 glVertexPointer(3, GL_FLOAT, 3,  v)

 (the C prototype is
 void glVertexPointer(GLint  size, GLenum  type, GLsizei  stride, const
 GLvoid *  pointer);


 however in some cases this function has been overloaded so you pass in an
 integer as the last parameter.  In C this is easy
 glVertexPointer(3, GL_FLOAT, 3, (void *) 12)

 This is a horrible bit of API design in OpenGL but allows graphics data to
 be stored in the graphics memory (in vertex buffer objects) instead of in
 host memory so gives a significant performance boost for large data sets.

 The MacRuby Pointer objects don't have any way of setting the pointer to a
 given value - understandable as this is a dangerous thing to do normally -
 so the only way to use vertex buffer objects directly from MacRuby is to
 create a small objective c stub along the lines:

 - (void) glVBOVertexPointer: (GLint) size type: (GLenum) type stride:
 (GLsizei) stride offset:(GLint) offset
 {
         glVertexPointer(size, type, stride, (void *) offset);
 }

 and to call this.

 An alternative way of handling this (not tested) may be to add a method on
 to Integer along the lines to_void_ptr to return the a void * pointer
 initialised to the integer value?

 OpenGL uses this idiom in several places and it is probably not alone.

 Dave.

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/1112>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list