# EXT_PIXEL_BUFFER_OBJECT for Render to Texture

## Recommended Posts

this way PBO can be used for render-to-texture implementation:
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, m_iBuffer);
glReadPixels(0,0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);

glBindTexture(GL_TEXTURE_2D, m_iTexture);

glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, m_iBuffer);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, 0);

it works, but it is only 3% faster(GeForce2 GTS) than the following:
char buff[512][512][3];
glReadPixels(0,0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, buff);
glBindTexture(GL_TEXTURE_2D, m_iTexture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, buff);

what's wrong? Why doesn't PBO accelerate the process of data transmission within the videocard? Well, maybe the PBO main intent is to parallelize data excange between app and gfx card, but in this case it should also increase performance, I think.

##### Share on other sites
Quote:
 Original post by glJackchar buff[512][512][3];glReadPixels(0,0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, buff);glBindTexture(GL_TEXTURE_2D, m_iTexture);glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, buff);

If this is all you need, glCopyTexImage2D(...) will be a lot faster. Allthough it's supposed to be better on newer hardware, glReadPixels() is still dreadfully slow. You won't be able to modify or access the texture in your app, though (because it copies within GPU memory).

Tom

##### Share on other sites
Quote:
 If this is all you need, glCopyTexImage2D(...) will be a lot faster.

I tried it, and it is 2 times faster. Yes, it is faster and I'd use it.

But I just want to compare performance of 1st and 2nd cases. I think that in the first case data copying has be faster than in the second case, because in 1st case all copying operations happen within gfx card/driver memory, and in 2nd case data is copied to system memory, and read back from it.

The first piece of code uses PBO, has to be nearly as fast as glCopyTexImage2D(...) is.

Why there is no difference in performance between these 2 approaches?
Maybe this is because I test them on GeForce 2 GTS card. Maybe GeForce 2 GTS doesn't have hardware support for this extension, and all PBO memory allocations/operations happen within system memory?

##### Share on other sites
Quote:
 Original post by glJackBut I just want to compare performance of 1st and 2nd cases. I think that in the first case data copying has be faster than in the second case, because in 1st case all copying operations happen within gfx card/driver memory, and in 2nd case data is copied to system memory, and read back from it.The first piece of code uses PBO, has to be nearly as fast as glCopyTexImage2D(...) is.

Do you have any evidence to support this claim?

Tom

##### Share on other sites
Quote:
 Original post by dimeboltDo you have any evidence to support this claim?Tom

He thinks that it should be faster. If he is wrong just explain him why. Why is it that everybody has to show evidences for everything these days? This is not a politic show.

##### Share on other sites
Quote:
 He thinks that it should be faster. If he is wrong just explain him why. Why is it that everybody has to show evidences for everything these days? This is not a politic show.

If I knew why, I would tell him why. I do not know the mechanics behind GL_PIXEL_PACK_BUFFER_EXT (and I'm sure, I'm not alone in that). From the posts from glJack, I get the impression he is aware of these mechanics. All I meant was to ask for a link or pointer to a document that explained why it should work as he claims it should work. English not being my first language, I probably used the incorrect phrasing to convey this message.

Tom

##### Share on other sites
Quote:
 Do you have any evidence to support this claim?

No, I don't. If I did, I would post it here. As I allready said
I think that it should be faster, because all data transfer operations happen wihting gfx card memory, as in the case with glCopyTexImage2D, so the speed has to be comparable with that.

Maybe the PBO approach speed doesn't have to be as glCopyTexImage2D but it has to be more than just 3% faster than pure
glReadPixels(0,0, 512, 512, GL_RGB, GL_UNSIGNED_BYTE, buff);

The fact that speed difference is minimal made me think that GeForce 2 GTS
implements PBO ext in software, and keeps all PBO data in system memory...

Quote:
 He thinks that it should be faster. If he is wrong just explain him why. Why is it that everybody has to show evidences for everything these days? This is not a politic show.

I really just think it should be faster, I don't claim that.

Anonymous poster
Thanx :)

##### Share on other sites
Quote:
 Original post by glJackThe fact that speed difference is minimal made me think that GeForce 2 GTS implements PBO ext in software, and keeps all PBO data in system memory...

I don't know enough about GL_PIXEL_PACK_BUFFER_EXT to answer your question. Could you post the entire code? I can try it later today, on my Geforce6 at home. That one should definately support the extension. Then we'll at least know if the problem is caused by your geforce2. It is quite likely that the problem lies there, because the GL_PIXEL_PACK_BUFFER_EXT extension is more recent than the Geforce2.

Tom

##### Share on other sites
dimebolt
the source and binaries are here: www.glplanet3d.newmail.ru/pbo/pbo.html

The demo will work for 30 seconds and generate "out.txt" file.
thank you for assistance!

btw, which tag is used to post a link ?

[Edited by - glJack on July 5, 2005 11:30:57 AM]

##### Share on other sites
Quote:
 Original post by glJackdimebolt the source and binaries are here: www.glplanet3d.newmail.ru/pbo/pbo.htmlThe demo will work for 30 seconds and generate "out.txt" file.thank you for assistance!btw, which tag is used to post a link ?

Sorry, but I was already offline when you posted. Did you take it down again? Because the link is dead now... You can use normal html to post links ("a href") tags to post links.

Tom

##### Share on other sites
Try this link again. I fixed it:
www.glplanet3d.newmail.ru/pbo/pbo.html

##### Share on other sites
Quote:
 Original post by glJackTry this link again. I fixed it:www.glplanet3d.newmail.ru/pbo/pbo.html

Yes, that worked. I got your program working on a geforce3 (Geforce6 results tomorrow). These were the results (VS6 compiled with O2):
glCopyTexImage2D : 3705

As you can see, similar results... But the Geforce3 probably also predates VBO's.

Note: you did not add your 'Primitive' class, so I replaced the drawing of the teapot with:
glBegin(GL_QUADS);	glVertex3d(-1,-1,0);	glVertex3d( 1,-1,0);	glVertex3d( 1, 1,0);	glVertex3d(-1, 1,0);glEnd();

This should also give more accurate performance results, as the rendering time of the teapot is taken out of the loop. That's why glCopyTexImage is now 6 times faster.

When I get home, I'll try it on my Geforce6 for the interesting test...

Tom

##### Share on other sites
Thanx Tom, I'll look forward for the results.

##### Share on other sites
The results are not much different on my geforce6 (recent Nvidia drivers installed):
glCopyTexImage2D : 10611

In fact the PBO is slower than the pure version, just like on the geforce3. Clearly the glReadPixels still goes through main memory in all implementations. I don't know why. It appears we'll have to use glCopyTexImage2D or, even better, FBO's for efficient RTT. This presentation from Nvidia explains how to use FBO's and why FBO's are even faster than glCopyTexImage2D(...).

Tom

[Edited by - dimebolt on July 7, 2005 8:15:34 AM]

##### Share on other sites
yes glCopyTexSubImage2D should be faster than readpixels + PBO no surprise there

##### Share on other sites
VIRUS WARNING: The binary: PBO.exe is infected with "W32/Jeefo"!

Scanned with McAffee Virus Scan Enterprise 8.0.0
Virus Definitions April 6 2005

##### Share on other sites
Can anybody confirm the above? Virus checkers can sometimes give out erroneous warnings due to the somewhat primitive signature checking some of them use.

##### Share on other sites
Tom
Tom, Thanx. You really helped me a lot! I appreciate your help.

Quote:
 VIRUS WARNING

I don't have anti virus software installed, so, I'm not sure about executable safety. Sorry, if there is a virus.
Well, the problem is solved by the time, so don't download it.

##### Share on other sites

--------------------------------------------------------
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, buff_0);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, buff_1);
glReadPixels(0, height/2, width, height, GL_RGB, GL_UNSIGNED_BYTE, NULL);
--------------------------------------------------------

Are these 2 data transfers supposed to be parralel ?

##### Share on other sites
Quote:
 Original post by KylotanCan anybody confirm the above? Virus checkers can sometimes give out erroneous warnings due to the somewhat primitive signature checking some of them use.
NAV 2005 flags it as the same virus.

##### Share on other sites
Quote:
Original post by Myopic Rhino
Quote:
 Original post by KylotanCan anybody confirm the above? Virus checkers can sometimes give out erroneous warnings due to the somewhat primitive signature checking some of them use.
NAV 2005 flags it as the same virus.

Good thing I never tried the exe :)

Tom

##### Share on other sites
hi,
im beginner in image processing,
just want to read the framebuffer with glreadpixels and then draw it with gldrawpixels.
i had some problems and didnt worked, could anyone write me a few lines of code for an example?
(with initializing variables, and so on, with anything i need to that)

thanks all

##### Share on other sites
Quote:
Original post by dimebolt
Quote:
 Original post by glJackThe fact that speed difference is minimal made me think that GeForce 2 GTS implements PBO ext in software, and keeps all PBO data in system memory...

I don't know enough about GL_PIXEL_PACK_BUFFER_EXT to answer your question. Could you post the entire code? I can try it later today, on my Geforce6 at home. That one should definately support the extension. Then we'll at least know if the problem is caused by your geforce2. It is quite likely that the problem lies there, because the GL_PIXEL_PACK_BUFFER_EXT extension is more recent than the Geforce2.

Tom

Just because a driver supports an extensions doesn't mean it is actually in hardware.. some cards 'support' ARB Vertex programs but actually do it in software in the driver. It could be that because NVidia drivers support all of their cards doesn't mean it is being done in hardware, so it maybe that the Geforce 2 has this extension but the driver emulates it (maybe even with glTexSubImage2D...). Don't know, nobody but NVidia knows how their drivers work.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627671
• Total Posts
2978551

• 11
• 10
• 10
• 12
• 22