void Texture::load(std::string filename) { uint8 *data; file_t fd = fs_open(filename.c_str(), O_RDONLY); data = new uint8[fs_total(fd)]; fs_read(fd, data, fs_total(fd)); fs_close(fd); memcpy(&header, data, sizeof(HeaderStruct)); assert_msg(Texture::formatTag.compare(header.formatTag) == 0, "Wrong texture format OR version"); /* Read texture */ uint16 *tdata = new uint16[header.byteCount]; memcpy(tdata, &data[0x18], header.byteCount); int pvrfmt = -1; if(header.format == KOS_IMG_FMT_ARGB1555) pvrfmt = PVR_TXRFMT_ARGB1555; else if(header.format == KOS_IMG_FMT_ARGB4444) pvrfmt = PVR_TXRFMT_ARGB4444; assert_msg(pvrfmt != -1, "Cannot determine PVR texture format"); sys->debugLog(" -> size %lu*%lu, KOS format %lu, pvr format %i, byteCount %08lx\n", header.width, header.height, header.format, pvrfmt, header.byteCount); texture = plx_txr_canvas(header.width, header.height, pvrfmt); pvr_txr_load_ex(tdata, texture->ptr, texture->w, texture->h, PVR_TXRLOAD_16BPP); delete[] tdata; delete[] data; }
static void init_effect (void *params) { pvr_mem_print_list (); // pvr_mem_reset (); warp_texture[0] = pvr_mem_malloc (1024 * 512 * 2); warp_texture[1] = pvr_mem_malloc (1024 * 512 * 2); memset (warp_texture[0], 0, 1024 * 512 * 2); memset (warp_texture[1], 0, 1024 * 512 * 2); if (cooltmp) { cooling_texture = pvr_mem_malloc (COOL_X * COOL_Y * 2); pvr_txr_load_ex (cooltmp, cooling_texture, COOL_X, COOL_Y, PVR_TXRLOAD_16BPP); free (cooltmp); cooltmp = 0; } flame_texture = pvr_mem_malloc (256 * 256 * 2); png_to_texture ("/rd/flametex.png", flame_texture, PNG_NO_ALPHA); backdrop_texture = pvr_mem_malloc (512 * 256 * 2); png_to_texture ("/rd/backdrop.png", backdrop_texture, PNG_NO_ALPHA); //printf ("memory free: %d bytes\n", pvr_mem_available ()); }
/* Load a texture from a 2D image */ void glTexImage2D(GLenum target, GLint level, GLint internal_fmt, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) { pvr_ptr_t txr; assert_msg(border == 0 && level == 0, "Borders and levels not supported."); assert_msg((internal_fmt & ~1) == (format & ~1), "Pixel conversion not supported."); /* Allocate space for it */ txr = pvr_mem_malloc(width * height * 2); /* Load the texture data */ if ((internal_fmt & 1) != (format & 1)) pvr_txr_load_ex((GLvoid *)pixels, txr, width, height, PVR_TXRLOAD_16BPP); else pvr_txr_load((GLvoid *)pixels, txr, width * height * 2); /* Store texture state in context */ gl_cur_texture->txr.width = width; gl_cur_texture->txr.height = height; gl_cur_texture->txr.format = internal_fmt; gl_cur_texture->txr.base = txr; gl_pbuf_submitted = GL_FALSE; }
void fakephong_highlight_texture (pvr_ptr_t highlight, unsigned int xsize, unsigned int ysize, float hardness) { uint8 *tmphilight; unsigned int x, y; float norm[3] = {0.0, 0.0, 1.0}; const float xscale = (float) (xsize - 1) / 2.0f; const float yscale = (float) (ysize - 1) / 2.0f; tmphilight = malloc (xsize * ysize); /* We need a way to map 2D texture coordinates to points on a unit hemisphere, such that interpolating linearly along the texture approximates travelling smoothly along a great circle around the hemisphere. Not sure how best to do this. Maybe a parabolic texture? Using x, y coords unaltered and choosing z on the surface of the sphere. Only the circular part of the texture is used. */ for (y = 0; y < ysize; y++) for (x = 0; x < xsize; x++) { float reflection[3]; float dot; reflection[0] = (x - xscale) / xscale; reflection[1] = (y - yscale) / yscale; reflection[2] = fsqrt (1.0 - reflection[0] * reflection[0] - reflection[1] * reflection[1]); dot = vec_dot (reflection, norm); tmphilight[y * ysize + x] = 255.0 * powf (dot, hardness); } assert (highlight != 0); pvr_txr_load_ex (tmphilight, highlight, xsize, ysize, PVR_TXRLOAD_8BPP); free (tmphilight); }
void Font::load(std::string filename) { uint8 *data; file_t fd = fs_open(filename.c_str(), O_RDONLY); data = new uint8[fs_total(fd)]; fs_read(fd, data, fs_total(fd)); fs_close(fd); uint32 rofs; memcpy(&header, data, sizeof(HeaderStruct)); assert_msg(Font::formatTag.compare(header.formatTag) == 0, "Wrong font format OR version"); /* Read characters */ rofs = header.characterDataOffset; memcpy(&characterList.characterCount, &data[rofs], 4); rofs += 4; characterList.characters = new CharacterDataStruct[characterList.characterCount]; memcpy(characterList.characters, &data[rofs], (sizeof(CharacterDataStruct) * characterList.characterCount)); /* Read font texture */ rofs = header.fontTextureOffset; int w = 0, h = 0, fmt = 0, byte_count = 0; memcpy(&w, &data[rofs], 4); memcpy(&h, &data[rofs + 0x4], 4); memcpy(&fmt, &data[rofs + 0x8], 4); memcpy(&byte_count, &data[rofs + 0xC], 4); uint32 *tdata = new uint32[byte_count]; memcpy(tdata, &data[rofs + 0x10], byte_count); texture = plx_txr_canvas(w, h, PVR_TXRFMT_ARGB4444); pvr_txr_load_ex(tdata, texture->ptr, texture->w, texture->h, PVR_TXRLOAD_16BPP); delete[] tdata; delete[] data; }