newDirectFloatBuffer() description

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

newDirectFloatBuffer() description

gmseed
Hi

I'm looking for a detailed description of the method newDirectFloatBuffer().

Looking at the JavaDoc I get a 1 liner.

I found the following at https://sites.google.com/site/justinscsstuff/rendering-methods/vertex-arrays

"
We cannot use normal Java arrays in the glVertexPointer, glColorPointer, glNormalPointer, and glTexCoordPointer functions. Instead, we must use direct buffers; these are buffers that use memory outside of the Java heap. Using a direct buffer means garbage collection will never relocate the data stored in these arrays around inside the heap; the buffer uses a fixed area in the operating system's memory.
In JOGL, functions that have untyped parameters (GLvoid*) with deferred use (not used immediately) must use direct buffers. The pointer functions above are examples of this: the data inside the buffers isn't used until glDrawArrays is called. If a non-direct buffer was used, garbage collection may occur between glVertexPointer and glDrawArrays, potentially causing the memory address of the buffer to change, and who knows what glDrawArrays would actually render! Direct buffers are also nice for Java programs that have higher memory requirements - which is often the case when working with graphics - because you're not limited by the size of the Java heap.
"

but curious how accurate this is without a formal description at jogamp.

Thanks

Graham
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: newDirectFloatBuffer() description

Michael Bien
On 11/17/2011 03:44 PM, gmseed [via jogamp] wrote:

> Hi
>
> I'm looking for a detailed description of the method
> newDirectFloatBuffer().
>
> Looking at the JavaDoc I get a 1 liner.
>
> I found the following at
> https://sites.google.com/site/justinscsstuff/rendering-methods/vertex-arrays
>
> "
> We cannot use normal Java arrays in the glVertexPointer,
> glColorPointer, glNormalPointer, and glTexCoordPointer functions.
> Instead, we must use direct buffers; these are buffers that use memory
> outside of the Java heap. Using a direct buffer means garbage
> collection will never relocate the data stored in these arrays around
> inside the heap; the buffer uses a fixed area in the operating
> system's memory.
> In JOGL, functions that have untyped parameters (GLvoid*) with
> deferred use (not used immediately) must use direct buffers. The
> pointer functions above are examples of this: the data inside the
> buffers isn't used until glDrawArrays is called. If a non-direct
> buffer was used, garbage collection may occur between glVertexPointer
> and glDrawArrays, potentially causing the memory address of the buffer
> to change, and who knows what glDrawArrays would actually render!
> Direct buffers are also nice for Java programs that have higher memory
> requirements - which is often the case when working with graphics -
> because you're not limited by the size of the Java heap.
> "
>
> but curious how accurate this is without a formal description at jogamp.
>
> Thanks
>
> Graham


it creates a direct allocated float buffer with native (machine
dependent) ordering. Justin's description about the reasoning behind
direct nio usage is spot on. Direct nio is currently the only way on the
JVM to reach high data transfer throughput between java and native code.

regards,
michael

--
- - - -
http://michael-bien.com

Loading...