PDA

View Full Version : FBOs with 3d coordinates



jas511
04-25-2011, 08:40 AM
I'm learning more about framebuffers (thanks for all the help on the forum so far!), but all of the tutorials I have been reading have been about using FBOs to draw to 2D textures.
In my case, I want to draw some 3D coordinates to a buffer using a particular blending function, then draw the entire contents of that buffer back to the main screen. Do I need to render this to a 3D texture in the FBO? Or am I misunderstanding?

thanks,
Jeff

BionicBytes
04-25-2011, 08:53 AM
Never tried drawing to a 3D texture or texture array.
ARB Framebuffer does have attachments for texture layers (Texture arrays) so that means it should be possible.
In the worst case, you could attach upto 16 different colour atatchments and write to anyone of them or simultaneously using MRTs (upto an implmentation limit simultaneously - 4 or 8 on later hardware)

jas511
04-25-2011, 10:00 AM
Maybe there is another way to do what I'm trying to do. Basically I'm trying to create a heatmap (on a 3d surface). I first generate a bunch of black and white circles that blend together. Then I try to colorize those based on a color lookup table (not the glColorTable, but just conceptually a color lookup). The problem is I want to disable blending when I colorize them, so what I'm trying to do is render the blended black/white circles to the frame buffer and then render that whole image with no blending and use a fragment shader to color it (or a 1d texture to color it, either one).

BionicBytes
04-25-2011, 01:23 PM
Can you not just use a series of frame buffer attachments ?
Use glReadBuffer to select the read attachment containing the circles and use glDrawbuffers to select the destination attachment.

jas511
04-25-2011, 01:33 PM
I've been having difficulty finding how to do this. All the examples I've seen have been to draw to a 2d texture and then draw that 2d texture back into the main window. The problem is my heatmap points have x,y and z coordinates so I think it needs to be 3d, and I'm not quite sure how to properly map the 3d texture back to the main window...

V-man
04-25-2011, 01:43 PM
Post some code.
What are you having problem with?

jas511
04-25-2011, 02:25 PM
Ok, this is in Java JOGL, but conceptually still the same. In my initialization code I have



IntBuffer fbo = IntBuffer.allocate(1);
gl.glGenFramebuffersEXT(1, fbo);
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fbo.get(0));

int[] tex = new int[1];
gl.glGenTextures(1, tex, 0);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glBindTexture(GL.GL_TEXTURE_2D, tex[0]);

gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT , GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, tex[0], 0);
IntBuffer fboDepth = IntBuffer.allocate(1);
gl.glGenRenderbuffersEXT(1, fboDepth);
gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, fboDepth.get(0)); gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT , GL.GL_DEPTH_COMPONENT, width, height);
gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_ EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, fboDepth.get(0));

int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_E XT);
if (status != GL.GL_FRAMEBUFFER_COMPLETE_EXT) {
System.out.println("error creating FBO");
}
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, 0);


Then in the main display loop I have:


gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fbo.get(0);
gl.glBindTexture(GL.GL_TEXTURE_2D, tex[0]);
gl.glViewport(0, 0, width, height);

// here I have code to draw my heatmap.
// it just draws a bunch of circles and blends them together.
// The coordinates of the circles are specified in x,y,z
// coordinates, not screen points (because they are shown on
// the surface of the earth).

gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);



Then I get stuck. Basically I would like to take the x,y,z coordinates of the heatmap circles and drawn them back onto the main display (and I'll apply a fragment shader when I draw them back).
I don't know if I need to be drawing to a texture here, if I need to draw to a 3D texture, or if I can somehow read back the rgba of each of the points (and associated each value with its x,y,z coordinate)...

Any help would be appreciated. thanks.

V-man
04-25-2011, 04:52 PM
I'm confused. Do you want to render to a 3D texture or a 2D texture?

Also, you call
gl.glGenTextures(1, tex, 0);

but you did not call glBindTexture so glTexImage2D goes into the air.

You forgot to clear your FBO. (glClear).

jas511
04-25-2011, 05:01 PM
Thanks for that reply. I'm confused about whether I need a 2d or a 3d texture also. I'm basically drawing a bunch of circles on the surface a sphere. The sphere is 3d (obviously), but the circles are drawn on the surface, so I'm not sure if I would need a 2d or 3d texture...

BionicBytes
04-28-2011, 04:39 AM
Can you use the ARB version of FBO rather than EXT version.
There are many benefits by doing so, and one of which is support of textureArrays (another separate extension).
using the 3rd texture coordinate, you could be rendering to a different layer of the texture array instead.