opengl - 在 DSA 代码的更新循环中是否使用 glBindVertexArray
问题描述
我正在将一些opengl代码转换为DSA,并且在任何地方都编写了不绑定顶点数组,因为它在DSA中继承。所以我用
GLuint VBO, VAO, indexBuffer;
glCreateVertexArrays(1, &VAO);
glCreateBuffers(1, &indexBuffer);
glCreateBuffers(1, &VBO);
...
而不是 glGen... 对应物。
但是现在我只是想知道是否有在更新循环中绑定顶点数组的 DSA 版本。我现在有
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Draw the triangle
ourShader.Use();
const auto Textureloc = glGetUniformLocation(ourShader.Program, "ourTexture");
glBindTextureUnit(Textureloc, texture);
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
glBindTextureUnit(0, 0);
glfwSwapBuffers(window);
}
这很好用。但是,如果我不将 替换glBindVertexArray
为其他东西,我会在以后的编码中遇到一些有趣的问题吗?就像我替换glBindTexture
为glBindTextureUnit
解决方案
总结一下,按照问题中的示例编写更新循环是完全正确的。在更新循环中使用VAO时应该绑定它。但是当您使用 DSA 时,您在修改它们时不需要绑定 VAO(也不是 VBO 或索引缓冲区)。因此,没有其他选择glDrawElements
可以像 eg 这样将 VAO id 作为参数glVertexArrayElementBuffer
。
推荐阅读
- javascript - 如何通过 Javascript 访问 php 代码中的输入名称?
- vulkan - 绑定每个对象统一缓冲区(例如相机矩阵)的有效方法是什么?
- javascript - 如何在时刻 js 中获得正确的格式
- reactjs - 我正在使用带有 React js 的 google oauth 并且它正在加载 google 帐户,并且在我点击我的个人资料弹出窗口后被关闭
- java - 实现不带斜线的 url
- javascript - TypeScript myFunction 不是函数
- python - 如何简化 sympy 向量?
- php - 如何在codeigniter中将横幅徽标图像链接到home.php
- python - 如何在绘图轴上只保留时间
- ruby-on-rails - Rails ActiveSupport::CachingKeyGenerator 的内存使用问题