diff options
author | Éloi Rivard <azmeuk@gmail.com> | 2013-03-15 13:02:33 +0100 |
---|---|---|
committer | Éloi Rivard <azmeuk@gmail.com> | 2013-04-04 11:17:36 +0200 |
commit | b4786e49d4ad395300ed0fffcfaedee75906f8d3 (patch) | |
tree | ce37986b7e970582f169af32dc63ecf0ab1c19d5 | |
parent | 37045ce20ef8f3767337d35e368645f13f8727e0 (diff) |
* OpenGL extensions.
-rw-r--r-- | AUTHORS | 6 | ||||
-rw-r--r-- | src/library_glfw.js | 64 | ||||
-rw-r--r-- | tests/glfw/glfwsample.c | 20 |
3 files changed, 57 insertions, 33 deletions
@@ -24,7 +24,7 @@ a license to everyone to use it as detailed in LICENSE.) * Pierre Renaux <pierre@talansoft.com> * Brian Anderson <banderson@mozilla.com> * Jon Bardin <diclophis@gmail.com> -* Jukka Jylänki <jujjyl@gmail.com> +* Jukka Jylänki <jujjyl@gmail.com> * Aleksander Guryanov <caiiiycuk@gmail.com> * Chad Austin <chad@chadaustin.me> (copyright owned by IMVU) * nandhp <nandhp@gmail.com> @@ -46,7 +46,7 @@ a license to everyone to use it as detailed in LICENSE.) * Anthony Liot <wolfviking0@yahoo.com> * Michael Riss <Michael.Riss@gmx.de> * Jasper St. Pierre <jstpierre@mecheye.net> -* Manuel Schölling <manuel.schoelling@gmx.de> +* Manuel Schölling <manuel.schoelling@gmx.de> * Bruce Mitchener, Jr. <bruce.mitchener@gmail.com> * Michael Bishop <mbtyke@gmail.com> * Roger Braun <roger@rogerbraun.net> @@ -56,3 +56,5 @@ a license to everyone to use it as detailed in LICENSE.) * Martin von Gagern <martin@von-gagern.net> * Ting-Yuan Huang <thuang@mozilla.com> * Felix H. Dahlke <fhd@ubercode.de> +* Éloi Rivard <azmeuk@gmail.com> + diff --git a/src/library_glfw.js b/src/library_glfw.js index 4746cf02..3dc032aa 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js @@ -6,17 +6,19 @@ * What it does: * - Creates a GL context. * - Manage keyboard and mouse events. + * - GL Extensions support. * * What it does not but should do: * - Transmit events when glfwPollEvents, glfwWaitEvents or glfwSwapBuffers is * called. Events callbacks are called as soon as event are received. - * - Correctly handle unicode characters + * - Correctly handle unicode characters. To be tested. * - Thread emulation. * - Joystick support. * - Image/Texture I/O support. - * - GL Extensions support. * - Video modes. * + * Authors: + * - Éloi Rivard <eloi.rivard@gmail.com> ******************************************************************************/ var LibraryGLFW = { @@ -112,13 +114,20 @@ var LibraryGLFW = { output += String.fromCharCode(value); return output; }, - - savePosition: function(event) { - /* TODO maybe loop here ala http://www.quirksmode.org/js/findpos.html */ - GLFW.lastX = event['clientX'] - Module['canvas'].offsetLeft; - GLFW.lastY = event['clientY'] - Module['canvas'].offsetTop; - }, + onKeyPress: function(event) { + //charCode is only available whith onKeyPress event + var char = GLFW.getUnicodeChar(event.charCode); + + if(event.charCode){ + var char = GLFW.getUnicodeChar(event.charCode); + if( char !== null && GLFW.charFunc ) { + event.preventDefault(); + Runtime.dynCall('vii', GLFW.charFunc, [event.charCode, 1]); + } + } + }, + onKeyChanged: function(event, status){ var key = GLFW.DOMToGLFWKeyCode(event.keyCode); if(key && GLFW.keyFunc) { @@ -135,17 +144,11 @@ var LibraryGLFW = { onKeyup: function(event) { GLFW.onKeyChanged(event, 0);//GLFW_RELEASE }, - - onKeyPress: function(event) { - var char = GLFW.getUnicodeChar(event.charCode); - Module.printErr(event.charCode + " - " + char); - if(event.charCode){ - var char = GLFW.getUnicodeChar(event.charCode); - if( char !== null && GLFW.charFunc ) { - event.preventDefault(); - Runtime.dynCall('vii', GLFW.charFunc, [event.charCode, status]); - } - } + + savePosition: function(event) { + /* TODO maybe loop here ala http://www.quirksmode.org/js/findpos.html */ + GLFW.lastX = event['clientX'] - Module['canvas'].offsetLeft; + GLFW.lastY = event['clientY'] - Module['canvas'].offsetTop; }, onMousemove: function(event) { @@ -477,18 +480,25 @@ var LibraryGLFW = { GLFW.initTime = Date.now()/1000 + time; }, - glfwSleep : function( time ) { throw "glfwSleep is not implemented yet."; }, + glfwSleep__deps: ['sleep'], + glfwSleep : function( time ) { + _sleep(time); + }, /* Extension support */ - glfwExtensionSupported : function( extension ) { return 1; /*throw "glfwExtensionSupported is not implemented yet.";*/ }, - glfwGetProcAddress : function( procname ) { return null; /*throw "glfwGetProcAddress is not implemented yet.";*/ }, + glfwExtensionSupported : function( extension ) { + return Module.ctx.getSupportedExtensions().indexOf(Pointer_stringify(extension)) > -1; + }, + + glfwGetProcAddress__deps: ['glfwGetProcAddress'], + glfwGetProcAddress : function( procname ) { + return _getProcAddress(procname); + }, glfwGetGLVersion : function( major, minor, rev ) { - //TODO: Find something better here. - Module.printErr("Fake GL version"); - setValue(major, 4, 'i32'); - setValue(minor, 2, 'i32'); - setValue(rev, 0, 'i32'); + setValue(major, 0, 'i32'); + setValue(minor, 0, 'i32'); + setValue(rev, 1, 'i32'); }, /* Threading support */ diff --git a/tests/glfw/glfwsample.c b/tests/glfw/glfwsample.c index 771537c5..3d9be100 100644 --- a/tests/glfw/glfwsample.c +++ b/tests/glfw/glfwsample.c @@ -67,8 +67,8 @@ void Init() glfwSetWindowSizeCallback(OnResize); glfwSetWindowRefreshCallback(OnRefresh); glfwSetMouseWheelCallback(OnMouseWheel); - glfwSetMousePosCallback(OnMouseMove); - glfwSetMouseButtonCallback(OnMouseClick); + //glfwSetMousePosCallback(OnMouseMove); + //glfwSetMouseButtonCallback(OnMouseClick); // set the projection matrix to a normal frustum with a max depth of 50 glMatrixMode(GL_PROJECTION); @@ -289,14 +289,15 @@ char* GetParamName(int param){ default : return "Invalid param"; } } + void OnKeyPressed( int key, int action ){ const char* key_name = GetKeyName(key); if(key_name == 0) return; if(action == GLFW_PRESS) - printf("%s (%i) key is pressed\n", key_name, key); + printf("'%s' (%i) key is pressed\n", key_name, key); if(action == GLFW_RELEASE) - printf("%s (%i) key is released\n", key_name, key); + printf("'%s' (%i) key is released\n", key_name, key); if(action == GLFW_RELEASE && key == GLFW_KEY_ENTER) PullInfo(); } @@ -331,6 +332,7 @@ void OnMouseWheel( int pos ){ void PullInfo(){ printf("================================================================================\n"); + int major, minor, rev; glfwGetVersion(&major, &minor, &rev); printf("GLFW version is %i.%i.%i\n", major, minor, rev); @@ -371,5 +373,15 @@ void PullInfo(){ for(i = 0; i<nb_params; i++) printf(" - %-27s : %i\n", GetParamName(params[i]), glfwGetWindowParam(params[i])); + const char* extension = "MOZ_WEBGL_compressed_texture_s3tc"; + printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); + + extension = "GL_EXT_framebuffer_object"; + printf("'%s' extension is %s.\n", extension, glfwExtensionSupported(extension) ? "supported" : "not supported"); + + printf("Sleeping 1 sec...\n"); + glfwSleep(1); + printf("...Done.\n"); + printf("================================================================================\n"); } |