SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppEmscripten.cpp
Go to the documentation of this file.
1 /**
2  * \file AppEmscripten.cpp
3  * \date June 2024
4  * \brief App::run implementation from App.h for the Emscripten platform
5  * \details The functions implement mostly the callbacks for the platform
6  * that are forwarded to the C interface in SLInterface.
7  * For more info on how to create a new app with SLProject see:
8  * https://github.com/cpvrlab/SLProject4/wiki/Creating-a-New-App
9  * For more info about App framework see:
10  * https://cpvrlab.github.io/SLProject4/app-framework.html
11  * For more info about the Emscripten platform see:
12  * https://cpvrlab.github.io/SLProject4/emscripten.html
13  * For more info on how to set up the Emscripten platform see:
14  * https://github.com/cpvrlab/SLProject4/wiki/Build-for-the-web-with-Emscripten
15  * \authors Marino von Wattenwyl
16  * \copyright http://opensource.org/licenses/GPL-3.0
17  * \remarks Please use clangformat to format the code. See more code style on
18  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
19 */
20 
21 #include <App.h>
22 #include <SLGLState.h>
23 #include <SLEnums.h>
24 #include <SLInterface.h>
25 #include <AppCommon.h>
26 #include <SLAssetManager.h>
27 #include <SLScene.h>
28 #include <SLSceneView.h>
29 #include <CVCapture.h>
30 #include <Profiler.h>
31 #include <SLAssetLoader.h>
32 
33 #include <emscripten.h>
34 #include <emscripten/em_asm.h>
35 #include <emscripten/html5.h>
36 #include <emscripten/val.h>
37 
38 //-----------------------------------------------------------------------------
39 // Global variables
40 App::Config App::config; //!< The configuration set in App::run
41 static SLint svIndex; //!< Scene view index
42 static SLint startX; //!< start position x in pixels
43 static SLint startY; //!< start position y in pixels
44 static SLint mouseX; //!< Last mouse position x in pixels
45 static SLint mouseY; //!< Last mouse position y in pixels
46 static SLVec2i touch2; //!< Last finger touch 2 position in pixels
47 static SLVec2i touchDelta; //!< Delta between two fingers in x
48 static SLint lastWidth; //!< Last window width in pixels
49 static SLint lastHeight; //!< Last window height in pixels
50 static int canvasWidth; //!< Width of the HTML canvas
51 static int canvasHeight; //!< Height of the HTML canvas
52 static int lastTouchDownX; //!< X coordinate of last touch down
53 static int lastTouchDownY; //!< Y coordinate of last touch down
54 static double lastTouchDownTimeMS; //!< Time of last touch down in milliseconds
55 static long animationFrameID = 0; //!< ID of the current JavaScript animation frame
56 static SLbool coreAssetsLoaded = false; //!< Indicates whether core assets can be used
57 
58 //-----------------------------------------------------------------------------
59 // Function forward declarations
60 static SLbool onPaint();
61 static void updateCanvas();
62 static void onLoadingCoreAssets();
63 static EM_BOOL onAnimationFrame(double time, void* userData);
64 static EMSCRIPTEN_RESULT onMousePressed(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
65 static EM_BOOL onMouseReleased(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
66 static EM_BOOL onMouseDoubleClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
67 static EM_BOOL onMouseMove(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
68 static EM_BOOL onMouseWheel(int eventType, const EmscriptenWheelEvent* wheelEvent, void* userData);
69 static EM_BOOL onKeyPressed(int eventType, const EmscriptenKeyboardEvent* keyEvent, void* userData);
70 static EM_BOOL onKeyReleased(int eventType, const EmscriptenKeyboardEvent* keyEvent, void* userData);
71 static EM_BOOL onTouchStart(int eventType, const EmscriptenTouchEvent* touchEvent, void* userData);
72 static EM_BOOL onTouchEnd(int eventType, const EmscriptenTouchEvent* touchEvent, void* userData);
73 static EM_BOOL onTouchMove(int eventType, const EmscriptenTouchEvent* touchEvent, void* userData);
74 static const char* onUnload(int eventType, const void* reserved, void* userData);
75 static SLint convertToCanvasCoordinate(SLint coordinate);
76 static SLKey mapKeyToSLKey(unsigned long key);
77 static SLKey mapModifiersToSLModifiers(bool shiftDown, bool ctrlDown, bool altDown);
78 static SLKey mapModifiersToSLModifiers(const EmscriptenMouseEvent* mouseEvent);
79 static SLKey mapModifiersToSLModifiers(const EmscriptenKeyboardEvent* keyEvent);
80 
81 //-----------------------------------------------------------------------------
82 //! App::run implementation from App.h for the Emscripten platform
83 int App::run(Config config)
84 {
86 
87  canvasWidth = EM_ASM_INT(return window.devicePixelRatio * window.innerWidth);
88  canvasHeight = EM_ASM_INT(return window.devicePixelRatio * window.innerHeight);
89  updateCanvas();
90 
91  EmscriptenWebGLContextAttributes attributes;
92  emscripten_webgl_init_context_attributes(&attributes);
93  attributes.enableExtensionsByDefault = true;
94  attributes.antialias = false;
95  attributes.depth = true;
96  attributes.stencil = true;
97  attributes.alpha = true;
98  attributes.majorVersion = 2;
99  attributes.minorVersion = 0;
100  attributes.preserveDrawingBuffer = true;
101 
102  auto context = emscripten_webgl_create_context("#canvas", &attributes);
103  if (context > 0)
104  SL_LOG("WebGL context created.");
105  else
106  SL_EXIT_MSG("Failed to create WebGL context.");
107 
108  EMSCRIPTEN_RESULT result = emscripten_webgl_make_context_current(context);
109  if (result == EMSCRIPTEN_RESULT_SUCCESS)
110  SL_LOG("WebGL context made current.");
111  else
112  SL_EXIT_MSG("Failed to make WebGL context current.");
113 
114  emscripten_set_mousedown_callback("#canvas", nullptr, false, onMousePressed);
115  emscripten_set_mouseup_callback("#canvas", nullptr, false, onMouseReleased);
116  emscripten_set_dblclick_callback("#canvas", nullptr, false, onMouseDoubleClicked);
117  emscripten_set_mousemove_callback("#canvas", nullptr, false, onMouseMove);
118  emscripten_set_wheel_callback("#canvas", nullptr, false, onMouseWheel);
119  emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, false, onKeyPressed);
120  emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, false, onKeyReleased);
121  emscripten_set_touchstart_callback("#canvas", nullptr, false, onTouchStart);
122  emscripten_set_touchend_callback("#canvas", nullptr, false, onTouchEnd);
123  emscripten_set_touchmove_callback("#canvas", nullptr, false, onTouchMove);
124  emscripten_set_beforeunload_callback(nullptr, onUnload);
125 
126  SL_LOG("------------------------------------------------------------------");
127  SL_LOG("Platform : Emscripten");
128 
129  AppCommon::calibIniPath = "data/calibrations/";
130 
131  SLVstring args;
132  slCreateApp(args,
133  "data/",
134  "data/shaders/",
135  "data/models/",
136  "data/images/textures/",
137  "data/images/fonts/",
138  "data/videos/",
139  "data/config/",
140  "AppDemoEmscripten");
141 
143 
144  // Request an animation frame from the browser. This will call the `update` function once.
145  // The `update` function itself requests the next animation frame, creating an update loop.
146  animationFrameID = emscripten_request_animation_frame(onAnimationFrame, nullptr);
147 
148  return 0;
149 }
150 //-----------------------------------------------------------------------------
151 //! Paint event handler that passes the event to the slPaintAllViews function.
152 static SLbool onPaint()
153 {
154  if (AppCommon::sceneViews.empty())
155  return false;
156 
158 
159  int newCanvasWidth = EM_ASM_INT(return window.devicePixelRatio * window.innerWidth);
160  int newCanvasHeight = EM_ASM_INT(return window.devicePixelRatio * window.innerHeight);
161 
162  if (newCanvasWidth != canvasWidth || newCanvasHeight != canvasHeight)
163  {
164  canvasWidth = newCanvasWidth;
165  canvasHeight = newCanvasHeight;
166  updateCanvas();
167 
168  if (!AppCommon::sceneViews.empty())
170  canvasWidth,
171  canvasHeight);
172  }
173 
175  {
177  AppCommon::sceneToLoad = {}; // sets optional to empty
178  }
179 
180  if (AppCommon::assetLoader->isLoading())
182 
183  //////////////////////////////////////////////////////////////////////////
184  SLbool appNeedsUpdate = App::config.onUpdate && App::config.onUpdate(sv);
185  SLbool jobIsRunning = slUpdateParallelJob();
186  SLbool isLoading = AppCommon::assetLoader->isLoading();
187  SLbool viewNeedsUpdate = slPaintAllViews();
188  //////////////////////////////////////////////////////////////////////////
189 
190  return appNeedsUpdate || viewNeedsUpdate || jobIsRunning || isLoading;
191 }
192 //-----------------------------------------------------------------------------
193 static void updateCanvas()
194 {
195  // clang-format off
196  EM_ASM({
197  let canvas = Module['canvas'];
198  canvas.width = $0;
199  canvas.height = $1;
201  // clang-format on
202 }
203 //-----------------------------------------------------------------------------
204 static void onLoadingCoreAssets()
205 {
206  if (AppCommon::assetLoader->isLoading())
207  {
209  return;
210  }
211 
212  coreAssetsLoaded = true;
213 
216  canvasWidth,
217  canvasHeight,
218  (int)(142.0 * EM_ASM_DOUBLE(return window.devicePixelRatio)),
220  reinterpret_cast<void*>(onPaint),
221  nullptr,
222  reinterpret_cast<void*>(App::config.onNewSceneView),
223  reinterpret_cast<void*>(App::config.onGuiBuild),
224  reinterpret_cast<void*>(App::config.onGuiLoadConfig),
225  reinterpret_cast<void*>(App::config.onGuiSaveConfig));
226 
227  EM_ASM(document.querySelector("#loading-overlay").style.opacity = 0);
228 }
229 //-----------------------------------------------------------------------------
230 static EM_BOOL onAnimationFrame(double time, void* userData)
231 {
232  if (coreAssetsLoaded)
233  onPaint();
234  else
236 
237  // Request another animation frame from the browser to run the next iteration of `update`.
238  animationFrameID = emscripten_request_animation_frame(onAnimationFrame, nullptr);
239 
240  return EM_TRUE;
241 }
242 //-----------------------------------------------------------------------------
243 static EMSCRIPTEN_RESULT onMousePressed(int eventType,
244  const EmscriptenMouseEvent* mouseEvent,
245  void* userData)
246 {
247  SLint x = convertToCanvasCoordinate(mouseEvent->targetX);
248  SLint y = convertToCanvasCoordinate(mouseEvent->targetY);
250 
251  startX = x;
252  startY = y;
253 
254  switch (mouseEvent->button)
255  {
256  case 0:
257  if (modifiers & K_alt && modifiers & K_ctrl)
258  slTouch2Down(svIndex, x - 20, y, x + 20, y);
259  else
261  MB_left,
262  x,
263  y,
264  modifiers);
265  break;
266  case 1:
268  MB_middle,
269  x,
270  y,
271  modifiers);
272  break;
273  case 2:
275  MB_right,
276  x,
277  y,
278  modifiers);
279  break;
280  default: break;
281  }
282 
283  return EM_TRUE;
284 }
285 //-----------------------------------------------------------------------------
286 static EM_BOOL onMouseReleased(int eventType,
287  const EmscriptenMouseEvent* mouseEvent,
288  void* userData)
289 {
290  SLint x = convertToCanvasCoordinate(mouseEvent->targetX);
291  SLint y = convertToCanvasCoordinate(mouseEvent->targetY);
293 
294  startX = -1;
295  startY = -1;
296 
297  switch (mouseEvent->button)
298  {
299  case 0:
301  MB_left,
302  x,
303  y,
304  modifiers);
305  break;
306  case 1:
308  MB_middle,
309  x,
310  y,
311  modifiers);
312  break;
313  case 2:
315  MB_right,
316  x,
317  y,
318  modifiers);
319  break;
320  default: break;
321  }
322 
323  return EM_TRUE;
324 }
325 //-----------------------------------------------------------------------------
326 static EM_BOOL onMouseDoubleClicked(int eventType,
327  const EmscriptenMouseEvent* mouseEvent,
328  void* userData)
329 {
330  SLint x = convertToCanvasCoordinate(mouseEvent->targetX);
331  SLint y = convertToCanvasCoordinate(mouseEvent->targetY);
333 
334  switch (mouseEvent->button)
335  {
336  case 0:
338  MB_left,
339  x,
340  y,
341  modifiers);
342  break;
343  case 1:
345  MB_middle,
346  x,
347  y,
348  modifiers);
349  break;
350  case 2:
352  MB_right,
353  x,
354  y,
355  modifiers);
356  break;
357  default: break;
358  }
359 
360  return EM_TRUE;
361 }
362 //-----------------------------------------------------------------------------
363 static EM_BOOL onMouseMove(int eventType,
364  const EmscriptenMouseEvent* mouseEvent,
365  void* userData)
366 {
367  mouseX = convertToCanvasCoordinate(mouseEvent->targetX);
368  mouseY = convertToCanvasCoordinate(mouseEvent->targetY);
369 
370  if (mouseEvent->altKey && mouseEvent->ctrlKey)
372  mouseX - 20,
373  mouseY,
374  mouseX + 20,
375  mouseY);
376  else
378  mouseX,
379  mouseY);
380 
381  return EM_TRUE;
382 }
383 //-----------------------------------------------------------------------------
384 static EM_BOOL onMouseWheel(int eventType,
385  const EmscriptenWheelEvent* wheelEvent,
386  void* userData)
387 {
388  // Invert the sign because the scroll value is inverted
389  double deltaY = -wheelEvent->deltaY;
390 
391  // Make sure the delta is at least one integer
392  if (std::abs(deltaY) < 1) deltaY = Utils::sign(wheelEvent->deltaY);
393 
394  SLKey modifiers = mapModifiersToSLModifiers(&wheelEvent->mouse);
395  slMouseWheel(svIndex, (int)deltaY, modifiers);
396 
397  return EM_TRUE;
398 }
399 //-----------------------------------------------------------------------------
400 static EM_BOOL onKeyPressed(int eventType,
401  const EmscriptenKeyboardEvent* keyEvent,
402  void* userData)
403 {
404  if (keyEvent->repeat)
405  return EM_TRUE;
406 
407  SLKey key = mapKeyToSLKey(keyEvent->keyCode);
410 
411  return EM_FALSE;
412 }
413 //-----------------------------------------------------------------------------
414 static EM_BOOL onKeyReleased(int eventType,
415  const EmscriptenKeyboardEvent* keyEvent,
416  void* userData)
417 {
418  SLKey key = mapKeyToSLKey(keyEvent->keyCode);
421 
422  return EM_FALSE;
423 }
424 //-----------------------------------------------------------------------------
425 static EM_BOOL onTouchStart(int eventType,
426  const EmscriptenTouchEvent* touchEvent,
427  void* userData)
428 {
429  if (touchEvent->numTouches == 1)
430  {
431  mouseX = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
432  mouseY = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
434  MB_left,
435  mouseX,
436  mouseY,
437  K_none);
438  lastTouchDownTimeMS = touchEvent->timestamp;
439  }
440  else if (touchEvent->numTouches == 2)
441  {
442  int x0 = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
443  int y0 = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
444  int x1 = convertToCanvasCoordinate(touchEvent->touches[1].clientX);
445  int y1 = convertToCanvasCoordinate(touchEvent->touches[1].clientY);
446  slTouch2Down(svIndex, x0, y0, x1, y1);
447  }
448 
451 
452  return EM_TRUE;
453 }
454 //-----------------------------------------------------------------------------
455 static EM_BOOL onTouchEnd(int eventType,
456  const EmscriptenTouchEvent* touchEvent,
457  void* userData)
458 {
459  if (touchEvent->numTouches == 1)
460  {
461  mouseX = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
462  mouseY = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
464  MB_left,
465  mouseX,
466  mouseY,
467  K_none);
468 
469  int dx = std::abs(mouseX - lastTouchDownX);
470  int dy = std::abs(mouseY - lastTouchDownY);
471  double dt = touchEvent->timestamp - lastTouchDownTimeMS;
472 
473  if (dt > 800 && dx < 15 && dy < 15)
474  {
476  MB_right,
479  K_none);
481  MB_right,
484  K_none);
485  }
486  }
487  else if (touchEvent->numTouches == 2)
488  {
489  int x0 = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
490  int y0 = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
491  int x1 = convertToCanvasCoordinate(touchEvent->touches[1].clientX);
492  int y1 = convertToCanvasCoordinate(touchEvent->touches[1].clientY);
493  slTouch2Up(svIndex, x0, y0, x1, y1);
494  }
495 
496  return EM_TRUE;
497 }
498 //-----------------------------------------------------------------------------
499 static EM_BOOL onTouchMove(int eventType,
500  const EmscriptenTouchEvent* touchEvent,
501  void* userData)
502 {
503  if (touchEvent->numTouches == 1)
504  {
505  mouseX = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
506  mouseY = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
508  }
509  else if (touchEvent->numTouches == 2)
510  {
511  int x0 = convertToCanvasCoordinate(touchEvent->touches[0].clientX);
512  int y0 = convertToCanvasCoordinate(touchEvent->touches[0].clientY);
513  int x1 = convertToCanvasCoordinate(touchEvent->touches[1].clientX);
514  int y1 = convertToCanvasCoordinate(touchEvent->touches[1].clientY);
515  slTouch2Move(svIndex, x0, y0, x1, y1);
516  }
517 
518  return EM_TRUE;
519 }
520 //-----------------------------------------------------------------------------
521 static const char* onUnload(int eventType,
522  const void* reserved,
523  void* userData)
524 {
525  slTerminate();
526 
527  // Cancel the current animation frame to prevent `update` being called after
528  // everything has been terminated and cleaned up.
529  emscripten_cancel_animation_frame(animationFrameID);
530 
531  return nullptr;
532 }
533 //-----------------------------------------------------------------------------
535 {
536  return (SLint)((double)coordinate * EM_ASM_DOUBLE(return window.devicePixelRatio));
537 }
538 //-----------------------------------------------------------------------------
539 static SLKey mapKeyToSLKey(unsigned long key)
540 {
541  switch (key)
542  {
543  case 8: return K_backspace;
544  case 9: return K_tab;
545  case 13: return K_enter;
546  case 16: return K_shift;
547  case 17: return K_ctrl;
548  case 18: return K_alt;
549  case 27: return K_esc;
550  case 32: return K_space;
551  case 33: return K_pageUp;
552  case 34: return K_pageDown;
553  case 35: return K_end;
554  case 36: return K_home;
555  case 37: return K_left;
556  case 38: return K_up;
557  case 39: return K_right;
558  case 40: return K_down;
559  case 45: return K_insert;
560  case 46: return K_delete;
561  case 96: return K_NP0;
562  case 97: return K_NP1;
563  case 98: return K_NP2;
564  case 99: return K_NP3;
565  case 100: return K_NP4;
566  case 101: return K_NP5;
567  case 102: return K_NP6;
568  case 103: return K_NP7;
569  case 104: return K_NP8;
570  case 105: return K_NP9;
571  case 106: return K_NPMultiply;
572  case 107: return K_NPAdd;
573  case 109: return K_NPSubtract;
574  case 110: return K_NPDecimal;
575  case 111: return K_NPDivide;
576  case 112: return K_F1;
577  case 113: return K_F2;
578  case 114: return K_F3;
579  case 115: return K_F4;
580  case 116: return K_F5;
581  case 117: return K_F6;
582  case 118: return K_F7;
583  case 119: return K_F8;
584  case 120: return K_F9;
585  case 121: return K_F10;
586  case 122: return K_F11;
587  case 123: return K_F12;
588  default: return (SLKey)key;
589  }
590 }
591 //-----------------------------------------------------------------------------
592 SLKey mapModifiersToSLModifiers(bool shiftDown, bool ctrlDown, bool altDown)
593 {
594  int modifiers = 0;
595  if (shiftDown) modifiers |= K_shift;
596  if (ctrlDown) modifiers |= K_ctrl;
597  if (altDown) modifiers |= K_alt;
598  return (SLKey)modifiers;
599 }
600 //-----------------------------------------------------------------------------
601 SLKey mapModifiersToSLModifiers(const EmscriptenMouseEvent* mouseEvent)
602 {
603  return mapModifiersToSLModifiers(mouseEvent->shiftKey,
604  mouseEvent->ctrlKey,
605  mouseEvent->altKey);
606 }
607 //-----------------------------------------------------------------------------
608 SLKey mapModifiersToSLModifiers(const EmscriptenKeyboardEvent* keyEvent)
609 {
610  return mapModifiersToSLModifiers(keyEvent->shiftKey,
611  keyEvent->ctrlKey,
612  keyEvent->altKey);
613 }
614 //-----------------------------------------------------------------------------
The App namespace declares the App::Config struct and the App::run function.
The AppCommon class holds the top-level instances of the app-demo.
static EM_BOOL onTouchEnd(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
static SLint svIndex
Scene view index.
static SLbool onPaint()
Paint event handler that passes the event to the slPaintAllViews function.
static EM_BOOL onMouseWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData)
static int canvasWidth
Width of the HTML canvas.
static const char * onUnload(int eventType, const void *reserved, void *userData)
static SLbool coreAssetsLoaded
Indicates whether core assets can be used.
static SLint startY
start position y in pixels
static EM_BOOL onKeyPressed(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
static SLKey mapModifiersToSLModifiers(bool shiftDown, bool ctrlDown, bool altDown)
static EM_BOOL onMouseReleased(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
static EM_BOOL onMouseDoubleClicked(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
static double lastTouchDownTimeMS
Time of last touch down in milliseconds.
static EMSCRIPTEN_RESULT onMousePressed(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
static SLKey mapKeyToSLKey(unsigned long key)
static SLint mouseX
Last mouse position x in pixels.
static EM_BOOL onTouchMove(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
static void updateCanvas()
static SLint lastHeight
Last window height in pixels.
static SLint startX
start position x in pixels
static SLVec2i touchDelta
Delta between two fingers in x.
static int lastTouchDownY
Y coordinate of last touch down.
static EM_BOOL onKeyReleased(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
static SLint convertToCanvasCoordinate(SLint coordinate)
static SLint lastWidth
Last window width in pixels.
static long animationFrameID
ID of the current JavaScript animation frame.
static EM_BOOL onMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
static SLint mouseY
Last mouse position y in pixels.
static SLVec2i touch2
Last finger touch 2 position in pixels.
static int lastTouchDownX
X coordinate of last touch down.
static int canvasHeight
Height of the HTML canvas.
static void onLoadingCoreAssets()
static EM_BOOL onTouchStart(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
static EM_BOOL onAnimationFrame(double time, void *userData)
static SLKey modifiers
last modifier keys
Definition: AppGLFW.cpp:50
static GLFWwindow * window
The global glfw window handle.
Definition: AppGLFW.cpp:35
#define SL_LOG(...)
Definition: SL.h:233
bool SLbool
Definition: SL.h:175
vector< SLstring > SLVstring
Definition: SL.h:201
#define SL_EXIT_MSG(message)
Definition: SL.h:240
int SLint
Definition: SL.h:170
@ MB_left
Definition: SLEnums.h:100
@ MB_right
Definition: SLEnums.h:102
@ MB_middle
Definition: SLEnums.h:101
SLKey
Keyboard key codes enumeration.
Definition: SLEnums.h:16
@ K_down
Definition: SLEnums.h:25
@ K_NP5
Definition: SLEnums.h:38
@ K_delete
Definition: SLEnums.h:23
@ K_space
Definition: SLEnums.h:18
@ K_F2
Definition: SLEnums.h:50
@ K_F1
Definition: SLEnums.h:49
@ K_F12
Definition: SLEnums.h:60
@ K_NP9
Definition: SLEnums.h:42
@ K_F6
Definition: SLEnums.h:54
@ K_F4
Definition: SLEnums.h:52
@ K_up
Definition: SLEnums.h:24
@ K_enter
Definition: SLEnums.h:20
@ K_esc
Definition: SLEnums.h:21
@ K_none
Definition: SLEnums.h:17
@ K_tab
Definition: SLEnums.h:19
@ K_NP6
Definition: SLEnums.h:39
@ K_shift
Definition: SLEnums.h:62
@ K_end
Definition: SLEnums.h:29
@ K_insert
Definition: SLEnums.h:30
@ K_right
Definition: SLEnums.h:26
@ K_F9
Definition: SLEnums.h:57
@ K_NPDivide
Definition: SLEnums.h:43
@ K_pageDown
Definition: SLEnums.h:32
@ K_F8
Definition: SLEnums.h:56
@ K_F5
Definition: SLEnums.h:53
@ K_pageUp
Definition: SLEnums.h:31
@ K_NPMultiply
Definition: SLEnums.h:44
@ K_NPSubtract
Definition: SLEnums.h:46
@ K_NP8
Definition: SLEnums.h:41
@ K_NP1
Definition: SLEnums.h:34
@ K_NP3
Definition: SLEnums.h:36
@ K_ctrl
Definition: SLEnums.h:63
@ K_NP7
Definition: SLEnums.h:40
@ K_NP2
Definition: SLEnums.h:35
@ K_F10
Definition: SLEnums.h:58
@ K_F11
Definition: SLEnums.h:59
@ K_NP4
Definition: SLEnums.h:37
@ K_F3
Definition: SLEnums.h:51
@ K_F7
Definition: SLEnums.h:55
@ K_alt
Definition: SLEnums.h:64
@ K_left
Definition: SLEnums.h:27
@ K_NP0
Definition: SLEnums.h:33
@ K_backspace
Definition: SLEnums.h:22
@ K_home
Definition: SLEnums.h:28
@ K_NPDecimal
Definition: SLEnums.h:48
@ K_NPAdd
Definition: SLEnums.h:45
Singleton class for global render state.
void slTouch2Move(int sceneViewIndex, int xpos1, int ypos1, int xpos2, int ypos2)
void slMouseDown(int sceneViewIndex, SLMouseButton button, int xpos, int ypos, SLKey modifier)
void slTouch2Down(int sceneViewIndex, int xpos1, int ypos1, int xpos2, int ypos2)
void slLoadCoreAssetsAsync()
void slMouseMove(int sceneViewIndex, int x, int y)
void slSwitchScene(SLSceneView *sv, SLSceneID sceneID)
void slMouseWheel(int sceneViewIndex, int pos, SLKey modifier)
void slKeyRelease(int sceneViewIndex, SLKey key, SLKey modifier)
void slMouseUp(int sceneViewIndex, SLMouseButton button, int xpos, int ypos, SLKey modifier)
void slTouch2Up(int sceneViewIndex, int xpos1, int ypos1, int xpos2, int ypos2)
void slDoubleClick(int sceneViewIndex, SLMouseButton button, int xpos, int ypos, SLKey modifier)
void slResize(int sceneViewIndex, int width, int height)
bool slPaintAllViews()
void slKeyPress(int sceneViewIndex, SLKey key, SLKey modifier)
void slTerminate()
bool slUpdateParallelJob()
void slCreateApp(SLVstring &cmdLineArgs, const SLstring &dataPath, const SLstring &shaderPath, const SLstring &modelPath, const SLstring &texturePath, const SLstring &fontPath, const SLstring &videoPath, const SLstring &configPath, const SLstring &applicationName)
Definition: SLInterface.cpp:57
SLint slCreateSceneView(SLAssetManager *am, SLScene *scene, int screenWidth, int screenHeight, int dotsPerInch, SLSceneID initScene, void *onWndUpdateCallback, void *onSelectNodeMeshCallback, void *onNewSceneViewCallback, void *onImGuiBuild, void *onImGuiLoadConfig, void *onImGuiSaveConfig)
Declaration of the main Scene Library C-Interface.
static SLstring calibIniPath
That's where data/calibrations folder is located.
Definition: AppCommon.h:108
static optional< SLSceneID > sceneToLoad
Scene id to load at start up.
Definition: AppCommon.h:90
static SLAssetManager * assetManager
asset manager is the owner of all assets
Definition: AppCommon.h:59
static SLVSceneView sceneViews
Vector of sceneview pointers.
Definition: AppCommon.h:62
static SLAssetLoader * assetLoader
Asset-loader for async asset loading.
Definition: AppCommon.h:60
static SLScene * scene
Pointer to the one and only SLScene instance.
Definition: AppCommon.h:61
void checkIfAsyncLoadingIsDone()
bool isLoading() const
Definition: SLAssetLoader.h:68
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
int run(Config config)
App::run implementation from App.h for the Emscripten platform.
Definition: AppAndroid.cpp:78
Config config
The configuration set in App::run.
Definition: AppAndroid.cpp:34
T sign(T a)
Definition: Utils.h:245
T abs(T a)
Definition: Utils.h:249
App configuration struct to be passed to the App::run function.
Definition: App.h:57
OnGuiLoadConfigCallback onGuiLoadConfig
Definition: App.h:73
SLSceneID startSceneID
Definition: App.h:64
OnNewSceneViewCallback onNewSceneView
Definition: App.h:65
OnUpdateCallback onUpdate
Definition: App.h:71
OnGuiSaveConfigCallback onGuiSaveConfig
Definition: App.h:74
OnGuiBuildCallback onGuiBuild
Definition: App.h:72