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