2

I'm using the OpenGL API (v 4.6) to do some image processing stuff, its basically OpenGL image load store operations in a shader, I load the Texture via glBindImageTexture and do some processing, then I want to use glGetTexImage to read the contents of my updated image but while the function itself works fine it returns an all black image, which isnt really the case when its loaded in other shaders.

TLDR: Image works fine when loaded inside a shader (I use it in many and renderdoc displays it all fine in the GPU side) but it is all-black software side.

this is what my output should have been like using glGetTexImage (viewed with renderdoc after rendering)

use_shader(&shader);
glBindBuffer (GL_ARRAY_BUFFER, quad_vbo);
setInt(shader, "screen_width", window_width);
setInt(shader, "screen_height", window_height);
glBindImageTexture(0, head_list, 0, FALSE, 0,  GL_READ_WRITE, GL_R32UI); //head list is the opengl texture id

glDrawArrays(GL_TRIANGLES, 0, 24);
glBindVertexArray(0);

glMemoryBarrier(GL_ALL_BARRIER_BITS);


//the image is just a GL_RED so one component
 GLint *image_head= (GLint*)malloc(sizeof(u32) *window_width *window_height);   
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, head_list);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED, GL_UNSIGNED_INT, image_head);
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • I'm not sure about what I'm saying, but it could be that the image is not ready when you request it. Try adding `glFinish()` just before reading the image, it's a quick and dirty way to tell OpenGL to block until everyting is finished. – tuket Nov 10 '20 at 09:53
  • It doesn't seem to be a synchronization issue as I have glMemoryBarrier(GL_ALL_BARRIER_BITS) everything just to be sure. Nice hack though. – user14279931 Nov 10 '20 at 10:03
  • Ah, okay. Maybe can you show us some bits of your code? – tuket Nov 10 '20 at 10:07
  • I've updated the question with the code, thanks a lot. – user14279931 Nov 10 '20 at 10:17
  • Thanks, how do you know image_head is all black? It's a bit weird that you are reading the image as `GL_FLOAT` and the pointer is of type `GLint`, that shouldn't be a problem though – tuket Nov 10 '20 at 10:39
  • yeah that's what I figured, uh I check it on visual studio and also output a ppm image with only the red component and its all black. – user14279931 Nov 10 '20 at 10:54

1 Answers1

2

Found it. GL_RED is for floating-point components only, by changing in all the code, meaning glTexImage and glGetTexImage GL_REDs to GL_RED_INTEGERs the issue is resolved!

  • Nice catch! I'm just leaving this table of formats here for future reference: https://gist.github.com/Kos/4739337 – tuket Nov 10 '20 at 21:16