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 

Buffer width and u32

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



Joined: 20 Sep 2005
Posts: 11

PostPosted: Tue Sep 20, 2005 6:06 pm    Post subject: Buffer width and u32 Reply with quote

Hey, I’m not new to programming but have recently been learning C/C++, reading books and looking over sample PSP code. I’ve managed to get quite a few things to compile and run on my PSP but there are a few things still confusing me:

From: pspdisplay.h
Code:

/**
 * Display set framebuf
 *
 * @param topaddr - address of start of framebuffer
 * @param bufferwidth - buffer width (must be power of 2)
 * @param pixelformat - One of ::PspDisplayPixelFormats.
 * @param sync - One of ::PspDisplaySetBufSync
 */
void sceDisplaySetFrameBuf(void *topaddr, int bufferwidth, int pixelformat, int sync);


How do I calculate the bufferwidth I’m meant to use if I’m using the 32-bit RGBA pixel format (PSP_DISPLAY_PIXEL_FORMAT_8888)? Allot of the examples I’ve been looking at seam to have this as 512 but I just can’t understand why (512 what?).

What are the u16/u32 (etc) data types for? What are they meant to contain? I haven’t come across them in any C/C++ books I’ve been reading yet.

Thanks.
Back to top
View user's profile Send private message
Bytrix



Joined: 14 Sep 2005
Posts: 72
Location: England

PostPosted: Tue Sep 20, 2005 6:57 pm    Post subject: Reply with quote

I'm not sure about the bufferwidth, possibly it's pixel type (in bytes) multiplied by pixels used (480 * 272 * 4) which is just under 512Kb.

u16 and u32 are just unsigned values, look for the chapter about unsigned values in your books to see why they're useful.
Back to top
View user's profile Send private message Send e-mail
rinco



Joined: 21 Jan 2005
Posts: 255
Location: Canberra, Australia

PostPosted: Tue Sep 20, 2005 6:59 pm    Post subject: Reply with quote

u16/u32:

Code:
/usr/local/pspdev/psp/sdk/include/psptypes.h:typedef unsigned short                     u16;
/usr/local/pspdev/psp/sdk/include/psptypes.h:typedef unsigned int                       u32;


You calculate the buffer width by taking the width of the screen (480 pixels) and round up to the nearest power of 2 (512 pixels). The last 32 pixels are not used, and http://www.scorpioncity.com/dj2.html briefly explains why (and has a nice ascii diagram):

Quote:
Even though the screen resolution might be, say, 640x480x32, this does not necessarily mean that each row of pixels will take up 640*4 bytes in memory. For speed reasons, graphics cards often store surfaces wider than their logical width (a trade-off of memory for speed.) For example, a graphics card that supports a maximum of 1024x768 might store all modes from 320x200 up to 1024x768 as 1024x768 internally. This leaves a "margin" on the right side of a surface. This actual allocated width for a surface is known as the pitch or stride of the surface.
Back to top
View user's profile Send private message
ddgFFco



Joined: 20 Sep 2005
Posts: 11

PostPosted: Tue Sep 20, 2005 7:45 pm    Post subject: Reply with quote

Thanks, makes sense now.
Back to top
View user's profile Send private message
StouffR



Joined: 15 Sep 2005
Posts: 11

PostPosted: Tue Sep 20, 2005 11:36 pm    Post subject: Reply with quote

For u32 or u16 you can use the hexadecimal values like HTML code :

0xRRGGBBAA (R=Red, G=Green, B=blue, A=aliasing)

4x8 = 32bits (U32)
Back to top
View user's profile Send private message MSN Messenger
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Wed Sep 21, 2005 5:17 pm    Post subject: Reply with quote

I'm sorry, I might be completely wrong here, but I dont believe its in bytes, I believe its in PIXELS. In which case it should always be 512, unless you are... for some reason... not using a 480x272 screen.

It does the internal conversion since it knows the size of each pixel.
Back to top
View user's profile Send private message AIM Address MSN Messenger
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