SDL tearing/flickering during update

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

Moderators: cheriff, TyRaNiD

Post Reply
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

SDL tearing/flickering during update

Post by PosX100 »

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)
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

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..
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

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...
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

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 :)
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

@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: Select all



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

PSP_MODULE_INFO&#40;"GLAPP", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_VFPU | PSP_THREAD_ATTR_USER&#41;;
PSP_HEAP_SIZE_KB&#40;20480&#41;; 

	/*typedef enum 
	&#123;
		BALL = 255
	&#125;;*/

	int main&#40;&#41;
		&#123;
		CALLBACKS&#58;&#58;SetupCallbacks&#40;&#41;;
		SDL_Init &#40;SDL_INIT_VIDEO&#41;;
		SDL_SetVideoMode&#40; 480, 272, 32, SDL_OPENGL|SDL_GL_DOUBLEBUFFER &#41;;
		glClearColor&#40;0.0f, 0.0f, 0.0f, 0.0f&#41;;
		glClear&#40;GL_COLOR_BUFFER_BIT&#41;;
		//2d
	        glViewport&#40;0,0,SCREEN_WIDTH,SCREEN_HEIGHT&#41;;

	        glMatrixMode&#40; GL_PROJECTION &#41;;

	        glLoadIdentity&#40;&#41;;

	        glOrtho&#40; 0, SCREEN_WIDTH,SCREEN_HEIGHT, 0, -1, 1 &#41;;

	        glMatrixMode&#40; GL_MODELVIEW &#41;;

	        glLoadIdentity&#40;&#41;;
		/*
		CNamedTextures texture_list;
		texture_list.add&#40;"sprite.tga",BALL&#41;;
		texture_list.callByName&#40;BALL&#41;;*/

                glTranslatef&#40;50,50,0&#41;;
		// a quad
       		glBegin&#40; GL_QUADS &#41;,glColor4f&#40; 1.0, 1.0, 1.0, 1.0 &#41;;
		glVertex3f&#40; 0, 0, 0 &#41;,glVertex3f&#40; 32, 0, 0 &#41;; 
		glVertex3f&#40; 32, 32, 0 &#41;,glVertex3f&#40; 0, 32, 0 &#41;;
		glEnd&#40;&#41;;

		SDL_GL_SwapBuffers&#40;&#41;;
		
		SDL_Delay&#40;5000&#41;;
And my makefile:

Code: Select all

 -CFLAGS= -Wall -g -G0 -I/usr/local/pspdev/psp/include -I/usr/local/pspdev/psp/sdk/include -fsingle-precision-constant -O2 \
	-DHAVE_OPENGL
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41; -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=$&#40;shell psp-config --pspsdk-path&#41;
include $&#40;PSPSDK&#41;/lib/build.mak
hardrive
Posts: 11
Joined: Fri Mar 17, 2006 11:13 am

Post by hardrive »

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.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

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.
be2003
Posts: 144
Joined: Thu Apr 20, 2006 2:46 pm

Post by be2003 »

hmm... does pspgl even support gl quads?
- be2003
blog
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

be2003 wrote:hmm... does pspgl even support gl quads?
Yes, it does. When in doubt, just look at the source code. :)
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

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


@jimparis:


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


Code: Select all

 
        CALLBACKS&#58;&#58;SetupCallbacks&#40;&#41;;
	MEMORYTRACKER&#58;&#58;Init&#40;&#41;;
	set clock speed 333
        SDL_Init &#40;SDL_INIT_VIDEO&#41;;
        screen=SDL_SetVideoMode&#40; 480, 272, 16, SDL_SWSURFACE | SDL_DOUBLEBUF &#41;;

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

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

		if&#40;t->get&#40;&#41; >= 10&#41;&#123;
		clear screen
		rc->render&#40;screen&#41;;
		sdl flip &#40;screen&#41;
		t->reset&#40;&#41;;
			&#125;
		t->update&#40;&#41;;
		&#125;
	rc->release&#40;&#41;;
	e->release&#40;&#41;;
	t->release&#40;&#41;;
	DEALLOC_TRACKMEM&#40;rc,D_NO_ARRAY&#41;;
	DEALLOC_TRACKMEM&#40;e,D_NO_ARRAY&#41;;
	DEALLOC_TRACKMEM&#40;t,D_NO_ARRAY&#41;;
	MEMORYTRACKER&#58;&#58;Release&#40;&#41;;
	SDL_Quit&#40;&#41;;
Last edited by PosX100 on Thu Apr 10, 2008 1:46 am, edited 2 times in total.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

PosX100 wrote:My code looks EXACTLY like this:

Code: Select all

		rc->render&#40;screen&#41;;
		sdl flip &#40;screen&#41;
Then it's amazing it compiles at all.
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

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...
Smong
Posts: 82
Joined: Tue Sep 04, 2007 4:44 am

Post by Smong »

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.
(+[__]%)
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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. :)
PosX100
Posts: 98
Joined: Wed Aug 15, 2007 1:02 am

Post by PosX100 »

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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
Post Reply