1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +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

@@ -57,32 +57,25 @@
#elif defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
// actual version of Emscripten does not define these yet
#ifndef EM_LOG_INFO
#define EM_LOG_INFO 0
#endif
#ifndef EM_LOG_DEBUG
#define EM_LOG_DEBUG 0
#endif
//! Convert message gravity into emscripten_log() flags.
static int getEmscriptenPriority (const Message_Gravity theGravity)
{
switch (theGravity)
{
case Message_Trace: return EM_LOG_CONSOLE | EM_LOG_DEBUG;
case Message_Info: return EM_LOG_CONSOLE | EM_LOG_INFO;
case Message_Warning: return EM_LOG_CONSOLE | EM_LOG_WARN;
case Message_Alarm: return EM_LOG_CONSOLE | EM_LOG_ERROR;
case Message_Fail: return EM_LOG_CONSOLE | EM_LOG_ERROR;
}
return EM_LOG_CONSOLE;
}
//! Print message to console.debug().
EM_JS(void, debugMsgToConsole, (const char* theStr), {
EM_JS(void, occJSConsoleDebug, (const char* theStr), {
console.debug(UTF8ToString(theStr));
});
//! Print message to console.info().
EM_JS(void, occJSConsoleInfo, (const char* theStr), {
console.info(UTF8ToString(theStr));
});
//! Print message to console.warn().
EM_JS(void, occJSConsoleWarn, (const char* theStr), {
console.warn(UTF8ToString(theStr));
});
//! Print message to console.error().
EM_JS(void, occJSConsoleError, (const char* theStr), {
console.error(UTF8ToString(theStr));
});
#else
#include <syslog.h>
@@ -176,14 +169,16 @@ void Message_PrinterSystemLog::send (const TCollection_AsciiString& theString,
#elif defined(__ANDROID__)
__android_log_write (getAndroidLogPriority (theGravity), myEventSourceName.ToCString(), theString.ToCString());
#elif defined(__EMSCRIPTEN__)
if (theGravity == Message_Trace)
// don't use bogus emscripten_log() corrupting UNICODE strings
switch (theGravity)
{
debugMsgToConsole (theString.ToCString());
}
else
{
emscripten_log (getEmscriptenPriority (theGravity), "%s", theString.ToCString());
case Message_Trace: occJSConsoleDebug(theString.ToCString()); return;
case Message_Info: occJSConsoleInfo (theString.ToCString()); return;
case Message_Warning: occJSConsoleWarn (theString.ToCString()); return;
case Message_Alarm: occJSConsoleError(theString.ToCString()); return;
case Message_Fail: occJSConsoleError(theString.ToCString()); return;
}
occJSConsoleWarn (theString.ToCString());
#else
syslog (getSysLogPriority (theGravity), "%s", theString.ToCString());
#endif

View File

@@ -1577,14 +1577,20 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
&& FindProcShort (glDeleteVertexArrays)
&& FindProcShort (glGenVertexArrays)
&& FindProcShort (glIsVertexArray);
#ifndef __EMSCRIPTEN__ // latest Emscripten does not pretend having / simulating mapping buffer functions
const bool hasMapBufferRange = IsGlGreaterEqual (3, 0)
&& FindProcShort (glMapBufferRange)
&& FindProcShort (glUnmapBuffer)
&& FindProcShort (glGetBufferPointerv)
&& FindProcShort (glFlushMappedBufferRange);
#endif
// load OpenGL ES 3.0 new functions
const bool has30es = IsGlGreaterEqual (3, 0)
&& hasVAO
#ifndef __EMSCRIPTEN__
&& hasMapBufferRange
#endif
&& hasInstanced
&& arbSamplerObject != NULL
&& arbFBOBlit != NULL
@@ -1602,8 +1608,6 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
&& FindProcShort (glEndQuery)
&& FindProcShort (glGetQueryiv)
&& FindProcShort (glGetQueryObjectuiv)
&& FindProcShort (glUnmapBuffer)
&& FindProcShort (glGetBufferPointerv)
&& FindProcShort (glDrawBuffers)
&& FindProcShort (glUniformMatrix2x3fv)
&& FindProcShort (glUniformMatrix3x2fv)

View File

@@ -60,8 +60,10 @@ public: //! @name GL_ARB_vertex_array_object (added to OpenGL 3.0 core)
public: //! @name GL_ARB_map_buffer_range (added to OpenGL 3.0 core)
#ifndef __EMSCRIPTEN__
using theBaseClass_t::glMapBufferRange;
using theBaseClass_t::glFlushMappedBufferRange;
#endif
public: //! @name OpenGL 3.0 additives to 2.1
@@ -142,8 +144,10 @@ public: //! @name OpenGL 3.0 additives to 2.1
using theBaseClass_t::glEndQuery;
using theBaseClass_t::glGetQueryiv;
using theBaseClass_t::glGetQueryObjectuiv;
#ifndef __EMSCRIPTEN__
using theBaseClass_t::glUnmapBuffer;
#endif
#endif
};
//! OpenGL 3.0 core based on 2.1 version.