Hi, I’m implementing stencil-routed a-buffer for some good transparency for my game, as described in http://staffwww.itn.liu.se/~andyn/courses/tncg08/sketches/content/sketches/0518.pdf, and I’ve got a quick question.
In another stencil-routing algorithm (not multisample) at http://www.tatwood.net/articles/25/stencil-routing, they initialize the entire incrementing stencil pattern themselves, with the following code:
void createStencilPattern()
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, mStencilUnpackBuffer);
unsigned* unpackData = static_cast<unsigned*>(glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY));
for(int tr = 0; tr < TILE_ROWS; ++tr)
{
for(int tc = 0; tc < TILE_COLS; ++tc)
{
for(int gr = 0; gr < GRID_ROWS; ++gr)
{
for(int gc = 0; gc < GRID_COLS; ++gc)
{
int x = gc*TILE_COLS + tc;
int y = gr*TILE_ROWS + tr;
unpackData[y*BUFFER_WIDTH + x] = tr*TILE_COLS + tc;
}
}
}
}
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
}
And they do this every time we render the screen. Questions:
- Isn’t this inefficient, because the stencil buffer lives on the graphics card, and we’re setting the data manually from the CPU?
- Would it be more efficient to initialize the stencil pattern inside the graphics card with a shader?
- If so, how would I go about doing that?
- Even if I could do that for a regular stencil buffer, I still need to be able to do it with a multisample buffer. Is that possible?
If this is the best way to do it, awesome. I just have an itching feeling that there’s a better way out there. Any ideas?
Thank you so much!
- Evan Ovadia