aboutsummaryrefslogtreecommitdiff
path: root/src/library_sdl.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library_sdl.js')
-rw-r--r--src/library_sdl.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 48e45f27..662620d6 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -28,6 +28,9 @@ var LibrarySDL = {
mixerNumChannels: 2,
mixerChunkSize: 1024,
+ GL: false, // Set to true if we call SDL_SetVideoMode with SDL_OPENGL, and if so, we do not create 2D canvases&contexts for blitting
+ // Note that images loaded before SDL_SetVideoMode will not get this optimization
+
keyboardState: null,
shiftKey: false,
ctrlKey: false,
@@ -263,6 +266,7 @@ var LibrarySDL = {
// Decide if we want to use WebGL or not
var useWebGL = (flags & 0x04000000) != 0; // SDL_OPENGL
+ SDL.GL = SDL.GL || useWebGL;
var canvas;
if (!usePageCanvas) {
canvas = document.createElement('canvas');
@@ -695,6 +699,8 @@ var LibrarySDL = {
// Copy data from the C++-accessible storage to the canvas backing
SDL_UnlockSurface: function(surf) {
+ assert(!SDL.GL); // in GL mode we do not keep around 2D canvases and contexts
+
var surfData = SDL.surfaces[surf];
surfData.locked--;
@@ -977,9 +983,13 @@ var LibrarySDL = {
}
var raw = Module["preloadedImages"][filename];
if (!raw) {
+ if (raw === null) Module.printErr('Trying to reuse preloaded image, but freePreloadedMediaOnUse is set!');
Runtime.warnOnce('Cannot find preloaded image ' + filename);
return 0;
}
+ if (Module['freePreloadedMediaOnUse']) {
+ Module["preloadedImages"][filename] = null;
+ }
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);
@@ -989,6 +999,10 @@ var LibrarySDL = {
// are in fact available, so we retrieve it here. This does add overhead though.
_SDL_LockSurface(surf);
surfData.locked--; // The surface is not actually locked in this hack
+ if (SDL.GL) {
+ // After getting the pixel data, we can free the canvas and context if we do not need to do 2D canvas blitting
+ surfData.canvas = surfData.ctx = null;
+ }
return surf;
},
SDL_LoadBMP: 'IMG_Load',
@@ -1110,9 +1124,13 @@ var LibrarySDL = {
filename = FS.standardizePath(Pointer_stringify(filename));
var raw = Module["preloadedAudios"][filename];
if (!raw) {
+ if (raw === null) Module.printErr('Trying to reuse preloaded audio, but freePreloadedMediaOnUse is set!');
Runtime.warnOnce('Cannot find preloaded audio ' + filename);
return 0;
}
+ if (Module['freePreloadedMediaOnUse']) {
+ Module["preloadedAudios"][filename] = null;
+ }
var id = SDL.audios.length;
SDL.audios.push({
source: filename,