The type of buffer is often specified by a type argument. For the
glDrawElements method you can see this argument described in the
Javadoc right before the argument where you are a passing a
FloatBuffer:
http://java.sun.com/javame/reference/apis/jsr239/javax/microedition/khronos/opengles/GL10.html#glDrawElements%28int,%20int,%20int,%20java.nio.Buffer%29
>type - Specifies the type of the values in indices. Must be either 
>GL_UNSIGNED_BYTE or GL_UNSIGNED_SHORT.
>indices - Specifies a pointer to the location where the indices are stored.

There's an Android example of creating a buffer of indices and passing
it to the glDrawElements method here:
http://developer.android.com/intl/fr/resources/samples/ApiDemos/src/com/example/android/apis/graphics/spritetext/Grid.html

Floats don't make any sense for indices. Referring to vertex 1 or 2
makes sense, referring to vertex 1.5 doesn't. Floats can be used for
things like coordinates, however. The above API Demo has an example of
using glVertexPointer with type GL10.GL_FLOAT, for example. You can
see in the Javadoc that the type argument is described differently for
the glVertexPointer method:
http://java.sun.com/javame/reference/apis/jsr239/javax/microedition/khronos/opengles/GL10.html#glVertexPointer%28int,%20int,%20int,%20java.nio.Buffer%29
>type - Specifies the data type of each vertex coordinate in the array. 
>Symbolic constants GL_BYTE, GL_SHORT, GL_FIXED, and GL_FLOAT are accepted. The 
>initial value is GL_FLOAT.

It is easy to use an array when appropriate by using the wrap methods
on the buffer type in question, but often that is not allowed because
arrays may be moved around in memory. There's a long discussion on
this in the Javadoc. Here's a part of it:
http://java.sun.com/javame/reference/apis/jsr239/overview-summary.html
>Functions that take an untyped (void*) pointer argument for immediate use are 
>given a single binding that takes a Buffer object. The Buffer can be of any 
>type allowable by the function (and compatible with the other arguments to the 
>function) and can be direct or indirect.
>
>Functions that take a typed pointer (e.g., GLfloat *) argument for immediate 
>use are given two bindings. The first takes a primitive array with a type that 
>matches the C pointer type (that is, GLfloat* maps to float[]) and an integer 
>offset indicating the first array entry to be read or written. The second 
>takes a typed Buffer object (that is, GLfloat* maps to FloatBuffer).
>
>Functions that take an untyped (void*) pointer argument for deferred use are 
>given a single binding that takes a Buffer object. The Buffer can be of any 
>type allowable by the function (and compatible with the other arguments to the 
>function), but must be direct. That is, it must not have been created from a 
>Java primitive array using the wrap method.
>
>The functions that fall into this category generally have names ending with 
>the suffix "Pointer" (such as glVertexPointer). Because these functions do not 
>consume the data located at the given pointer immediately, but only at some 
>unspecified later time, it is not possible to use an array since the Java 
>virtual machine may relocate the array within system memory.
>
>Functions that take a typed (for example, GLfloat*) pointer argument for 
>deferred use are given a single binding that takes a typed Buffer object (that 
>is, GLfloat* maps to FloatBuffer). The Buffer must be direct. That is, it must 
>not have been created from primitive array using the wrap method. At present, 
>OpenGL ES does not contain functions that fall into this category.

On Jan 22, 2:36 pm, Greg Donald <gdon...@gmail.com> wrote:
> On Fri, Jan 22, 2010 at 1:25 PM, Lance Nanek <lna...@gmail.com> wrote:
> >http://khronos.org/opengles/documentation/opengles1_0/html/glDrawElem...
>
> Ok, so the Kronos API docs have the fourth parameter glDrawElements()
> as a void pointer, and then the Android SDK has it as a Buffer.  But
> what kind of Buffer?  I tried using a FloatBuffer and got a segfault.
> And why wouldn't a simple float[] work there?  These are the kinds of
> questions/problems I'm having.
>
> In general, what do I use to connect the dots from the documented
> Kronos C API to the undocumented Android/Java API?  Trial and error is
> not something I favor.
>
> --
> Greg Donald
> destiney.com | gregdonald.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to