2

I want to store some particles in a shader-storage-buffer. I use the glMapBufferRange() function to set the particles values but I always get an Access Violation error whenever this function is called.

glGenBuffers(1, &bufferID);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferID);
glBufferData(GL_SHADER_STORAGE_BUFFER, numParticles*sizeof(Particle), NULL ,GL_STATIC_DRAW);


struct Particle* particles = (struct Particle*) glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, numParticles*sizeof(Particle), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

for(int i = 0; i < numParticles; ++i){
    //.. Do something with particles..//
}

glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);

When I use glMapBuffer() instead, everything works fine. I already made sure that I have created an OpenGL context with glfw and initialized glew properly.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Stan
  • 721
  • 10
  • 24
  • Are you sure that glMapBufferRange did not return NULL for some reason? – Sergey Sep 30 '12 at 11:54
  • I did not include all the error checking in the code above, but right after the glMapBufferRange() call I check for a NULL pointer. Unfortunately the execution doesn't even come this far. It always stops at glMapBufferRange(). – Stan Sep 30 '12 at 12:07
  • Can you glMapBufferRange with another target type than GL_SHADER_STORAGE? In the original ARB extension SHADER_STORAGE was specified as being accepted by only glMapBuffer not glMapeBufferRange, this has been only added for OpenGL-4.3 and I'd not be surprised if the drivers were still a bit buggy on that, especially with OpenGL-4.3 being still quite new. – datenwolf Sep 30 '12 at 12:49
  • I updated my drivers to 306.63 now and tried GL_SHADER_STORAGE_BUFFER and GL_ARRAY_BUFFER. Both times the same problem occurs. :/ – Stan Sep 30 '12 at 14:39

1 Answers1

1

Ok, I finally found the problem. When I designed my GLFW-Window class I used the GLFW_OPENGL_FORWARD_COMPAT hint to create a forward-compatible OpenGL context. I don't know why I did this, but when I don't use this hint everything works fine. :)

genpfault
  • 51,148
  • 11
  • 85
  • 139
Stan
  • 721
  • 10
  • 24