void load_texture(C3D_Tex *tex, const u8 *img, const u32 img_size) { unsigned int width, height; u8* image; lodepng_decode32(&image, &width, &height, img, img_size); u8 *gpusrc = (u8 *) linearAlloc(width * height * 4); // lodepng outputs big endian rgba so we need to convert convert_endianess(gpusrc, image, width * height); // ensure data is in physical ram GSPGPU_FlushDataCache(gpusrc, width * height * 4); // Load the texture and bind it to the first texture unit C3D_TexInit(tex, width, height, GPU_RGBA8); // Convert image to 3DS tiled texture format C3D_SyncDisplayTransfer((u32*)gpusrc, GX_BUFFER_DIM(width, height), (u32*) tex->data, GX_BUFFER_DIM(width, height), TEXTURE_TRANSFER_FLAGS); C3D_TexSetFilter(tex, GPU_LINEAR, GPU_NEAREST); free(image); linearFree(gpusrc); }
void Sprite::render() { if (dirtyPixels) { dirtyPixels = false; GSPGPU_FlushDataCache(pixels, w * h * format.bytesPerPixel); C3D_SyncDisplayTransfer((u32*)pixels, GX_BUFFER_DIM(w, h), (u32*)texture.data, GX_BUFFER_DIM(w, h), TEXTURE_TRANSFER_FLAGS); // gspWaitForPPF(); } C3D_TexBind(0, &texture); C3D_BufInfo *bufInfo = C3D_GetBufInfo(); BufInfo_Init(bufInfo); BufInfo_Add(bufInfo, vertices, sizeof(vertex), 2, 0x10); C3D_DrawArrays(GPU_TRIANGLE_STRIP, 0, 4); }