convert Vertex buffer to Vertex array

血红的双手。 提交于 2019-12-19 10:44:11

问题


I'm working on OpenGL program and I must calculate a bounding box . I made the code to do it but I can't get vertexes coordinations from vertex buffer . Someone can explain me an easy way to get data from vertex buffer? I'm using Java for android and OpenGL es


回答1:


If you use OpenGL ES 3.0 or later, you can use glMapBufferRange() to access buffer data directly. See the man page for details about the functionality, and the GLES30 documentation for details about the Java bindings in Android.

I don't think there's any reasonable way to do this in ES 2.0. I could think of absolutely awful ways, but I would feel bad to steer you in that direction. Well, for completeness, but please do not do this: You could render something that ends up leaving the vertex data in a render target, and read it back with glReadPixels().

If you need frequent access to the vertex data in your own code, it will most likely work better if you keep a copy of it. You already had the data when you called glBufferData(). If you're currently throwing it away after the glBufferData() call, simply keep it around, and use it whenever you need access to vertex data.




回答2:


i've found how to do it

    mFb= (FloatBuffer)    vb.getData(UlVertexBuffer.VERTEX_FIELD_POSITION).position(0);
    getmFloatArray(mFb);
    mSb= (ShortBuffer) ib.getData();
    getmShortArray(mSb);


来源:https://stackoverflow.com/questions/26398790/convert-vertex-buffer-to-vertex-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!