简体   繁体   中英

Is there a way to use objects in the vertex buffer in Android's OpenGL ES 2.0 with Java?

In C++, I could define a vertex such as

class Vertex
    {
    public:
        Vertex();
        ~Vertex();
        //Position
        float x, y, z, w;
        //Normals
        float nx, ny, nz, nw;
        //Textures
        float tu, tv;

    };

and then create a vertex buffer of an array of the above Vertex objects. I would tell the shader what the offsets for the position, normal, and textures were, and the shader would be able to map the values correctly.

In Java on Android, with OpenGL ES 2.0, I've been able to create individual float arrays for position, normals, and textures, or a single float array for all of them where I specify the offsets, but I haven't found a way to tell the buffer I'm using an array of objects. Is this possible? Or do I need to generate an array of floats myself?

No, as far as I know this is not possible in Java.

In C and C++ this works as in an array of objects, the objects are aligned contiguously in memory, as are their member variables. So you have one big contiguous block of data to pass to GL.

Java stores object by reference - so you rather have an array of references. The actual objects are not aligned contiguously in memory.

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