简体   繁体   中英

Java - vector of vectors to Buffer

I am completely terrified how tough is it in java..

I am using OpenGL ES 2.0 which requires me to pass a Buffer here and there.

Imagine I store a vector of objects. Each object stores many things, along with vertices it stores. It looks like this:

class MyObject {
    Vector<Float> vertices;
}
Vector<MyObject> objects;

Now, I need to convert these into a Buffer (FloatBuffer, I guess). I tried to do it many ways, but none seem to be anything near fast / they're dumb and might not work.

Can somebody show me the right way?

@EDIT

Just to clarify - I need to have a buffer that holds all vertices from all objects.

Pseudo-code :

float[] allvertices;
for(i = 0; i<objects.length; i++)
   for(n = 0; n<objects[i].vertices.length; n++)
       allvertices.add(objects[i].vertices[n]);
// Now convert allvertices to buffer

How about using wrap method?

float[] values = new float[vertices.size()];
int index = 0;
for (Float f : vertices) {
    values[index++] = f;
}
FloatBuffer b = FloatBuffer.wrap(values);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM