Archived

This topic is now archived and is closed to further replies.

Why does gluBuild2DMipMaps slow down glDrawPixels?

This topic is 5147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m having a strange problem using gluBuild2DMipMaps. I''m developing an app in which I do some software rendering to a (typically) 640x480 RGBA buffer which is then drawn to the screen using glDrawPixels. I also render some fairly simple OpenGL objects. The whole thing trundles along quite nicely at 30-50fps. The problem comes when I introduced a textured quad. This is created using gluBuild2DMipMaps and is also normally 640x480, RGBA. After the gluBuild2DMipMaps call the application slows down to <1fps whenever the glDrawPixels call is being made. This doesn''t seem to be affected by whether the quad is actually drawn, it''s the call to glBuild2DMipMaps that seems to make the difference. Has anyone encountered anything like this before or have any ideas about what might be happening? Thanks in advance for any help, ResearchMonkey

Share this post


Link to post
Share on other sites
You''re not calling gluBuild2DMipMaps every frame are you? That function can take quite a bit of time to run as it has to resample the texture to generate the mip versions. You should definitely not be calling this every frame. I don''t immediately see any other reason why this call would cause you grief.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites
Thats weird, I think I''m getting the same problem... my mouse pointer slows down as I move it across the screen when the app is running. I am not using gluBuild2DMipmaps(), instead i''m using glTexImage2D() because my application is 2D and doesn''t require scaling of textures due to pixel zooming. My task manager shows some pretty erratic memory dumps, small but noticable enough, maybe I''ll check my loading code just to make sure it only gets called at the start.

I''m drawing one 800x600 backdrop each frame but surely that won''t slow it down?

Share this post


Link to post
Share on other sites
yeah,

i use that function when i''m setting up my textures for objects that need mipmaps. i got a 10FPS boost from putting that function in with my terrain tiles. a slowdown is wierd.

got code you can show us?

-me

Share this post


Link to post
Share on other sites
quote:
You're not calling gluBuild2DMipMaps every frame are you?

quote:
got code you can show us?

No, I just call it once when I create my textured quad object:
glGenTextures(1, &mTextureID);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mTextureID);
gluBuild2DMipmaps(GL_TEXTURE_2D, colourComps, pImage->x,
pImage->y, formatGL, GL_UNSIGNED_BYTE, pImage->ubData);

To render the quad I use:
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, myTextureID);
glColor4f(1.0, 1.0, 1.0, 0.5);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, 0);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, 0);
glEnd();

And then to render my software buffer I use:
glRasterPos3d(windowPoint.X/1.001, windowPoint.Y/1.001, windowPoint.Z);
glPixelZoom(((float) windowSize.x) / ((float) image->x),
-((float) windowSize.y) / ((float) image->y));

glEnable(GL_DEPTH_TEST);
// Set alpha function to only draw pixels with positive alpha values

glAlphaFunc(GL_GREATER, 0.0);
glEnable(GL_ALPHA_TEST);

glDrawPixels(image->x, image->y, GL_RGBA, GL_UNSIGNED_BYTE, image->ubData);


My best guess at the moment is that it's having to swap textures in and out of video card memory. Does this seem likely (I have a GeForce4, plenty of RAM)? Is there any way to test/debug this?

Thanks for your input so far, I'd be very grateful to hear anyone's comments on the above code.

[edited by - ResearchMonkey on November 11, 2003 10:25:52 PM]

[edited by - ResearchMonkey on November 11, 2003 10:27:48 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Lev Povalahev
Make sure you're getting hardware acceleration.


I've profiled the app and it's spending nearly all of it's time in the nVidia OpenGL DLL so it looks like it's using the hardware.

I've also tried to change the gluBuild2DMipMaps line to glTexImage2D
glTexImage2D(GL_TEXTURE_2D, 0, 4, pImage->x, pImage->y, 0, formatGL, GL_UNSIGNED_BYTE, pImage->ubData); 

but get the error code GL_INVALID_VALUE. Do the image dimensions have to be powers of two here?

[edit]Resizing the image to 256x256 got rid of the error but now the quad is not textured (but no slowdown).[/edit]

[edited by - ResearchMonkey on November 13, 2003 11:40:54 PM]

Share this post


Link to post
Share on other sites
Yes you need power of 2 textures. gluBuild2DMipMaps will scale them to a power of 2 for you.

Try glBindTexture(GL_TEXTURE_2D, 0) before you do you glDrawPixels call, and see if that helps.

Share this post


Link to post
Share on other sites
quote:
Original post by duke
Try glBindTexture(GL_TEXTURE_2D, 0) before you do you glDrawPixels call, and see if that helps.


[edited]
Thanks Duke that's fixed it! It also works with gluBuild2DMipMaps as well. Please help yourself to some good karma.

To summarise, the problem was that glDrawPixels was called with the quad texture still bound which (I think) was causing slow video memory/RAM swapping with gluBuild2DMipMaps and was clearing the texture when I used glTexImage2D. Cheers to everyone who helped, I don't think I'd have been able to fix it on my own.


[edited by - ResearchMonkey on November 13, 2003 12:15:51 AM]

Share this post


Link to post
Share on other sites