无法使用DSA创建对象

xriantvc  于 2022-10-18  发布在  其他
关注(0)|答案(1)|浏览(134)

此代码运行良好。

glGenVertexArrays(1, &m_VAO);
glGenBuffers(1, &m_VBO);
glGenBuffers(1, &m_EBO);
glBindVertexArray(m_VAO);
glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
glBufferData(GL_ARRAY_BUFFER, data.size()  * sizeof(VertexFormat), &data[0] , GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GL_UNSIGNED_INT), &indices[0], GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexFormat), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VertexFormat), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(VertexFormat), (void*)(6 * sizeof(float)));
glBindVertexArray(0);

但当我尝试将其更改为DSA时,屏幕上什么都没有显示。

glCreateBuffers(1, &m_VBO);
glNamedBufferStorage(m_VBO, data.size() * sizeof(VertexFormat), &data[0], GL_DYNAMIC_STORAGE_BIT);

glCreateBuffers(1, &m_EBO);
glNamedBufferStorage(m_EBO, indices.size() * sizeof(unsigned int), &indices[0], GL_DYNAMIC_STORAGE_BIT);

glCreateVertexArrays(1, &m_VAO);

glVertexArrayVertexBuffer(m_VAO, 0, m_VBO, 0, data.size() * sizeof(VertexFormat));
glVertexArrayElementBuffer(m_VAO, m_EBO);

glEnableVertexArrayAttrib(m_VAO, 0);
glEnableVertexArrayAttrib(m_VAO, 1);
glEnableVertexArrayAttrib(m_VAO, 2);

glVertexArrayAttribFormat(m_VAO, 0, 3 , GL_FLOAT, GL_FALSE, 0);
glVertexArrayAttribFormat(m_VAO, 1, 3 , GL_FLOAT, GL_FALSE, 0);
glVertexArrayAttribFormat(m_VAO, 2, 2 , GL_FLOAT, GL_FALSE, 0);

glVertexArrayAttribBinding(m_VAO, 0, 0);
glVertexArrayAttribBinding(m_VAO, 1, 0); 
glVertexArrayAttribBinding(m_VAO, 2, 0);

代码的DSA部分有什么问题?

h6my8fg2

h6my8fg21#

你没有传递两条信息。
您在glVertexArrayVertexBuffer中指定的步幅不正确。当使用单独的属性格式时,跨度为0并不意味着“紧密打包”;它的意思就是:将添加零字节来获取下一个数组元素。
您也没有像使用glVertexAttribPointer那样为glVertexArrayAttribFormat中的每个属性指定偏移量。

相关问题