PDA

View Full Version : How to alpha blend PBOs?



bsder
06-10-2010, 05:11 AM
How do I alpha blend two PBOs?

I've been trying to use glBlitFramebuffer/glBlitFramebufferEXT to blend 2 PBOs, but I'm not having any luck. I get a complete overwrite of one on top of the other with no blending. *Does* glBlitFramebuffer alpha blend or am I flat-out using the wrong function?

My drawing to each of the individual PBO's blends quite fine, so I've got blending enabled and the blend functions working (not exactly the way I want, but I can sort that out once I get something).

I'd really like *not* to have to use textures (although I will if that's the only solution) as there seem to be way too many drivers requiring powers of two, and I'm at 2560x1600 which would require 4096x4096 textures of which most is wasted. Not to mention the strange issues with getting pixel accurate alignment.

Thanks.

DmitryM
06-10-2010, 08:45 AM
You can use TransformFeedback if it's supported on your HW, doing the blending in vertex shader.

ZbuffeR
06-10-2010, 10:19 AM
2560x1600 which would require 4096x4096
Wrong, as NPOT does not mean square.
You could go with 4096*2048. Twice smaller :)

Alfonse Reinheart
06-10-2010, 11:18 AM
*Does* glBlitFramebuffer alpha blend

No. It's a copy operation, not a read/modify/write like blending.

Although I'm curious as to how you blit "PBOs," since blitting requires framebuffers, not buffer objects.


I'd really like *not* to have to use textures (although I will if that's the only solution) as there seem to be way too many drivers requiring powers of two

No (ATI or NVIDIA) desktop hardware (and therefore drivers written for them) made in the last half-decade requires POT textures. And if you're really that concerned, use rectangle textures, which have been available for even longer than half a decade.

bsder
06-10-2010, 06:36 PM
*Does* glBlitFramebuffer alpha blend

No. It's a copy operation, not a read/modify/write like blending.


Well, that answers that. So, I really have to use textures? Really? There's no way to pixelwise composite two FBO's directly? Not even with a shader? Seems like a major oversight.

Okay, so if I have to use textures, what's the best way to get a pixel accurate copy? Currently I use (yes, this is JOGL):



gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, currentXDimension, 0.0, currentYDimension, 2.0f, -2.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();


gl.glEnable(GL.GL_TEXTURE_2D);
gl.glBindTexture(GL.GL_TEXTURE_2D, texPointers[0]);

gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f);
gl.glVertex3i(0, 0, 0);
gl.glTexCoord2f(1.0f, 0.0f);
gl.glVertex3i(currentXDimension, 0, 0);
gl.glTexCoord2f(1.0f, 1.0f);
gl.glVertex3i(currentXDimension, currentYDimension, 0);
gl.glTexCoord2f(0.0f, 1.0f);
gl.glVertex3i(0, currentYDimension, 0);
gl.glEnd();

gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glDisable(GL.GL_TEXTURE_2D);


However, drawing a quad is not guaranteed to render some edge pixels (although I could probably live with that). I could be mistaken, but I seem to recall that you have to do something to offset the texture since it samples in the *center* of the pixel while rendering is at the *corner* of the pixel.

Any suggestions or corrections welcome.

Thanks.

Alfonse Reinheart
06-10-2010, 07:34 PM
There's no way to pixelwise composite two FBO's directly? Not even with a shader? Seems like a major oversight.

Oversight? The object that stores pixel data which can be both rendered to by the system and read from by a shader has a specific name. It is called a texture. Indeed, the main reason FBOs exist at all is to allow you to render to textures.


I seem to recall that you have to do something to offset the texture since it samples in the *center* of the pixel while rendering is at the *corner* of the pixel.

If you want to be technical, you sample from wherever you want, since we have shaders now. However, if you have set up your matrices as you've shown, that should be sufficient to get you pixel-accurate results.

The only concern would be around the edges if you're multisampling.