Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support header-file-only library generation #52

Closed
raysan5 opened this issue Jun 1, 2016 · 16 comments
Closed

Support header-file-only library generation #52

raysan5 opened this issue Jun 1, 2016 · 16 comments

Comments

@raysan5
Copy link

raysan5 commented Jun 1, 2016

Would it be possible to add support for header-file-only generation for GLAD? I mean, similar to the stb libraries.

It would be very useful to just drop glad.h into the project and avoid pipeline modification.

Here it is a sample I'm working on; I created the GLAD header-file-only myself manually.

@Shimmen
Copy link

Shimmen commented Jun 1, 2016

I think this is a great idea. I never really want to put the glad-files in with the rest of my code, but the alternative for now is just a tad too complicated.

I think that simplicity is the one features of glad that makes it stand above rest (like GLEW). Having just a header file to import would make it even more simple and better.

However, I imagine compiling the whole file @raysan5 has made takes some time, especially if it's included in several files. Quite often I just want like a GLuint declared for my header file. Maybe a complimentary glad_types.h would be good. Personally I'm not worried about many files, but rather .c files.

@raysan5
Copy link
Author

raysan5 commented Jun 2, 2016

Hi @Shimmen, I'm using OpenGL 3.3 core profile glad version, originally, glad.h was already ~14K LoC and glad.c was ~7.6K LoC. Once unified, glad.h is ~22K LoC and compiling time with GCC 4.7.2 takes about 2-3 seconds in my dev workstation.

@Shimmen
Copy link

Shimmen commented Jun 6, 2016

I'm considering making a pull request. Do you want it to be an option to only have a header file and should it be default?

@Dav1dde
Copy link
Owner

Dav1dde commented Jun 6, 2016

Hey, that's awesome!

I am still thinking if that option makes sense, as previously pointed out the header file would be really large and slow down the compilation process by quite a bit. I am also not sure if splitting the header into multiple header files is a good idea.

Then again, having the option probably doesn't hurt, the header-only option wouldn't be the default though.

@raysan5
Copy link
Author

raysan5 commented Jun 10, 2016

I used the web tool to just select the extensions I needed (basic OpenGL 3.3 Core) and then I created a header only file; it was around 5K LoC and it compiles in milliseconds (unnoticeable any delay).

@Dav1dde
Copy link
Owner

Dav1dde commented Aug 12, 2016

Just a heads up, the glad2 branch supports a header only option now!

python -m glad --out-path=build --api="gl:core=" --extensions= c --header-only

@elmindreda
Copy link
Contributor

Modern preprocessors are very fast so when GLAD_IMPLEMENTATION isn't defined there would be virtually no performance impact.

@raysan5
Copy link
Author

raysan5 commented Aug 12, 2016

Great addition @Dav1dde! Thank you very much for the update! :)

@Dav1dde Dav1dde added this to the glad 2 milestone Jan 28, 2017
@ricanteja
Copy link

Any news on when this functionality will be hitting the website or will that be when version 2 is officially launched? Thanks!

@Dav1dde
Copy link
Owner

Dav1dde commented Feb 23, 2017

I don't have an ETA.

If you want to play around with it, the glad2 branch should produced working C-Code. API slightly changed: gladLoadGL is the only way to load a GL context and it always requires to be passed a loader function.

@IntellectualKitty
Copy link

I was hoping we could get a status update on when this might make it to the website. I love the web service! I think it's great! Header-only support would make it perfect. Thanks!

@Dav1dde
Copy link
Owner

Dav1dde commented May 24, 2017

http://glad2.dav1d.de currently hosts the glad2 branch, it is functional but with no fixed API. The glad2 does support header only. If you find bugs, I am happy to fix them.

@maek
Copy link

maek commented Nov 13, 2017

I believe I found some issues with this:

  1. The header guard __glad_gl_h_ should be closed at the end of the file, not just after the glad.h part
  2. You should define all functions as inline otherwise you are breaking ODR, i.e. it is not possible to include it more than once

@Dav1dde
Copy link
Owner

Dav1dde commented Nov 13, 2017

Thanks, yeah the header only still needs some improvements.

@elmindreda pointed me to (just so I don't forget): https://github.com/nothings/stb/blob/master/docs/stb_howto.txt#L9

@Dav1dde
Copy link
Owner

Dav1dde commented May 2, 2018

Works in glad2.

@Dav1dde Dav1dde closed this as completed May 2, 2018
@elimerl
Copy link

elimerl commented Jan 23, 2023

For the lazy: You have to #define GLAD_GL_IMPLEMENTATION before including gl.h when using header-only libraries. GLAD_IMPLEMENTATION does not work. Then again this took 15 seconds of looking at the header so whatever, anyone with CTRL+F should be fine :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants