PDA

View Full Version : copy app generated stencil data to stencil buffer



guilder
12-10-2010, 03:24 PM
Hello All,

I am new to this forum, hoping someone can help me with my problem.

I am looking for fastest method to copy application generated stencil data to stencil buffer? My OpenGL app uses ATI Radeon 5970 video card and when I used glDrawPixels to copy the data as below the performance was terribly slow about 3 FPS.

glDrawPixels(768, 768, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, (const GLvoid* )data);

What is interesting is the same app runs 25 FPS on ATI Radeon 3800 video card.

After browsing the forum, I even tried using the pixel buffer objects in conjunction with glDrawPixels, the performance seems to be fine but the stencil buffer is corrupted.
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo);
glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, size, (const GLvoid *) plane_data);
glDrawPixels(768, 768, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, 0);


Please let me know if anyone needs a sample code.

thanks in advance

Dark Photon
12-10-2010, 04:25 PM
Well, if it's not multisampled, one way would be to upload it to a ALPHA texture (say where value is 0 if you don't want to set stencil and non-zero if you do). Then enable stencil writes and render that texture with a full-screen quad batch. Use ALPHA_TEST (or frag shader discard) to avoid setting stencil for texels that are 0.

If it is multisampled, you can run the frag shader at sample rate and presumably do something similar.

Another approach: if you have newer hardware that supports ARB_shader_stencil_export, you can write the stencil value directly in the frag shader.

guilder
12-10-2010, 09:58 PM
Dark Photon,
Thanks for the response. My non-zero stencil value is not same for all of the pixels that I want to set in stencil buffer. It is different values for different pixels. If I use the alpha texture and alpha test, the stencil buffer will be set for those passed the alpha test with a stencil value fixed and same for all of these pixels, as determined by stencil ref and mask values. Afraid your suggestion does not fit my problem, suggest otherwise.

Thanks

guilder
12-13-2010, 02:25 PM
Hello All,
Is there an alternate to write to stencil buffer without using shaders? see my earlier post on what I currently have implemented.

thanks in advance

mhagain
12-13-2010, 05:18 PM
Can you check how many bits of stencil you're getting on the 5970? Stencil buffers normally come as 4-bit or 8-bit, and it sounds like the 5970 may be giving you a suboptimal format that requires conversion by the driver in software before it can be copied to hardware.

guilder
12-14-2010, 09:24 AM
Its 8-bit stencil buffer.

guilder
12-23-2010, 02:41 PM
Dark Photon,

May be too much to ask, could you provide me shader sample code using the ARB_shader_stencil_export extension to write to stencil buffer.
thanks in advance

Dark Photon
12-23-2010, 06:46 PM
Dark Photon, May be too much to ask, could you provide me shader sample code using the ARB_shader_stencil_export extension to write to stencil buffer.
I don't have any. Don't have a GPU that supports this extension. However, the extension spec tells you what to do:

* ARB_shader_stencil_export (http://www.opengl.org/registry/specs/ARB/shader_stencil_export.txt)

What part is confusing?