PDA

View Full Version : glMapBuffer problem!



korija
05-19-2016, 03:22 PM
So im trying to upload vertex data from an std::<Vector> arrays into the array buffers and then mapping them into the mapbuffer.

Error ocmes from include\cmemory
Expression: invalid null pointer

glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, entity.m_Vertices.size() * sizeof(Vec3fR), &entity.m_Vertices.front(), GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(entity.m_Vertices), (const GLvoid*)0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ARRAY_BUFFER, textureBufferID);
glBufferData(GL_ARRAY_BUFFER, entity.m_Textures.size() * sizeof(Vec2fR), &entity.m_Textures.front(), GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(entity.m_Textures), (const GLvoid*)(entity.m_Vertices.size() * 12));
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ARRAY_BUFFER, vboUID);
glBufferData(GL_ARRAY_BUFFER, entity.m_Normals.size() * sizeof(Vec3fR), &entity.m_Normals.front(), GL_STATIC_DRAW);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(entity.m_Normals), (const GLvoid*)(entity.m_Textures.size() * 8));
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, entity.m_Indices.size() * sizeof(unsigned int), &entity.m_Indices.front(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);

void Renderer::begin()
{

glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBindBuffer(GL_ARRAY_BUFFER, textureBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vboUID);
m_VertexData = (VertexData*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); //Position, normals and texture data combined

}

void Renderer::submit(Entity& entity)
{

m_VertexData->m_PositionData = entity.m_Vertices; // <- these gives me the errors!
m_VertexData->m_TextureData = entity.m_Textures;
m_VertexData->m_NormalData = entity.m_Normals;

}

Hermannicus
05-19-2016, 05:20 PM
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBindBuffer(GL_ARRAY_BUFFER, textureBufferID);
glBindBuffer(GL_ARRAY_BUFFER, vboUID);
m_VertexData = (VertexData*) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); //Position, normals and texture data combined

glMapBuffer only maps the data which is currently bound, so only the buffer vboUID here.