如何在 openGL ES 3 中创建 VAO android
How to create a VAO in openGL ES 3 android
所以在普通的 openGL 中你可以像这样创建一个 VAO
glGenVetrexArray();
并期待此函数为您创建一个 VAO 并为您提供一个 int,即 VAO ID。
问题
在android中函数是这样的:
glGenVetrexArray(int n , int[] array, int offset);
我不知道这些参数是什么,我不知道如何使用上述方法创建 VAO 和获取 ID?
n - 要返回的 VAO 的数量(数量);
array - n 个元素的数组,带有创建对象的标识符;
offset - 为 VAO 设置偏移量(通常 = 0)。
创建 VAO 时,使用以下函数使其成为当前函数:GLES30.glBindVertexArray(VAO[0])。绑定VAO后,所有的调用,如:glBindBuffer、glEnableVertexAttribArray、glVertexAttribPointer,都会影响当前的VAO。
public class Renderer implements GLSurfaceView.Renderer {
private int[] VBOIds = new int[2]; // VertexBufferObject Ids
private int[] VAOId = new int[1]; // VertexArrayObject Id
public Renderer(...) {
// create vertex buffer objects
VBOIds[0] = 0;
VBOIds[1] = 0;
GLES30.glGenBuffers(2, VBO, 0);
...
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, VBO[0]);
GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, verticesData.length * 4,
vertices, GLES30.GL_STATIC_DRAW);
...
GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, VBO[1]);
GLES30.glBufferData(GLES30.GL_ELEMENT_ARRAY_BUFFER, indicesData.length * 2, indices, GLES30.GL_STATIC_DRAW);
...
}
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
GLES30.glGenVertexArrays(1, VAOId, 0); // Generate VAO Id
GLES30.glBindVertexArray(VAOId[0]); // Bind the VAO
// invokes commands glBindBuffer, glEnableVertexAttribArray,
// glVertexAttribPointer for VBOs
...
// Reset to the default VAO (default VAO always is 0)
GLES30.glBindVertexArray(0);
}
public void onDrawFrame() {
...
GLES30.glBindVertexArray(VAOId[0]); // active VAO
// Draw on base the VAO settings
GLES30.glDrawElements(GLES30.GL_TRIANGLES, indicesData.length,
GLES30.GL_UNSIGNED_SHORT, 0);
// Return to the default VAO
GLES30.glBindVertexArray(0);
}
}
你可以看到一个很好的使用 VAO 的例子here
所以在普通的 openGL 中你可以像这样创建一个 VAO
glGenVetrexArray();
并期待此函数为您创建一个 VAO 并为您提供一个 int,即 VAO ID。
问题
在android中函数是这样的:
glGenVetrexArray(int n , int[] array, int offset);
我不知道这些参数是什么,我不知道如何使用上述方法创建 VAO 和获取 ID?
n - 要返回的 VAO 的数量(数量);
array - n 个元素的数组,带有创建对象的标识符;
offset - 为 VAO 设置偏移量(通常 = 0)。
创建 VAO 时,使用以下函数使其成为当前函数:GLES30.glBindVertexArray(VAO[0])。绑定VAO后,所有的调用,如:glBindBuffer、glEnableVertexAttribArray、glVertexAttribPointer,都会影响当前的VAO。
public class Renderer implements GLSurfaceView.Renderer {
private int[] VBOIds = new int[2]; // VertexBufferObject Ids
private int[] VAOId = new int[1]; // VertexArrayObject Id
public Renderer(...) {
// create vertex buffer objects
VBOIds[0] = 0;
VBOIds[1] = 0;
GLES30.glGenBuffers(2, VBO, 0);
...
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, VBO[0]);
GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, verticesData.length * 4,
vertices, GLES30.GL_STATIC_DRAW);
...
GLES30.glBindBuffer(GLES30.GL_ELEMENT_ARRAY_BUFFER, VBO[1]);
GLES30.glBufferData(GLES30.GL_ELEMENT_ARRAY_BUFFER, indicesData.length * 2, indices, GLES30.GL_STATIC_DRAW);
...
}
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
GLES30.glGenVertexArrays(1, VAOId, 0); // Generate VAO Id
GLES30.glBindVertexArray(VAOId[0]); // Bind the VAO
// invokes commands glBindBuffer, glEnableVertexAttribArray,
// glVertexAttribPointer for VBOs
...
// Reset to the default VAO (default VAO always is 0)
GLES30.glBindVertexArray(0);
}
public void onDrawFrame() {
...
GLES30.glBindVertexArray(VAOId[0]); // active VAO
// Draw on base the VAO settings
GLES30.glDrawElements(GLES30.GL_TRIANGLES, indicesData.length,
GLES30.GL_UNSIGNED_SHORT, 0);
// Return to the default VAO
GLES30.glBindVertexArray(0);
}
}
你可以看到一个很好的使用 VAO 的例子here