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 

SDL tearing/flickering during update

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



Joined: 15 Aug 2007
Posts: 98

PostPosted: Sun Apr 06, 2008 8:30 pm    Post subject: SDL tearing/flickering during update Reply with quote

Im having some trouble with SDL on psp.

The screen , for some reason , flickers during update (sdl_flip()) , and ONLY, when objects are moving(and we're talking about 5-10 objects which use the same surface...).

I have tried every possible solution that i found after searching on forums , but , nothing really worked (Except setting Software mode rendering , and screen bpp to 16).

Also , removing displayvblank() function(before calling sdl_flip) with my own timer , improved the frames a little more..

sceKernelDcacheWritebackAll before rendering anything didnt help either.


Any other suggestions?

EDIT: Screen surface is double-buffered (init code : sdl_init(480,272,16,SDL_DOUBLEBUF | SDL_SWSURFACE)
Back to top
View user's profile Send private message
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Mon Apr 07, 2008 12:23 am    Post subject: Reply with quote

Can't find any solution.

I've been trying for more than 3 hours.

Things that i've tried:


-Optimize loaded surfaces to screen format : result : a little boost
-Created an even more accurate timer : result : better visual result

What i haven't tried yet:
-Convert sdl surface to 8bit mode..


Tearing still occurs , and makes the game unplayable(who's going to play a platform game with so bad performance?....no one)

I've been thinking to switch to SDL+OpenGL(im more familiar with opengl),
But i have a few questions ...

1) OpenGL is Hardware or Software accelerated?
2) In windows/linux the standar way to initialize SDL + opengl , is :
SDL_Setvideomode(width,height,bpp,SDL_OPENGL|SDL_GL_DOUBLEBUFFER)
It will work the same on psp?
3) PSPGL is what im after(hardware opengl support on psp)?

Thanks for looking..
Back to top
View user's profile Send private message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Mon Apr 07, 2008 2:39 am    Post subject: Reply with quote

foreword: i know nothing about SDL
1) ?????? If it was software it would be not accelerated at all. Punctualization: on PC, if openGl can't find an hardware way to perform a base task, it will do it in software. Actually this was true 5 years ago, now a card has every basilar acceleration needed, while advanced ones (extensions and shaders) are generally too complex to be emulated. As i already said, pspGl is good, but is still lacking some useful features...
2) see foreword
3) yes, pspGl is a layer upon GE and i think it's doing in hardware all the things it can do in hardware (like GU/GUM)...don't really know about matrix manipulation on VFPU...
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Apr 07, 2008 5:31 am    Post subject: Reply with quote

Quote:
removing displayvblank() function(before calling sdl_flip) with my own timer

I think SDL already handles waiting for vblank (the docs are unclear if the platform should do this, and if I recall correctly the PSP does). Also try SDL_HWSURFACE as the code paths for SWSURFACE and HWSURFACE are very different. as always you can check the source for all the details :)
Back to top
View user's profile Send private message
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Mon Apr 07, 2008 8:36 pm    Post subject: Reply with quote

@Jean:

Thanks for the reply , you covered all my questions :)


@Jimparis:

I dont know why , but with SWSURFACE the program runs a little faster.
But again , since the tearing effect is there , you can only see this effect
in debug log where all statistics are printed.

Im so disapointed with SDL...so much work for nothing.


_____________________________________________


I just installed PSPGL(modified version) , and after all the trouble installing it (had to edit a header..),
it seems that every opengl command will hang the psp!(..........so bad luck)

Here's my code:

Code:



#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "Callbacks.h"
#include "NamedTextures.h"

PSP_MODULE_INFO("GLAPP", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_VFPU | PSP_THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(20480);

   /*typedef enum
   {
      BALL = 255
   };*/

   int main()
      {
      CALLBACKS::SetupCallbacks();
      SDL_Init (SDL_INIT_VIDEO);
      SDL_SetVideoMode( 480, 272, 32, SDL_OPENGL|SDL_GL_DOUBLEBUFFER );
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      glClear(GL_COLOR_BUFFER_BIT);
      //2d
           glViewport(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);

           glMatrixMode( GL_PROJECTION );

           glLoadIdentity();

           glOrtho( 0, SCREEN_WIDTH,SCREEN_HEIGHT, 0, -1, 1 );

           glMatrixMode( GL_MODELVIEW );

           glLoadIdentity();
      /*
      CNamedTextures texture_list;
      texture_list.add("sprite.tga",BALL);
      texture_list.callByName(BALL);*/

                glTranslatef(50,50,0);
      // a quad
             glBegin( GL_QUADS ),glColor4f( 1.0, 1.0, 1.0, 1.0 );
      glVertex3f( 0, 0, 0 ),glVertex3f( 32, 0, 0 );
      glVertex3f( 32, 32, 0 ),glVertex3f( 0, 32, 0 );
      glEnd();

      SDL_GL_SwapBuffers();
      
      SDL_Delay(5000);


And my makefile:

Code:

 -CFLAGS= -Wall -g -G0 -I/usr/local/pspdev/psp/include -I/usr/local/pspdev/psp/sdk/include -fsingle-precision-constant -O2 \
   -DHAVE_OPENGL
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS) -c

OBJS=main.o NamedTextures.o ImageLoader.o CallBacks.o

TARGET = sdlgltest
BUILD_PRX = 1
PSP_FW_VERSION = 371

LIBDIR =
LDFLAGS =
LIBS= -lstdc++ -lSDL -lGLU -lGL  -lpng -ljpeg -lz -lm -lstdc++ -lc -lc -lpsputility -lpspdebug -lpspgu -lpspge -lpspdisplay -lpspctrl -lpspvfpu -lpspuser -lpsprtc -lpsppower -lpspdebug -lpspge -lpspaudio -lpspctrl -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpsphprm -lpspsdk

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = sdlgltest

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Back to top
View user's profile Send private message
hardrive



Joined: 17 Mar 2006
Posts: 11

PostPosted: Tue Apr 08, 2008 10:53 am    Post subject: Reply with quote

Did you try setting the clock speed to 333? I noticed that helps a bit. I don't see the massive tearing you describe though.
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Apr 08, 2008 11:29 am    Post subject: Reply with quote

If you're doing double-buffering right, there really shouldn't be any tearing. maybe post your main loop here & let us take a look.
Back to top
View user's profile Send private message
be2003



Joined: 20 Apr 2006
Posts: 144

PostPosted: Tue Apr 08, 2008 12:17 pm    Post subject: Reply with quote

hmm... does pspgl even support gl quads?
_________________
- be2003
blog
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Tue Apr 08, 2008 1:09 pm    Post subject: Reply with quote

be2003 wrote:
hmm... does pspgl even support gl quads?


Yes, it does. When in doubt, just look at the source code. :)
Back to top
View user's profile Send private message AIM Address
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Wed Apr 09, 2008 8:36 pm    Post subject: Reply with quote

HardDrive : yes , i've tried already, without any results.


@jimparis:


My code looks EXACTLY(WELL,also includes pseudo-code ..) like this:



Code:

 
        CALLBACKS::SetupCallbacks();
   MEMORYTRACKER::Init();
   set clock speed 333
        SDL_Init (SDL_INIT_VIDEO);
        screen=SDL_SetVideoMode( 480, 272, 16, SDL_SWSURFACE | SDL_DOUBLEBUF );

   CEvents*   e  = ALLOC_TRACKMEM(CEvents); // a define that creates dynamically(using 'new' operator) the object,
                   // and updates memory tracker...for statistics
   CTimer*    t  = ALLOC_TRACKMEM(CTimer);
   CResource* rc = ALLOC_TRACKMEM(CResource);
   rc->init(); //load player's object & bullet system
   e->init();
   e->start();
   t->reset();

   while( (e->running()) )
      {
      
      e->proccess();//read SDL input events/messages etc.
      handle player movement
      if e->keyPressed(KEY_L) then
       rc->Player->fire() <-add more 2 dimensional vectors in the list
      the 2d vector for bullet system looks like this:
      class Vector2
      {
      public:
      float x,y,w,h;
      unsigned int texture_index;
      };
      Function FIRE() adds  a vector in the list, and the renderer
      draws the double-buffered images(uses 1 surface or 1 set of animation)

      if(t->get() >= 10){
      clear screen
      rc->render(screen);
      sdl flip (screen)
      t->reset();
         }
      t->update();
      }
   rc->release();
   e->release();
   t->release();
   DEALLOC_TRACKMEM(rc,D_NO_ARRAY);
   DEALLOC_TRACKMEM(e,D_NO_ARRAY);
   DEALLOC_TRACKMEM(t,D_NO_ARRAY);
   MEMORYTRACKER::Release();
   SDL_Quit();


Last edited by PosX100 on Thu Apr 10, 2008 1:46 am; edited 2 times in total
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Apr 10, 2008 12:52 am    Post subject: Reply with quote

PosX100 wrote:
My code looks EXACTLY like this:
Code:

      rc->render(screen);
      sdl flip (screen)

Then it's amazing it compiles at all.
Back to top
View user's profile Send private message
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Thu Apr 10, 2008 1:44 am    Post subject: Reply with quote

I thought it was obvious that i have replaced some code with pseudo-code , but....(there are even comments...un-commented rofl) doh...

I believe you're joking...
Back to top
View user's profile Send private message
Smong



Joined: 04 Sep 2007
Posts: 82

PostPosted: Fri Apr 11, 2008 4:03 am    Post subject: Reply with quote

I can't see any evidence of you using pspDebugScreen*, but if you are I think that can cause some flickering, I've seen at least one game that has this issue.
_________________
(+[__]%)
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Fri Apr 11, 2008 5:24 am    Post subject: Reply with quote

Smong wrote:
I can't see any evidence of you using pspDebugScreen*, but if you are I think that can cause some flickering, I've seen at least one game that has this issue.


Yep! When I was working on Doom, I had a bunch of printfs going to see how far it got. Once it was finally working, the screen blinked every time a debug printf occurred. It took about ten minutes to find the printfs to disable to make the screen quit blinking. :)
Back to top
View user's profile Send private message AIM Address
PosX100



Joined: 15 Aug 2007
Posts: 98

PostPosted: Fri Apr 11, 2008 8:08 pm    Post subject: Reply with quote

I don't print anything on screen or to a file.
Only memory tracker has a function that prints the results to a file.
But since the files are loaded before the loop, there isn't any problem.

And just a note: The tearing occurs when i move the objects around the screen.

To get an idea:

I have a spaceship controlled by player.
The ship has unlimited ammo.

When i press the button to fire , the bullets start moving.

The bullets also collide with screen(just like geometry wars) , and they go crazy until they're "alive"(there is a timer for this porpuse).

Now , add to this the tearing/flickering effect , and you should understand how serious is the problem.

Anyway,im not going to work with SDL anymore(on psp i mean).

If anyone knows what im doing wrong with sdl opengl please let me know..

My last hope is GU , which is similar to opengl(i think its a wrapper...not sure)...

Thanks , and sorry for the trouble.
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Apr 12, 2008 5:40 am    Post subject: Reply with quote

The problem is you're only posting pseudo-code at best. If you aren't willing to post code, you'll have to debug this yourself. SDL works fine on the PSP, so it's clearly something you're doing in your code. Since we can't see the code, there's not much we can do but make suggestions. Sorry.
Back to top
View user's profile Send private message AIM Address
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