forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Image Flickering using double buffer(very annoying).

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
HexDump



Joined: 07 Jun 2005
Posts: 70

PostPosted: Mon Aug 08, 2005 9:08 pm    Post subject: Image Flickering using double buffer(very annoying). Reply with quote

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:


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:

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]
Back to top
View user's profile Send private message
matkeupon



Joined: 02 Jul 2005
Posts: 26

PostPosted: Mon Aug 08, 2005 10:27 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
HexDump



Joined: 07 Jun 2005
Posts: 70

PostPosted: Mon Aug 08, 2005 10:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
HexDump



Joined: 07 Jun 2005
Posts: 70

PostPosted: Tue Aug 09, 2005 8:35 am    Post subject: Reply with quote

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

Thanks in advance,
HexDump.
Back to top
View user's profile Send private message
matkeupon



Joined: 02 Jul 2005
Posts: 26

PostPosted: Wed Aug 10, 2005 8:44 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
HexDump



Joined: 07 Jun 2005
Posts: 70

PostPosted: Fri Aug 12, 2005 3:03 am    Post subject: Reply with quote

Ok, thanks for everything mate.


HexDump.
Back to top
View user's profile Send private message
Garak



Joined: 27 Jul 2005
Posts: 46

PostPosted: Tue Aug 16, 2005 1:15 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message Send e-mail AIM Address
remleduff



Joined: 24 Jul 2005
Posts: 11

PostPosted: Tue Aug 16, 2005 2:38 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
greij



Joined: 18 Aug 2005
Posts: 1

PostPosted: Thu Aug 18, 2005 4:06 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
framerate



Joined: 14 Aug 2005
Posts: 20

PostPosted: Fri Aug 19, 2005 2:52 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group