Trouble understanding sceGuTexImage()

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

Moderators: cheriff, TyRaNiD

Post Reply
GORETHRASHER
Posts: 12
Joined: Wed Sep 10, 2008 12:28 pm

Trouble understanding sceGuTexImage()

Post by GORETHRASHER »

Code: Select all

void sceGuTexImage  	(  	int   	 mipmap,
		int  	width,
		int  	height,
		int  	tbw,
		const void *  	tbp	 
	) 			

Set current texturemap.

Textures may reside in main RAM, but it has a huge speed-penalty. Swizzle textures to get maximum speed.

Note:
    Data must be aligned to 1 quad word (16 bytes)

Parameters:
    	mipmap 	- Mipmap level
    	width 	- Width of texture (must be a power of 2)
    	height 	- Height of texture (must be a power of 2)
    	tbw 	- Texture Buffer Width (block-aligned)
    	tbp 	- Texture buffer pointer (16 byte aligned) 
What does it mean by 16 byte aligned, and block aligned?

How should the pixel data look like in my array? Currently I am reading a bitmap to an unsigned char array

Code: Select all

int j = 0;
for &#40;i=0; i < &#40;int&#41;width * &#40;int&#41;height; i++&#41;
&#123; 
	
	fread&#40;&rgb, sizeof&#40;rgb&#41;, 1, l_file&#41;; 
	l_texture&#91;j+0&#93; = rgb.rgbtRed; // Red component
	l_texture&#91;j+1&#93; = rgb.rgbtGreen; // Green component
	l_texture&#91;j+2&#93; = rgb.rgbtBlue; // Blue component

	j += 3; // Go to the next position
&#125;
Which sceGuTexMode and sceGuTexImage calls do I need to get it rendering properly?
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

This should help you understanding what is aligning data:
http://en.wikipedia.org/wiki/Packed
Image
Upgrade your PSP
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Also take a look at the supported texture pixel formats. There is no RGB888 24bit format.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
GORETHRASHER
Posts: 12
Joined: Wed Sep 10, 2008 12:28 pm

Post by GORETHRASHER »

I decided upon Using GU_PSM_4444 - Hicolor, 16-bit for the internal pixel format

So here is what I have got so far, does it make sense?

Code: Select all

	
int size  = width * height * 2; //Using GU_PSM_4444

l_texture = &#40;BYTE *&#41; malloc&#40;size&#41;;	//Assign memory
memset&#40;l_texture, 0, size&#41;;			//Clear the memory

//... check memory ...

char a,b;

	for &#40;i=0; i < width * height; i++&#41;
	&#123; 
		fread&#40;&rgb, sizeof&#40;rgb&#41;, 1, l_file&#41;; 

		//We have to convert a 24bit 888 image to a 16bit 4444&#40;RGBA&#41; image

		a = &#40;rgb.rgbtRed/255.0f&#41; * 0xF;		//divide the value by 255 then multiply by 15
		a = a << 4;						//Shift left by 4 bits to make room for next value
		b = &#40;rgb.rgbtGreen/255.0f&#41; * 0xF;	//do this again to get 4 bit number for green
		a = a | b;						//OR the two numbers together
		l_texture&#91;j+0&#93; = a;				// Red and Green component

		a = &#40;rgb.rgbtBlue/255.0f&#41; * 0xF;	//Same goes for this pair of values
		a = a << 4;						//each value will take up 4 bits or half a byte
		a = a | 0xF;					//Set alpha to 0xF
		l_texture&#91;j+1&#93; = a;				// Green and Alpha component

		j += 2; // Go to the next position
	&#125;

Later on I try to use it

Code: Select all

sceGuTexMode&#40;GU_PSM_4444,0,0,0&#41;;
sceGuTexImage&#40;0,image_size,image_size,buffer_width,texture&#41;;
image_size is 128 and same for buffer_width, texture points to the texture above.

It seems to render one frame then crash, I see no texture either, any ideas?
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

The crash must be caused by some other error in your program, but the texture not showing has to do with the CPU cache:

http://www.goop.org/psp/cache-howto.html

You need to writeback the cache after the conversion to make sure the data is in RAM, so the GPU reads the proper values.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Post Reply