Image Flickering using double buffer(very annoying).

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Image Flickering using double buffer(very annoying).

Post by HexDump »

Hi, I have wrote some code to get double buffer working.
The code is very simple, but although it seems to do things
like it should, image flickering is appearing all around
(only on scrolling parts). I´m using this code:

+Draw everything you want to back buffer
+CGfxUtils::Flip();
+sceDisplayWaitVblankStart();

This is my flip function:

Code: Select all


void CGfxUtils::Flip()
{
    m_iCurrentFB=!m_iCurrentFB;
    sceDisplaySetFrameBuf((char*)m_FBs[m_iCurrentFB],
                                      512,PSP_DISPLAY_PIXEL_FORMAT_565,1);
}

m_iCurrentFB is the Front Buffer index to a vector where both frame buffers pointers are kept (just for easy switching)

I init this with this code:

Code: Select all

void CGfxUtils::InitGfx16()
{
 //m_iCurrentFB is the Front Buffer   
    m_iCurrentFB=0;
    m_FBs[0]=(void*)VRAM_START;
    m_FBs[1]=(void*)(VRAM_START+FRAME_LENGHT);
    sceDisplaySetMode(  0, SCREEN_WIDTH,SCREEN_HEIGHT);
    sceDisplaySetFrameBuf((char*)m_FBs[0],512,PSP_DISPLAY_PIXEL_FORMAT_565,1);
}

If anyone needs more info, let me know. I think everything is right
but I can´t believe this flickering is because of the slow LCD
screen refresh :(.


Thanks in advance,
HexDump.[/code]
matkeupon
Posts: 26
Joined: Sat Jul 02, 2005 10:58 pm

Post by matkeupon »

Hi,

About your flickering problem, I believe it is the place where you put the sceDisplayWaitVblankStart(); that is wrong...

But I also have a problem with it. On any other system, you would wait for vblank, and then just after, flip the buffers. But if your loop doesn't take enough time to complete, then sceDisplayWaitVblankStart(); seems to let go too early. So I tried, like in the first examples, to put the sceDisplayWaitVblankStart(); right after the screen flip, and it seems to work on tiny loops, but not on bigger ones. It works better if, for example, you flip your buffers, then do a little something, like check for what keys are being pressed, and then wait for vblank.

One last very strange thing, once I started using the Gu functions, I had to put the vwait just before the flip like on other systems... Very odd.
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Post by HexDump »

Thanks for your answering matkeupon. You´re right, in my first attempt I do things like they normally are done in other systems. First wait for vblank and then flip, but this seemed not to work (as you stated), so I tried to do things this way, I got less flickering but it is a lot anyway. I hope someone could bring some light to the problem.

Anyway do you think I should use Gu functions instead of the others?
does they give better results?.

Thanks in advance,
HexDump.
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Post by HexDump »

I have tried the little loop trick but I get the same result :(.

Thanks in advance,
HexDump.
matkeupon
Posts: 26
Joined: Sat Jul 02, 2005 10:58 pm

Post by matkeupon »

You should try using the Gu then. Look at the blend example, you'll find how to blit simple planes with textures. Screen flip will get a lot easier then.
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Post by HexDump »

Ok, thanks for everything mate.


HexDump.
Garak
Posts: 46
Joined: Wed Jul 27, 2005 1:59 am

Post by Garak »

To diplay graphics on the PSP, you have to call sceDisplaySetFrameBuf and pass in the buffer to draw as a paramater. If the graphics are only displayed when you call sceDisplaySetFrameBuf, then why have the 2 buffers? You can write to your single buffer all you want, and draw the complete frame to the screen with your call to sceDisplaySetFrameBuf. Any writing you do to the buffer before calling sceDisplaySetFrameBuf does not show up on the screen anway.

I have been looking through the origional pg code (pg.c & pg.h), and I don't really see why they use 2 buffers. Is there some reason I am missing?
remleduff
Posts: 11
Joined: Sun Jul 24, 2005 3:29 am

Post by remleduff »

I believe you're incorrect about requiring sceDisplaySetFrameBuf for your changes to show.

If you make changes within the current framebuffer, they show immediately. The screen refresh rate will result in tearing if you just try to do all your drawing to the visible screen.

sceDisplaySetFrameBuf is used to implement "flipping" the current and back buffer, which is why you might think it's required for drawn changes to be shown.
greij
Posts: 1
Joined: Thu Aug 18, 2005 3:54 am

Post by greij »

i think i know your problem, sounds like something we experienced on the GBA.
basically it sets a hardware register the tells if the screen is in the vblank, but as you know the vblank takes some length of time, say 6ms, during which the register will remain set.
now my guess is all sceDisplayWaitVblankStart() does is wait until that register is set.
so you call it and it waits then frees your thread to process further when the vblank register sets, you flip the buffers then go through to the beginning of your loop and do all the drawing again, but if all of this only takes less the 6ms, when it calls sceDisplayWaitVblankStart() again it lets it go through right away. by now however, the vblank period is almost over and you get tearing because of it.

i'm not sure because i can't see the code for sceDisplayWaitVblankStart(), but what we did on GBA was create 2 functions, one that waits for the vblank to be start and another that waits for it to finish. after we write to the screen we call the one that waits for the vblank to finish in order to keep it synchronized. so what you'd need is a sceDisplayWaitVblankEnd() if one exists...

again i dont know for sure cuz i'm just starting with PSP programming.
framerate
Posts: 20
Joined: Sun Aug 14, 2005 2:30 am

Post by framerate »

Could someone point me in a good direction for setting up some simple double buffering using pg.c? If it's easier to write my own graphics library for double buffering, feel free to point me that way too..

email is framerate AT gmail.com. My project is coming along nicely, so you know I'm not just a dreamer.. Some older source is at www.framerate.info/psp (but has changed a lot since then)

I haven't done any game programming for a few years, and then it was in java, so I can't quite figure out how to implement the double buffering... any help is appreciated
Post Reply