[Gambas-devel] My first attempts to extend GL and GLU components.

Benoît Minisini gambas at ...1...
Tue Jul 5 00:31:15 CEST 2011


> 2011/7/4 Tomek <tommyline at ...670...>
> 
> > Hello to all Hero Programmers!
> > Since I got intersted in OpenGL programming in Gambas, I begun to search
> > for source files and add some functions I felt I could use.
> > I'm not a C programmer, I just understand some code, so using analogy I
> > tried to attach Evaluators to GL. It works ok, but my question is if
> > copying the array and then pointing to it is the only method to pass a
> > pointer to the array from gambas to library? It slows down the process
> > greatly. I would be really happy if someone could point me to some
> > documentation about how the combination of Gambas and C works in
> > components.
> > I attach my files and chcnaged GL.c file, so you can evaluate them,
> > little Bezier curve project and please don't be too harsh on me, I'm
> > just a beginner :)
> > 
> > Regards
> > Tomek
> 
> Nice job!

Yes, cool.

> 
> Personnaly, i prefer working with patches (tips: svn diff > mypatch.diff),
> Benoit prefers modified files.

Actually I just like subversion commits that implies no job for me! :-)

Either you send your code to Laurent (I don't know OpenGL enough), either you 
get a sourceforge account and do your commits directly.

Beware that I'm trying to release Gambas 3, so please be careful with your 
changes! :-)

> 
> Some quick comments:
> - No need to implement double and float support, i"ve only added Float
> datatype, but it use double internally (
> http://gambasdoc.org/help/cat/datatypes) so the GL API show Gl.Map1f(), but
> we use glMap1d()
> - Associated glGets are already here (see GLinfo.c) , it seem you have
> properly added the associated constants.
> - Typos in the methods, the first letter of the variables must be in
> uppercase ((target)i(u1)f -> (Target)i(U1)f)
> - Gambas doesn't provide native C arrays support, so there is no other ways
> to provide C arrays to GL functions. But i don't think it slow down so much
> the code.

I think it does partially:

If you receive a Gambas array (for example a Float[]), and you need to send a 
double[] to a C function, you can use the GB.Array.Get(array, 0) to get a 
pointer to the array data, and GB.Array.Count(array) to get the array length.

Then you must be aware of who owns the data, and if the data must be kept 
around after the C function has terminated.

If you want to keep the data for a while, use GB.Ref() and GB.Unref() on the 
array.

If the C OpenGL function takes the ownership of the data (it should be 
specified in the OpenGL documentation), then use GB.Ref() to prevent the 
Gambas array to be freed. If you cannot use GB.Ref(), because you cannot store 
the array pointer between two functions calls, then you have to copy the data.

You have to copy the data too if, for example, you receive a Float[] (i.e. a 
double[] in C) and have to pass a float[] to the C function (i.e. a Single[] 
in Gambas).

Then the question is: why does the function argument (for example GlMap2f) 
take a Float[] and not a Single[]? Now Gambas 3 can convert arrays on the fly, 
so it will do the copy for you. More code for me, less code for you!

Regards,

-- 
Benoît Minisini




More information about the Devel mailing list