Reading back buffer content from the CPU

Started by
9 comments, last by wintertime 5 years, 2 months ago

I am doing a function call logger via hooks and trying to read back the content of a OpenGL buffer

Inside the hooked function, I am doing the following:

 


void  WINAPI hk_glBindBufferRange (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) {


	RealglBindBufferRange(target, index, buffer, offset, size);
  
  
	float *temp = (float *)glMapNamedBuffer(buffer, GL_MAP_READ_BIT);
  
      // Access temp's contents
  
	int e = glGetError();
  
	if (temp) glUnmapBuffer(buffer);
}

glMapNamedBuffer returns a null temp pointer. The error I receive when I call glGetError is an 0x500 or GL_INVALID_ENUM.

I also tried glMapNamedBuffer with the GL_READ_ONLY flags but fails as well.

What am I doing wrong? What are other ways to get the content (data) of the GLuint buffer ?

Thanks

 

Advertisement

https://www.geeks3d.com/20140704/gpu-buffers-introduction-to-opengl-3-1-uniform-buffers-objects/

There is a section with map/unmap buffer. Hope this helps.

8 minutes ago, _Silence_ said:

Thanks. The example confirms how these functions work. On the other side, the example shows how to write data to the buffer.

I appreciate it but don’t understand how it applies to reading back a buffer.

 

The docs suggest GL_MAP_READ_BIT is not valid for glMapNamedBuffer, hence the GL_INVALID_ENUM. What was the error code when you used GL_READ_ONLY??

It throws GL_INVALID_OPERATION

what could it be wrong?

So did you try to follow the example, which isn't using the gl*Named* functions ? Does this work ? Named functions require OpenGL 4.5, is it your case ?

Also, from your example this is not clear if the buffer is bound. Finally, the GL context must be current and you "must" be in the same thread.

1 hour ago, fs1 said:

On the other side, the example shows how to write data to the buffer.

I appreciate it but don’t understand how it applies to reading back a buffer.

This is one of the intend of glMapBuffer. Read its documentation.

49 minutes ago, fs1 said:

It throws GL_INVALID_OPERATION

what could it be wrong?

From the doc:

Quote

GL_INVALID_OPERATION is generated by glMapNamedBuffer if buffer is not the name of an existing buffer object.

GL_INVALID_OPERATION is generated if the buffer object is in a mapped state.

 

1 hour ago, _Silence_ said:

So did you try to follow the example, which isn't using the gl*Named* functions ? Does this work ? Named functions require OpenGL 4.5, is it your case ?

Also, from your example this is not clear if the buffer is bound. Finally, the GL context must be current and you "must" be in the same thread.

This is one of the intend of glMapBuffer. Read its documentation.

From the doc:

 

I am calling this from the same thread in a hook, where the buffer is bound by the RealglMapNamedBuffer before my calls. See above the example.

I have OpenGL 4.5 is installed.

I need to use the gl*Named functions as I have the buffer GLuint. Is there a way to map this buffer other way? How can I use glMapBuffer in this case?

thanks!

 

2 hours ago, fs1 said:

I have OpenGL 4.5 is installed.

 

Great, most people do.  Have you verified your rendering context IS created and using 4.5?  Never assume, verify.  I actually have a check to make sure the OpenGL version of my context is equal to or greater than what my renderer requires and posts up an error message and quits if it doesn't.  Just because the drivers support it, does not mean your context is creating successfully with it.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

11 minutes ago, CrazyCdn said:

Great, most people do.  Have you verified your rendering context IS created and using 4.5?  Never assume, verify.  I actually have a check to make sure the OpenGL version of my context is equal to or greater than what my renderer requires and posts up an error message and quits if it doesn't.  Just because the drivers support it, does not mean your context is creating successfully with it.

Good point. I have made the code work with a call to glGetNamedBufferSubData. This function returns back valid data. Don’t know how this works flawlessly but not the other ones stated.

.

 

18 hours ago, fs1 said:

I am calling this from the same thread in a hook, where the buffer is bound by the RealglMapNamedBuffer before my calls.

You are assuming the glMapNamedBuffer function would bind the buffer, when the whole point of the named functions is to not bind the buffer, just using it once without disturbing the bindings.

This topic is closed to new replies.

Advertisement