PDA

View Full Version : glMapBufferRange and GL_INVALID_OPERATION error



Groovounet
01-07-2009, 09:11 AM
Hi!

I try to have fun with glMapBufferRange a really cool feature I believe!

Basically, I have just updated a code that was using glMapBuffer with buffer range stuff. Unfortunately at draw call I get a GL_INVALID_OPERATION error ... I work fine with glMapBuffer code.

Is there something wrong with my code? I'm thinking of blaming the drivers ^_^

Map buffer range code:


GLint Size = Histogram.getData(0).size() * 2 * sizeof(glm::vec2);

glBindBuffer(GL_ARRAY_BUFFER, EnvHistogram.ArrayBuffer);

GLvoid* Pointer = glMapBufferRange(
GL_ARRAY_BUFFER,
0, // Offset
Size, // Size
GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT | GL_MAP_FLUSH_EXPLICIT_BIT);

for(GLint i = 0; i < GLint(Histogram.getData(0).size()); ++i)
{
glm::vec2 Src[2];
Src[0] = glm::vec2(float(i), 0.f);
Src[1] = glm::vec2(float(i), float(Histogram.getData(0)[i]));

memcpy((glm::vec2*)Pointer + i * 2, Src, sizeof(glm::vec2) * 2);
}

glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, Size);

glBindBuffer(GL_ARRAY_BUFFER, 0);

Map buffer code:


GLint Size = Histogram.getData(0).size() * 2 * sizeof(glm::vec2);

glBindBuffer(GL_ARRAY_BUFFER, EnvHistogram.ArrayBuffer);

GLvoid* Pointer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);

for(GLint i = 0; i < GLint(Histogram.getData(0).size()); ++i)
{
glm::vec2 Src[2];
Src[0] = glm::vec2(float(i), 0.f);
Src[1] = glm::vec2(float(i), float(Histogram.getData(0)[i]));

memcpy((glm::vec2*)Pointer + i * 2, Src, sizeof(glm::vec2) * 2);
}

glUnmapBuffer(GL_ARRAY_BUFFER);

glBindBuffer(GL_ARRAY_BUFFER, 0);

Rob Barris
01-07-2009, 10:30 AM
You still need an unmap buffer call.

The flush mapped buffer range call tells the driver what you changed, potentially letting unmap become more efficient, but you still need to unmap before drawing.

Groovounet
01-07-2009, 11:38 AM
Thanks, it works better this way!