Reputation: 167
I am developing a program, which can calculate histogram on GPU. I'm using OpenGL to write code. In first step, I load value of pixel (RGB) to an array (arr_image
) and upload it to Vertex buffer (vbo
):
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
GLuint num_input_data = width * height;
/* Upload data */
glBufferData(GL_ARRAY_BUFFER, num_input_data * sizeof(float) * 3, arr_image, GL_STATIC_DRAW);
And it's working, I can calculate histogram of image.
But now, I want load data from a texture (GL_TEXTURE_2D
) (as results of my previous steps) to Array Buffer (GL_ARRAY_BUFFER). Is it possible?
Upvotes: 1
Views: 1886
Reputation: 45352
I'm not sure if your overall approach is really the best way to go, but I'm going to address only your specific question here:
A buffer object in OpenGL can be bound to every buffer target. To copy pixel data from a texture into a buffer object, you can just bind your buffer to GL_PIXEL_PACK_BUFFER
which means using it as a Pixel Buffer Object (PBO). When a PBO is bound, any operation reading back pixel data from the GL will write the data into the PBO. So you can issue a glGetTexImage
call. Just like with VBOs, the pixels
pointer of these calls is now interpreted not as a client memory address, but an offset into the PBO.
You can then bind this buffer to the GL_ARRAY_BUFFER
target and use it as a source for vertex data.
Upvotes: 5