pbuffer & offscreen rendering

Started by
8 comments, last by DoomhammerDE 17 years, 4 months ago
Hi all, I am currently working on a video output in open gl. I use a videocard, which copies the data from a buffer into its video ram and display it. Therefore I render the scene twice: first into an off-screen pbuffer (which is ised to copy the image to the card) and second on-screen. The double rendering divides my performance. I want to use the image rendered into the pbuffer and use it to display it on-screen in a window. I've tried some gl functions like glCopyPixels etc. , but it does not work. I am not sure, if my attempt is right. I've found only examples, where the pbuffer is mapped to a texture and mapped onto a primitive. I think this is a little overkill, because I want the exact data in the pbuffer shown on-screen. I hope some can help me :) Thank you !
Advertisement
PBuffers are a right pain, you'll probably find it much easier to use the new(ish) FrameBuffer Objects (FBO) extension. Basically they let you render straight to a texture and avoid having to do the copy. You can then treat it like a normal texture, and draw it using a fullscreen quad if you want it back on the screen again.
thank you for your reply.
I think there is a more easier solution than drawing to texture and render again.

I've tried to use the wglMakeContextCurrentARB and glCopyPixels, but I'm not sure if that way works ?!
I'm not sure I'm understanding you properly, but it seems all you need is to display a single image every frame and every so often update that image, right? If that's the case, don't bother with rendering to an offscreen buffer or anything. Just create a texture and render it every frame. Whenever the image data in the texture needs to be updated, use glTexSubImage2D. If the GL_ARB_pixel_buffer_object extension is supported, you may be able to use that to optimize the transfer speeds, but don't worry about that yet.
I am not sure, this works with the driver interface of my videocard (not my graphic card). The videocard takes the data from the buffer and display it on the TV.

Actually the app renders two times: offscreen and onscreen.

I want the pbuffer to be displayed onscreen without rendering twice.

I do not really understand how the glTexSubImage2D can help me in this context.

edit1:
My attempt:

wglMakeContextCurrentARB(MainHdc,PbufferHdc,MainGlRC);
glReadBuffer(GL_BACK);
glDrawBuffer(GL_BACK);
glCopyPixels(0, 0, width, height, GL_COLOR);

but I get only artifacts and no image. I am not sure if the Read and DrawBuffer calls are right and can be done in this way??

edit2:
the pbuffer is bigger (2048*2048) than the window (720*576).. maybe this cause the error ? width and height are the dimensions of the window
When you call wglShareList you can share resources between the two contexts and then you just render it to texture in the pbuffer using glTexSubImage2D. Then switch to the on-screen context and draw a quad with the texture mapped on it.
Regardless of what method you use to render either of the parts of the image, rendering it twice will be slower than rendering it once.

Consider using display lists or some other (more advanced) method of avoiding uploading the data twice to the card (especially if you're currently using immediate mode).

If you're doing something like a rear view mirror in a racing game (for example), consider rendering it directly to where it's going, but with a stencil buffer to clip the unwanted parts of the image. Or abuse the zbuffer in some way to achieve a similar effect.

Doing offscreen rendering and copying it will introduce a copy operation, but not add any more overhead than that- you'll still need to render the scene twice- which is what you originally suggested took the extra time (of course we don't really know that for definite, but copying is pretty fast if it's vram to vram (e.g. glCopyTexImage2d or something as suggested by DoomHammer). Copying to system RAM and back again is horrendously slow (e.g. with glCopyPixels) and should definitely be avoided.

Mark
I have to render the content to the offscreen pbuffer to copy the content from the graphic card to my video card (done via glreadpixels). This is required by the API of the video card.

glreadpixels load the data into the system RAM, right ?
Because this muist be done, I don't want to waste more performance and use this data in the pbuffer for vram - vram copy to display its content.

but how ??
Quote:Original post by DoomhammerDE
to copy the content from the graphic card to my video card (done via glreadpixels). This is required by the API of the video card.

Ahhh... This would be the cause of the confusion I think. "graphics card" and "video card" are pretty interchangable terms, but I think you actually have a separate video out device other than the regular graphics card found in most pcs?

I think you're going to have to do a copy here - IIRC you can't copy straight between two PCI/AGP devices, you have to go via main memory. But I'm still not sure I properly understand how you've got your devices and contexts setup.
OrangyTang: yes I use a graphic card (nvidia Quadro) to render the image into the pbuffer. Then the data is copied to the video card (for SDI output, a seperate device). I should have mentioned it more precisely.

It is copied with glreadpixels (to the system RAM?!) and after that it is load into the video ram of the video card (done by the videocard drivers).

This works fine, but I want to preview the output on my computer screen. That is my starting point.

Is it faster to load the data from system ram to video ram again, or to render the pbuffer into a texture and render it on-screen? (If it is the only possibility to get the pbuffer content onscreen ?!?)

This topic is closed to new replies.

Advertisement