[英]OpenGL ES : How to use VAOs together with glVertexAttribPointer?
我正在嘗試使用 VAO 更新以下代碼:
fun onSurfaceCreated() {
// ...
// Coordinates Handle
this.meshCoordinatesHandle = GLES31.glGetAttribLocation(program, "mesh_coordinates")
GLES31.glEnableVertexAttribArray(this.meshCoordinatesHandle)
// Color Handle
this.colorHandle = GLES31.glGetUniformLocation(program, "color")
GLES31.glEnableVertexAttribArray(this.colorHandle)
}
fun onDrawFrame() {
// ...
// Mesh A
GLES31.glVertexAttribPointer(this.meshCoordinatesHandle, 3, GLES31.GL_FLOAT, false, 3 * 4, this.meshACoordinatesBuffer)
GLES31.glUniform4fv(this.colorHandle, 1, this.meshAColor, 0)
GLES31.glDrawElements(GLES31.GL_LINES, this.meshALinesBuffer.capacity(), GLES31.GL_UNSIGNED_SHORT, this.meshALinesBuffer)
// Mesh B
GLES31.glVertexAttribPointer(this.meshCoordinatesHandle, 3, GLES31.GL_FLOAT, false, 3 * 4, this.meshBCoordinatesBuffer)
GLES31.glUniform4fv(this.colorHandle, 1, this.meshBColor, 0)
GLES31.glDrawElements(GLES31.GL_LINES, this.meshBLinesBuffer.capacity(), GLES31.GL_UNSIGNED_SHORT, this.meshBLinesBuffer)
}
我走了這么遠,但我被困在這里:
fun onSurfaceCreated() {
// ...
GLES31.glGenVertexArrays(2, vaos, 0)
// VAO A
GLES31.glBindVertexArray(vaos[0])
GLES31.glGetAttribLocation(program, "mesh_coordinates").also {
GLES31.glEnableVertexAttribArray(it)
GLES31.glVertexAttribPointer(it, 3, GLES31.GL_FLOAT, false, 3 * 4, this.meshACoordinatesBuffer)
}
GLES31.glGetUniformLocation(program, "color").also {
GLES31.glEnableVertexAttribArray(it)
GLES31.glUniform4fv(it, 1, this.meshAColor, 0)
}
// VAO B
GLES31.glBindVertexArray(vaos[1])
GLES31.glGetAttribLocation(program, "mesh_coordinates").also {
GLES31.glEnableVertexAttribArray(it)
GLES31.glVertexAttribPointer(it, 3, GLES31.GL_FLOAT, false, 3 * 4, this.meshBCoordinatesBuffer)
}
GLES31.glGetUniformLocation(program, "color").also {
GLES31.glEnableVertexAttribArray(it)
GLES31.glUniform4fv(it, 1, this.meshBColor, 0)
}
}
fun onDrawFrame() {
// ...
// Mesh A
GLES31.glBindVertexArray(vaos[0])
GLES31.glDrawElements(GLES31.GL_LINES, this.meshALinesBuffer.capacity(), GLES31.GL_UNSIGNED_SHORT, this.meshALinesBuffer)
// Mesh B
GLES31.glBindVertexArray(vaos[1])
GLES31.glDrawElements(GLES31.GL_LINES, this.meshBLinesBuffer.capacity(), GLES31.GL_UNSIGNED_SHORT, this.meshBLinesBuffer)
}
知道問題可能來自哪里嗎? 我必須用glBindBuffer和glBufferData替換glVertexAttribPointer嗎?
制服存儲在當前安裝程序的默認制服塊中。 制服不是VAO的狀態。 制服是程序的一部分,但不是屬性的一部分。 如果要組織制服,可以使用Uniform Buffer Object或Shader Storage Buffer Objects 。
在繪制網格之前設置均勻:
fun onSurfaceCreated() {
// [...]
GLES31.glGenVertexArrays(2, vaos, 0)
// VAO A
GLES31.glBindVertexArray(vaos[0])
GLES31.glGetAttribLocation(program, "mesh_coordinates").also {
GLES31.glEnableVertexAttribArray(it)
GLES31.glVertexAttribPointer(it, 3, GLES31.GL_FLOAT, false, 3 * 4, this.meshACoordinatesBuffer)
}
// VAO B
GLES31.glBindVertexArray(vaos[1])
GLES31.glGetAttribLocation(program, "mesh_coordinates").also {
GLES31.glEnableVertexAttribArray(it)
GLES31.glVertexAttribPointer(it, 3, GLES31.GL_FLOAT, false, 3 * 4, this.meshBCoordinatesBuffer)
}
}
fun onDrawFrame() {
// [...]
// Mesh A
GLES31.glGetUniformLocation(program, "color").also {
GLES31.glUniform4fv(it, 1, this.meshAColor, 0)
}
GLES31.glBindVertexArray(vaos[0])
GLES31.glDrawElements(GLES31.GL_LINES, this.meshALinesBuffer.capacity(), GLES31.GL_UNSIGNED_SHORT, this.meshALinesBuffer)
// Mesh B
GLES31.glGetUniformLocation(program, "color").also {
GLES31.glUniform4fv(it, 1, this.meshBColor, 0)
}
GLES31.glBindVertexArray(vaos[1])
GLES31.glDrawElements(GLES31.GL_LINES, this.meshBLinesBuffer.capacity(), GLES31.GL_UNSIGNED_SHORT, this.meshBLinesBuffer)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.