Fixed emscripten_async_call() calls to use requestAnimationFrame() instead of setTimeout().
ViewerTest_EventManager::handleViewRedraw() - fixed queuing new onWasmRedrawView()
before previous one has been processed (leading to multiplying of pending redraws executed at the same time).
RWGltf_TriangulationReader::readDracoBuffer - suppressed CLang compilation warnings.
// ================================================================
WasmOcctView::WasmOcctView()
: myDevicePixelRatio (1.0f),
- myUpdateRequests (0)
+ myNbUpdateRequests (0)
{
addActionHotKeys (Aspect_VKey_NavForward, Aspect_VKey_W, Aspect_VKey_W | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavBackward , Aspect_VKey_S, Aspect_VKey_S | Aspect_VKeyFlags_SHIFT);
// Queue onRedrawView()/redrawView callback to redraw canvas after all user input is flushed by browser.
// Redrawing viewer on every single message would be a pointless waste of resources,
// as user will see only the last drawn frame due to WebGL implementation details.
- if (++myUpdateRequests == 1)
+ // -1 in emscripten_async_call() redirects to requestAnimationFrame();
+ // requestPostAnimationFrame() is a better under development alternative.
+ if (++myNbUpdateRequests == 1)
{
- emscripten_async_call (onRedrawView, this, 0);
+ emscripten_async_call (onRedrawView, this, -1);
}
}
}
{
if (!myView.IsNull())
{
+ myNbUpdateRequests = 0;
FlushViewEvents (myContext, myView, true);
}
}
void WasmOcctView::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(V3d_View)& theView)
{
- myUpdateRequests = 0;
AIS_ViewController::handleViewRedraw (theCtx, theView);
if (myToAskNextFrame)
{
// ask more frames
- ++myUpdateRequests;
- emscripten_async_call (onRedrawView, this, 0);
+ if (++myNbUpdateRequests == 1)
+ {
+ emscripten_async_call (onRedrawView, this, -1);
+ }
}
}
TCollection_AsciiString myCanvasId; //!< canvas element id on HTML page
Graphic3d_Vec2i myWinSizeOld;
float myDevicePixelRatio; //!< device pixel ratio for handling high DPI displays
- unsigned int myUpdateRequests; //!< counter for unhandled update requests
+ unsigned int myNbUpdateRequests; //!< counter for unhandled update requests
};
#ifdef HAVE_DRACO
std::vector<char> aReadData;
- aReadData.resize (theGltfData.StreamLength);
+ aReadData.resize ((size_t )theGltfData.StreamLength);
aSharedStream->read (aReadData.data(), (std::streamsize )theGltfData.StreamLength);
if (!aSharedStream->good())
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wall"
#pragma clang diagnostic ignored "-Wextra"
+ #pragma clang diagnostic ignored "-Wshorten-64-to-32"
#elif defined(_MSC_VER)
#pragma warning(push, 0)
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#include <emscripten.h>
#include <emscripten/html5.h>
- //! Callback flushing events and redrawing the WebGL canvas.
- static void onWasmRedrawView (void* )
+//=======================================================================
+//function : onWasmRedrawView
+//purpose :
+//=======================================================================
+void ViewerTest_EventManager::onWasmRedrawView (void* )
+{
+ Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
+ if (!aViewCtrl.IsNull())
{
- Handle(ViewerTest_EventManager) aViewCtrl = ViewerTest::CurrentEventManager();
+ aViewCtrl->myNbUpdateRequests = 0;
+
const Handle(V3d_View)& aView = ViewerTest::CurrentView();
const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
- if (!aViewCtrl.IsNull() && !aView.IsNull() && !aCtx.IsNull())
+ if (!aView.IsNull() && !aCtx.IsNull())
{
aViewCtrl->ProcessExpose();
}
}
+}
#endif
Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
myView (theView),
myToPickPnt (Standard_False),
myIsTmpContRedraw (Standard_False),
- myUpdateRequests (0)
+ myNbUpdateRequests (0)
{
myViewAnimation = GlobalViewAnimation();
void ViewerTest_EventManager::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(V3d_View)& theView)
{
- myUpdateRequests = 0;
AIS_ViewController::handleViewRedraw (theCtx, theView);
// On non-Windows platforms Aspect_Window::InvalidateContent() from rendering thread does not work as expected
}
// ask more frames
- ++myUpdateRequests;
- #if defined(__EMSCRIPTEN__)
- emscripten_async_call (onWasmRedrawView, this, 0);
- #endif
+ if (++myNbUpdateRequests == 1)
+ {
+ #if defined(__EMSCRIPTEN__)
+ emscripten_async_call (onWasmRedrawView, this, -1);
+ #endif
+ }
}
else if (myIsTmpContRedraw)
{
// Queue onWasmRedrawView() callback to redraw canvas after all user input is flushed by browser.
// Redrawing viewer on every single message would be a pointless waste of resources,
// as user will see only the last drawn frame due to WebGL implementation details.
- if (++myUpdateRequests == 1)
+ // -1 in emscripten_async_call() redirects to requestAnimationFrame();
+ // requestPostAnimationFrame() is a better under development alternative.
+ if (++myNbUpdateRequests == 1)
{
- #if defined(__EMSCRIPTEN__)
- emscripten_async_call (onWasmRedrawView, this, 0);
- #endif
+ emscripten_async_call (onWasmRedrawView, this, -1);
}
#else
// handle synchronously
unsigned int theModifNew,
double theTimeStamp);
+private:
+
+#if defined(__EMSCRIPTEN__)
+ //! Callback flushing events and redrawing the WebGL canvas.
+ static void onWasmRedrawView (void* );
+#endif
+
private:
Handle(AIS_InteractiveContext) myCtx;
Standard_Boolean myToPickPnt;
Standard_Boolean myIsTmpContRedraw;
- unsigned int myUpdateRequests; //!< counter for unhandled update requests
+ unsigned int myNbUpdateRequests; //!< counter for unhandled update requests
};