Hi, I'm trying to make a class to build vbo, but it doesn't work, the size of the data passed is not good : (it's 4 instead of 12 so it draw nothing)
void VBO::create (const void* data, const unsigned int dataSize) {
ensureGlContext();
if (m_vbo == 0) {
GLuint vbo;
glCheck(glGenBuffers(1, &vbo));
m_vbo = static_cast<unsigned int>(vbo);
}
if (isAvailable() && m_vbo != 0 ) {
glCheck(glBindBuffer(GL_ARRAY_BUFFER, m_vbo));
glCheck(glBufferDataARB(GL_ARRAY_BUFFER_ARB,dataSize, data, GL_DYNAMIC_DRAW));
glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
} else {
std::cerr<<"Failed to create the vbo, you should check if vbo are avalaible first! (by calling the VBO::isAvailable function)"<<std::endl;
}
}
const_cast<VertexArray*>(this)->vboVertex.create(&m_vertices[0], m_vertices.size() * sizeof(Vertex));
Anyone have any idea about how I have to pass data to my create function ?
And I'm searching for a good opengl forum to get some help. :P
When I don't pass the datas to a generic class, it works :
if (vboVertexBuffer == 0) {
GLuint vbo;
glCheck(glGenBuffers(1, &vbo));
const_cast<VertexArray*>(this)->vboVertexBuffer = static_cast<unsigned int>(vbo);
glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
glCheck(glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertices.size() * sizeof(Vertex), &(m_vertices[0]), GL_DYNAMIC_DRAW));
} else {
GLvoid *pos_vbo = nullptr;
glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
pos_vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if (pos_vbo != nullptr) {
memcpy(pos_vbo,&m_vertices[0], m_vertices.size() * sizeof(Vertex));
glCheck(glUnmapBuffer(GL_VERTEX_ARRAY));
pos_vbo = nullptr;
}
glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
}
if (vboVertexBuffer == 0) {
GLuint vbo;
glCheck(glGenBuffers(1, &vbo));
const_cast<VertexArray*>(this)->vboNormalBuffer = static_cast<unsigned int>(vbo);
glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
glCheck(glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_normals.size() * sizeof(Vector3f), &(m_normals[0]), GL_DYNAMIC_DRAW));
} else {
GLvoid *pos_vbo = nullptr;
glCheck(glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer));
pos_vbo = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
if (pos_vbo != nullptr) {
memcpy(pos_vbo,&m_normals[0], m_normals.size() * sizeof(Vector3f));
glCheck(glUnmapBuffer(GL_VERTEX_ARRAY));
pos_vbo = nullptr;
}
glCheck(glBindBuffer(GL_ARRAY_BUFFER, 0));
}
But it's quite anoying to don't have the possibility to encapsulate them in a class.