Skip to content

Commit f95c7b9

Browse files
committed
Micro-optimize WebGL context activation. Saves -18 bytes (0.12%)
1 parent 519f3ab commit f95c7b9

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/library_gl.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,25 +847,19 @@ var LibraryGL = {
847847
},
848848

849849
makeContextCurrent: function(contextHandle) {
850-
// Deactivating current context?
851-
if (!contextHandle) {
852-
GLctx = Module.ctx = GL.currentContext = null;
853-
return true;
854-
}
855-
var context = GL.contexts[contextHandle];
856-
if (!context) {
857850
#if GL_DEBUG
851+
if (contextHandle && !GL.contexts[contextHandle]) {
858852
#if USE_PTHREADS
859853
console.error('GL.makeContextCurrent() failed! WebGL context ' + contextHandle + ' does not exist, or was created on another thread!');
860854
#else
861855
console.error('GL.makeContextCurrent() failed! WebGL context ' + contextHandle + ' does not exist!');
862856
#endif
863-
#endif
864-
return false;
865857
}
866-
GLctx = Module.ctx = context.GLctx; // Active WebGL context object.
867-
GL.currentContext = context; // Active Emscripten GL layer context object.
868-
return true;
858+
#endif
859+
860+
GL.currentContext = GL.contexts[contextHandle]; // Active Emscripten GL layer context object.
861+
Module.ctx = GLctx = GL.currentContext && GL.currentContext.GLctx; // Active WebGL context object.
862+
return !(contextHandle && !GLctx);
869863
},
870864

871865
getContext: function(contextHandle) {

0 commit comments

Comments
 (0)