diff options
-rw-r--r-- | src/library_sdl.js | 9 | ||||
-rw-r--r-- | tests/sdl_ogl.c | 4 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index efcb377a..c1935e5b 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -701,15 +701,20 @@ var LibrarySDL = { // SDL_Image + IMG_Load__deps: ['SDL_LockSurface'], IMG_Load: function(filename) { - // XXX Image load by default creates HWSURFACE, so you must call LockSurface to access - // pixel data from C++! filename = FS.standardizePath(Pointer_stringify(filename)); var raw = preloadedImages[filename]; assert(raw, 'Cannot find preloaded image ' + filename); var surf = SDL.makeSurface(raw.width, raw.height, 0, false, 'load:' + filename); var surfData = SDL.surfaces[surf]; surfData.ctx.drawImage(raw, 0, 0, raw.width, raw.height, 0, 0, raw.width, raw.height); + // XXX SDL does not specify that loaded images must have available pixel data, in fact + // there are cases where you just want to blit them, so you just need the hardware + // accelerated version. However, code everywhere seems to assume that the pixels + // are in fact available, so we retrieve it here. This does add overhead though. + _SDL_LockSurface(surf); + surfData.locked = 0; // The surface is not actually locked in this hack return surf; }, SDL_LoadBMP: 'IMG_Load', diff --git a/tests/sdl_ogl.c b/tests/sdl_ogl.c index c423a16e..b7dd29e1 100644 --- a/tests/sdl_ogl.c +++ b/tests/sdl_ogl.c @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - SDL_LockSurface(surface); + //SDL_LockSurface(surface); // Add some greyness memset(surface->pixels, 0x66, surface->w*surface->h); @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels ); - SDL_UnlockSurface(surface); + //SDL_UnlockSurface(surface); } else { printf("SDL could not load image.bmp: %s\n", SDL_GetError()); |