I have an Object class and I want to implement the copy constructor. I have set it up like this:
glGenBuffers(1, &m_vertexBuffer);
glGenBuffers(1, &m_colorBuffer);
glGenBuffers(1, &m_indexBuffer);
glGenVertexArrays(1, &m_vertexArray);
glBindVertexArray(m_vertexArray);
GLint size = 0;
glBindBuffer(GL_COPY_READ_BUFFER, other.m_indexBuffer);
glGetBufferParameteriv(GL_COPY_READ_BUFFER, GL_BUFFER_SIZE, &size);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, nullptr, GL_STATIC_DRAW);
glCopyBufferSubData(other.m_indexBuffer, m_indexBuffer, 0, 0, size);
glBindBuffer(GL_COPY_READ_BUFFER, other.m_vertexBuffer);
glGetBufferParameteriv(GL_COPY_READ_BUFFER, GL_BUFFER_SIZE, &size);
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_STATIC_DRAW);
glCopyBufferSubData(other.m_vertexBuffer, m_vertexBuffer, 0, 0, size);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *) 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_COPY_READ_BUFFER, other.m_colorBuffer);
glGetBufferParameteriv(GL_COPY_READ_BUFFER, GL_BUFFER_SIZE, &size);
glBindBuffer(GL_ARRAY_BUFFER, m_colorBuffer);
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_STATIC_DRAW);
glCopyBufferSubData(other.m_colorBuffer, m_colorBuffer, 0, 0, size);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void *) 0);
glEnableVertexAttribArray(1);
glBindVertexArray(0);
I can see the orignal object, but the new object won’t show up. How do I correctly copy the buffers?
I hope someone can help me! Thanks!