[MacRuby] #1112: Allowing pointers to be created and initialised directly with an integer
#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/>
#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: ----------------------------------------+----------------------------------- Comment(by lsansonetti@…): I think a method such as Pointer.magic_value(fixnum) has to be introduced. -- Ticket URL: <http://www.macruby.org/trac/ticket/1112#comment:1> MacRuby <http://macruby.org/>
#1112: Allowing pointers to be created and initialised directly with an integer ----------------------------------------+----------------------------------- Reporter: dave.baldwin@… | Owner: lsansonetti@… Type: enhancement | Status: closed Priority: minor | Milestone: MacRuby 0.9 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------------+----------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.9 Comment: I added Pointer.magic_cookie in r5160. In your case, you can pass Pointer.magic_cookie(13) as the last argument of glVertexPointer(). Note that Pointer.magic_cookie will only accept Numeric values that can fit in a C long type (otherwise, an exception will be raised). -- Ticket URL: <http://www.macruby.org/trac/ticket/1112#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby