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.js47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 07a618a3..eaa2b5bb 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -1314,20 +1314,14 @@ var LibrarySDL = {
Module['canvas'].addEventListener(event, SDL.receiveEvent, true);
});
+ var canvas = Module['canvas'];
+
// (0,0) means 'use fullscreen' in native; in Emscripten, use the current canvas size.
if (width == 0 && height == 0) {
- var canvas = Module['canvas'];
width = canvas.width;
height = canvas.height;
}
- Browser.setCanvasSize(width, height, true);
- // Free the old surface first.
- if (SDL.screen) {
- SDL.freeSurface(SDL.screen);
- assert(!SDL.screen);
- }
- SDL.screen = SDL.makeSurface(width, height, flags, true, 'screen');
if (!SDL.addedResizeListener) {
SDL.addedResizeListener = true;
Browser.resizeListeners.push(function(w, h) {
@@ -1338,6 +1332,21 @@ var LibrarySDL = {
});
});
}
+
+ if (width !== canvas.width || height !== canvas.height) {
+ Browser.setCanvasSize(width, height);
+ }
+
+ // Free the old surface first if there is one
+ if (SDL.screen) {
+ SDL.freeSurface(SDL.screen);
+ assert(!SDL.screen);
+ }
+
+ if (SDL.GL) flags = flags | 0x04000000; // SDL_OPENGL - if we are using GL, then later calls to SetVideoMode may not mention GL, but we do need it. Once in GL mode, we never leave it.
+
+ SDL.screen = SDL.makeSurface(width, height, flags, true, 'screen');
+
return SDL.screen;
},
@@ -1946,8 +1955,10 @@ var LibrarySDL = {
} else {
var imageData = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height);
if (raw.bpp == 4) {
+ // rgba
imageData.data.set({{{ makeHEAPView('U8', 'raw.data', 'raw.data+raw.size') }}});
} else if (raw.bpp == 3) {
+ // rgb
var pixels = raw.size/3;
var data = imageData.data;
var sourcePtr = raw.data;
@@ -1958,6 +1969,19 @@ var LibrarySDL = {
data[destPtr++] = {{{ makeGetValue('sourcePtr++', 0, 'i8', null, 1) }}};
data[destPtr++] = 255;
}
+ } else if (raw.bpp == 1) {
+ // grayscale
+ var pixels = raw.size;
+ var data = imageData.data;
+ var sourcePtr = raw.data;
+ var destPtr = 0;
+ for (var i = 0; i < pixels; i++) {
+ var value = {{{ makeGetValue('sourcePtr++', 0, 'i8', null, 1) }}};
+ data[destPtr++] = value;
+ data[destPtr++] = value;
+ data[destPtr++] = value;
+ data[destPtr++] = 255;
+ }
} else {
Module.printErr('cannot handle bpp ' + raw.bpp);
return 0;
@@ -2883,7 +2907,12 @@ var LibrarySDL = {
return _emscripten_GetProcAddress(name_);
},
- SDL_GL_SwapBuffers: function() {},
+ SDL_GL_SwapBuffers: function() {
+#if PROXY_TO_WORKER
+ // postMainLoop is where the proxy code listens, to know when to proxy buffered render commands
+ if (Module['postMainLoop']) Module['postMainLoop']();
+#endif
+ },
// SDL 2