From 158189f75d95713d9e27de2d7befdfc454065159 Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Thu, 9 Sep 2021 17:28:44 +0200 Subject: [PATCH 1/7] Update ofTrueTypeFont.cpp --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 3c815812b50..68e187036c6 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -614,7 +614,7 @@ bool ofTrueTypeFont::loadFont(string filename, int fontSize, bool bAntiAliased, //----------------------------------------------------------- ofTrueTypeFont::glyph ofTrueTypeFont::loadGlyph(uint32_t utf8) const{ glyph aGlyph; - auto err = FT_Load_Glyph( face.get(), FT_Get_Char_Index( face.get(), utf8 ), settings.antialiased ? FT_LOAD_FORCE_AUTOHINT : FT_LOAD_DEFAULT ); + auto err = FT_Load_Glyph( face.get(), FT_Get_Char_Index( face.get(), utf8 ), FT_LOAD_DEFAULT ); if(err){ ofLogError("ofTrueTypeFont") << "loadFont(): FT_Load_Glyph failed for utf8 code " << utf8 << ": FT_Error " << err; return aGlyph; From 9ad869b0464120a441cc0d4b0eae0f2cd479abe8 Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Fri, 8 Oct 2021 05:35:27 +0200 Subject: [PATCH 2/7] Update ofxAppEmscriptenWindow.cpp --- .../src/ofxAppEmscriptenWindow.cpp | 78 +++++++++++++++++-- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp index b17505f59b4..a1789ec6c98 100644 --- a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp +++ b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp @@ -70,10 +70,22 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ EGL_SAMPLE_BUFFERS, EGL_DONT_CARE, EGL_NONE }; + + // We'll try these alpha sizes in order ending with EGL_DONT_CARE if we don't get anything higher. + std::vector alphaPreference = {8, EGL_DONT_CARE}; + // Find the index for the value EGL_ALPHA_SIZE uses, so we can try a few different values till we get a successful config. + int attribListAlphaIndex = -1; + for(int i = 0; i < attribList.size(); i++){ + if( attribList[i] == EGL_ALPHA_SIZE ){ + attribListAlphaIndex = i+1; + break; + } + } + // We'll try these depth sizes in order ending with EGL_DONT_CARE if we don't get anything higher. std::vector depthPreference = {24, 16, EGL_DONT_CARE}; - + // Find the index for the value EGL_DEPTH_SIZE uses, so we can try a few different values till we get a successful config. int attribListDepthIndex = -1; for(int i = 0; i < attribList.size(); i++){ @@ -83,6 +95,18 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ } } + // We'll try these sample buffers in order ending with EGL_DONT_CARE if we don't get anything higher. + std::vector sampleBuffersPreference = {1, EGL_DONT_CARE}; + + // Find the index for the value EGL_SAMPLE_BUFFERS uses, so we can try a few different values till we get a successful config. + int attribListSampleBuffersIndex = -1; + for(int i = 0; i < attribList.size(); i++){ + if( attribList[i] == EGL_SAMPLE_BUFFERS ){ + attribListSampleBuffersIndex = i+1; + break; + } + } + // Get Display display = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); if ( display == EGL_NO_DISPLAY ){ @@ -102,6 +126,27 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ return; } + // Choose the config based on our attribute list + // Try higher EGL_ALPHA_SIZE first + for(int i = 0; i < alphaPreference.size(); i++){ + // Set EGL_ALPHA_SIZE + attribList[attribListAlphaIndex] = alphaPreference[i]; + + // Try out that depth value + if ( !eglChooseConfig(display, &attribList[0], &config, 1, &numConfigs) ){ + + // Finally fail like we did before if no preference works + if( alphaPreference[i] == EGL_DONT_CARE ){ + ofLogError() << "couldn't choose display"; + return; + } + + }else{ + // Got a good configuration. Stop searching. + break; + } + } + // Choose the config based on our attribute list // Try higher EGL_DEPTH_SIZE first for(int i = 0; i < depthPreference.size(); i++){ @@ -122,6 +167,27 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ break; } } + + // Choose the config based on our attribute list + // Try higher EGL_SAMPLE_BUFFERS first + for(int i = 0; i < sampleBuffersPreference.size(); i++){ + // Set EGL_SAMPLE_BUFFERS + attribList[attribListSampleBuffersIndex] = sampleBuffersPreference[i]; + + // Try out that depth value + if ( !eglChooseConfig(display, &attribList[0], &config, 1, &numConfigs) ){ + + // Finally fail like we did before if no preference works + if( sampleBuffersPreference[i] == EGL_DONT_CARE ){ + ofLogError() << "couldn't choose display"; + return; + } + + }else{ + // Got a good configuration. Stop searching. + break; + } + } // Create a surface surface = eglCreateWindowSurface(display, config, NULL, NULL); @@ -282,21 +348,19 @@ void ofxAppEmscriptenWindow::setWindowPosition(int x, int y){ } void ofxAppEmscriptenWindow::setWindowShape(int w, int h){ - emscripten_set_canvas_element_size(NULL,w,h); + emscripten_set_canvas_size(w,h); } - - glm::vec2 ofxAppEmscriptenWindow::getWindowPosition(){ return glm::vec2(0,0); } - glm::vec2 ofxAppEmscriptenWindow::getWindowSize(){ int width; int height; - emscripten_get_canvas_element_size(NULL, &width, &height); - return glm::vec2(width,height); + int isFullscreen; + emscripten_get_canvas_size(&width, &height, &isFullscreen); + return glm::vec3(width,height,isFullscreen); } glm::vec2 ofxAppEmscriptenWindow::getScreenSize(){ From 94a065cfa2b42953447b3fe24abc9da2048e0914 Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Fri, 8 Oct 2021 05:55:21 +0200 Subject: [PATCH 3/7] Update library_html5audio.js --- .../libs/html5audio/lib/emscripten/library_html5audio.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js index a984e36422e..3a4714b3be7 100644 --- a/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js +++ b/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js @@ -31,7 +31,10 @@ var LibraryHTML5Audio = { try { // Fix up for prefixing window.AudioContext = window.AudioContext || window.webkitAudioContext; - var context = new AudioContext(); + var context = new AudioContext({ + latencyHint: "interactive", + sampleRate: 44100 + }); // Fix issue with chrome autoplay policy document.addEventListener('mousedown', function cb(event) { From 8b4cbb652245b3fc89c96df11bfef77d4cae931d Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Sun, 10 Oct 2021 01:05:47 +0200 Subject: [PATCH 4/7] Update ofxAppEmscriptenWindow.cpp --- .../src/ofxAppEmscriptenWindow.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp index a1789ec6c98..219fee4d289 100644 --- a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp +++ b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp @@ -214,16 +214,16 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ _renderer = make_shared(this); ((ofGLProgrammableRenderer*)_renderer.get())->setup(2,0); - emscripten_set_keydown_callback(0,this,1,&keydown_cb); - emscripten_set_keyup_callback(0,this,1,&keyup_cb); - emscripten_set_mousedown_callback(0,this,1,&mousedown_cb); - emscripten_set_mouseup_callback(0,this,1,&mouseup_cb); - emscripten_set_mousemove_callback(0,this,1,&mousemoved_cb); + emscripten_set_keydown_callback("#canvas",this,1,&keydown_cb); + emscripten_set_keyup_callback("#canvas",this,1,&keyup_cb); + emscripten_set_mousedown_callback("#canvas",this,1,&mousedown_cb); + emscripten_set_mouseup_callback("#canvas",this,1,&mouseup_cb); + emscripten_set_mousemove_callback("#canvas",this,1,&mousemoved_cb); - emscripten_set_touchstart_callback(0,this,1,&touch_cb); - emscripten_set_touchend_callback(0,this,1,&touch_cb); - emscripten_set_touchmove_callback(0,this,1,&touch_cb); - emscripten_set_touchcancel_callback(0,this,1,&touch_cb); + emscripten_set_touchstart_callback("#canvas",this,1,&touch_cb); + emscripten_set_touchend_callback("#canvas",this,1,&touch_cb); + emscripten_set_touchmove_callback("#canvas",this,1,&touch_cb); + emscripten_set_touchcancel_callback("#canvas",this,1,&touch_cb); } void ofxAppEmscriptenWindow::loop(){ @@ -295,9 +295,9 @@ int ofxAppEmscriptenWindow::mouseup_cb(int eventType, const EmscriptenMouseEvent int ofxAppEmscriptenWindow::mousemoved_cb(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData){ if(ofGetMousePressed()){ - instance->events().notifyMouseDragged(mouseEvent->canvasX,mouseEvent->canvasY,0); + instance->events().notifyMouseDragged(mouseEvent->targetX,mouseEvent->targetY,0); }else{ - instance->events().notifyMouseMoved(mouseEvent->canvasX,mouseEvent->canvasY); + instance->events().notifyMouseMoved(mouseEvent->targetX,mouseEvent->targetY); } return 0; @@ -327,8 +327,8 @@ int ofxAppEmscriptenWindow::touch_cb(int eventType, const EmscriptenTouchEvent* ofTouchEventArgs touchArgs; touchArgs.type = touchArgsType; touchArgs.id = i; - touchArgs.x = e->touches[i].canvasX; - touchArgs.y = e->touches[i].canvasY; + touchArgs.x = e->touches[i].targetX; + touchArgs.y = e->touches[i].targetY; instance->events().notifyTouchEvent(touchArgs); } return 0; From 06cf73b15a1b186b8cc97a51fc1be15250248e23 Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Sun, 10 Oct 2021 10:06:30 +0200 Subject: [PATCH 5/7] Update ofTrueTypeFont.cpp --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 68e187036c6..12983426674 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -614,7 +614,12 @@ bool ofTrueTypeFont::loadFont(string filename, int fontSize, bool bAntiAliased, //----------------------------------------------------------- ofTrueTypeFont::glyph ofTrueTypeFont::loadGlyph(uint32_t utf8) const{ glyph aGlyph; - auto err = FT_Load_Glyph( face.get(), FT_Get_Char_Index( face.get(), utf8 ), FT_LOAD_DEFAULT ); + bool autoHint = settings.antialiased; + #ifdef OF_TARGET_EMSCRIPTEN + autoHint = false; + #endif + + auto err = FT_Load_Glyph( face.get(), FT_Get_Char_Index( face.get(), utf8 ), autoHint ? FT_LOAD_FORCE_AUTOHINT : FT_LOAD_DEFAULT ); if(err){ ofLogError("ofTrueTypeFont") << "loadFont(): FT_Load_Glyph failed for utf8 code " << utf8 << ": FT_Error " << err; return aGlyph; From e84001b234e911b43afd8710012fe19d22883a6d Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Sun, 10 Oct 2021 10:13:00 +0200 Subject: [PATCH 6/7] Update ofTrueTypeFont.cpp --- libs/openFrameworks/graphics/ofTrueTypeFont.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp index 12983426674..6bf071099e8 100644 --- a/libs/openFrameworks/graphics/ofTrueTypeFont.cpp +++ b/libs/openFrameworks/graphics/ofTrueTypeFont.cpp @@ -615,7 +615,7 @@ bool ofTrueTypeFont::loadFont(string filename, int fontSize, bool bAntiAliased, ofTrueTypeFont::glyph ofTrueTypeFont::loadGlyph(uint32_t utf8) const{ glyph aGlyph; bool autoHint = settings.antialiased; - #ifdef OF_TARGET_EMSCRIPTEN + #ifdef TARGET_EMSCRIPTEN autoHint = false; #endif From 7a9464da3bcafd54f17d592cb6e983f0cde7f3d4 Mon Sep 17 00:00:00 2001 From: Jonathan <41275844+Jonathhhan@users.noreply.github.com> Date: Tue, 12 Oct 2021 00:21:09 +0200 Subject: [PATCH 7/7] Update ofxAppEmscriptenWindow.cpp --- addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp index 219fee4d289..2c0b23a7753 100644 --- a/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp +++ b/addons/ofxEmscripten/src/ofxAppEmscriptenWindow.cpp @@ -58,7 +58,7 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ EGLint majorVersion; EGLint minorVersion; EGLConfig config; - EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; + EGLint contextAttribs[] = { EGL_CONTEXT_MAJOR_VERSION, 3, EGL_NONE, EGL_NONE }; std::vector attribList = { EGL_RED_SIZE, EGL_DONT_CARE, @@ -68,6 +68,7 @@ void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ EGL_DEPTH_SIZE, EGL_DONT_CARE, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_SAMPLE_BUFFERS, EGL_DONT_CARE, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, EGL_NONE };