Need help with textures

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

Moderators: cheriff, TyRaNiD

Post Reply
bumper
Posts: 10
Joined: Thu Oct 06, 2005 5:39 am

Need help with textures

Post by bumper »

Hi,

I am playing around with the pspsdk and I would like to replace the texture of the cube sample with a 32-bit one.

So i removed the logo.o in the Makefile and I created a 32x32x32-bit texture in the code, plus I modified few lines to replace the 64x64 4444 texture with 32x32 8888 texture.

My texture is totally white but at the screen I have strange black lines on it.

I cannot show you a screenshot but there is several black lines on the white texture. With the 32x32 texture, they are strangely located from 0px to 16px or from 16px to 32px.

I tried with a 256x256 texture and the black lines are only present at the top of the texture.

It looks like some data have been written in the texture memory area but that is not the case.

Here are the code (its compiled with c++):

Code: Select all

static unsigned short __attribute__((aligned(16))) pixels[32*32*4];

Code: Select all

unsigned char *pData = (unsigned char *)pixels;

for &#40;int y = 0 ; y < 32 ; ++y&#41;
&#123;
	for &#40;int x = 0 ; x < 32 ; ++x&#41;
	&#123;
		*&#40;pData++&#41; = 255;
		*&#40;pData++&#41; = 255;
		*&#40;pData++&#41; = 255;
		*&#40;pData++&#41; = 255;
	&#125;
&#125;

Code: Select all

sceGuTexMode&#40;GU_PSM_8888, 0, 0, 0&#41;;
sceGuTexImage&#40;0,32, 32, 32, pixels&#41;;
sceGuTexFunc&#40;GU_TFX_REPLACE, GU_TCC_RGB&#41;;
1) Any idea about my corrupted texture (black lines) ?

2) Another question not related to the previous one, can I use malloc and free with the PSPSDK ? I noted that there is no dynamic allocation at all in the samples. I know that there is reserved memory area, where can I find info about that ?

Thanks in advance for any help
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Re: Need help with textures

Post by jimparis »

bumper wrote:1) Any idea about my corrupted texture (black lines) ?
Flush the data cache. sceKernelDcacheWritebackAll()
2) Another question not related to the previous one, can I use malloc and free with the PSPSDK ?
Yes.
bumper
Posts: 10
Joined: Thu Oct 06, 2005 5:39 am

Post by bumper »

I tried sceKernelDcacheWritebackAll() and there is no change.

Something else, when I launch the demo, some black lines on the texture (but not all) progressively disappear after 1 or 2 seconds :S
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Paste your full code at rafb.net/paste
bumper
Posts: 10
Joined: Thu Oct 06, 2005 5:39 am

Post by bumper »

jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

I also saw the black lines. I added sceKernelDcacheWritebackAll() at line 143 (before "for(;;)") and they went away.
bumper
Posts: 10
Joined: Thu Oct 06, 2005 5:39 am

Post by bumper »

Thanks Jim!

I tried to put sceKernelDcacheWritebackAll() just after SetupCallbacks like the envmap sample and at that place it did nothing.

Now it works great :)

btw I do not understand what does sceKernelDcacheWritebackAll(), could you please explain me what is the data cache and what lines are affected by that call ?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

CPUs have a small cache of fast on-board memory that is used to avoid accessing slower main memory when possible. The CPU takes care of writing that cache back to main memory at some unknown later time. The GU doesn't know about this cache and accesses the main memory directly, so anytime you want to put something in memory and have the GU access it, you need to tell the CPU to make sure that the contents of the cache are written back to main memory first.
bumper
Posts: 10
Joined: Thu Oct 06, 2005 5:39 am

Post by bumper »

Thx again :)
Post Reply