aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-07-15 11:07:17 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-07-15 11:07:17 -0700
commit743636c21107a0c2b45700f2d6245551fdb5bf19 (patch)
tree571db9533465d0300f9c218e39938169f1855501
parentb43e2dc67717a5decc3dc4cf31ab7650bf15cbd6 (diff)
when using SDL for GL, do not keep canvas and contexts for 2D blitting
-rw-r--r--src/library_sdl.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 73848502..df0274e9 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--;
@@ -989,6 +995,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',