[cl-opengl-devel] a patch to add a support for the Vertex Arrays
Denys Rtveliashvili
rtvd at mail.ru
Thu May 3 17:35:36 UTC 2007
Hi,
I think I need to have more LISP experience to get the idea how it works :-)
As far as I see, when a function like cl:vertex-pointer is called, the
arguments are automatically converted to native arrays. Perhaps it's one
of the features of the new CFFI library.
Could you tell a few words about the things which happen behind the scenes?
And how do you make sure that the native array does not get
garbage-collected / moved / re-used until the next call to the
...-pointer function?
------
As for my patch, it is quite simple and does not require new CFFI. While
the drawback is that it does not support interleaved arrays. On the
other hand, I do not see any reason why they could be useful in LISP as
their complexity seems to overweight the benefit.
- According to the OpenGL specification, there are 9 types of pointers
which can be used for batch-drawing with the functions like
glDrawElements. Also there are 9 client states. And it is important that
the arrays have to be available since their declaration to OpenGL using
the functions like glVertexPointer up to the moment when they are
already used and are not going to be used any more.
- On LISP side the the arrays can be specified either as an array (1D or
2D, depending on the case) or as a sequence (which is treated like a 1D
array). Theoretically it is possible to support a 2D list-based
structure or a native representation. That is not yet implemented and
can be easily added.
My implementation maintains 9 native arrays. Each time a ....pointer
function is called, the array is populated from the supplied data
structure. There is no need to specify the "width" of the data. It is
retrieved from the source data directly.
The array is maintained until the moment it is declared that it not
going to be used or the program terminates. This guarantees its
availability to the OpenGL subsystem.
....-pointer functions are called either with a data structure or with
"nil" as a parameter. If it is "nil", the respective client state is
disabled. If not, the state is enabled and the data structure is mapped
to the native array (the array is resized when necessary) and then
advertised to OpenGL using functions like glColorPointer. So, there is
no need to maintain the client state manually.
So, the code for aapoly demo from the Red Book (method "draw") looks
like this:
(let ((colors
(make-array '(8 4)
:initial-contents '((0.0 0.0 0.0 1.0)
(1.0 0.0 0.0 1.0)
(0.0 0.0 1.0 1.0)
(1.0 1.0 0.0 1.0)
(0.0 0.0 1.0 1.0)
(1.0 0.0 1.0 1.0)
(0.0 1.0 1.0 1.0)
(1.0 1.0 1.0 1.0))))
(indices
(make-array '(6 4)
:initial-contents '((4 5 6 7)
(2 3 7 6)
(0 4 7 3)
(0 1 5 4)
(1 5 6 2)
(0 3 2 1))))
(verticles
(make-array '(8 3)
:initial-contents `((,x0 ,y0 ,z0)
(,x1 ,y0 ,z0)
(,x1 ,y1 ,z0)
(,x0 ,y1 ,z0)
(,x0 ,y0 ,z1)
(,x1 ,y0 ,z1)
(,x1 ,y1 ,z1)
(,x0 ,y1 ,z1)))))
(gl:vertex-pointer verticles :float)
(gl:color-pointer colors :float)
(gl:draw-elements :quads indices)
(gl:color-pointer)
(gl:vertex-pointer))
Thank you,
Denis Rtveliashvili
> On 02/05/07, Denys Rtveliashvili <rtvd at mail.ru> wrote:
>> I created a patch for adding a support for Vertex Arrays in cl-opengl.
>
> There's been some work on that already. I've been meaning to announce
> this branch on this list, so here it goes. There's a cl-opengl-thomas
> branch in <http://common-lisp.net/~loliveira/darcs/>, which, among
> other things, includes some work on vertex arrays, including a macro
> for defining array layouts. It depends on the cffi-newtypes tree which
> you can find in that same directory.
>
> Please have a look at that branch and let us know what you think, how
> that relates to your work, etc...
>
> Thanks.
>
> --
> Luís Oliveira
> http://student.dei.uc.pt/~lmoliv/
> _______________________________________________
> cl-opengl-devel mailing list
> cl-opengl-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/cl-opengl-devel
>
>
More information about the cl-opengl-devel
mailing list