PDA

View Full Version : rendering to texture - 2 part



Alessandro_dup1
06-04-2003, 07:39 AM
Last days i have studied this tecnoque and it works just fine, however, because it renders the scene twice, it's too slow for my project. Seeking for another solution, now i coded a function which grab the whole screen and bind it to a texture. This function uses the GetDIBits method, but unfortunately also this is quite slow. There is a way to grab the screen in a better and faster way, maybe with ARB extensions ? Thanks

Alessandro_dup1
06-04-2003, 07:58 AM
Also, would wglSaveBufferRegionARB a solution to it ? The region saved from this function can be binded to a texture ?

jra101
06-04-2003, 08:14 AM
You can't use buffer region's to do render to texture. You use them to save a copy of the current contents in various buffers (depth, color, stencil, etc...) which you can then restore.

You should look into the ARB_render_texture extension.

knackered
06-05-2003, 01:35 AM
Have you tried glCopyTexSubImage ?
The process is basically...after you've finished drawing your scene, you issue a call the glCopyTexSubImage to copy the frame buffer into a texture that you've previously created. This method is REALLY fast.

rgpc
06-05-2003, 01:47 AM
An important factor to think about is the volume of data you are pushing/pulling across your AGP bus.

If you render your scene twice, calculate how much data you are sending to the card, and compare that to reading the full ( http://www.opengl.org/discussion_boards/ubb/eek.gif ) buffer, and then sending that data back to the card to be used in your texture.

I am not sure why you mention the use of GetDIBits. It sounds to me like you render your scene, read the full buffer, rescale the data and send it to the card. You would be better just rendering the scene to the resolution you want (Eg. 256x256 or 128x128) and using glCopyTexSubImage2D() to update the texture.

Incidentally glCopyTexSubImage2D is the fastest method for render to texture on nVidia (or was I haven't checked the latest drivers). If you use any other method, you will be suffering a drop in performance.

[This message has been edited by rgpc (edited 06-05-2003).]

paulc
06-05-2003, 02:16 AM
If your lucky enough to have use of pbuffers, you can render to them and then bind the pbuffer to a texture. Anyone now how this compares speed wise? Possibly faster as there's no transfer needed, but will depend on the drivers I guess. It is still a windows specific extension I believe, but it is another option.

rgpc
06-05-2003, 03:43 AM
Originally posted by paulc:
Anyone now how this compares speed wise?

It's slower (on nVidia) because of the context switch (unless that's been fixed recently).

MarkHarris
06-05-2003, 02:25 PM
Originally posted by rgpc:
It's slower (on nVidia) because of the context switch (unless that's been fixed recently).

This isn't entirely true. In my own tests on NVIDIA hardware, it depends on resolution. glCopy... was faster for me for 128x128 and smaller. For higher resolutions, RTT is faster, because the cost of the copy overtakes the cost of the context switch.

Mark

knackered
06-06-2003, 01:07 AM
Sorry, are we talking about the device context (DC) switch here? Not the render context (RC), I hope (I've never entirely understood why people use multiple render contexts...unless we're talking multiple threads).

Humus
06-06-2003, 03:58 AM
Perhaps because that's the only way you can render to a pBuffer unless you're using the same pixel format as the framebuffer.

Alessandro_dup1
06-06-2003, 07:12 AM
ok, i'm trying to use the glCopyTexSubImage2D function.
At the end of the render() loop i put the following instructions:

glBindTexture(GL_TEXTURE_2D,BlurTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXSIZE, TEXSIZE);

and i would expect to have the content of the screen in BlurTexture, but that doesnt happen, if i draw a simple quad binding this texture it doesnt show.

MarkHarris
06-13-2003, 05:51 AM
Originally posted by knackered:
Sorry, are we talking about the device context (DC) switch here? Not the render context (RC), I hope (I've never entirely understood why people use multiple render contexts...unless we're talking multiple threads).

Yes, the DC switch. However, multiple RCs are useful when you have two very different GL states. For example if you are performing procedural texturing in a pbuffer, but rendering a scene using the texturing to the screen. If you use two RCs, then you can make sure one of these doesn't clobber the state of the other.

Mark

MarkHarris
06-13-2003, 05:53 AM
glBindTexture(GL_TEXTURE_2D,BlurTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXSIZE, TEXSIZE);


Did you create blurTexture using a glTexImage2D before you called glCopyTexSubImage2D()? CopyTexSubImage does not allocate textures, it only copies to them. If you want to copy and allocate at the same time, use glCopyTexImage2D() instead of the "sub" version.

Mark