diff --git a/samples/webgl/WasmOcctView.cpp b/samples/webgl/WasmOcctView.cpp
index 68a8b86bba..aa5e67228c 100644
--- a/samples/webgl/WasmOcctView.cpp
+++ b/samples/webgl/WasmOcctView.cpp
@@ -109,13 +109,13 @@ void WasmOcctView::initWindow()
{
myDevicePixelRatio = jsDevicePixelRatio();
myCanvasId = THE_CANVAS_ID;
- const char* aTargetId = !myCanvasId.IsEmpty() ? myCanvasId.ToCString() : NULL;
+ const char* aTargetId = !myCanvasId.IsEmpty() ? myCanvasId.ToCString() : EMSCRIPTEN_EVENT_TARGET_WINDOW;
const EM_BOOL toUseCapture = EM_TRUE;
- emscripten_set_resize_callback (NULL, this, toUseCapture, onResizeCallback);
+ emscripten_set_resize_callback (EMSCRIPTEN_EVENT_TARGET_WINDOW, this, toUseCapture, onResizeCallback);
- emscripten_set_mousedown_callback (NULL, this, toUseCapture, onMouseCallback);
- emscripten_set_mouseup_callback (NULL, this, toUseCapture, onMouseCallback);
- emscripten_set_mousemove_callback (NULL, this, toUseCapture, onMouseCallback);
+ emscripten_set_mousedown_callback (aTargetId, this, toUseCapture, onMouseCallback);
+ emscripten_set_mouseup_callback (aTargetId, this, toUseCapture, onMouseCallback);
+ emscripten_set_mousemove_callback (aTargetId, this, toUseCapture, onMouseCallback);
emscripten_set_dblclick_callback (aTargetId, this, toUseCapture, onMouseCallback);
emscripten_set_click_callback (aTargetId, this, toUseCapture, onMouseCallback);
emscripten_set_mouseenter_callback (aTargetId, this, toUseCapture, onMouseCallback);
@@ -127,9 +127,9 @@ void WasmOcctView::initWindow()
emscripten_set_touchmove_callback (aTargetId, this, toUseCapture, onTouchCallback);
emscripten_set_touchcancel_callback(aTargetId, this, toUseCapture, onTouchCallback);
- //emscripten_set_keypress_callback (NULL, this, toUseCapture, onKeyCallback);
- emscripten_set_keydown_callback (NULL, this, toUseCapture, onKeyDownCallback);
- emscripten_set_keyup_callback (NULL, this, toUseCapture, onKeyUpCallback);
+ //emscripten_set_keypress_callback (EMSCRIPTEN_EVENT_TARGET_WINDOW, this, toUseCapture, onKeyCallback);
+ emscripten_set_keydown_callback (EMSCRIPTEN_EVENT_TARGET_WINDOW, this, toUseCapture, onKeyDownCallback);
+ emscripten_set_keyup_callback (EMSCRIPTEN_EVENT_TARGET_WINDOW, this, toUseCapture, onKeyUpCallback);
}
// ================================================================
@@ -396,7 +396,7 @@ EM_BOOL WasmOcctView::onMouseEvent (int theEventType, const EmscriptenMouseEvent
Graphic3d_Vec2i aWinSize;
myView->Window()->Size (aWinSize.x(), aWinSize.y());
- const Graphic3d_Vec2i aNewPos = convertPointToBacking (Graphic3d_Vec2i (theEvent->canvasX, theEvent->canvasY));
+ const Graphic3d_Vec2i aNewPos = convertPointToBacking (Graphic3d_Vec2i (theEvent->targetX, theEvent->targetY));
Aspect_VKeyFlags aFlags = 0;
if (theEvent->ctrlKey == EM_TRUE) { aFlags |= Aspect_VKeyFlags_CTRL; }
if (theEvent->shiftKey == EM_TRUE) { aFlags |= Aspect_VKeyFlags_SHIFT; }
@@ -477,7 +477,7 @@ EM_BOOL WasmOcctView::onWheelEvent (int theEventType, const EmscriptenWheelEvent
Graphic3d_Vec2i aWinSize;
myView->Window()->Size (aWinSize.x(), aWinSize.y());
- const Graphic3d_Vec2i aNewPos = convertPointToBacking (Graphic3d_Vec2i (theEvent->mouse.canvasX, theEvent->mouse.canvasY));
+ const Graphic3d_Vec2i aNewPos = convertPointToBacking (Graphic3d_Vec2i (theEvent->mouse.targetX, theEvent->mouse.targetY));
if (aNewPos.x() < 0 || aNewPos.x() > aWinSize.x()
|| aNewPos.y() < 0 || aNewPos.y() > aWinSize.y())
{
diff --git a/samples/webgl/main.cpp b/samples/webgl/main.cpp
index 8f55322501..fd7b94dae7 100644
--- a/samples/webgl/main.cpp
+++ b/samples/webgl/main.cpp
@@ -19,6 +19,13 @@
//! Global viewer instance.
static WasmOcctView aViewer;
+//! Dummy main loop callback for a single shot.
+extern "C" void onMainLoop()
+{
+ // do nothing here - viewer updates are handled on demand
+ emscripten_cancel_main_loop();
+}
+
//! File data read event.
extern "C" void onFileDataRead (void* theOpaque, void* theBuffer, int theDataLen)
{
@@ -60,6 +67,10 @@ int main()
Handle(Message_PrinterSystemLog) aJSConsolePrinter = new Message_PrinterSystemLog ("webgl-sample", Message_Trace);
Message::DefaultMessenger()->AddPrinter (aJSConsolePrinter); // open JavaScript console within the Browser to see this output
Message::DefaultMessenger()->Send (TCollection_AsciiString("NbLogicalProcessors: ") + OSD_Parallel::NbLogicalProcessors(), Message_Trace);
+
+ // setup a dummy single-shot main loop callback just to shut up a useless Emscripten error message on calling eglSwapInterval()
+ emscripten_set_main_loop (onMainLoop, -1, 0);
+
aViewer.run();
Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
diff --git a/samples/webgl/occt-webgl-sample.html b/samples/webgl/occt-webgl-sample.html
index 80f7e6f4d8..efec7dba0e 100644
--- a/samples/webgl/occt-webgl-sample.html
+++ b/samples/webgl/occt-webgl-sample.html
@@ -69,6 +69,7 @@ var Module =
printErr: function(theText) {
//var anElement = document.getElementById('output');
//anElement.innerHTML += theText + "
";
+ console.warn(theText);
},
canvas: (function() {
var aCanvas = document.getElementById('canvas');
@@ -85,11 +86,12 @@ fileInput.onchange = function()
var aReader = new FileReader();
aReader.onload = function()
{
+ var aNameLenBytes = lengthBytesUTF8(aFile.name) + 1;
+ const aNameBuffer = Module._malloc(aNameLenBytes);
+ stringToUTF8(aFile.name, aNameBuffer, aNameLenBytes);
+
var aDataArray = new Uint8Array (aReader.result);
- var aNameArray = new Uint8Array (toUtf8Array (aFile.name));
const aDataBuffer = Module._malloc(aDataArray.length);
- const aNameBuffer = Module._malloc(aNameArray.length);
- Module.HEAPU8.set(aNameArray, aNameBuffer);
Module.HEAPU8.set(aDataArray, aDataBuffer);
Module.ccall('onFileDataRead', null, ['number', 'number', 'number'], [aNameBuffer, aDataBuffer, aDataArray.length]);
Module._free(aDataBuffer);
@@ -98,35 +100,6 @@ fileInput.onchange = function()
};
aReader.readAsArrayBuffer(aFile);
};
-
-//! Convert string into UTF-8 array.
-function toUtf8Array (theText)
-{
- var aRes = [];
- for (var aCharIter = 0; aCharIter < theText.length; ++aCharIter)
- {
- var aCharCode = theText.charCodeAt (aCharIter);
- if (aCharCode < 0x80)
- {
- aRes.push (aCharCode);
- }
- else if (aCharCode < 0x800)
- {
- aRes.push (0xc0 | (aCharCode >> 6), 0x80 | (aCharCode & 0x3f));
- }
- else if (aCharCode < 0xd800 || aCharCode >= 0xe000)
- {
- aRes.push (0xe0 | (aCharCode >> 12), 0x80 | ((aCharCode>>6) & 0x3f), 0x80 | (aCharCode & 0x3f));
- }
- else
- {
- ++aCharIter;
- aCharCode = 0x10000 + (((aCharCode & 0x3ff)<<10) | (theText.charCodeAt (aCharIter) & 0x3ff));
- aRes.push(0xf0 | (aCharCode >>18), 0x80 | ((aCharCode>>12) & 0x3f), 0x80 | ((aCharCode>>6) & 0x3f), 0x80 | (aCharCode & 0x3f));
- }
- }
- return aRes;
-}