I have two computers, a Toshiba laptop with an i5 and ATI Radeon HD 5145, and an old Dell desktop, with Pentium D and ATI Radeon X1300 Series.
I have created a Java application, using LWJGL, that creates an FBO. The texture attached to the FBO is the size of the screen (1366x768 on the Toshiba and 1024x768 on the Dell).
I try the same application on both computers, using a program called MSI Afterburner to see the CPU usage, GPU usage and framerate.
On the Toshiba, it works perfect, on the Dell it hungs. I explain better later on.
Below is the code for creating the FBO:
//Create FBO
DisplayMode display = Display.getDisplayMode();
int fboWidth = display.getWidth();
int fboHeight = display.getHeight();
int fboTextureID = glGenTextures();
int fboID = glGenFramebuffersEXT();
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fboID);
glBindTexture(GL_TEXTURE_2D, fboTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, fboWidth, fboHeight, 0, GL_RGBA, GL_INT,
(java.nio.IntBuffer) null);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, fboTextureID, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
This is the while loop where the FBO is displayed:
while(true)
{
renderFBO();
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, fboTextureID);
glBegin(GL_QUADS);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
int x=0; int y=0; //FBO position
int w=fboWidth; int h=fboHeight; //FBO size
glTexCoord2f(0, 1);
glVertex2f(x, y);
glTexCoord2f(1, 1);
glVertex2f(x+w, y);
glTexCoord2f(1, 0);
glVertex2f(x+w, y+h);
glTexCoord2f(0, 0);
glVertex2f(x, y+h);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
Display.update(); //Update the screen
Display.sync(60); //Cap the framerate to 60fps
}
This method draws some textures to the FBO offscreen
private void renderFBO()
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
//Start FBO drawing
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID );
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Here I draw some textures using quads
//Stop FBO drawing
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
As I said before, the application on the Toshiba with the Radeon HD works perfect.
5% CPU usage, 20% GPU usage and 60fps.
When executing this application on the old Dell with the Radeon X1300 the computer hungs;
the CPU usage is 50%, the GPU can't be measured and the fps is 0.
If I don't draw the FBO, just render it offscreen, then the old Dell doesn't hung, and I get normal results 5% CPU usage, 20% GPU usage and 60fps.
It's drawing the FBO in the quad what causes the computer to hung. And I ask, why?
Why does this happen? Is there something wrong with my code? At first I thought it was the computer just being too old (it's from 2006) and having trouble dealing with FBO's, but then why doesn't it hung when rendering the FBO offscreen?