diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-16 10:42:08 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-16 10:42:08 -0700 |
commit | 86fe72e8bfdcf5e6518c7e615ce599d1c6c491dd (patch) | |
tree | 53e56b4bb071578fbe409e3e21383dbb8a4df3f6 /src | |
parent | 9ca5fc4f2af23e78e8f44e89b5024588d0f57cf8 (diff) | |
parent | c2ace4f8473ca8851be15d1f49f3f8bc2bb76ce5 (diff) |
Merge branch 'antialiasing' of github.com:wsmind/emscripten into incoming
Conflicts:
AUTHORS
Diffstat (limited to 'src')
-rw-r--r-- | src/library_browser.js | 20 | ||||
-rw-r--r-- | src/library_egl.js | 7 | ||||
-rw-r--r-- | src/library_glfw.js | 5 | ||||
-rw-r--r-- | src/library_glut.js | 11 | ||||
-rw-r--r-- | src/library_sdl.js | 45 |
5 files changed, 75 insertions, 13 deletions
diff --git a/src/library_browser.js b/src/library_browser.js index dd60a581..59d2945e 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -225,7 +225,7 @@ mergeInto(LibraryManager.library, { } }, - createContext: function(canvas, useWebGL, setInModule) { + createContext: function(canvas, useWebGL, setInModule, webGLContextAttributes) { #if !USE_TYPED_ARRAYS if (useWebGL) { Module.print('(USE_TYPED_ARRAYS needs to be enabled for WebGL)'); @@ -235,12 +235,22 @@ mergeInto(LibraryManager.library, { var ctx; try { if (useWebGL) { - ctx = canvas.getContext('experimental-webgl', { + var contextAttributes = { + antialias: false, + alpha: false + }; + + if (webGLContextAttributes) { + for (var attribute in webGLContextAttributes) { + contextAttributes[attribute] = webGLContextAttributes[attribute]; + } + } + #if GL_TESTING - preserveDrawingBuffer: true, + contextAttributes.preserveDrawingBuffer = true; #endif - alpha: false - }); + + ctx = canvas.getContext('experimental-webgl', contextAttributes); } else { ctx = canvas.getContext('2d'); } diff --git a/src/library_egl.js b/src/library_egl.js index ff912ed2..c25dc8ef 100644 --- a/src/library_egl.js +++ b/src/library_egl.js @@ -170,10 +170,10 @@ var LibraryEGL = { {{{ makeSetValue('value', '0', '0x3038' /* EGL_NONE */, 'i32') }}}; return 1; case 0x3031: // EGL_SAMPLES - {{{ makeSetValue('value', '0', '0' /* No multisampling. */, 'i32') }}}; + {{{ makeSetValue('value', '0', '4' /* 2x2 Multisampling */, 'i32') }}}; return 1; case 0x3032: // EGL_SAMPLE_BUFFERS - {{{ makeSetValue('value', '0', '0' /* No multisampling. */, 'i32') }}}; + {{{ makeSetValue('value', '0', '1' /* Multisampling enabled */, 'i32') }}}; return 1; case 0x3033: // EGL_SURFACE_TYPE {{{ makeSetValue('value', '0', '0x0004' /* EGL_WINDOW_BIT */, 'i32') }}}; @@ -250,7 +250,7 @@ var LibraryEGL = { return 1; /* Magic ID for Emscripten 'default surface' */ }, - eglCreateContext__deps: ['glutCreateWindow', '$GL'], + eglCreateContext__deps: ['glutInitDisplayMode', 'glutCreateWindow', '$GL'], // EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list); eglCreateContext: function(display, config, hmm, contextAttribs) { @@ -259,6 +259,7 @@ var LibraryEGL = { return 0; } + _glutInitDisplayMode(0x92 /* GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE */); EGL.windowID = _glutCreateWindow(); if (EGL.windowID != 0) { EGL.setErrorCode(0x3000 /* EGL_SUCCESS */); diff --git a/src/library_glfw.js b/src/library_glfw.js index 5e76071f..b0519e39 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -354,7 +354,10 @@ var LibraryGLFW = { throw "Invalid glfwOpenWindow mode."; } - Module.ctx = Browser.createContext(Module['canvas'], true, true); + var contextAttributes = { + antialias: (GLFW.params[0x00020013] > 1) //GLFW_FSAA_SAMPLES + } + Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes); return 1; //GL_TRUE }, diff --git a/src/library_glut.js b/src/library_glut.js index 2321486a..722ea85c 100644 --- a/src/library_glut.js +++ b/src/library_glut.js @@ -16,6 +16,7 @@ var LibraryGLUT = { modifiers: 0, initWindowWidth: 256, initWindowHeight: 256, + initDisplayMode: 0x0000 /*GLUT_RGBA*/ | 0x0002 /*GLUT_DOUBLE*/ | 0x0010 /*GLUT_DEPTH*/, // Set when going fullscreen windowX: 0, windowY: 0, @@ -425,7 +426,10 @@ var LibraryGLUT = { glutCreateWindow__deps: ['$Browser'], glutCreateWindow: function(name) { - Module.ctx = Browser.createContext(Module['canvas'], true, true); + var contextAttributes = { + antialias: ((GLUT.initDisplayMode & 0x0080 /*GLUT_MULTISAMPLE*/) != 0) + }; + Module.ctx = Browser.createContext(Module['canvas'], true, true, contextAttributes); return Module.ctx ? 1 /* a new GLUT window ID for the created context */ : 0 /* failure */; }, @@ -464,7 +468,10 @@ var LibraryGLUT = { GLUT.requestFullScreen(); }, - glutInitDisplayMode: function(mode) {}, + glutInitDisplayMode: function(mode) { + GLUT.initDisplayMode = mode; + }, + glutSwapBuffers: function() {}, glutPostRedisplay: function() { diff --git a/src/library_sdl.js b/src/library_sdl.js index e64f117f..a0689343 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -43,6 +43,29 @@ var LibrarySDL = { 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 + // all possible GL attributes, with their default value + glAttributes: { + 0: 3, /* SDL_GL_RED_SIZE */ + 1: 3, /* SDL_GL_GREEN_SIZE */ + 2: 2, /* SDL_GL_BLUE_SIZE */ + 3: 0, /* SDL_GL_ALPHA_SIZE */ + 4: 0, /* SDL_GL_BUFFER_SIZE */ + 5: 1, /* SDL_GL_DOUBLEBUFFER */ + 6: 16, /* SDL_GL_DEPTH_SIZE */ + 7: 0, /* SDL_GL_STENCIL_SIZE */ + 8: 0, /* SDL_GL_ACCUM_RED_SIZE */ + 9: 0, /* SDL_GL_ACCUM_GREEN_SIZE */ + 10: 0, /* SDL_GL_ACCUM_BLUE_SIZE */ + 11: 0, /* SDL_GL_ACCUM_ALPHA_SIZE */ + 12: 0, /* SDL_GL_STEREO */ + 13: 0, /* SDL_GL_MULTISAMPLEBUFFERS */ + 14: 0, /* SDL_GL_MULTISAMPLESAMPLES */ + 15: 1, /* SDL_GL_ACCELERATED_VISUAL */ + 16: 0, /* SDL_GL_RETAINED_BACKING */ + 17: 0, /* SDL_GL_CONTEXT_MAJOR_VERSION */ + 18: 0 /* SDL_GL_CONTEXT_MINOR_VERSION */ + }, + keyboardState: null, keyboardMap: {}, @@ -229,7 +252,11 @@ var LibrarySDL = { } else { canvas = Module['canvas']; } - var ctx = Browser.createContext(canvas, useWebGL, usePageCanvas); + + var webGLContextAttributes = { + antialias: ((SDL.glAttributes[13 /*SDL_GL_MULTISAMPLEBUFFERS*/] != 0) && (SDL.glAttributes[14 /*SDL_GL_MULTISAMPLESAMPLES*/] > 1)) + }; + var ctx = Browser.createContext(canvas, useWebGL, usePageCanvas, webGLContextAttributes); SDL.surfaces[surf] = { width: width, height: height, @@ -2240,7 +2267,21 @@ var LibrarySDL = { // GL SDL_GL_SetAttribute: function(attr, value) { - console.log('TODO: SDL_GL_SetAttribute'); + if (!(attr in SDL.glAttributes)) { + abort('Unknown SDL GL attribute (' + attr + '). Please check if your SDL version is supported.'); + } + + SDL.glAttributes[attr] = value; + }, + + SDL_GL_GetAttribute: function(attr, value) { + if (!(attr in SDL.glAttributes)) { + abort('Unknown SDL GL attribute (' + attr + '). Please check if your SDL version is supported.'); + } + + if (value) {{{ makeSetValue('value', '0', 'SDL.glAttributes[attr]', 'i32') }}}; + + return 0; }, SDL_GL_GetProcAddress__deps: ['emscripten_GetProcAddress'], |