static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; SDL_Log("enter %s\n", __func__); glLoadTileSet(txdat->image, rect->w, rect->h, rect->w, rect->h, GL_RGBA, get_gltexture_size(rect->w), get_gltexture_size(rect->h), TEXGEN_OFF, 0, NULL, pixels); return 0; }
static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata; char *new_pixels = NULL; const int gl_w = get_gltexture_size(rect->w); const int gl_h = get_gltexture_size(rect->h); const int w = 1 << (3+gl_w); /* Texture sizes must be a power of 2. */ const int h = 1 << (3+gl_h); /* Texture sizes must be a power of 2. */ if (w != rect->w || h != rect->h) { /* Allocate a temporary surface and copy pixels into it while * enlarging the pitch. */ const char *src; char *dst; int new_pitch = 2 * w; int i; new_pixels = malloc(2 * w * h); if (!new_pixels) return SDL_ENOMEM; src = pixels; dst = new_pixels; for (i=0; i<rect->h; i++) { memcpy(dst, src, pitch); src += pitch; dst += new_pitch; } } glLoadTile(txdat->image, gl_w, gl_h, rect->w, rect->h, texture->format == SDL_PIXELFORMAT_ABGR1555 ? GL_RGBA : GL_RGB, TEXGEN_OFF, 0, NULL, new_pixels? new_pixels : pixels); if (new_pixels) free(new_pixels); return 0; }