MeshLib C++ Docs
Loading...
Searching...
No Matches
MRGladGlfw.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
3
4#ifdef __EMSCRIPTEN__
5#include <GLES3/gl3.h>
6#else
7#include <glad/glad.h>
8#endif
9#include <GLFW/glfw3.h>
10#ifdef _WIN32
11#undef APIENTRY
12#endif
13
14#ifndef __EMSCRIPTEN__
15#define MR_GLSL_VERSION_LINE R"(#version 150)"
16#else
17#define MR_GLSL_VERSION_LINE R"(#version 300 es)"
18#endif
19
20namespace MR {
21
22// Returns modifier id of SUPER on mac or wasm on macos, or CTRL otherwise
23MRVIEWER_API int getGlfwModPrimaryCtrl();
24
25// Returns name of the SUPER modifier depending on current environment:
26// windows - Win
27// macos - Command
28// wasm/mac - Command
29// otherwise - Super
30MRVIEWER_API const char* getSuperModName();
31
32// Returns name of the ALT modifier depending on current environment:
33// macos - Option
34// wasm/mac - Option
35// otherwise - Alt
36MRVIEWER_API const char* getAltModName();
37
38// Load OpenGL and its extensions
39inline int loadGL()
40{
41#ifndef __EMSCRIPTEN__
42#pragma warning(push)
43#pragma warning(disable: 4191) //'type cast': unsafe conversion from 'GLFWglproc (__cdecl *)(const char *)' to 'GLADloadproc'
44 // thread_local here - because we have two windows in two different threads (main window and splash)
45 // so we need to be sure that each thread loaded gl (it can be called from GUI threads only)
46 //
47 // function is inline to be sure that each dll/so has its own instance of `loadRes`
48 static thread_local auto loadRes = gladLoadGLLoader( ( GLADloadproc )glfwGetProcAddress );
49 return loadRes;
50#pragma warning(pop)
51#else
52return 1;
53#endif
54}
55
56// finds power of 2 that represents given msaa number
57// ==log2(msaa)
58inline int getMSAAPow( int msaa )
59{
60 if ( msaa <= 1 )
61 return 0;
62 int i = 1;
63 for ( ; i < 4; ++i )
64 {
65 if ( ( msaa & ( 1 << i ) ) != 0 )
66 return i;
67 }
68 return i;
69}
70
71} //namespace MR
Definition MRCameraOrientationPlugin.h:8
MRVIEWER_API const char * getAltModName()
MRVIEWER_API const char * getSuperModName()
int getMSAAPow(int msaa)
Definition MRGladGlfw.h:58
MRVIEWER_API int getGlfwModPrimaryCtrl()
int loadGL()
Definition MRGladGlfw.h:39