0032460: Coding Rules - eliminate CLang warning -Wunused-but-set-variable
[occt.git] / samples / webgl / main.cpp
1 // Copyright (c) 2019 OPEN CASCADE SAS
2 //
3 // This file is part of the examples of the Open CASCADE Technology software library.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
21
22 #include <iostream>
23
24 #include "WasmOcctView.h"
25
26 #include <Message.hxx>
27 #include <Message_Messenger.hxx>
28 #include <Message_PrinterSystemLog.hxx>
29 #include <OSD_MemInfo.hxx>
30 #include <OSD_Parallel.hxx>
31
32 #include <emscripten.h>
33 #include <emscripten/html5.h>
34
35 //! Dummy main loop callback for a single shot.
36 extern "C" void onMainLoop()
37 {
38   // do nothing here - viewer updates are handled on demand
39   emscripten_cancel_main_loop();
40 }
41
42 EMSCRIPTEN_KEEPALIVE int main()
43 {
44   Message::DefaultMessenger()->Printers().First()->SetTraceLevel (Message_Trace);
45   Handle(Message_PrinterSystemLog) aJSConsolePrinter = new Message_PrinterSystemLog ("webgl-sample", Message_Trace);
46   Message::DefaultMessenger()->AddPrinter (aJSConsolePrinter); // open JavaScript console within the Browser to see this output
47   Message::SendTrace() << "Emscripten SDK " << __EMSCRIPTEN_major__ << "." << __EMSCRIPTEN_minor__ << "." << __EMSCRIPTEN_tiny__;
48 #if defined(__LP64__)
49   Message::SendTrace() << "Architecture: WASM 64-bit";
50 #else
51   Message::SendTrace() << "Architecture: WASM 32-bit";
52 #endif
53   Message::SendTrace() << "NbLogicalProcessors: "
54     << OSD_Parallel::NbLogicalProcessors()
55 #ifdef __EMSCRIPTEN_PTHREADS__
56     << " (pthreads ON)"
57 #else
58     << " (pthreads OFF)"
59 #endif
60   ;
61
62   // setup a dummy single-shot main loop callback just to shut up a useless Emscripten error message on calling eglSwapInterval()
63   emscripten_set_main_loop (onMainLoop, -1, 0);
64
65   WasmOcctView& aViewer = WasmOcctView::Instance();
66   aViewer.run();
67   Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
68   return 0;
69 }