Search code examples
c++openglcompute-shader

Binding an empty texture to image unit produces segfault


I want to draw to the texture via a compute shader. For this I am trying to bind the texture to an image unit:

    glBindImageTexture(0, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);

But when I run the code it produces a segfault. This is how I create the empty texture:

unsigned int texture;
glGenTextures(1, &texture);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);

glBindTexture(GL_TEXTURE_2D, 0);

I used the following tutorial for compute shaders: https://antongerdelan.net/opengl/compute.html


Solution

  • According to https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml glBindImageTextureis only available in GL versions greater or equal to 4.2. After updating the GL version of my project everyone works fine now.