 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
GORETHRASHER
Joined: 10 Sep 2008 Posts: 12
|
Posted: Thu Sep 18, 2008 3:31 am Post subject: Trouble understanding sceGuTexImage() |
|
|
| Code: | 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: | int j = 0;
for (i=0; i < (int)width * (int)height; i++)
{
fread(&rgb, sizeof(rgb), 1, l_file);
l_texture[j+0] = rgb.rgbtRed; // Red component
l_texture[j+1] = rgb.rgbtGreen; // Green component
l_texture[j+2] = rgb.rgbtBlue; // Blue component
j += 3; // Go to the next position
} |
Which sceGuTexMode and sceGuTexImage calls do I need to get it rendering properly? |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Thu Sep 18, 2008 6:22 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
GORETHRASHER
Joined: 10 Sep 2008 Posts: 12
|
Posted: Thu Sep 18, 2008 11:44 am Post subject: |
|
|
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: |
int size = width * height * 2; //Using GU_PSM_4444
l_texture = (BYTE *) malloc(size); //Assign memory
memset(l_texture, 0, size); //Clear the memory
//... check memory ...
char a,b;
for (i=0; i < width * height; i++)
{
fread(&rgb, sizeof(rgb), 1, l_file);
//We have to convert a 24bit 888 image to a 16bit 4444(RGBA) image
a = (rgb.rgbtRed/255.0f) * 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 = (rgb.rgbtGreen/255.0f) * 0xF; //do this again to get 4 bit number for green
a = a | b; //OR the two numbers together
l_texture[j+0] = a; // Red and Green component
a = (rgb.rgbtBlue/255.0f) * 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[j+1] = a; // Green and Alpha component
j += 2; // Go to the next position
} |
Later on I try to use it
| Code: | sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuTexImage(0,image_size,image_size,buffer_width,texture); |
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? |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Thu Sep 18, 2008 10:52 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
|
|
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
|