PDA

View Full Version : How to use FBO with COLOR_ATTACHMENT of different dimensions



yalmar
07-28-2006, 08:07 PM
Hi,

I need use two different color attachments with different dimensions (NxN and MxM), i'm working with an ATI X600. I get the "1286" GL Error code, i don't know what error is this.

GLuint tex[2]; // two textures
...
// make two textures (vtx, adj)
glGenTextures(2, &tex[0]);

// initialize texture 1
glBindTexture(TEXTURE_TARGET, tex[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(TEXTURE_TARGET, 0, TEXTURE_TYPE, vImageWidth, vImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
assert(errcheck());

// initialize texture 2
glBindTexture(TEXTURE_TARGET, tex[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(TEXTURE_TARGET, 0, TEXTURE_TYPE, cImageWidth, cImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
assert(errcheck());
...

// gen the FBO
glGenFramebuffersEXT(1, &fb);
assert(errcheck());

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, TEXTURE_TARGET, tex[0], 0);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, TEXTURE_TARGET, tex[1], 0);
CHECK_FRAMEBUFFER_STATUS()
assert(errcheck());

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

...

// send array data for both textures
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,vImageWidth,0.0,vImageHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,vImageWidth,vImageHeight);

glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glRasterPos2i(0,0);
glDrawPixels(vImageWidth,vImageHeight,GL_RGBA,GL_F LOAT,vtx);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,cImageWidth,0.0,cImageHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0,cImageWidth,cImageHeight);

glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT);
glRasterPos2i(0,0);
glDrawPixels(cImageWidth,cImageHeight,GL_RGBA,GL_F LOAT,adj); // Here!!! crashes the program
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

...

A solution will be create another FBO, but it crashes too, in this case i don't know if the COLOR_ATTACHMENTS "id" start with 0 or continues with the last used in the first FBO, i.e., last_id+1


yalmar.

Zengar
07-29-2006, 05:30 AM
It is not possible, read the specs. All attachements must be of teh same size

moebi
07-29-2006, 08:17 PM
Check out EXT_framebuffer_blit.

I've never worked with it since my current platform does not support it, but if I get it right, this extension will be able to help you ;)

Zengar
07-30-2006, 03:48 AM
Framebuffer_blit is not supported on current hardware and I don't think it will be supported soon (but who knows).

moebi
07-30-2006, 12:00 PM
Framebuffer_blit is not supported on current hardware [...] Okay, I supposed sth. like this...

But at least yalmar has a theoretical answer to his problem ;)

Frogblast
07-30-2006, 03:06 PM
DirectX 9 already has StretchBlit, which is basically what framebuffer_blit does. To me, that means that existing hardware is probably capable, but it hasn't been exposed in existing OpenGL drivers (because no suitable API for it existed yet).