Equiv of glDrawpixels that operates on GPU memory?

1.7k views Asked by At
glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const ovid *pixels);

Is there a function like this, except instead of accessing CPU memory, it accesses GPU memory? [Either a texture of a frame buffer object]

4

There are 4 answers

1
Bahbar On

glDrawPixels can read from a Buffer Object. Just do a

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, XXX)

before calling glDrawPixels.

Caveat: glDrawPixels is deprecated...

0
Luca On

Use glBlitFramebuffer, which operates on frambuffer objects (Link). Ans this is not deprecated.

You can take advantage of format conversion, scaling and multisampling.

0
eile On

If it is in a texture:

  • set up orthographic frustum
  • disable blending, depth test, etc.
  • bind texture
  • draw screen-aligned textured quad with correct texture coordinates

I use this in for example in Compositor::_drawPixels

0
Nicol Bolas On

Let's cover all the bases here.

First, a direct answer: yes, there is such a function. It's called glDrawPixels. I'm not kidding.

glDrawPixels can certainly read from GPU memory, provided that you are using buffer objects as their source data (commonly called "pixel buffer objects"). glDrawPixels can use pixel buffer objects as the source for pixel data. Buffer objects are (theoretically, at least) in GPU memory, so they qualify.

However, you add onto this "Either a texture of a frame buffer object". Under this qualification, you're asking, "is there a way to copy pixel data from one texture/framebuffer to the current framebuffer?"

Yes. glBlitFramebuffer can do that. It blits from the GL_READ_FRAMEBUFFER to the GL_DRAW_FRAMEBUFFER. And since you can add images from textures to FBOs, you can copy from images just fine. You can even copy from the default framebuffer to some renderbuffer or texture.

You can also employ glCopyImageSubData, which copies pixel rectangles from one image to another. It's a lot more convenient than glBlitFramebuffer if all you're doing is copying pixel data. This is quite new at present (GL 4.3, or ARB_copy_image). It cannot be used to copy data to the default framebuffer.