1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39

OpenGl_Context now skips loading functions related to mapping buffer,
which are required by OpenGL ES 3.0 specs but not provided by WebGL 2.0.
Message_PrinterSystemLog does not use a broken emscripten_log() anymore, which corrupted UNICODE strings.

WasmOcctView::initWindow() - callbacks now set using EMSCRIPTEN_EVENT_TARGET_WINDOW
instead of 0 used by older Emscripten API.

Mouse callbacks now track canvas element and use
EmscriptenMouseEvent::targetX/targetY instead of ::canvasX/canvasY
as the latter was broken.

Added emscripten_set_main_loop() setup to shut up eglSwapInterval() error message.
Fixed missing \0 at the end of string converted by toUtf8Array().
This commit is contained in:
kgv
2020-07-16 16:15:22 +03:00
committed by bugmaster
parent b939a13923
commit 7465bfa65e
6 changed files with 60 additions and 73 deletions

View File

@@ -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())
{