[英]Pass array of Java vertex objects to OpenGL entry points
I am starting to port my games over to Android from iOS and I've run into a problem. 我开始将游戏从iOS移植到Android,但遇到了问题。
In my standard workflow on iOS I would store my vertex info in an array of structs: 在iOS上的标准工作流中,我会将顶点信息存储在一系列结构中:
typedef struct{
float x, y, z;
} Vector3;
Vector3 verts[];
That sort of thing. 之类的东西。
Then when it came time to send my vertex data to GL, I would just point to the verts array and it would treat it like an array of floats. 然后,当需要将我的顶点数据发送到GL时,我将指向verts数组,并将其视为浮点数组。
glVertexAttribPointer(Vertex_POSITION, 3, GL_FLOAT, 0, 0, (void *)verts);
How do I do this in Java? 如何在Java中执行此操作?
I tried making a Vector3 class and putting a few of them into an array, but it throws an error when I try to stuff that array into GL. 我试图制作一个Vector3类并将其中的一些放入数组中,但是当我尝试将该数组填充到GL中时会引发错误。
With the direction you are going, I don't think this can work directly. 按照您的方向,我认为这不能直接起作用。 When you have an array of objects in Java (like an array of your
Vector3
class ), the array contains a sequence of references to those objects, and each object is allocated in a separate chunk of memory. 当您在Java中拥有一个对象数组(例如
Vector3
类的数组)时,该数组包含对这些对象的引用序列 ,并且每个对象都分配在单独的内存块中。
What you need to pass to OpenGL entry points like glVertexAttribPointer()
or glBufferData()
is a contiguous block of memory containing the data. 您需要传递给诸如
glVertexAttribPointer()
或glBufferData()
类的OpenGL入口点的是包含数据的连续内存块 。 An array of objects does not have that layout, so it's simply not possible to use it directly. 对象数组没有这种布局,因此根本无法直接使用它。
You have various options: 您有多种选择:
float[]
, or a FloatBuffer
. float[]
或FloatBuffer
。 The Java entry points in Android take buffers as arguments, so using buffers is the most straightforward approach.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.