September 7th, 2011, 09:08 PM
blitting one large bitmap is slower than blitting thousands of small bitmaps? SDL
I'm using SDL-1.2.14 for this.
I'm trying to set up a rendering system for my program - which is a 2D tile/grid based game. The first rendering system I made would use a couple of for loops to scan through all visible tiles, and draw the appropriate image to the screen.
I thought it wasn't efficient because of how many times the SDL_BlitSurface function is called, so I then setup a second system - it gives every 32x32 tile region a bitmap of its own to draw to the screen in one call to SDL_BlitSurface, as opposed to 1024 calls to blit individual tiles. It works by gradually drawing to the region's bitmap, instead of the screen. The region's bitmap then goes to the screen. I thought this would be faster because the CPU would be sending less data to the GPU once the region is fully rendered, but actually, it ends up quite a lot slower.
Is this actually just the way SDL does things, or maybe I've setup something wrong?
Furthermore, using the new rendering system, occasionally some regions appear corrupted - some or all tiles may have bright colors. I'm not sure why that would be besides maybe a region having the wrong pixel format?
I've included the full source code for the program in case that would be helpful. source\main.cpp has comments at the top to direct you to the relevant parts about the rendering systems and an easy way to enable one or the other.
Make sure to put the resulting .exe file from compiling into the included bin folder and that the bin folder has an images folder and a map folder, otherwise the program will complain or crash.
Controls for interacting with the program:
WASD keys to move, hold space bar for hyper drive.
press and hold the 1 key to set the window's title bar to an efficiency rating (based on frames per second, basically) 100%=best, less is okay, negatives means the framerate is going below the desired amount.
2 key to set the window's title bar to number of objects
Left clicking will place a tile, right clicking a tile will copy it to your mouse.
So, my questions are:
1) Why is the second rendering system (1 big bitmap) slower than my first (many small bitmaps)?
2) Why are some regions corrupted sometimes?
3) Ideas for a faster rendering system?
Things I tried:
creating region bitmaps with SDL_HWSURFACE flag,
also tried SDL_SWSURFACE for comparison and got nothing different that I could notice by eye.
If there is any other information that you need, please let me know.
also: I noticed I included SDL_ttf.h in the header.h file. I'm pretty sure that it's not even used yet, so you probably don't need any SDL_ttf-related things. Remove that line if it's a problem.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!