0
votes

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?

1

1 Answers

1
votes

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.