Comments (7)
Just for reference for anyone who may be reading this: In emscripten there is no need for any OpenGL loader, simply #include <GL/gl.h>
and it will automatically use emscripten's built-in OpenGL stuff.
If you have a project that can be in both native mode and emscripten, then you can create a simple OpenGL wrapper header:
opengl.h
#ifdef __EMSCRIPTEN__
// For emscripten, instead of using glad we use its built-in support for OpenGL:
#include <GL/gl.h>
#else
#include "glad.h"
#endif
And then just include this "opengl.h" header everywhere you need it. Also, in your main
function, you can check the same __EMSCRIPTEN__
ifdef to determine if glad should be initialized
from glad-web.
Good idea.
Jfyi you can already use glad with emscripten: gladLoadGLLoader((GLADloadproc) emscripten_GetProcAddress)
.
I'll track the issue in the main repository.
from glad-web.
Has been added to the glad2 branch, playing around with it, it seems like it would only be useful if you're using neither glfw nor SDL.
from glad-web.
Please do not use emscripten_GetProcAddress
. It is slow and should not be used.
Here is the quote directly from the emscripten wiki:
Avoid using any of the *glGetProcAddress() API functions. Emscripten provides static linking to all of the GL API functions, even for all WebGL extensions. The *glGetProcAddress() API is only provided for compatibility to ease porting of existing code, but accessing WebGL via calling dynamically obtained function pointers is noticeably slower than direct function calls, due to extra function pointer security validation that dynamic dispatching has to do in asm.js/WebAssembly. Since Emscripten provides all of the GL entry points statically linked in, it is recommended to take advantage of this for best performance.
from glad-web.
@bitc Thanks, I'll keep that in mind, for now the function pointer loading thing just did fit more into the current way of how things worked within glad. For static linking I'll probably have to add an extra option if you want otherwise the headers will get even more bloated.
from glad-web.
There are other platforms where it isn't necessary to look up the functions dynamically, yet I gladly use glad to get consistent headers everywhere, and to keep such ifdefs out of my code. It would be great if glad supports emscripten through the same API as all other platforms.
from glad-web.
@zajo The glad2 branch has the non-optimal (as described above) loading integrated: gles2_glfw_emscripten.
from glad-web.
Related Issues (20)
- Generated code issues pedantic warnings with modern compilers HOT 1
- glad wgl generated online with --local-files differs from local HOT 1
- add GL, GLES, GLSC enum member to gladGLversionStruct HOT 1
- Emscripten support HOT 1
- Permanent Link HOT 1
- `glMapBuffer` is missing from the OpenGL ES (2) header. HOT 3
- 500 Internal Server Error on generating gles2 HOT 4
- what is the documntation setup for glad? HOT 1
- What license should I distribute this? HOT 1
- Date is ahead of current system time HOT 13
- new vulkan loader? HOT 1
- WGL Undefined References HOT 1
- wgl identifier undefined
- mx global causes an error and overall bad UX on website
- Glad header for different GL version or platform HOT 2
- executing my code gives symbol lookup error undefined symbol: glad_glGenTextures HOT 1
- Add support for OpenGL in Rust. HOT 4
- Add Nim support HOT 2
- Can't omit khrplatform? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glad-web.