![]() |
|
What form of bitmap is faster? |
Kevin Epps
Member #5,856
May 2005
![]() |
Which bitmaps use less memory? Reg Bitmap? |
ReyBrujo
Moderator
January 2001
![]() |
Hmmm... less memory, or faster? For memory purposes, Reg Bitmap, Loaded Bitmap and Datafile Bitmap are all the same, they use RAM memory. Video Bitmap to Video Bitmap is faster if it works with HW acceleration, but you have limited Video memory. But, on the other side, copying any non-video bitmap to a video bitmap is SLOW. -- |
Kevin Epps
Member #5,856
May 2005
![]() |
Yeah. Faster. That's what I meant to say. So video to Video... What kind of method can I use to use this type of method if I'm loading png's, gif's, and bitmaps? |
ReyBrujo
Moderator
January 2001
![]() |
Page flipping. Use create_video_bitmap to create two bitmaps. If you have a fixed amount of sprites, and enough video bitmap, you can create a small square of video bitmap and blit your loaded sprites there. Then, instead of blitting from the datafiles to the video bitmap, you could blit from that small square to the video bitmap. -- |
CGamesPlay
Member #2,559
July 2002
![]() |
Once you load the bitmap, the file type has nothing to do with how it looks in memory. Furthermore, where you load it from doesn't either. Any loaded bitmap goes into a memory bitmap, you have to copy it to video or system manually. This is a program I wrote to test blits. -- Ryan Patterson - <http://cgamesplay.com/> |
Kevin Epps
Member #5,856
May 2005
![]() |
This is what I did before the game loop:
After that, I'm just drawing the the layers(ie layer_one, etc.) to video memory in the loop. So I guess I have it where it needs to be then. Thanks guys! |
ReyBrujo
Moderator
January 2001
![]() |
Geez... your video card? And how much memory it does have? I think I would not be able to allocate that much memory with my 64mb one... -- |
Kevin Epps
Member #5,856
May 2005
![]() |
Oh really? Is that considered a lot of memory? So what size should the video memory bitmaps be, just the size of the screen? I think my Video memory is around 8mb for the Rage Pro and 64mb for the Radeon. Rage Pro 128 8mb Radeon x300 64mb |
ReyBrujo
Moderator
January 2001
![]() |
Which is your bitmap depth? 8bpp? -- |
Kevin Epps
Member #5,856
May 2005
![]() |
16bpp. I also made sure that the pics loaded were at screen's width or maybe double(just one) and it works much better, too. So all of the created video bitmaps are only the width of the screen. |
HoHo
Member #4,534
April 2004
![]() |
16bbp is two bytes per pixel. You create eight 3200x480 images. That is 12MiB of memory. Of course some memory is for the screen bitmap and buffer too. That is not too much by todays standards but certainly it will never work on anything that has below 16MiB of Vram. __________ |
Kevin Epps
Member #5,856
May 2005
![]() |
Ok. I've changed those video sizes to 640x480l. So now I've created 8 640x480 video bitmaps. It seems to work fine on the Rage as well. Even with more than one character sprite on the screen. |
Neil Walker
Member #210
April 2000
![]() |
Why do you need 3200 width bitmaps? or is this something different to your tilemap program? Also, why are you creating a bitmap, colouring it magenta then drawing masked images to it, why not just create the bitmaps then blit the image, saving the clear_to_colour() commands? Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Kevin Epps
Member #5,856
May 2005
![]() |
They're not 3200 now. They're 640. As far as the clear color. I was told that the draw_sprite call was faster than the blit call. Is that wrong? |
Neil Walker
Member #210
April 2000
![]() |
But you aren't doing that create_bitmap every loop are you? Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
Kevin Epps
Member #5,856
May 2005
![]() |
no. Here's what i have now.
Each file is 640x480 void init(BITMAP *src, int src_y, float src_speed) { sprite = create_video_bitmap(src->w, src->h); clear_to_color(sprite, makecol(255,0,255)); draw_sprite(sprite, src, 0, 0); y = src_y; speed = src_speed; } And here's how it's drawn:
And this works well for me now. And yes, I know that I need a for loop there and I will add it, but I also have problems when I add a for loop inside of the drawing loop. But anyway it works fine. |
ReyBrujo
Moderator
January 2001
![]() |
Aren't you overwritting the sprite sprite with a new one everytime you call the init function? -- |
Kevin Epps
Member #5,856
May 2005
![]() |
Sort of. I'm just creating each layer sprite as a video bitmap and then drawing the 1st paramerter(loaded bitmap) to it so the now the sprite will be a video bitmap of the loaded bitmap. That's all. When an object is created, the sprite is NULL; |
Tobias Dammers
Member #2,604
August 2002
![]() |
Can you see that this:
masked_blit(layer[0].sprite, buffer, 0, 0, -((int)(camera.x*layer[0].speed)%layer[0].sprite->w), layer[0].y - camera.y*layer[0].speed, layer[0].sprite->w, layer[0].sprite->h); masked_blit(layer[0].sprite, buffer, 0, 0, layer[0].sprite->w - ((int)(camera.x*layer[0].speed)%layer[0].sprite->w), layer[0].y - camera.y*layer[0].speed, layer[0].sprite->w, layer[0].sprite->h); masked_blit(layer[1].sprite, buffer, 0, 0, -((int)(camera.x*layer[1].speed)%layer[1].sprite->w), layer[1].y - camera.y*layer[1].speed, layer[1].sprite->w, layer[1].sprite->h); masked_blit(layer[1].sprite, buffer, 0, 0, layer[1].sprite->w - ((int)(camera.x*layer[1].speed)%layer[1].sprite->w), layer[1].y - camera.y*layer[1].speed, layer[1].sprite->w, layer[1].sprite->h); masked_blit(layer[2].sprite, buffer, 0, 0, -((int)(camera.x*layer[2].speed)%layer[2].sprite->w), layer[2].y - camera.y*layer[2].speed, layer[2].sprite->w, layer[2].sprite->h); masked_blit(layer[2].sprite, buffer, 0, 0, layer[2].sprite->w - ((int)(camera.x*layer[2].speed)%layer[2].sprite->w), layer[2].y - camera.y*layer[2].speed, layer[2].sprite->w, layer[2].sprite->h); masked_blit(layer[3].sprite, buffer, 0, 0, -((int)(camera.x*layer[3].speed)%layer[3].sprite->w), layer[3].y - camera.y*layer[3].speed, layer[3].sprite->w, layer[3].sprite->h); masked_blit(layer[3].sprite, buffer, 0, 0, layer[3].sprite->w - ((int)(camera.x*layer[3].speed)%layer[3].sprite->w), layer[3].y - camera.y*layer[3].speed, layer[3].sprite->w, layer[3].sprite->h); MapDrawBGT(buffer, camera.x, camera.y, 0, 0, WIDTH-1, HEIGHT-1); //draw foreground tiles MapDrawFG(buffer, camera.x, camera.y, 0, 0, WIDTH-1, HEIGHT-1, 0); player.draw(buffer, camera.x, camera.y); masked_blit(layer[5].sprite, buffer, 0, 0, -((int)(camera.x*layer[5].speed)%layer[5].sprite->w), layer[5].y - camera.y*layer[5].speed, layer[5].sprite->w, layer[5].sprite->h); masked_blit(layer[5].sprite, buffer, 0, 0, layer[5].sprite->w - ((int)(camera.x*layer[5].speed)%layer[5].sprite->w), layer[5].y - camera.y*layer[5].speed, layer[5].sprite->w, layer[5].sprite->h); masked_blit(layer[6].sprite, buffer, 0, 0, -((int)(camera.x*layer[6].speed)%layer[6].sprite->w), layer[6].y - camera.y*layer[6].speed, layer[6].sprite->w, layer[6].sprite->h); masked_blit(layer[6].sprite, buffer, 0, 0, layer[6].sprite->w - ((int)(camera.x*layer[6].speed)%layer[6].sprite->w), layer[6].y - camera.y*layer[6].speed, layer[6].sprite->w, layer[6].sprite->h); masked_blit(layer[7].sprite, buffer, 0, 0, -((int)(camera.x*layer[7].speed)%layer[7].sprite->w), layer[7].y - camera.y*layer[7].speed, layer[7].sprite->w, layer[7].sprite->h); masked_blit(layer[7].sprite, buffer, 0, 0, layer[7].sprite->w - ((int)(camera.x*layer[7].speed)%layer[7].sprite->w), layer[7].y - camera.y*layer[7].speed, layer[7].sprite->w, layer[7].sprite->h); masked_blit(layer[8].sprite, buffer, 0, 0, -((int)(camera.x*layer[8].speed)%layer[8].sprite->w), layer[8].y - camera.y*layer[8].speed, layer[8].sprite->w, layer[8].sprite->h); masked_blit(layer[8].sprite, buffer, 0, 0, layer[8].sprite->w - ((int)(camera.x*layer[8].speed)%layer[8].sprite->w), layer[8].y - camera.y*layer[8].speed, layer[8].sprite->w, layer[8].sprite->h);...contains tons of duplicate code? Duplicate code is a sign that your layout isn't structured well. I'd recommend using a dedicated function for blitting a layer: void draw_layer(int i) { masked_blit(layer[i].sprite, buffer, 0, 0, -((int)(camera.x*layer[i].speed)%layer[i].sprite->w), layer[i].y - camera.y*layer[i].speed, layer[i].sprite->w, layer[i].sprite->h); masked_blit(layer[i].sprite, buffer, 0, 0, layer[i].sprite->w - ((int)(camera.x*layer[i].speed)%layer[i].sprite->w), layer[i].y - camera.y*layer[i].speed, layer[i].sprite->w, layer[i].sprite->h); } Then your drawing code looks like this: int l; for (l = 0; l < 4; ++l) draw_layer(l); MapDrawBGT(buffer, camera.x, camera.y, 0, 0, WIDTH-1, HEIGHT-1); //draw foreground tiles MapDrawFG(buffer, camera.x, camera.y, 0, 0, WIDTH-1, HEIGHT-1, 0); player.draw(buffer, camera.x, camera.y); for (l = 4; l < 9; ++l) draw_layer(l);Much cleaner, and compiler-friendly. If you want to avoid the function call and loop overhead (but in this situation, that's silly IMHO), you can mark draw_code() as inline, and specify -funroll-loops -funroll-all-loops when compiling. As for the draw_sprite() vs. blit() thing; the way you do it is certainly not the fastest, but I suggest that since it works, you leave it exactly as it is (avoiding color conversion issues). It's initialization code we're talking about here, no need to optimize unless loading takes more than 60 seconds. For the record: draw_sprite() is not faster than blit(). It can be faster than masked_blit() under certain circumstances, and it may be as fast as blit() for accelerated video-video operations. --- |
|