Hi, tldr Texture (uv) indices are not used, same with every other EBO data after indices of vertices.
From wiki I know that it is possible to use sub data with EBO, but it does not seem work the way I did it, about half of the cube uv is “properly” set (triangles directly connected) and the rest seems twisted in other direction + one triangle seems buggy like if the texture was scretched and not always visible, depends how I rotate the cube.
Bellow there’s a screenshot.
glBindVertexArray(_VAO);
glBindBuffer(GL_ARRAY_BUFFER, _VBO);
int vertices_size = this->m_vertices.size() * sizeof(glm::vec3);
int uv_size = this->m_uv.size() * sizeof(glm::vec2);
int normals_size = this->m_normals.size() * sizeof(glm::vec3);
int colors_size = this->m_colors.size() * sizeof(glm::vec4);
int data_size = vertices_size + uv_size + normals_size + colors_size;
glBufferData(GL_ARRAY_BUFFER, data_size, NULL, GL_STATIC_DRAW);
if (!m_vertices.empty()) {
glBufferSubData(GL_ARRAY_BUFFER, 0, vertices_size, &m_vertices[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(0));
glEnableVertexAttribArray(0);
if (!m_uv.empty()) {
glBufferSubData(GL_ARRAY_BUFFER, vertices_size, uv_size, &m_uv[0]);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)(vertices_size));
glEnableVertexAttribArray(1);
}
if (!m_normals.empty()){
glBufferSubData(GL_ARRAY_BUFFER, vertices_size + uv_size, normals_size, &m_normals[0]);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(vertices_size + uv_size));
glEnableVertexAttribArray(2);
}
if (!m_colors.empty()) {
glBufferSubData(GL_ARRAY_BUFFER, vertices_size + uv_size + normals_size, colors_size, &m_colors[0]);
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(vertices_size + uv_size + normals_size));
glEnableVertexAttribArray(3);
}
}
int indices_vertex_size = this->m_indices.size() * sizeof(unsigned int);
int indices_uv_size = this->m_uv_indices.size() * sizeof(unsigned int);
int indices_normals_size = this->m_normals_indices.size() * sizeof(unsigned int);
int indices_data_size = indices_vertex_size + indices_uv_size + indices_normals_size;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _EBO);
if (!m_indices.empty()) {
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_data_size, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indices_vertex_size, &this->m_indices[0]);
if (!m_uv_indices.empty()) {
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, indices_vertex_size, indices_uv_size, &this->m_uv_indices[0]);
}
if (!m_normals_indices.empty()) {
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, indices_vertex_size + indices_uv_size, indices_normals_size, &this->m_normals_indices[0]);
}
}
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Screenshot of what I see: